CMS 3D CMS Logo

DTSegmentAnalysisTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Mila - INFN Torino
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah ncpp-um-my
7  *
8  */
9 
11 
12 // Framework
18 
19 // Geometry
24 
27 
29 
30 #include <iostream>
31 #include <cstdio>
32 #include <string>
33 #include <sstream>
34 #include <cmath>
35 
36 using namespace edm;
37 using namespace std;
38 
40  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: Constructor";
41  parameters = ps;
42 
43  // get the cfi parameters
44  detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis", false);
45  normalizeHistoPlots = parameters.getUntrackedParameter<bool>("normalizeHistoPlots", false);
46  runOnline = parameters.getUntrackedParameter<bool>("runOnline", true);
47  // top folder for the histograms in DQMStore
48  topHistoFolder = ps.getUntrackedParameter<string>("topHistoFolder", "DT/02-Segments");
49  // hlt DQM mode
50 
51  hltDQMMode = ps.getUntrackedParameter<bool>("hltDQMMode", false);
52  nMinEvts = ps.getUntrackedParameter<int>("nEventsCert", 5000);
53  maxPhiHit = ps.getUntrackedParameter<int>("maxPhiHit", 7);
54  maxPhiZHit = ps.getUntrackedParameter<int>("maxPhiZHit", 11);
55 
56  nevents = 0;
57 
58  bookingdone = false;
59 }
60 
62  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "DTSegmentAnalysisTest: analyzed " << nevents << " events";
63 }
64 
65 void DTSegmentAnalysisTest::beginRun(const Run& run, const EventSetup& context) {
66  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: BeginRun";
67 
68  context.get<MuonGeometryRecord>().get(muonGeom);
69 }
70 
72  DQMStore::IGetter& igetter,
73  edm::LuminosityBlock const& lumiSeg,
74  edm::EventSetup const& context) {
75  // book the histos
76 
77  if (!bookingdone)
78  bookHistos(ibooker);
79  bookingdone = true;
80 
81  // counts number of lumiSegs
82  nLumiSegs = lumiSeg.id().luminosityBlock();
83 
84  if (runOnline) {
85  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
86  << "[DTSegmentAnalysisTest]: End of LS " << nLumiSegs
87  << ". Client called in online mode , perform DQM client operation";
88 
89  performClientDiagnostic(igetter);
90  }
91 }
92 
93 void DTSegmentAnalysisTest::endRun(Run const& run, EventSetup const& context) {}
94 
96  if (!runOnline) {
97  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
98  << "[DTSegmentAnalysisTest]: endJob. Client called in offline mode , perform DQM client operation";
99 
100  performClientDiagnostic(igetter);
101  }
102 
103  if (normalizeHistoPlots) {
104  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << " Performing time-histo normalization" << endl;
105  MonitorElement* hNevtPerLS = nullptr;
106 
107  if (hltDQMMode)
108  hNevtPerLS = igetter.get(topHistoFolder + "/NevtPerLS");
109  else
110  hNevtPerLS = igetter.get("DT/EventInfo/NevtPerLS");
111 
112  if (hNevtPerLS != nullptr) {
113  for (int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
114  for (int sector = 1; sector <= 12; ++sector) { // loop over sectors
115  stringstream wheelstr;
116  wheelstr << wheel;
117  stringstream sectorstr;
118  sectorstr << sector;
119  string sectorHistoName = topHistoFolder + "/Wheel" + wheelstr.str() + "/Sector" + sectorstr.str() +
120  "/NSegmPerEvent_W" + wheelstr.str() + "_Sec" + sectorstr.str();
121 
122  //FR get the histo from here (igetter available!) ...
123  MonitorElement* histoGot = igetter.get(sectorHistoName);
124 
125  //FR ...and just make with it a DTTimeEvolutionHisto
126  DTTimeEvolutionHisto hNSegmPerLS(histoGot);
127 
128  hNSegmPerLS.normalizeTo(hNevtPerLS);
129  }
130  }
131  } else {
132  LogError("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Histo NevtPerLS not found!" << endl;
133  }
134  }
135 }
136 
138  summaryHistos[3]->Reset();
139  summaryHistos[4]->Reset();
140  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
141  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
142 
143  for (; ch_it != ch_end; ++ch_it) {
144  DTChamberId chID = (*ch_it)->id();
145 
146  MonitorElement* hNHits = igetter.get(getMEName(chID, "h4DSegmNHits"));
147  MonitorElement* hSegmOcc = igetter.get(getMEName(chID, "numberOfSegments"));
148 
149  if (hNHits && hSegmOcc) {
150  TH1F* hNHits_root = hNHits->getTH1F();
151  TH2F* hSegmOcc_root = hSegmOcc->getTH2F();
152  TH2F* summary_histo_root = summaryHistos[3]->getTH2F();
153 
154  int sector = chID.sector();
155  if (sector == 13)
156  sector = 4;
157  if (sector == 14)
158  sector = 10;
159 
160  if ((chID.station() != 4 && hNHits_root->GetMaximumBin() < maxPhiZHit) ||
161  (chID.station() == 4 && hNHits_root->GetMaximumBin() < maxPhiHit)) {
162  summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(), 1);
163  if (summary_histo_root->GetBinContent(sector, chID.wheel() + 3) < 1)
164  summaryHistos[3]->setBinContent(sector, chID.wheel() + 3, 1);
165  } else
166  summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(), 0);
167 
168  if (detailedAnalysis) {
169  if (chID.station() != 4)
170  segmRecHitHistos[make_pair(chID.wheel(), chID.sector())]->Fill(chID.station(),
171  abs(12 - hNHits_root->GetMaximumBin()));
172  else
173  segmRecHitHistos[make_pair(chID.wheel(), chID.sector())]->Fill(chID.station(),
174  abs(8 - hNHits_root->GetMaximumBin()));
175  }
176 
177  TH2F* summary2_histo_root = summaryHistos[3]->getTH2F();
178  float weight = 0.001;
179  if (hSegmOcc_root->GetBinContent(sector, chID.station()) == 0) {
180  summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(), 2);
181  if (summary2_histo_root->GetBinContent(sector, chID.wheel() + 3) < 2)
182  summaryHistos[3]->setBinContent(sector, chID.wheel() + 3, 2);
183  } else {
184  // Fill the percentage of segment occupancy
185  weight = 1. / 4.;
186  if ((sector == 4 || sector == 10) && chID.station() == 4)
187  weight = 1. / 8.;
188  }
189  summaryHistos[4]->Fill(sector, chID.wheel(), weight);
190  } else {
191  LogVerbatim("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
192  << "[DTSegmentAnalysisTest]: histos not found!!"; // FIXME
193  }
194 
195  if (detailedAnalysis) { // switch on detailed analysis
196 
197  //test on chi2 segment quality
198 
199  MonitorElement* chi2_histo = igetter.get(getMEName(chID, "h4DChi2"));
200  if (chi2_histo) {
201  TH1F* chi2_histo_root = chi2_histo->getTH1F();
202  double threshold = parameters.getUntrackedParameter<double>("chi2Threshold", 5);
203  double maximum = chi2_histo_root->GetXaxis()->GetXmax();
204  double minimum = chi2_histo_root->GetXaxis()->GetXmin();
205  int nbins = chi2_histo_root->GetXaxis()->GetNbins();
206  int thresholdBin = int(threshold / ((maximum - minimum) / nbins));
207 
208  double badSegments = 0;
209  for (int bin = thresholdBin; bin <= nbins; bin++) {
210  badSegments += chi2_histo_root->GetBinContent(bin);
211  }
212 
213  if (chi2_histo_root->GetEntries() != 0) {
214  double badSegmentsPercentual = badSegments / double(chi2_histo_root->GetEntries());
215  chi2Histos[make_pair(chID.wheel(), chID.sector())]->Fill(chID.station(), badSegmentsPercentual);
216  }
217  } else {
218  LogVerbatim("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
219  << "[DTSegmentAnalysisTest]: Histo: " << getMEName(chID, "h4DChi2") << " not found!" << endl;
220  }
221  } // end of switch for detailed analysis
222 
223  } //loop over all the chambers
224 
225  string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsSegment";
226 
227  MonitorElement* meProcEvts = igetter.get(nEvtsName);
228 
229  if (meProcEvts) {
230  int nProcEvts = meProcEvts->getFloatValue();
231  summaryHistos[4]->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
232  } else {
233  summaryHistos[4]->setEntries(nMinEvts + 1);
234  LogVerbatim("DTDQM|DTMonitorClient|DTOccupancyTest")
235  << "[DTOccupancyTest] ME: " << nEvtsName << " not found!" << endl;
236  }
237 
238  if (detailedAnalysis) {
239  string chi2CriterionName = parameters.getUntrackedParameter<string>("chi2TestName", "chi2InRange");
240  for (map<pair<int, int>, MonitorElement*>::const_iterator histo = chi2Histos.begin(); histo != chi2Histos.end();
241  histo++) {
242  const QReport* theChi2QReport = (*histo).second->getQReport(chi2CriterionName);
243  if (theChi2QReport) {
244  vector<dqm::me_util::Channel> badChannels = theChi2QReport->getBadChannels();
245  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
246  channel++) {
247  LogError("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
248  << "Wheel: " << (*histo).first.first << " Sector: " << (*histo).first.second
249  << " Bad stations: " << (*channel).getBin() << " Contents : " << (*channel).getContents();
250  }
251  }
252  }
253 
254  string segmRecHitCriterionName =
255  parameters.getUntrackedParameter<string>("segmRecHitTestName", "segmRecHitInRange");
256  for (map<pair<int, int>, MonitorElement*>::const_iterator histo = segmRecHitHistos.begin();
257  histo != segmRecHitHistos.end();
258  histo++) {
259  const QReport* theSegmRecHitQReport = (*histo).second->getQReport(segmRecHitCriterionName);
260  if (theSegmRecHitQReport) {
261  vector<dqm::me_util::Channel> badChannels = theSegmRecHitQReport->getBadChannels();
262  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
263  channel++) {
264  LogError("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
265  << "Wheel: " << (*histo).first.first << " Sector: " << (*histo).first.second
266  << " Bad stations on recHit number: " << (*channel).getBin()
267  << " Contents : " << (*channel).getContents();
268  }
269  }
270  }
271 
272  } // end of detailedAnalysis
273 }
274 
276  stringstream wheel;
277  wheel << chID.wheel();
278  stringstream station;
279  station << chID.station();
280  stringstream sector;
281  sector << chID.sector();
282 
283  string folderName =
284  topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/";
285 
286  string histoname = folderName + histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
287 
288  if (histoTag == "numberOfSegments")
289  histoname = topHistoFolder + "/Wheel" + wheel.str() + "/" + histoTag + +"_W" + wheel.str();
290 
291  return histoname;
292 }
293 
295  for (int wh = -2; wh <= 2; wh++) {
296  stringstream wheel;
297  wheel << wh;
298  string histoName = "segmentSummary_W" + wheel.str();
299 
301 
302  summaryHistos[wh] = ibooker.book2D(histoName.c_str(), histoName.c_str(), 12, 1, 13, 4, 1, 5);
303  summaryHistos[wh]->setAxisTitle("Sector", 1);
304  summaryHistos[wh]->setBinLabel(1, "MB1", 2);
305  summaryHistos[wh]->setBinLabel(2, "MB2", 2);
306  summaryHistos[wh]->setBinLabel(3, "MB3", 2);
307  summaryHistos[wh]->setBinLabel(4, "MB4", 2);
308 
309  if (detailedAnalysis) {
310  for (int sect = 1; sect <= 14; sect++) {
311  stringstream sector;
312  sector << sect;
313  string chi2HistoName = "chi2BadSegmPercentual_W" + wheel.str() + "_Sec" + sector.str();
314  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Tests");
315  chi2Histos[make_pair(wh, sect)] = ibooker.book1D(chi2HistoName.c_str(), chi2HistoName.c_str(), 4, 1, 5);
316  chi2Histos[make_pair(wh, sect)]->setBinLabel(1, "MB1");
317  chi2Histos[make_pair(wh, sect)]->setBinLabel(2, "MB2");
318  chi2Histos[make_pair(wh, sect)]->setBinLabel(3, "MB3");
319  chi2Histos[make_pair(wh, sect)]->setBinLabel(4, "MB4");
320 
321  string segmHistoName = "residualsOnSegmRecHitNumber_W" + wheel.str() + "_Sec" + sector.str();
322  segmRecHitHistos[make_pair(wh, sect)] = ibooker.book1D(segmHistoName.c_str(), segmHistoName.c_str(), 4, 1, 5);
323  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(1, "MB1");
324  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(2, "MB2");
325  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(3, "MB3");
326  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(4, "MB4");
327  }
328  }
329  }
330 
331  string histoName = "segmentSummary";
332 
334 
335  summaryHistos[3] = ibooker.book2D(histoName.c_str(), histoName.c_str(), 12, 1, 13, 5, -2, 3);
336  summaryHistos[3]->setAxisTitle("Sector", 1);
337  summaryHistos[3]->setAxisTitle("Wheel", 2);
338 
339  summaryHistos[4] = ibooker.book2D("SegmentGlbSummary", histoName.c_str(), 12, 1, 13, 5, -2, 3);
340  summaryHistos[4]->setAxisTitle("Sector", 1);
341  summaryHistos[4]->setAxisTitle("Wheel", 2);
342 }
LuminosityBlockID id() const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
const std::vector< DQMChannel > & getBadChannels() const
Definition: QReport.h:37
~DTSegmentAnalysisTest() override
Destructor.
void beginRun(const edm::Run &, const edm::EventSetup &) override
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
virtual TH1F * getTH1F() const
Definition: weight.py:1
void bookHistos()
Definition: Histogram.h:33
void endRun(edm::Run const &run, edm::EventSetup const &c) override
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void bookHistos(DQMStore::IBooker &)
DTSegmentAnalysisTest(const edm::ParameterSet &ps)
Constructor.
virtual 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)
#define LogTrace(id)
std::string getMEName(const DTChamberId &chID, std::string histoTag)
Get the ME name.
LuminosityBlockNumber_t luminosityBlock() const
void normalizeTo(const MonitorElement *histForNorm)
HLT enums.
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
virtual double getFloatValue() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
int sector() const
Definition: DTChamberId.h:49
T get() const
Definition: EventSetup.h:73
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
int station() const
Return the station number.
Definition: DTChamberId.h:42
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:437
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
void performClientDiagnostic(DQMStore::IGetter &)
Perform client diagnostic operations.
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)