Changeset 6465 for trunk/MagicSoft


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

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtemp/mifae/Changelog

    r6359 r6465  
    1919                                                 -*-*- END OF LINE -*-*-
    2020
     21 2005/02/10 Javier Rico
     22    * library/MEffAreaAndCoeffCalc.[h,cc]
     23    * macros/computeCoeff.C
     24      - compute the coefficients in the big bins
     25      - migrate to new data format
     26     
     27       
    2128 2005/02/10 Javier Rico
    2229    * library/MEffAreaAndCoeffCalc.[h,cc]
  • 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;}
  • trunk/MagicSoft/Mars/mtemp/mifae/macros/computeCoeff.C

    r6368 r6465  
    44{   
    55  MEffAreaAndCoeffCalc calc;
     6  calc.AddFile("/data/star_gamma_test.root");
    67
    7   // initial MC files
    8   calc.AddFileToInitialMC("/data/camera_NCL/Gamma_zbin0_0_7_1000to1009_w0.root");
    9   calc.AddFileToInitialMC("/data/camera_NCL/Gamma_zbin0_0_7_1130to1139_w0.root");
    10   calc.AddFileToInitialMC("/data/camera_NCL/Gamma_zbin0_0_7_1520to1529_w0.root");
    11   calc.AddFileToInitialMC("/data/camera_NCL/Gamma_zbin0_90_7_1260to1269_w0.root");
    12   calc.AddFileToInitialMC("/data/camera_NCL/Gamma_zbin0_90_7_1390to1399_w0.root");
    13   calc.AddFileToInitialMC("/data/camera_NCL/Gamma_zbin0_90_7_1650to1659_w0.root");
    14  
    15 
    16   // files with remaining events after cuts (or where to apply cuts) see warning above
    17   calc.AddFileToFinalMC("/data/camera_CL/Gamma_zbin0_0_7_1000to1009_w0_cleaned4035.root");
    18   calc.AddFileToFinalMC("/data/camera_CL/Gamma_zbin0_0_7_1130to1139_w0_cleaned4035.root");
    19   calc.AddFileToFinalMC("/data/camera_CL/Gamma_zbin0_0_7_1520to1529_w0_cleaned4035.root");
    20   calc.AddFileToFinalMC("/data/camera_CL/Gamma_zbin0_90_7_1260to1269_w0_cleaned4035.root");
    21   calc.AddFileToFinalMC("/data/camera_CL/Gamma_zbin0_90_7_1390to1399_w0_cleaned4035.root");
    22   calc.AddFileToFinalMC("/data/camera_CL/Gamma_zbin0_90_7_1650to1659_w0_cleaned4035.root");
    23 
    24 
    25   // define the funtion of the desired spectrum
    26   calc.SetFunction("4.e9*pow(x,-2.6+1)",10.,10000.);
    27   calc.ComputeAllFactors();
    28  
    298  /************************************************/
    309  /* Build spectrum                               */
     
    3211  /************************************************/
    3312  const Int_t ebins = 10;              // number of bins to build spectrum
    34   const Int_t esubbins = 20;           // number of subbins per big bin
    3513  const Double_t emin=10;
    36   const Double_t emax=1000;
     14  const Double_t emax=600;
    3715  const Double_t logemin = TMath::Log10(emin);
    3816  const Double_t logemax = TMath::Log10(emax);
    39   const Double_t de = (logemax-logemin)/ebins; // bin size (in log)
    40   const Double_t desub = de/esubbins; // subbin size (in log)
    41   const Int_t esbins = ebins*esubbins; // total number of subbins
     17  calc.SetEbins(ebins);
     18  //  calc.SetEsubbins(1);
    4219
    43   // remaining events after cuts
    44   const UInt_t ncutfiles=6;
    45   Char_t* cutName[ncutfiles]={
    46     "/data/camera_CL/Gamma_zbin0_0_7_1000to1009_w0_cleaned4035.root",
    47     "/data/camera_CL/Gamma_zbin0_0_7_1130to1139_w0_cleaned4035.root",
    48     "/data/camera_CL/Gamma_zbin0_0_7_1520to1529_w0_cleaned4035.root",
    49     "/data/camera_CL/Gamma_zbin0_90_7_1260to1269_w0_cleaned4035.root",
    50     "/data/camera_CL/Gamma_zbin0_90_7_1390to1399_w0_cleaned4035.root",
    51     "/data/camera_CL/Gamma_zbin0_90_7_1650to1659_w0_cleaned4035.root"
    52   };
     20  // define the funtion of the desired spectrum
     21  calc.SetFunction("4.e9*pow(x,-2.6+1)",emin,emax);
     22  calc.ComputeAllFactors();
     23 
     24  const UInt_t ncutfiles=1;
     25  Char_t* cutName[ncutfiles]={"/data/star_gamma_test.root"};
    5326
    5427  TChain* ccut = new TChain("Events");
    5528  for(Int_t i = 0; i < ncutfiles; i++)
    5629    ccut->Add(cutName[i]);
    57   ccut->SetAlias("logestenergy","log10(MHillas.fSize/15.)");
    58   const Int_t nentries = Int_t(ccut->GetEntries());
    59 
    60   MHillas*  hillas;
    61   MMcEvt*   mcevt;
    62   ccut->SetBranchStatus("*",0);
    63   ccut->SetBranchStatus("MHillas.*",1);
    64   ccut->SetBranchStatus("MMcEvt.*",1);
    65   ccut->SetBranchAddress("MHillas.",&hillas);
    66   ccut->SetBranchAddress("MMcEvt.",&mcevt);
     30  ccut->SetAlias("logestenergy","log10(MHillas.fSize/0.18/15.)");
     31  ccut->SetAlias("theta","MMcEvt.fTelescopeTheta*180./3.14159");
    6732
    6833  TH1D* hspec = new TH1D("hspec","Spectrum",ebins,logemin,logemax);
    6934  hspec->Sumw2();
     35  ccut->Draw("logestenergy>>hspec","theta<10","goff");
    7036
    71   for(Int_t i=0;i<nentries;i++)
     37  for(Int_t i=0;i<ebins;i++)
    7238    {
    73       ccut->GetEntry(i); 
    74      
    75       // OJO!! Estimated energy will be taken directly from some input container
    76       Float_t estim  = hillas->GetSize()/15.;
    77 
    78       UInt_t effabin = UInt_t((TMath::Log10(estim)-logemin)/desub);
    79       UInt_t coefbin = UInt_t((TMath::Log10(estim)-logemin)/de);
    80      
    81       Float_t effa  =  calc.GetEffectiveAreaHisto()->GetBinContent(effabin+1,1);
    82       Float_t unfold = calc.GetCoefficientHisto()->GetBinContent(coefbin+1,1);
    83      
     39      const Float_t uncorrval = hspec->GetBinContent(i+1);
     40      const Float_t effa  =  calc.GetEffectiveAreaHisto()->GetBinContent(i+1,1);
     41      const Float_t unfold = calc.GetCoefficientHisto()->GetBinContent(i+1,1);
     42      Float_t corrval;
    8443      if(effa)
    85         hspec->Fill(TMath::Log10(estim),unfold/effa*1e9);
    86     }     
     44        corrval = uncorrval*unfold/effa;
     45      else
     46        corrval = 0;
     47      hspec->SetBinContent(i+1,corrval);
     48    }
    8749
    8850  // SAVE RESULTS
Note: See TracChangeset for help on using the changeset viewer.