CMS 3D CMS Logo

Classes | Functions | Variables
Zmumumerge.cc File Reference
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "toolbox.h"
#include "FitWithRooFit.cc"
#include "Options.h"
#include "TAxis.h"
#include "TBranch.h"
#include "TCanvas.h"
#include "TChain.h"
#include "TCut.h"
#include "TF1.h"
#include "TFile.h"
#include "TFrame.h"
#include "TH1.h"
#include "TH1D.h"
#include "TH1F.h"
#include "TH2.h"
#include "TH2F.h"
#include "THStack.h"
#include "TLatex.h"
#include "TLegend.h"
#include "TMath.h"
#include "TPad.h"
#include "TPaveText.h"
#include "TRandom.h"
#include "TString.h"
#include "TStyle.h"
#include "TSystem.h"
#include "TTree.h"
#include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/range/adaptor/indexed.hpp>

Go to the source code of this file.

Classes

class  FitOut
 

Functions

void Draw_th1d (TH1D *th1d_input, TString variable_name)
 
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 Fitting_GetMassmeanVSvariables (TString inputfile_name, TString output_path)
 
int main (int argc, char *argv[])
 
void makeNicePlotStyle (RooPlot *plot)
 
RooRealVar MuMu_mass ("MuMu_mass", "MuMu_mass", 70, 110)
 
FitOut ZMassBinFit_OldTool (TH1D *th1d_input, TString s_name="zmumu_fitting", TString output_path="./")
 
int Zmumumerge (int argc, char *argv[])
 

Variables

static TString GT = ""
 
static const int max_file_number = 10
 
TLatex * tlxg = new TLatex()
 
const TString tstring_variables_name [variables_number]
 
static const int variables_number = 8
 

Function Documentation

◆ Draw_th1d()

void Draw_th1d ( TH1D *  th1d_input,
TString  variable_name 
)

Definition at line 125 of file Zmumumerge.cc.

References HltBtagPostValidation_cff::c, GT, and tlxg.

Referenced by Fitting_GetMassmeanVSvariables().

125  {
126  TCanvas* c = new TCanvas();
127  c->cd();
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)");
137  th1d_input->Draw();
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()));
140 }
static TString GT
Definition: Zmumumerge.cc:64
TLatex * tlxg
Definition: Zmumumerge.cc:65

◆ Draw_TH1D_forMultiRootFiles()

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 
)

Definition at line 205 of file Zmumumerge.cc.

References cms::cuda::assert(), HltBtagPostValidation_cff::c, gather_cfg::cout, corrVsCorr::filename, max_file_number, and styles.

Referenced by Zmumumerge().

210  {
211  if (file_names.empty() || label_names.empty()) {
212  cout << "Provided an empty list of file and label names" << std::endl;
213  return;
214  }
215 
216  // do not allow the list of files and labels names to differ
217  assert(file_names.size() == label_names.size());
218 
219  TH1D* th1d_input[max_file_number];
220  TFile* file_input[max_file_number];
221  for (auto const& filename : file_names | boost::adaptors::indexed(0)) {
222  file_input[filename.index()] = TFile::Open(filename.value());
223  th1d_input[filename.index()] = (TH1D*)file_input[filename.index()]->Get(th1d_name);
224  }
225 
226  TCanvas* c = new TCanvas();
227  TLegend* lg = new TLegend(0.2, 0.7, 0.5, 0.95);
228  c->cd();
229  gStyle->SetOptStat(0);
230  th1d_input[0]->SetTitle("");
231 
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());
238  }
239  lg->Draw("same");
240  c->SaveAs(output_name);
241  if (output_name.Contains(".pdf")) {
242  TString output_name_png(output_name); // output_name is const, copy to modify
243  output_name_png.Replace(output_name_png.Index(".pdf"), 4, ".png");
244  c->SaveAs(output_name_png);
245  }
246 }
vector< Style_t > styles
static const int max_file_number
Definition: Zmumumerge.cc:204
assert(be >=bs)
Definition: colors.py:1

◆ Fitting_GetMassmeanVSvariables()

void Fitting_GetMassmeanVSvariables ( TString  inputfile_name,
TString  output_path 
)

Definition at line 145 of file Zmumumerge.cc.

References gather_cfg::cout, Draw_th1d(), mps_fire::i, dqmiolumiharvest::j, M_PI, FitOut::mean, FitOut::mean_err, tstring_variables_name, variables_number, and ZMassBinFit_OldTool().

Referenced by Zmumumerge().

145  {
146  TH2D* th2d_mass_variables[variables_number];
147  TFile* inputfile = TFile::Open(inputfile_name.Data());
148  TDirectoryFile* tdirectory = (TDirectoryFile*)inputfile->Get("DiMuonMassValidation");
149  for (int i = 0; i < variables_number; i++) {
150  TString th2d_name = Form("th2d_mass_%s", tstring_variables_name[i].Data());
151  th2d_mass_variables[i] = (TH2D*)tdirectory->Get(th2d_name);
152  }
153 
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");
157  TH1D* th1d_variables_meanmass[variables_number];
158  TH1D* th1d_variables_entries[variables_number];
159  const int variables_rebin[variables_number] = {1, 1, 1, 1, 1, 1, 1, 1};
160  const double xaxis_range[variables_number][2] = {
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}};
162  for (int i = 0; i < variables_number; i++) {
163  TString th1d_name = Form("th1d_meanmass_%s", tstring_variables_name[i].Data());
164 
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) {
169  continue;
170  }
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);
175 
176  TString th1d_mass_temp_name = Form("th1d_mass_%s_%d", tstring_variables_name[i].Data(), j);
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");
180  TString s_name = Form("%s_%d", tstring_variables_name[i].Data(), j);
181 
182  FitOut fitR = ZMassBinFit_OldTool(th1d_i, s_name, output_path);
183  th1d_variables_meanmass[i]->SetBinContent(j, fitR.mean);
184  th1d_variables_meanmass[i]->SetBinError(j, fitR.mean_err);
185  }
186  th1d_variables_meanmass[i]->GetXaxis()->SetRangeUser(xaxis_range[i][0], xaxis_range[i][1]);
187  Draw_th1d(th1d_variables_meanmass[i], tstring_variables_name[i]);
188  outpufile->cd();
189  th1d_variables_meanmass[i]->Write(th1d_name);
190 
191  TString th1d_name_entries = Form("th1d_entries_%s", tstring_variables_name[i].Data());
192  th1d_variables_entries[i] = th2d_mass_variables[i]->ProjectionY(th1d_name_entries, 0, -1, "d");
193  th1d_variables_entries[i]->GetXaxis()->SetTitle(tstring_variables_name[i].Data());
194  th1d_variables_entries[i]->GetYaxis()->SetTitle("Entry");
195  outpufile->cd();
196  th1d_variables_entries[i]->Write(th1d_name_entries);
197  }
198 
199  outpufile->Write();
200  outpufile->Close();
201  delete outpufile;
202 }
void Draw_th1d(TH1D *th1d_input, TString variable_name)
Definition: Zmumumerge.cc:125
static const int variables_number
Definition: Zmumumerge.cc:142
FitOut ZMassBinFit_OldTool(TH1D *th1d_input, TString s_name="zmumu_fitting", TString output_path="./")
Definition: Zmumumerge.cc:76
#define M_PI
const TString tstring_variables_name[variables_number]
Definition: Zmumumerge.cc:143
double mean
Definition: Zmumumerge.cc:68
double mean_err
Definition: Zmumumerge.cc:69

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 306 of file Zmumumerge.cc.

References dir2webdir::argc, GCPpyPlots::argv, and Zmumumerge().

306 { return Zmumumerge(argc, argv); }
int Zmumumerge(int argc, char *argv[])
Definition: Zmumumerge.cc:248

◆ makeNicePlotStyle()

void makeNicePlotStyle ( RooPlot *  plot)

Definition at line 47 of file Zmumumerge.cc.

References plotFactory::plot.

47  {
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);
60 }

◆ MuMu_mass()

RooRealVar MuMu_mass ( "MuMu_mass"  ,
"MuMu_mass"  ,
70  ,
110   
)

◆ ZMassBinFit_OldTool()

FitOut ZMassBinFit_OldTool ( TH1D *  th1d_input,
TString  s_name = "zmumu_fitting",
TString  output_path = "./" 
)

Definition at line 76 of file Zmumumerge.cc.

References alignmentValidation::c1, FitWithRooFit::fit(), FitWithRooFit::gamma(), FitWithRooFit::initA0(), FitWithRooFit::initA1(), FitWithRooFit::initA2(), FitWithRooFit::initA3(), FitWithRooFit::initA4(), FitWithRooFit::initA5(), FitWithRooFit::initA6(), FitWithRooFit::initAlpha(), FitWithRooFit::initExpCoeffA0(), FitWithRooFit::initExpCoeffA1(), FitWithRooFit::initExpCoeffA2(), FitWithRooFit::initFGCB(), FitWithRooFit::initFsig(), FitWithRooFit::initGamma(), FitWithRooFit::initMean(), FitWithRooFit::initMean2(), FitWithRooFit::initN(), FitWithRooFit::initSigma(), FitWithRooFit::initSigma2(), FitWithRooFit::mean(), FitWithRooFit::mean2(), FitWithRooFit::sigma(), FitWithRooFit::useChi2_, multiplicitycorr_cfi::xMax, and photonAnalyzer_cfi::xMin.

Referenced by Fitting_GetMassmeanVSvariables().

76  {
77  double xMin(75), xMax(105), xMean(91);
78  double sigma = 2;
79  double sigmaMin = 0.1;
80  double sigmaMax = 10;
81 
82  FitWithRooFit* fitter = new FitWithRooFit();
83  double sigma2(0.1), sigma2Min(0.), sigma2Max(10.), useChi2(false);
84  fitter->useChi2_ = useChi2;
85  fitter->initMean(xMean, xMin, xMax);
86  fitter->initSigma(sigma, sigmaMin, sigmaMax);
87  fitter->initSigma2(sigma2, sigma2Min, sigma2Max);
88  fitter->initAlpha(1.5, 0.05, 10.);
89  fitter->initN(1, 0.01, 100.);
90  fitter->initFGCB(0.4, 0., 1.);
91 
92  fitter->initMean(91.1876, xMin, xMax);
93  fitter->initGamma(2.4952, 0., 10.);
94  fitter->gamma()->setConstant(kTRUE);
95  fitter->initMean2(0., -20., 20.);
96  fitter->mean2()->setConstant(kTRUE);
97  fitter->initSigma(1.2, 0., 5.);
98  fitter->initAlpha(1.5, 0.05, 10.);
99  fitter->initN(1, 0.01, 100.);
100  fitter->initExpCoeffA0(-1., -10., 10.);
101  fitter->initExpCoeffA1(0., -10., 10.);
102  fitter->initExpCoeffA2(0., -2., 2.);
103  fitter->initFsig(0.9, 0., 1.);
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();
112  c1->Clear();
113  c1->SetLeftMargin(0.15);
114  c1->SetRightMargin(0.10);
115 
116  fitter->fit(th1d_input, "breitWignerTimesCB", "exponential", xMin, xMax, false);
117 
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()));
120 
121  FitOut fitRes(
122  fitter->mean()->getValV(), fitter->mean()->getError(), fitter->sigma()->getValV(), fitter->sigma()->getError());
123  return fitRes;
124 }
void initA6(const double &value, const double &min, const double &max, const TString &name="a6", const TString &title="a6")
RooRealVar * sigma()
void initA1(const double &value, const double &min, const double &max, const TString &name="a1", const TString &title="a1")
void initFsig(const double &value, const double &min, const double &max, const TString &name="fsig", const TString &title="signal fraction")
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")
void initA3(const double &value, const double &min, const double &max, const TString &name="a3", const TString &title="a3")
RooRealVar * mean()
RooRealVar * mean2()
void initA4(const double &value, const double &min, const double &max, const TString &name="a4", const TString &title="a4")
RooRealVar * gamma()
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")
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 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")

◆ Zmumumerge()

int Zmumumerge ( int  argc,
char *  argv[] 
)

Definition at line 248 of file Zmumumerge.cc.

References dir2webdir::argc, GCPpyPlots::argv, gather_cfg::cout, Draw_TH1D_forMultiRootFiles(), Fitting_GetMassmeanVSvariables(), mps_fire::i, AlcaSiPixelAliHarvester0T_cff::options, AlCaHLTBitMon_QueryRunRegistry::string, tstring_variables_name, and variables_number.

Referenced by main().

248  {
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;
255 
257  options.helper(argc, argv);
258  options.parser(argc, argv);
259  pt::ptree main_tree;
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"));
270 
271  //Fitting_GetMassmeanVSvariables(childTree.second.get<std::string>("file") + "/Zmumu.root", childTree.second.get<std::string>("file"));
272  }
273  TString merge_output = main_tree.get<std::string>("output");
274  //=============================================
275  vector<TString> vec_single_fittingoutput;
276  vec_single_fittingoutput.clear();
277  for (unsigned i = 0; i < vec_single_file_path.size(); i++) {
278  Fitting_GetMassmeanVSvariables(vec_single_file_name[i], vec_single_file_path[i]);
279  vec_single_fittingoutput.push_back(vec_single_file_path[i] + "/fitting_output.root");
280  }
281 
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++) {
285  TString th1d_name = Form("th1d_meanmass_%s", tstring_variables_name[idx_variable].Data());
287  vec_single_fittingoutput,
288  vec_title,
289  vec_color,
290  vec_style,
291  th1d_name,
292  merge_output + Form("/meanmass_%s_GTs.pdf", tstring_variables_name[idx_variable].Data()));
293  TString th1d_name_entries = Form("th1d_entries_%s", tstring_variables_name[idx_variable].Data());
295  vec_single_fittingoutput,
296  vec_title,
297  vec_color,
298  vec_style,
299  th1d_name_entries,
300  merge_output + Form("/entries_%s_GTs.pdf", tstring_variables_name[idx_variable].Data()));
301  }
302  //=============================================
303  return EXIT_SUCCESS;
304 }
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)
Definition: Zmumumerge.cc:205
static const int variables_number
Definition: Zmumumerge.cc:142
const TString tstring_variables_name[variables_number]
Definition: Zmumumerge.cc:143
void Fitting_GetMassmeanVSvariables(TString inputfile_name, TString output_path)
Definition: Zmumumerge.cc:145

Variable Documentation

◆ GT

TString GT = ""
static

Definition at line 64 of file Zmumumerge.cc.

Referenced by Draw_th1d().

◆ max_file_number

const int max_file_number = 10
static

Definition at line 204 of file Zmumumerge.cc.

Referenced by Draw_TH1D_forMultiRootFiles().

◆ tlxg

TLatex* tlxg = new TLatex()

Definition at line 65 of file Zmumumerge.cc.

Referenced by Draw_th1d().

◆ tstring_variables_name

const TString tstring_variables_name[variables_number]
Initial value:
= {
"CosThetaCS", "DeltaEta", "EtaMinus", "EtaPlus", "PhiCS", "PhiMinus", "PhiPlus", "Pt"}

Definition at line 143 of file Zmumumerge.cc.

Referenced by Fitting_GetMassmeanVSvariables(), and Zmumumerge().

◆ variables_number

const int variables_number = 8
static

Definition at line 142 of file Zmumumerge.cc.

Referenced by Fitting_GetMassmeanVSvariables(), and Zmumumerge().