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