CMS 3D CMS Logo

APVValidationPlots.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <memory>
4 #include <sstream>
5 #include <vector>
6 
7 // user include files
19 
20 // ROOT includes
21 #include "TCanvas.h"
22 #include "TFile.h"
23 #include "TH1.h"
24 #include "TH1D.h"
25 #include "TH1F.h"
26 #include "TH2F.h"
27 #include "TProfile.h"
28 #include "TStyle.h"
29 #include "TTree.h"
30 
31 //
32 // class decleration
33 //
34 
36 public:
39 
40  explicit APVValidationPlots(const edm::ParameterSet&);
41 
42 private:
43  void analyze(const edm::Event&, const edm::EventSetup&) override;
44  void endJob() override;
45 
48 
49  // ----------member data ---------------------------
50 };
51 
52 //
53 // constructors and destructor
54 //
56  : infilename(iConfig.getUntrackedParameter<std::string>("inputFilename", "in.root")),
57  outfilename(iConfig.getUntrackedParameter<std::string>("outputFilename", "out.root"))
58 
59 {
60  //now do what ever initialization is needed
61 }
62 
63 //
64 // member functions
65 //
66 
67 // ------------ method called to for each event ------------
69 
70 // ------------ method called once each job just after ending the event loop ------------
72  std::ostringstream oss;
73  oss << 1; //runNumber
74 
76  dqmStore->setCurrentFolder("ChannelStatusPlots");
77 
78  // Initialize histograms
79  std::vector<std::string> subDetName;
80  std::vector<unsigned int> nLayers;
81  std::vector<std::string> layerName;
82  subDetName.push_back("");
83  subDetName.push_back("TIB");
84  subDetName.push_back("TID");
85  subDetName.push_back("TOB");
86  subDetName.push_back("TEC");
87  nLayers.push_back(0);
88  nLayers.push_back(4);
89  nLayers.push_back(3);
90  nLayers.push_back(6);
91  nLayers.push_back(9);
92  layerName.push_back("");
93  layerName.push_back("Layer");
94  layerName.push_back("Disk");
95  layerName.push_back("Layer");
96  layerName.push_back("Disk");
97 
99  std::string histoTitle;
100  // Histograms
101  // indexes in these arrays are [SubDetId-2][LayerN]
102  // histograms for [SubDetId-2][0] are global for the subdetector
103  // histogram for [0][0] is global for the tracker
104  TH2F* medianVsAbsoluteOccupancy[5][10];
105  TH1F* medianOccupancy[5][10];
106  TH1F* absoluteOccupancy[5][10];
107  for (unsigned int i = 0; i < subDetName.size(); i++) {
108  for (unsigned int j = 0; j <= nLayers[i]; j++) {
109  histoName = "medianVsAbsoluteOccupancy" + subDetName[i];
110  if (j != 0) {
111  oss.str("");
112  oss << j;
113  histoName += layerName[i] + oss.str();
114  }
115  histoTitle = "Median APV occupancy vs. absolute APV occupancy";
116  if (i != 0)
117  histoTitle += " in " + subDetName[i];
118  if (j != 0) {
119  histoTitle += " " + layerName[i] + " " + oss.str();
120  }
121  MonitorElement* tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6., 1000, -1., 3.);
122  medianVsAbsoluteOccupancy[i][j] = tmp->getTH2F();
123  medianVsAbsoluteOccupancy[i][j]->Rebin2D(10, 10);
124  medianVsAbsoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Abs. Occupancy)");
125  medianVsAbsoluteOccupancy[i][j]->GetYaxis()->SetTitle("log_{10}(Median Occupancy)");
126  //
127  histoName = "medianOccupancy" + subDetName[i];
128  if (j != 0) {
129  oss.str("");
130  oss << j;
131  histoName += layerName[i] + oss.str();
132  }
133  histoTitle = "Median APV occupancy";
134  if (i != 0)
135  histoTitle += " in " + subDetName[i];
136  if (j != 0) {
137  histoTitle += " " + layerName[i] + " " + oss.str();
138  }
139  tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -1., 3.);
140  medianOccupancy[i][j] = tmp->getTH1F();
141  medianOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
142  medianOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
143  //
144  histoName = "absoluteOccupancy" + subDetName[i];
145  if (j != 0) {
146  oss.str("");
147  oss << j;
148  histoName += layerName[i] + oss.str();
149  }
150  histoTitle = "Absolute APV occupancy";
151  if (i != 0)
152  histoTitle += " in " + subDetName[i];
153  if (j != 0) {
154  histoTitle += " " + layerName[i] + " " + oss.str();
155  }
156  tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6.);
157  absoluteOccupancy[i][j] = tmp->getTH1F();
158  absoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
159  absoluteOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
160  }
161  }
162 
163  TFile* infile = new TFile(infilename.c_str(), "READ");
164  TTree* intree = (TTree*)infile->Get("moduleOccupancy");
165 
166  // Declaration of leaf types
167  Int_t DetRawId;
168  Int_t SubDetId;
169  Int_t Layer_Ring;
170  Int_t Disc;
171  Int_t IsBack;
172  Int_t IsExternalString;
173  Int_t IsZMinusSide;
174  Int_t RodStringPetal;
175  Int_t IsStereo;
176  Int_t ModulePosition;
177  Int_t NumberOfStrips;
178  Float_t APVGlobalPositionX;
179  Float_t APVGlobalPositionY;
180  Float_t APVGlobalPositionZ;
181  Int_t APVNumber;
182  Int_t APVAbsoluteOccupancy;
183  Double_t APVMedianOccupancy;
184  intree->SetBranchAddress("DetRawId", &DetRawId);
185  intree->SetBranchAddress("SubDetId", &SubDetId);
186  intree->SetBranchAddress("Layer_Ring", &Layer_Ring);
187  intree->SetBranchAddress("Disc", &Disc);
188  intree->SetBranchAddress("IsBack", &IsBack);
189  intree->SetBranchAddress("IsExternalString", &IsExternalString);
190  intree->SetBranchAddress("IsZMinusSide", &IsZMinusSide);
191  intree->SetBranchAddress("RodStringPetal", &RodStringPetal);
192  intree->SetBranchAddress("IsStereo", &IsStereo);
193  intree->SetBranchAddress("ModuleNumber", &ModulePosition);
194  intree->SetBranchAddress("NumberOfStrips", &NumberOfStrips);
195  intree->SetBranchAddress("APVGlobalPositionX", &APVGlobalPositionX);
196  intree->SetBranchAddress("APVGlobalPositionY", &APVGlobalPositionY);
197  intree->SetBranchAddress("APVGlobalPositionZ", &APVGlobalPositionZ);
198  intree->SetBranchAddress("APVNumber", &APVNumber);
199  intree->SetBranchAddress("APVAbsoluteOccupancy", &APVAbsoluteOccupancy);
200  intree->SetBranchAddress("APVMedianOccupancy", &APVMedianOccupancy);
201 
202  for (int i = 0; i < intree->GetEntries(); i++) {
203  intree->GetEntry(i);
204 
205  double logMedianOccupancy = -1;
206  double logAbsoluteOccupancy = -1;
207 
208  if (APVMedianOccupancy > 0)
209  logMedianOccupancy = log10(APVMedianOccupancy);
210  if (APVAbsoluteOccupancy > 0)
211  logAbsoluteOccupancy = log10(APVAbsoluteOccupancy);
212 
213  // The layer/disk information is stored in Layer_Ring for TIB/TOB and in Disc for TID/TEC
214  unsigned int layer = 0;
215  if (SubDetId == 3 || SubDetId == 5)
216  layer = Layer_Ring;
217  else
218  layer = Disc;
219 
220  // Fill histograms for all the tracker
221  medianVsAbsoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy, logMedianOccupancy);
222  medianOccupancy[0][0]->Fill(logMedianOccupancy);
223  absoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy);
224  // Fill summary histograms for each subdetector
225  medianVsAbsoluteOccupancy[SubDetId - 2][0]->Fill(logAbsoluteOccupancy, logMedianOccupancy);
226  medianOccupancy[SubDetId - 2][0]->Fill(logMedianOccupancy);
227  absoluteOccupancy[SubDetId - 2][0]->Fill(logAbsoluteOccupancy);
228  // Fill histograms for each layer/disk
229  medianVsAbsoluteOccupancy[SubDetId - 2][layer]->Fill(logAbsoluteOccupancy, logMedianOccupancy);
230  medianOccupancy[SubDetId - 2][layer]->Fill(logMedianOccupancy);
231  absoluteOccupancy[SubDetId - 2][layer]->Fill(logAbsoluteOccupancy);
232  }
233 
234  dqmStore->cd();
235  dqmStore->save(outfilename, "ChannelStatusPlots");
236 }
237 
238 //define this as a plug-in
dqm::legacy::DQMStore DQMStore
const std::string infilename
const std::string outfilename
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
int iEvent
Definition: GenABIO.cc:224
void endJob() override
dqm::legacy::MonitorElement MonitorElement
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
APVValidationPlots(const edm::ParameterSet &)
void analyze(const edm::Event &, const edm::EventSetup &) override
tmp
align.sh
Definition: createJobs.py:716