test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
APVValidationPlots.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
12 
14 
19 
22 
23 #include "TH1F.h"
24 #include "TFile.h"
25 #include "TCanvas.h"
26 #include "TH1.h"
27 #include "TH2F.h"
28 #include "TH1D.h"
29 #include "TProfile.h"
30 #include "TStyle.h"
31 #include "TTree.h"
32 
33 #include <sstream>
34 #include <iostream>
35 #include <vector>
36 
37 //
38 // class decleration
39 //
40 
42  public:
43  explicit APVValidationPlots(const edm::ParameterSet&);
45 
46 
47  private:
48  virtual void beginJob() override ;
49  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
50  virtual void endJob() override ;
51 
52  std::ostringstream oss;
53 
55 
57 
58  // Histograms
59  // indexes in these arrays are [SubDetId-2][LayerN]
60  // histograms for [SubDetId-2][0] are global for the subdetector
61  // histogram for [0][0] is global for the tracker
62 
64  TH1F* medianOccupancy[5][10];
65  TH1F* absoluteOccupancy[5][10];
66 
67  std::vector<std::string> subDetName;
68  std::vector<unsigned int> nLayers;
69  std::vector<std::string> layerName;
70 
73 
74  TFile* infile;
75  TTree* intree;
76 
77  // Declaration of leaf types
78  Int_t DetRawId;
79  Int_t SubDetId;
80  Int_t Layer_Ring;
81  Int_t Disc;
82  Int_t IsBack;
84  Int_t IsZMinusSide;
86  Int_t IsStereo;
92  Int_t APVNumber;
95 
96 
97 
98  // ----------member data ---------------------------
99 };
100 
101 //
102 // constants, enums and typedefs
103 //
104 
105 //
106 // static data member definitions
107 //
108 
109 //
110 // constructors and destructor
111 //
112 APVValidationPlots::APVValidationPlots(const edm::ParameterSet& iConfig) : infilename(iConfig.getUntrackedParameter<std::string>("inputFilename","in.root")),
113  outfilename(iConfig.getUntrackedParameter<std::string>("outputFilename","out.root"))
114 
115 {
116  //now do what ever initialization is needed
117 
118 }
119 
120 
122 {
123 
124  // do anything here that needs to be done at desctruction time
125  // (e.g. close files, deallocate resources etc.)
126 
127 }
128 
129 
130 //
131 // member functions
132 //
133 
134 // ------------ method called to for each event ------------
135 void
137 {
138 
139 }
140 
141 
142 // ------------ method called once each job just before starting event loop ------------
143 void
145 {
146  oss.str("");
147  oss << 1; //runNumber
148 
150  dqmStore->setCurrentFolder("ChannelStatusPlots");
151 
152  // Initialize histograms
153  subDetName.push_back(""); subDetName.push_back("TIB"); subDetName.push_back("TID"); subDetName.push_back("TOB"); subDetName.push_back("TEC");
154  nLayers.push_back(0); nLayers.push_back(4); nLayers.push_back(3); nLayers.push_back(6); nLayers.push_back(9);
155  layerName.push_back(""); layerName.push_back("Layer"); layerName.push_back("Disk"); layerName.push_back("Layer"); layerName.push_back("Disk");
156 
157  std::string histoName;
158  std::string histoTitle;
159  for(unsigned int i = 0; i < subDetName.size(); i++)
160  {
161  for(unsigned int j = 0; j <= nLayers[i]; j++)
162  {
163  histoName = "medianVsAbsoluteOccupancy" + subDetName[i];
164  if(j!=0)
165  {
166  oss.str("");
167  oss << j;
168  histoName += layerName[i] + oss.str();
169  }
170  histoTitle = "Median APV occupancy vs. absolute APV occupancy";
171  if(i!=0)
172  histoTitle += " in " + subDetName[i];
173  if(j!=0)
174  {
175  histoTitle += " " + layerName[i] + " " + oss.str();
176  }
177  tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6., 1000, -1., 3.);
179  medianVsAbsoluteOccupancy[i][j]->Rebin2D(10,10);
180  medianVsAbsoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Abs. Occupancy)");
181  medianVsAbsoluteOccupancy[i][j]->GetYaxis()->SetTitle("log_{10}(Median Occupancy)");
182  //
183  histoName = "medianOccupancy" + subDetName[i];
184  if(j!=0)
185  {
186  oss.str("");
187  oss << j;
188  histoName += layerName[i] + oss.str();
189  }
190  histoTitle = "Median APV occupancy";
191  if(i!=0)
192  histoTitle += " in " + subDetName[i];
193  if(j!=0)
194  {
195  histoTitle += " " + layerName[i] + " " + oss.str();
196  }
197  tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -1., 3.);
198  medianOccupancy[i][j] = tmp->getTH1F();
199  medianOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
200  medianOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
201  //
202  histoName = "absoluteOccupancy" + subDetName[i];
203  if(j!=0)
204  {
205  oss.str("");
206  oss << j;
207  histoName += layerName[i] + oss.str();
208  }
209  histoTitle = "Absolute APV occupancy";
210  if(i!=0)
211  histoTitle += " in " + subDetName[i];
212  if(j!=0)
213  {
214  histoTitle += " " + layerName[i] + " " + oss.str();
215  }
216  tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6.);
218  absoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
219  absoluteOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
220  }
221  }
222 
223 }
224 
225 // ------------ method called once each job just after ending the event loop ------------
226 void
228 
229  infile = new TFile(infilename.c_str(),"READ");
230  intree = (TTree*)infile->Get("moduleOccupancy");
231 
232  intree->SetBranchAddress("DetRawId", &DetRawId);
233  intree->SetBranchAddress("SubDetId", &SubDetId);
234  intree->SetBranchAddress("Layer_Ring", &Layer_Ring);
235  intree->SetBranchAddress("Disc", &Disc);
236  intree->SetBranchAddress("IsBack", &IsBack);
237  intree->SetBranchAddress("IsExternalString", &IsExternalString);
238  intree->SetBranchAddress("IsZMinusSide", &IsZMinusSide);
239  intree->SetBranchAddress("RodStringPetal", &RodStringPetal);
240  intree->SetBranchAddress("IsStereo", &IsStereo);
241  intree->SetBranchAddress("ModuleNumber", &ModulePosition);
242  intree->SetBranchAddress("NumberOfStrips", &NumberOfStrips);
243  intree->SetBranchAddress("APVGlobalPositionX", &APVGlobalPositionX);
244  intree->SetBranchAddress("APVGlobalPositionY", &APVGlobalPositionY);
245  intree->SetBranchAddress("APVGlobalPositionZ", &APVGlobalPositionZ);
246  intree->SetBranchAddress("APVNumber", &APVNumber);
247  intree->SetBranchAddress("APVAbsoluteOccupancy", &APVAbsoluteOccupancy);
248  intree->SetBranchAddress("APVMedianOccupancy", &APVMedianOccupancy);
249 
250  for (int i=0; i<intree->GetEntries(); i++)
251  {
252  intree->GetEntry(i);
253 
254  double logMedianOccupancy = -1;
255  double logAbsoluteOccupancy = -1;
256 
257  if (APVMedianOccupancy>0) logMedianOccupancy = log10(APVMedianOccupancy);
258  if (APVAbsoluteOccupancy>0) logAbsoluteOccupancy = log10(APVAbsoluteOccupancy);
259 
260  // The layer/disk information is stored in Layer_Ring for TIB/TOB and in Disc for TID/TEC
261  unsigned int layer = 0;
262  if(SubDetId==3 || SubDetId==5)
263  layer=Layer_Ring;
264  else
265  layer=Disc;
266 
267  // Fill histograms for all the tracker
268  medianVsAbsoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
269  medianOccupancy[0][0]->Fill(logMedianOccupancy);
270  absoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy);
271  // Fill summary histograms for each subdetector
272  medianVsAbsoluteOccupancy[SubDetId-2][0]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
273  medianOccupancy[SubDetId-2][0]->Fill(logMedianOccupancy);
274  absoluteOccupancy[SubDetId-2][0]->Fill(logAbsoluteOccupancy);
275  // Fill histograms for each layer/disk
276  medianVsAbsoluteOccupancy[SubDetId-2][layer]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
277  medianOccupancy[SubDetId-2][layer]->Fill(logMedianOccupancy);
278  absoluteOccupancy[SubDetId-2][layer]->Fill(logAbsoluteOccupancy);
279  }
280 
281  dqmStore->cd();
282  dqmStore->save(outfilename.c_str(),"ChannelStatusPlots");
283 
284 }
285 
286 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > subDetName
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:1017
TH1F * medianOccupancy[5][10]
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:700
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * tmp
TH2F * medianVsAbsoluteOccupancy[5][10]
std::ostringstream oss
int iEvent
Definition: GenABIO.cc:230
virtual void endJob() override
int j
Definition: DBlmapReader.cc:9
std::vector< std::string > layerName
APVValidationPlots(const edm::ParameterSet &)
TH1F * getTH1F(void) const
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2632
std::vector< unsigned int > nLayers
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1145
TH1F * absoluteOccupancy[5][10]
virtual void beginJob() override
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:723