Changeset 6465 for trunk/MagicSoft/Mars/mtemp/mifae
- Timestamp:
- 02/14/05 19:04:58 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mtemp/mifae
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtemp/mifae/Changelog
r6359 r6465 19 19 -*-*- END OF LINE -*-*- 20 20 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 21 28 2005/02/10 Javier Rico 22 29 * library/MEffAreaAndCoeffCalc.[h,cc] -
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;} -
trunk/MagicSoft/Mars/mtemp/mifae/macros/computeCoeff.C
r6368 r6465 4 4 { 5 5 MEffAreaAndCoeffCalc calc; 6 calc.AddFile("/data/star_gamma_test.root"); 6 7 7 // initial MC files8 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 above17 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 spectrum26 calc.SetFunction("4.e9*pow(x,-2.6+1)",10.,10000.);27 calc.ComputeAllFactors();28 29 8 /************************************************/ 30 9 /* Build spectrum */ … … 32 11 /************************************************/ 33 12 const Int_t ebins = 10; // number of bins to build spectrum 34 const Int_t esubbins = 20; // number of subbins per big bin35 13 const Double_t emin=10; 36 const Double_t emax= 1000;14 const Double_t emax=600; 37 15 const Double_t logemin = TMath::Log10(emin); 38 16 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); 42 19 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"}; 53 26 54 27 TChain* ccut = new TChain("Events"); 55 28 for(Int_t i = 0; i < ncutfiles; i++) 56 29 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"); 67 32 68 33 TH1D* hspec = new TH1D("hspec","Spectrum",ebins,logemin,logemax); 69 34 hspec->Sumw2(); 35 ccut->Draw("logestenergy>>hspec","theta<10","goff"); 70 36 71 for(Int_t i=0;i< nentries;i++)37 for(Int_t i=0;i<ebins;i++) 72 38 { 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; 84 43 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 } 87 49 88 50 // SAVE RESULTS
Note:
See TracChangeset
for help on using the changeset viewer.