Ignore:
Timestamp:
02/10/05 19:54:14 (20 years ago)
Author:
rico
Message:
*** empty log message ***
File:
1 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
Note: See TracChangeset for help on using the changeset viewer.