29 #include "TPaveText.h" 37 #include <boost/filesystem.hpp> 38 #include <boost/property_tree/ptree.hpp> 39 #include <boost/property_tree/json_parser.hpp> 40 #include <boost/range/adaptor/indexed.hpp> 45 namespace pt = boost::property_tree;
48 plot->GetXaxis()->CenterTitle(
true);
49 plot->GetYaxis()->CenterTitle(
true);
50 plot->GetXaxis()->SetTitleFont(42);
51 plot->GetYaxis()->SetTitleFont(42);
52 plot->GetXaxis()->SetTitleSize(0.05);
53 plot->GetYaxis()->SetTitleSize(0.05);
54 plot->GetXaxis()->SetTitleOffset(0.9);
55 plot->GetYaxis()->SetTitleOffset(1.3);
56 plot->GetXaxis()->SetLabelFont(42);
57 plot->GetYaxis()->SetLabelFont(42);
58 plot->GetYaxis()->SetLabelSize(.05);
59 plot->GetXaxis()->SetLabelSize(.05);
63 RooRealVar
MuMu_mass(
"MuMu_mass",
"MuMu_mass", 70, 110);
64 static TString
GT =
"";
65 TLatex*
tlxg =
new TLatex();
77 double xMin(75),
xMax(105), xMean(91);
79 double sigmaMin = 0.1;
83 double sigma2(0.1), sigma2Min(0.), sigma2Max(10.), useChi2(
false);
86 fitter->
initSigma(sigma, sigmaMin, sigmaMax);
87 fitter->
initSigma2(sigma2, sigma2Min, sigma2Max);
89 fitter->
initN(1, 0.01, 100.);
94 fitter->
gamma()->setConstant(kTRUE);
96 fitter->
mean2()->setConstant(kTRUE);
99 fitter->
initN(1, 0.01, 100.);
104 fitter->
initA0(0., -10., 10.);
105 fitter->
initA1(0., -10., 10.);
106 fitter->
initA2(0., -10., 10.);
107 fitter->
initA3(0., -10., 10.);
108 fitter->
initA4(0., -10., 10.);
109 fitter->
initA5(0., -10., 10.);
110 fitter->
initA6(0., -10., 10.);
111 TCanvas*
c1 =
new TCanvas();
113 c1->SetLeftMargin(0.15);
114 c1->SetRightMargin(0.10);
116 fitter->
fit(th1d_input,
"breitWignerTimesCB",
"exponential",
xMin,
xMax,
false);
118 c1->Print(Form(
"%s/fitResultPlot/%s_oldtool.pdf", output_path.Data(), s_name.Data()));
119 c1->Print(Form(
"%s/fitResultPlot/%s_oldtool.root", output_path.Data(), s_name.Data()));
122 fitter->
mean()->getValV(), fitter->
mean()->getError(), fitter->
sigma()->getValV(), fitter->
sigma()->getError());
125 void Draw_th1d(TH1D* th1d_input, TString variable_name) {
126 TCanvas*
c =
new TCanvas();
128 gStyle->SetOptStat(0);
129 th1d_input->SetMarkerStyle(kFullCircle);
130 th1d_input->SetMarkerColor(kRed);
131 th1d_input->SetLineColor(kRed);
132 th1d_input->SetMaximum(91.4);
133 th1d_input->SetMinimum(90.85);
134 th1d_input->GetXaxis()->SetTitle(variable_name.Data());
135 th1d_input->GetXaxis()->SetTitleOffset(1.2);
136 th1d_input->GetYaxis()->SetTitle(
"Mass mean (GeV)");
138 tlxg->DrawLatexNDC(0.2, 0.8, Form(
"%s",
GT.Data()));
139 c->Print(Form(
"%s/fitResultPlot/mass_VS_%s.pdf",
GT.Data(), variable_name.Data()));
144 "CosThetaCS",
"DeltaEta",
"EtaMinus",
"EtaPlus",
"PhiCS",
"PhiMinus",
"PhiPlus",
"Pt"};
147 TFile* inputfile = TFile::Open(inputfile_name.Data());
148 TDirectoryFile* tdirectory = (TDirectoryFile*)inputfile->Get(
"DiMuonMassValidation");
151 th2d_mass_variables[
i] = (TH2D*)tdirectory->Get(th2d_name);
154 gSystem->Exec(Form(
"mkdir -p %s", output_path.Data()));
155 gSystem->Exec(Form(
"mkdir -p %s/fitResultPlot", output_path.Data()));
156 TFile* outpufile = TFile::Open(Form(
"%s/fitting_output.root", output_path.Data()),
"recreate");
161 {-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}};
165 th2d_mass_variables[
i]->RebinY(variables_rebin[
i]);
166 th1d_variables_meanmass[
i] = th2d_mass_variables[
i]->ProjectionY(th1d_name, 1, 1,
"d");
167 for (
int j = 0;
j < th1d_variables_meanmass[
i]->GetNbinsX();
j++) {
168 if (
i == 7 and
j > 25) {
171 cout <<
"th1d_variables_meanmass[i]->GetNbinsX()=" << th1d_variables_meanmass[
i]->GetNbinsX() << endl;
172 cout <<
"th2d_mass_variables[i]->GetNbinsY()=" << th2d_mass_variables[
i]->GetNbinsY() << endl;
173 th1d_variables_meanmass[
i]->SetBinContent(
j, 0);
174 th1d_variables_meanmass[
i]->SetBinError(
j, 0);
177 TH1D* th1d_i = th2d_mass_variables[
i]->ProjectionX(th1d_mass_temp_name,
j,
j,
"d");
178 th1d_i->Write(th1d_mass_temp_name);
179 TString s_cut = Form(
"nocut");
183 th1d_variables_meanmass[
i]->SetBinContent(
j, fitR.
mean);
184 th1d_variables_meanmass[
i]->SetBinError(
j, fitR.
mean_err);
186 th1d_variables_meanmass[
i]->GetXaxis()->SetRangeUser(xaxis_range[
i][0], xaxis_range[
i][1]);
189 th1d_variables_meanmass[
i]->Write(th1d_name);
192 th1d_variables_entries[
i] = th2d_mass_variables[
i]->ProjectionY(th1d_name_entries, 0, -1,
"d");
194 th1d_variables_entries[
i]->GetYaxis()->SetTitle(
"Entry");
196 th1d_variables_entries[
i]->Write(th1d_name_entries);
206 const vector<TString>& label_names,
207 const vector<int>&
colors,
208 const vector<int>&
styles,
209 const TString& th1d_name,
210 const TString& output_name) {
211 if (file_names.empty() || label_names.empty()) {
212 cout <<
"Provided an empty list of file and label names" << std::endl;
217 assert(file_names.size() == label_names.size());
221 for (
auto const&
filename : file_names | boost::adaptors::indexed(0)) {
223 th1d_input[
filename.index()] = (TH1D*)file_input[
filename.index()]->Get(th1d_name);
226 TCanvas*
c =
new TCanvas();
227 TLegend* lg =
new TLegend(0.2, 0.7, 0.5, 0.95);
229 gStyle->SetOptStat(0);
230 th1d_input[0]->SetTitle(
"");
232 for (
auto const& labelname : label_names | boost::adaptors::indexed(0)) {
233 th1d_input[labelname.index()]->SetMarkerColor(
colors[labelname.index()]);
234 th1d_input[labelname.index()]->SetLineColor(
colors[labelname.index()]);
235 th1d_input[labelname.index()]->SetMarkerStyle(
styles[labelname.index()]);
236 th1d_input[labelname.index()]->Draw(
"same");
237 lg->AddEntry(th1d_input[labelname.index()], labelname.value());
240 c->SaveAs(output_name);
241 if (output_name.Contains(
".pdf")) {
242 TString output_name_png(output_name);
243 output_name_png.Replace(output_name_png.Index(
".pdf"), 4,
".png");
244 c->SaveAs(output_name_png);
249 vector<TString> vec_single_file_path;
250 vector<TString> vec_single_file_name;
251 vector<TString> vec_global_tag;
252 vector<TString> vec_title;
253 vector<int> vec_color;
254 vector<int> vec_style;
260 pt::read_json(
options.config, main_tree);
261 pt::ptree alignments = main_tree.get_child(
"alignments");
262 pt::ptree
validation = main_tree.get_child(
"validation");
263 for (
const auto& childTree : alignments) {
264 vec_single_file_path.push_back(childTree.second.get<
std::string>(
"file"));
265 vec_single_file_name.push_back(childTree.second.get<
std::string>(
"file") +
"/Zmumu.root");
266 vec_color.push_back(childTree.second.get<
int>(
"color"));
267 vec_style.push_back(childTree.second.get<
int>(
"style"));
268 vec_global_tag.push_back(childTree.second.get<
std::string>(
"globaltag"));
269 vec_title.push_back(childTree.second.get<
std::string>(
"title"));
273 TString merge_output = main_tree.get<
std::string>(
"output");
275 vector<TString> vec_single_fittingoutput;
276 vec_single_fittingoutput.clear();
277 for (
unsigned i = 0;
i < vec_single_file_path.size();
i++) {
279 vec_single_fittingoutput.push_back(vec_single_file_path[
i] +
"/fitting_output.root");
282 int files_number = vec_single_file_path.size();
283 cout <<
"files_number=" << files_number << endl;
284 for (
int idx_variable = 0; idx_variable <
variables_number; idx_variable++) {
287 vec_single_fittingoutput,
295 vec_single_fittingoutput,
305 #ifndef DOXYGEN_SHOULD_SKIP_THIS void initA6(const double &value, const double &min, const double &max, const TString &name="a6", const TString &title="a6")
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 Draw_th1d(TH1D *th1d_input, TString variable_name)
static const int variables_number
void initA1(const double &value, const double &min, const double &max, const TString &name="a1", const TString &title="a1")
static const int max_file_number
void initFsig(const double &value, const double &min, const double &max, const TString &name="fsig", const TString &title="signal fraction")
FitOut ZMassBinFit_OldTool(TH1D *th1d_input, TString s_name="zmumu_fitting", TString output_path="./")
void fit(TH1 *histo, const TString signalType, const TString backgroundType, const double &xMin=0., const double &xMax=0., bool sumW2Error=false)
void initGamma(const double &value, const double &min, const double &max, const TString &name="gamma", const TString &title="gamma")
FitOut(double a, double b, double c, double d)
int main(int argc, char *argv[])
void initA3(const double &value, const double &min, const double &max, const TString &name="a3", const TString &title="a3")
void initA4(const double &value, const double &min, const double &max, const TString &name="a4", const TString &title="a4")
RooRealVar MuMu_mass("MuMu_mass", "MuMu_mass", 70, 110)
void initMean(const double &value, const double &min, const double &max, const TString &name="mean", const TString &title="mean")
void initN(const double &value, const double &min, const double &max, const TString &name="n", const TString &title="n")
const TString tstring_variables_name[variables_number]
void initA0(const double &value, const double &min, const double &max, const TString &name="a0", const TString &title="a0")
void initAlpha(const double &value, const double &min, const double &max, const TString &name="alpha", const TString &title="alpha")
void initA5(const double &value, const double &min, const double &max, const TString &name="a5", const TString &title="a5")
void initExpCoeffA0(const double &value, const double &min, const double &max, const TString &name="expCoeffa0", const TString &title="expCoeffa0")
void initExpCoeffA1(const double &value, const double &min, const double &max, const TString &name="expCoeffa1", const TString &title="expCoeffa1")
void initA2(const double &value, const double &min, const double &max, const TString &name="a2", const TString &title="a2")
void Fitting_GetMassmeanVSvariables(TString inputfile_name, TString output_path)
void initSigma2(const double &value, const double &min, const double &max, const TString &name="sigma2", const TString &title="sigma2")
void initFGCB(const double &value, const double &min, const double &max, const TString &name="fGCB", const TString &title="fGCB")
void initExpCoeffA2(const double &value, const double &min, const double &max, const TString &name="expCoeffa2", const TString &title="expCoeffa2")
void initSigma(const double &value, const double &min, const double &max, const TString &name="sigma", const TString &title="sigma")
void initMean2(const double &value, const double &min, const double &max, const TString &name="mean2", const TString &title="mean2")