Changeset 8882 for trunk/MagicSoft/Mars/mjobs
- Timestamp:
- 03/18/08 17:41:53 (17 years ago)
- Location:
- trunk/MagicSoft/Mars/mjobs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
r8750 r8882 38 38 #include <TLine.h> 39 39 #include <TFile.h> 40 #include <TGraph.h> 40 41 #include <TChain.h> 41 42 #include <TLatex.h> … … 56 57 #include "MHn.h" 57 58 #include "MBinning.h" 59 #include "MParameters.h" 58 60 #include "MDataSet.h" 59 61 #include "MMcCorsikaRunHeader.h" … … 79 81 #include "MFDataMember.h" 80 82 #include "MContinue.h" 83 #include "MWriteRootFile.h" 81 84 82 85 ClassImp(MJSpectrum); … … 239 242 } 240 243 241 TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta", "TH1D", "OnTime"); 242 TH1D *size = (TH1D*)arr.FindObjectInCanvas("Excess", "TH1D", "Hist"); 243 if (!vstime || !size) 244 TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta", "TH1D", "OnTime"); 245 TH1D *size = (TH1D*)arr.FindObjectInCanvas("Excess", "TH1D", "Hist"); 246 TH1D *time = (TH1D*)arr.FindObjectInCanvas("ExcessTime", "TH1D", "Hist"); 247 if (!vstime || !size || !time) 244 248 return -1; 245 249 … … 280 284 return -1; 281 285 282 return vstime->Integral(); 286 if (vstime->GetBinContent(0)>0) 287 { 288 *fLog << err << "ERROR - Undeflow bin of OnTime histogram not empty as it ought to be." << endl; 289 return -1; 290 } 291 292 const Double_t ofl = vstime->GetBinContent(vstime->GetNbinsX()); 293 const Double_t eff = vstime->Integral()+ofl; 294 if (ofl>0) 295 *fLog << warn << "WARNING - " << Form("%.1f%% (%.0fs)", 100*ofl/eff, ofl) << " of the eff. observation time is out of histogram range." << endl; 296 297 const Double_t obs = time->GetXaxis()->GetXmax()-time->GetXaxis()->GetXmin(); 298 if (fForceRunTime) 299 { 300 *fLog << inf; 301 *fLog << "Total run time: " << obs/60 << "min" << endl; 302 *fLog << "Eff. obs. time: " << eff/60 << "min (" << Form("%.1f%%", 100*eff/obs) << ")" << endl; 303 } 304 305 return fForceRunTime ? obs : eff; 283 306 } 284 307 … … 479 502 // ----- Complete incomplete energy ranges ----- 480 503 // ----- and apply production area weights ----- 481 weight.CompleteEnergySpectrum(*hfill, Emin); 482 483 hfill->Scale(scale*scale); 504 weight.CompleteEnergySpectrum(*hfill, Emin, scale*scale); 484 505 485 506 // Add weighted data from file to final histogram … … 537 558 // Calculate the Probability 538 559 temp1.Divide(&temp2); 539 temp1.Scale(1./temp1.Integral( ));560 temp1.Scale(1./temp1.Integral(1, temp1.GetNbinsX())); 540 561 541 562 // Some cosmetics: Name, Axis, etc. … … 849 870 { 850 871 const TString fmt0 = Form("(%%%sf#pm%%%sf)\\bullet10^{%%d}", f1, f1); 851 const TString fmt1 = Form("(\\frac{E}{ TeV})^{%%%sf#pm%%%sf}", f0, f0);872 const TString fmt1 = Form("(\\frac{E}{500GeV})^{%%%sf#pm%%%sf}", f0, f0); 852 873 853 874 str = Form(fmt0.Data(), p1/exp, e1/exp, np); … … 966 987 spectrum.SetBit(TH1::kNoStats); 967 988 968 for (int i=0; i<excess.GetNbinsX(); i++) 969 { 970 spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)*weights.GetBinContent(i+1)); 971 spectrum.SetBinError(i+1, spectrum.GetBinError(i+1) *weights.GetBinContent(i+1)); 972 973 spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)/spectrum.GetBinWidth(i+1)*1000); 974 spectrum.SetBinError(i+1, spectrum.GetBinError(i+1)/ spectrum.GetBinWidth(i+1)*1000); 975 } 989 // Minimum number of excessevents to get 3sigma in 1h 990 TF1 sensl("SensLZA", "85*(x/200)^(-0.55)", 100, 6000); 991 TF1 sensh("SensHZA", "35*(x/200)^(-0.70)", 100, 1000); 992 //sens.SetLineColor(kBlue); 993 //sens.DrawClone("Csame"); 976 994 977 995 c1.cd(4); … … 981 999 gPad->SetGridx(); 982 1000 gPad->SetGridy(); 1001 1002 TGraph gsensl;//("Sensitivity LZA", ""); 1003 TGraph gsensh;//("Sensitivity HZA", ""); 1004 1005 const Double_t sqrton = TMath::Sqrt(ontime/3600.); 1006 1007 for (int i=0; i<excess.GetNbinsX(); i++) 1008 { 1009 spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)*weights.GetBinContent(i+1)); 1010 spectrum.SetBinError(i+1, spectrum.GetBinError(i+1) *weights.GetBinContent(i+1)); 1011 1012 spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)/spectrum.GetBinWidth(i+1)*1000); 1013 spectrum.SetBinError(i+1, spectrum.GetBinError(i+1)/ spectrum.GetBinWidth(i+1)*1000); 1014 1015 if (collarea.GetBinContent(i+1)<=0) 1016 continue; 1017 1018 const Double_t cen = spectrum.GetBinCenter(i+1); 1019 gsensl.SetPoint(gsensl.GetN(), cen, sensl.Eval(cen)*sqrton/spectrum.GetBinWidth(i+1)*1000/collarea.GetBinContent(i+1)/ontime); 1020 gsensh.SetPoint(gsensh.GetN(), cen, sensh.Eval(cen)*sqrton/spectrum.GetBinWidth(i+1)*1000/collarea.GetBinContent(i+1)/ontime); 1021 1022 cout << cen << " " << sensl.Eval(cen)*sqrton/spectrum.GetBinWidth(i+1)*1000/collarea.GetBinContent(i+1)/ontime; 1023 cout << " " << sensh.Eval(cen)*sqrton/spectrum.GetBinWidth(i+1)*1000/collarea.GetBinContent(i+1)/ontime; 1024 cout << endl; 1025 } 1026 983 1027 spectrum.SetMinimum(1e-12); 984 1028 spectrum.SetXTitle("E [GeV]"); … … 987 1031 988 1032 TLatex tex; 1033 tex.SetTextColor(13); 989 1034 990 1035 TF1 fc("Crab", "7.0e-6*(x/300)^(-2.31-0.26*log10(x/300))", 100, 6000); 991 fc.SetLineStyle( 7);1036 fc.SetLineStyle(9); 992 1037 fc.SetLineWidth(2); 993 1038 fc.SetLineColor(14); 994 1039 fc.DrawCopy("same"); 995 1040 996 tex.Draw Text(90, fc.Eval(100), "Crab (\\Gamma=-2.31)");1041 tex.DrawLatex(1250, fc.Eval(1250), "Crab/\\Gamma=-2.3"); 997 1042 998 1043 TF1 fa("PG1553", "1.8e-6*(x/200)^-4.21", 90, 600); … … 1000 1045 fa.DrawCopy("same"); 1001 1046 1002 tex.DrawText(90, fa.Eval(90), "PG1553 (\\Gamma=-4.21)"); 1047 tex.SetTextAlign(23); 1048 tex.DrawLatex(600, fa.Eval(600), "PG1553/\\Gamma=-4.2"); 1049 1050 gROOT->SetSelectedPad(0); 1051 1052 gsensl.SetLineStyle(5); 1053 gsensl.SetLineColor(14); 1054 gsensl.SetLineWidth(2); 1055 gsensl.DrawClone("C")->SetBit(kCanDelete); 1056 1057 gsensh.SetLineStyle(5); 1058 gsensh.SetLineColor(14); 1059 gsensh.SetLineWidth(2); 1060 gsensh.DrawClone("C")->SetBit(kCanDelete); 1003 1061 1004 1062 // Display dN/dE*E^2 for conveinience … … 1015 1073 spectrum.SetBinContent(i+1, spectrum.GetBinContent(i+1)*e*e); 1016 1074 spectrum.SetBinError( i+1, spectrum.GetBinError(i+1) *e*e); 1075 } 1076 1077 for (int i=0; i<gsensl.GetN(); i++) 1078 { 1079 const Double_t e = gsensl.GetX()[i]*1e-3; 1080 1081 gsensl.GetY()[i] *= e*e; 1082 gsensh.GetY()[i] *= e*e; 1017 1083 } 1018 1084 … … 1031 1097 static_cast<const TAttLine&>(fc).Copy(fa2); 1032 1098 fa2.DrawCopy("same"); 1099 1100 gsensl.DrawClone("C")->SetBit(kCanDelete); 1101 gsensh.DrawClone("C")->SetBit(kCanDelete); 1033 1102 1034 1103 // Fit Spectrum … … 1317 1386 hist.InitTitle(";Slope;Disp-Dist [\\circ];"); 1318 1387 hist.SetDrawOption("colz profx"); 1388 } 1389 1390 // -------------------------------------------------------------------------- 1391 // 1392 // Setup write to write: 1393 // container tree optional? 1394 // -------------- ---------- ----------- 1395 // "MHillas" to "Events" 1396 // "MHillasSrc" to "Events" 1397 // "Hadronness" to "Events" yes 1398 // "MEnergyEst" to "Events" yes 1399 // "DataType" to "Events" 1400 // 1401 void MJSpectrum::SetupWriter(MWriteRootFile *write/*, const char *name*/) const 1402 { 1403 if (!write) 1404 return; 1405 1406 //write->SetName(name); 1407 write->AddContainer("MHillas", "Events"); 1408 write->AddContainer("MHillasSrc", "Events"); 1409 write->AddContainer("MHillasExt", "Events"); 1410 //write->AddContainer("MPointingPos", "Events"); 1411 write->AddContainer("MHillasSrcAnti", "Events", kFALSE); 1412 write->AddContainer("MImagePar", "Events", kFALSE); 1413 write->AddContainer("MNewImagePar", "Events", kFALSE); 1414 write->AddContainer("MNewImagePar2", "Events", kFALSE); 1415 write->AddContainer("Hadronness", "Events", kFALSE); 1416 write->AddContainer("MSrcPosCam", "Events", kFALSE); 1417 write->AddContainer("MSrcPosAnti", "Events", kFALSE); 1418 write->AddContainer("ThetaSquared", "Events", kFALSE); 1419 write->AddContainer("OpticalAxis", "Events", kFALSE); 1420 write->AddContainer("Disp", "Events", kFALSE); 1421 write->AddContainer("Ghostbuster", "Events", kFALSE); 1422 write->AddContainer("MEnergyEst", "Events", kFALSE); 1423 write->AddContainer("MTime", "Events", kFALSE); 1424 write->AddContainer("MMcEvt", "Events", kFALSE); 1425 write->AddContainer("MWeight", "Events"); 1426 write->AddContainer("DataType", "Events"); 1427 write->AddContainer("RunNumber", "Events"); 1428 write->AddContainer("EvtNumber", "Events"); 1319 1429 } 1320 1430 … … 1598 1708 taskenv2.SetDefault(fEstimateEnergy ? fEstimateEnergy : &est); 1599 1709 1710 MWriteRootFile write(GetPathOut()); 1711 SetupWriter(&write); 1712 1713 MParameterI par("DataType"); 1714 plist.AddToList(&par); 1715 par.SetVal(2); 1716 1600 1717 tlist2.AddToList(&read); 1601 1718 // If no weighting should be applied but the events should … … 1621 1738 tlist2.AddToList(fCut3); 1622 1739 tlist2.AddToList(&taskenv2); 1740 if (!GetPathOut().IsNull()) 1741 tlist2.AddToList(&write); 1623 1742 tlist2.AddToList(&fill31); 1624 1743 tlist2.AddToList(&fill4); … … 1670 1789 1671 1790 // Spectrum fitted (convert res[1] from TeV to GeV) 1672 TF1 flx("flx", Form("%e*pow(x/ 1000, %f)", res[1]/1000, res[0]));1791 TF1 flx("flx", Form("%e*pow(x/500, %f)", res[1]/500, res[0])); 1673 1792 1674 1793 // Number of events this spectrum would produce per s and m^2 … … 1701 1820 cont.Add((TObject*)GetEnv()); // const_cast 1702 1821 cont.Add((TObject*)&set); // const_cast 1822 cont.Add(plist.FindObject("MAlphaFitter")); 1703 1823 cont.Add(&area0); 1704 1824 cont.Add(&area1); … … 1708 1828 cont.Add(fDisplay); 1709 1829 1710 if (!WriteContainer(cont, "", "RECREATE"))1830 if (!WriteContainer(cont, "", GetPathOut().IsNull()?"RECREATE":"UPDATE")) 1711 1831 { 1712 1832 *fLog << err << GetDescriptor() << ": Writing result failed." << endl; -
trunk/MagicSoft/Mars/mjobs/MJSpectrum.h
r8709 r8882 19 19 class MAlphaFitter; 20 20 class MStatusArray; 21 class MWriteRootFile; 21 22 class MHCollectionArea; 22 23 class MMcSpectrumWeight; … … 36 37 37 38 Bool_t fForceTheta; 39 Bool_t fForceRunTime; 38 40 39 41 // Setup Histograms … … 50 52 Bool_t Refill(MParList &plist, TH1D &h) /*const*/; 51 53 Bool_t InitWeighting(const MDataSet &set, MMcSpectrumWeight &w) const; 54 55 // Write output 56 void SetupWriter(MWriteRootFile *write/*, const char *name*/) const; 52 57 53 58 // Display Output … … 67 72 Bool_t Process(const MDataSet &set); 68 73 69 void ForceTheta(Bool_t b=kTRUE) { fForceTheta=b; } 74 void ForceTheta(Bool_t b=kTRUE) { fForceTheta=b; } 75 void ForceRunTime(Bool_t b=kTRUE) { fForceRunTime=b; } 70 76 71 77 void SetEnergyEstimator(const MTask *task); -
trunk/MagicSoft/Mars/mjobs/MJob.cc
r8719 r8882 431 431 title += fName; 432 432 433 // In case the update-option is selected check whether 434 // the file is already open 435 if (TString(option).Contains("update", TString::kIgnoreCase)) 436 { 437 TFile *file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(oname)); 438 if (file && file->IsOpen() && !file->IsZombie()) 439 { 440 *fLog << inf << "Open file found." << endl; 441 file->cd(); 442 return WriteContainer(cont); 443 } 444 } 445 446 // Open a new file with the defined option for writing 433 447 TFile file(oname, option, title, compr); 434 if (!file.IsOpen() )448 if (!file.IsOpen() || file.IsZombie()) 435 449 { 436 450 *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
Note:
See TracChangeset
for help on using the changeset viewer.