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> 46 namespace pt = boost::property_tree;
49 plot->GetXaxis()->CenterTitle(
true);
50 plot->GetYaxis()->CenterTitle(
true);
51 plot->GetXaxis()->SetTitleFont(42);
52 plot->GetYaxis()->SetTitleFont(42);
53 plot->GetXaxis()->SetTitleSize(0.05);
54 plot->GetYaxis()->SetTitleSize(0.05);
55 plot->GetXaxis()->SetTitleOffset(0.9);
56 plot->GetYaxis()->SetTitleOffset(1.3);
57 plot->GetXaxis()->SetLabelFont(42);
58 plot->GetYaxis()->SetLabelFont(42);
59 plot->GetYaxis()->SetLabelSize(.05);
60 plot->GetXaxis()->SetLabelSize(.05);
64 RooRealVar
MuMu_mass(
"MuMu_mass",
"MuMu_mass", 70, 110);
65 static TString
GT =
"";
66 TLatex*
tlxg =
new TLatex();
78 double xMin(75),
xMax(105), xMean(91);
80 double sigmaMin = 0.1;
84 double sigma2(0.1), sigma2Min(0.), sigma2Max(10.), useChi2(
false);
87 fitter->
initSigma(sigma, sigmaMin, sigmaMax);
88 fitter->
initSigma2(sigma2, sigma2Min, sigma2Max);
90 fitter->
initN(1, 0.01, 100.);
95 fitter->
gamma()->setConstant(kTRUE);
97 fitter->
mean2()->setConstant(kTRUE);
100 fitter->
initN(1, 0.01, 100.);
105 fitter->
initA0(0., -10., 10.);
106 fitter->
initA1(0., -10., 10.);
107 fitter->
initA2(0., -10., 10.);
108 fitter->
initA3(0., -10., 10.);
109 fitter->
initA4(0., -10., 10.);
110 fitter->
initA5(0., -10., 10.);
111 fitter->
initA6(0., -10., 10.);
112 TCanvas*
c1 =
new TCanvas();
114 c1->SetLeftMargin(0.15);
115 c1->SetRightMargin(0.10);
117 fitter->
fit(th1d_input,
"breitWignerTimesCB",
"exponential",
xMin,
xMax,
false);
119 c1->Print(Form(
"%s/fitResultPlot/%s_oldtool.pdf", output_path.Data(), s_name.Data()));
120 c1->Print(Form(
"%s/fitResultPlot/%s_oldtool.root", output_path.Data(), s_name.Data()));
123 fitter->
mean()->getValV(), fitter->
mean()->getError(), fitter->
sigma()->getValV(), fitter->
sigma()->getError());
126 void Draw_th1d(TH1D* th1d_input, TString variable_name) {
127 TCanvas*
c =
new TCanvas();
129 gStyle->SetOptStat(0);
130 th1d_input->SetMarkerStyle(kFullCircle);
131 th1d_input->SetMarkerColor(kRed);
132 th1d_input->SetLineColor(kRed);
133 th1d_input->SetMaximum(91.4);
134 th1d_input->SetMinimum(90.85);
135 th1d_input->GetXaxis()->SetTitle(variable_name.Data());
136 th1d_input->GetXaxis()->SetTitleOffset(1.2);
137 th1d_input->GetYaxis()->SetTitle(
"Mass mean (GeV)");
139 tlxg->DrawLatexNDC(0.2, 0.8, Form(
"%s",
GT.Data()));
140 c->Print(Form(
"%s/fitResultPlot/mass_VS_%s.pdf",
GT.Data(), variable_name.Data()));
145 "CosThetaCS",
"DeltaEta",
"EtaMinus",
"EtaPlus",
"PhiCS",
"PhiMinus",
"PhiPlus",
"Pt"};
148 TFile* inputfile = TFile::Open(inputfile_name.Data());
149 TDirectoryFile* tdirectory = (TDirectoryFile*)inputfile->Get(
"DiMuonMassValidation");
152 th2d_mass_variables[
i] = (TH2D*)tdirectory->Get(th2d_name);
155 gSystem->Exec(Form(
"mkdir -p %s", output_path.Data()));
156 gSystem->Exec(Form(
"mkdir -p %s/fitResultPlot", output_path.Data()));
157 TFile* outpufile = TFile::Open(Form(
"%s/fitting_output.root", output_path.Data()),
"recreate");
162 {-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}};
166 th2d_mass_variables[
i]->RebinY(variables_rebin[
i]);
167 th1d_variables_meanmass[
i] = th2d_mass_variables[
i]->ProjectionY(th1d_name, 1, 1,
"d");
168 for (
int j = 0;
j < th1d_variables_meanmass[
i]->GetNbinsX();
j++) {
169 if (
i == 7 and
j > 25) {
172 cout <<
"th1d_variables_meanmass[i]->GetNbinsX()=" << th1d_variables_meanmass[
i]->GetNbinsX() << endl;
173 cout <<
"th2d_mass_variables[i]->GetNbinsY()=" << th2d_mass_variables[
i]->GetNbinsY() << endl;
174 th1d_variables_meanmass[
i]->SetBinContent(
j, 0);
175 th1d_variables_meanmass[
i]->SetBinError(
j, 0);
178 TH1D* th1d_i = th2d_mass_variables[
i]->ProjectionX(th1d_mass_temp_name,
j,
j,
"d");
179 th1d_i->Write(th1d_mass_temp_name);
180 TString s_cut = Form(
"nocut");
184 th1d_variables_meanmass[
i]->SetBinContent(
j, fitR.
mean);
185 th1d_variables_meanmass[
i]->SetBinError(
j, fitR.
mean_err);
187 th1d_variables_meanmass[
i]->GetXaxis()->SetRangeUser(xaxis_range[
i][0], xaxis_range[
i][1]);
190 th1d_variables_meanmass[
i]->Write(th1d_name);
193 th1d_variables_entries[
i] = th2d_mass_variables[
i]->ProjectionY(th1d_name_entries, 0, -1,
"d");
195 th1d_variables_entries[
i]->GetYaxis()->SetTitle(
"Entry");
197 th1d_variables_entries[
i]->Write(th1d_name_entries);
207 const vector<TString>& label_names,
208 const vector<int>&
colors,
209 const vector<int>&
styles,
210 const TString& th1d_name,
211 const TString& output_name) {
212 if (file_names.empty() || label_names.empty()) {
213 cout <<
"Provided an empty list of file and label names" << std::endl;
218 assert(file_names.size() == label_names.size());
222 for (
auto const&
filename : file_names | boost::adaptors::indexed(0)) {
224 th1d_input[
filename.index()] = (TH1D*)file_input[
filename.index()]->Get(th1d_name);
225 th1d_input[
filename.index()]->SetTitle(
"");
228 TCanvas*
c =
new TCanvas();
229 TLegend* lg =
new TLegend(0.2, 0.7, 0.5, 0.95);
231 gStyle->SetOptStat(0);
233 for (
auto const& labelname : label_names | boost::adaptors::indexed(0)) {
234 th1d_input[labelname.index()]->SetMarkerColor(
colors[labelname.index()]);
235 th1d_input[labelname.index()]->SetLineColor(
colors[labelname.index()]);
236 th1d_input[labelname.index()]->SetMarkerStyle(
styles[labelname.index()]);
237 th1d_input[labelname.index()]->Draw(
"same");
238 lg->AddEntry(th1d_input[labelname.index()], labelname.value());
241 c->SaveAs(output_name);
242 if (output_name.Contains(
".pdf")) {
243 TString output_name_png(output_name);
244 output_name_png.Replace(output_name_png.Index(
".pdf"), 4,
".png");
245 c->SaveAs(output_name_png);
250 vector<TString> vec_single_file_path;
251 vector<TString> vec_single_file_name;
252 vector<TString> vec_global_tag;
253 vector<TString> vec_title;
254 vector<int> vec_color;
255 vector<int> vec_style;
261 pt::read_json(
options.config, main_tree);
262 pt::ptree alignments = main_tree.get_child(
"alignments");
263 pt::ptree
validation = main_tree.get_child(
"validation");
264 for (
const auto& childTree : alignments) {
265 vec_single_file_path.push_back(childTree.second.get<
std::string>(
"file"));
266 vec_single_file_name.push_back(childTree.second.get<
std::string>(
"file") +
"/Zmumu.root");
267 vec_color.push_back(childTree.second.get<
int>(
"color"));
268 vec_style.push_back(childTree.second.get<
int>(
"style"));
269 vec_global_tag.push_back(childTree.second.get<
std::string>(
"globaltag"));
270 vec_title.push_back(childTree.second.get<
std::string>(
"title"));
274 TString merge_output = main_tree.get<
std::string>(
"output");
276 vector<TString> vec_single_fittingoutput;
277 vec_single_fittingoutput.clear();
278 for (
unsigned i = 0;
i < vec_single_file_path.size();
i++) {
280 vec_single_fittingoutput.push_back(vec_single_file_path[
i] +
"/fitting_output.root");
283 int files_number = vec_single_file_path.size();
284 cout <<
"files_number=" << files_number << endl;
285 for (
int idx_variable = 0; idx_variable <
variables_number; idx_variable++) {
288 vec_single_fittingoutput,
296 vec_single_fittingoutput,
306 #ifndef DOXYGEN_SHOULD_SKIP_THIS void initA0(double value, double min, double max, const TString &name="a0", const TString &title="a0")
int Zmumumerge(int argc, char *argv[])
void Draw_TH1D_forMultiRootFiles(const vector< TString > &file_names, const vector< TString > &label_names, const vector< int > &colors, const vector< int > &styles, const TString &th1d_name, const TString &output_name)
void makeNicePlotStyle(RooPlot *plot)
void initGamma(double value, double min, double max, const TString &name="gamma", const TString &title="gamma")
void Draw_th1d(TH1D *th1d_input, TString variable_name)
void initA5(double value, double min, double max, const TString &name="a5", const TString &title="a5")
void initSigma(double value, double min, double max, const TString &name="sigma", const TString &title="sigma")
void initSigma2(double value, double min, double max, const TString &name="sigma2", const TString &title="sigma2")
static const int variables_number
void initA1(double value, double min, double max, const TString &name="a1", const TString &title="a1")
void initFGCB(double value, double min, double max, const TString &name="fGCB", const TString &title="fGCB")
void initA2(double value, double min, double max, const TString &name="a2", const TString &title="a2")
static const int max_file_number
FitOut ZMassBinFit_OldTool(TH1D *th1d_input, TString s_name="zmumu_fitting", TString output_path="./")
void initA6(double value, double min, double max, const TString &name="a6", const TString &title="a6")
FitOut(double a, double b, double c, double d)
void initMean2(double value, double min, double max, const TString &name="mean2", const TString &title="mean2")
int main(int argc, char *argv[])
void initN(double value, double min, double max, const TString &name="n", const TString &title="n")
void initFsig(double value, double min, double max, const TString &name="fsig", const TString &title="signal fraction")
void initExpCoeffA1(double value, double min, double max, const TString &name="expCoeffa1", const TString &title="expCoeffa1")
RooRealVar MuMu_mass("MuMu_mass", "MuMu_mass", 70, 110)
const TString tstring_variables_name[variables_number]
void initAlpha(double value, double min, double max, const TString &name="alpha", const TString &title="alpha")
std::vector< Style_t > styles
void fit(TH1 *histo, const TString signalType, const TString backgroundType, double xMin=0., double xMax=0., bool sumW2Error=false)
void initExpCoeffA2(double value, double min, double max, const TString &name="expCoeffa2", const TString &title="expCoeffa2")
void Fitting_GetMassmeanVSvariables(TString inputfile_name, TString output_path)
void initA3(double value, double min, double max, const TString &name="a3", const TString &title="a3")
void initExpCoeffA0(double value, double min, double max, const TString &name="expCoeffa0", const TString &title="expCoeffa0")
void initMean(double value, double min, double max, const TString &name="mean", const TString &title="mean")
void initA4(double value, double min, double max, const TString &name="a4", const TString &title="a4")