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 <stdlib.h>
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  firstLumi = false;
82  }
83 
84  if (runOnEndLumi_) fillSummaries(iBooker,iGetter);
85 
86  // iBooker.cd();
87 
88 }
89 
90 //------------------------------------------------------------------
91 // Method called for every event
92 //------------------------------------------------------------------
94 {
95  if (runOnEndJob_) fillSummaries(iBooker,iGetter);
96 
97 }
98 
99 //------------------------------------------------------------------
100 // Used to book the summary plots
101 //------------------------------------------------------------------
103  iBooker.setCurrentFolder("PixelPhase1/Summary");
104 
105  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 !?!?!?!
106  std::vector<std::string> yAxisLabels_ = {"1","2","3","4"}; // why not having a global variable ?!?!?!!?
107 
108  for (auto mapInfo: summaryPlotName_){
109  auto name = mapInfo.first;
110  summaryMap_[name] = iBooker.book2D("pixel"+name+"Summary","Pixel "+name+" Summary",12,0,12,4,0,4);
111  for (unsigned int i = 0; i < xAxisLabels_.size(); i++){
112  summaryMap_[name]->setBinLabel(i+1, xAxisLabels_[i],1);
113  }
114  for (unsigned int i = 0; i < yAxisLabels_.size(); i++){
115  summaryMap_[name]->setBinLabel(i+1,yAxisLabels_[i],2);
116  }
117  summaryMap_[name]->setAxisTitle("Subdetector",1);
118  summaryMap_[name]->setAxisTitle("Layer/disk",2);
119  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
120  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
121  summaryMap_[name]->Fill(i,j,-1.);
122  }
123  }
124  }
125 }
126 
127 //------------------------------------------------------------------
128 // Fill the summary histograms
129 //------------------------------------------------------------------
131  //Firstly, we will fill the regular summary maps.
132  for (auto mapInfo: summaryPlotName_){
133  auto name = mapInfo.first;
134  if (name == "Grand") continue;
135  std::ostringstream histNameStream;
136  std::string histName;
137 
138  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
139  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
140  if (i > 3 && j == 3) continue;
141  bool minus = i < 2 || (i > 3 && i < 8); // bleah !
142  int iOver2 = floor(i/2.);
143  bool outer = (i > 3)?iOver2%2==0:i%2==0;
144  //Complicated expression that creates the name of the histogram we are interested in.
145  histNameStream.str("");
146  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);
147  histName = histNameStream.str();
148  MonitorElement * me = iGetter.get(histName);
149 
150  if (!me) {
151  edm::LogWarning("SiPixelPhase1Summary") << "ME " << histName << " is not available !!";
152  continue; // Ignore non-existing MEs, as this can cause the whole thing to crash
153  }
154 
155  if (me->hasError()) {
156  //If there is an error, fill with 0
157  summaryMap_[name]->setBinContent(i+1,j+1,0);
158  } //Do we want to include warnings here?
159  else if (me->hasWarning()){
160  summaryMap_[name]->setBinContent(i+1,j+1,0.5);
161  }
162  else summaryMap_[name]->setBinContent(i+1,j+1,1);
163  }
164  }
165  }
166  //Now we will use the other summary maps to create the overall map.
167  for (int i = 0; i < 12; i++){ // !??!?!? xAxisLabels_.size() ?!?!
168  for (int j = 0; j < 4; j++){ // !??!?!? yAxisLabels_.size() ?!?!?!
169  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.
170  for (auto const mapInfo: summaryPlotName_){ //Check summary maps
171  auto name = mapInfo.first;
172  if (name == "Grand") continue;
173  if (summaryMap_[name]->getBinContent(i+1,j+1) < 0.9 && 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)); // This could be changed to include warnings if we want?
174  }
175  }
176  }
177 
178 }
179 
180 //define this as a plug-in
T getParameter(std::string const &) const
SiPixelPhase1Summary(const edm::ParameterSet &conf)
std::map< std::string, std::string > summaryPlotName_
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:305
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void fillSummaries(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
bool hasError(void) const
true if at least of one of the quality tests returned an error
std::map< std::string, MonitorElement * > summaryMap_
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup)
bool hasWarning(void) const
true if at least of one of the quality tests returned a warning
edm::ParameterSet conf_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
void dqmEndJob(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) override
HLT enums.
void bookSummaries(DQMStore::IBooker &iBooker)
void dqmEndLuminosityBlock(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c) override
Definition: Run.h:42