File indexing completed on 2023-03-17 11:14:52
0001 #include "TFile.h"
0002 #include "TCanvas.h"
0003 #include "TPad.h"
0004 #include "TH1F.h"
0005 #include "TH1D.h"
0006 #include "TLegend.h"
0007
0008 #include "TROOT.h"
0009 #include <map>
0010 #include <iostream>
0011
0012
0013 void getHistograms(const TString canvasName, TH1F * & histo1, TH1D * & histo2, const TString & resonance);
0014
0015
0016
0017
0018
0019
0020 void ShowMassComparison(const TString & resonance = "Z")
0021 {
0022 gROOT->SetBatch(true);
0023 TString canvasName("Allres");
0024 if( resonance == "Psis" || resonance == "Upsilons" || resonance == "LowPtResonances" || resonance == "AllResonances" ) {
0025 canvasName += "Together";
0026 }
0027 TH1F * histo1 = 0;
0028 TH1D * histo2 = 0;
0029 getHistograms(canvasName, histo1, histo2, resonance);
0030
0031 TH1F * histo3 = 0;
0032 TH1D * histo4 = 0;
0033 getHistograms(canvasName+"2", histo3, histo4, resonance);
0034
0035 TString option("width");
0036 double integral = histo1->Integral(option);
0037 histo2->Scale(integral/histo2->Integral(option));
0038 histo3->Scale(integral/histo3->Integral(option));
0039 histo4->Scale(integral/histo4->Integral(option));
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 std::map<double, TH1*, greater<double> > histoMap;
0062 histoMap.insert(make_pair(histo1->GetMaximum(), histo1));
0063 histoMap.insert(make_pair(histo2->GetMaximum(), histo2));
0064 histoMap.insert(make_pair(histo3->GetMaximum(), histo3));
0065 histoMap.insert(make_pair(histo4->GetMaximum(), histo4));
0066
0067 TCanvas * newCanvas = new TCanvas("newCanvas", "newCanvas", 1000, 800);
0068 histo4->SetLineColor(kBlue);
0069
0070 histo4->SetMarkerColor(kBlue);
0071 histo2->SetMarkerColor(kRed);
0072 histo2->SetLineColor(kRed);
0073
0074 histo1->SetLineColor(kBlack);
0075 histo3->SetLineColor(kGreen);
0076
0077 std::map<double, TH1*, greater<double> >::const_iterator it = histoMap.begin();
0078 it->second->Draw();
0079 for( ; it != histoMap.end(); ++it ) it->second->Draw("SAME");
0080
0081 TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
0082 legend->SetTextSize(0.02);
0083 legend->SetFillColor(0);
0084 legend->AddEntry(histo1, "mass before correction");
0085 legend->AddEntry(histo2, "mass prob before correction");
0086 legend->AddEntry(histo3, "mass after correction");
0087 legend->AddEntry(histo4, "mass prob after correction");
0088 legend->Draw("SAME");
0089
0090 TFile * outputFile = new TFile("ShowMassComparison.root", "RECREATE");
0091 newCanvas->Write();
0092 outputFile->Close();
0093 }
0094
0095
0096
0097
0098
0099 void fillMapAndLegend( const TString & canvasName, const TString & resonance, std::map<double, TH1*, greater<double> > & histoMap, TLegend * legend = 0 )
0100 {
0101 TH1F * histo1 = 0;
0102 TH1D * histo2 = 0;
0103 getHistograms(canvasName, histo1, histo2, resonance);
0104 TH1F * histo3 = 0;
0105 TH1D * histo4 = 0;
0106 getHistograms(canvasName+"2", histo3, histo4, resonance);
0107
0108 histo2->Scale(histo1->GetEntries()/histo2->GetEntries());
0109 histo3->Scale(histo1->GetEntries()/histo3->GetEntries());
0110 histo4->Scale(histo1->GetEntries()/histo4->GetEntries());
0111
0112 histoMap.insert(make_pair(histo1->GetMaximum(), histo1));
0113 histoMap.insert(make_pair(histo2->GetMaximum(), histo2));
0114 histoMap.insert(make_pair(histo3->GetMaximum(), histo3));
0115 histoMap.insert(make_pair(histo4->GetMaximum(), histo4));
0116
0117 histo4->SetLineColor(kBlue);
0118 histo4->SetMarkerColor(kBlue);
0119 histo2->SetMarkerColor(kRed);
0120 histo2->SetLineColor(kRed);
0121 histo1->SetLineColor(kBlack);
0122 histo3->SetLineColor(kGreen);
0123
0124 if( legend != 0 ) {
0125 legend->SetTextSize(0.02);
0126 legend->SetFillColor(0);
0127 legend->AddEntry(histo1, "mass before correction");
0128 legend->AddEntry(histo2, "mass prob before correction");
0129 legend->AddEntry(histo3, "mass after correction");
0130 legend->AddEntry(histo4, "mass prob after correction");
0131 }
0132 }
0133
0134 void ShowMassesComparison(const TString & resonance = "Z")
0135 {
0136 TString canvasName("Allres");
0137
0138 std::map<double, TH1*, greater<double> > histoMap;
0139 TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
0140
0141 fillMapAndLegend(canvasName, "Upsilon", histoMap, legend);
0142 fillMapAndLegend(canvasName, "Upsilon2S", histoMap);
0143 fillMapAndLegend(canvasName, "Upsilon3S", histoMap);
0144
0145 TCanvas * newCanvas = new TCanvas("newCanvas", "newCanvas", 1000, 800);
0146 std::cout << "size = " << histoMap.size() << std::endl;
0147 std::map<double, TH1*, greater<double> >::const_iterator it = histoMap.begin();
0148 it->second->Draw();
0149 it->second->SetAxisRange(9,11);
0150 for( ; it != histoMap.end(); ++it ) it->second->Draw("SAME");
0151 legend->Draw("SAME");
0152
0153 TFile * outputFile = new TFile("ShowMassComparison.root", "RECREATE");
0154 newCanvas->Write();
0155 outputFile->Close();
0156 }
0157
0158
0159
0160
0161
0162
0163 void getHistograms(const TString canvasName, TH1F * & histo1, TH1D * & histo2, const TString & resonance)
0164 {
0165 std::cout << "canvasName = " << canvasName << std::endl;
0166 TFile * inputFile = new TFile("plotMassOutput.root");
0167 TCanvas * canvas = (TCanvas*)inputFile->Get(canvasName);
0168 TString resonanceNum("_1");
0169 if( resonance == "Upsilon3S" ) resonanceNum = "_2";
0170 if( resonance == "Upsilon2S" ) resonanceNum = "_3";
0171 if( resonance == "Upsilon" ) resonanceNum = "_4";
0172 if( resonance == "Psi2S" ) resonanceNum = "_5";
0173 if( resonance == "JPsi" ) resonanceNum = "_6";
0174
0175 if( resonance == "Psis" ) resonanceNum = "_1";
0176 if( resonance == "Upsilons" ) resonanceNum = "_2";
0177 if( resonance == "LowPtResonances" ) resonanceNum = "_3";
0178 if( resonance == "AllResonances" ) resonanceNum = "_4";
0179
0180 TPad * pad = (TPad*)canvas->GetPrimitive(canvasName+resonanceNum);
0181 histo1 = (TH1F*)pad->GetPrimitive("hRecBestResAllEvents_Mass");
0182 if( resonance == "Z" || resonance == "AllResonances" ) histo2 = (TH1D*)pad->GetPrimitive("Mass_PProf");
0183 else histo2 = (TH1D*)pad->GetPrimitive("Mass_fine_PProf");
0184
0185
0186
0187
0188
0189 }
0190