CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
moduleOccupancyTrend.cc File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <TROOT.h>
#include <TStyle.h>
#include "TFile.h"
#include "THStack.h"
#include "TH1D.h"
#include "TDirectoryFile.h"
#include "TCanvas.h"
#include "TLine.h"
#include "TLegend.h"
#include "TRint.h"

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 17 of file moduleOccupancyTrend.cc.

References alignmentValidation::c1, gather_cfg::cout, alignCSCRings::e, harvestTrackValidationPlots::filelist, lut2db_cfg::filename, groupFilesInBlocks::fin, timingPdfMaker::histo, relval_2017::k, cmsLHEtoEOSManager::l, create_public_lumi_plots::leg, geometryCSVtoXML::line, bookConverter::max, min(), and AlCaHLTBitMon_QueryRunRegistry::string.

17  {
18 
19  gROOT->SetStyle("Plain");
20 
21  char* filelist;
22  char* modulelist;
23 
24  filelist= argv[1];
25  modulelist= argv[2];
26 
27  std::string detid;
28  std::string hn;
29 
30  TLegend leg(0.1,0.7,0.2,0.9);
31  leg.SetFillStyle(0);
32 
33  std::ifstream inmodules(modulelist);
34 
35  while(1){
36 
37  inmodules >> detid;
38  if (!inmodules.good()) break;
39 
40  hn="ClusterDigiPosition__det__" + detid;//std::to_string(detid);
41 
42  TCanvas c1("c1","c1",1600,900);
43 
44  c1.SetBatch(kTRUE);
45  c1.SetLogy(1);
46  c1.SetGridy(1);
47 
48  //cout << detid << endl;
49  std::ifstream fileToCountLines(filelist);
50  std::size_t lines_count =0;
52 
53  while (std::getline(fileToCountLines , line))
54  ++lines_count;
55 
56  const float dim=lines_count;
57 
58  std::ifstream filesin(filelist);
59 
61  int k=0;
62 
63  TH1D* trend=new TH1D("trend","trend",int(dim),0.5,dim+0.5);
64  trend->SetMarkerSize(3);
65  trend->SetMarkerStyle(8);
66  trend->SetMarkerColor(4);
67 
68  std::string ttitle=hn+"_trend";
69  trend->SetTitle(ttitle.c_str());
70 
71  double max=-1;
72  double min=1000000;
73 
74  leg.Clear();
75  TFile* fin;
76 
77  THStack *hs = new THStack("hs","");
78 
79 
80  while(1){
81 
82  filesin >> filename;
83  if (!filesin.good()) break;
84 
85  std::string runNum= filename.substr(filename.find("run_")+4, 6);
86  //std::cout << runNum << std::endl;
87 
88  fin=TFile::Open(filename.c_str());
89 
90  if (!fin) {std::cout << "Cannot open file " << filename.c_str() << std::endl;
91  return 0;
92  }
93 
94  TH1D* Events=(TH1D*)fin->Get("TotEvents");
95 
96  double EvtNum=Events->GetBinContent(1);
97 
98  TH1D* histo=(TH1D*) fin->Get(hn.c_str());
99 
100  if (!histo) {std::cout << "Cannot open histo " << hn.c_str() << std::endl;
101  return 0;
102  }
103 
104  histo->SetDirectory(0);
105  histo->SetStats(kFALSE);
106 
107  if (hn.find("Summary")==std::string::npos) histo->Scale(1/EvtNum);
108 
109  double numberPerEvent= histo->Integral();
110 
111 
112  if (max<=histo->GetBinContent(histo->GetMaximumBin())) max=histo->GetBinContent(histo->GetMaximumBin());
113  if (min>histo->GetBinContent(histo->GetMinimumBin())) min=histo->GetBinContent(histo->GetMinimumBin());
114 
115  histo->SetLineColor(k+1);
116  histo->SetMarkerStyle(9);
117  histo->SetMarkerColor(k+1);
118 
119 
120 
121 
122  trend->SetBinContent(k+1,numberPerEvent);
123  trend->GetXaxis()->SetBinLabel(k+1,runNum.c_str());
124 
125  leg.AddEntry(histo, runNum.c_str(), "L");
126  hs->Add(histo);
127  k++;
128 
129  fin->Close();
130  }
131 
132  if (min==0) min=1.e-6;
133 
134  max=max*10;// in a way one can read the legend
135 
136  hs->SetMaximum(max);
137  hs->SetMinimum(min);
138  hs->SetTitle(hn.c_str());
139 
140  hs->Draw("nostack");
141 
142  TLine l;
143 
144  l.SetLineColor(4);
145  l.SetLineStyle(2);
146  l.SetLineWidth(3);
147 
148  l.DrawLine(128,min,128,max);
149  l.DrawLine(256,min,256,max);
150  l.DrawLine(384,min,384,max);
151  l.DrawLine(384,min,384,max);
152  l.DrawLine(512,min,512,max);
153  l.DrawLine(640,min,640,max);
154 
155  leg.Draw();
156  std::string outname= hn+"_Super.png";
157  c1.SaveAs(outname.c_str());
158 
159  c1.SetGridx(1);
160 
161  double mintrend=0;
162  if (trend->GetMinimum()==0) mintrend=1.e-4;
163  else mintrend=trend->GetMinimum();
164 
165  trend->SetStats(kFALSE);
166 
167  trend->GetYaxis()->SetRangeUser(mintrend*0.5,trend->GetMaximum()*2);
168  trend->Draw("P");
169  outname=hn+"_Trend.png";
170  c1.SaveAs(outname.c_str());
171  c1.Clear();
172 
173  delete trend;
174 
175  }
176  return 0;
177 }
T min(T a, T b)
Definition: MathUtil.h:58
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:145