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