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 "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>
#include "Alignment/OfflineValidation/interface/FitWithRooFit.h"

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 126 of file Zmumumerge.cc.

References HltBtagPostValidation_cff::c, GT, and tlxg.

Referenced by Fitting_GetMassmeanVSvariables().

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

◆ 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 206 of file Zmumumerge.cc.

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

Referenced by Zmumumerge().

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

◆ Fitting_GetMassmeanVSvariables()

void Fitting_GetMassmeanVSvariables ( TString  inputfile_name,
TString  output_path 
)

Definition at line 146 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().

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

◆ main()

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

Definition at line 307 of file Zmumumerge.cc.

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

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

◆ makeNicePlotStyle()

void makeNicePlotStyle ( RooPlot *  plot)

Definition at line 48 of file Zmumumerge.cc.

References plotFactory::plot.

48  {
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);
61 }

◆ 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 77 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().

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

◆ Zmumumerge()

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

Definition at line 249 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().

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

Variable Documentation

◆ GT

TString GT = ""
static

Definition at line 65 of file Zmumumerge.cc.

Referenced by Draw_th1d().

◆ max_file_number

const int max_file_number = 10
static

Definition at line 205 of file Zmumumerge.cc.

Referenced by Draw_TH1D_forMultiRootFiles().

◆ tlxg

TLatex* tlxg = new TLatex()

Definition at line 66 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 144 of file Zmumumerge.cc.

Referenced by Fitting_GetMassmeanVSvariables(), and Zmumumerge().

◆ variables_number

const int variables_number = 8
static

Definition at line 143 of file Zmumumerge.cc.

Referenced by Fitting_GetMassmeanVSvariables(), and Zmumumerge().