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
23 
26 
27 #include <iostream>
28 #include <cstdio>
29 #include <string>
30 #include <sstream>
31 #include <cmath>
32 
33 using namespace edm;
34 using namespace std;
35 
37  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
38  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: Constructor";
39  parameters = ps;
40 
41  // get the cfi parameters
42  detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis", false);
43  runOnline = parameters.getUntrackedParameter<bool>("runOnline", true);
44  // top folder for the histograms in DQMStore
45  topHistoFolder = ps.getUntrackedParameter<string>("topHistoFolder", "DT/02-Segments");
46  nMinEvts = ps.getUntrackedParameter<int>("nEventsCert", 5000);
47  maxPhiHit = ps.getUntrackedParameter<int>("maxPhiHit", 7);
48  maxPhiZHit = ps.getUntrackedParameter<int>("maxPhiZHit", 11);
49 
50  nLSs = 0;
51 
52  bookingdone = false;
53 }
54 
56  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "DTSegmentAnalysisTest: analyzed " << nLSs << " LS";
57 }
58 
60  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: BeginRun";
61  muonGeom = &context.getData(muonGeomToken_);
62 }
63 
65  nLSs++;
66  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
67  << "DTSegmentAnalysisTest: analyzing LS" << lumiSeg.id().luminosityBlock() << " of " << nLSs << endl;
68 }
69 
71  DQMStore::IGetter& igetter,
72  edm::LuminosityBlock const& lumiSeg,
73  edm::EventSetup const& context) {
74  // book the histos
75 
76  if (!bookingdone)
77  bookHistos(ibooker);
78  bookingdone = true;
79 
80  // counts number of lumiSegs
81  nLumiSegs = lumiSeg.id().luminosityBlock();
82 
83  if (runOnline) {
84  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
85  << "[DTSegmentAnalysisTest]: End of LS " << nLumiSegs
86  << ". Client called in online mode , perform DQM client operation";
87 
88  performClientDiagnostic(igetter);
89  }
90 }
91 
93  if (!runOnline) {
94  LogTrace("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
95  << "[DTSegmentAnalysisTest]: endJob. Client called in offline mode , perform DQM client operation";
96 
97  performClientDiagnostic(igetter);
98  }
99 }
100 
102  summaryHistos[3]->Reset();
103  summaryHistos[4]->Reset();
104  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
105  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
106 
107  for (; ch_it != ch_end; ++ch_it) {
108  DTChamberId chID = (*ch_it)->id();
109 
110  MonitorElement* hNHits = igetter.get(getMEName(chID, "h4DSegmNHits"));
111  MonitorElement* hSegmOcc = igetter.get(getMEName(chID, "numberOfSegments"));
112 
113  if (hNHits && hSegmOcc) {
114  TH1F* hNHits_root = hNHits->getTH1F();
115  TH2F* hSegmOcc_root = hSegmOcc->getTH2F();
116  TH2F* summary_histo_root = summaryHistos[3]->getTH2F();
117 
118  int sector = chID.sector();
119  if (sector == 13)
120  sector = 4;
121  if (sector == 14)
122  sector = 10;
123 
124  if ((chID.station() != 4 && hNHits_root->GetMaximumBin() < maxPhiZHit) ||
125  (chID.station() == 4 && hNHits_root->GetMaximumBin() < maxPhiHit)) {
126  summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(), 1);
127  if (summary_histo_root->GetBinContent(sector, chID.wheel() + 3) < 1)
128  summaryHistos[3]->setBinContent(sector, chID.wheel() + 3, 1);
129  } else
130  summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(), 0);
131 
132  if (detailedAnalysis) {
133  if (chID.station() != 4)
134  segmRecHitHistos[make_pair(chID.wheel(), chID.sector())]->Fill(chID.station(),
135  abs(12 - hNHits_root->GetMaximumBin()));
136  else
137  segmRecHitHistos[make_pair(chID.wheel(), chID.sector())]->Fill(chID.station(),
138  abs(8 - hNHits_root->GetMaximumBin()));
139  }
140 
141  TH2F* summary2_histo_root = summaryHistos[3]->getTH2F();
142  float weight = 0.001;
143  if (hSegmOcc_root->GetBinContent(sector, chID.station()) == 0) {
144  summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(), 2);
145  if (summary2_histo_root->GetBinContent(sector, chID.wheel() + 3) < 2)
146  summaryHistos[3]->setBinContent(sector, chID.wheel() + 3, 2);
147  } else {
148  // Fill the percentage of segment occupancy
149  weight = 1. / 4.;
150  if ((sector == 4 || sector == 10) && chID.station() == 4)
151  weight = 1. / 8.;
152  }
153  summaryHistos[4]->Fill(sector, chID.wheel(), weight);
154  } else {
155  LogVerbatim("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
156  << "[DTSegmentAnalysisTest]: histos not found!!"; // FIXME
157  }
158 
159  if (detailedAnalysis) { // switch on detailed analysis
160 
161  //test on chi2 segment quality
162 
163  MonitorElement* chi2_histo = igetter.get(getMEName(chID, "h4DChi2"));
164  if (chi2_histo) {
165  TH1F* chi2_histo_root = chi2_histo->getTH1F();
166  double threshold = parameters.getUntrackedParameter<double>("chi2Threshold", 5);
167  double maximum = chi2_histo_root->GetXaxis()->GetXmax();
168  double minimum = chi2_histo_root->GetXaxis()->GetXmin();
169  int nbins = chi2_histo_root->GetXaxis()->GetNbins();
170  int thresholdBin = int(threshold / ((maximum - minimum) / nbins));
171 
172  double badSegments = 0;
173  for (int bin = thresholdBin; bin <= nbins; bin++) {
174  badSegments += chi2_histo_root->GetBinContent(bin);
175  }
176 
177  if (chi2_histo_root->GetEntries() != 0) {
178  double badSegmentsPercentual = badSegments / double(chi2_histo_root->GetEntries());
179  chi2Histos[make_pair(chID.wheel(), chID.sector())]->Fill(chID.station(), badSegmentsPercentual);
180  }
181  } else {
182  LogVerbatim("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
183  << "[DTSegmentAnalysisTest]: Histo: " << getMEName(chID, "h4DChi2") << " not found!" << endl;
184  }
185  } // end of switch for detailed analysis
186 
187  } //loop over all the chambers
188 
189  string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsSegment";
190 
191  MonitorElement* meProcEvts = igetter.get(nEvtsName);
192 
193  if (meProcEvts) {
194  int nProcEvts = meProcEvts->getFloatValue();
195  summaryHistos[4]->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
196  } else {
197  summaryHistos[4]->setEntries(nMinEvts + 1);
198  LogVerbatim("DTDQM|DTMonitorClient|DTOccupancyTest")
199  << "[DTOccupancyTest] ME: " << nEvtsName << " not found!" << endl;
200  }
201 
202  if (detailedAnalysis) {
203  string chi2CriterionName = parameters.getUntrackedParameter<string>("chi2TestName", "chi2InRange");
204  for (map<pair<int, int>, MonitorElement*>::const_iterator histo = chi2Histos.begin(); histo != chi2Histos.end();
205  histo++) {
206  const QReport* theChi2QReport = (*histo).second->getQReport(chi2CriterionName);
207  if (theChi2QReport) {
208  vector<dqm::me_util::Channel> badChannels = theChi2QReport->getBadChannels();
209  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
210  channel++) {
211  LogError("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
212  << "Wheel: " << (*histo).first.first << " Sector: " << (*histo).first.second
213  << " Bad stations: " << (*channel).getBin() << " Contents : " << (*channel).getContents();
214  }
215  }
216  }
217 
218  string segmRecHitCriterionName =
219  parameters.getUntrackedParameter<string>("segmRecHitTestName", "segmRecHitInRange");
220  for (map<pair<int, int>, MonitorElement*>::const_iterator histo = segmRecHitHistos.begin();
221  histo != segmRecHitHistos.end();
222  histo++) {
223  const QReport* theSegmRecHitQReport = (*histo).second->getQReport(segmRecHitCriterionName);
224  if (theSegmRecHitQReport) {
225  vector<dqm::me_util::Channel> badChannels = theSegmRecHitQReport->getBadChannels();
226  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
227  channel++) {
228  LogError("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
229  << "Wheel: " << (*histo).first.first << " Sector: " << (*histo).first.second
230  << " Bad stations on recHit number: " << (*channel).getBin()
231  << " Contents : " << (*channel).getContents();
232  }
233  }
234  }
235 
236  } // end of detailedAnalysis
237 }
238 
240  stringstream wheel;
241  wheel << chID.wheel();
242  stringstream station;
243  station << chID.station();
244  stringstream sector;
245  sector << chID.sector();
246 
247  string folderName =
248  topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/";
249 
250  string histoname = folderName + histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
251 
252  if (histoTag == "numberOfSegments")
253  histoname = topHistoFolder + "/Wheel" + wheel.str() + "/" + histoTag + +"_W" + wheel.str();
254 
255  return histoname;
256 }
257 
259  for (int wh = -2; wh <= 2; wh++) {
260  stringstream wheel;
261  wheel << wh;
262  string histoName = "segmentSummary_W" + wheel.str();
263 
265 
266  summaryHistos[wh] = ibooker.book2D(histoName.c_str(), histoName.c_str(), 12, 1, 13, 4, 1, 5);
267  summaryHistos[wh]->setAxisTitle("Sector", 1);
268  summaryHistos[wh]->setBinLabel(1, "MB1", 2);
269  summaryHistos[wh]->setBinLabel(2, "MB2", 2);
270  summaryHistos[wh]->setBinLabel(3, "MB3", 2);
271  summaryHistos[wh]->setBinLabel(4, "MB4", 2);
272 
273  if (detailedAnalysis) {
274  for (int sect = 1; sect <= 14; sect++) {
275  stringstream sector;
276  sector << sect;
277  string chi2HistoName = "chi2BadSegmPercentual_W" + wheel.str() + "_Sec" + sector.str();
278  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Tests");
279  chi2Histos[make_pair(wh, sect)] = ibooker.book1D(chi2HistoName.c_str(), chi2HistoName.c_str(), 4, 1, 5);
280  chi2Histos[make_pair(wh, sect)]->setBinLabel(1, "MB1");
281  chi2Histos[make_pair(wh, sect)]->setBinLabel(2, "MB2");
282  chi2Histos[make_pair(wh, sect)]->setBinLabel(3, "MB3");
283  chi2Histos[make_pair(wh, sect)]->setBinLabel(4, "MB4");
284 
285  string segmHistoName = "residualsOnSegmRecHitNumber_W" + wheel.str() + "_Sec" + sector.str();
286  segmRecHitHistos[make_pair(wh, sect)] = ibooker.book1D(segmHistoName.c_str(), segmHistoName.c_str(), 4, 1, 5);
287  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(1, "MB1");
288  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(2, "MB2");
289  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(3, "MB3");
290  segmRecHitHistos[make_pair(wh, sect)]->setBinLabel(4, "MB4");
291  }
292  }
293  }
294 
295  string histoName = "segmentSummary";
296 
298 
299  summaryHistos[3] = ibooker.book2D(histoName.c_str(), histoName.c_str(), 12, 1, 13, 5, -2, 3);
300  summaryHistos[3]->setAxisTitle("Sector", 1);
301  summaryHistos[3]->setAxisTitle("Wheel", 2);
302 
303  summaryHistos[4] = ibooker.book2D("SegmentGlbSummary", histoName.c_str(), 12, 1, 13, 5, -2, 3);
304  summaryHistos[4]->setAxisTitle("Sector", 1);
305  summaryHistos[4]->setAxisTitle("Wheel", 2);
306 }
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:42
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LuminosityBlockNumber_t luminosityBlock() const
edm::ParameterSet parameters
~DTSegmentAnalysisTest() override
Destructor.
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::pair< int, int >, MonitorElement * > chi2Histos
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const std::vector< DQMChannel > & getBadChannels() const
Definition: weight.py:1
std::map< int, MonitorElement * > summaryHistos
Log< level::Error, false > LogError
#define LogTrace(id)
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
void dqmBeginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual double getFloatValue() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const DTGeometry * muonGeom
Transition
Definition: Transition.h:12
void bookHistos(DQMStore::IBooker &)
DTSegmentAnalysisTest(const edm::ParameterSet &ps)
Constructor.
std::string getMEName(const DTChamberId &chID, std::string histoTag)
Get the ME name.
std::map< std::pair< int, int >, MonitorElement * > segmRecHitHistos
LuminosityBlockID id() const
virtual TH1F * getTH1F() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:680
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
void performClientDiagnostic(DQMStore::IGetter &)
Perform client diagnostic operations.
Definition: Run.h:45