CMS 3D CMS Logo

Functions
StatisticsPlots.cc File Reference
#include "StatisticsPlots.h"
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include "TPad.h"
#include "TH1D.h"
#include "TFile.h"
#include "TH2F.h"
#include "TH1F.h"
#include "TText.h"
#include "DPGAnalysis/SiStripTools/interface/CommonAnalyzer.h"
#include "TCanvas.h"
#include "TGraphAsymmErrors.h"

Go to the source code of this file.

Functions

TH2F * Combined2DHisto (TFile &ff, const char *module, const char *histname)
 
TH1F * CombinedHisto (TFile &ff, const char *module, const char *histname)
 
void DeadTimeAPVCycle (TH1F *hist, const std::vector< int > &bins)
 
void StatisticsPlots (const char *fullname, const char *module, const char *label, const char *postfix, const char *shortname, const char *outtrunk)
 
TH1D * SummaryHisto (TFile &ff, const char *module)
 
TH1D * SummaryHistoRatio (TFile &f1, const char *mod1, TFile &f2, const char *mod2, const char *hname)
 
TGraphAsymmErrors * SummaryHistoRatioGraph (TFile &f1, const char *mod1, TFile &f2, const char *mod2, const char *)
 
TH1F * TimeRatio (TFile &ff, const char *modulen, const char *moduled, const int irun, const int rebin)
 

Function Documentation

◆ Combined2DHisto()

TH2F* Combined2DHisto ( TFile &  ff,
const char *  module,
const char *  histname 
)

Definition at line 189 of file StatisticsPlots.cc.

References gather_cfg::cout, alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), compareTotals::hist, mps_fire::i, callgraph::module, mps_fire::result, writedatasetfile::runs, CommonAnalyzer::setPath(), and jetUpdater_cfi::sort.

189  {
190  CommonAnalyzer castat(&ff, "", module);
191 
192  TH2F* result = nullptr;
193 
194  std::vector<unsigned int> runs = castat.getRunList();
195  std::sort(runs.begin(), runs.end());
196 
197  {
198  for (unsigned int i = 0; i < runs.size(); ++i) {
199  char runlabel[100];
200  sprintf(runlabel, "%d", runs[i]);
201  char runpath[100];
202  sprintf(runpath, "run_%d", runs[i]);
203  castat.setPath(runpath);
204 
205  TH2F* hist = (TH2F*)castat.getObject(histname);
206 
207  if (hist) {
208  if (result == nullptr) {
209  result = new TH2F(*hist);
210  result->Reset();
211  }
212  result->Add(hist);
213  std::cout << hist->GetTitle() << " added: " << hist->GetEntries() << " " << result->GetEntries() << std::endl;
214  }
215  }
216  }
217 
218  return result;
219 }

◆ CombinedHisto()

TH1F* CombinedHisto ( TFile &  ff,
const char *  module,
const char *  histname 
)

Definition at line 72 of file StatisticsPlots.cc.

References gather_cfg::cout, alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), compareTotals::hist, mps_fire::i, callgraph::module, mps_fire::result, writedatasetfile::runs, CommonAnalyzer::setPath(), and jetUpdater_cfi::sort.

72  {
73  CommonAnalyzer castat(&ff, "", module);
74 
75  TH1F* result = nullptr;
76 
77  std::vector<unsigned int> runs = castat.getRunList();
78  std::sort(runs.begin(), runs.end());
79 
80  {
81  for (unsigned int i = 0; i < runs.size(); ++i) {
82  char runlabel[100];
83  sprintf(runlabel, "%d", runs[i]);
84  char runpath[100];
85  sprintf(runpath, "run_%d", runs[i]);
86  castat.setPath(runpath);
87 
88  TH1F* hist = (TH1F*)castat.getObject(histname);
89 
90  if (hist) {
91  if (result == nullptr) {
92  result = new TH1F(*hist);
93  result->Reset();
94  }
95  result->Add(hist);
96  std::cout << hist->GetTitle() << " added: " << hist->GetEntries() << " " << result->GetEntries() << std::endl;
97  }
98  }
99  }
100 
101  return result;
102 }

◆ DeadTimeAPVCycle()

void DeadTimeAPVCycle ( TH1F *  hist,
const std::vector< int > &  bins 
)

Definition at line 17 of file StatisticsPlots.cc.

References trigObjTnPSource_cfi::bins, gather_cfg::cout, dqmMemoryStats::float, compareTotals::hist, mps_fire::i, and HcalSpecialTimes::isSpecial().

17  {
18  float ntotodd = 0;
19  float ntoteven = 0;
20  float nspecialodd = 0;
21  float nspecialeven = 0;
22  unsigned int nbintotodd = 0;
23  unsigned int nbintoteven = 0;
24  unsigned int nbinspecialodd = 0;
25  unsigned int nbinspecialeven = 0;
26 
27  for (int i = 1; i < hist->GetNbinsX() + 1; ++i) {
28  bool isSpecial = false;
29  for (unsigned int special = 0; special < bins.size(); ++special) {
30  if (i == bins[special]) {
31  isSpecial = true;
32  break;
33  }
34  }
35 
36  if (i % 2 == 0) {
37  if (isSpecial) {
38  ++nbinspecialeven;
39  nspecialeven += hist->GetBinContent(i);
40  } else {
41  ++nbintoteven;
42  ntoteven += hist->GetBinContent(i);
43  }
44  } else {
45  if (isSpecial) {
46  ++nbinspecialodd;
47  nspecialodd += hist->GetBinContent(i);
48  } else {
49  ++nbintotodd;
50  ntotodd += hist->GetBinContent(i);
51  }
52  }
53  }
54  std::cout << "Summary" << std::endl;
55  std::cout << "Odd events " << ntotodd << " special " << nspecialodd << std::endl;
56  std::cout << "Odd bins " << nbintotodd << " special " << nbinspecialodd << std::endl;
57  std::cout << "Odd bins populations" << float(ntotodd) / nbintotodd << " special "
58  << float(nspecialodd) / nbinspecialodd << std::endl;
59  std::cout << "Even events " << ntoteven << " special " << nspecialeven << std::endl;
60  std::cout << "Even bins " << nbintoteven << " special " << nbinspecialeven << std::endl;
61  std::cout << "Even bins populations" << float(ntoteven) / nbintoteven << " special "
62  << float(nspecialeven) / nbinspecialeven << std::endl;
63 
64  float oddloss = nspecialodd - nbinspecialodd * ntotodd / nbintotodd;
65  float evenloss = nspecialeven - nbinspecialeven * ntoteven / nbintoteven;
66 
67  float fracloss = (oddloss + evenloss) / (ntotodd + ntoteven + nspecialodd + nspecialeven);
68 
69  std::cout << "Loss " << oddloss << " " << evenloss << " " << fracloss << std::endl;
70 }
constexpr bool isSpecial(const float t)

◆ StatisticsPlots()

void StatisticsPlots ( const char *  fullname,
const char *  module,
const char *  label,
const char *  postfix,
const char *  shortname,
const char *  outtrunk 
)

Definition at line 221 of file StatisticsPlots.cc.

References l1GtPatternGenerator_cfi::bx, gather_cfg::cout, BTVHLTOfflineSource_cfi::dirname, alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), mps_fire::i, label, callgraph::module, createIOVlist::nevents, writedatasetfile::runs, CommonAnalyzer::setPath(), jetUpdater_cfi::sort, and AlCaHLTBitMon_QueryRunRegistry::string.

226  {
227  char modfull[300];
228  sprintf(modfull, "%s%s", module, postfix);
229  char labfull[300];
230  sprintf(labfull, "%s%s", label, postfix);
231 
232  char dirname[400];
233  sprintf(dirname, "%s", shortname);
234 
235  // char fullname[300];
236  // if(strlen(family)==0) { sprintf(fullname,"rootfiles/Tracking_PFG_%s.root",filename);}
237  // else { sprintf(fullname,"rootfiles/%s.root",dirname); }
238 
239  TFile ff(fullname);
240 
241  // Colliding events
242 
243  /*
244  char modname[300];
245  sprintf(modname,"trackcount%s",postfix);
246 
247  CommonAnalyzer castatall(&ff,"",modname);
248 
249  TH1F* ntrk = (TH1F*)castatall.getObject("ntrk");
250  if (ntrk) {
251  std::cout << " All runs " << ntrk->GetEntries() << std::endl;
252  delete ntrk;
253  }
254  */
255 
256  // sprintf(modname,"eventtimedistribution%s",postfix);
257 
258  CommonAnalyzer castat(&ff, "", modfull);
259 
260  // Summary histograms
261 
262  TH1D* nevents = new TH1D("nevents", "Number of events vs run", 10, 0., 10.);
263  nevents->SetCanExtend(TH1::kXaxis);
264 
265  std::vector<unsigned int> runs = castat.getRunList();
266  std::sort(runs.begin(), runs.end());
267 
268  {
269  std::cout << "Collision Events" << std::endl;
270 
271  for (unsigned int i = 0; i < runs.size(); ++i) {
272  char runlabel[100];
273  sprintf(runlabel, "%d", runs[i]);
274  char runpath[100];
275  sprintf(runpath, "run_%d", runs[i]);
276  castat.setPath(runpath);
277 
278  TH1* orbit = nullptr;
279  TH2F* orbitvsbx = (TH2F*)castat.getObject("orbitvsbxincycle");
280  if (orbitvsbx == nullptr)
281  orbitvsbx = (TH2F*)castat.getObject("orbitvsbx");
282  if (orbitvsbx) {
283  std::cout << runpath << " " << orbitvsbx->GetEntries() << std::endl;
284  // prepare plot
285  new TCanvas;
286  if (orbitvsbx->GetEntries() > 0) {
287  orbit = orbitvsbx->ProjectionY();
288  }
289  delete orbitvsbx;
290  }
291  if (orbit == nullptr)
292  orbit = (TH1F*)castat.getObject("orbit");
293  if (orbit) {
294  orbit->GetXaxis()->SetTitle("orbit");
295  orbit->SetTitle(runpath);
296  //normalize to get the rate
297  orbit->Scale(11223, "width");
298  orbit->GetYaxis()->SetTitle("Rate (Hz)");
299  // fill the summary
300  nevents->Fill(runlabel, orbit->GetEntries());
301 
302  //
303  orbit->Draw();
304  std::string plotfilename;
305  plotfilename += outtrunk;
306  plotfilename += dirname;
307  plotfilename += "/orbit_";
308  plotfilename += labfull;
309  plotfilename += "_";
310  plotfilename += dirname;
311  plotfilename += "_";
312  plotfilename += runpath;
313  plotfilename += ".gif";
314  gPad->Print(plotfilename.c_str());
315  delete orbit;
316  }
317 
318  TH1F* dbx = (TH1F*)castat.getObject("dbx");
319  if (dbx) {
320  // prepare plot
321  if (dbx->GetEntries() > 0) {
322  dbx->Draw();
323  gPad->SetLogy(1);
324  std::string plotfilename;
325  plotfilename += outtrunk;
326  plotfilename += dirname;
327  plotfilename += "/dbx_";
328  plotfilename += labfull;
329  plotfilename += "_";
330  plotfilename += dirname;
331  plotfilename += "_";
332  plotfilename += runpath;
333  plotfilename += ".gif";
334  gPad->Print(plotfilename.c_str());
335  delete dbx;
336  }
337  gPad->SetLogy(0);
338  }
339  TH1F* bx = (TH1F*)castat.getObject("bx");
340  if (bx) {
341  // prepare plot
342  if (bx->GetEntries() > 0) {
343  bx->SetLineColor(kRed);
344  bx->Draw();
345  gPad->SetLogy(1);
346  std::string plotfilename;
347  plotfilename += outtrunk;
348  plotfilename += dirname;
349  plotfilename += "/bx_";
350  plotfilename += labfull;
351  plotfilename += "_";
352  plotfilename += dirname;
353  plotfilename += "_";
354  plotfilename += runpath;
355  plotfilename += ".gif";
356  gPad->Print(plotfilename.c_str());
357  delete bx;
358  }
359  gPad->SetLogy(0);
360  }
361  }
362  }
363 
364  if (!runs.empty()) {
365  std::string plotfilename;
366  plotfilename = outtrunk;
367  plotfilename += dirname;
368  plotfilename += "/nevents_";
369  plotfilename += labfull;
370  plotfilename += "_";
371  plotfilename += dirname;
372  plotfilename += ".gif";
373 
374  TCanvas* cwide = new TCanvas(plotfilename.c_str(), plotfilename.c_str(), 1500, 500);
375  nevents->Draw();
376 
377  char nentries[100];
378  sprintf(nentries, "%.0f", nevents->GetSumOfWeights());
379  TText ttlabel;
380  ttlabel.DrawTextNDC(.8, .7, nentries);
381 
382  std::cout << nentries << std::endl;
383 
384  gPad->Print(plotfilename.c_str());
385  delete cwide;
386  }
387  delete nevents;
388 
389  ff.Close();
390 }
char const * label

◆ SummaryHisto()

TH1D* SummaryHisto ( TFile &  ff,
const char *  module 
)

Definition at line 133 of file StatisticsPlots.cc.

References alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), mps_fire::i, callgraph::module, createIOVlist::nevents, writedatasetfile::runs, CommonAnalyzer::setPath(), and jetUpdater_cfi::sort.

Referenced by SummaryHistoRatio(), and SummaryHistoRatioGraph().

133  {
134  CommonAnalyzer castat(&ff, "", module);
135 
136  TH1D* nevents = new TH1D("nevents", "Number of events vs run", 10, 0., 10.);
137  nevents->SetCanExtend(TH1::kXaxis);
138 
139  std::vector<unsigned int> runs = castat.getRunList();
140  std::sort(runs.begin(), runs.end());
141 
142  {
143  for (unsigned int i = 0; i < runs.size(); ++i) {
144  char runlabel[100];
145  sprintf(runlabel, "%d", runs[i]);
146  char runpath[100];
147  sprintf(runpath, "run_%d", runs[i]);
148  castat.setPath(runpath);
149 
150  TH1F* orbit = nullptr;
151  if (orbit == nullptr)
152  orbit = (TH1F*)castat.getObject("orbit");
153  if (orbit) {
154  // fill the summary
155  nevents->Fill(runlabel, orbit->GetEntries());
156  }
157  }
158  }
159  return nevents;
160 }

◆ SummaryHistoRatio()

TH1D* SummaryHistoRatio ( TFile &  f1,
const char *  mod1,
TFile &  f2,
const char *  mod2,
const char *  hname 
)

Definition at line 162 of file StatisticsPlots.cc.

References makePileupJSON::denom, DeadROC_duringRun::f1, DeadROC_duringRun::f2, particleFlowDisplacedVertex_cfi::ratio, and SummaryHisto().

162  {
163  TH1D* denom = SummaryHisto(f1, mod1);
164  TH1D* numer = SummaryHisto(f2, mod2);
165 
166  TH1D* ratio = (TH1D*)denom->Clone(hname);
167  ratio->SetTitle("Fraction of events vs run");
168  ratio->Sumw2();
169  ratio->Reset();
170  ratio->SetDirectory(nullptr);
171  ratio->Divide(numer, denom, 1, 1, "b");
172 
173  return ratio;
174 }
TH1D * SummaryHisto(TFile &ff, const char *module)

◆ SummaryHistoRatioGraph()

TGraphAsymmErrors* SummaryHistoRatioGraph ( TFile &  f1,
const char *  mod1,
TFile &  f2,
const char *  mod2,
const char *   
)

Definition at line 176 of file StatisticsPlots.cc.

References makePileupJSON::denom, DeadROC_duringRun::f1, DeadROC_duringRun::f2, particleFlowDisplacedVertex_cfi::ratio, and SummaryHisto().

177  {
178  TH1D* denom = SummaryHisto(f1, mod1);
179  TH1D* numer = SummaryHisto(f2, mod2);
180 
181  TGraphAsymmErrors* ratio = new TGraphAsymmErrors;
182  ;
183 
184  ratio->BayesDivide(numer, denom);
185 
186  return ratio;
187 }
TH1D * SummaryHisto(TFile &ff, const char *module)

◆ TimeRatio()

TH1F* TimeRatio ( TFile &  ff,
const char *  modulen,
const char *  moduled,
const int  irun,
const int  rebin 
)

Definition at line 104 of file StatisticsPlots.cc.

References alignCSCRings::ff, CommonAnalyzer::getObject(), particleFlowDisplacedVertex_cfi::ratio, and CommonAnalyzer::setPath().

104  {
105  CommonAnalyzer castatn(&ff, "", modulen);
106  CommonAnalyzer castatd(&ff, "", moduled);
107 
108  char runlabel[100];
109  sprintf(runlabel, "%d", irun);
110  char runpath[100];
111  sprintf(runpath, "run_%d", irun);
112  castatn.setPath(runpath);
113  castatd.setPath(runpath);
114 
115  TH1F* ratio = nullptr;
116 
117  TH1F* orbitn = nullptr;
118  if (orbitn == nullptr)
119  orbitn = (TH1F*)castatn.getObject("orbit");
120  TH1F* orbitd = nullptr;
121  if (orbitd == nullptr)
122  orbitd = (TH1F*)castatd.getObject("orbit");
123  if (orbitn != nullptr && orbitd != nullptr) {
124  orbitn->Rebin(rebin);
125  orbitd->Rebin(rebin);
126  ratio = new TH1F(*orbitd);
127  ratio->Reset();
128  ratio->Divide(orbitn, orbitd);
129  }
130  return ratio;
131 }