CMS 3D CMS Logo

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