CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
22 
23 //Root
24 #include"TH1.h"
25 #include"TAxis.h"
26 
27 #include <sstream>
28 #include <iostream>
29 #include <fstream>
30 
31 
32 using namespace edm;
33 using namespace std;
34 
36  trigGeomUtils(0),
37  isLocalRun(ps.getUntrackedParameter<bool>("localrun", true))
38  {
39  if (!isLocalRun) {
40  ltcDigiCollectionToken_ = consumes<LTCDigiCollection>(
41  ps.getParameter<edm::InputTag>("ltcDigiCollectionTag"));
42  }
43 
44  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Constructor"<<endl;
45 
46  tpMode = ps.getUntrackedParameter<bool>("testPulseMode", false);
47  detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis", false);
48  doTMTheta = ps.getUntrackedParameter<bool>("enableTMTheta", false);
49  dcc_Token_ = consumes<L1MuDTChambPhContainer>(
50  edm::InputTag(ps.getUntrackedParameter<string>("dcc_label", "dttpgprod")));
51 // NEW (M.C Fouz July14) Needed, since at least version 710
52  dccTh_Token_ = consumes<L1MuDTChambThContainer>(
53  edm::InputTag(ps.getUntrackedParameter<string>("dcc_label", "dttpgprod")));
54 // end NEW
55 
56  ros_Token_ = consumes<DTLocalTriggerCollection>(
57  edm::InputTag(ps.getUntrackedParameter<string>("ros_label", "dtunpacker")));
58  seg_Token_ = consumes<DTRecSegment4DCollection>(
59  edm::InputTag(ps.getUntrackedParameter<string>("seg_label", "dt4DSegments")));
60 
61  if (tpMode) {
62  baseFolderTM = "DT/11-LocalTriggerTP-TM/";
63  baseFolderDDU = "DT/12-LocalTriggerTP-DDU/";
64  }
65  else {
66  baseFolderTM = "DT/03-LocalTrigger-TM/";
67  baseFolderDDU = "DT/04-LocalTrigger-DDU/";
68  }
69 
70  parameters = ps;
71 
72 }
73 
74 
76 
77  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: analyzed " << nevents << " events" << endl;
78  if (trigGeomUtils) { delete trigGeomUtils; }
79 
80 }
81 
83 
84  nevents = 0;
85  context.get<MuonGeometryRecord>().get(muonGeom);
87 
88 }
89 
90 void DTLocalTriggerTask::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & iRun, edm::EventSetup const & context) {
91 
92  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: bookHistograms" << endl;
93 
94  if(parameters.getUntrackedParameter<bool>("staticBooking", true)) { // Static histo booking
95 
96  vector<string> trigSources;
97  if(parameters.getUntrackedParameter<bool>("localrun", true)) {
98  trigSources.push_back("");
99  }
100  else {
101  trigSources.push_back("_DTonly");
102  trigSources.push_back("_NoDT");
103  trigSources.push_back("_DTalso");
104  }
105  vector<string>::const_iterator trigSrcIt = trigSources.begin();
106  vector<string>::const_iterator trigSrcEnd = trigSources.end();
107 
108  if(parameters.getUntrackedParameter<bool>("process_dcc", true)) {
109  bookBarrelHistos(ibooker, "TM_ErrorsChamberID");
110  }
111 
112  if (tpMode) {
113  for (int stat=1;stat<5;++stat){
114  for (int wh=-2;wh<3;++wh){
115  for (int sect=1;sect<13;++sect){
116  DTChamberId dtChId(wh,stat,sect);
117 
118  if (parameters.getUntrackedParameter<bool>("process_dcc", true)){ // TM data
119  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_BXvsQual"+(*trigSrcIt));
120  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_QualvsPhirad"+(*trigSrcIt));
121  }
122 
123  if (parameters.getUntrackedParameter<bool>("process_ros", true)){ // DDU data
124  bookHistos(ibooker, dtChId,"LocalTriggerPhi","DDU_BXvsQual"+(*trigSrcIt));
125  }
126 
127  }
128  }
129  } // end of loop
130  }
131  else {
132  for (;trigSrcIt!=trigSrcEnd;++trigSrcIt){
133  for (int wh=-2;wh<3;++wh){
134  if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
135  parameters.getUntrackedParameter<bool>("process_ros", true)){ // TM+DDU data
136  bookWheelHistos(ibooker, wh,"COM_BXDiff"+(*trigSrcIt));
137  }
138  for (int sect=1;sect<13;++sect){
139  for (int stat=1;stat<5;++stat){
140  DTChamberId dtChId(wh,stat,sect);
141  if (parameters.getUntrackedParameter<bool>("process_dcc", true)){ // TM data
142 
143  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_BXvsQual"+(*trigSrcIt));
144  if (detailedAnalysis) {
145  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_QualvsPhirad"+(*trigSrcIt));
146  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_QualvsPhibend"+(*trigSrcIt));
147  }
148  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_Flag1stvsQual"+(*trigSrcIt));
149  bookHistos(ibooker, dtChId,"LocalTriggerPhi","TM_BestQual"+(*trigSrcIt));
150  if (stat!=4 && doTMTheta){
151  bookHistos(ibooker, dtChId,"LocalTriggerTheta","TM_PositionvsBX"+(*trigSrcIt));
152  }
153 
154  if (parameters.getUntrackedParameter<bool>("process_seg", true)){ // TM + Segemnt
155  bookHistos(ibooker, dtChId,"Segment","TM_PhitkvsPhitrig"+(*trigSrcIt));
156  bookHistos(ibooker, dtChId,"Segment","TM_PhibtkvsPhibtrig"+(*trigSrcIt));
157  bookHistos(ibooker, dtChId,"Segment","TM_PhiResidual"+(*trigSrcIt));
158  bookHistos(ibooker, dtChId,"Segment","TM_PhiResidualvsLUTPhi"+(*trigSrcIt));
159  bookHistos(ibooker, dtChId,"Segment","TM_PhibResidual"+(*trigSrcIt));
160  bookHistos(ibooker, dtChId,"Segment","TM_HitstkvsQualtrig"+(*trigSrcIt));
161  bookHistos(ibooker, dtChId,"Segment","TM_TrackPosvsAngle"+(*trigSrcIt));
162  bookHistos(ibooker, dtChId,"Segment","TM_TrackPosvsAngleandTrig"+(*trigSrcIt));
163  bookHistos(ibooker, dtChId,"Segment","TM_TrackPosvsAngleandTrigHHHL"+(*trigSrcIt));
164  if(stat!=4){
165  bookHistos(ibooker, dtChId,"Segment","TM_TrackThetaPosvsAngle"+(*trigSrcIt)); // theta view
166  bookHistos(ibooker, dtChId,"Segment","TM_TrackThetaPosvsAngleandTrig"+(*trigSrcIt));
167 // bookHistos(ibooker, dtChId,"Segment","TM_TrackThetaPosvsAngleandTrigH"+(*trigSrcIt)); // TM theta quality not available!
168  }
169  }
170 
171  }
172 
173  if (parameters.getUntrackedParameter<bool>("process_ros", true)){ // DDU data
174 
175  bookHistos(ibooker, dtChId,"LocalTriggerPhi","DDU_BXvsQual"+(*trigSrcIt));
176  bookHistos(ibooker, dtChId,"LocalTriggerPhi","DDU_Flag1stvsQual"+(*trigSrcIt));
177  bookHistos(ibooker, dtChId,"LocalTriggerPhi","DDU_BestQual"+(*trigSrcIt));
178  if(stat!=4){ // theta view
179  bookHistos(ibooker, dtChId,"LocalTriggerTheta","DDU_ThetaBXvsQual"+(*trigSrcIt));
180  bookHistos(ibooker, dtChId,"LocalTriggerTheta","DDU_ThetaBestQual"+(*trigSrcIt));
181  }
182 
183  if (parameters.getUntrackedParameter<bool>("process_seg", true)){ // DDU + Segment
184  bookHistos(ibooker, dtChId,"Segment","DDU_HitstkvsQualtrig"+(*trigSrcIt));
185  bookHistos(ibooker, dtChId,"Segment","DDU_TrackPosvsAngle"+(*trigSrcIt));
186  bookHistos(ibooker, dtChId,"Segment","DDU_TrackPosvsAngleandTrig"+(*trigSrcIt));
187  bookHistos(ibooker, dtChId,"Segment","DDU_TrackPosvsAngleandTrigHHHL"+(*trigSrcIt));
188  if(stat!=4){
189  bookHistos(ibooker, dtChId,"Segment","DDU_TrackThetaPosvsAngle"+(*trigSrcIt)); // theta view
190  bookHistos(ibooker, dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrig"+(*trigSrcIt));
191  bookHistos(ibooker, dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrigH"+(*trigSrcIt));
192  }
193  }
194 
195  }
196 
197  if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
198  parameters.getUntrackedParameter<bool>("process_ros", true)){ // TM+DDU data
199  bookHistos(ibooker, dtChId,"LocalTriggerPhi","COM_QualDDUvsQualTM"+(*trigSrcIt));
200  }
201 
202  }
203  }
204  for (int sect=13;sect<15;++sect){
205  DTChamberId dtChId(wh,4,sect);
206  if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
207  parameters.getUntrackedParameter<bool>("process_seg", true)){ // TM+SEG LUTs data
208  bookHistos(ibooker, dtChId,"Segment","TM_PhitkvsPhitrig"+(*trigSrcIt));
209  bookHistos(ibooker, dtChId,"Segment","TM_PhibtkvsPhibtrig"+(*trigSrcIt));
210  bookHistos(ibooker, dtChId,"Segment","TM_PhiResidual"+(*trigSrcIt));
211  bookHistos(ibooker, dtChId,"Segment","TM_PhiResidualvsLUTPhi"+(*trigSrcIt));
212  bookHistos(ibooker, dtChId,"Segment","TM_PhibResidual"+(*trigSrcIt));
213  }
214  }
215  }
216  }// end of loop
217  }
218 
219  }
220 
221 
222 }
223 
224 
226 
227  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Begin of LS transition" << endl;
228 
229  if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
230  for(map<uint32_t, map<string, MonitorElement*> > ::const_iterator histo = digiHistos.begin();
231  histo != digiHistos.end();
232  histo++) {
233  for(map<string, MonitorElement*> ::const_iterator ht = (*histo).second.begin();
234  ht != (*histo).second.end();
235  ht++) {
236  (*ht).second->Reset();
237  }
238  }
239  }
240 
241 }
242 
244  if (!nevents){
245 
247  e.getByToken(dcc_Token_, l1DTTPGPh);
249  // e.getByToken(dcc_Token_, l1DTTPGTh);// CHANGED (M.C Fouz July14) Needed, since at least version 710
250  e.getByToken(dccTh_Token_, l1DTTPGTh); // CHANGED (F.R.Cavallo Nov14)
251 
252  useTM = (l1DTTPGPh.isValid() || l1DTTPGTh.isValid()) && parameters.getUntrackedParameter<bool>("process_dcc", true) ;
253 
255  e.getByToken(ros_Token_,l1DDUTrigs);
256  useDDU = l1DDUTrigs.isValid() && parameters.getUntrackedParameter<bool>("process_ros", true) ;
257 
258  Handle<DTRecSegment4DCollection> all4DSegments;
259  e.getByToken(seg_Token_, all4DSegments);
260  useSEG = all4DSegments.isValid() && parameters.getUntrackedParameter<bool>("process_seg", true) ;
261 
262  }
263 
264  nevents++;
265 
266  triggerSource(e);
267 
268  if ( useTM ) {
270  e.getByToken(dcc_Token_, l1DTTPGPh);
271  vector<L1MuDTChambPhDigi> const* l1PhTrig = l1DTTPGPh->getContainer();
272 
274  //e.getByToken(dcc_Token_, l1DTTPGTh);// CHANGED (M.C Fouz July14) Needed, since at least version 710
275  e.getByToken(dccTh_Token_, l1DTTPGTh);// CHANGED (F.R. Cavallo Nov14)
276 
277  vector<L1MuDTChambThDigi> const* l1ThTrig = l1DTTPGTh->getContainer();
278 
279  runTMAnalysis(l1PhTrig, l1ThTrig);
280  }
281  if ( useDDU ) {
283  e.getByToken(ros_Token_, l1DDUTrigs);
284 
285  runDDUAnalysis(l1DDUTrigs);
286  }
287  if ( !tpMode && useSEG ) {
289  e.getByToken(seg_Token_, segments4D);
290 
291  runSegmentAnalysis(segments4D);
292  }
293  if ( !tpMode && useTM && useDDU ) {
295  }
296 
297 }
298 
299 
300 void DTLocalTriggerTask::bookBarrelHistos(DQMStore::IBooker & ibooker, string histoTag) {
301 
302  bool isTM = histoTag.substr(0,3) == "TM";
303  ibooker.setCurrentFolder(topFolder(isTM));
304  if (histoTag == "TM_ErrorsChamberID") {
305  dcc_IDDataErrorPlot = ibooker.book1D(histoTag.c_str(),"TM Data ID Error",5,-2,3);
306  dcc_IDDataErrorPlot->setAxisTitle("wheel",1);
307  }
308 
309  return;
310 
311 }
312 
313 void DTLocalTriggerTask::bookHistos(DQMStore::IBooker & ibooker, const DTChamberId& dtCh, string folder, string histoTag) {
314 
315  int wh=dtCh.wheel();
316  int sc=dtCh.sector();
317  stringstream wheel; wheel << wh;
318  stringstream station; station << dtCh.station();
319  stringstream sector; sector << sc;
320 
321  double minBX=0;
322  double maxBX=0;
323  int rangeBX=0;
324 
325  string histoType = histoTag.substr(4,histoTag.find("_",4)-4);
326  bool isTM = histoTag.substr(0,3) == "TM";
327 
328  ibooker.setCurrentFolder(topFolder(isTM) + "Wheel" + wheel.str() +
329  "/Sector" + sector.str() +
330  "/Station" + station.str() + "/" + folder);
331 
332  string histoName = histoTag + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
333 
334  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: booking " << topFolder(isTM) << "Wheel" << wheel.str()
335  << "/Sector" << sector.str()
336  << "/Station"<< station.str() << "/" << folder << "/" << histoName << endl;
337 
338  if (histoType.find("BX") != string::npos){
339  if (histoTag.substr(0,3) == "TM"){
340  minBX= parameters.getUntrackedParameter<int>("minBXTM",-2) - 0.5;
341  maxBX= parameters.getUntrackedParameter<int>("maxBXTM",2) + 0.5;
342  }
343  else {
344  minBX= parameters.getUntrackedParameter<int>("minBXDDU",0) - 0.5;
345  maxBX= parameters.getUntrackedParameter<int>("maxBXDDU",20) + 0.5;
346  }
347  rangeBX = (int)(maxBX-minBX);
348  }
349 
350  if ( folder == "LocalTriggerPhi") {
351 
352  if( histoType == "BXvsQual" ){
353  (digiHistos[dtCh.rawId()])[histoTag] =
354  ibooker.book2D(histoName,"BX vs trigger quality",7,-0.5,6.5,rangeBX,minBX,maxBX);
355  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
356  return ;
357  }
358  if( histoType == "BestQual" ){
359  (digiHistos[dtCh.rawId()])[histoTag] =
360  ibooker.book1D(histoName,"Trigger quality of best primitives",7,-0.5,6.5);
361  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
362  return ;
363  }
364  if( histoType == "QualvsPhirad" ){
365  (digiHistos[dtCh.rawId()])[histoTag] =
366  ibooker.book2D(histoName,"Trigger quality vs local position",100,-500.,500.,7,-0.5,6.5);
367  setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);
368  return ;
369  }
370  if( histoType == "QualvsPhibend" ) {
371  (digiHistos[dtCh.rawId()])[histoTag] =
372  ibooker.book2D(histoName,"Trigger quality vs local direction",200,-40.,40.,7,-0.5,6.5);
373  setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);
374  return ;
375  }
376  if( histoType == "Flag1stvsQual" ) {
377  (digiHistos[dtCh.rawId()])[histoTag] =
378  ibooker.book2D(histoName,"1st/2nd trig flag vs quality",7,-0.5,6.5,2,-0.5,1.5);
379  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
380  return ;
381  }
382  if( histoType == "QualDDUvsQualTM" ){
383  (digiHistos[dtCh.rawId()])[histoTag] =
384  ibooker.book2D(histoName,"DDU quality vs TM quality",8,-1.5,6.5,8,-1.5,6.5);
385  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
386  setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);
387  return ;
388  }
389 
390  }
391  else if ( folder == "LocalTriggerTheta") {
392 
393  if( histoType == "PositionvsBX" ) {
394  (digiHistos[dtCh.rawId()])[histoTag] =
395  ibooker.book2D(histoName,"Theta trigger position vs BX",rangeBX,minBX,maxBX,7,-0.5,6.5);
396  return ;
397  }
398  if( histoType == "PositionvsQual" ) {
399  (digiHistos[dtCh.rawId()])[histoTag] =
400  ibooker.book2D(histoName,"Theta trigger position vs quality",7,-0.5,6.5,7,-0.5,6.5);
401  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
402  return ;
403  }
404  if( histoType == "ThetaBXvsQual" ) {
405  (digiHistos[dtCh.rawId()])[histoTag] =
406  ibooker.book2D(histoName,"BX vs trigger quality",7,-0.5,6.5,rangeBX,minBX,maxBX);
407  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
408  }
409  if( histoType == "ThetaBestQual" ){
410  (digiHistos[dtCh.rawId()])[histoTag] =
411  ibooker.book1D(histoName,"Trigger quality of best primitives (theta)",7,-0.5,6.5);
412  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
413  return ;
414  }
415 
416  }
417  else if ( folder == "Segment") {
418 
419  if( histoType.find("TrackThetaPosvsAngle" ) == 0 ) {
420 
421  string histoLabel = "Position vs Angle (theta)";
422  if (histoType.find("andTrigH") != string::npos) histoLabel += " for H triggers";
423  else if (histoType.find("andTrig") != string::npos) histoLabel += " for triggers";
424 
425  float min,max;
426  int nbins;
427  trigGeomUtils->thetaRange(dtCh,min,max,nbins);
428  (digiHistos[dtCh.rawId()])[histoTag] =
429  ibooker.book2D(histoName,histoLabel,16,-40.,40.,nbins,min,max);
430  return ;
431  }
432  if( histoType.find("TrackPosvsAngle") == 0 ){
433 
434  float min,max;
435  int nbins;
436  trigGeomUtils->phiRange(dtCh,min,max,nbins);
437 
438  string histoLabel = "Position vs Angle (phi)";
439  if (histoType.find("andTrigHHHL") != string::npos) histoLabel += " for HH/HL triggers";
440  else if (histoType.find("andTrig") != string::npos) histoLabel += " for triggers";
441 
442  (digiHistos[dtCh.rawId()])[histoTag] =
443  ibooker.book2D(histoName,histoLabel,16,-40.,40.,nbins,min,max);
444  return ;
445  }
446  if( histoType == "PhitkvsPhitrig" ){
447  (digiHistos[dtCh.rawId()])[histoTag] =
448  ibooker.book2D(histoName,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
449  return ;
450  }
451  if( histoType == "PhibtkvsPhibtrig" ){
452  (digiHistos[dtCh.rawId()])[histoTag] =
453  ibooker.book2D(histoName,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
454  return ;
455  }
456  if( histoType == "PhiResidual" ){
457  (digiHistos[dtCh.rawId()])[histoTag] =
458  ibooker.book1D(histoName,"Trigger local position - Segment local position (correlated triggers)",400,-10.,10.);
459  return ;
460  }
461  if( histoType == "PhibResidual" ){
462  (digiHistos[dtCh.rawId()])[histoTag] =
463  ibooker.book1D(histoName,"Trigger local direction - Segment local direction (correlated triggers)",500,-10.,10.);
464  return ;
465  }
466  if( histoType == "HitstkvsQualtrig" ){
467  (digiHistos[dtCh.rawId()])[histoTag] =
468  ibooker.book2D(histoName,"Segment hits (phi) vs trigger quality",7,-0.5,6.5,10,0.5,10.5);
469  setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
470  return ;
471  }
472 
473  }
474 
475 }
476 
477 void DTLocalTriggerTask::bookWheelHistos(DQMStore::IBooker & ibooker, int wh, string histoTag) {
478 
479  stringstream wheel; wheel << wh;
480 
481  string histoType = histoTag.substr(4,histoTag.find("_",4)-4);
482  bool isTM = histoTag.substr(0,3) == "TM";
483 
484  ibooker.setCurrentFolder(topFolder(isTM) + "Wheel" + wheel.str() + "/");
485 
486  string histoName = histoTag + "_W" + wheel.str();
487 
488  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: booking " << topFolder(isTM)
489  << "Wheel" << wheel.str() << "/" << histoName << endl;
490 
491  if( histoType.find("BXDiff") != string::npos ){
492  MonitorElement *me = ibooker.bookProfile2D(histoName,"DDU-TM BX Difference",12,1,13,4,1,5,0.,20.);
493  me->setAxisTitle("Sector",1);
494  me->setAxisTitle("station",2);
495  (wheelHistos[wh])[histoTag] = me;
496  return ;
497  }
498 
499 }
500 
501 void DTLocalTriggerTask::runTMAnalysis(std::vector<L1MuDTChambPhDigi> const* phTrigs,
502  std::vector<L1MuDTChambThDigi> const* thTrigs ) {
503 
504  string histoType ;
505  string histoTag ;
506 
507  // define best quality trigger segment (phi and theta)
508  // in any station start from 1 and zero is kept empty
509  for (int i=0;i<5;++i){
510  for (int j=0;j<6;++j){
511  for (int k=0;k<13;++k){
512  phcode_best[j][i][k] = -1;
513  thcode_best[j][i][k] = -1;
514  }
515  }
516  }
517 
518  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
519  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
520  for(; iph !=iphe ; ++iph) {
521 
522  int phwheel = iph->whNum();
523  int phsec = iph->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
524  int phst = iph->stNum();
525  int phbx = iph->bxNum();
526  int phcode = iph->code();
527  int phi1st = iph->Ts2Tag();
528 
529  // FIXME: workaround for TM data with station ID
530  if(phst == 0) {
531  dcc_IDDataErrorPlot->Fill(phwheel);
532  continue;
533  }
534 
535  if(phcode>phcode_best[phwheel+3][phst][phsec] && phcode<7) {
536  phcode_best[phwheel+3][phst][phsec]=phcode;
537  iphbest[phwheel+3][phst][phsec] = &(*iph);
538  }
539 
540  DTChamberId dtChId(phwheel,phst,phsec);
541 
542  float x = trigGeomUtils->trigPos(&(*iph));
543  float angle = trigGeomUtils->trigDir(&(*iph));
544  uint32_t indexCh = dtChId.rawId();
545 
546  map<string, MonitorElement*> &innerME = digiHistos[indexCh];
547 
548  if (tpMode) {
549  innerME.find("TM_BXvsQual"+trigsrc)->second->Fill(phcode,phbx-phi1st); // SM BX vs Qual Phi view (1st tracks)
550  innerME.find("TM_QualvsPhirad"+trigsrc)->second->Fill(x,phcode); // SM Qual vs radial angle Phi view
551  }
552  else {
553  innerME.find("TM_BXvsQual"+trigsrc)->second->Fill(phcode,phbx-phi1st); // SM BX vs Qual Phi view (1st tracks)
554  innerME.find("TM_Flag1stvsQual"+trigsrc)->second->Fill(phcode,phi1st); // SM Qual 1st/2nd track flag Phi view
555  if (detailedAnalysis) {
556  innerME.find("TM_QualvsPhirad"+trigsrc)->second->Fill(x,phcode); // SM Qual vs radial angle Phi view
557  innerME.find("TM_QualvsPhibend"+trigsrc)->second->Fill(angle,phcode); // SM Qual vs bending Phi view
558  }
559  }
560 
561  }
562 
563  if (doTMTheta) {
564  int thcode[7];
565  vector<L1MuDTChambThDigi>::const_iterator ith = thTrigs->begin();
566  vector<L1MuDTChambThDigi>::const_iterator ithe = thTrigs->end();
567  for(; ith != ithe; ++ith) {
568  int thwheel = ith->whNum();
569  int thsec = ith->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
570  int thst = ith->stNum();
571  int thbx = ith->bxNum();
572 
573  for (int pos=0; pos<7; pos++) {
574  thcode[pos] = ith->code(pos);
575 
576  if(thcode[pos]>thcode_best[thwheel+3][thst][thsec] ) {
577  thcode_best[thwheel+3][thst][thsec]=thcode[pos];
578  ithbest[thwheel+3][thst][thsec] = &(*ith);
579  }
580  }
581 
582  DTChamberId dtChId(thwheel,thst,thsec);
583  uint32_t indexCh = dtChId.rawId();
584 
585  map<string, MonitorElement*> &innerME = digiHistos[indexCh];
586 
587  for (int pos=0; pos<7; pos++) { //SM fill position for non zero position bit in theta view
588  if(thcode[pos]>0){
589  innerME.find("TM_PositionvsBX"+trigsrc)->second->Fill(thbx,pos); // SM BX vs Position Theta view
590  }
591  }
592  }
593  }
594 
595 
596  // Fill Quality plots with best TM triggers in phi & theta
597  if (!tpMode) {
598  for (int st=1;st<5;++st){
599  for (int wh=-2;wh<3;++wh){
600  for (int sc=1;sc<13;++sc){
601  if (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7){
602  DTChamberId id(wh,st,sc);
603  uint32_t indexCh = id.rawId();
604  map<string, MonitorElement*> &innerME = digiHistos[indexCh];
605 
606  innerME.find("TM_BestQual"+trigsrc)->second->Fill(phcode_best[wh+3][st][sc]); // Best Qual Trigger Phi view
607  }
608  }
609  }
610  }
611  }
612 
613 }
614 
616 
618 
619  for (int i=0;i<5;++i){
620  for (int j=0;j<6;++j){
621  for (int k=0;k<13;++k){
622  dduphcode_best[j][i][k] = -1;
623  dduthcode_best[j][i][k] = -1;
624  }
625  }
626  }
627 
628  for (detUnitIt=trigsDDU->begin();
629  detUnitIt!=trigsDDU->end();
630  ++detUnitIt){
631 
632  const DTChamberId& id = (*detUnitIt).first;
633  const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
634  uint32_t indexCh = id.rawId();
635  map<string, MonitorElement*> &innerME = digiHistos[indexCh];
636 
637  int wh = id.wheel();
638  int sec = id.sector();
639  int st = id.station();
640 
641  for (DTLocalTriggerCollection::const_iterator trigIt = range.first;
642  trigIt!=range.second;
643  ++trigIt){
644 
645  int bx = trigIt->bx();
646  int quality = trigIt->quality();
647  int thqual = trigIt->trTheta();
648  int flag1st = trigIt->secondTrack() ? 1 : 0;
649 
650  // check if SC data exist: fill for any trigger
651  if( quality>-1 && quality<7 ) { // it is a phi trigger
652 
653  if(quality>dduphcode_best[wh+3][st][sec]) {
654  dduphcode_best[wh+3][st][sec]=quality;
655  iphbestddu[wh+3][st][sec] = &(*trigIt);
656  }
657 
658  if(tpMode) {
659  innerME.find("DDU_BXvsQual"+trigsrc)->second->Fill(quality,bx-flag1st); // SM BX vs Qual Phi view
660  }
661  else {
662  innerME.find("DDU_BXvsQual"+trigsrc)->second->Fill(quality,bx-flag1st); // SM BX vs Qual Phi view
663  innerME.find("DDU_Flag1stvsQual"+trigsrc)->second->Fill(quality,flag1st); // SM Quality vs 1st/2nd track flag Phi view
664  }
665  }
666  if( thqual>0 && !tpMode ) { // it is a theta trigger
667 
668  if(thqual>dduthcode_best[wh+3][st][sec] ) {
669  dduthcode_best[wh+3][st][sec]=thqual;
670  }
671 
672  innerME.find("DDU_ThetaBXvsQual"+trigsrc)->second->Fill(thqual,bx); // SM BX vs Qual Theta view
673  }
674  }
675 
676  // Fill Quality plots with best ddu triggers in phi & theta
677  if (!tpMode) {
678  if (dduphcode_best[wh+3][st][sec]>-1 &&
679  dduphcode_best[wh+3][st][sec]<7){
680 
681  innerME.find("DDU_BestQual"+trigsrc)->second->Fill(dduphcode_best[wh+3][st][sec]); // Best Qual Trigger Phi view
682  }
683  if (dduthcode_best[wh+3][st][sec]>0){
684  innerME.find("DDU_ThetaBestQual"+trigsrc)->second->Fill(dduthcode_best[wh+3][st][sec]); // Best Qual Trigger Theta view
685  }
686  }
687  }
688 }
689 
690 
692 
694 
695  // Find best tracks & good tracks
696  memset(track_ok,false,450*sizeof(bool));
697 
698  DTRecSegment4DCollection::id_iterator chamberId;
699  vector<const DTRecSegment4D*> best4DSegments;
700 
701  // Preliminary loop finds best 4D Segment and high quality ones
702  for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
703 
704  DTRecSegment4DCollection::range range = segments4D->get(*chamberId);
705  const DTRecSegment4D* tmpBest=0;
706  int tmpdof = 0;
707  int dof = 0;
708 
709  for ( track = range.first; track != range.second; ++track){
710 
711  if( (*track).hasPhi() ) {
712 
713  dof = (*track).phiSegment()->degreesOfFreedom();
714  if ( dof>tmpdof ){
715  tmpBest = &(*track);
716  tmpdof = dof;
717 
718  int wheel = (*track).chamberId().wheel();
719  int sector = (*track).chamberId().sector();
720  int station = (*track).chamberId().station();
721  if (sector==13){
722  sector=4;
723  }
724  else if (sector==14){
725  sector=10;
726  }
727  track_ok[wheel+3][station][sector] = (!track_ok[wheel+3][station][sector] && dof>=2);
728  }
729 
730  }
731  }
732  if (tmpBest) best4DSegments.push_back(tmpBest);
733  }
734 
735  vector<const DTRecSegment4D*>::const_iterator btrack;
736 
737  for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
738 
739  if( (*btrack)->hasPhi() ) { // Phi component
740 
741  int wheel = (*btrack)->chamberId().wheel();
742  int station = (*btrack)->chamberId().station();
743  int sector = (*btrack)->chamberId().sector();
744  int scsector = 0;
745  float x_track, y_track, x_angle, y_angle;
746  trigGeomUtils->computeSCCoordinates((*btrack),scsector,x_track,x_angle,y_track,y_angle);
747  int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom()+2;
748 
749  DTChamberId dtChId(wheel,station,sector); // get chamber for LUTs histograms (Sectors 1 to 14)
750  uint32_t indexCh = dtChId.rawId();
751  map<string, MonitorElement*> &innerMECh = digiHistos[indexCh];
752 
753  DTChamberId dtChIdSC = DTChamberId(wheel,station,scsector); // get chamber for histograms SC granularity (sectors 1 to 12)
754  indexCh = dtChIdSC.rawId();
755  map<string, MonitorElement*> &innerME = digiHistos[indexCh];
756 
757  if (useDDU &&
758  dduphcode_best[wheel+3][station][scsector] > -1 &&
759  dduphcode_best[wheel+3][station][scsector] < 7 ) {
760 
761  // SM hits of the track vs quality of the trigger
762  innerME.find("DDU_HitstkvsQualtrig"+trigsrc)->second->Fill(dduphcode_best[wheel+3][station][scsector],nHitsPhi);
763 
764  }
765 
766  if (useTM &&
767  phcode_best[wheel+3][station][scsector] > -1 &&
768  phcode_best[wheel+3][station][scsector] < 7 ) {
769 
770  innerME.find("TM_HitstkvsQualtrig"+trigsrc)->second->Fill(phcode_best[wheel+3][station][scsector],nHitsPhi);
771 
772  if (phcode_best[wheel+3][station][scsector]>3 && nHitsPhi>=7){
773 
774  float x_trigger = trigGeomUtils->trigPos(iphbest[wheel+3][station][scsector]);
775  float angle_trigger = trigGeomUtils->trigDir(iphbest[wheel+3][station][scsector]);
776  trigGeomUtils->trigToSeg(station,x_trigger,x_angle);
777 
778  innerMECh.find("TM_PhitkvsPhitrig"+trigsrc)->second->Fill(x_trigger,x_track);
779  innerMECh.find("TM_PhibtkvsPhibtrig"+trigsrc)->second->Fill(angle_trigger,x_angle);
780  innerMECh.find("TM_PhiResidual"+trigsrc)->second->Fill(x_trigger-x_track);
781  innerMECh.find("TM_PhibResidual"+trigsrc)->second->Fill(angle_trigger-x_angle);
782  }
783  }
784 
785 
786  if (useTM) {
787 
788  // check for triggers elsewhere in the sector
789  bool trigFlagTM =false;
790  for (int ist=1; ist<5; ist++){
791  if (ist!=station &&
792  phcode_best[wheel+3][ist][scsector]>=2 &&
793  phcode_best[wheel+3][ist][scsector]<7 &&
794  track_ok[wheel+3][ist][scsector]==true){
795  trigFlagTM = true;
796  break;
797  }
798  }
799 
800  if (trigFlagTM && fabs(x_angle)<40. && nHitsPhi>=7){
801 
802  // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
803  innerME.find("TM_TrackPosvsAngle"+trigsrc)->second->Fill(x_angle,x_track);
804  if (phcode_best[wheel+3][station][scsector] >= 2 && phcode_best[wheel+3][station][scsector] < 7) {
805  innerME.find("TM_TrackPosvsAngleandTrig"+trigsrc)->second->Fill(x_angle,x_track);
806  if (phcode_best[wheel+3][station][scsector] > 4){ //HH & HL Triggers
807  innerME.find("TM_TrackPosvsAngleandTrigHHHL"+trigsrc)->second->Fill(x_angle,x_track);
808  }
809  }
810 
811  }
812 
813  if ((*btrack)->hasZed() && trigFlagTM && fabs(y_angle)<40. && (*btrack)->zSegment()->degreesOfFreedom()>=1){
814 
815  // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
816  innerME.find("TM_TrackThetaPosvsAngle"+trigsrc)->second->Fill(y_angle,y_track);
817  if (thcode_best[wheel+3][station][scsector] > 0) {
818  innerME.find("TM_TrackThetaPosvsAngleandTrig"+trigsrc)->second->Fill(y_angle,y_track);
819  }
820 
821  }
822  }
823 
824  if (useDDU) {
825 
826  // check for triggers elsewhere in the sector
827  bool trigFlagDDU =false;
828  for (int ist=1; ist<5; ist++){
829  if (ist!=station &&
830  dduphcode_best[wheel+3][ist][scsector]>=2 &&
831  dduphcode_best[wheel+3][ist][scsector]<7 &&
832  track_ok[wheel+3][ist][scsector]==true){
833  trigFlagDDU = true;
834  break;
835  }
836  }
837 
838  if (trigFlagDDU && fabs(x_angle)<40. && nHitsPhi>=7){
839 
840  // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
841  innerME.find("DDU_TrackPosvsAngle"+trigsrc)->second->Fill(x_angle,x_track);
842  if (dduphcode_best[wheel+3][station][scsector] >= 2 && dduphcode_best[wheel+3][station][scsector] < 7) {
843  innerME.find("DDU_TrackPosvsAngleandTrig"+trigsrc)->second->Fill(x_angle,x_track);
844  if (dduphcode_best[wheel+3][station][scsector] > 4){ //HH & HL Triggers
845  innerME.find("DDU_TrackPosvsAngleandTrigHHHL"+trigsrc)->second->Fill(x_angle,x_track);
846  }
847  }
848 
849  }
850 
851  if ((*btrack)->hasZed() && trigFlagDDU && fabs(y_angle)<40. && (*btrack)->zSegment()->degreesOfFreedom()>=1){
852 
853  // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
854  innerME.find("DDU_TrackThetaPosvsAngle"+trigsrc)->second->Fill(y_angle,y_track);
855  if (dduthcode_best[wheel+3][station][scsector] > 0) {
856  innerME.find("DDU_TrackThetaPosvsAngleandTrig"+trigsrc)->second->Fill(y_angle,y_track);
857  if (dduthcode_best[wheel+3][station][scsector] == 3) {
858  innerME.find("DDU_TrackThetaPosvsAngleandTrigH"+trigsrc)->second->Fill(y_angle,y_track);
859  }
860  }
861 
862  }
863  }
864  }
865  }
866 
867 }
868 
869 
871 
872  string histoType ;
873  string histoTag ;
874 
875  for (int st=1;st<5;++st){
876  for (int wh=-2;wh<3;++wh){
877  for (int sc=1;sc<13;++sc){
878  if ( (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7) ||
879  (dduphcode_best[wh+3][st][sc]>-1 && dduphcode_best[wh+3][st][sc]<7) ){
880  DTChamberId id(wh,st,sc);
881  uint32_t indexCh = id.rawId();
882  map<string, MonitorElement*> &innerME = digiHistos[indexCh];
883 
884  innerME.find("COM_QualDDUvsQualTM"+trigsrc)->second->Fill(phcode_best[wh+3][st][sc],dduphcode_best[wh+3][st][sc]);
885  if ( (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7) &&
886  (dduphcode_best[wh+3][st][sc]>-1 && dduphcode_best[wh+3][st][sc]<7) ){
887  int bxDDU = iphbestddu[wh+3][st][sc]->bx() - iphbestddu[wh+3][st][sc]->secondTrack();
888  int bxTM = iphbest[wh+3][st][sc]->bxNum() - iphbest[wh+3][st][sc]->Ts2Tag();
889  (wheelHistos[wh]).find("COM_BXDiff"+trigsrc)->second->Fill(sc,st,bxDDU-bxTM);
890  }
891  }
892  }
893  }
894  }
895 
896 }
897 
899 
900  TH1* histo = me->getTH1();
901  if (!histo) return;
902 
903  TAxis* axis=0;
904  if (iaxis==1) {
905  axis=histo->GetXaxis();
906  }
907  else if(iaxis==2) {
908  axis=histo->GetYaxis();
909  }
910  if (!axis) return;
911 
912  string labels[7] = {"LI","LO","HI","HO","LL","HL","HH"};
913  int istart = axis->GetXmin()<-1 ? 2 : 1;
914  for (int i=0;i<7;i++) {
915  axis->SetBinLabel(i+istart,labels[i].c_str());
916  }
917 
918 }
919 
921 
922 
923  if (!isLocalRun){
924 
925  Handle<LTCDigiCollection> ltcdigis;
926  e.getByToken(ltcDigiCollectionToken_, ltcdigis);
927 
928  for (std::vector<LTCDigi>::const_iterator ltc_it = ltcdigis->begin(); ltc_it != ltcdigis->end(); ltc_it++){
929 
930  size_t otherTriggerSum=0;
931  for (size_t i = 1; i < 6; i++) {
932  otherTriggerSum += size_t((*ltc_it).HasTriggered(i));
933  }
934  if ((*ltc_it).HasTriggered(0) && otherTriggerSum == 0)
935  trigsrc = "_DTonly";
936  else if (!(*ltc_it).HasTriggered(0))
937  trigsrc = "_NoDT";
938  else if ((*ltc_it).HasTriggered(0) && otherTriggerSum > 0)
939  trigsrc = "_DTalso";
940 
941  }
942  return;
943  }
944 
945  trigsrc = "";
946  return;
947 
948 }
949 
950 // Local Variables:
951 // show-trailing-whitespace: t
952 // truncate-lines: t
953 // End:
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
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.
int phcode_best[6][5][13]
virtual int degreesOfFreedom() const
return the DOF of the segment
std::map< int, std::map< std::string, MonitorElement * > > wheelHistos
void runTMAnalysis(std::vector< L1MuDTChambPhDigi > const *phTrigs, std::vector< L1MuDTChambThDigi > const *thTrigs)
Run analysis on TM data.
edm::EDGetTokenT< LTCDigiCollection > ltcDigiCollectionToken_
int thcode_best[6][5][13]
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Book the histograms.
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
float trigDir(const L1MuDTChambPhDigi *trig)
Return local direction (trigger RF) for a given trigger primitive.
edm::EDGetTokenT< L1MuDTChambPhContainer > dcc_Token_
int dduphcode_best[6][5][13]
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
Beginrun.
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool track_ok[6][5][15]
std::string & topFolder(bool isTM)
Get the Top folder (different between Physics and TP and TM/DDU)
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
int dduthcode_best[6][5][13]
void runSegmentAnalysis(edm::Handle< DTRecSegment4DCollection > &segments4D)
Run analysis using DT 4D segments.
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:163
void trigToSeg(int st, float &x, float dir)
Compute Trigger x coordinate in chamber RF.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int j
Definition: DBlmapReader.cc:9
TH1 * getTH1(void) const
T min(T a, T b)
Definition: MathUtil.h:58
DTLocalTriggerTask(const edm::ParameterSet &ps)
Constructor.
bool isValid() const
Definition: HandleBase.h:75
#define LogTrace(id)
edm::EDGetTokenT< DTLocalTriggerCollection > ros_Token_
edm::ESHandle< DTGeometry > muonGeom
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)
const DTLocalTrigger * iphbestddu[6][5][13]
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
void runDDUvsTMAnalysis(std::string &trigsrc)
Run analysis on ROS data.
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
const L1MuDTChambThDigi * ithbest[6][5][13]
LuminosityBlockNumber_t luminosityBlock() const
void setQLabels(MonitorElement *me, short int iaxis)
Set Quality labels.
std::vector< DTLocalTrigger >::const_iterator const_iterator
edm::EDGetTokenT< L1MuDTChambThContainer > dccTh_Token_
return(e1-e2)*(e1-e2)+dp *dp
edm::ParameterSet parameters
bool secondTrack() const
DTTrigGeomUtils * trigGeomUtils
const L1MuDTChambPhDigi * iphbest[6][5][13]
int sector() const
Definition: DTChamberId.h:61
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
virtual ~DTLocalTriggerTask()
Destructor.
void bookWheelHistos(DQMStore::IBooker &, int wh, std::string histoTag)
Book the histograms.
void triggerSource(const edm::Event &e)
Get the L1A source.
std::pair< const_iterator, const_iterator > Range
float trigPos(const L1MuDTChambPhDigi *trig)
Return local position (trigger RF) for a given trigger primitive.
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
MonitorElement * dcc_IDDataErrorPlot
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void bookBarrelHistos(DQMStore::IBooker &, std::string histoTag)
Book the histograms.
std::map< uint32_t, std::map< std::string, MonitorElement * > > digiHistos
void computeSCCoordinates(const DTRecSegment4D *track, int &scsec, float &x, float &xdir, float &y, float &ydir)
Compute track coordinates with SC sector numbering.
uint16_t bx() const
Definition: Run.h:43
void runDDUAnalysis(edm::Handle< DTLocalTriggerCollection > &trigsDDU)
Run analysis on ROS data.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11