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