Changeset 7094 for trunk/MagicSoft/Mars/mjobs
- Timestamp:
- 05/27/05 09:46:22 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mjobs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
r7071 r7094 52 52 #include "MBinning.h" 53 53 #include "MDataSet.h" 54 #include "MMcCorsikaRunHeader.h" 54 55 55 56 // Spectrum … … 58 59 #include "../mhflux/MHCollectionArea.h" 59 60 #include "../mhflux/MHEnergyEst.h" 61 #include "../mhflux/MMcSpectrumWeight.h" 60 62 61 63 // Eventloop … … 155 157 } 156 158 159 // -------------------------------------------------------------------------- 160 // 161 // Read the first MMcCorsikaRunHeader from the RunHeaders tree in 162 // the dataset. 163 // The simulated energy range and spectral slope is initialized from 164 // there. 165 // In the following eventloops the forced check in MMcSpectrumWeight 166 // ensures, that the spectral slope and energy range doesn't change. 167 // 168 Bool_t MJSpectrum::InitWeighting(const MDataSet &set, MMcSpectrumWeight &w) const 169 { 170 fLog->Separator("Initialize energy weighting"); 171 172 MParList l; 173 l.AddToList(&w); 174 if (!CheckEnv(l)) 175 { 176 *fLog << err << "ERROR - Reading resources for MMcSpectrumWeight failed." << endl; 177 return kFALSE; 178 } 179 180 TChain chain("RunHeaders"); 181 set.AddFilesOn(chain); 182 183 MMcCorsikaRunHeader *h=0; 184 chain.SetBranchAddress("MMcCorsikaRunHeader.", &h); 185 chain.GetEntry(1); 186 187 if (!h) 188 { 189 *fLog << err << "ERROR - Couldn't read MMcCorsikaRunHeader from DataSet." << endl; 190 return kFALSE; 191 } 192 193 if (!w.Set(*h)) 194 { 195 *fLog << err << "ERROR - Initializing MMcSpectrumWeight failed." << endl; 196 return kFALSE; 197 } 198 199 w.Print(); 200 return kTRUE; 201 } 202 157 203 Float_t MJSpectrum::ReadInput(MParList &plist, TH1D &h1, TH1D &h2) 158 204 { … … 211 257 } 212 258 213 Bool_t MJSpectrum::ReadOrigMCDistribution(const MDataSet &set, TH1 &h ) const259 Bool_t MJSpectrum::ReadOrigMCDistribution(const MDataSet &set, TH1 &h, MMcSpectrumWeight &weight) const 214 260 { 215 261 // Some debug output 216 262 fLog->Separator("Compiling original MC distribution"); 217 263 218 *fLog << inf << "Please stand by, this may take a while..." << flush; 264 weight.SetNameMcEvt("MMcEvtBasic"); 265 const TString w(weight.GetFormulaWeights()); 266 weight.SetNameMcEvt(); 267 268 *fLog << inf << "Using weights: " << w << endl; 269 *fLog << "Please stand by, this may take a while..." << flush; 219 270 220 271 if (fDisplay) … … 236 287 h.SetYTitle("E [GeV]"); 237 288 h.SetZTitle("Counts"); 238 chain.Draw("MMcEvtBasic.fEnergy:MMcEvtBasic.fTelescopeTheta*TMath::RadToDeg()>>ThetaEMC", "", "goff");289 chain.Draw("MMcEvtBasic.fEnergy:MMcEvtBasic.fTelescopeTheta*TMath::RadToDeg()>>ThetaEMC", w, "goff"); 239 290 } 240 291 else … … 243 294 h.SetXTitle("\\Theta [\\circ]"); 244 295 h.SetYTitle("Counts"); 245 chain.Draw("MMcEvtBasic.fTelescopeTheta*TMath::RadToDeg()>>ThetaMC", "", "goff");296 chain.Draw("MMcEvtBasic.fTelescopeTheta*TMath::RadToDeg()>>ThetaMC", w, "goff"); 246 297 } 247 298 h.SetDirectory(0); … … 413 464 } 414 465 415 Bool_t MJSpectrum::IntermediateLoop(MParList &plist, MH3 &mh1, TH1D &temp1, const MDataSet &set ) const466 Bool_t MJSpectrum::IntermediateLoop(MParList &plist, MH3 &mh1, TH1D &temp1, const MDataSet &set, MMcSpectrumWeight &weight) const 416 467 { 417 468 MTaskList tlist1; … … 439 490 } 440 491 tlist1.AddToList(&readmc); 492 tlist1.AddToList(&weight); 441 493 442 494 temp1.SetXTitle("MMcEvtBasic.fTelescopeTheta*kRad2Deg"); … … 477 529 bins3->SetName("BinningTheta"); 478 530 } 531 479 532 return kTRUE; 480 533 } 481 534 482 voidMJSpectrum::DisplaySpectrum(MHCollectionArea &area, TH1D &excess, MHEnergyEst &hest, Double_t ontime) const535 TArrayD MJSpectrum::DisplaySpectrum(MHCollectionArea &area, TH1D &excess, MHEnergyEst &hest, Double_t ontime) const 483 536 { 484 537 TH1D collarea(area.GetHEnergy()); … … 546 599 f.SetParameter(1, 1.9e-6); 547 600 f.SetLineColor(kGreen); 548 spectrum.Fit(&f, "NI ", "", 55, 2e4);601 spectrum.Fit(&f, "NIM", "", 55, 2e4); 549 602 f.DrawCopy("same"); 550 603 … … 558 611 tex.DrawLatex(2e2, 7e-5, str); 559 612 */ 560 } 561 562 Bool_t MJSpectrum::PlotSame(MStatusArray &arr, MParList &plist, const char *name, const char *tab, const char *plot) const 563 { 564 cout << name << endl; 613 614 TArrayD res(2); 615 res[0] = f.GetParameter(0); 616 res[1] = f.GetParameter(1); 617 return res; 618 } 619 620 Bool_t MJSpectrum::PlotSame(MStatusArray &arr, MParList &plist, const char *name, const char *tab, const char *plot, Double_t scale) const 621 { 565 622 TString same(name); 566 623 same += "Same"; … … 587 644 588 645 const MAlphaFitter *fit = (MAlphaFitter*)plist.FindObject("MAlphaFitter"); 589 const Double_t scale = fit ? fit->GetScaleFactor() : 1;646 const Double_t ascale = fit ? fit->GetScaleFactor() : 1; 590 647 591 648 gPad->SetBorderMode(0); 592 649 h2->SetLineColor(kBlack); 593 650 h3->SetLineColor(kBlue); 594 h2->Add(h1, - scale);595 596 h2->Scale(1./h2->Integral());597 h3->Scale( 1./h3->Integral());651 h2->Add(h1, -ascale); 652 653 //h2->Scale(1./ontime); //h2->Integral()); 654 h3->Scale(scale); //h3->Integral()); 598 655 599 656 h2->SetMaximum(1.05*TMath::Max(h2->GetMaximum(), h3->GetMaximum())); … … 609 666 } 610 667 611 Bool_t MJSpectrum::DisplaySize(MParList &plist ) const668 Bool_t MJSpectrum::DisplaySize(MParList &plist, Double_t scale) const 612 669 { 613 670 *fLog << inf << "Reading from file: " << fPathIn << endl; … … 644 701 645 702 excess->SetTitle("Number of excess events vs Size (data, mc/blue)"); 646 excess->Scale(1./excess->Integral()); 647 excess = excess->DrawCopy(); 703 excess = excess->DrawCopy("E2"); 648 704 // Don't do this on the original object! 649 705 excess->SetStats(kFALSE); 706 excess->SetMarkerStyle(kFullDotMedium); 707 excess->SetFillColor(kBlack); 708 excess->SetFillStyle(0); 709 excess->SetName("Excess "); 710 excess->SetDirectory(0); 650 711 651 712 TObject *o=0; 652 if ((o=plist.FindObject("Excess Size")))713 if ((o=plist.FindObject("ExcessMC"))) 653 714 { 654 715 TH1 *histsel = (TH1F*)o->FindObject(""); 655 716 if (histsel) 656 717 { 657 histsel->Scale(1./histsel->Integral()); 718 if (scale<0) 719 scale = excess->Integral()/histsel->Integral(); 720 721 histsel->Scale(scale); 658 722 histsel->SetLineColor(kBlue); 659 723 histsel->SetBit(kCanDelete); 660 histsel = histsel->DrawCopy(" same");724 histsel = histsel->DrawCopy("E1 same"); 661 725 // Don't do this on the original object! 662 726 histsel->SetStats(kFALSE); 727 728 fLog->Separator("Kolmogorov Test"); 729 histsel->KolmogorovTest(excess, "DX"); 730 fLog->Separator("Chi^2 Test"); 731 histsel->Chi2Test(excess, "P"); 663 732 } 664 733 } … … 666 735 // -------------- Comparison of Image Parameters -------------- 667 736 c.cd(2); 668 PlotSame(arr, plist, "Dist", "HilSrc", "MHHilSrcMCPost" );737 PlotSame(arr, plist, "Dist", "HilSrc", "MHHilSrcMCPost", scale); 669 738 670 739 c.cd(3); 671 PlotSame(arr, plist, "Length", "PostCut", "MHHillasMCPost" );740 PlotSame(arr, plist, "Length", "PostCut", "MHHillasMCPost", scale); 672 741 673 742 c.cd(4); 674 PlotSame(arr, plist, "M3l", "HilExt", "MHHilExtMCPost" );743 PlotSame(arr, plist, "M3l", "HilExt", "MHHilExtMCPost", scale); 675 744 676 745 c.cd(5); 677 PlotSame(arr, plist, "Conc1", "NewPar", "MHNewParMCPost" );746 PlotSame(arr, plist, "Conc1", "NewPar", "MHNewParMCPost", scale); 678 747 679 748 c.cd(6); 680 PlotSame(arr, plist, "Width", "PostCut", "MHHillasMCPost" );749 PlotSame(arr, plist, "Width", "PostCut", "MHHillasMCPost", scale); 681 750 682 751 return kTRUE; … … 734 803 } 735 804 805 MMcSpectrumWeight weight; 806 if (!InitWeighting(set, weight)) 807 return kFALSE; 808 736 809 PrintSetup(fit); 737 810 bins3.SetEdges(temp1, 'x'); 738 811 739 812 TH1D temp2(temp1); 740 if (!ReadOrigMCDistribution(set, temp2 ))813 if (!ReadOrigMCDistribution(set, temp2, weight)) 741 814 return kFALSE; 742 815 … … 754 827 hist.UseCurrentStyle(); 755 828 MH::SetBinning(&hist, &bins3/*temp1.GetXaxis()*/, &bins2/*excess.GetXaxis()*/); 756 if (!ReadOrigMCDistribution(set, hist ))829 if (!ReadOrigMCDistribution(set, hist, weight)) 757 830 return kFALSE; 758 831 … … 762 835 for (int x=0; x<hist.GetNbinsX(); x++) 763 836 hist.SetBinContent(x, y, hist.GetBinContent(x, y)*temp1.GetBinContent(x)); 837 //hist.SetEntries(hist.Integral()); 764 838 } 765 839 } 766 840 else 767 if (!IntermediateLoop(plist, mh1, temp1, set)) 841 { 842 weight.SetNameMcEvt("MMcEvtBasic"); 843 if (!IntermediateLoop(plist, mh1, temp1, set, weight)) 768 844 return kFALSE; 845 weight.SetNameMcEvt(); 846 } 769 847 770 848 DisplayResult(fSimpleMode ? hist : (TH2D&)mh1.GetHist()); … … 813 891 MFillH fill3(&area, "", "FillCollectionArea"); 814 892 MFillH fill4(&hest, "", "FillEnergyEst"); 893 fill3.SetWeight(); 894 fill4.SetWeight(); 815 895 816 896 MH3 hsize("MHillas.fSize"); 817 //MH3 henergy("MEnergyEst.fVal");818 hsize.S etName("ExcessSize");819 //henergy.SetName("EnergyEst"); 820 MBinning bins(size, "BinningExcess Size");897 hsize.SetName("ExcessMC"); 898 hsize.Sumw2(); 899 900 MBinning bins(size, "BinningExcessMC"); 821 901 plist.AddToList(&hsize); 822 //plist.AddToList(&henergy);823 902 plist.AddToList(&bins); 824 903 … … 830 909 MFillH fill6a("MHImgParMCPost [MHImagePar]", "MImagePar", "FillImgParPost"); 831 910 MFillH fill7a("MHNewParMCPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost"); 832 MFillH fill8a("ExcessSize [MH3]", "", "FillExcessSize"); 833 //MFillH fill9a("EnergyEst [MH3]", "", "FillExcessEEst"); 911 MFillH fill8a("ExcessMC [MH3]", "", "FillExcessMC"); 834 912 fill1a.SetNameTab("PreCut"); 835 913 fill2a.SetNameTab("PostCut"); … … 840 918 fill7a.SetNameTab("NewPar"); 841 919 fill8a.SetBit(MFillH::kDoNotDisplay); 842 //fill9a.SetBit(MFillH::kDoNotDisplay); 920 fill1a.SetWeight(); 921 fill2a.SetWeight(); 922 fill3a.SetWeight(); 923 fill4a.SetWeight(); 924 fill5a.SetWeight(); 925 fill6a.SetWeight(); 926 fill7a.SetWeight(); 927 fill8a.SetWeight(); 843 928 844 929 MEnergyEstimate est; … … 852 937 tlist2.AddToList(&hcalc1); 853 938 tlist2.AddToList(&hcalc2); 939 tlist2.AddToList(&weight); 854 940 tlist2.AddToList(&fill1a); 855 941 tlist2.AddToList(fCut0); … … 891 977 // -------------------------- Spectrum ---------------------------- 892 978 893 DisplaySpectrum(area, excess, hest, ontime); 894 DisplaySize(plist); 895 979 // Calculate and display spectrum (N/TeVsm^2 at 1TeV) 980 TArrayD res(DisplaySpectrum(area, excess, hest, ontime)); 981 982 // Spectrum fitted (convert res[1] from TeV to GeV) 983 TF1 flx("flx", Form("%e*pow(x/1000, %f)", res[1]/1000, res[0])); 984 985 // Number of events this spectrum would produce per s and m^2 986 Double_t n = flx.Integral(weight.GetEnergyMin(), weight.GetEnergyMax()); 987 988 // scale with effective collection area to get the event rate (N/s) 989 // scale with the effective observation time to absolute observed events 990 n *= area.GetCollectionAreaAbs()*ontime; // N 991 992 // Now calculate the scale factor from the number of events 993 // produced and the number of events which should have been 994 // observed with our telescope in the time ontime 995 const Double_t scale = n/area.GetEntries(); 996 997 // Print normalization constant 998 cout << "MC normalization factor: " << scale << endl; 999 1000 // Overlay normalized plots 1001 DisplaySize(plist, scale); 1002 1003 // check if output should be written 896 1004 if (!fPathOut.IsNull()) 897 1005 fDisplay->SaveAsRoot(fPathOut); -
trunk/MagicSoft/Mars/mjobs/MJSpectrum.h
r6978 r7094 18 18 class MStatusArray; 19 19 class MHCollectionArea; 20 class MMcSpectrumWeight; 20 21 21 22 class MJSpectrum : public MJob … … 35 36 Bool_t ReadTask(MTask* &task, const char *name) const; 36 37 Float_t ReadInput(MParList &plist, TH1D &h1, TH1D &size); 37 Bool_t ReadOrigMCDistribution(const MDataSet &set, TH1 &h ) const;38 Bool_t ReadOrigMCDistribution(const MDataSet &set, TH1 &h, MMcSpectrumWeight &w) const; 38 39 Bool_t GetThetaDistribution(TH1D &temp1, TH1D &temp2) const; 39 40 Bool_t Refill(MParList &plist, TH1D &h) const; 41 Bool_t InitWeighting(const MDataSet &set, MMcSpectrumWeight &w) const; 40 42 41 43 // Display Output 42 44 void PrintSetup(const MAlphaFitter &fit) const; 43 45 void DisplayResult(const TH2D &mh1) const; 44 Bool_t IntermediateLoop(MParList &plist, MH3 &h1, TH1D &temp1, const MDataSet &set ) const;45 voidDisplaySpectrum(MHCollectionArea &area, TH1D &excess, MHEnergyEst &hest, Double_t ontime) const;46 Bool_t DisplaySize(MParList &plist ) const;47 Bool_t PlotSame(MStatusArray &arr, MParList &plist, const char *name, const char *tab, const char *plot ) const;46 Bool_t IntermediateLoop(MParList &plist, MH3 &h1, TH1D &temp1, const MDataSet &set, MMcSpectrumWeight &w) const; 47 TArrayD DisplaySpectrum(MHCollectionArea &area, TH1D &excess, MHEnergyEst &hest, Double_t ontime) const; 48 Bool_t DisplaySize(MParList &plist, Double_t scale) const; 49 Bool_t PlotSame(MStatusArray &arr, MParList &plist, const char *name, const char *tab, const char *plot, Double_t scale) const; 48 50 49 51 public:
Note:
See TracChangeset
for help on using the changeset viewer.