46 if (argc < 5 || argc > 7)
48 std::cout <<
"USAGE: " <<
argv[0] <<
" <JetCollection> <ConfigFile> <OutputFile> <isData> (dev mode switch) (timing test switch)" << std::endl;
53 const TString jetAlgo =
argv[1];
56 const bool isData = (TString(
argv[4]) ==
"true");
57 const bool isDevMode =
argc > 5 && (TString(
argv[5]) ==
"true" || TString(
argv[5]) ==
"dev");
58 const bool isTimeTest =
argc > 6 && TString(
argv[6]) ==
"true";
61 const bool outFileIsExtensible =
outFile.EndsWith(
".pdf") ||
outFile.EndsWith(
".ps");
62 const bool outFileIsRoot =
outFile.EndsWith(
".root");
65 const TString calibSeq =
"Smear";
66 const std::vector<float> ptVals = {20, 40, 60, 100, 400, 1000};
67 const float eta = 0.202;
69 const float mass = 10;
70 const int maxNumIter = 1e5;
71 const int numTimeIter = 100;
74 const TString startingScaleString =
"JetGSCScaleMomentum";
75 const TString endingScaleString =
"JetSmearedMomentum";
87 std::cout <<
"Failed to make ana tool" << std::endl;
90 if (calibTool.
setProperty(
"JetCollection",jetAlgo.Data()).isFailure())
92 std::cout <<
"Failed to set JetCollection: " << jetAlgo.Data() << std::endl;
97 std::cout <<
"Failed to set ConfigFile: " <<
config.Data() << std::endl;
100 if (calibTool.
setProperty(
"CalibSequence",calibSeq.Data()).isFailure())
102 std::cout <<
"Failed to set CalibSequence: " << calibSeq.Data() << std::endl;
105 if (calibTool.
setProperty(
"IsData",isData).isFailure())
107 std::cout <<
"Failed to set IsData: " << (isData ? std::string(
"true") : std::string(
"false")) << std::endl;
110 if (isDevMode && calibTool.
setProperty(
"DEVmode",isDevMode).isFailure())
112 std::cout <<
"Failed to set DEVmode" << std::endl;
115 if (calibTool.
retrieve().isFailure())
117 std::cout <<
"Failed to initialize the JetCalibTool" << std::endl;
133 std::vector<TH1D*> hists_pt;
134 std::vector<TH1D*> hists_m;
135 for (
float pt : ptVals)
137 const TString baseName = Form(
"Smear_%.0f",
pt);
138 hists_pt.push_back(
new TH1D(baseName+
"_pT",baseName+
"_pT",100,0.25*
pt,1.75*
pt));
139 hists_m.push_back(
new TH1D(baseName+
"_mass",baseName+
"_mass",100,0.25*
mass,1.75*
mass));
148 for (
int numTest = 0; numTest < numTimeIter; ++numTest)
152 if (jetCalibTool->setProperty(
"JetCollection",jetAlgo.Data()).isFailure())
154 if (jetCalibTool->setProperty(
"ConfigFile",
config.Data()).isFailure())
156 if (jetCalibTool->setProperty(
"CalibSequence",calibSeq.Data()).isFailure())
158 if (jetCalibTool->setProperty(
"IsData",isData).isFailure())
160 if (isDevMode && jetCalibTool->setProperty(
"DEVmode",isDevMode).isFailure())
166 for (
int numIter = 0; numIter < maxNumIter; ++numIter)
169 jet->setJetP4(fourvec);
172 if(jetCalibTool->
modify(*jets).isFailure())
176 printf(
"Iteration %d: %f seconds\n",numTest+1,(clock()-
startTime)/((
double)CLOCKS_PER_SEC));
184 const float pt = ptVals.at(
index);
185 TH1D* hist_pt = hists_pt.at(
index);
186 TH1D* hist_m = hists_m.at(
index);
191 printf(
"Running for pT of %.0f\n",
pt);
193 for (
int numIter = 0; numIter < maxNumIter; ++numIter)
197 jet->setJetP4(fourvec);
201 if(calibTool->
modify(*jets).isFailure())
205 if (fabs(endingScale(*jet).pt() -
jet->pt()) > 1.e-3)
207 printf(
"ERROR: mismatch between ending scale (%.3f) and jet pT (%.3f)\n",endingScale(*jet).pt(),
jet->pt());
210 if (endingScale(*jet).pt() == startingScale(*jet).pt())
213 printf(
"WARNING: starting and ending scales are identical: %.3f\n",endingScale(*jet).pt());
217 hist_pt->Fill(
jet->pt()/1.e3);
218 hist_m->Fill(
jet->m()/1.e3);
224 printf(
"Getting nominal resolutions\n");
225 TH1D nominalResData(
"NominalResData",
"NominalResData",1000,20,2020);
226 TH1D nominalResMC(
"NominalResMC",
"NominalResMC", 1000,20,2020);
227 for (Long64_t
binX = 1;
binX < nominalResData.GetNbinsX()+1; ++
binX)
230 const float pt = nominalResData.GetXaxis()->GetBinCenter(
binX);
232 jet->setJetP4(fourvec);
238 printf(
"ERROR: Failed to get nominal data resolution\n");
244 printf(
"ERROR: Failed to get nominal MC resolution\n");
253 TCanvas*
canvas =
new TCanvas(
"canvas");
254 canvas->SetMargin(0.07,0.13,0.1,0.10);
255 canvas->SetFillStyle(4000);
257 canvas->SetFrameBorderMode(0);
261 std::vector<TF1*> fits_pt;
262 std::vector<TF1*> fits_m;
265 TH1D* hist_pt = hists_pt.at(
index);
266 TH1D* hist_m = hists_m.at(
index);
268 TF1* fit_pt =
new TF1(Form(
"fitPt_%zu",
index),
"gaus");
269 TF1* fit_m =
new TF1(Form(
"fitMass_%zu",
index),
"gaus");
271 hist_pt->Fit(fit_pt,
"E");
272 hist_m->Fit(fit_m,
"E");
274 fits_pt.push_back(fit_pt);
275 fits_m.push_back(fit_m);
279 for (TH1D*
hist : hists_pt)
281 hist->SetStats(
false);
282 hist->GetXaxis()->SetTitle(
"Jet #it{p}_{T} [GeV]");
283 hist->GetXaxis()->SetTitleOffset(1.35);
284 hist->GetYaxis()->SetTitle(
"Number of events");
285 hist->GetYaxis()->SetTitleOffset(0.9);
287 for (TH1D*
hist : hists_m)
289 hist->SetStats(
false);
290 hist->GetXaxis()->SetTitle(
"Jet mass [GeV]");
291 hist->GetXaxis()->SetTitleOffset(1.35);
292 hist->GetYaxis()->SetTitle(
"Number of events");
293 hist->GetYaxis()->SetTitleOffset(0.9);
300 tex.SetTextSize(0.04);
303 if (outFileIsExtensible)
309 nominalResData.Draw();
318 hists_pt.at(
index)->Draw(
"pe");
319 tex.DrawLatex(0.70,0.9,
"Gaussian fit results");
320 tex.DrawLatex(0.70,0.85,Form(
"#mu = %.0f GeV",fits_pt.at(
index)->GetParameter(1)));
321 tex.DrawLatex(0.70,0.80,Form(
"#sigma = %.1f GeV",fits_pt.at(
index)->GetParameter(2)));
322 tex.DrawLatex(0.70,0.75,Form(
"#mu/#sigma = %.1f%%",fits_pt.at(
index)->GetParameter(2)/fits_pt.at(
index)->GetParameter(1)*100));
325 hists_m.at(
index)->Draw(
"pe");
326 tex.DrawLatex(0.70,0.9,
"Gaussian fit results");
327 tex.DrawLatex(0.70,0.85,Form(
"#mu = %.0f GeV",fits_m.at(
index)->GetParameter(1)));
328 tex.DrawLatex(0.70,0.80,Form(
"#sigma = %.1f GeV",fits_m.at(
index)->GetParameter(2)));
329 tex.DrawLatex(0.70,0.75,Form(
"#mu/#sigma = %.1f%%",fits_m.at(
index)->GetParameter(2)/fits_m.at(
index)->GetParameter(1)*100));
334 else if (outFileIsRoot)
337 std::cout <<
"Writing to output ROOT file: " <<
outFile << std::endl;
341 nominalResData.Write();
342 nominalResMC.Write();
347 hists_pt.at(
index)->Write();
348 hists_m.at(
index)->Write();
358 nominalResData.Draw();
367 hists_pt.at(
index)->Draw(
"pe");
370 hists_m.at(
index)->Draw(
"pe");