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 
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  fillSummaries(iBooker,iGetter);
87  int lumiSec = lumiSeg.id().luminosityBlock();
88  fillTrendPlots(iBooker,iGetter,lumiSec);
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  fillSummaries(iBooker,iGetter);
107  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
108  }
109 
110 }
111 
112 //------------------------------------------------------------------
113 // Used to book the summary plots
114 //------------------------------------------------------------------
116 
117  iBooker.cd();
118 
119  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 !?!?!?!
120  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!
121 
122  iBooker.setCurrentFolder("PixelPhase1/Summary");
123  //Book the summary plots for the variables as described in the config file
124  for (auto mapInfo: summaryPlotName_){
125  auto name = mapInfo.first;
126  summaryMap_[name] = iBooker.book2D("pixel"+name+"Summary","Pixel "+name+" Summary",12,0,12,4,0,4);
127  }
128  //Now book the overall summary map
129  iBooker.setCurrentFolder("PixelPhase1/EventInfo");
130  summaryMap_["Grand"] = iBooker.book2D("reportSummaryMap","Pixel Summary Map",12,0,12,4,0,4);
131  reportSummary = iBooker.bookFloat("reportSummary");
132 
133  //Now set up axis and bin labels
134  for (auto summaryMapEntry: summaryMap_){
135  auto summaryMap = summaryMapEntry.second;
136  for (unsigned int i = 0; i < xAxisLabels_.size(); i++){
137  summaryMap->setBinLabel(i+1, xAxisLabels_[i],1);
138  }
139  for (unsigned int i = 0; i < yAxisLabels_.size(); i++){
140  summaryMap->setBinLabel(i+1,yAxisLabels_[i],2);
141  }
142  summaryMap->setAxisTitle("Subdetector",1);
143  summaryMap->setAxisTitle("Layer/disk",2);
144  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
145  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
146  summaryMap->Fill(i,j,-1.);
147  }
148  }
149  }
150  reportSummary->Fill(-1.);
151  //Reset the iBooker
152  iBooker.setCurrentFolder("PixelPhase1/");
153 }
154 
155 //------------------------------------------------------------------
156 // Used to book the trend plots
157 //------------------------------------------------------------------
159  //We need different plots depending on if we're online (runOnEndLumi) or offline (!runOnEndLumi)
160  iBooker.setCurrentFolder("PixelPhase1/");
161  std::vector<string> binAxisLabels = {"Layer 1", "Layer 2", "Layer 3", "Layer 4", "Ring 1", "Ring 2"};
162  if (runOnEndLumi_){
163  std::vector<trendPlots> histoOrder = {layer1,layer2,layer3,layer4,ring1,ring2};
164  std::vector<string> varName ={"Layer_1","Layer_2","Layer_3","Layer_4","Ring_1","Ring_2"};
165  std::vector<int> yMax = {1536,3584,5632,8192,4224,6528};
166  for (unsigned int i = 0; i < histoOrder.size(); i++){
167  string varNameStr = "deadRocTrend"+varName[i];
168  string varTitle = binAxisLabels[i]+" dead ROC trend";
169  deadROCTrends_[histoOrder[i]] = iBooker.bookProfile(varNameStr,varTitle,500,0.,5000,0.,yMax[i],"");
170  varNameStr = "ineffRocTrend"+varName[i];
171  varTitle = binAxisLabels[i]+" inefficient ROC trend";
172  ineffROCTrends_[histoOrder[i]] = iBooker.bookProfile(varNameStr,varTitle,500,0.,5000,0.,yMax[i],"");
173  deadROCTrends_[histoOrder[i]]->setAxisTitle("Lumisection",1);
174  ineffROCTrends_[histoOrder[i]]->setAxisTitle("Lumisection",1);
175  }
176  }
177  else {
178  deadROCTrends_[offline] = iBooker.book1D("deadRocTotal","N dead ROCs",6,0,6);
179  ineffROCTrends_[offline] = iBooker.book1D("ineffRocTotal","N inefficient ROCs",6,0,6);
180  deadROCTrends_[offline]->setAxisTitle("Subdetector",1);
181  ineffROCTrends_[offline]->setAxisTitle("Subdetector",1);
182  for (unsigned int i = 1; i <= binAxisLabels.size(); i++){
183  deadROCTrends_[offline]->setBinLabel(i,binAxisLabels[i-1]);
184  ineffROCTrends_[offline]->setBinLabel(i,binAxisLabels[i-1]);
185  }
186  }
187 
188 }
189 
190 //------------------------------------------------------------------
191 // Fill the summary histograms
192 //------------------------------------------------------------------
194  //Firstly, we will fill the regular summary maps.
195  for (auto mapInfo: summaryPlotName_){
196  auto name = mapInfo.first;
197  std::ostringstream histNameStream;
198  std::string histName;
199 
200  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
201  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
202  if (i > 3 && j == 3) continue;
203  bool minus = i < 2 || (i > 3 && i < 8); // bleah !
204  int iOver2 = floor(i/2.);
205  bool outer = (i > 3)?iOver2%2==0:i%2==0;
206  //Complicated expression that creates the name of the histogram we are interested in.
207  histNameStream.str("");
208  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);
209  histName = histNameStream.str();
210  MonitorElement * me = iGetter.get(histName);
211 
212  if (!me) {
213  edm::LogWarning("SiPixelPhase1Summary") << "ME " << histName << " is not available !!";
214  continue; // Ignore non-existing MEs, as this can cause the whole thing to crash
215  }
216 
217  if (summaryMap_[name]==nullptr){
218  edm::LogWarning("SiPixelPhase1Summary") << "Summary map " << name << " is not available !!";
219  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.
220  }
221  if (!(me->getQReports()).empty()) summaryMap_[name]->setBinContent(i+1,j+1,(me->getQReports())[0]->getQTresult());
222  else summaryMap_[name]->setBinContent(i+1,j+1,-1);
223  }
224  }
225  }
226  //Sum of non-negative bins for the reportSummary
227  float sumOfNonNegBins = 0.;
228  //Now we will use the other summary maps to create the overall map.
229  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
230  if (summaryMap_["Grand"]==nullptr){
231  edm::LogWarning("SiPixelPhase1Summary") << "Grand summary does not exist!";
232  break;
233  }
234  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
235  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.
236  for (auto const mapInfo: summaryPlotName_){ //Check summary maps
237  auto name = mapInfo.first;
238  if (summaryMap_[name]==nullptr){
239  edm::LogWarning("SiPixelPhase1Summary") << "Summary " << name << " does not exist!";
240  continue;
241  }
242  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));
243  }
244  if (summaryMap_["Grand"]->getBinContent(i+1,j+1) > -0.1) sumOfNonNegBins += summaryMap_["Grand"]->getBinContent(i+1,j+1);
245  }
246  }
247  reportSummary->Fill(sumOfNonNegBins/40.); // The average of the 40 useful bins in the summary map.
248 
249 }
250 
251 //------------------------------------------------------------------
252 // Fill the trend plots
253 //------------------------------------------------------------------
255 
256  // 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.
257  if (lumiSec%10 != 0) return;
258 
259  std::string histName;
260 
261 
262  //Find the total number of filled bins and hi efficiency bins
263  std::vector<trendPlots> trendOrder = {layer1,layer2,layer3,layer4,ring1,ring2};
264  std::vector<int> nFilledROCs(trendOrder.size(),0);
265  std::vector<int> hiEffROCs(trendOrder.size(),0);
266  std::vector<int> nRocsPerTrend = {1536,3584,5632,8192,4224,6528};
267  std::vector<string> trendNames = {};
268 
269  for (auto it : {1,2,3,4}) {
270  histName = "PXBarrel/digi_occupancy_per_SignedModuleCoord_per_SignedLadderCoord_PXLayer_" + std::to_string(it);
271  trendNames.push_back(histName);
272  }
273  for (auto it : {1,2}) {
274  histName = "PXForward/digi_occupancy_per_SignedDiskCoord_per_SignedBladePanelCoord_PXRing_" + std::to_string(it);
275  trendNames.push_back(histName);
276  }
277  //Loop over layers. This will also do the rings, but we'll skip the ring calculation for
278  for (unsigned int trendIt = 0; trendIt < trendOrder.size(); trendIt++){
279  iGetter.cd();
280  histName = "PixelPhase1/Phase1_MechanicalView/" + trendNames[trendIt];
281  MonitorElement * tempLayerME = iGetter.get(histName);
282  if (tempLayerME==nullptr) continue;
283  float lowEffValue = 0.25 * (tempLayerME->getTH1()->Integral() / nRocsPerTrend[trendIt]);
284  for (int i=1; i<=tempLayerME->getTH1()->GetXaxis()->GetNbins(); i++){
285  for (int j=1; j<=tempLayerME->getTH1()->GetYaxis()->GetNbins(); j++){
286  if (tempLayerME->getBinContent(i,j) > 0.) nFilledROCs[trendIt]++;
287  if (tempLayerME->getBinContent(i,j) > lowEffValue) hiEffROCs[trendIt]++;
288  }
289  }
290  if (runOnEndLumi_) {
291  tempLayerME->Reset(); //If we're doing online monitoring, reset the digi maps.
292  }
293  } // Close layers/ring loop
294 
295  if (!runOnEndLumi_) { //offline
296  for (unsigned int i = 0; i < trendOrder.size(); i++){
297  deadROCTrends_[offline]->setBinContent(i+1,nRocsPerTrend[i]-nFilledROCs[i]);
298  ineffROCTrends_[offline]->setBinContent(i+1,nFilledROCs[i]-hiEffROCs[i]);
299  }
300  }
301  else { //online
302  for (unsigned int i = 0; i < trendOrder.size(); i++){
303  deadROCTrends_[trendOrder[i]]->Fill(lumiSec-1,nRocsPerTrend[i]-nFilledROCs[i]);
304  ineffROCTrends_[trendOrder[i]]->Fill(lumiSec-1,nFilledROCs[i]-hiEffROCs[i]);
305  }
306  }
307 
308  if (!runOnEndLumi_) return; // The following only occurs in the online
309  //Reset some MEs every 10LS here
310  for (auto it : {1,2,3,4}) { //PXBarrel
311  histName = "PixelPhase1/Phase1_MechanicalView/PXBarrel/clusterposition_zphi_PXLayer_" +std::to_string(it);
312  MonitorElement * toReset = iGetter.get(histName);
313  if (toReset!=nullptr) {
314  toReset->Reset();
315  }
316  }
317  for (auto it : {-3,-2,-1,1,2,3}){ //PXForward
318  histName = "PixelPhase1/Phase1_MechanicalView/PXForward/clusterposition_xy_PXDisk_" + std::to_string(it);
319  MonitorElement * toReset = iGetter.get(histName);
320  if (toReset!=nullptr) {
321  toReset->Reset();
322  }
323  }
324 
325 }
326 
327 //define this as a plug-in
LuminosityBlockID id() const
T getParameter(std::string const &) const
void cd(void)
Definition: DQMStore.cc:339
SiPixelPhase1Summary(const edm::ParameterSet &conf)
std::map< std::string, std::string > summaryPlotName_
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
void cd(void)
Definition: DQMStore.cc:269
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:305
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< trendPlots, MonitorElement * > deadROCTrends_
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_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
TH1 * getTH1(void) const
void bookTrendPlots(DQMStore::IBooker &iBooker)
MonitorElement * reportSummary
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
std::vector< QReport * > getQReports(void) const
get map of QReports
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
LuminosityBlockNumber_t luminosityBlock() const
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:109
void bookSummaries(DQMStore::IBooker &iBooker)
void dqmEndLuminosityBlock(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c) override
void Reset(void)
reset ME (ie. contents, errors, etc)
Definition: Run.h:43