Changeset 6368 for trunk/MagicSoft/Mars/mtemp/mifae/library
- Timestamp:
- 02/10/05 19:54:14 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mtemp/mifae/library
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtemp/mifae/library/MEffAreaAndCoeffCalc.cc
r6359 r6368 37 37 #include "MHillas.h" 38 38 #include "MMcEvt.hxx" 39 #include "TH 1D.h"39 #include "TH2F.h" 40 40 41 41 #include "MLog.h" … … 46 46 using namespace std; 47 47 48 const Int_t fNTbins = 2; 49 const Double_t fTbin[fNTbins+1] = {0,10,20}; 50 48 51 49 52 // ------------------------------------------------------------------------- … … 52 55 // 53 56 MEffAreaAndCoeffCalc::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) 55 59 { 56 60 // set the default function … … 64 68 65 69 // define some usefull aliases 66 fCini->SetAlias("energy","MMcEvt.fEnergy");67 70 fCini->SetAlias("logenergy","log10(MMcEvt.fEnergy)"); 68 fCini->SetAlias(" hastriggered","MMcTrig.fNumFirstLevel");71 fCini->SetAlias("theta","MMcEvt.fTheta*180./3.14159"); 69 72 70 73 // OJO!! the estimated energy must be changed for a real one 71 fCcut->SetAlias("logestenergy","log10(MHillas.fSize/15.)");72 74 fCcut->SetAlias("logenergy","log10(MMcEvt.fEnergy)"); 75 fCcut->SetAlias("theta","MMcEvt.fTheta*180./3.14159"); 73 76 74 77 fCcut->SetBranchStatus("*",0); … … 92 95 93 96 if(fCoeff) 94 delete []fCoeff;97 delete fCoeff; 95 98 96 99 if(fEffA) 97 delete []fEffA;100 delete fEffA; 98 101 99 102 if(fHorig) … … 142 145 143 146 if(fHorig) delete fHorig; 144 fHorig = new TH1 D("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"); 146 149 } 147 150 … … 201 204 202 205 // declare needed histos 203 TH 1D* hest = new TH1D("hest","Estimated energy",fEbins,logemin,logemax);204 TH 1D* 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); 205 208 206 209 // reset the coefficients 207 210 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); 210 213 211 214 // fill the histograms of estimated and measured energy for weighted events … … 218 221 Float_t emc = fMcEvt->GetEnergy(); 219 222 Float_t estim = fHillas->GetSize()/15.; 223 Float_t theta = fMcEvt->GetTheta()*180./3.14159; // zenith angle (in degrees) 220 224 221 225 // compute the bin where the weight is taken from … … 225 229 if(wbin<esbins) 226 230 { 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]); 229 233 } 230 234 else … … 233 237 234 238 // 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 247 253 248 254 delete hmc; … … 256 262 void MEffAreaAndCoeffCalc::ComputeEffectiveAreas() 257 263 { 264 if(!fWeight) 265 { 266 cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: No weights computed! nothing done" << endl; 267 return; 268 } 269 258 270 //OJO!! radius should be read from somewhere! 259 271 const Double_t radius = 30000.; // generation radius (in cm) … … 265 277 // reset the effective areas 266 278 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); 273 281 274 282 // 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 278 289 // 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++) 281 292 { 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)); 284 300 } 285 else286 fEffA[i]=Atot*hpass->GetBinContent(i+1)/fHorig->GetBinContent(i+1); 287 301 302 303 288 304 delete hpass; 305 delete horig; 289 306 } 290 307 -
trunk/MagicSoft/Mars/mtemp/mifae/library/MEffAreaAndCoeffCalc.h
r6359 r6368 7 7 8 8 class TF1; 9 class TH1D; 9 class TH1F; 10 class TH2F; 10 11 class MHillas; 11 12 class MMcEvt; … … 18 19 19 20 TF1* fSpec; // function used to parametrized the spectrum 20 TH1 D* fHorig; // histogram with the original energy spectrum21 TH1F* fHorig; // histogram with the original energy spectrum 21 22 22 23 Int_t fEbins; // number of bins to build spectrum … … 25 26 Double_t fEmax; // Maximum energy in GeV 26 27 27 28 28 Double_t* fWeight; // array containing weights 29 Double_t* fCoeff; // array containing coefficients30 Double_t* fEffA; // arraycontaining effective areas29 TH2F* fCoeff; // histogram containing unfolding coefficients 30 TH2F* fEffA; // histogram containing effective areas 31 31 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) 34 34 35 MHillas* fHillas; // pointer to the MHillas Branch35 MHillas* fHillas; // pointer to the MHillas Branch 36 36 MMcEvt* fMcEvt; // pointer to the MMcEvt Branch 37 37 38 38 protected: 39 39 40 void FillOriginalSpectrum(); 40 41 void ComputeCoefficients(); … … 51 52 void SetEbins(Int_t i) {fEbins=i;} 52 53 void SetEsubbins(Int_t i) {fEsubbins=i;} 53 void SetE (Float_t x){fEmin=x;}54 void SetE bins(Float_t x){fEmax=x;}54 void SetEmin(Float_t x) {fEmin=x;} 55 void SetEmax(Float_t x) {fEmax=x;} 55 56 56 57 void AddFileToInitialMC(const Char_t* name) {fCini->Add(name);} 57 58 void AddFileToFinalMC(const Char_t* name) {fCcut->Add(name);} 58 59 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;} 61 62 62 63 void ComputeAllFactors();
Note:
See TracChangeset
for help on using the changeset viewer.