CMS 3D CMS Logo

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