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