Ignore:
Timestamp:
04/07/03 15:34:51 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhist
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhist/MHHadronness.cc

    r1809 r1910  
    1919!   Author(s): Abelardo Moralejo <mailto:moralejo@pd.infn.it>
    2020!
    21 !   Copyright: MAGIC Software Development, 2000-2002
     21!   Copyright: MAGIC Software Development, 2000-2003
    2222!
    2323!
     
    5151//    - blue cross: minimum of distance to (0, 1)
    5252//
     53// As a default MHHadronness searches for the container "MHadronness".
     54// This can be overwritten by a different pointer specified in the
     55// Fill function (No type check is done!) Use a different name in
     56// MFillH.
     57//
    5358////////////////////////////////////////////////////////////////////////////
    5459#include "MHHadronness.h"
    55 
    56 /*
    57  // - blue:  2D distance of (acceptance_hadrons, acceptances_gammas)
    58  //          to optimum (0, 1):  1-sqrt(Ag*Ag + (1-Ah)*(1-Ah))
    59  */
    6060
    6161#include <TPad.h>
     
    107107    fIntPhness->SetYTitle("Acceptance");
    108108
    109     /*
    110     fQfac = new TH1D("Qfac", "Naive Quality factor", nbins, 0, 1);
    111     fQfac->SetXTitle("Hadronness");
    112     fQfac->SetYTitle("Quality");
    113     */
    114109    fQfac = new TGraph;
    115110    fQfac->SetTitle(" Naive Quality factor ");
    116111
    117     /*
    118      fMinDist = new TH1D("MinDist", "Minimum Dist to (0, 1)", nbins, 0, 1);
    119      fMinDist->SetXTitle("Hadronness");
    120      fMinDist->SetYTitle("Distance");
    121      */
    122 
    123     //fQfac->SetDirectory(NULL);
    124112    fGhness->SetDirectory(NULL);
    125113    fPhness->SetDirectory(NULL);
    126     //fMinDist->SetDirectory(NULL);
    127114    fIntGhness->SetDirectory(NULL);
    128115    fIntPhness->SetDirectory(NULL);
     
    140127    delete fIntPhness;
    141128    delete fQfac;
    142     //    delete fMinDist;
    143129    delete fGraph;
    144130}
     
    159145
    160146    fHadronness = (MHadronness*)plist->FindObject("MHadronness");
    161     if (!fHadronness)
    162     {
    163         *fLog << err << dbginf << "MHadronness not found... aborting." << endl;
    164         return kFALSE;
    165     }
    166147
    167148    /*
     
    186167// histogram dependant on the particle id.
    187168//
     169// Every particle Id different than kGAMMA is considered a hadron.
     170//
     171// If you call Fill with a pointer (eg. from MFillH) this container is
     172// used as a hadronness (Warning: No type check is done!) otherwise
     173// the default is used ("MHadronness")
     174//
    188175// Sometimes a distance is calculated as NaN (not a number). Such events
    189176// are skipped at the moment.
     
    192179{
    193180    // Preliminary Workaround: FIXME!
    194 
    195     const Double_t h = fHadronness->GetHadronness();
     181    if (!par && !fHadronness)
     182    {
     183        *fLog << err << "MHHadronness::Fill: No MHadronness container specified!" << endl;
     184        return kFALSE;
     185    }
     186
     187    const MHadronness &had = par ? *(MHadronness*)par : *fHadronness;
     188
     189    const Double_t h = had.GetHadronness();
    196190
    197191    if (TMath::IsNaN(h))
     
    235229    }
    236230
    237     Float_t retValue;
    238     if (val2x-val1x != 0.0)
    239       retValue = val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
    240     else
    241       retValue = 0.0;
    242 
    243     return retValue;
     231    return val2x-val1x == 0 ? 0 : val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
    244232}
    245233
     
    258246    fQfac->Set(n);
    259247
    260     Stat_t sumg;
    261     Stat_t sump;
    262 
    263     sumg = fGhness->Integral(1, n);
    264     sump = fPhness->Integral(1, n);
    265 
    266     if (sumg == 0.0  ||  sump == 0.0)
    267     {
    268       *fLog << "MHHadronness::Finalize; sumg or sump is zero;   sumg, sump = "
    269             << sumg << ",  " << sump << ".  Cannot calculate hadronness"
    270             << endl;
    271     }
     248    const Stat_t sumg = fGhness->Integral();
     249    const Stat_t sump = fPhness->Integral();
     250
     251    *fLog << inf << "MHHadronness::Finalize - Sum Hadronness: gammas=" << sumg << " hadrons=" << sump << endl;
     252
     253    if (sumg==0 || sump==0)
     254        *fLog << warn << "MHHadronness::Finalize: Cannot calculate hadronness." << endl;
    272255
    273256
    274257    // Normalize photon distribution
    275     Stat_t con;
    276     if (sumg > 0.0)
    277       for (Int_t i=1; i<=n; i++)
    278       {
    279         con = (fGhness->GetBinContent(i)) / sumg;
    280         fGhness->SetBinContent(i, con);       
    281       }
     258    if (sumg>0)
     259        fGhness->Scale(1./sumg);
    282260
    283261    // Normalize hadron distribution
    284     if (sump > 0.0)
    285       for (Int_t i=1; i<=n; i++)
    286       {
    287         con = (fPhness->GetBinContent(i)) / sump;
    288         fPhness->SetBinContent(i, con);       
    289       }
     262    if (sump>0)
     263        fGhness->Scale(1./sump);
    290264
    291265    // Calculate acceptances
    292     sumg = fGhness->Integral(1, n);
    293     sump = fPhness->Integral(1, n);
    294 
    295     *fLog << "MHHadronness::Finalize; sumg, sump = " << sumg << ",  "
    296           << sump << endl;
    297 
    298266    Float_t max=0;
    299267
    300268    for (Int_t i=1; i<=n; i++)
    301269    {
    302         Stat_t ip;
    303         if (sump != 0.0)
    304           ip = fPhness->Integral(1, i)/sump;
    305         else
    306           ip = 0;
    307 
    308         Stat_t ig;
    309         if (sumg != 0.0)
    310           ig = fGhness->Integral(1, i)/sumg;
    311         else
    312           ig = 0;
     270        const Stat_t ip = sump!=0 ? fPhness->Integral(1, i)/sump : 0;
     271        const Stat_t ig = sumg!=0 ? fGhness->Integral(1, i)/sumg : 0;
    313272
    314273        fIntPhness->SetBinContent(i, ip);
     
    319278        if (ip<=0)
    320279            continue;
    321 
    322         //fMinDist->SetBinContent(i, 1-sqrt(ip*ip + (ig-1)*(ig-1)));
    323280
    324281        const Double_t val = ig/sqrt(ip);
     
    432389    *fLog << endl;
    433390
    434     /*
    435      const Int_t h = fMinDist->GetMaximumBin();
    436      *fLog << "Minimum Distance to (0, 1): " << Form("%.2f", 1-fMinDist->GetMaximum()) << " @ H=" << fMinDist->GetBinCenter(h) << endl;
    437      *fLog << "  Acc Gammas = " << Form("%3.0f", fIntGhness->GetBinContent(h)*100) << "%, ";
    438      *fLog << "Acc Hadrons = " << Form("%3.0f", fIntPhness->GetBinContent(h)*100) << "%" << endl;
    439      */
    440 
    441391    *fLog << "Q-Factor @ Acc Gammas=0.5: Q(0.5)=" << Form("%.1f", GetQ05()) << endl;
    442392    *fLog << "  Acc Hadrons = " << Form("%5.1f", GetHadronAcceptance(0.5)*100) << "%" << endl;
     
    463413    Getphness()->SetLineColor(kRed);
    464414    Getphness()->DrawCopy("same");
     415
    465416    c.cd(2);
    466417    //gStyle->SetOptStat(0);
     
    468419    Getiphness()->SetLineColor(kRed);
    469420    Getiphness()->DrawCopy("same");
    470     /*
    471      fMinDist->SetLineColor(kBlue);
    472      fMinDist->DrawCopy("same");
    473      */
     421
    474422    c.cd(3);
    475     //GetQfac()->DrawCopy();
    476423    TGraph &g2 = (TGraph&)*fQfac->DrawClone("A*");
    477424    g2.SetBit(kCanDelete);
     
    489436        gPad->Update();
    490437    }
     438
    491439    c.cd(4);
    492440    gPad->Modified();
     
    537485    Getphness()->SetLineColor(kRed);
    538486    Getphness()->Draw("same");
     487
    539488    gPad->cd(2);
    540489    //gStyle->SetOptStat(0);
     
    542491    Getiphness()->SetLineColor(kRed);
    543492    Getiphness()->Draw("same");
    544     /*
    545      fMinDist->SetLineColor(kBlue);
    546      fMinDist->Draw("same");
    547      */
     493
    548494    gPad->cd(3);
    549     //GetQfac()->Draw();
    550495    fQfac->Draw("A*");
    551496    gPad->Modified();
     
    578523        gPad->Update();
    579524    }
    580     /*
    581     const Int_t h = fMinDist->GetMaximumBin();
    582     TMarker *m = new TMarker(fIntPhness->GetBinContent(h),
    583                              fIntGhness->GetBinContent(h), kStar);
    584     m->SetMarkerColor(kBlue);
    585     m->SetBit(kCanDelete);
    586     m->Draw();
    587     */
    588 }
     525}
  • trunk/MagicSoft/Mars/mhist/MHHadronness.h

    r1668 r1910  
    2222    TH1D* fIntPhness; //-> Hadrons Acceptance
    2323    TH1D* fIntGhness; //-> Gammas  Acceptance
    24     //TH1D* fMinDist; //-> Minimum Distance to optimum acceptance
    2524
    2625    TGraph *fQfac;    //-> Quality factor
Note: See TracChangeset for help on using the changeset viewer.