Ignore:
Timestamp:
02/14/05 19:04:58 (20 years ago)
Author:
rico
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mtemp/mifae/library
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtemp/mifae/library/MEffAreaAndCoeffCalc.cc

    r6368 r6465  
    3838#include "MMcEvt.hxx"
    3939#include "TH2F.h"
     40#include "TFile.h"
    4041
    4142#include "MLog.h"
     
    5556//
    5657MEffAreaAndCoeffCalc::MEffAreaAndCoeffCalc()
    57   : fSpec(NULL), fHorig(NULL), fEbins(10), fEsubbins(20), fEmin(10.), fEmax(10000.),
    58     fCoeff(NULL), fEffA(NULL)
     58  : fSpec(NULL), fHorig(NULL), fEmin(10.), fEmax(10000.), fEbins(10), fEsubbins(20),
     59    fCoeff(NULL), fEffA(NULL), fFile(NULL)
    5960{
    6061  // set the default function
    61   // OJO!! this should be changed
    6262  SetFunction("4.e9*pow(x,-2.6+1)"); 
    6363
    6464  // create the TChains
    6565  // OJO!! make sure they read the appropriate branch
    66   fCini = new TChain("Events");
     66  fCini = new TChain("OriginalMC");
    6767  fCcut = new TChain("Events");
    6868
    69   // define some usefull aliases
    70   fCini->SetAlias("logenergy","log10(MMcEvt.fEnergy)");
    71   fCini->SetAlias("theta","MMcEvt.fTheta*180./3.14159");
    72 
    73   // OJO!! the estimated energy must be changed for a real one
     69  // define some useful aliases
     70  fCini->SetAlias("logenergy","log10(MMcEvtBasic.fEnergy)");
     71  fCini->SetAlias("theta","MMcEvtBasic.fTelescopeTheta*180./3.14159");
     72
    7473  fCcut->SetAlias("logenergy","log10(MMcEvt.fEnergy)");
    75   fCcut->SetAlias("theta","MMcEvt.fTheta*180./3.14159");
    76 
    77   fCcut->SetBranchStatus("*",0);
    78   fCcut->SetBranchStatus("MHillas.*",1);
    79   fCcut->SetBranchStatus("MMcEvt.*",1);
     74  fCcut->SetAlias("theta","MMcEvt.fTelescopeTheta*180./3.14159");
     75
    8076  fCcut->SetBranchAddress("MHillas.",&fHillas);
    8177  fCcut->SetBranchAddress("MMcEvt.",&fMcEvt);
     78 
     79  // borra
     80  fFile = new TFile("test.root","RECREATE");
    8281}
    8382
     
    119118      emin = fEmin;
    120119      emax = fEmax;
     120    }
     121  else
     122    {
     123      fEmin = emin;
     124      fEmax = emax;
    121125    }
    122126  fSpec = new TF1("fspec",chfunc,emin,emax);
     
    147151  fHorig   = new TH1F("fhorig","Original energy spectrum",esbins,logemin,logemax);
    148152  fCini->Draw("logenergy>>fhorig","","goff");
     153  // borra
     154  fHorig->Write();
    149155}
    150156
     
    169175    FillOriginalSpectrum();
    170176 
     177  // borra
     178  TH1F hw("hw","hw",esbins,fEmin,fEmax);
    171179  for(Int_t i=0;i<esbins;i++)
    172180    {
     
    181189          fWeight[i]=-1;
    182190        }
    183     }
     191      // borra
     192      hw.SetBinContent(i+1,fWeight[i]);
     193    }
     194  // borra
     195  hw.Write();
    184196}
    185197
     
    207219  TH2F* hmc  = new TH2F("hmc","MC energy",fEbins,logemin,logemax,fNTbins,fTbin);
    208220
     221  // borra
     222  TH1F* hest1  = new TH1F("hest1","Estimated energy",fEbins,logemin,logemax);
     223  TH1F* hmc1   = new TH1F("hmc1","MC energy",fEbins,logemin,logemax);
     224  TH1F* coef1  = new TH1F("coef1","coefficients",fEbins,logemin,logemax);
     225
    209226  // reset the coefficients
    210227  if(fCoeff)
     
    220237      // OJO!! Estimated energy will be taken directly from some input container
    221238      Float_t emc   = fMcEvt->GetEnergy();
    222       Float_t estim = fHillas->GetSize()/15.;
     239      Float_t estim = fHillas->GetSize()/0.18/15.;
    223240      Float_t theta = fMcEvt->GetTheta()*180./3.14159; // zenith angle (in degrees)
    224241
     
    231248          hest->Fill(TMath::Log10(estim),theta,fWeight[wbin]);
    232249          hmc->Fill(TMath::Log10(emc),theta,fWeight[wbin]);
     250          // borra
     251          if(theta<fTbin[1])
     252            {
     253              hest1->Fill(TMath::Log10(estim),fWeight[wbin]);
     254              hmc1->Fill(TMath::Log10(emc),fWeight[wbin]);
     255            }
    233256        }
    234257      else
    235         cout << "MEffAreaAndCoeffCalc::ComputeCoefficients Warning: event " << i << " with energy " << emc << " has energy out of bounds, skpping" << endl;
     258        cout << "MEffAreaAndCoeffCalc::ComputeCoefficients Warning: event " << i << " with energy " << emc << " has energy out of bounds, skipping" << endl;
    236259    }
    237260
     
    242265        const Float_t num = hmc->GetBinContent(i+1,j+1);
    243266        const Float_t den = hest->GetBinContent(i+1,j+1);
     267        //borra
     268        const Float_t num1 = hmc1->GetBinContent(i+1);
     269        const Float_t den1 = hest1->GetBinContent(i+1);
    244270        if(den)
    245           fCoeff->SetBinContent(i+1,j+1,num/den);
     271          {
     272            fCoeff->SetBinContent(i+1,j+1,num/den);
     273            //borra
     274            if(j==0 && den1)
     275              coef1->SetBinContent(i+1,num1/den1);
     276          }
    246277        else
    247278          {
     
    252283
    253284
     285  //borra
     286  hmc1->Write();
     287  hest1->Write();
     288  coef1->Write();
     289
    254290  delete hmc;
    255291  delete hest;
     
    270306  //OJO!! radius should be read from somewhere!
    271307  const Double_t radius = 30000.; // generation radius (in cm)
    272   const Double_t Atot = 3.14159*radius*radius; //total area (in cm^2)
     308  //  const Double_t Atot = 3.14159*radius*radius; //total area (in cm^2)
     309  const Double_t Atot = 1.; //total area (in cm^2)
    273310  const Double_t logemin = TMath::Log10(fEmin);
    274311  const Double_t logemax = TMath::Log10(fEmax);
    275312  const Int_t esbins = fEbins*fEsubbins; // total number of subbins
     313  const Double_t de = (logemax-logemin)/fEbins; // bin size (in log)
     314  const Double_t desub = de/fEsubbins; // subbin size (in log)
    276315
    277316  // reset the effective areas
    278317  if(fEffA)
    279318    delete fEffA;
    280   fEffA = new TH2F("feffa","Effective area",esbins,logemin,logemax,fNTbins,fTbin);
    281 
     319  fEffA = new TH2F("feffa","Effective area",fEbins,logemin,logemax,fNTbins,fTbin);
     320  //borra
     321  TH1F eff("eff","Effective area",fEbins,logemin,logemax);
     322 
    282323  // fill the spectrum of the survivors
    283324  TH2F* hpass= new TH2F("hpass","Survivors",esbins,logemin,logemax,fNTbins,fTbin);
     
    289330  // compute the effective areas
    290331  for(Int_t j=0;j<fNTbins;j++)
    291     for(Int_t i=0;i<esbins;i++)
     332    for(Int_t i=0;i<fEbins;i++)
    292333      {
    293         if(horig->GetBinContent(i+1,j+1)<=0)
     334        Float_t effarea =0;
     335        Float_t wtot = 0;
     336        for(Int_t k=0;k<fEsubbins;k++)
     337          {
     338            Float_t numerator = hpass->GetBinContent(i*fEsubbins+k+1,j+1);
     339            Float_t denominator = horig->GetBinContent(i*fEsubbins+k+1,j+1);
     340           
     341            if(denominator<=0)
     342              cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: energy subbin " << i*fEsubbins+k <<", theta bin " << j << " contains no events" << endl;
     343            else
     344              {
     345                const Double_t ew = TMath::Power(10,logemin+(i*fEsubbins+k+0.5)*desub);
     346                const Double_t ww = fSpec->Eval(ew);
     347                effarea+=Atot*numerator/denominator*ww;
     348                wtot   += ww;
     349              }
     350          }
     351        if(!wtot)
    294352          {
    295353            cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: energy bin " << i <<", theta bin " << j << " contains no events setting effective area to 0" << endl;
    296354            fEffA->SetBinContent(i+1,j+1,0);
     355          }         
     356        else
     357          {
     358            fEffA->SetBinContent(i+1,j+1,effarea/wtot);
     359            if(j==0)
     360              {
     361                cout << "*****" << i << ": " << effarea/wtot << endl;
     362                eff.SetBinContent(i+1,effarea/wtot);
     363              }
    297364          }
    298         else
    299           fEffA->SetBinContent(i+1,j+1,Atot*hpass->GetBinContent(i+1,j+1)/horig->GetBinContent(i+1,j+1));
    300365      }
    301  
    302 
     366
     367  // borra
     368  eff.Write();
    303369 
    304370  delete hpass;
  • trunk/MagicSoft/Mars/mtemp/mifae/library/MEffAreaAndCoeffCalc.h

    r6368 r6465  
    1818 private:
    1919
    20   TF1* fSpec;        // function used to parametrized the spectrum
    21   TH1F* fHorig;      // histogram with the original energy spectrum
     20  TF1* fSpec;        // function used to parametrize the spectrum
     21  TH1F* fHorig;      // histogram with the original sample energy spectrum
    2222
    23   Int_t fEbins;      // number of bins to build spectrum
    24   Int_t fEsubbins;   // number of subbins per big bin
    2523  Double_t fEmin;    // Minimum energy in GeV
    2624  Double_t fEmax;    // Maximum energy in GeV
     25  Int_t fEbins;      // number of bins to build spectrum
     26  Int_t fEsubbins;   // number of subbins per big bin (to compute weights, eff areas...)
    2727
    2828  Double_t* fWeight; // array containing weights
     
    3030  TH2F* fEffA;       // histogram containing effective areas
    3131
    32   TChain* fCini;     // chain for initial MC events (even those not triggering)
     32  TChain* fCini;     // chain for initial MC files (before trigger)
    3333  TChain* fCcut;     // chain for surviving MC events (after cuts)
    3434
    3535  MHillas* fHillas;  // pointer to the MHillas Branch
    3636  MMcEvt*  fMcEvt;   // pointer to the MMcEvt Branch
     37
     38  TFile* fFile; // output file (for debugging only)
    3739
    3840 protected:
     
    4446
    4547 public:
     48
    4649  MEffAreaAndCoeffCalc();
    4750
     
    5558  void SetEmax(Float_t x)   {fEmax=x;}
    5659
    57   void AddFileToInitialMC(const Char_t* name) {fCini->Add(name);}
    58   void AddFileToFinalMC(const Char_t* name) {fCcut->Add(name);}
     60  void AddFile(const Char_t* name) {fCini->Add(name); fCcut->Add(name);}
    5961
    6062  TH2F* GetEffectiveAreaHisto() {return fEffA;}
Note: See TracChangeset for help on using the changeset viewer.