28 #include "TPaveText.h" 36 #include <boost/filesystem.hpp> 37 #include <boost/property_tree/ptree.hpp> 38 #include <boost/property_tree/json_parser.hpp> 39 #include <boost/range/adaptor/indexed.hpp> 47 namespace pt = boost::property_tree;
50 plot->GetXaxis()->CenterTitle(
true);
51 plot->GetYaxis()->CenterTitle(
true);
52 plot->GetXaxis()->SetTitleFont(42);
53 plot->GetYaxis()->SetTitleFont(42);
54 plot->GetXaxis()->SetTitleSize(0.05);
55 plot->GetYaxis()->SetTitleSize(0.05);
56 plot->GetXaxis()->SetTitleOffset(0.9);
57 plot->GetYaxis()->SetTitleOffset(1.3);
58 plot->GetXaxis()->SetLabelFont(42);
59 plot->GetYaxis()->SetLabelFont(42);
60 plot->GetYaxis()->SetLabelSize(.05);
61 plot->GetXaxis()->SetLabelSize(.05);
65 RooRealVar
MuMu_mass(
"MuMu_mass",
"MuMu_mass", 70, 110);
66 static TString
GT =
"";
67 TLatex*
tlxg =
new TLatex();
82 double xMean = 91.1876;
83 double xMin = th1d_input->GetXaxis()->GetXmin();
84 double xMax = th1d_input->GetXaxis()->GetXmax();
92 double sigma2Max(10.);
94 std::unique_ptr<FitWithRooFit> fitter = std::make_unique<FitWithRooFit>();
98 fitter->useChi2_ = useChi2;
100 fitter->initSigma(sigma, sigmaMin, sigmaMax);
101 fitter->initSigma2(sigma2, sigma2Min, sigma2Max);
102 fitter->initAlpha(1.5, 0.05, 10.);
103 fitter->initN(1, 0.01, 100.);
104 fitter->initFGCB(0.4, 0., 1.);
105 fitter->initGamma(2.4952, 0., 10.);
106 fitter->gamma()->setConstant(kTRUE);
107 fitter->initMean2(0., -20., 20.);
108 fitter->mean2()->setConstant(kTRUE);
109 fitter->initSigma(1.2, 0., 5.);
110 fitter->initAlpha(1.5, 0.05, 10.);
111 fitter->initN(1, 0.01, 100.);
112 fitter->initExpCoeffA0(-1., -10., 10.);
113 fitter->initExpCoeffA1(0., -10., 10.);
114 fitter->initExpCoeffA2(0., -2., 2.);
115 fitter->initFsig(0.9, 0., 1.);
116 fitter->initA0(0., -10., 10.);
117 fitter->initA1(0., -10., 10.);
118 fitter->initA2(0., -10., 10.);
119 fitter->initA3(0., -10., 10.);
120 fitter->initA4(0., -10., 10.);
121 fitter->initA5(0., -10., 10.);
122 fitter->initA6(0., -10., 10.);
124 TCanvas*
c1 =
new TCanvas();
126 c1->SetLeftMargin(0.15);
127 c1->SetRightMargin(0.10);
129 fitter->fit(th1d_input,
"breitWignerTimesCB",
"exponential",
xMin,
xMax,
false);
131 c1->Print(Form(
"%s/fitResultPlot/%s_oldtool.pdf", output_path.Data(), s_name.Data()));
132 c1->Print(Form(
"%s/fitResultPlot/%s_oldtool.root", output_path.Data(), s_name.Data()));
135 fitter->mean()->getValV(), fitter->mean()->getError(), fitter->sigma()->getValV(), fitter->sigma()->getError());
139 void Draw_th1d(TH1D* th1d_input, TString variable_name, TString output_path) {
140 TCanvas*
c =
new TCanvas();
142 gStyle->SetOptStat(0);
143 th1d_input->SetMarkerStyle(kFullCircle);
144 th1d_input->SetMarkerColor(kRed);
145 th1d_input->SetLineColor(kRed);
146 th1d_input->SetMaximum(91.4);
147 th1d_input->SetMinimum(90.85);
148 th1d_input->GetXaxis()->SetTitle(variable_name.Data());
149 th1d_input->GetXaxis()->SetTitleOffset(1.2);
150 th1d_input->GetYaxis()->SetTitle(
"Mass mean (GeV)");
152 tlxg->DrawLatexNDC(0.2, 0.8, Form(
"%s",
GT.Data()));
153 c->Print(Form(
"%s/fitResultPlot/mass_VS_%s.pdf", output_path.Data(), variable_name.Data()));
158 "CosThetaCS",
"DeltaEta",
"EtaMinus",
"EtaPlus",
"PhiCS",
"PhiMinus",
"PhiPlus",
"Pt"};
170 TFile* inputfile = TFile::Open(inputfile_name.Data());
171 TDirectoryFile* tdirectory = (TDirectoryFile*)inputfile->Get(
"DiMuonMassValidation");
174 th2d_mass_variables[
i] = (TH2D*)tdirectory->Get(th2d_name);
177 gSystem->Exec(Form(
"mkdir -p %s", output_path.Data()));
178 gSystem->Exec(Form(
"mkdir -p %s/fitResultPlot", output_path.Data()));
179 TFile*
outputfile = TFile::Open(Form(
"%s/fitting_output.root", output_path.Data()),
"RECREATE");
184 {-1, 1}, {-4.8, 4.8}, {-2.4, 2.4}, {-2.4, 2.4}, {-1, 1}, {-
M_PI,
M_PI}, {-
M_PI,
M_PI}, {0, 100}};
188 th2d_mass_variables[
i]->RebinY(variables_rebin[
i]);
189 th1d_variables_meanmass[
i] = th2d_mass_variables[
i]->ProjectionY(th1d_name, 1, 1,
"d");
190 for (
int j = 0;
j < th1d_variables_meanmass[
i]->GetNbinsX();
j++) {
191 if (
i == 7 and
j > 25) {
195 <<
" th1d_variables_meanmass[i]->GetNbinsX()=" << th1d_variables_meanmass[
i]->GetNbinsX() << endl;
196 std::cout << __PRETTY_FUNCTION__ <<
" th2d_mass_variables[i]->GetNbinsY()=" << th2d_mass_variables[
i]->GetNbinsY()
198 th1d_variables_meanmass[
i]->SetBinContent(
j, 0);
199 th1d_variables_meanmass[
i]->SetBinError(
j, 0);
202 TH1D* th1d_i = th2d_mass_variables[
i]->ProjectionX(th1d_mass_temp_name,
j,
j,
"d");
203 th1d_i->Write(th1d_mass_temp_name);
204 TString s_cut = Form(
"nocut");
209 th1d_variables_meanmass[
i]->SetBinContent(
j, fitR.
mean);
210 th1d_variables_meanmass[
i]->SetBinError(
j, fitR.
mean_err);
213 th1d_variables_meanmass[
i]->GetXaxis()->SetRangeUser(xaxis_range[
i][0], xaxis_range[
i][1]);
216 th1d_variables_meanmass[
i]->Write(th1d_name);
219 th1d_variables_entries[
i] = th2d_mass_variables[
i]->ProjectionY(th1d_name_entries, 0, -1,
"d");
221 th1d_variables_entries[
i]->GetYaxis()->SetTitle(
"Entry");
223 th1d_variables_entries[
i]->Write(th1d_name_entries);
231 std::cout <<
"File is going to be written in the directory: " <<
path <<
" for input file: " << inputfile_name
234 std::cerr <<
"Error: Unable to determine the path." << std::endl;
243 const vector<TString>& label_names,
244 const vector<int>&
colors,
245 const vector<int>&
styles,
246 const TString& Rlabel,
247 const TString& th1d_name,
250 const TString& output_name) {
251 if (file_names.empty() || label_names.empty()) {
252 std::cout <<
"Provided an empty list of file and label names" << std::endl;
257 assert(file_names.size() == label_names.size());
261 for (
auto const&
filename : file_names | boost::adaptors::indexed(0)) {
263 th1d_input[
filename.index()] = (TH1D*)file_input[
filename.index()]->Get(th1d_name);
264 th1d_input[
filename.index()]->SetTitle(
"");
277 canvasName.Form(
"canv_%s", th1d_name.Data());
280 TCanvas* canv =
new TCanvas(canvasName, canvasName, W,
H);
281 canv->SetFillColor(0);
282 canv->SetBorderMode(0);
283 canv->SetFrameFillStyle(0);
284 canv->SetFrameBorderMode(0);
285 canv->SetLeftMargin(
L / W + 0.05);
286 canv->SetRightMargin(
R / W);
287 canv->SetTopMargin(
T /
H);
288 canv->SetBottomMargin(
B /
H);
294 gStyle->SetOptStat(0);
296 TLegend* lg =
new TLegend(0.3, 0.7, 0.7, 0.9);
299 lg->SetEntrySeparation(0.05);
304 for (
auto const& labelname : label_names | boost::adaptors::indexed(0)) {
305 double temp_ymin = th1d_input[labelname.index()]->GetMinimum();
306 double temp_ymax = th1d_input[labelname.index()]->GetMaximum();
307 if (labelname.index() == 0) {
311 if (temp_ymin <=
ymin) {
314 if (temp_ymax >=
ymax) {
319 for (
auto const& labelname : label_names | boost::adaptors::indexed(0)) {
320 th1d_input[labelname.index()]->SetMarkerColor(
colors[labelname.index()]);
321 th1d_input[labelname.index()]->SetLineColor(
colors[labelname.index()]);
322 th1d_input[labelname.index()]->SetMarkerStyle(
styles[labelname.index()]);
323 th1d_input[labelname.index()]->GetXaxis()->SetTitle(
xlabel);
324 th1d_input[labelname.index()]->GetYaxis()->SetTitle(
ylabel);
325 th1d_input[labelname.index()]->GetYaxis()->SetTitleOffset(2.0);
326 lg->AddEntry(th1d_input[labelname.index()], labelname.value());
328 TString label_meanmass_plot =
"Mean M_{#mu#mu} (GeV)";
329 if (
ylabel.EqualTo(label_meanmass_plot)) {
330 double ycenter = (
ymax +
ymin) / 2.0;
332 double Ymin = ycenter - yrange;
333 double Ymax = ycenter + yrange * 1.10;
334 th1d_input[labelname.index()]->SetAxisRange(Ymin, Ymax,
"Y");
335 th1d_input[labelname.index()]->Draw(
"PEX0same");
339 th1d_input[labelname.index()]->SetAxisRange(Ymin, Ymax,
"Y");
340 th1d_input[labelname.index()]->Draw(
"HIST E1 same");
350 canv->GetFrame()->Draw();
351 canv->SaveAs(output_name);
353 if (output_name.Contains(
".pdf")) {
354 TString output_name_png(output_name);
355 output_name_png.Replace(output_name_png.Index(
".pdf"), 4,
".png");
356 canv->SaveAs(output_name_png);
361 vector<TString> vec_single_file_path;
362 vector<TString> vec_single_file_name;
363 vector<TString> vec_global_tag;
364 vector<TString> vec_title;
365 vector<int> vec_color;
366 vector<int> vec_style;
367 vector<TString> vec_right_title;
373 pt::read_json(
options.config, main_tree);
374 pt::ptree alignments = main_tree.get_child(
"alignments");
375 pt::ptree
validation = main_tree.get_child(
"validation");
378 std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
379 for (
const auto& childTree : alignments) {
380 alignmentsOrdered.push_back(childTree);
383 alignmentsOrdered.end(),
384 [](
const std::pair<std::string, pt::ptree>& left,
const std::pair<std::string, pt::ptree>& right) {
385 return left.second.get<
int>(
"index") < right.second.get<
int>(
"index");
388 for (
const auto& childTree : alignmentsOrdered) {
390 if (childTree.second.find(
"file") == childTree.second.not_found()) {
391 std::cerr <<
"Ignoring alignment: " << childTree.second.get<
std::string>(
"title") <<
".\nNo file to merged found!" 397 vec_single_file_path.push_back(childTree.second.get<
std::string>(
"file"));
398 vec_single_file_name.push_back(childTree.second.get<
std::string>(
"file") +
"/Zmumu.root");
399 vec_color.push_back(childTree.second.get<
int>(
"color"));
400 vec_style.push_back(childTree.second.get<
int>(
"style"));
401 if (childTree.second.find(
"customrighttitle") == childTree.second.not_found()) {
402 vec_right_title.push_back(
"");
404 vec_right_title.push_back(childTree.second.get<
std::string>(
"customrighttitle"));
406 vec_global_tag.push_back(childTree.second.get<
std::string>(
"globaltag"));
407 vec_title.push_back(childTree.second.get<
std::string>(
"title"));
412 TString merge_output = main_tree.get<
std::string>(
"output");
414 vector<TString> vec_single_fittingoutput;
415 vec_single_fittingoutput.clear();
416 for (
unsigned i = 0;
i < vec_single_file_path.size();
i++) {
418 vec_single_fittingoutput.push_back(vec_single_file_path[
i] +
"/fitting_output.root");
421 int files_number = vec_single_file_path.size();
422 cout <<
"files_number=" << files_number << endl;
423 for (
int idx_variable = 0; idx_variable <
variables_number; idx_variable++) {
427 vec_single_fittingoutput,
434 "Mean M_{#mu#mu} (GeV)",
440 vec_single_fittingoutput,
454 #ifndef DOXYGEN_SHOULD_SKIP_THIS int Zmumumerge(int argc, char *argv[])
void makeNicePlotStyle(RooPlot *plot)
static const int variables_number
static PFTauRenderPlugin instance
static const int max_file_number
FitOut ZMassBinFit_OldTool(TH1D *th1d_input, TString s_name="zmumu_fitting", TString output_path="./")
FitOut(double a, double b, double c, double d)
int main(int argc, char *argv[])
const TString tstring_variables_name_label[variables_number]
void Draw_TH1D_forMultiRootFiles(const vector< TString > &file_names, const vector< TString > &label_names, const vector< int > &colors, const vector< int > &styles, const TString &Rlabel, const TString &th1d_name, const TString &xlabel, const TString &ylabel, const TString &output_name)
RooRealVar MuMu_mass("MuMu_mass", "MuMu_mass", 70, 110)
const TString tstring_variables_name[variables_number]
void Draw_th1d(TH1D *th1d_input, TString variable_name, TString output_path)
std::vector< Style_t > styles
void Fitting_GetMassmeanVSvariables(TString inputfile_name, TString output_path)
void CMS_lumi(TPad *pad, int iPeriod=3, int iPosX=10, TString RLabel="")