CMS 3D CMS Logo

Functions
OOTMultiplicityPlotMacros.cc File Reference
#include "OOTMultiplicityPlotMacros.h"
#include "DPGAnalysis/SiStripTools/interface/CommonAnalyzer.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "TF1.h"
#include "TProfile.h"
#include <iostream>
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Functions

OOTResultComputeOOTFraction (TFile *ff, const char *itmodule, const char *ootmodule, const char *etmodule, const int run, const char *hname, const bool &perFill)
 
OOTSummaryComputeOOTFractionvsFill (TFile *ff, const char *itmodule, const char *ootmodule, const char *etmodule, const char *hname, OOTSummary *ootsumm)
 
OOTSummaryComputeOOTFractionvsRun (TFile *ff, const char *itmodule, const char *ootmodule, const char *etmodule, const char *hname, OOTSummary *ootsumm)
 
std::vector< int > FillingScheme (TFile *ff, const char *path, const float thr)
 
std::vector< int > FillingSchemeFromProfile (TFile *ff, const char *path, const char *hname, const float thr)
 

Function Documentation

◆ ComputeOOTFraction()

OOTResult* ComputeOOTFraction ( TFile *  ff,
const char *  itmodule,
const char *  ootmodule,
const char *  etmodule,
const int  run,
const char *  hname,
const bool &  perFill 
)

Definition at line 83 of file OOTMultiplicityPlotMacros.cc.

89  {
90  if (perFill) {
91  std::cout << "Processing fill " << run << std::endl;
92  } else {
93  std::cout << "Processing run " << run << std::endl;
94  }
95 
96  char itpath[100];
97  char ootpath[100];
98  char etpath[100];
99  if (perFill) {
100  sprintf(itpath, "%s/fill_%d", itmodule, run);
101  sprintf(ootpath, "%s/fill_%d", ootmodule, run);
102  sprintf(etpath, "%s/fill_%d", etmodule, run);
103  } else {
104  sprintf(itpath, "%s/run_%d", itmodule, run);
105  sprintf(ootpath, "%s/run_%d", ootmodule, run);
106  sprintf(etpath, "%s/run_%d", etmodule, run);
107  }
108 
109  OOTResult* res = new OOTResult;
110 
111  std::vector<int> filledbx = FillingSchemeFromProfile(ff, itpath, hname);
112  res->nfilledbx = filledbx.size();
113 
114  if (!perFill) {
115  std::vector<int> filledbxtest = FillingScheme(ff, etpath);
116  if (filledbx.size() != filledbxtest.size())
117  std::cout << "Inconsistency in number of filled BX " << run << " " << filledbx.size() << " "
118  << filledbxtest.size() << std::endl;
119  }
120 
121  TProfile* itmult = nullptr;
122  TProfile* ootmult = nullptr;
123  res->hratio = new TH1F("ratio", "ratio", 200, 0., 2.);
124 
125  float rclzb = 0;
126  float rclrandom = 0;
127  float errclzb = 0;
128  float errclrandom = 0;
129  float nzb = 0;
130  float nrandom = 0;
131 
132  if (ff) {
133  if (ff->cd(itpath)) {
134  itmult = (TProfile*)gDirectory->Get(hname);
135  } else {
136  std::cout << "In time path is not ok" << std::endl;
137  }
138  if (ff->cd(ootpath)) {
139  ootmult = (TProfile*)gDirectory->Get(hname);
140  } else {
141  std::cout << "out of time path is not ok" << std::endl;
142  }
143  if (itmult && ootmult) {
144  ootmult->SetLineColor(kRed);
145  ootmult->SetMarkerColor(kRed);
146  // ootmult->Draw();
147  // itmult->Draw("same");
148  for (std::vector<int>::const_iterator fbx = filledbx.begin(); fbx != filledbx.end(); ++fbx) {
149  nzb += itmult->GetBinEntries(*fbx);
150  nrandom += ootmult->GetBinEntries(*fbx + 1);
151  }
152  for (std::vector<int>::const_iterator fbx = filledbx.begin(); fbx != filledbx.end(); ++fbx) {
153  if (nzb > 0 && nrandom > 0) {
154  rclzb += (itmult->GetBinContent(*fbx) * itmult->GetBinEntries(*fbx)) / nzb;
155  errclzb += (itmult->GetBinError(*fbx) * itmult->GetBinEntries(*fbx)) *
156  (itmult->GetBinError(*fbx) * itmult->GetBinEntries(*fbx)) / (nzb * nzb);
157  rclrandom += (ootmult->GetBinContent(*fbx + 1) * ootmult->GetBinEntries(*fbx + 1)) / nrandom;
158  errclrandom += (ootmult->GetBinError(*fbx + 1) * ootmult->GetBinEntries(*fbx + 1)) *
159  (ootmult->GetBinError(*fbx + 1) * ootmult->GetBinEntries(*fbx + 1)) / (nrandom * nrandom);
160  }
161  if (itmult->GetBinContent(*fbx) == 0) {
162  std::cout << "No cluster in filled BX! " << *fbx << std::endl;
163  } else if (ootmult->GetBinEntries(*fbx + 1) ==
164  0) { /* std::cout << "No entry in OOT BX " << *fbx+1 << std::endl; */
165  } else {
166  float rat = ootmult->GetBinContent(*fbx + 1) / itmult->GetBinContent(*fbx);
167  res->hratio->Fill(rat);
168  }
169  }
170  } else {
171  std::cout << "histograms not found" << std::endl;
172  }
173  } else {
174  std::cout << "Input file pointer is not ok" << std::endl;
175  }
176 
177  res->ngoodbx = res->hratio->GetEntries();
178 
179  if (nzb > 0 && nrandom > 0 && rclzb > 0 && rclrandom > 0) {
180  res->ootfracsum = rclrandom / rclzb;
181  res->ootfracsumerr = rclrandom / rclzb * sqrt(errclzb / (rclzb * rclzb) + errclrandom / (rclrandom * rclrandom));
182  }
183  if (res->ngoodbx) {
184  res->hratio->Fit("gaus", "Q0", "", .01, 1.99);
185  if (res->hratio->GetFunction("gaus")) {
186  res->ootfrac = res->hratio->GetFunction("gaus")->GetParameter(1);
187  res->ootfracerr = res->hratio->GetFunction("gaus")->GetParError(1);
188  } else {
189  std::cout << "Missing fitting function" << std::endl;
190  }
191  } else {
192  std::cout << "No filled BX or strange filling scheme" << std::endl;
193  }
194 
195  return res;
196 }

References gather_cfg::cout, alignCSCRings::ff, FillingScheme(), FillingSchemeFromProfile(), writedatasetfile::run, and mathSSE::sqrt().

Referenced by ComputeOOTFractionvsFill(), and ComputeOOTFractionvsRun().

◆ ComputeOOTFractionvsFill()

OOTSummary* ComputeOOTFractionvsFill ( TFile *  ff,
const char *  itmodule,
const char *  ootmodule,
const char *  etmodule,
const char *  hname,
OOTSummary ootsumm 
)

Definition at line 12 of file OOTMultiplicityPlotMacros.cc.

17  {
18  if (ootsumm == nullptr) {
19  ootsumm = new OOTSummary;
20  }
21 
22  if (ff) {
23  CommonAnalyzer ca(ff, "", itmodule);
24  std::vector<unsigned int> runs = ca.getFillList();
25  std::sort(runs.begin(), runs.end());
26  for (unsigned int i = 0; i < runs.size(); ++i) {
27  char runlabel[100];
28  sprintf(runlabel, "%d", runs[i]);
29 
30  OOTResult* res = ComputeOOTFraction(ff, itmodule, ootmodule, etmodule, runs[i], hname, true);
31 
32  if (res->ngoodbx != res->hratio->GetEntries())
33  std::cout << "Inconsistency in number of good bx" << std::endl;
34  ootsumm->hngoodbx->Fill(runlabel, res->ngoodbx);
35  int ibin = ootsumm->hootfracsum->Fill(runlabel, res->ootfracsum);
36  ootsumm->hootfracsum->SetBinError(ibin, res->ootfracsumerr);
37  int bin = ootsumm->hootfrac->Fill(runlabel, res->ootfrac);
38  ootsumm->hootfrac->SetBinError(bin, res->ootfracerr);
39  delete res;
40  }
41  } else {
42  std::cout << "File is not ok" << std::endl;
43  }
44 
45  return ootsumm;
46 }

References newFWLiteAna::bin, ComputeOOTFraction(), gather_cfg::cout, alignCSCRings::ff, CommonAnalyzer::getFillList(), OOTSummary::hngoodbx, OOTSummary::hootfrac, OOTSummary::hootfracsum, mps_fire::i, and writedatasetfile::runs.

◆ ComputeOOTFractionvsRun()

OOTSummary* ComputeOOTFractionvsRun ( TFile *  ff,
const char *  itmodule,
const char *  ootmodule,
const char *  etmodule,
const char *  hname,
OOTSummary ootsumm 
)

Definition at line 47 of file OOTMultiplicityPlotMacros.cc.

52  {
53  if (ootsumm == nullptr) {
54  ootsumm = new OOTSummary;
55  }
56 
57  if (ff) {
58  CommonAnalyzer ca(ff, "", itmodule);
59  std::vector<unsigned int> runs = ca.getRunList();
60  std::sort(runs.begin(), runs.end());
61  for (unsigned int i = 0; i < runs.size(); ++i) {
62  char runlabel[100];
63  sprintf(runlabel, "%d", runs[i]);
64 
65  OOTResult* res = ComputeOOTFraction(ff, itmodule, ootmodule, etmodule, runs[i], hname);
66 
67  if (res->ngoodbx != res->hratio->GetEntries())
68  std::cout << "Inconsistency in number of good bx" << std::endl;
69  ootsumm->hngoodbx->Fill(runlabel, res->ngoodbx);
70  int ibin = ootsumm->hootfracsum->Fill(runlabel, res->ootfracsum);
71  ootsumm->hootfracsum->SetBinError(ibin, res->ootfracsumerr);
72  int bin = ootsumm->hootfrac->Fill(runlabel, res->ootfrac);
73  ootsumm->hootfrac->SetBinError(bin, res->ootfracerr);
74  delete res;
75  }
76  } else {
77  std::cout << "File is not ok" << std::endl;
78  }
79 
80  return ootsumm;
81 }

References newFWLiteAna::bin, ComputeOOTFraction(), gather_cfg::cout, alignCSCRings::ff, CommonAnalyzer::getRunList(), OOTSummary::hngoodbx, OOTSummary::hootfrac, OOTSummary::hootfracsum, mps_fire::i, and writedatasetfile::runs.

◆ FillingScheme()

std::vector<int> FillingScheme ( TFile *  ff,
const char *  path,
const float  thr 
)

Definition at line 198 of file OOTMultiplicityPlotMacros.cc.

198  {
199  TH1F* bx = nullptr;
200  std::vector<int> filledbx;
201  if (ff) {
202  if (ff->cd(path)) {
203  bx = (TH1F*)gDirectory->Get("bx");
204  if (bx) {
205  // bx->Draw();
206  std::cout << "Number of entries " << bx->GetEntries() << " threshold " << thr / 3564. * bx->GetEntries()
207  << std::endl;
208  for (int i = 1; i < bx->GetNbinsX() + 1; ++i) {
209  if (bx->GetBinContent(i) > thr / 3564. * bx->GetEntries()) {
210  if (!filledbx.empty() && i == filledbx[filledbx.size() - 1] + 1) {
211  std::cout << "This is not a 50ns run ! " << std::endl;
212  filledbx.clear();
213  return filledbx;
214  }
215  filledbx.push_back(i);
216  }
217  }
218  } else {
219  std::cout << "Histogram not found" << std::endl;
220  }
221  } else {
222  std::cout << "module path is not ok" << std::endl;
223  }
224  } else {
225  std::cout << "Input file pointer is not ok" << std::endl;
226  }
227 
228  // std::cout << filledbx.size() << " filled bunch crossings" << std::endl;
229  // for(std::vector<int>::const_iterator fbx=filledbx.begin();fbx!=filledbx.end();++fbx) { std::cout << *fbx << std::endl;}
230  return filledbx;
231 }

References l1GtPatternGenerator_cfi::bx, gather_cfg::cout, alignCSCRings::ff, mps_fire::i, and castor_dqm_sourceclient_file_cfg::path.

Referenced by ComputeOOTFraction().

◆ FillingSchemeFromProfile()

std::vector<int> FillingSchemeFromProfile ( TFile *  ff,
const char *  path,
const char *  hname,
const float  thr 
)

Definition at line 232 of file OOTMultiplicityPlotMacros.cc.

232  {
233  TProfile* bx = nullptr;
234  std::vector<int> filledbx;
235  if (ff) {
236  if (ff->cd(path)) {
237  bx = (TProfile*)gDirectory->Get(hname);
238  if (bx) {
239  // bx->Draw();
240  std::cout << "Number of entries " << bx->GetEntries() << " threshold " << thr / 3564. * bx->GetEntries()
241  << std::endl;
242  for (int i = 1; i < bx->GetNbinsX() + 1; ++i) {
243  if (bx->GetBinEntries(i) > thr / 3564. * bx->GetEntries()) {
244  if (!filledbx.empty() && i == filledbx[filledbx.size() - 1] + 1) {
245  std::cout << "This is not a 50ns run ! " << std::endl;
246  filledbx.clear();
247  return filledbx;
248  }
249  filledbx.push_back(i);
250  }
251  }
252  } else {
253  std::cout << "Histogram not found" << std::endl;
254  }
255  } else {
256  std::cout << "module path is not ok" << std::endl;
257  }
258  } else {
259  std::cout << "Input file pointer is not ok" << std::endl;
260  }
261 
262  // std::cout << filledbx.size() << " filled bunch crossings" << std::endl;
263  // for(std::vector<int>::const_iterator fbx=filledbx.begin();fbx!=filledbx.end();++fbx) { std::cout << *fbx << std::endl;}
264  return filledbx;
265 }

References l1GtPatternGenerator_cfi::bx, gather_cfg::cout, alignCSCRings::ff, mps_fire::i, and castor_dqm_sourceclient_file_cfg::path.

Referenced by ComputeOOTFraction().

OOTResult
Definition: OOTMultiplicityPlotMacros.h:33
mps_fire.i
i
Definition: mps_fire.py:355
gather_cfg.cout
cout
Definition: gather_cfg.py:144
OOTSummary::hootfracsum
TH1F * hootfracsum
Definition: OOTMultiplicityPlotMacros.h:50
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
writedatasetfile.runs
runs
Definition: writedatasetfile.py:27
OOTSummary::hootfrac
TH1F * hootfrac
Definition: OOTMultiplicityPlotMacros.h:49
FillingSchemeFromProfile
std::vector< int > FillingSchemeFromProfile(TFile *ff, const char *path, const char *hname, const float thr)
Definition: OOTMultiplicityPlotMacros.cc:232
CommonAnalyzer
Definition: CommonAnalyzer.h:12
alignCSCRings.ff
ff
Definition: alignCSCRings.py:148
OOTSummary::hngoodbx
TH1F * hngoodbx
Definition: OOTMultiplicityPlotMacros.h:51
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
FillingScheme
std::vector< int > FillingScheme(TFile *ff, const char *path, const float thr)
Definition: OOTMultiplicityPlotMacros.cc:198
res
Definition: Electron.h:6
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
writedatasetfile.run
run
Definition: writedatasetfile.py:27
OOTSummary
Definition: OOTMultiplicityPlotMacros.h:47
ComputeOOTFraction
OOTResult * ComputeOOTFraction(TFile *ff, const char *itmodule, const char *ootmodule, const char *etmodule, const int run, const char *hname, const bool &perFill)
Definition: OOTMultiplicityPlotMacros.cc:83
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37