Changeset 6465 for trunk/MagicSoft/Mars/mtemp/mifae/library
- Timestamp:
- 02/14/05 19:04:58 (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
r6368 r6465 38 38 #include "MMcEvt.hxx" 39 39 #include "TH2F.h" 40 #include "TFile.h" 40 41 41 42 #include "MLog.h" … … 55 56 // 56 57 MEffAreaAndCoeffCalc::MEffAreaAndCoeffCalc() 57 : fSpec(NULL), fHorig(NULL), fE bins(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) 59 60 { 60 61 // set the default function 61 // OJO!! this should be changed62 62 SetFunction("4.e9*pow(x,-2.6+1)"); 63 63 64 64 // create the TChains 65 65 // OJO!! make sure they read the appropriate branch 66 fCini = new TChain(" Events");66 fCini = new TChain("OriginalMC"); 67 67 fCcut = new TChain("Events"); 68 68 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 74 73 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 80 76 fCcut->SetBranchAddress("MHillas.",&fHillas); 81 77 fCcut->SetBranchAddress("MMcEvt.",&fMcEvt); 78 79 // borra 80 fFile = new TFile("test.root","RECREATE"); 82 81 } 83 82 … … 119 118 emin = fEmin; 120 119 emax = fEmax; 120 } 121 else 122 { 123 fEmin = emin; 124 fEmax = emax; 121 125 } 122 126 fSpec = new TF1("fspec",chfunc,emin,emax); … … 147 151 fHorig = new TH1F("fhorig","Original energy spectrum",esbins,logemin,logemax); 148 152 fCini->Draw("logenergy>>fhorig","","goff"); 153 // borra 154 fHorig->Write(); 149 155 } 150 156 … … 169 175 FillOriginalSpectrum(); 170 176 177 // borra 178 TH1F hw("hw","hw",esbins,fEmin,fEmax); 171 179 for(Int_t i=0;i<esbins;i++) 172 180 { … … 181 189 fWeight[i]=-1; 182 190 } 183 } 191 // borra 192 hw.SetBinContent(i+1,fWeight[i]); 193 } 194 // borra 195 hw.Write(); 184 196 } 185 197 … … 207 219 TH2F* hmc = new TH2F("hmc","MC energy",fEbins,logemin,logemax,fNTbins,fTbin); 208 220 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 209 226 // reset the coefficients 210 227 if(fCoeff) … … 220 237 // OJO!! Estimated energy will be taken directly from some input container 221 238 Float_t emc = fMcEvt->GetEnergy(); 222 Float_t estim = fHillas->GetSize()/ 15.;239 Float_t estim = fHillas->GetSize()/0.18/15.; 223 240 Float_t theta = fMcEvt->GetTheta()*180./3.14159; // zenith angle (in degrees) 224 241 … … 231 248 hest->Fill(TMath::Log10(estim),theta,fWeight[wbin]); 232 249 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 } 233 256 } 234 257 else 235 cout << "MEffAreaAndCoeffCalc::ComputeCoefficients Warning: event " << i << " with energy " << emc << " has energy out of bounds, sk pping" << endl;258 cout << "MEffAreaAndCoeffCalc::ComputeCoefficients Warning: event " << i << " with energy " << emc << " has energy out of bounds, skipping" << endl; 236 259 } 237 260 … … 242 265 const Float_t num = hmc->GetBinContent(i+1,j+1); 243 266 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); 244 270 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 } 246 277 else 247 278 { … … 252 283 253 284 285 //borra 286 hmc1->Write(); 287 hest1->Write(); 288 coef1->Write(); 289 254 290 delete hmc; 255 291 delete hest; … … 270 306 //OJO!! radius should be read from somewhere! 271 307 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) 273 310 const Double_t logemin = TMath::Log10(fEmin); 274 311 const Double_t logemax = TMath::Log10(fEmax); 275 312 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) 276 315 277 316 // reset the effective areas 278 317 if(fEffA) 279 318 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 282 323 // fill the spectrum of the survivors 283 324 TH2F* hpass= new TH2F("hpass","Survivors",esbins,logemin,logemax,fNTbins,fTbin); … … 289 330 // compute the effective areas 290 331 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++) 292 333 { 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) 294 352 { 295 353 cout << "MEffAreaAndCoeffCalc::ComputeEffectiveAreas Warning: energy bin " << i <<", theta bin " << j << " contains no events setting effective area to 0" << endl; 296 354 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 } 297 364 } 298 else299 fEffA->SetBinContent(i+1,j+1,Atot*hpass->GetBinContent(i+1,j+1)/horig->GetBinContent(i+1,j+1));300 365 } 301 302 366 367 // borra 368 eff.Write(); 303 369 304 370 delete hpass; -
trunk/MagicSoft/Mars/mtemp/mifae/library/MEffAreaAndCoeffCalc.h
r6368 r6465 18 18 private: 19 19 20 TF1* fSpec; // function used to parametrize dthe spectrum21 TH1F* fHorig; // histogram with the original energy spectrum20 TF1* fSpec; // function used to parametrize the spectrum 21 TH1F* fHorig; // histogram with the original sample energy spectrum 22 22 23 Int_t fEbins; // number of bins to build spectrum24 Int_t fEsubbins; // number of subbins per big bin25 23 Double_t fEmin; // Minimum energy in GeV 26 24 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...) 27 27 28 28 Double_t* fWeight; // array containing weights … … 30 30 TH2F* fEffA; // histogram containing effective areas 31 31 32 TChain* fCini; // chain for initial MC events (even those not triggering)32 TChain* fCini; // chain for initial MC files (before trigger) 33 33 TChain* fCcut; // chain for surviving MC events (after cuts) 34 34 35 35 MHillas* fHillas; // pointer to the MHillas Branch 36 36 MMcEvt* fMcEvt; // pointer to the MMcEvt Branch 37 38 TFile* fFile; // output file (for debugging only) 37 39 38 40 protected: … … 44 46 45 47 public: 48 46 49 MEffAreaAndCoeffCalc(); 47 50 … … 55 58 void SetEmax(Float_t x) {fEmax=x;} 56 59 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);} 59 61 60 62 TH2F* GetEffectiveAreaHisto() {return fEffA;}
Note:
See TracChangeset
for help on using the changeset viewer.