CMS 3D CMS Logo

SiPixelPhase1Summary.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1Summary
4 // Class: SiPixelPhase1Summary
5 //
13 //
14 // Original Author: Duncan Leggat
15 // Created: 5th December 2016
16 //
17 //
19 // Framework
23 // DQM Framework
26 // Geometry
32 // DataFormats
39 //
40 #include <string>
41 #include <cstdlib>
42 #include <iostream>
43 #include <fstream>
44 #include <sstream>
45 
46 using namespace std;
47 using namespace edm;
48 
50  conf_(iConfig),
51  firstLumi(true)
52 {
53 
54  LogInfo ("PixelDQM") << "SiPixelPhase1Summary::SiPixelPhase1Summary: Got DQM BackEnd interface"<<endl;
55  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
56  runOnEndLumi_ = conf_.getParameter<bool>("RunOnEndLumi");
57  runOnEndJob_ = conf_.getParameter<bool>("RunOnEndJob");
58 
59  std::vector<edm::ParameterSet> mapPSets = conf_.getParameter<std::vector<edm::ParameterSet> >("SummaryMaps");
60 
61  //Go through the configuration file and add in
62  for (auto const mapPSet : mapPSets){
63  summaryPlotName_[mapPSet.getParameter<std::string>("MapName")] = mapPSet.getParameter<std::string>("MapHist");
64  }
65  deadRocThresholds_ = conf_.getParameter<std::vector<double> >("DeadROCErrorThreshold");
66 }
67 
69 {
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72  LogInfo ("PixelDQM") << "SiPixelPhase1Summary::~SiPixelPhase1Summary: Destructor"<<endl;
73 }
74 
76 }
77 
79  if (firstLumi){
80  bookSummaries(iBooker);
81  bookTrendPlots(iBooker);
82  firstLumi = false;
83  }
84 
85  if (runOnEndLumi_){
86  int lumiSec = lumiSeg.id().luminosityBlock();
87  fillTrendPlots(iBooker,iGetter,lumiSec);
88  fillSummaries(iBooker,iGetter);
89  }
90 
91  // iBooker.cd();
92 
93 }
94 
95 //------------------------------------------------------------------
96 // Method called for every event
97 //------------------------------------------------------------------
99 {
100  if (firstLumi){ //Book the plots in the (maybe possible?) case that they aren't booked in the dqmEndLuminosityBlock method
101  bookSummaries(iBooker);
102  bookTrendPlots(iBooker);
103  firstLumi = false;
104  }
105  if (runOnEndJob_){
106  if (!runOnEndLumi_) fillTrendPlots(iBooker,iGetter); //If we're filling these plots at the end lumi step, it doesn't really make sense to also do them at the end job
107  fillSummaries(iBooker,iGetter);
108 
109  }
110 
111 }
112 
113 //------------------------------------------------------------------
114 // Used to book the summary plots
115 //------------------------------------------------------------------
117 
118  iBooker.cd();
119 
120  std::vector<std::string> xAxisLabels_ = {"BMO","BMI","BPO ","BPI","HCMO_1","HCMO_2","HCMI_1","HCMI_2","HCPO_1","HCPO_2","HCPI_1","HCPI_2"}; // why not having a global variable !?!?!?!
121  std::vector<std::string> yAxisLabels_ = {"1","2","3","4"}; // why not having a global variable ?!?!?!!? - I originally did, but was told not to by David Lange!
122 
123  iBooker.setCurrentFolder("PixelPhase1/Summary");
124  //Book the summary plots for the variables as described in the config file
125  for (auto mapInfo: summaryPlotName_){
126  auto name = mapInfo.first;
127  summaryMap_[name] = iBooker.book2D("pixel"+name+"Summary","Pixel "+name+" Summary",12,0,12,4,0,4);
128  }
129  //Make the new 6 bin ROC summary
130  deadROCSummary = iBooker.book2D("deadROCSummary","Percentage of dead ROCs per layer/ring",2,0,2,4,0,4);
131  std::vector<std::string> xAxisLabelsReduced_ = {"Barrel","Forward"};
132  deadROCSummary->setAxisTitle("Subdetector",1);
133  for (unsigned int i = 0; i < xAxisLabelsReduced_.size(); i++){
134  deadROCSummary->setBinLabel(i+1,xAxisLabelsReduced_[i]);
135  }
136 
137  //Book the summary plot
138  iBooker.setCurrentFolder("PixelPhase1/EventInfo");
139 
140  if (runOnEndLumi_){
141  //New less granular summary plot - this is currently only done online
142  summaryMap_["Grand"] = iBooker.book2D("reportSummaryMap","Pixel Summary Map",2,0,2,4,0,4);
143  summaryMap_["Grand"]->setAxisTitle("Subdetector",1);
144  for (unsigned int i = 0; i < xAxisLabelsReduced_.size(); i++){
145  summaryMap_["Grand"]->setBinLabel(i+1,xAxisLabelsReduced_[i]);
146  for (unsigned int j = 0; j < 4; j++){ summaryMap_["Grand"]->setBinContent(i,j,-1);}
147  }
148  }
149  else{
150  //Book the original summary plot, for now juts doing this one offline.
151  summaryMap_["Grand"] = iBooker.book2D("reportSummaryMap","Pixel Summary Map",12,0,12,4,0,4);
152  }
153 
154  reportSummary = iBooker.bookFloat("reportSummary");
155 
156 
157  //Now set up axis and bin labels
158  for (auto summaryMapEntry: summaryMap_){
159  if (summaryMapEntry.first == "Grand") continue;
160  auto summaryMap = summaryMapEntry.second;
161  for (unsigned int i = 0; i < xAxisLabels_.size(); i++){
162  summaryMap->setBinLabel(i+1, xAxisLabels_[i],1);
163  }
164  for (unsigned int i = 0; i < yAxisLabels_.size(); i++){
165  summaryMap->setBinLabel(i+1,yAxisLabels_[i],2);
166  }
167  summaryMap->setAxisTitle("Subdetector",1);
168  summaryMap->setAxisTitle("Layer/disk",2);
169  for (int i = 0; i < summaryMap->getTH1()->GetXaxis()->GetNbins(); i++){ // !??!?!? xAxisLabels_.size() ?!?!
170  for (int j = 0; j < summaryMap->getTH1()->GetYaxis()->GetNbins(); j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
171  summaryMap->Fill(i,j,-1.);
172  }
173  }
174  }
175  reportSummary->Fill(-1.);
176 
177  //Reset the iBooker
178  iBooker.setCurrentFolder("PixelPhase1/");
179 }
180 
181 //------------------------------------------------------------------
182 // Used to book the trend plots
183 //------------------------------------------------------------------
185  //We need different plots depending on if we're online (runOnEndLumi) or offline (!runOnEndLumi)
186  iBooker.setCurrentFolder("PixelPhase1/");
187  std::vector<string> binAxisLabels = {"Layer 1", "Layer 2", "Layer 3", "Layer 4", "Ring 1", "Ring 2"};
188  if (runOnEndLumi_){
189  std::vector<trendPlots> histoOrder = {layer1,layer2,layer3,layer4,ring1,ring2};
190  std::vector<string> varName ={"Layer_1","Layer_2","Layer_3","Layer_4","Ring_1","Ring_2"};
191  std::vector<int> yMax = {1536,3584,5632,8192,4224,6528};
192  for (unsigned int i = 0; i < histoOrder.size(); i++){
193  string varNameStr = "deadRocTrend"+varName[i];
194  string varTitle = binAxisLabels[i]+" dead ROC trend";
195  deadROCTrends_[histoOrder[i]] = iBooker.bookProfile(varNameStr,varTitle,500,0.,5000,0.,yMax[i],"");
196  varNameStr = "ineffRocTrend"+varName[i];
197  varTitle = binAxisLabels[i]+" inefficient ROC trend";
198  ineffROCTrends_[histoOrder[i]] = iBooker.bookProfile(varNameStr,varTitle,500,0.,5000,0.,yMax[i],"");
199  deadROCTrends_[histoOrder[i]]->setAxisTitle("Lumisection",1);
200  ineffROCTrends_[histoOrder[i]]->setAxisTitle("Lumisection",1);
201  }
202  }
203  else {
204  deadROCTrends_[offline] = iBooker.bookProfile("deadRocTotal","N dead ROCs",6,0,6,0.,8192,"");
205  ineffROCTrends_[offline] = iBooker.bookProfile("ineffRocTotal","N inefficient ROCs",6,0,6,0.,8192,"");
206  deadROCTrends_[offline]->setAxisTitle("Subdetector",1);
207  ineffROCTrends_[offline]->setAxisTitle("Subdetector",1);
208  for (unsigned int i = 1; i <= binAxisLabels.size(); i++){
209  deadROCTrends_[offline]->setBinLabel(i,binAxisLabels[i-1]);
210  ineffROCTrends_[offline]->setBinLabel(i,binAxisLabels[i-1]);
211  }
212  }
213 
214 }
215 
216 //------------------------------------------------------------------
217 // Fill the summary histograms
218 //------------------------------------------------------------------
220  //Firstly, we will fill the regular summary maps.
221  for (auto mapInfo: summaryPlotName_){
222  auto name = mapInfo.first;
223  std::ostringstream histNameStream;
224  std::string histName;
225 
226  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
227  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
228  if (i > 3 && j == 3) continue;
229  bool minus = i < 2 || (i > 3 && i < 8); // bleah !
230  int iOver2 = floor(i/2.);
231  bool outer = (i > 3)?iOver2%2==0:i%2==0;
232  //Complicated expression that creates the name of the histogram we are interested in.
233  histNameStream.str("");
234  histNameStream << topFolderName_.c_str() << "PX" << ((i > 3)?"Forward":"Barrel") << "/" << ((i > 3)?"HalfCylinder":"Shell") << "_" << (minus?"m":"p") << ((outer)?"O":"I") << "/" << ((i > 3)?((i%2 == 0)?"PXRing_1/":"PXRing_2/"):"") << summaryPlotName_[name].c_str() << "_PX" << ((i > 3)?"Disk":"Layer") << "_" << ((i>3)?((minus)?"-":"+"):"") << (j+1);
235  histName = histNameStream.str();
236  MonitorElement * me = iGetter.get(histName);
237 
238  if (!me) {
239  edm::LogWarning("SiPixelPhase1Summary") << "ME " << histName << " is not available !!";
240  continue; // Ignore non-existing MEs, as this can cause the whole thing to crash
241  }
242 
243  if (summaryMap_[name]==nullptr){
244  edm::LogWarning("SiPixelPhase1Summary") << "Summary map " << name << " is not available !!";
245  continue; // Based on reported errors it seems possible that we're trying to access a non-existant summary map, so if the map doesn't exist but we're trying to access it here we'll skip it instead.
246  }
247  if (!(me->getQReports()).empty()) summaryMap_[name]->setBinContent(i+1,j+1,(me->getQReports())[0]->getQTresult());
248  else summaryMap_[name]->setBinContent(i+1,j+1,-1);
249  }
250  }
251  }
252 
253  //Fill the dead ROC summary
254  std::vector<trendPlots> trendOrder = {layer1,layer2,layer3,layer4,ring1,ring2};
255  std::vector<int> nRocsPerTrend = {1536,3584,5632,8192,4224,6528};
256  for (unsigned int i = 0; i < trendOrder.size(); i++){
257  int xBin = i < 4 ? 1 : 2;
258  int yBin = i%4 + 1;
259  float nROCs = 0.;
260  if (runOnEndLumi_){ //Online case
261  TH1 * tempProfile = deadROCTrends_[trendOrder[i]]->getTH1();
262  nROCs = tempProfile->GetBinContent(tempProfile->FindLastBinAbove());
263  }
264  else { //Offline case
265  TH1* tempProfile = deadROCTrends_[offline]->getTH1();
266  nROCs = tempProfile->GetBinContent(i+1);
267  }
268  deadROCSummary->setBinContent(xBin,yBin,nROCs/nRocsPerTrend[i]);
269  }
270 
271  //Sum of non-negative bins for the reportSummary
272  float sumOfNonNegBins = 0.;
273  //Now we will use the other summary maps to create the overall map.
274  //For now we only want to do this offline
275  if (!runOnEndLumi_){
276  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
277  if (summaryMap_["Grand"]==nullptr){
278  edm::LogWarning("SiPixelPhase1Summary") << "Grand summary does not exist!";
279  break;
280  }
281  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
282  summaryMap_["Grand"]->setBinContent(i+1,j+1,1); // This resets the map to be good. We only then set it to 0 if there has been a problem in one of the other summaries.
283  for (auto const mapInfo: summaryPlotName_){ //Check summary maps
284  auto name = mapInfo.first;
285  if (summaryMap_[name]==nullptr){
286  edm::LogWarning("SiPixelPhase1Summary") << "Summary " << name << " does not exist!";
287  continue;
288  }
289  if (summaryMap_["Grand"]->getBinContent(i+1,j+1) > summaryMap_[name]->getBinContent(i+1,j+1)) summaryMap_["Grand"]->setBinContent(i+1,j+1,summaryMap_[name]->getBinContent(i+1,j+1));
290  }
291  if (summaryMap_["Grand"]->getBinContent(i+1,j+1) > -0.1) sumOfNonNegBins += summaryMap_["Grand"]->getBinContent(i+1,j+1);
292  }
293  }
294  reportSummary->Fill(sumOfNonNegBins/40.); // The average of the 40 useful bins in the summary map.
295  }
296 
297  //Fill the new overall map
298  // if (!runOnEndLumi_) return;
299  else{ //Do this for online only
300  for (int i = 0; i < 2; i++){
301  if (summaryMap_["Grand"]==nullptr){
302  edm::LogWarning("SiPixelPhase1Summary") << "Grand summary does not exist!";
303  break;
304  }
305  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
306  //Ignore the bins without detectors in them
307  if (i == 1 && j > 1) continue;
308  summaryMap_["Grand"]->setBinContent(i+1,j+1,1); // This resets the map to be good. We only then set it to 0 if there has been a problem in one of the other summaries.
309  if (deadROCSummary->getBinContent(i+1,j+1) > deadRocThresholds_[i*4+j]) summaryMap_["Grand"]->setBinContent(i+1,j+1,0);
310  sumOfNonNegBins += summaryMap_["Grand"]->getBinContent(i+1,j+1);
311  }
312  }
313  }
314 
315 }
316 
317 //------------------------------------------------------------------
318 // Fill the trend plots
319 //------------------------------------------------------------------
321 
322  // If we're running in online mode and the lumi section is not modulo 10, return. Offline running always uses lumiSec=0, so it will pass this test.
323  if (lumiSec%10 != 0) return;
324 
325  if (runOnEndLumi_) {
326  MonitorElement * nClustersAll = iGetter.get("PixelPhase1/Phase1_MechanicalView/num_clusters_per_Lumisection_PXAll");
327  if (nClustersAll==nullptr){
328  edm::LogWarning("SiPixelPhase1Summary") << "All pixel cluster trend plot not available!!";
329  return;
330  }
331  if (nClustersAll->getTH1()->GetBinContent(lumiSec) < 100) return;
332  }
333 
334  std::string histName;
335 
336  //Find the total number of filled bins and hi efficiency bins
337  std::vector<trendPlots> trendOrder = {layer1,layer2,layer3,layer4,ring1,ring2};
338  std::vector<int> nFilledROCs(trendOrder.size(),0);
339  std::vector<int> hiEffROCs(trendOrder.size(),0);
340  std::vector<int> nRocsPerTrend = {1536,3584,5632,8192,4224,6528};
341  std::vector<string> trendNames = {};
342 
343  for (auto it : {1,2,3,4}) {
344  histName = "PXBarrel/digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_" + std::to_string(it);
345  trendNames.push_back(histName);
346  }
347  for (auto it : {1,2}) {
348  histName = "PXForward/digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_" + std::to_string(it);
349  trendNames.push_back(histName);
350  }
351  //Loop over layers. This will also do the rings, but we'll skip the ring calculation for
352  for (unsigned int trendIt = 0; trendIt < trendOrder.size(); trendIt++){
353  iGetter.cd();
354  histName = "PixelPhase1/Phase1_MechanicalView/" + trendNames[trendIt];
355  MonitorElement * tempLayerME = iGetter.get(histName);
356  if (tempLayerME==nullptr) continue;
357  float lowEffValue = 0.25 * (tempLayerME->getTH1()->Integral() / nRocsPerTrend[trendIt]);
358  for (int i=1; i<=tempLayerME->getTH1()->GetXaxis()->GetNbins(); i++){
359  for (int j=1; j<=tempLayerME->getTH1()->GetYaxis()->GetNbins(); j++){
360  if (tempLayerME->getBinContent(i,j) > 0.) nFilledROCs[trendIt]++;
361  if (tempLayerME->getBinContent(i,j) > lowEffValue) hiEffROCs[trendIt]++;
362  }
363  }
364  if (runOnEndLumi_) {
365  tempLayerME->Reset(); //If we're doing online monitoring, reset the digi maps.
366  }
367  } // Close layers/ring loop
368 
369  if (!runOnEndLumi_) { //offline
370  for (unsigned int i = 0; i < trendOrder.size(); i++){
371  deadROCTrends_[offline]->Fill(i,nRocsPerTrend[i]-nFilledROCs[i]);
372  ineffROCTrends_[offline]->Fill(i,nFilledROCs[i]-hiEffROCs[i]);
373  }
374  }
375  else { //online
376  for (unsigned int i = 0; i < trendOrder.size(); i++){
377  deadROCTrends_[trendOrder[i]]->Fill(lumiSec-1,nRocsPerTrend[i]-nFilledROCs[i]);
378  ineffROCTrends_[trendOrder[i]]->Fill(lumiSec-1,nFilledROCs[i]-hiEffROCs[i]);
379  }
380  }
381 
382  if (!runOnEndLumi_) return; // The following only occurs in the online
383  //Reset some MEs every 10LS here
384  for (auto it : {1,2,3,4}) { //PXBarrel
385  histName = "PixelPhase1/Phase1_MechanicalView/PXBarrel/clusterposition_zphi_PXLayer_" +std::to_string(it);
386  MonitorElement * toReset = iGetter.get(histName);
387  if (toReset!=nullptr) {
388  toReset->Reset();
389  }
390  }
391  for (auto it : {"-3","-2","-1","+1","+2","+3"}){ //PXForward
392  histName = "PixelPhase1/Phase1_MechanicalView/PXForward/clusterposition_xy_PXDisk_" + std::string(it);
393  MonitorElement * toReset = iGetter.get(histName);
394  if (toReset!=nullptr) {
395  toReset->Reset();
396  }
397  }
398 
399 }
400 
401 //define this as a plug-in
LuminosityBlockID id() const
T getParameter(std::string const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
SiPixelPhase1Summary(const edm::ParameterSet &conf)
std::map< std::string, std::string > summaryPlotName_
MonitorElement * deadROCSummary
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< trendPlots, MonitorElement * > deadROCTrends_
TH1 * getTH1() const
void fillSummaries(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
std::map< trendPlots, MonitorElement * > ineffROCTrends_
void fillTrendPlots(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, int lumiSeg=0)
void Fill(long long x)
std::map< std::string, MonitorElement * > summaryMap_
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
edm::ParameterSet conf_
void bookTrendPlots(DQMStore::IBooker &iBooker)
void Reset()
reset ME (ie. contents, errors, etc)
MonitorElement * reportSummary
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
LuminosityBlockNumber_t luminosityBlock() const
std::vector< QReport * > getQReports() const
get map of QReports
void dqmEndJob(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) override
double getBinContent(int binx) const
get content of bin (1-D)
HLT enums.
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:112
void bookSummaries(DQMStore::IBooker &iBooker)
void dqmEndLuminosityBlock(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c) override
std::vector< double > deadRocThresholds_
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
yBin
Definition: cuy.py:892
Definition: Run.h:44