CMS 3D CMS Logo

DTLocalTriggerTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTLocalTriggerTask.cc
3  *
4  * \author M. Zanetti - INFN Padova
5  *
6 */
7 
9 
10 // Framework
12 
13 // DT trigger
15 
16 // Geometry
21 
22 //Root
23 #include "TH1.h"
24 #include "TAxis.h"
25 
26 #include <sstream>
27 #include <iostream>
28 #include <fstream>
29 
30 using namespace edm;
31 using namespace std;
32 
34  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()),
35  trigGeomUtils(nullptr),
36  isLocalRun(ps.getUntrackedParameter<bool>("localrun", true)) {
37  if (!isLocalRun) {
38  ltcDigiCollectionToken_ = consumes<LTCDigiCollection>(ps.getParameter<edm::InputTag>("ltcDigiCollectionTag"));
39  }
40 
41  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Constructor" << endl;
42 
43  tpMode = ps.getUntrackedParameter<bool>("testPulseMode", false);
44  detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis", false);
45  doTMTheta = ps.getUntrackedParameter<bool>("enableTMTheta", false);
46  tm_Token_ = consumes<L1MuDTChambPhContainer>(
47  ps.getUntrackedParameter<InputTag>("tm_label", InputTag("twinMuxStage2Digis:PhIn")));
48  tmTh_Token_ = consumes<L1MuDTChambThContainer>(
49  ps.getUntrackedParameter<edm::InputTag>("tmTh_label", InputTag("twinMuxStage2Digis:ThIn")));
50 
51  ros_Token_ =
52  consumes<DTLocalTriggerCollection>(ps.getUntrackedParameter<InputTag>("ros_label", InputTag("dtunpacker")));
53  seg_Token_ =
54  consumes<DTRecSegment4DCollection>(ps.getUntrackedParameter<InputTag>("seg_label", InputTag("dt4DSegments")));
55 
56  if (tpMode) {
57  baseFolderTM = "DT/11-LocalTriggerTP-TM/";
58  } else {
59  baseFolderTM = "DT/03-LocalTrigger-TM/";
60  }
61 
62  parameters = ps;
63 }
64 
66  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask")
67  << "[DTLocalTriggerTask]: analyzed " << nevents << " events" << endl;
68  if (trigGeomUtils) {
69  delete trigGeomUtils;
70  }
71 }
72 
74  nevents = 0;
75  muonGeom = &context.getData(muonGeomToken_);
77 }
78 
80  edm::Run const& iRun,
81  edm::EventSetup const& context) {
82  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: bookHistograms" << endl;
83 
84  if (parameters.getUntrackedParameter<bool>("staticBooking", true)) { // Static histo booking
85 
86  vector<string> trigSources;
87  if (parameters.getUntrackedParameter<bool>("localrun", true)) {
88  trigSources.push_back("");
89  } else {
90  trigSources.push_back("_DTonly");
91  trigSources.push_back("_NoDT");
92  trigSources.push_back("_DTalso");
93  }
94  vector<string>::const_iterator trigSrcIt = trigSources.begin();
95  vector<string>::const_iterator trigSrcEnd = trigSources.end();
96 
97  if (parameters.getUntrackedParameter<bool>("process_tm", true)) {
98  bookBarrelHistos(ibooker, "TM_ErrorsChamberID");
99  }
100 
101  if (tpMode) {
102  for (int stat = 1; stat < 5; ++stat) {
103  for (int wh = -2; wh < 3; ++wh) {
104  for (int sect = 1; sect < 13; ++sect) {
105  DTChamberId dtChId(wh, stat, sect);
106 
107  if (parameters.getUntrackedParameter<bool>("process_tm", true)) { // TM data
108  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_BXvsQual" + (*trigSrcIt));
109  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_QualvsPhirad" + (*trigSrcIt));
110  }
111  }
112  }
113  } // end of loop
114  } else {
115  for (; trigSrcIt != trigSrcEnd; ++trigSrcIt) {
116  for (int wh = -2; wh < 3; ++wh) {
117  for (int sect = 1; sect < 13; ++sect) {
118  for (int stat = 1; stat < 5; ++stat) {
119  DTChamberId dtChId(wh, stat, sect);
120  if (parameters.getUntrackedParameter<bool>("process_tm", true)) { // TM data
121 
122  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_BXvsQual_In" + (*trigSrcIt));
123  if (detailedAnalysis) {
124  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_QualvsPhirad_In" + (*trigSrcIt));
125  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_QualvsPhibend_In" + (*trigSrcIt));
126  }
127  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_Flag1stvsQual_In" + (*trigSrcIt));
128  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_FlagUpDownvsQual_In" + (*trigSrcIt));
129 
130  bookHistos(ibooker, dtChId, "LocalTriggerPhiIn", "TM_BestQual_In" + (*trigSrcIt));
131  if (stat != 4 && doTMTheta) {
132  bookHistos(ibooker, dtChId, "LocalTriggerTheta", "TM_PositionvsBX" + (*trigSrcIt));
133  bookHistos(ibooker, dtChId, "LocalTriggerTheta", "TM_QualityvsBX" + (*trigSrcIt));
134 
135  bookHistos(ibooker, dtChId, "LocalTriggerTheta", "TM_PositionvsQual" + (*trigSrcIt));
136 
137  bookHistos(ibooker, dtChId, "LocalTriggerTheta", "TM_ThetaBXvsQual" + (*trigSrcIt));
138  bookHistos(ibooker, dtChId, "LocalTriggerTheta", "TM_ThetaBestQual" + (*trigSrcIt));
139  }
140 
141  if (parameters.getUntrackedParameter<bool>("process_seg", true)) { // TM + Segemnt
142  bookHistos(ibooker, dtChId, "Segment", "TM_PhitkvsPhitrig" + (*trigSrcIt));
143  bookHistos(ibooker, dtChId, "Segment", "TM_PhibtkvsPhibtrig" + (*trigSrcIt));
144  bookHistos(ibooker, dtChId, "Segment", "TM_PhiResidual" + (*trigSrcIt));
145  bookHistos(ibooker, dtChId, "Segment", "TM_PhiResidualvsLUTPhi" + (*trigSrcIt));
146  bookHistos(ibooker, dtChId, "Segment", "TM_PhibResidual" + (*trigSrcIt));
147  bookHistos(ibooker, dtChId, "Segment", "TM_HitstkvsQualtrig" + (*trigSrcIt));
148  bookHistos(ibooker, dtChId, "Segment", "TM_TrackPosvsAngle" + (*trigSrcIt));
149  bookHistos(ibooker, dtChId, "Segment", "TM_TrackPosvsAngleandTrig" + (*trigSrcIt));
150  bookHistos(ibooker, dtChId, "Segment", "TM_TrackPosvsAngleandTrigHHHL" + (*trigSrcIt));
151  if (stat != 4) {
152  bookHistos(ibooker, dtChId, "Segment", "TM_TrackThetaPosvsAngle" + (*trigSrcIt)); // theta view
153  bookHistos(ibooker, dtChId, "Segment", "TM_TrackThetaPosvsAngleandTrig" + (*trigSrcIt));
154  bookHistos(ibooker,
155  dtChId,
156  "Segment",
157  "TM_TrackThetaPosvsAngleandTrigH" + (*trigSrcIt)); // TM theta quality not available!
158  }
159  }
160  }
161  }
162  }
163  for (int sect = 13; sect < 15; ++sect) {
164  DTChamberId dtChId(wh, 4, sect);
165  if (parameters.getUntrackedParameter<bool>("process_tm", true) &&
166  parameters.getUntrackedParameter<bool>("process_seg", true)) { // TM+SEG LUTs data
167  bookHistos(ibooker, dtChId, "Segment", "TM_PhitkvsPhitrig" + (*trigSrcIt));
168  bookHistos(ibooker, dtChId, "Segment", "TM_PhibtkvsPhibtrig" + (*trigSrcIt));
169  bookHistos(ibooker, dtChId, "Segment", "TM_PhiResidual" + (*trigSrcIt));
170  bookHistos(ibooker, dtChId, "Segment", "TM_PhiResidualvsLUTPhi" + (*trigSrcIt));
171  bookHistos(ibooker, dtChId, "Segment", "TM_PhibResidual" + (*trigSrcIt));
172  }
173  }
174  }
175  } // end of loop
176  }
177  }
178 }
179 
181  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Begin of LS transition" << endl;
182 
183  if (lumiSeg.id().luminosityBlock() % parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
184  for (map<uint32_t, map<string, MonitorElement*> >::const_iterator histo = digiHistos.begin();
185  histo != digiHistos.end();
186  histo++) {
187  for (map<string, MonitorElement*>::const_iterator ht = (*histo).second.begin(); ht != (*histo).second.end();
188  ht++) {
189  (*ht).second->Reset();
190  }
191  }
192  }
193 }
194 
196  if (!nevents) {
198  e.getByToken(tm_Token_, l1DTTPGPh);
200  e.getByToken(tmTh_Token_, l1DTTPGTh);
201 
202  useTM = (l1DTTPGPh.isValid() || l1DTTPGTh.isValid()) && parameters.getUntrackedParameter<bool>("process_tm", true);
203 
204  Handle<DTRecSegment4DCollection> all4DSegments;
205  e.getByToken(seg_Token_, all4DSegments);
206  useSEG = all4DSegments.isValid() && parameters.getUntrackedParameter<bool>("process_seg", true);
207  }
208 
209  nevents++;
210 
211  triggerSource(e);
212 
213  if (useTM) {
215  e.getByToken(tm_Token_, l1DTTPGPh);
216  vector<L1MuDTChambPhDigi> const* l1PhTrig = l1DTTPGPh->getContainer();
217 
219  e.getByToken(tmTh_Token_, l1DTTPGTh);
220 
221  vector<L1MuDTChambThDigi> const* l1ThTrig = l1DTTPGTh->getContainer();
222 
223  runTMAnalysis(l1PhTrig, l1ThTrig);
224  }
225  if (!tpMode && useSEG) {
227  e.getByToken(seg_Token_, segments4D);
228 
229  runSegmentAnalysis(segments4D);
230  }
231 }
232 
234  ibooker.setCurrentFolder(topFolder());
235  if (histoTag == "TM_ErrorsChamberID") {
236  tm_IDDataErrorPlot = ibooker.book1D(histoTag.c_str(), "TM Data ID Error", 5, -2, 3);
237  tm_IDDataErrorPlot->setAxisTitle("wheel", 1);
238  }
239 
240  return;
241 }
242 
244  const DTChamberId& dtCh,
245  string folder,
246  string histoTag) {
247  int wh = dtCh.wheel();
248  int sc = dtCh.sector();
249  stringstream wheel;
250  wheel << wh;
251  stringstream station;
252  station << dtCh.station();
253  stringstream sector;
254  sector << sc;
255 
256  double minBX = 0;
257  double maxBX = 0;
258  int rangeBX = 0;
259 
260  string histoType = histoTag.substr(3, histoTag.find('_', 3) - 3);
261 
262  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() +
263  "/" + folder);
264 
265  string histoName = histoTag + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
266 
267  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask")
268  << "[DTLocalTriggerTask]: booking " << topFolder() << "Wheel" << wheel.str() << "/Sector" << sector.str()
269  << "/Station" << station.str() << "/" << folder << "/" << histoName << endl;
270 
271  if (histoType.find("BX") != string::npos) {
272  if (histoTag.substr(0, 2) == "TM") {
273  minBX = parameters.getUntrackedParameter<int>("minBXTM", -2) - 0.5;
274  maxBX = parameters.getUntrackedParameter<int>("maxBXTM", 2) + 0.5;
275  }
276  rangeBX = (int)(maxBX - minBX);
277  }
278 
279  if (folder == "LocalTriggerPhiIn") {
280  if (histoType == "BXvsQual") {
281  (digiHistos[dtCh.rawId()])[histoTag] =
282  ibooker.book2D(histoName, "BX vs trigger quality", 7, -0.5, 6.5, rangeBX, minBX, maxBX);
283  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 1);
284  return;
285  }
286  if (histoType == "BestQual") {
287  (digiHistos[dtCh.rawId()])[histoTag] =
288  ibooker.book1D(histoName, "Trigger quality of best primitives", 7, -0.5, 6.5);
289  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 1);
290  return;
291  }
292  if (histoType == "QualvsPhirad") {
293  (digiHistos[dtCh.rawId()])[histoTag] =
294  ibooker.book2D(histoName, "Trigger quality vs local position", 100, -500., 500., 7, -0.5, 6.5);
295  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 2);
296  return;
297  }
298  if (histoType == "QualvsPhibend") {
299  (digiHistos[dtCh.rawId()])[histoTag] =
300  ibooker.book2D(histoName, "Trigger quality vs local direction", 200, -40., 40., 7, -0.5, 6.5);
301  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 2);
302  return;
303  }
304  if (histoType == "Flag1stvsQual") {
305  (digiHistos[dtCh.rawId()])[histoTag] =
306  ibooker.book2D(histoName, "1st/2nd trig flag vs quality", 7, -0.5, 6.5, 2, -0.5, 1.5);
307  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 1);
308  return;
309  }
310  if (histoType == "FlagUpDownvsQual") {
311  (digiHistos[dtCh.rawId()])[histoTag] =
312  ibooker.book2D(histoName, "Up/Down trig flag vs quality", 7, -0.5, 6.5, 2, -0.5, 1.5);
313  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 1);
314  return;
315  }
316 
317  } else if (folder == "LocalTriggerTheta") {
318  if (histoType == "PositionvsBX") {
319  (digiHistos[dtCh.rawId()])[histoTag] =
320  ibooker.book2D(histoName, "Theta trigger position vs BX", rangeBX, minBX, maxBX, 7, -0.5, 6.5);
321  return;
322  }
323  if (histoType == "PositionvsQual") {
324  (digiHistos[dtCh.rawId()])[histoTag] =
325  ibooker.book2D(histoName, "Theta trigger position vs quality", 2, 0.5, 2.5, 7, -0.5, 6.5);
326  setQLabelsTheta((digiHistos[dtCh.rawId()])[histoTag], 1);
327  return;
328  }
329  if (histoType == "ThetaBXvsQual") {
330  (digiHistos[dtCh.rawId()])[histoTag] =
331  ibooker.book2D(histoName, "BX vs trigger quality", 2, 0.5, 2.5, rangeBX, minBX, maxBX);
332  setQLabelsTheta((digiHistos[dtCh.rawId()])[histoTag], 1);
333  }
334  if (histoType == "ThetaBestQual") { //It does not make sense: 7 positions, how to define best?
335  (digiHistos[dtCh.rawId()])[histoTag] = ibooker.book1D(
336  histoName, "Trigger quality of best primitives (theta)", 2, 0.5, 2.5); // 0 = not fired, 1 = L, 2 = H
337  setQLabelsTheta((digiHistos[dtCh.rawId()])[histoTag], 1);
338  return;
339  }
340 
341  } else if (folder == "Segment") {
342  if (histoType.find("TrackThetaPosvsAngle") == 0) {
343  string histoLabel = "Position vs Angle (theta)";
344  if (histoType.find("andTrigH") != string::npos)
345  histoLabel += " for H triggers";
346  else if (histoType.find("andTrig") != string::npos)
347  histoLabel += " for triggers";
348 
349  float min, max;
350  int nbins;
352  (digiHistos[dtCh.rawId()])[histoTag] = ibooker.book2D(histoName, histoLabel, 16, -40., 40., nbins, min, max);
353  return;
354  }
355  if (histoType.find("TrackPosvsAngle") == 0) {
356  float min, max;
357  int nbins;
358  trigGeomUtils->phiRange(dtCh, min, max, nbins);
359 
360  string histoLabel = "Position vs Angle (phi)";
361  if (histoType.find("andTrigHHHL") != string::npos)
362  histoLabel += " for HH/HL triggers";
363  else if (histoType.find("andTrig") != string::npos)
364  histoLabel += " for triggers";
365 
366  (digiHistos[dtCh.rawId()])[histoTag] = ibooker.book2D(histoName, histoLabel, 16, -40., 40., nbins, min, max);
367  return;
368  }
369  if (histoType == "PhitkvsPhitrig") {
370  (digiHistos[dtCh.rawId()])[histoTag] =
371  ibooker.book2D(histoName, "Local position: segment vs trigger", 100, -500., 500., 100, -500., 500.);
372  return;
373  }
374  if (histoType == "PhibtkvsPhibtrig") {
375  (digiHistos[dtCh.rawId()])[histoTag] =
376  ibooker.book2D(histoName, "Local direction : segment vs trigger", 200, -40., 40., 200, -40., 40.);
377  return;
378  }
379  if (histoType == "PhiResidual") {
380  (digiHistos[dtCh.rawId()])[histoTag] = ibooker.book1D(
381  histoName, "Trigger local position - Segment local position (correlated triggers)", 400, -10., 10.);
382  return;
383  }
384  if (histoType == "PhibResidual") {
385  (digiHistos[dtCh.rawId()])[histoTag] = ibooker.book1D(
386  histoName, "Trigger local direction - Segment local direction (correlated triggers)", 500, -10., 10.);
387  return;
388  }
389  if (histoType == "HitstkvsQualtrig") {
390  (digiHistos[dtCh.rawId()])[histoTag] =
391  ibooker.book2D(histoName, "Segment hits (phi) vs trigger quality", 7, -0.5, 6.5, 10, 0.5, 10.5);
392  setQLabels((digiHistos[dtCh.rawId()])[histoTag], 1);
393  return;
394  }
395  }
396 }
397 
399  stringstream wheel;
400  wheel << wh;
401 
402  string histoType = histoTag.substr(3, histoTag.find('_', 3) - 3);
403 
404  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/");
405 
406  string histoName = histoTag + "_W" + wheel.str();
407 
408  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask")
409  << "[DTLocalTriggerTask]: booking " << topFolder() << "Wheel" << wheel.str() << "/" << histoName << endl;
410 }
411 
412 void DTLocalTriggerTask::runTMAnalysis(std::vector<L1MuDTChambPhDigi> const* phTrigs,
413  std::vector<L1MuDTChambThDigi> const* thTrigs) {
414  //exit(0);
415 
416  string histoType;
417  string histoTag;
418 
419  // define best quality trigger segment (phi and theta)
420  // in any station start from 1 and zero is kept empty
421  for (int i = 0; i < 5; ++i) {
422  for (int j = 0; j < 6; ++j) {
423  for (int k = 0; k < 13; ++k) {
424  phcode_best[j][i][k] = -1;
425  thcode_best[j][i][k] = -1;
426  }
427  }
428  }
429 
430  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
431  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
432  for (; iph != iphe; ++iph) {
433  int phwheel = iph->whNum();
434  int phsec = iph->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
435  int phst = iph->stNum();
436  int phbx = iph->bxNum();
437  int phcode = iph->code();
438  int phi1st = iph->Ts2Tag();
439  int updown = iph->UpDownTag();
440 
441  // FIXME: workaround for TM data with station ID
442  if (phst == 0) {
443  tm_IDDataErrorPlot->Fill(phwheel);
444  continue;
445  }
446 
447  if (phcode > phcode_best[phwheel + 3][phst][phsec] && phcode < 7) {
448  phcode_best[phwheel + 3][phst][phsec] = phcode;
449  iphbest[phwheel + 3][phst][phsec] = &(*iph);
450  }
451 
452  DTChamberId dtChId(phwheel, phst, phsec);
453 
454  float x = trigGeomUtils->trigPos(&(*iph));
455  float angle = trigGeomUtils->trigDir(&(*iph));
456  uint32_t indexCh = dtChId.rawId();
457 
458  map<string, MonitorElement*>& innerME = digiHistos[indexCh];
459 
460  if (tpMode) {
461  innerME.find("TM_BXvsQual" + trigsrc)->second->Fill(phcode, phbx - phi1st); // SM BX vs Qual Phi view (1st tracks)
462  innerME.find("TM_QualvsPhirad" + trigsrc)->second->Fill(x, phcode); // SM Qual vs radial angle Phi view
463  } else {
464  innerME.find("TM_BXvsQual_In" + trigsrc)
465  ->second->Fill(phcode, phbx - phi1st); // SM BX vs Qual Phi view (1st tracks)
466  innerME.find("TM_Flag1stvsQual_In" + trigsrc)
467  ->second->Fill(phcode, phi1st); // SM Qual 1st/2nd track flag Phi view
468  innerME.find("TM_FlagUpDownvsQual_In" + trigsrc)
469  ->second->Fill(phcode, updown); // SM Qual Up/Down track flag Phi view
470  if (detailedAnalysis) {
471  innerME.find("TM_QualvsPhirad_In" + trigsrc)->second->Fill(x, phcode); // SM Qual vs radial angle Phi view
472  innerME.find("TM_QualvsPhibend_In" + trigsrc)->second->Fill(angle, phcode); // SM Qual vs bending Phi view
473  }
474  }
475  }
476 
477  if (doTMTheta) {
478  int thcode[7];
479  vector<L1MuDTChambThDigi>::const_iterator ith = thTrigs->begin();
480  vector<L1MuDTChambThDigi>::const_iterator ithe = thTrigs->end();
481  for (; ith != ithe; ++ith) {
482  int thwheel = ith->whNum();
483  int thsec = ith->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
484  int thst = ith->stNum();
485  int thbx = ith->bxNum();
486 
487  for (int pos = 0; pos < 7; pos++) {
488  thcode[pos] = ith->code(pos);
489 
490  if (thcode[pos] > thcode_best[thwheel + 3][thst][thsec]) {
491  thcode_best[thwheel + 3][thst][thsec] = thcode[pos];
492  ithbest[thwheel + 3][thst][thsec] = &(*ith);
493  }
494  }
495 
496  DTChamberId dtChId(thwheel, thst, thsec);
497  uint32_t indexCh = dtChId.rawId();
498 
499  map<string, MonitorElement*>& innerME = digiHistos[indexCh];
500 
501  for (int pos = 0; pos < 7; pos++) { //SM fill position for non zero position bit in theta view
502  if (thcode[pos] > 0) { //Fired
503  innerME.find("TM_PositionvsBX" + trigsrc)->second->Fill(thbx, pos); // SM BX vs Position Theta view
504  innerME.find("TM_PositionvsQual" + trigsrc)
505  ->second->Fill(thcode[pos], pos); //code = pos + qual; so 0, 1, 2 for 0, L, H resp.
506  innerME.find("TM_ThetaBXvsQual" + trigsrc)
507  ->second->Fill(thcode[pos], thbx); //code = pos + qual; so 0, 1, 2 for 0, L, H resp.
508  }
509  }
510  }
511  }
512 
513  // Fill Quality plots with best TM triggers in phi & theta
514  if (!tpMode) {
515  for (int st = 1; st < 5; ++st) {
516  for (int wh = -2; wh < 3; ++wh) {
517  for (int sc = 1; sc < 13; ++sc) {
518  if (phcode_best[wh + wheelArrayShift][st][sc] > -1 && phcode_best[wh + wheelArrayShift][st][sc] < 7) {
519  DTChamberId id(wh, st, sc);
520  uint32_t indexCh = id.rawId();
521  map<string, MonitorElement*>& innerME = digiHistos[indexCh];
522 
523  innerME.find("TM_BestQual_In" + trigsrc)
524  ->second->Fill(phcode_best[wh + wheelArrayShift][st][sc]); // Best Qual Trigger Phi view
525  }
526  if (thcode_best[wh + wheelArrayShift][st][sc] > 0 && thcode_best[wh + wheelArrayShift][st][sc] < 3) {
527  DTChamberId id(wh, st, sc);
528  uint32_t indexCh = id.rawId();
529  map<string, MonitorElement*>& innerME = digiHistos[indexCh];
530 
531  innerME.find("TM_ThetaBestQual" + trigsrc)
532  ->second->Fill(thcode_best[wh + wheelArrayShift][st][sc]); // Best Qual Trigger Theta view
533  }
534  }
535  }
536  }
537  }
538 }
539 
542 
543  // Find best tracks & good tracks
544  memset(track_ok, false, 450 * sizeof(bool));
545 
547  vector<const DTRecSegment4D*> best4DSegments;
548 
549  // Preliminary loop finds best 4D Segment and high quality ones
550  for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId) {
551  DTRecSegment4DCollection::range range = segments4D->get(*chamberId);
552  const DTRecSegment4D* tmpBest = nullptr;
553  int tmpdof = 0;
554  int dof = 0;
555 
556  for (track = range.first; track != range.second; ++track) {
557  if ((*track).hasPhi()) {
558  dof = (*track).phiSegment()->degreesOfFreedom();
559  if (dof > tmpdof) {
560  tmpBest = &(*track);
561  tmpdof = dof;
562 
563  int wheel = (*track).chamberId().wheel();
564  int sector = (*track).chamberId().sector();
565  int station = (*track).chamberId().station();
566  if (sector == 13) {
567  sector = 4;
568  } else if (sector == 14) {
569  sector = 10;
570  }
571  track_ok[wheel + 3][station][sector] = (!track_ok[wheel + 3][station][sector] && dof >= 2);
572  }
573  }
574  }
575  if (tmpBest)
576  best4DSegments.push_back(tmpBest);
577  }
578 
579  vector<const DTRecSegment4D*>::const_iterator btrack;
580 
581  for (btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack) {
582  if ((*btrack)->hasPhi()) { // Phi component
583 
584  int wheel = (*btrack)->chamberId().wheel();
585  int station = (*btrack)->chamberId().station();
586  int sector = (*btrack)->chamberId().sector();
587  int scsector = 0;
588  float x_track, y_track, x_angle, y_angle;
589  trigGeomUtils->computeSCCoordinates((*btrack), scsector, x_track, x_angle, y_track, y_angle);
590  int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom() + 2;
591 
592  DTChamberId dtChId(wheel, station, sector); // get chamber for LUTs histograms (Sectors 1 to 14)
593  uint32_t indexCh = dtChId.rawId();
594  map<string, MonitorElement*>& innerMECh = digiHistos[indexCh];
595 
596  DTChamberId dtChIdSC =
597  DTChamberId(wheel, station, scsector); // get chamber for histograms SC granularity (sectors 1 to 12)
598  indexCh = dtChIdSC.rawId();
599  map<string, MonitorElement*>& innerME = digiHistos[indexCh];
600 
601  if (useTM && phcode_best[wheel + 3][station][scsector] > -1 && phcode_best[wheel + 3][station][scsector] < 7) {
602  innerME.find("TM_HitstkvsQualtrig" + trigsrc)->second->Fill(phcode_best[wheel + 3][station][scsector], nHitsPhi);
603 
604  if (phcode_best[wheel + 3][station][scsector] > 3 && nHitsPhi >= 7) {
605  float x_trigger = trigGeomUtils->trigPos(iphbest[wheel + 3][station][scsector]);
606  float angle_trigger = trigGeomUtils->trigDir(iphbest[wheel + 3][station][scsector]);
607  trigGeomUtils->trigToSeg(station, x_trigger, x_angle);
608 
609  innerMECh.find("TM_PhitkvsPhitrig" + trigsrc)->second->Fill(x_trigger, x_track);
610  innerMECh.find("TM_PhibtkvsPhibtrig" + trigsrc)->second->Fill(angle_trigger, x_angle);
611  innerMECh.find("TM_PhiResidual" + trigsrc)->second->Fill(x_trigger - x_track);
612  innerMECh.find("TM_PhibResidual" + trigsrc)->second->Fill(angle_trigger - x_angle);
613  }
614  }
615 
616  if (useTM) {
617  // check for triggers elsewhere in the sector
618  bool trigFlagTM = false;
619  for (int ist = 1; ist < 5; ist++) {
620  if (ist != station && phcode_best[wheel + 3][ist][scsector] >= 2 &&
621  phcode_best[wheel + 3][ist][scsector] < 7 && track_ok[wheel + 3][ist][scsector] == true) {
622  trigFlagTM = true;
623  break;
624  }
625  }
626 
627  if (trigFlagTM && fabs(x_angle) < 40. && nHitsPhi >= 7) {
628  // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
629  innerME.find("TM_TrackPosvsAngle" + trigsrc)->second->Fill(x_angle, x_track);
630  if (phcode_best[wheel + 3][station][scsector] >= 2 && phcode_best[wheel + 3][station][scsector] < 7) {
631  innerME.find("TM_TrackPosvsAngleandTrig" + trigsrc)->second->Fill(x_angle, x_track);
632  if (phcode_best[wheel + 3][station][scsector] > 4) { //HH & HL Triggers
633  innerME.find("TM_TrackPosvsAngleandTrigHHHL" + trigsrc)->second->Fill(x_angle, x_track);
634  }
635  }
636  }
637 
638  if ((*btrack)->hasZed() && trigFlagTM && fabs(y_angle) < 40. &&
639  (*btrack)->zSegment()->degreesOfFreedom() >= 1) {
640  // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
641  innerME.find("TM_TrackThetaPosvsAngle" + trigsrc)->second->Fill(y_angle, y_track);
642  if (thcode_best[wheel + 3][station][scsector] > 0) {
643  innerME.find("TM_TrackThetaPosvsAngleandTrig" + trigsrc)->second->Fill(y_angle, y_track);
644  if (thcode_best[wheel + 3][station][scsector] == 2) {
645  innerME.find("TM_TrackThetaPosvsAngleandTrigH" + trigsrc)->second->Fill(y_angle, y_track);
646  }
647  }
648  }
649  }
650  }
651  }
652 }
653 
655  TH1* histo = me->getTH1();
656  if (!histo)
657  return;
658 
659  TAxis* axis = nullptr;
660  if (iaxis == 1) {
661  axis = histo->GetXaxis();
662  } else if (iaxis == 2) {
663  axis = histo->GetYaxis();
664  }
665  if (!axis)
666  return;
667 
668  string labels[7] = {"LI", "LO", "HI", "HO", "LL", "HL", "HH"};
669  int istart = axis->GetXmin() < -1 ? 2 : 1;
670  for (int i = 0; i < 7; i++) {
671  axis->SetBinLabel(i + istart, labels[i].c_str());
672  }
673 }
674 
676  TH1* histo = me->getTH1();
677  if (!histo)
678  return;
679 
680  TAxis* axis = nullptr;
681  if (iaxis == 1) {
682  axis = histo->GetXaxis();
683  } else if (iaxis == 2) {
684  axis = histo->GetYaxis();
685  }
686  if (!axis)
687  return;
688 
689  string labels[2] = {"L", "H"};
690  int istart = axis->GetXmin() < -1 ? 2 : 1;
691  for (int i = 0; i < 2; i++) {
692  axis->SetBinLabel(i + istart, labels[i].c_str());
693  }
694 }
695 
697  if (!isLocalRun) {
698  Handle<LTCDigiCollection> ltcdigis;
699  e.getByToken(ltcDigiCollectionToken_, ltcdigis);
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  trigsrc = "_DTonly";
708  else if (!(*ltc_it).HasTriggered(0))
709  trigsrc = "_NoDT";
710  else if ((*ltc_it).HasTriggered(0) && otherTriggerSum > 0)
711  trigsrc = "_DTalso";
712  }
713  return;
714  }
715 
716  trigsrc = "";
717  return;
718 }
719 
720 // Local Variables:
721 // show-trailing-whitespace: t
722 // truncate-lines: t
723 // End:
int station() const
Return the station number.
Definition: DTChamberId.h:42
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LuminosityBlockNumber_t luminosityBlock() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
void thetaRange(const DTChamberId &id, float &min, float &max, int &nbins, float step=15)
Compute theta range in local chamber coordinates.
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void runTMAnalysis(std::vector< L1MuDTChambPhDigi > const *phTrigs, std::vector< L1MuDTChambThDigi > const *thTrigs)
Run analysis on TM data.
edm::EDGetTokenT< LTCDigiCollection > ltcDigiCollectionToken_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Beginrun.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Book the histograms.
float trigDir(const L1MuDTChambPhDigi *trig)
Return local direction (trigger RF) for a given trigger primitive.
void setQLabelsTheta(MonitorElement *me, short int iaxis)
identifier iterator
Definition: RangeMap.h:130
MonitorElement * tm_IDDataErrorPlot
bool track_ok[6][5][15]
#define LogTrace(id)
void runSegmentAnalysis(edm::Handle< DTRecSegment4DCollection > &segments4D)
Run analysis using DT 4D segments.
The_Container const * getContainer() const
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_Token_
const DTGeometry * muonGeom
void trigToSeg(int st, float &x, float dir)
Compute Trigger x coordinate in chamber RF.
Transition
Definition: Transition.h:12
edm::EDGetTokenT< L1MuDTChambThContainer > tmTh_Token_
DTLocalTriggerTask(const edm::ParameterSet &ps)
Constructor.
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
edm::EDGetTokenT< DTLocalTriggerCollection > ros_Token_
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
void phiRange(const DTChamberId &id, float &min, float &max, int &nbins, float step=15)
Compute phi range in local chamber coordinates.
void bookHistos(DQMStore::IBooker &, const DTChamberId &dtCh, std::string folder, std::string histoTag)
Phi_Container const * getContainer() const
LuminosityBlockID id() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
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 setQLabels(MonitorElement *me, short int iaxis)
Set Quality labels.
bool isValid() const
Definition: HandleBase.h:70
edm::ParameterSet parameters
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
DTTrigGeomUtils * trigGeomUtils
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
To reset the MEs.
void bookWheelHistos(DQMStore::IBooker &, int wh, std::string histoTag)
Book the histograms.
void triggerSource(const edm::Event &e)
Get the L1A source.
float trigPos(const L1MuDTChambPhDigi *trig)
Return local position (trigger RF) for a given trigger primitive.
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::string & topFolder()
Get the Top folder (different between Physics and TP and TM)
void bookBarrelHistos(DQMStore::IBooker &, std::string histoTag)
Book the histograms.
std::map< uint32_t, std::map< std::string, MonitorElement * > > digiHistos
~DTLocalTriggerTask() override
Destructor.
void computeSCCoordinates(const DTRecSegment4D *track, int &scsec, float &x, float &xdir, float &y, float &ydir)
Compute track coordinates with SC sector numbering.
Definition: Run.h:45
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)