Changeset 6368 for trunk/MagicSoft/Mars


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

Legend:

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

    r6359 r6368  
    3737#include "MHillas.h"
    3838#include "MMcEvt.hxx"
    39 #include "TH1D.h"
     39#include "TH2F.h"
    4040
    4141#include "MLog.h"
     
    4646using namespace std;
    4747
     48const Int_t fNTbins = 2;
     49const Double_t fTbin[fNTbins+1] = {0,10,20};
     50
    4851
    4952// -------------------------------------------------------------------------
     
    5255//
    5356MEffAreaAndCoeffCalc::MEffAreaAndCoeffCalc()
    54   : fSpec(NULL), fHorig(NULL), fEbins(10), fEsubbins(20), fEmin(10.), fEmax(10000.)
     57  : fSpec(NULL), fHorig(NULL), fEbins(10), fEsubbins(20), fEmin(10.), fEmax(10000.),
     58    fCoeff(NULL), fEffA(NULL)
    5559{
    5660  // set the default function
     
    6468
    6569  // define some usefull aliases
    66   fCini->SetAlias("energy","MMcEvt.fEnergy");
    6770  fCini->SetAlias("logenergy","log10(MMcEvt.fEnergy)");
    68   fCini->SetAlias("hastriggered","MMcTrig.fNumFirstLevel");
     71  fCini->SetAlias("theta","MMcEvt.fTheta*180./3.14159");
    6972
    7073  // OJO!! the estimated energy must be changed for a real one
    71   fCcut->SetAlias("logestenergy","log10(MHillas.fSize/15.)");
    7274  fCcut->SetAlias("logenergy","log10(MMcEvt.fEnergy)");
     75  fCcut->SetAlias("theta","MMcEvt.fTheta*180./3.14159");
    7376
    7477  fCcut->SetBranchStatus("*",0);
     
    9295
    9396  if(fCoeff)
    94     delete [] fCoeff;
     97    delete fCoeff;
    9598
    9699  if(fEffA)
    97     delete [] fEffA;
     100    delete fEffA;
    98101
    99102  if(fHorig)
     
    142145 
    143146  if(fHorig) delete fHorig;
    144   fHorig   = new TH1D("horig","Original energy spectrum",esbins,logemin,logemax);
    145   fCini->Draw("logenergy>>horig","","goff");
     147  fHorig   = new TH1F("fhorig","Original energy spectrum",esbins,logemin,logemax);
     148  fCini->Draw("logenergy>>fhorig","","goff");
    146149}
    147150
     
    201204 
    202205  // declare needed histos
    203   TH1D* hest = new TH1D("hest","Estimated energy",fEbins,logemin,logemax);
    204   TH1D* hmc  = new TH1D("hmc","MC energy",fEbins,logemin,logemax);
     206  TH2F* hest = new TH2F("hest","Estimated energy",fEbins,logemin,logemax,fNTbins,fTbin);
     207  TH2F* hmc  = new TH2F("hmc","MC energy",fEbins,logemin,logemax,fNTbins,fTbin);
    205208
    206209  // reset the coefficients
    207210  if(fCoeff)
    208     delete [] fCoeff;
    209   fCoeff = new Double_t[fEbins];
     211    delete fCoeff;
     212  fCoeff = new TH2F("fcoeff","Coefficients for unfolding",fEbins,logemin,logemax,fNTbins,fTbin);
    210213
    211214  // fill the histograms of estimated and measured energy for weighted events
     
    218221      Float_t emc   = fMcEvt->GetEnergy();
    219222      Float_t estim = fHillas->GetSize()/15.;
     223      Float_t theta = fMcEvt->GetTheta()*180./3.14159; // zenith angle (in degrees)
    220224
    221225      // compute the bin where the weight is taken from
     
    225229      if(wbin<esbins)
    226230        {
    227           hest->Fill(TMath::Log10(estim),fWeight[wbin]);
    228           hmc->Fill(TMath::Log10(emc),fWeight[wbin]);
     231          hest->Fill(TMath::Log10(estim),theta,fWeight[wbin]);
     232          hmc->Fill(TMath::Log10(emc),theta,fWeight[wbin]);
    229233        }
    230234      else
     
    233237
    234238  // divide the previous histos to get the coefficients for unfolding
    235   for(Int_t i=0;i<fEbins;i++)
    236     {
    237       const Float_t num = hmc->GetBinContent(i+1);
    238       const Float_t den = hest->GetBinContent(i+1);
    239       if(den)
    240         fCoeff[i]=num/den;
    241       else
    242         {
    243           cout << "MEffAreaAndCoeffCalc::ComputeCoefficients Warning: energy bin " << i << " has no survivors, setting coefficient to 0" << endl;
    244           fCoeff[i]=0;
    245         }
    246     }
     239  for(Int_t j=0;j<fNTbins;j++)
     240    for(Int_t i=0;i<fEbins;i++)
     241      {
     242        const Float_t num = hmc->GetBinContent(i+1,j+1);
     243        const Float_t den = hest->GetBinContent(i+1,j+1);
     244        if(den)
     245          fCoeff->SetBinContent(i+1,j+1,num/den);
     246        else
     247          {
     248            cout << "MEffAreaAndCoeffCalc::ComputeCoefficients Warning: energy bin " << i << ", thetabin " << j << " has no survivors, setting coefficient to 0" << endl;
     249            fCoeff->SetBinContent(i+1,j+1,0.);
     250          }
     251      }
     252
    247253
    248254  delete hmc;
     
    256262void MEffAreaAndCoeffCalc::ComputeEffectiveAreas()
    257263{
     264  if(!fWeight)
     265    {
     266      cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: No weights computed! nothing done" << endl;
     267      return;
     268    }
     269
    258270  //OJO!! radius should be read from somewhere!
    259271  const Double_t radius = 30000.; // generation radius (in cm)
     
    265277  // reset the effective areas
    266278  if(fEffA)
    267     delete [] fEffA;
    268   fEffA = new Double_t[esbins];
    269 
    270   // check if the original spectrum is filled
    271   if(!fHorig)
    272     FillOriginalSpectrum();
     279    delete fEffA;
     280  fEffA = new TH2F("feffa","Effective area",esbins,logemin,logemax,fNTbins,fTbin);
    273281
    274282  // fill the spectrum of the survivors
    275   TH1F* hpass= new TH1F("hpass","Survivors",esbins,logemin,logemax);
    276   fCcut->Draw("logenergy>>hpass","","goff");
    277 
     283  TH2F* hpass= new TH2F("hpass","Survivors",esbins,logemin,logemax,fNTbins,fTbin);
     284  TH2F* horig= new TH2F("horig","Original events",esbins,logemin,logemax,fNTbins,fTbin);
     285
     286  fCcut->Draw("theta:logenergy>>hpass","","goff");
     287  fCini->Draw("theta:logenergy>>horig","","goff");
     288 
    278289  // compute the effective areas
    279   for(Int_t i=0;i<esbins;i++)
    280     if(fHorig->GetBinContent(i+1)<=0)
     290  for(Int_t j=0;j<fNTbins;j++)
     291    for(Int_t i=0;i<esbins;i++)
    281292      {
    282         cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: energy bin " << i << " contains no events setting effective area to 0" << endl;
    283         fEffA[i]=0;
     293        if(horig->GetBinContent(i+1,j+1)<=0)
     294          {
     295            cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: energy bin " << i <<", theta bin " << j << " contains no events setting effective area to 0" << endl;
     296            fEffA->SetBinContent(i+1,j+1,0);
     297          }
     298        else
     299          fEffA->SetBinContent(i+1,j+1,Atot*hpass->GetBinContent(i+1,j+1)/horig->GetBinContent(i+1,j+1));
    284300      }
    285     else
    286       fEffA[i]=Atot*hpass->GetBinContent(i+1)/fHorig->GetBinContent(i+1);
    287 
     301 
     302
     303 
    288304  delete hpass;
     305  delete horig;
    289306}
    290307
  • trunk/MagicSoft/Mars/mtemp/mifae/library/MEffAreaAndCoeffCalc.h

    r6359 r6368  
    77
    88class TF1;
    9 class TH1D;
     9class TH1F;
     10class TH2F;
    1011class MHillas;
    1112class MMcEvt;
     
    1819
    1920  TF1* fSpec;        // function used to parametrized the spectrum
    20   TH1D* fHorig;      // histogram with the original energy spectrum
     21  TH1F* fHorig;      // histogram with the original energy spectrum
    2122
    2223  Int_t fEbins;      // number of bins to build spectrum
     
    2526  Double_t fEmax;    // Maximum energy in GeV
    2627
    27  
    2828  Double_t* fWeight; // array containing weights
    29   Double_t* fCoeff;  // array containing coefficients
    30   Double_t* fEffA;   // array containing effective areas
     29  TH2F* fCoeff;      // histogram containing unfolding coefficients
     30  TH2F* fEffA;       // histogram containing effective areas
    3131
    32   TChain* fCini; // chain for initial MC events (even those not triggering)
    33   TChain* fCcut; // chain for surviving MC events (after cuts)
     32  TChain* fCini;     // chain for initial MC events (even those not triggering)
     33  TChain* fCcut;     // chain for surviving MC events (after cuts)
    3434
    35   MHillas* fHillas; // pointer to the MHillas Branch
     35  MHillas* fHillas;  // pointer to the MHillas Branch
    3636  MMcEvt*  fMcEvt;   // pointer to the MMcEvt Branch
    3737
    3838 protected:
     39
    3940  void FillOriginalSpectrum();
    4041  void ComputeCoefficients();
     
    5152  void SetEbins(Int_t i)    {fEbins=i;}
    5253  void SetEsubbins(Int_t i) {fEsubbins=i;}
    53   void SetE(Float_t x)        {fEmin=x;}
    54   void SetEbins(Float_t x)    {fEmax=x;}
     54  void SetEmin(Float_t x)   {fEmin=x;}
     55  void SetEmax(Float_t x)   {fEmax=x;}
    5556
    5657  void AddFileToInitialMC(const Char_t* name) {fCini->Add(name);}
    5758  void AddFileToFinalMC(const Char_t* name) {fCcut->Add(name);}
    5859
    59   Double_t GetEffectiveArea(Int_t i) {return fEffA[i];}
    60   Double_t GetCoefficient(Int_t i)   {return fCoeff[i];}
     60  TH2F* GetEffectiveAreaHisto() {return fEffA;}
     61  TH2F* GetCoefficientHisto()   {return fCoeff;}
    6162
    6263  void ComputeAllFactors();
  • trunk/MagicSoft/Mars/mtemp/mifae/macros/computeCoeff.C

    r6359 r6368  
    3434  const Int_t esubbins = 20;           // number of subbins per big bin
    3535  const Double_t emin=10;
    36   const Double_t emax=10000;
     36  const Double_t emax=1000;
    3737  const Double_t logemin = TMath::Log10(emin);
    3838  const Double_t logemax = TMath::Log10(emax);
     
    7979      UInt_t coefbin = UInt_t((TMath::Log10(estim)-logemin)/de);
    8080     
    81       Float_t effa  =  calc.GetEffectiveArea(effabin);
    82       Float_t unfold = calc.GetCoefficient(coefbin);
     81      Float_t effa  =  calc.GetEffectiveAreaHisto()->GetBinContent(effabin+1,1);
     82      Float_t unfold = calc.GetCoefficientHisto()->GetBinContent(coefbin+1,1);
    8383     
    8484      if(effa)
     
    8989  TFile file("prueba.root","RECREATE");
    9090  hspec->Write();
    91 
     91  calc.GetEffectiveAreaHisto()->Write();
     92  calc.GetCoefficientHisto()->Write();
    9293  return;
    9394}
Note: See TracChangeset for help on using the changeset viewer.