23 #include "TGraphAsymmErrors.h" 37 TF1 *
linposfit =
new TF1(
"linposfit",
"[0]+[1]*x", 0., 15.);
50 hist->SetTitle(
"Active Region Only");
51 hist->GetXaxis()->SetTitle(
"Reco Muon Track Length (m)");
52 hist->GetYaxis()->SetTitle(
"True Muon Energy (GeV)");
56 hist->SetTitle(
"Muons Entering Catcher");
57 hist->GetXaxis()->SetTitle(
"Reco Muon Track Length in Active (m)");
58 hist->GetYaxis()->SetTitle(
"True Active Region Muon Energy (GeV)");
59 hist->GetYaxis()->SetTitleSize(0.048);
62 hist->SetTitle(
"Muons Entering Catcher");
63 hist->GetXaxis()->SetTitle(
"Reco Muon Track Length in Catcher (m)");
64 hist->GetYaxis()->SetTitle(
"True Catcher Region Muon Energy (GeV)");
67 throw std::runtime_error(
"Invalid fit mode");
71 hist->GetZaxis()->SetTitle(zaxisname.c_str());
72 static const int nn = 150;
80 for(
int iw = 1; iw <= hist->GetNbinsX(); ++iw){
82 TH1D* py = hist->ProjectionY(
"py",iw,iw,
"");
83 int maxbin = py->GetMaximumBin();
84 double maxcont = py->GetBinContent(maxbin);
86 if (maxcont == 0){
continue; }
88 double totalEntries = py->GetEntries();
89 if (totalEntries < 30){
continue; }
91 double modex = py->GetBinCenter(maxbin);
94 int yyhighbin = maxbin+1;
95 int yylowbin = maxbin-1;
98 for(
int ihigh = maxbin+1; ihigh <= nn; ++ihigh){
100 if(py->GetBinContent(yyhighbin) <= maxcont/2.0){
break; }
104 for(
int ilow = maxbin-1; ilow > 0; --ilow){
106 if(py->GetBinContent(yylowbin) <= maxcont/2.0){
break; }
109 float multiplier = 1.5;
110 int veryHighBin = (yyhighbin - maxbin)*multiplier+maxbin;
111 int veryLowBin = maxbin - multiplier*(maxbin-yylowbin);
113 double lowSide = modex-multiplier*(modex-py->GetBinCenter(yylowbin));
114 double highSide = multiplier*(py->GetBinCenter(yyhighbin)-modex)+modex;
116 xxx[iw-1] = (hist->GetXaxis()->GetBinCenter(iw));
118 TF1 *
f1 =
new TF1(
"customGaus",
"gaus",0,5);
119 py->Fit(
"customGaus",
"OQ",
"",lowSide,highSide);
120 double mean = f1->GetParameter(1);
121 double error = f1->GetParError(1);
122 double chi = f1->GetChisquare();
123 double ndf = f1->GetNDF();
141 TGraphAsymmErrors* customProfile =
new TGraphAsymmErrors(nn,xxx,yyx,exxl,exxh,eyxl,eyxh);
143 customProfile->GetXaxis()->SetNoExponent(kTRUE);
144 customProfile->GetXaxis()->CenterTitle();
145 customProfile->GetYaxis()->CenterTitle();
148 customProfile->GetXaxis()->SetTitle(
"Reco Muon Track Length (m)");
149 customProfile->GetYaxis()->SetTitle(
"True Muon Energy (GeV)");
150 customProfile->GetXaxis()->SetLimits(0,15);
151 customProfile->GetHistogram()->SetMaximum(5);
152 customProfile->GetHistogram()->SetMinimum(0);
157 customProfile->GetXaxis()->SetTitle(
"Reco Muon Track Length (m)");
158 customProfile->GetYaxis()->SetTitle(
"True Muon E - True Muon E in Catcher (GeV)");
159 customProfile->GetXaxis()->SetLimits(0,15);
160 customProfile->GetHistogram()->SetMaximum(5);
161 customProfile->GetHistogram()->SetMinimum(0);
164 customProfile->GetYaxis()->SetTitleSize(0.048);
167 customProfile->GetXaxis()->SetTitle(
"Reco Muon Track Length in Catcher (m)");
168 customProfile->GetYaxis()->SetTitle(
"True Muon Energy in Catcher (GeV)");
169 customProfile->GetXaxis()->SetLimits(0,3);
170 customProfile->GetHistogram()->SetMaximum(3);
171 customProfile->GetHistogram()->SetMinimum(0);
176 throw std::runtime_error(
"Invalid fit mode");
180 customProfile->SetTitle(
"");
183 TCanvas*
c1 =
new TCanvas(
"c1",
"c1");
184 customProfile->SetMarkerColor(18);
185 customProfile->SetLineColor(18);
187 customProfile->Draw(
"P");
190 c1->SetRightMargin(0.15);
191 c1->SetLeftMargin(0.15);
194 c1->SaveAs((
outDir+
"/muon_" + label +
".png").c_str());
195 c1->SaveAs((
outDir+
"/muon_" + label +
".pdf").c_str());
199 TCanvas*
c2 =
new TCanvas(
"c2",
"c2");
201 customProfile->SetMarkerColor(13);
202 customProfile->SetLineColor(13);
204 customProfile->Draw(
"P");
207 c2->SetRightMargin(0.15);
208 c2->SetLeftMargin(0.15);
210 c2->SaveAs((
outDir+
"/muon_logz" + label +
".png").c_str());
211 c2->SaveAs((
outDir+
"/muon_logz" + label +
".pdf").c_str());
215 TCanvas*
c3 =
new TCanvas(
"c3",
"c3");
216 customProfile->SetMarkerColor(1);
217 customProfile->SetLineColor(1);
218 customProfile->Draw(
"AP");
220 c3->SetRightMargin(0.15);
223 customProfile->Fit(
"pol3",
"",
"",0.2, 12.0);
227 customProfile->Fit(
"pol3",
"",
"",3.75, 12.2);
231 customProfile->Fit(
"pol1",
"",
"",0.02, 2.3);
235 throw std::runtime_error(
"Invalid fit mode");
238 c3->SetLeftMargin(0.15);
241 c3->SaveAs((
outDir+
"/fit_" + label +
".png").c_str());
242 c3->SaveAs((
outDir+
"/fit_" + label +
".pdf").c_str());
248 TFile *
fin = TFile::Open(infile.c_str(),
"READ");
263 MuonFit(MuonE_hist_act, Form(
"Events/(%2.2E POT)",pot),
266 MuonFit(MuonE_hist_actAndCat, Form(
"Events/(%2.2E POT)",pot),
269 MuonFit(MuonE_hist_cat, Form(
"Events/(%2.2E POT)",pot),
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Cuts and Vars for the 2020 FD DiF Study.
void CenterTitles(TH1 *histo)
Representation of a spectrum in any variable, with associated POT.
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
void MuonFit(Spectrum *plot1, string zaxisname, string label, MuonFitMode fitmode, string outDir="")
void plot_estimate_energy(string infile, string outputDir=".")