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