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