CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

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

Definition at line 203 of file StatisticsPlots.cc.

References gather_cfg::cout, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), estimatePileup::hist, i, mps_fire::result, gather_cfg::runs, and CommonAnalyzer::setPath().

203  {
204 
205  CommonAnalyzer castat(&ff,"",module);
206 
207  TH2F* result = 0;
208 
209  std::vector<unsigned int> runs = castat.getRunList();
210  std::sort(runs.begin(),runs.end());
211 
212  {
213  for(unsigned int i=0;i<runs.size();++i) {
214 
215  char runlabel[100];
216  sprintf(runlabel,"%d",runs[i]);
217  char runpath[100];
218  sprintf(runpath,"run_%d",runs[i]);
219  castat.setPath(runpath);
220 
221  TH2F* hist = (TH2F*)castat.getObject(histname);
222 
223  if(hist) {
224  if(result==0) {
225  result = new TH2F(*hist);
226  result->Reset();
227  }
228  result->Add(hist);
229  std::cout << hist->GetTitle() << " added: " << hist->GetEntries() << " " << result->GetEntries() << std::endl;
230  }
231 
232  }
233  }
234 
235  return result;
236 
237 }
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: mps_fire.py:95
tuple runs
Definition: gather_cfg.py:87
tuple cout
Definition: gather_cfg.py:145
Definition: vlib.h:208
TH1F* CombinedHisto ( TFile &  ff,
const char *  module,
const char *  histname 
)

Definition at line 76 of file StatisticsPlots.cc.

References gather_cfg::cout, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), estimatePileup::hist, i, mps_fire::result, gather_cfg::runs, and CommonAnalyzer::setPath().

76  {
77 
78  CommonAnalyzer castat(&ff,"",module);
79 
80  TH1F* result = 0;
81 
82  std::vector<unsigned int> runs = castat.getRunList();
83  std::sort(runs.begin(),runs.end());
84 
85  {
86  for(unsigned int i=0;i<runs.size();++i) {
87 
88  char runlabel[100];
89  sprintf(runlabel,"%d",runs[i]);
90  char runpath[100];
91  sprintf(runpath,"run_%d",runs[i]);
92  castat.setPath(runpath);
93 
94  TH1F* hist = (TH1F*)castat.getObject(histname);
95 
96  if(hist) {
97  if(result==0) {
98  result = new TH1F(*hist);
99  result->Reset();
100  }
101  result->Add(hist);
102  std::cout << hist->GetTitle() << " added: " << hist->GetEntries() << " " << result->GetEntries() << std::endl;
103  }
104 
105  }
106  }
107 
108  return result;
109 
110 }
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: mps_fire.py:95
tuple runs
Definition: gather_cfg.py:87
tuple cout
Definition: gather_cfg.py:145
Definition: vlib.h:208
void DeadTimeAPVCycle ( TH1F *  hist,
const std::vector< int > &  bins 
)

Definition at line 17 of file StatisticsPlots.cc.

References gather_cfg::cout, and i.

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

Definition at line 241 of file StatisticsPlots.cc.

References gather_cfg::cout, HILowLumiHLTOfflineSource_cfi::dirname, alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), i, cmsHarvester::nevents, gather_cfg::runs, CommonAnalyzer::setPath(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 142 of file StatisticsPlots.cc.

References CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), i, cmsHarvester::nevents, gather_cfg::runs, and CommonAnalyzer::setPath().

Referenced by SummaryHistoRatio(), and SummaryHistoRatioGraph().

142  {
143 
144  CommonAnalyzer castat(&ff,"",module);
145 
146  TH1D* nevents = new TH1D("nevents","Number of events vs run",10,0.,10.);
147  nevents->SetCanExtend(TH1::kXaxis);
148 
149  std::vector<unsigned int> runs = castat.getRunList();
150  std::sort(runs.begin(),runs.end());
151 
152  {
153  for(unsigned int i=0;i<runs.size();++i) {
154 
155  char runlabel[100];
156  sprintf(runlabel,"%d",runs[i]);
157  char runpath[100];
158  sprintf(runpath,"run_%d",runs[i]);
159  castat.setPath(runpath);
160 
161 
162  TH1F* orbit=0;
163  if(orbit==0) orbit = (TH1F*)castat.getObject("orbit");
164  if(orbit) {
165  // fill the summary
166  nevents->Fill(runlabel,orbit->GetEntries());
167  }
168  }
169  }
170  return nevents;
171 
172 }
int i
Definition: DBlmapReader.cc:9
tuple runs
Definition: gather_cfg.py:87
Definition: vlib.h:208
TH1D* SummaryHistoRatio ( TFile &  f1,
const char *  mod1,
TFile &  f2,
const char *  mod2,
const char *  hname 
)

Definition at line 174 of file StatisticsPlots.cc.

References SummaryHisto().

174  {
175 
176  TH1D* denom = SummaryHisto(f1,mod1);
177  TH1D* numer = SummaryHisto(f2,mod2);
178 
179  TH1D* ratio = (TH1D*)denom->Clone(hname);
180  ratio->SetTitle("Fraction of events vs run");
181  ratio->Sumw2();
182  ratio->Reset();
183  ratio->SetDirectory(0);
184  ratio->Divide(numer,denom,1,1,"b");
185 
186  return ratio;
187 
188 }
TH1D * SummaryHisto(TFile &ff, const char *module)
TGraphAsymmErrors* SummaryHistoRatioGraph ( TFile &  f1,
const char *  mod1,
TFile &  f2,
const char *  mod2,
const char *   
)

Definition at line 190 of file StatisticsPlots.cc.

References SummaryHisto().

190  {
191 
192  TH1D* denom = SummaryHisto(f1,mod1);
193  TH1D* numer = SummaryHisto(f2,mod2);
194 
195  TGraphAsymmErrors* ratio = new TGraphAsymmErrors;;
196 
197  ratio->BayesDivide(numer,denom);
198 
199  return ratio;
200 
201 }
TH1D * SummaryHisto(TFile &ff, const char *module)
TH1F* TimeRatio ( TFile &  ff,
const char *  modulen,
const char *  moduled,
const int  irun,
const int  rebin 
)

Definition at line 112 of file StatisticsPlots.cc.

References CommonAnalyzer::getObject(), and CommonAnalyzer::setPath().

112  {
113 
114  CommonAnalyzer castatn(&ff,"",modulen);
115  CommonAnalyzer castatd(&ff,"",moduled);
116 
117 
118  char runlabel[100];
119  sprintf(runlabel,"%d",irun);
120  char runpath[100];
121  sprintf(runpath,"run_%d",irun);
122  castatn.setPath(runpath);
123  castatd.setPath(runpath);
124 
125  TH1F* ratio = 0;
126 
127  TH1F* orbitn=0;
128  if(orbitn==0) orbitn = (TH1F*)castatn.getObject("orbit");
129  TH1F* orbitd=0;
130  if(orbitd==0) orbitd = (TH1F*)castatd.getObject("orbit");
131  if(orbitn != 0 && orbitd != 0) {
132  orbitn->Rebin(rebin);
133  orbitd->Rebin(rebin);
134  ratio = new TH1F(*orbitd);
135  ratio->Reset();
136  ratio->Divide(orbitn,orbitd);
137  }
138  return ratio;
139 
140 }