CMS 3D CMS Logo

DTDigiTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTDigiTask.cc
3  *
4  * \author M. Zanetti - INFN Padova
5  *
6  */
7 
9 
10 // Framework
12 
13 // Digis
16 
17 // Geometry
21 
22 // T0s
25 
26 #include <sstream>
27 #include <cmath>
28 
29 using namespace edm;
30 using namespace std;
31 
32 // Contructor
34  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()),
35  readOutMapToken_(esConsumes<edm::Transition::BeginRun>()),
36  TtrigToken_(esConsumes<edm::Transition::BeginRun>()),
37  T0Token_(esConsumes<edm::Transition::BeginRun>()),
38  statusMapToken_(esConsumes()) {
39  // switch for the verbosity
40  LogTrace("DTDQM|DTMonitorModule|DTDigiTask") << "[DTDigiTask]: Constructor" << endl;
41 
42  // The label to retrieve the digis
43  dtDigiToken_ = consumes<DTDigiCollection>(ps.getUntrackedParameter<InputTag>("dtDigiLabel"));
44  // Read the configuration parameters
45  maxTDCHits = ps.getUntrackedParameter<int>("maxTDCHitsPerChamber", 30000);
46  // Set to true to read the ttrig from DB (useful to determine in-time and out-of-time hits)
47  readTTrigDB = ps.getUntrackedParameter<bool>("readDB", false);
48  // Set to true to subtract t0 from test pulses
49  subtractT0 = ps.getParameter<bool>("performPerWireT0Calibration");
50  // Tmax value (TDC counts)
51  defaultTmax = ps.getParameter<int>("defaultTmax");
52  // Switch from static to dinamic histo booking
53  doStaticBooking = ps.getUntrackedParameter<bool>("staticBooking", true);
54 
55  // Switch for local/global runs
56  isLocalRun = ps.getUntrackedParameter<bool>("localrun", true);
57  if (!isLocalRun) {
59  consumes<LTCDigiCollection>(ps.getUntrackedParameter<edm::InputTag>("ltcDigiCollectionTag"));
60  }
61 
62  // Setting for the reset of the ME after n (= ResetCycle) luminosity sections
63  resetCycle = ps.getUntrackedParameter<int>("ResetCycle", 3);
64  // Check the DB of noisy channels
65  checkNoisyChannels = ps.getUntrackedParameter<bool>("checkNoisyChannels", false);
66  // Default TTrig to be used when not reading the TTrig DB
67  defaultTTrig = ps.getParameter<int>("defaultTtrig");
68  inTimeHitsLowerBound = ps.getParameter<int>("inTimeHitsLowerBound");
69  inTimeHitsUpperBound = ps.getParameter<int>("inTimeHitsUpperBound");
70  timeBoxGranularity = ps.getUntrackedParameter<int>("timeBoxGranularity", 4);
71  maxTTMounts = ps.getUntrackedParameter<int>("maxTTMounts", 6400);
72 
73  doAllHitsOccupancies = ps.getUntrackedParameter<bool>("doAllHitsOccupancies", true);
74  doNoiseOccupancies = ps.getUntrackedParameter<bool>("doNoiseOccupancies", false);
75  doInTimeOccupancies = ps.getUntrackedParameter<bool>("doInTimeOccupancies", false);
76 
77  // switch on the mode for running on test pulses (different top folder)
78  tpMode = ps.getUntrackedParameter<bool>("testPulseMode", false);
79  // switch on/off the filtering of synchronous noise events (cutting on the # of digis)
80  // time-boxes and occupancy plots are not filled and summary plots are created to report the problem
81  filterSyncNoise = ps.getUntrackedParameter<bool>("filterSyncNoise", false);
82  // look for synch noisy events, produce histograms but do not filter them
83  lookForSyncNoise = ps.getUntrackedParameter<bool>("lookForSyncNoise", false);
84 
85  // switch on the mode for running on slice test (different top folder and other customizations)
86  sliceTestMode = ps.getUntrackedParameter<bool>("sliceTestMode", false);
87  // time pedestal used to set the minimum in the time box plot
88  tdcPedestal = ps.getUntrackedParameter<int>("tdcPedestal", 0);
89 
90  // switch on production of time-boxes with layer granularity
91  doLayerTimeBoxes = ps.getUntrackedParameter<bool>("doLayerTimeBoxes", false);
92 
93  syncNumTot = 0;
94  syncNum = 0;
95 }
96 
97 // destructor
99  LogTrace("DTDQM|DTMonitorModule|DTDigiTask") << "DTDigiTask: analyzed " << nevents << " events" << endl;
100 }
101 
103  LogTrace("DTDQM|DTMonitorModule|DTDigiTask") << "[DTDigiTask]: begin run" << endl;
104  nevents = 0;
105 
106  // Get the geometry
107  muonGeom = &context.getData(muonGeomToken_);
108 
109  // map of the channels
110  mapping = &context.getData(readOutMapToken_);
111 
112  // tTrig
113  if (readTTrigDB)
114  tTrigMap = &context.getData(TtrigToken_);
115  // t0s
116  if (subtractT0)
117  t0Map = &context.getData(T0Token_);
118  // FIXME: tMax (not yet from the DB)
119  tMax = defaultTmax;
120 
121  // ----------------------------------------------------------------------
122 }
123 
125  if (doStaticBooking) { // Static histo booking
126  // book the event counter
127  ibooker.setCurrentFolder("DT/EventInfo/Counters");
128  nEventMonitor = ibooker.bookFloat(tpMode ? "nProcessedEventsDigiTP" : "nProcessedEventsDigi");
129  ibooker.setCurrentFolder(topFolder());
130  for (int wh = -2; wh <= 2; ++wh) { // loop over wheels
131  if (sliceTestMode && wh != 2)
132  continue;
133 
135  bookHistos(ibooker, wh, string("Occupancies"), "OccupancyAllHits");
136 
137  if (doNoiseOccupancies)
138  bookHistos(ibooker, wh, string("Occupancies"), "OccupancyNoise");
140  bookHistos(ibooker, wh, string("Occupancies"), "OccupancyInTimeHits");
141 
143  bookHistos(ibooker, wh, string("SynchNoise"), "SyncNoiseEvents");
144  bookHistos(ibooker, wh, string("SynchNoise"), "SyncNoiseChambs");
145  }
146 
147  for (int st = 1; st <= 4; ++st) { // loop over stations
148  for (int sect = 1; sect <= 14; ++sect) { // loop over sectors
149  if ((sect == 13 || sect == 14) && st != 4)
150  continue;
151 
152  if (sliceTestMode && (sect != 12 || wh != 2))
153  continue;
154 
155  // Get the chamber ID
156  const DTChamberId dtChId(wh, st, sect);
157 
158  // Occupancies
159  if (doAllHitsOccupancies) {
160  bookHistos(ibooker, dtChId, string("Occupancies"), "OccupancyAllHits_perCh");
161  // set channel mapping
162  channelsMap(dtChId, "OccupancyAllHits_perCh");
163  }
164  if (doNoiseOccupancies)
165  bookHistos(ibooker, dtChId, string("Occupancies"), "OccupancyNoise_perCh");
167  bookHistos(ibooker, dtChId, string("Occupancies"), "OccupancyInTimeHits_perCh");
168 
169  for (int sl = 1; sl <= 3; ++sl) { // Loop over SLs
170  if (st == 4 && sl == 2)
171  continue;
172  const DTSuperLayerId dtSLId(wh, st, sect, sl);
173  if (isLocalRun) {
174  bookHistos(ibooker, dtSLId, string("TimeBoxes"), "TimeBox");
175  } else {
176  // TimeBoxes for different triggers
177  bookHistos(ibooker, dtSLId, string("TimeBoxes"), "TimeBoxDTonly");
178  bookHistos(ibooker, dtSLId, string("TimeBoxes"), "TimeBoxNoDT");
179  bookHistos(ibooker, dtSLId, string("TimeBoxes"), "TimeBoxDTalso");
180  }
181  }
182  }
183  }
184  }
185  }
186 }
187 
189  LogTrace("DTDQM|DTMonitorModule|DTDigiTask") << "[DTDigiTask]: Begin of LS transition" << endl;
190 
191  // Reset the MonitorElements every n (= ResetCycle) Lumi Blocks
192  int lumiBlock = lumiSeg.id().luminosityBlock();
193  if (lumiBlock % resetCycle == 0) {
194  LogVerbatim("DTDQM|DTMonitorModule|DTDigiTask")
195  << "[DTDigiTask]: Reset at the LS transition : " << lumiBlock << endl;
196  // Loop over all ME
197  map<string, map<uint32_t, MonitorElement*> >::const_iterator histosIt = digiHistos.begin();
198  map<string, map<uint32_t, MonitorElement*> >::const_iterator histosEnd = digiHistos.end();
199  for (; histosIt != histosEnd; ++histosIt) {
200  map<uint32_t, MonitorElement*>::const_iterator histoIt = (*histosIt).second.begin();
201  map<uint32_t, MonitorElement*>::const_iterator histoEnd = (*histosIt).second.end();
202  for (; histoIt != histoEnd; ++histoIt) {
203  (*histoIt).second->Reset();
204  }
205  }
206 
207  // re-set mapping for not real channels in the occupancyHits per chamber
208  for (int wh = -2; wh <= 2; wh++) {
209  for (int sect = 1; sect <= 14; sect++) {
210  for (int st = 1; st <= 4; st++) {
211  if (sliceTestMode && (sect != 12 || wh != 2)) {
212  continue;
213  }
214  if ((sect == 13 || sect == 14) && st != 4) {
215  continue;
216  }
217  const DTChamberId dtChId(wh, st, sect);
218  channelsMap(dtChId, "OccupancyAllHits_perCh");
219  }
220  }
221  }
222 
223  // loop over wheel summaries
224  map<string, map<int, MonitorElement*> >::const_iterator whHistosIt = wheelHistos.begin();
225  map<string, map<int, MonitorElement*> >::const_iterator whHistosEnd = wheelHistos.end();
226  for (; whHistosIt != whHistosEnd; ++whHistosIt) {
227  if ((*whHistosIt).first.find("Sync") == string::npos) { // FIXME skips synch noise plots
228  map<int, MonitorElement*>::const_iterator histoIt = (*whHistosIt).second.begin();
229  map<int, MonitorElement*>::const_iterator histoEnd = (*whHistosIt).second.end();
230  for (; histoIt != histoEnd; ++histoIt) {
231  (*histoIt).second->Reset();
232  }
233  }
234  }
235  }
236 }
237 
238 void DTDigiTask::bookHistos(DQMStore::IBooker& ibooker, const DTSuperLayerId& dtSL, string folder, string histoTag) {
239  // set the folder
240  stringstream wheel;
241  wheel << dtSL.wheel();
242  stringstream station;
243  station << dtSL.station();
244  stringstream sector;
245  sector << dtSL.sector();
246  stringstream superLayer;
247  superLayer << dtSL.superlayer();
248  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str());
249 
250  // Build the histo name
251  string histoName =
252  histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str();
253 
254  LogTrace("DTDQM|DTMonitorModule|DTDigiTask")
255  << "[DTDigiTask]: booking SL histo:" << histoName << " (tag: " << histoTag << ") folder: "
256  << topFolder() + "Wheel" + wheel.str() + "/Station" + station.str() + "/Sector" + sector.str() + "/" + folder
257  << endl;
258 
259  // ttrig and rms are TDC counts
260  if (readTTrigDB)
262  else
264 
265  if (folder == "TimeBoxes") {
266  string histoTitle = histoName + " (TDC Counts)";
267 
268  if (!readTTrigDB) {
269  (digiHistos[histoTag])[dtSL.rawId()] = ibooker.book1D(
271  if (doLayerTimeBoxes) { // Book TimeBoxes per layer
272  for (int layer = 1; layer != 5; ++layer) {
273  DTLayerId layerId(dtSL, layer);
274  stringstream layerHistoName;
275  layerHistoName << histoName << "_L" << layer;
276  (digiHistos[histoTag])[layerId.rawId()] = ibooker.book1D(layerHistoName.str(),
277  layerHistoName.str(),
279  tdcPedestal,
281  }
282  }
283  } else {
284  (digiHistos[histoTag])[dtSL.rawId()] =
285  ibooker.book1D(histoName, histoTitle, 3 * tMax / timeBoxGranularity, tTrig - tMax, tTrig + 2 * tMax);
286  if (doLayerTimeBoxes) {
287  // Book TimeBoxes per layer
288  for (int layer = 1; layer != 5; ++layer) {
289  DTLayerId layerId(dtSL, layer);
290  stringstream layerHistoName;
291  layerHistoName << histoName << "_L" << layer;
292  (digiHistos[histoTag])[layerId.rawId()] = ibooker.book1D(
293  layerHistoName.str(), layerHistoName.str(), 3 * tMax / timeBoxGranularity, tTrig - tMax, tTrig + 2 * tMax);
294  }
295  }
296  }
297  }
298 
299  if (folder == "CathodPhotoPeaks") {
300  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" +
301  station.str() + "/" + folder);
302  (digiHistos[histoTag])[dtSL.rawId()] = ibooker.book1D(histoName, histoName, 500, 0, 1000);
303  }
304 }
305 
306 void DTDigiTask::bookHistos(DQMStore::IBooker& ibooker, const DTChamberId& dtCh, string folder, string histoTag) {
307  // set the current folder
308  stringstream wheel;
309  wheel << dtCh.wheel();
310  stringstream station;
311  station << dtCh.station();
312  stringstream sector;
313  sector << dtCh.sector();
314  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str());
315 
316  // build the histo name
317  string histoName = histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
318 
319  LogTrace("DTDQM|DTMonitorModule|DTDigiTask")
320  << "[DTDigiTask]: booking chamber histo:"
321  << " (tag: " << histoTag
322  << ") folder: " << topFolder() + "Wheel" + wheel.str() + "/Station" + station.str() + "/Sector" + sector.str()
323  << endl;
324 
325  if (folder == "Occupancies") {
326  const DTChamber* dtchamber = muonGeom->chamber(dtCh);
327  const std::vector<const DTSuperLayer*>& dtSupLylist = dtchamber->superLayers();
328  std::vector<const DTSuperLayer*>::const_iterator suly = dtSupLylist.begin();
329  std::vector<const DTSuperLayer*>::const_iterator sulyend = dtSupLylist.end();
330 
331  int nWires = 0;
332  int firstWire = 0;
333  int nWires_max = 0;
334 
335  while (suly != sulyend) {
336  const std::vector<const DTLayer*> dtLyList = (*suly)->layers();
337  std::vector<const DTLayer*>::const_iterator ly = dtLyList.begin();
338  std::vector<const DTLayer*>::const_iterator lyend = dtLyList.end();
339  stringstream superLayer;
340  superLayer << (*suly)->id().superlayer();
341 
342  while (ly != lyend) {
343  nWires = muonGeom->layer((*ly)->id())->specificTopology().channels();
344  firstWire = muonGeom->layer((*ly)->id())->specificTopology().firstChannel();
345  stringstream layer;
346  layer << (*ly)->id().layer();
347  string histoName_layer = histoName + "_SL" + superLayer.str() + "_L" + layer.str();
348  if (histoTag == "OccupancyAllHits_perL" || histoTag == "OccupancyNoise_perL" ||
349  histoTag == "OccupancyInTimeHits_perL")
350  (digiHistos[histoTag])[(*ly)->id().rawId()] =
351  ibooker.book1D(histoName_layer, histoName_layer, nWires, firstWire, nWires + firstWire);
352  ++ly;
353  if ((nWires + firstWire) > nWires_max)
354  nWires_max = (nWires + firstWire);
355  }
356  ++suly;
357  }
358 
359  if (histoTag != "OccupancyAllHits_perL" && histoTag != "OccupancyNoise_perL" &&
360  histoTag != "OccupancyInTimeHits_perL") {
361  // Set the title to show the time interval used (only if unique == not from DB)
362  string histoTitle = histoName;
363  if (!readTTrigDB && histoTag == "OccupancyInTimeHits_perCh") {
364  stringstream title;
365  int inTimeHitsLowerBoundCorr = int(round(defaultTTrig)) - inTimeHitsLowerBound;
366  int inTimeHitsUpperBoundCorr = int(round(defaultTTrig)) + defaultTmax + inTimeHitsUpperBound;
367  title << "Occ. digis in time [" << inTimeHitsLowerBoundCorr << ", " << inTimeHitsUpperBoundCorr
368  << "] (TDC counts)";
369  histoTitle = title.str();
370  }
371  (digiHistos[histoTag])[dtCh.rawId()] =
372  ibooker.book2D(histoName, histoTitle, nWires_max, 1, nWires_max + 1, 12, 0, 12);
373 
374  for (int i = 1; i <= 12; i++) {
375  if (i < 5) {
376  stringstream layer;
377  string layer_name;
378  layer << i;
379  layer >> layer_name;
380  string label = "SL1: L" + layer_name;
381  (digiHistos[histoTag])[dtCh.rawId()]->setBinLabel(i, label, 2);
382  } else if (i > 4 && i < 9) {
383  stringstream layer;
384  string layer_name;
385  layer << (i - 4);
386  layer >> layer_name;
387  string label = "SL2: L" + layer_name;
388  (digiHistos[histoTag])[dtCh.rawId()]->setBinLabel(i, label, 2);
389  } else if (i > 8 && i < 13) {
390  stringstream layer;
391  string layer_name;
392  layer << (i - 8);
393  layer >> layer_name;
394  string label = "SL3: L" + layer_name;
395  (digiHistos[histoTag])[dtCh.rawId()]->setBinLabel(i, label, 2);
396  }
397  }
398  }
399  }
400 }
401 
402 void DTDigiTask::bookHistos(DQMStore::IBooker& ibooker, const int wheelId, string folder, string histoTag) {
403  // Set the current folder
404  stringstream wheel;
405  wheel << wheelId;
406 
407  // build the histo name
408  string histoName = histoTag + "_W" + wheel.str();
409 
410  LogTrace("DTDQM|DTMonitorModule|DTDigiTask")
411  << "[DTDigiTask]: booking wheel histo:" << histoName << " (tag: " << histoTag
412  << ") folder: " << topFolder() + "Wheel" + wheel.str() + "/" << endl;
413 
414  if (folder == "Occupancies") {
415  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str());
416  string histoTitle = "# of digis per chamber WHEEL: " + wheel.str();
417  (wheelHistos[histoTag])[wheelId] = ibooker.book2D(histoName, histoTitle, 12, 1, 13, 4, 1, 5);
418  (wheelHistos[histoTag])[wheelId]->setBinLabel(1, "MB1", 2);
419  (wheelHistos[histoTag])[wheelId]->setBinLabel(2, "MB2", 2);
420  (wheelHistos[histoTag])[wheelId]->setBinLabel(3, "MB3", 2);
421  (wheelHistos[histoTag])[wheelId]->setBinLabel(4, "MB4", 2);
422  (wheelHistos[histoTag])[wheelId]->setAxisTitle("sector", 1);
423  } else if (folder == "SynchNoise") {
424  ibooker.setCurrentFolder("DT/05-Noise/SynchNoise");
425  if (histoTag == "SyncNoiseEvents") {
426  string histoTitle = "# of Syncronous-noise events WHEEL: " + wheel.str();
427  (wheelHistos[histoTag])[wheelId] = ibooker.book2D(histoName, histoTitle, 12, 1, 13, 4, 1, 5);
428  (wheelHistos[histoTag])[wheelId]->setBinLabel(1, "MB1", 2);
429  (wheelHistos[histoTag])[wheelId]->setBinLabel(2, "MB2", 2);
430  (wheelHistos[histoTag])[wheelId]->setBinLabel(3, "MB3", 2);
431  (wheelHistos[histoTag])[wheelId]->setBinLabel(4, "MB4", 2);
432  (wheelHistos[histoTag])[wheelId]->setAxisTitle("sector", 1);
433  } else if (histoTag == "SyncNoiseChambs") {
434  string histoTitle = "# of Synchornous-noise chamb per evt. WHEEL: " + wheel.str();
435  (wheelHistos[histoTag])[wheelId] = ibooker.book1D(histoName, histoTitle, 50, 0.5, 50.5);
436  (wheelHistos[histoTag])[wheelId]->setAxisTitle("# of noisy chambs.", 1);
437  (wheelHistos[histoTag])[wheelId]->setAxisTitle("# of evts.", 2);
438  }
439  }
440 }
441 // does the real job
443  nevents++;
445  if (nevents % 1000 == 0) {
446  LogTrace("DTDQM|DTMonitorModule|DTDigiTask")
447  << "[DTDigiTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event() << endl;
448  }
449 
450  // Get the ingredients from the event
451 
452  // Digi collection
454  event.getByToken(dtDigiToken_, dtdigis);
455 
456  // LTC digis
457  if (!isLocalRun)
458  event.getByToken(ltcDigiCollectionToken_, ltcdigis);
459 
460  // Status map (for noisy channels)
461  if (checkNoisyChannels) {
462  // Get the map of noisy channels
463  statusMap = &c.getData(statusMapToken_);
464  }
465 
466  string histoTag;
467 
468  // Check if the digi container is empty
469  if (dtdigis->begin() == dtdigis->end()) {
470  LogTrace("DTDQM|DTMonitorModule|DTDigiTask") << "Event " << nevents << " empty." << endl;
471  }
472 
473  if (lookForSyncNoise || filterSyncNoise) { // dosync
474  // Count the # of digis per chamber
476  for (dtLayerId_It = dtdigis->begin(); dtLayerId_It != dtdigis->end(); dtLayerId_It++) {
477  DTChamberId chId = ((*dtLayerId_It).first).chamberId();
478  if (hitMap.find(chId) == hitMap.end()) { // new chamber
479  hitMap[chId] = 0;
480  }
481  hitMap[chId] += (((*dtLayerId_It).second).second - ((*dtLayerId_It).second).first);
482  }
483 
484  // check chamber with # of digis above threshold and flag them as noisy
485  map<DTChamberId, int>::const_iterator hitMapIt = hitMap.begin();
486  map<DTChamberId, int>::const_iterator hitMapEnd = hitMap.end();
487 
488  map<int, int> chMap;
489 
490  for (; hitMapIt != hitMapEnd; ++hitMapIt) {
491  if ((hitMapIt->second) > maxTDCHits) {
492  DTChamberId chId = hitMapIt->first;
493  int wh = chId.wheel();
494 
495  LogTrace("DTDQM|DTMonitorModule|DTDigiTask")
496  << "[DTDigiTask] Synch noise in chamber: " << chId << " with # digis: " << hitMapIt->second << endl;
497 
498  if (chMap.find(wh) == chMap.end()) {
499  chMap[wh] = 0;
500  }
501  chMap[wh]++;
502 
503  syncNoisyChambers.insert(chId);
504 
505  wheelHistos["SyncNoiseEvents"][wh]->Fill(chId.sector(), chId.station());
506  }
507  }
508 
509  // fill # of noisy ch per wheel plot
510  map<int, int>::const_iterator chMapIt = chMap.begin();
511  map<int, int>::const_iterator chMapEnd = chMap.end();
512  for (; chMapIt != chMapEnd; ++chMapIt) {
513  wheelHistos["SyncNoiseChambs"][(*chMapIt).first]->Fill((*chMapIt).second);
514  }
515 
516  // clear the map of # of digis per chamber: not needed anymore
517  hitMap.clear();
518 
519  if (!syncNoisyChambers.empty()) {
520  LogVerbatim("DTDQM|DTMonitorModule|DTDigiTask") << "[DTDigiTask] Synch Noise in event: " << nevents;
521  if (filterSyncNoise)
522  LogVerbatim("DTDQM|DTMonitorModule|DTDigiTask")
523  << "\tnoisy time-boxes and occupancy will not be filled!" << endl;
524  syncNumTot++;
525  syncNum++;
526  }
527 
528  // Logging of "large" synch Noisy events in private DQM
529  if (syncNoisyChambers.size() > 3) {
530  time_t eventTime = time_t(event.time().value() >> 32);
531 
532  LogVerbatim("DTDQM|DTMonitorModule|DTDigiTask|DTSynchNoise")
533  << "[DTDigiTask] At least 4 Synch Noisy chambers in Run : " << event.id().run()
534  << " Lumi : " << event.id().luminosityBlock() << " Event : " << event.id().event()
535  << " at time : " << ctime(&eventTime) << endl;
536 
537  set<DTChamberId>::const_iterator chIt = syncNoisyChambers.begin();
538  set<DTChamberId>::const_iterator chEnd = syncNoisyChambers.end();
539 
540  stringstream synchNoisyCh;
541  for (; chIt != chEnd; ++chIt) {
542  synchNoisyCh << " " << (*chIt);
543  }
544  LogVerbatim("DTDQM|DTMonitorModule|DTDigiTask|DTSynchNoise")
545  << "[DTDigiTask] Chamber List :" << synchNoisyCh.str() << endl;
546  }
547 
548  if (nevents % 1000 == 0) {
549  LogVerbatim("DTDQM|DTMonitorModule|DTDigiTask")
550  << (syncNumTot * 100. / nevents) << "% sync noise events since the beginning \n"
551  << (syncNum * 0.1) << "% sync noise events in the last 1000 events " << endl;
552  syncNum = 0;
553  }
554  }
555 
556  bool isSyncNoisy = false;
557 
559  for (dtLayerId_It = dtdigis->begin(); dtLayerId_It != dtdigis->end(); ++dtLayerId_It) { // Loop over layers
560  isSyncNoisy = false;
561  // check if chamber labeled as synch noisy
562  if (filterSyncNoise) {
563  DTChamberId chId = ((*dtLayerId_It).first).chamberId();
564  if (syncNoisyChambers.find(chId) != syncNoisyChambers.end()) {
565  isSyncNoisy = true;
566  }
567  }
568 
569  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
570  digiIt != ((*dtLayerId_It).second).second;
571  ++digiIt) { // Loop over all digis
572 
573  bool isNoisy = false;
574  bool isFEMasked = false;
575  bool isTDCMasked = false;
576  bool isTrigMask = false;
577  bool isDead = false;
578  bool isNohv = false;
579  if (checkNoisyChannels) {
580  const DTWireId wireId(((*dtLayerId_It).first), (*digiIt).wire());
581  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
582  }
583 
584  // Get the useful IDs
585  const DTSuperLayerId dtSLId = ((*dtLayerId_It).first).superlayerId();
586  uint32_t indexSL = dtSLId.rawId();
587  const DTChamberId dtChId = dtSLId.chamberId();
588  uint32_t indexCh = dtChId.rawId();
589  int layer_number = ((*dtLayerId_It).first).layer();
590  int superlayer_number = dtSLId.superlayer();
591 
592  // Read the ttrig DB or set a rough value from config
593  // ttrig and rms are TDC counts
594  if (readTTrigDB)
595  tTrigMap->get(((*dtLayerId_It).first).superlayerId(), tTrig, tTrigRMS, kFactor, DTTimeUnits::counts);
596  else
598 
599  int inTimeHitsLowerBoundCorr = int(round(tTrig)) - inTimeHitsLowerBound;
600  int inTimeHitsUpperBoundCorr = int(round(tTrig)) + tMax + inTimeHitsUpperBound;
601 
602  float t0;
603  float t0RMS;
604  int tdcTime = (*digiIt).countsTDC();
605 
606  if (subtractT0) {
607  const DTWireId dtWireId(((*dtLayerId_It).first), (*digiIt).wire());
608  // t0s and rms are TDC counts
609  t0Map->get(dtWireId, t0, t0RMS, DTTimeUnits::counts);
610  tdcTime += int(round(t0));
611  }
612 
613  if (sliceTestMode) {
614  tdcTime = std::max(tdcPedestal + 1, std::min(tdcPedestal + maxTTMounts - 1, tdcTime));
615  // std::cout << tdcTime << std::endl;
616  }
617 
618  // Fill Time-Boxes
619  // NOTE: avoid to fill TB and PhotoPeak with noise. Occupancy are filled anyway
620  if ((!isNoisy) && (!isSyncNoisy)) { // Discard noisy channels
621  // TimeBoxes per SL
622  histoTag = "TimeBox" + triggerSource();
623 
624  (digiHistos.find(histoTag)->second).find(indexSL)->second->Fill(tdcTime);
625  if (doLayerTimeBoxes)
626  (digiHistos.find(histoTag)->second).find((*dtLayerId_It).first.rawId())->second->Fill(tdcTime);
627  }
628 
629  // Fill Occupancies
630  if (!isSyncNoisy) { // Discard synch noisy channels
631 
632  if (doAllHitsOccupancies) { // fill occupancies for all hits
633  //Occupancies per chamber & layer
634  histoTag = "OccupancyAllHits_perCh";
635  map<uint32_t, MonitorElement*>::const_iterator mappedHisto = digiHistos[histoTag].find(indexCh);
636 
637  //FR comment the following cannot pass ibooker to analyze method!
638  /*
639  if (mappedHisto == digiHistos[histoTag].end()) { // dynamic booking
640  bookHistos(ibooker, dtChId, string("Occupancies"), histoTag);
641  mappedHisto = digiHistos[histoTag].find(indexCh);
642  }
643  */
644  mappedHisto->second->Fill((*digiIt).wire(), (layer_number + (superlayer_number - 1) * 4) - 1);
645 
646  // Fill the chamber occupancy
647  histoTag = "OccupancyAllHits";
648  map<int, MonitorElement*>::const_iterator histoPerWheel = wheelHistos[histoTag].find(dtChId.wheel());
649 
650  histoPerWheel->second->Fill(dtChId.sector(), dtChId.station()); // FIXME: normalize to # of layers
651  }
652 
653  if (doNoiseOccupancies) { // fill occupancies for hits before the ttrig
654  if (tdcTime < inTimeHitsLowerBoundCorr) {
655  // FIXME: what about tdcTime > inTimeHitsUpperBoundCorr ???
656 
657  // Noise: Before tTrig
658  //Occupancies Noise per chamber & layer
659  histoTag = "OccupancyNoise_perCh";
660  map<uint32_t, MonitorElement*>::const_iterator mappedHisto = digiHistos[histoTag].find(indexCh);
661 
662  mappedHisto->second->Fill((*digiIt).wire(), (layer_number + (superlayer_number - 1) * 4) - 1);
663 
664  // Fill the chamber occupancy
665 
666  histoTag = "OccupancyNoise";
667  map<int, MonitorElement*>::const_iterator histoPerWheel = wheelHistos[histoTag].find(dtChId.wheel());
668 
669  histoPerWheel->second->Fill(dtChId.sector(), dtChId.station()); // FIXME: normalize to # of layers
670  }
671  }
672 
673  if (doInTimeOccupancies) { // fill occpunacies for in-time hits only
674  if (tdcTime > inTimeHitsLowerBoundCorr && tdcTime < inTimeHitsUpperBoundCorr) {
675  // Physical hits: within the time window
676 
677  //Occupancies Signal per chamber & layer
678  histoTag = "OccupancyInTimeHits_perCh";
679  map<uint32_t, MonitorElement*>::const_iterator mappedHisto = digiHistos[histoTag].find(indexCh);
680 
681  mappedHisto->second->Fill((*digiIt).wire(), (layer_number + (superlayer_number - 1) * 4) - 1);
682 
683  // Fill the chamber occupancy
684  histoTag = "OccupancyInTimeHits";
685  map<int, MonitorElement*>::const_iterator histoPerWheel = wheelHistos[histoTag].find(dtChId.wheel());
686 
687  histoPerWheel->second->Fill(dtChId.sector(), dtChId.station()); // FIXME: normalize to # of layers
688  }
689  }
690  }
691  }
692  }
693 
694  syncNoisyChambers.clear();
695 }
696 
698  string l1ASource;
699  if (isLocalRun)
700  return l1ASource;
701 
702  for (std::vector<LTCDigi>::const_iterator ltc_it = ltcdigis->begin(); ltc_it != ltcdigis->end(); ltc_it++) {
703  size_t otherTriggerSum = 0;
704  for (size_t i = 1; i < 6; i++)
705  otherTriggerSum += size_t((*ltc_it).HasTriggered(i));
706 
707  if ((*ltc_it).HasTriggered(0) && otherTriggerSum == 0)
708  l1ASource = "DTonly";
709  else if (!(*ltc_it).HasTriggered(0))
710  l1ASource = "NoDT";
711  else if ((*ltc_it).HasTriggered(0) && otherTriggerSum > 0)
712  l1ASource = "DTalso";
713  }
714 
715  return l1ASource;
716 }
717 
718 string DTDigiTask::topFolder() const {
719  if (tpMode)
720  return string("DT/10-TestPulses/");
721  else if (sliceTestMode)
722  return string("DT/01-SliceTestDigi/");
723  return string("DT/01-Digi/");
724 }
725 
726 void DTDigiTask::channelsMap(const DTChamberId& dtCh, string histoTag) {
727  // n max channels
728  int nWires_max = (digiHistos[histoTag])[dtCh.rawId()]->getNbinsX();
729 
730  // set bin content = -1 for each not real channel. For visualization purposes
731  for (int sl = 1; sl <= 3; sl++) {
732  for (int ly = 1; ly <= 4; ly++) {
733  for (int ch = 1; ch <= nWires_max; ch++) {
734  int dduId = -1, rosId = -1, robId = -1, tdcId = -1, channelId = -1;
735  int realCh = mapping->geometryToReadOut(
736  dtCh.wheel(), dtCh.station(), dtCh.sector(), sl, ly, ch, dduId, rosId, robId, tdcId, channelId);
737 
738  // realCh = 0 if the channel exists, while realCh = 1 if it does not exist
739  if (realCh) {
740  int lybin = (4 * sl - 4) + ly;
741  (digiHistos[histoTag])[dtCh.rawId()]->setBinContent(ch, lybin, -1.);
742  }
743  }
744  }
745  }
746 }
747 
748 // Local Variables:
749 // show-trailing-whitespace: t
750 // truncate-lines: t
751 // End:
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:42
int defaultTmax
Definition: DTDigiTask.h:135
bool doStaticBooking
Definition: DTDigiTask.h:138
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LuminosityBlockNumber_t luminosityBlock() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DTDigiTask.cc:102
void channelsMap(const DTChamberId &dtCh, std::string histoTag)
To map real channels.
Definition: DTDigiTask.cc:726
bool tpMode
Definition: DTDigiTask.h:156
bool doLayerTimeBoxes
Definition: DTDigiTask.h:163
bool filterSyncNoise
Definition: DTDigiTask.h:158
const DTReadOutMapping * mapping
Definition: DTDigiTask.h:109
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
int maxTTMounts
Definition: DTDigiTask.h:151
edm::ESGetToken< DTStatusFlag, DTStatusFlagRcd > statusMapToken_
Definition: DTDigiTask.h:117
bool readTTrigDB
Definition: DTDigiTask.h:131
bool lookForSyncNoise
Definition: DTDigiTask.h:157
float kFactor
Definition: DTDigiTask.h:95
int geometryToReadOut(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, int &dduId, int &rosId, int &robId, int &tdcId, int &channelId) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::map< DTChamberId, int > hitMap
Definition: DTDigiTask.h:99
#define LogTrace(id)
edm::ESGetToken< DTReadOutMapping, DTReadOutMappingRcd > readOutMapToken_
Definition: DTDigiTask.h:108
const DTStatusFlag * statusMap
Definition: DTDigiTask.h:118
T getUntrackedParameter(std::string const &, T const &) const
DTDigiTask(const edm::ParameterSet &ps)
Constructor.
Definition: DTDigiTask.cc:33
void Fill(long long x)
U second(std::pair< T, U > const &p)
edm::EDGetTokenT< DTDigiCollection > dtDigiToken_
Definition: DTDigiTask.h:126
char const * label
bool checkNoisyChannels
Definition: DTDigiTask.h:144
DTChamberId chamberId() const
Return the corresponding ChamberId.
bool isLocalRun
Definition: DTDigiTask.h:140
edm::ESGetToken< DTT0, DTT0Rcd > T0Token_
Definition: DTDigiTask.h:113
bool doInTimeOccupancies
Definition: DTDigiTask.h:154
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
Definition: DTDigiTask.h:106
bool doNoiseOccupancies
Definition: DTDigiTask.h:153
Transition
Definition: Transition.h:12
std::map< std::string, std::map< int, MonitorElement * > > wheelHistos
Definition: DTDigiTask.h:121
int nevents
Definition: DTDigiTask.h:86
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:51
const DTTtrig * tTrigMap
Definition: DTDigiTask.h:112
int resetCycle
Definition: DTDigiTask.h:142
int inTimeHitsUpperBound
Definition: DTDigiTask.h:149
int defaultTTrig
Definition: DTDigiTask.h:146
float tTrig
tTrig from the DB
Definition: DTDigiTask.h:93
int tMax
no needs to be precise. Value from PSets will always be used
Definition: DTDigiTask.h:89
int tdcPedestal
Definition: DTDigiTask.h:161
const DTGeometry * muonGeom
Definition: DTDigiTask.h:107
bool doAllHitsOccupancies
Definition: DTDigiTask.h:152
int maxTDCHits
Definition: DTDigiTask.h:90
int superlayer() const
Return the superlayer number (deprecated method name)
bool subtractT0
Definition: DTDigiTask.h:133
LuminosityBlockID id() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void bookHistos(DQMStore::IBooker &ibooker, const DTSuperLayerId &dtSL, std::string folder, std::string histoTag)
Book the ME.
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
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DTDigiTask.cc:124
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
Definition: DTT0.cc:48
std::vector< DigiType >::const_iterator const_iterator
int timeBoxGranularity
Definition: DTDigiTask.h:150
std::string topFolder() const
Definition: DTDigiTask.cc:718
~DTDigiTask() override
Destructor.
Definition: DTDigiTask.cc:98
std::set< DTChamberId > syncNoisyChambers
Definition: DTDigiTask.h:100
int syncNumTot
Definition: DTDigiTask.h:101
int get(int wheelId, int stationId, int sectorId, int slId, float &tTrig, float &tTrms, float &kFact, DTTimeUnits::type unit) const
get content
Definition: DTTtrig.cc:59
MonitorElement * nEventMonitor
Definition: DTDigiTask.h:166
int inTimeHitsLowerBound
Definition: DTDigiTask.h:148
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
float tTrigRMS
Definition: DTDigiTask.h:94
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context) override
To reset the MEs.
Definition: DTDigiTask.cc:188
edm::ESGetToken< DTTtrig, DTTtrigRcd > TtrigToken_
Definition: DTDigiTask.h:111
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::map< std::string, std::map< uint32_t, MonitorElement * > > digiHistos
Definition: DTDigiTask.h:120
int cellStatus(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, bool &noiseFlag, bool &feMask, bool &tdcMask, bool &trigMask, bool &deadFlag, bool &nohvFlag) const
get content
Definition: DTStatusFlag.h:90
std::string triggerSource()
get the L1A source
Definition: DTDigiTask.cc:697
const DTT0 * t0Map
Definition: DTDigiTask.h:114
edm::Handle< LTCDigiCollection > ltcdigis
Definition: DTDigiTask.h:104
bool sliceTestMode
Definition: DTDigiTask.h:160
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
Definition: DTDigiTask.cc:442
Definition: event.py:1
edm::EDGetTokenT< LTCDigiCollection > ltcDigiCollectionToken_
Definition: DTDigiTask.h:128
Definition: Run.h:45
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96