CMS 3D CMS Logo

DTTriggerEfficiencyTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTTriggerEfficiencyTask.cc
3  *
4  * \author C.Battilana - CIEMAT
5  *
6  */
7 
9 
10 // Framework
12 
13 // DT trigger
15 
16 // Geometry
23 
24 // DT Digi
27 
28 // Muon tracks
30 
31 //Root
32 #include"TH1.h"
33 #include"TAxis.h"
34 
35 #include <sstream>
36 #include <iostream>
37 #include <fstream>
38 
39 
40 using namespace edm;
41 using namespace std;
42 
44 
45  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: Constructor" << endl;
46 
47  parameters = ps;
48 
49  muons_Token_ = consumes<reco::MuonCollection>(
50  parameters.getUntrackedParameter<edm::InputTag>("inputTagMuons"));
51  tm_Token_ = consumes<L1MuDTChambPhContainer>(
52  parameters.getUntrackedParameter<edm::InputTag>("inputTagTM"));
53  ddu_Token_ = consumes<DTLocalTriggerCollection>(
54  parameters.getUntrackedParameter<edm::InputTag>("inputTagDDU"));
55  inputTagSEG = parameters.getUntrackedParameter<edm::InputTag>("inputTagSEG");
56  gmt_Token_ = consumes<L1MuGMTReadoutCollection>(
57  parameters.getUntrackedParameter<edm::InputTag>("inputTagGMT"));
58 
59  SegmArbitration = parameters.getUntrackedParameter<std::string>("SegmArbitration");
60 
61  detailedPlots = parameters.getUntrackedParameter<bool>("detailedAnalysis");
62  processTM = parameters.getUntrackedParameter<bool>("processTM");
63  processDDU = parameters.getUntrackedParameter<bool>("processDDU");
64  minBXDDU = parameters.getUntrackedParameter<int>("minBXDDU");
65  maxBXDDU = parameters.getUntrackedParameter<int>("maxBXDDU");
66 
67  checkRPCtriggers = parameters.getUntrackedParameter<bool>("checkRPCtriggers");
68  nMinHitsPhi = parameters.getUntrackedParameter<int>("nMinHitsPhi");
69  phiAccRange = parameters.getUntrackedParameter<double>("phiAccRange");
70 
71  if (processTM) processTags.push_back("TM");
72  if (processDDU) {processTags.push_back("DDU");
73  ddu_Token_ = consumes<DTLocalTriggerCollection>(
74  parameters.getUntrackedParameter<edm::InputTag>("inputTagDDU"));
75  }
76  if (!processTM && !processDDU) LogError ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: Error, no trigger source (DDU or Twinmux) has been selected!!" <<endl;
77 
78 }
79 
80 
82 
83  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: analyzed " << nevents << " events" << endl;
84 
85 }
86 
88 
89  // Get the geometry
90  context.get<MuonGeometryRecord>().get(muonGeom);
92 
93 }
94 
96  edm::Run const & run,
97  edm::EventSetup const & context) {
98 
99  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: bookHistograms" << endl;
100 
101  nevents = 0;
102  for (int wh=-2;wh<=2;++wh){
103  vector<string>::const_iterator tagIt = processTags.begin();
104  vector<string>::const_iterator tagEnd = processTags.end();
105  for (; tagIt!=tagEnd; ++tagIt) {
106 
107  bookWheelHistos(ibooker,wh,(*tagIt),"Task");
108  if (detailedPlots) {
109  for (int stat=1;stat<=4;++stat){
110  for (int sect=1;sect<=12;++sect){
111  bookChamberHistos(ibooker,DTChamberId(wh,stat,sect),(*tagIt),"Segment");
112  }
113  }
114  }
115  }
116  }
117 }
118 
119 
121 
122  nevents++;
123 
124  if (checkRPCtriggers){ //For pre-2016 Era compatibility
125  if (!hasRPCTriggers(e)) { return; }
126  }
127  map<DTChamberId,const L1MuDTChambPhDigi*> phBestTM;
128  map<DTChamberId,const DTLocalTrigger*> phBestDDU;
129  // Getting best TM Stuff
131  e.getByToken(tm_Token_, l1DTTPGPh);
132  vector<L1MuDTChambPhDigi> const* phTrigs = l1DTTPGPh->getContainer();
133  //empty from dttfDigis, needs emulator working?
134  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
135  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
136  for(; iph !=iphe ; ++iph) {
137 
138  int phwheel = iph->whNum();
139  int phsec = iph->scNum() + 1; // DTTF numbering [0:11] -> DT numbering [1:12]
140  int phst = iph->stNum();
141  int phcode = iph->code();
142 
143  DTChamberId chId(phwheel,phst,phsec);
144 
145  if( phcode < 7 && (phBestTM.find(chId) == phBestTM.end() ||
146  phcode>phBestTM[chId]->code()) ) phBestTM[chId] = &(*iph);
147  }
148 
149  //Getting Best DDU Stuff
150  if (processDDU){
152  e.getByToken(ddu_Token_, trigsDDU);
154 
155  for (detUnitIt=trigsDDU->begin();detUnitIt!=trigsDDU->end();++detUnitIt){
156 
157  const DTChamberId& id = (*detUnitIt).first;
158  const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
159 
160  DTLocalTriggerCollection::const_iterator trigIt = range.first;
161  DTLocalTriggerCollection::const_iterator trigEnd = range.second;
162  for (; trigIt!= trigEnd;++trigIt){
163  int quality = trigIt->quality();
164  if(quality>-1 && quality<7 &&
165  (phBestDDU.find(id) == phBestDDU.end() ||
166  quality>phBestDDU[id]->quality()) ) phBestDDU[id] = &(*trigIt);
167  }
168 
169  }
170  }//processDDU
171 
172  //Getting Best Segments
173  vector<const DTRecSegment4D*> best4DSegments;
174 
176  e.getByToken(muons_Token_, muons);
177  reco::MuonCollection::const_iterator mu;
178 
179  for( mu = muons->begin(); mu != muons->end(); ++mu ) {
180 
181  // Make sure that is standalone muon
182  if( !((*mu).isStandAloneMuon()) ) {continue;}
183 
184  // Get the chambers compatible with the muon
185  const vector<reco::MuonChamberMatch> matchedChambers = (*mu).matches();
186  vector<reco::MuonChamberMatch>::const_iterator chamber;
187 
188  for( chamber = matchedChambers.begin(); chamber != matchedChambers.end(); ++chamber ) {
189 
190  // look only in DTs
191  if( chamber->detector() != MuonSubdetId::DT ) {continue;}
192 
193  // Get the matched segments in the chamber
194  const vector<reco::MuonSegmentMatch> matchedSegments = (*chamber).segmentMatches;
195  vector<reco::MuonSegmentMatch>::const_iterator segment;
196 
197  for( segment = matchedSegments.begin(); segment != matchedSegments.end(); ++segment ) {
198 
199  edm::Ref<DTRecSegment4DCollection> dtSegment = segment->dtSegmentRef;
200 
201  // Segment Arbitration
202  if( SegmArbitration == "SegmentArbitration"
203  && !((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ) {continue;}
204 
205  if( SegmArbitration == "SegmentAndTrackArbitration"
206  && (!((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ||
207  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByDR))) ) {continue;}
208 
209  if( SegmArbitration == "SegmentAndTrackArbitrationCleaned"
210  && (!((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ||
211  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByDR)) ||
212  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByCleaning))) ) {continue;}
213 
214 
215  if( (*dtSegment).hasPhi() ) {
216  best4DSegments.push_back(&(*dtSegment));
217  }
218 
219  }// end loop on matched segments
220  }// end loop on compatible chambers
221  }// end loop on muons
222 
223  // Plot filling
224  vector<const DTRecSegment4D*>::const_iterator btrack;
225  for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
226  int wheel = (*btrack)->chamberId().wheel();
227  int station = (*btrack)->chamberId().station();
228  int scsector = 0;
229  float x, xdir, y, ydir;
230  trigGeomUtils->computeSCCoordinates((*btrack),scsector,x,xdir,y,ydir);
231  int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom()+2;
232  DTChamberId dtChId(wheel,station,scsector);
233  uint32_t indexCh = dtChId.rawId();
234  map<string, MonitorElement*> &innerChME = chamberHistos[indexCh];
235  map<string, MonitorElement*> &innerWhME = wheelHistos[wheel];
236 
237  if (fabs(xdir)<phiAccRange && nHitsPhi>=nMinHitsPhi){
238  vector<string>::const_iterator tagIt = processTags.begin();
239  vector<string>::const_iterator tagEnd = processTags.end();
240  for (; tagIt!=tagEnd; ++tagIt) {
241  int qual = (*tagIt) == "TM" ?
242  phBestTM.find(dtChId) != phBestTM.end() ? phBestTM[dtChId]->code() : -1 :
243  phBestDDU.find(dtChId) != phBestDDU.end() ? phBestDDU[dtChId]->quality() : -1;
244  innerWhME.find((*tagIt) + "_TrigEffDenum")->second->Fill(scsector,station);
245 
246  if ( qual>=0 && qual<7 ) {
247  innerWhME.find((*tagIt) + "_TrigEffNum")->second->Fill(scsector,station);
248  if ( qual>=4 ) {
249  innerWhME.find((*tagIt) + "_TrigEffCorrNum")->second->Fill(scsector,station);
250  }
251  }
252  if (detailedPlots) {
253  innerChME.find((*tagIt) + "_TrackPosvsAngle")->second->Fill(xdir,x);
254  if ( qual>=0 && qual<7 ) {
255  innerChME.find((*tagIt) + "_TrackPosvsAngleAnyQual")->second->Fill(xdir,x);
256  if ( qual>=4 ) {
257  innerChME.find((*tagIt) + "_TrackPosvsAngleCorr")->second->Fill(xdir,x);
258  }
259  }
260  }
261  }
262  }
263  }
264 
265 }
266 
268 
270  e.getByToken(gmt_Token_, gmtrc);
271 
272  std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
273  std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr = gmt_records.begin();
274  std::vector<L1MuGMTReadoutRecord>::const_iterator egmtrr = gmt_records.end();
275  for(; igmtrr!=egmtrr; igmtrr++) {
276 
277  std::vector<L1MuGMTExtendedCand> candsGMT = igmtrr->getGMTCands();
278  std::vector<L1MuGMTExtendedCand>::const_iterator candGMTIt = candsGMT.begin();
279  std::vector<L1MuGMTExtendedCand>::const_iterator candGMTEnd = candsGMT.end();
280 
281  for(; candGMTIt!=candGMTEnd; ++candGMTIt){
282  if(!candGMTIt->empty()) {
283  int quality = candGMTIt->quality();
284  if(candGMTIt->bx()==0 &&
285  (quality == 5 || quality == 7)){
286  return true;
287  }
288  }
289  }
290  }
291 
292  return false;
293 
294 }
295 
297  string histoType, string folder) {
298 
299  int wh = dtCh.wheel();
300  int sc = dtCh.sector();
301  int st = dtCh.station();
302  stringstream wheel; wheel << wh;
303  stringstream station; station << st;
304  stringstream sector; sector << sc;
305 
306  string hwFolder = topFolder(histoType);
307  string bookingFolder = hwFolder + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/" + folder;
308  string histoTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
309 
310  ibooker.setCurrentFolder(bookingFolder);
311 
312  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask")
313  << "[DTTriggerEfficiencyTask]: booking histos in " << bookingFolder << endl;
314 
315  float min, max;
316  int nbins;
317  trigGeomUtils->phiRange(dtCh,min,max,nbins,20);
318 
319  string histoName = histoType + "_TrackPosvsAngle" + histoTag;
320  string histoLabel = "Position vs Angle (phi)";
321 
322  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngle"] =
323  ibooker.book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
324 
325  histoName = histoType + "_TrackPosvsAngleAnyQual" + histoTag;
326  histoLabel = "Position vs Angle (phi) for any qual triggers";
327 
328  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngleAnyQual"] =
329  ibooker.book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
330 
331  histoName = histoType + "_TrackPosvsAngleCorr" + histoTag;
332  histoLabel = "Position vs Angle (phi) for correlated triggers";
333 
334  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngleCorr"] =
335  ibooker.book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
336 
337 }
338 
340  string folder) {
341 
342  stringstream wh; wh << wheel;
343  string basedir;
344  if (hTag.find("Summary") != string::npos ) {
345  basedir = topFolder(hTag); //Book summary histo outside folder directory
346  } else {
347  basedir = topFolder(hTag) + folder + "/" ;
348  }
349 
350  ibooker.setCurrentFolder(basedir);
351 
352  string hTagName = "_W" + wh.str();
353 
354  LogTrace("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask")
355  << "[DTTriggerEfficiencyTask]: booking histos in "<< basedir << endl;
356 
357  string hName = hTag + "_TrigEffDenum" + hTagName;
358 
359  MonitorElement* me = ibooker.book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
360 
361  me->setBinLabel(1,"MB1",2);
362  me->setBinLabel(2,"MB2",2);
363  me->setBinLabel(3,"MB3",2);
364  me->setBinLabel(4,"MB4",2);
365  me->setAxisTitle("Sector",1);
366 
367  wheelHistos[wheel][hTag + "_TrigEffDenum"] = me;
368 
369  hName = hTag + "_TrigEffNum" + hTagName;
370  me = ibooker.book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
371 
372  me->setBinLabel(1,"MB1",2);
373  me->setBinLabel(2,"MB2",2);
374  me->setBinLabel(3,"MB3",2);
375  me->setBinLabel(4,"MB4",2);
376  me->setAxisTitle("Sector",1);
377 
378  wheelHistos[wheel][hTag + "_TrigEffNum"] = me;
379 
380  hName = hTag + "_TrigEffCorrNum" + hTagName;
381  me = ibooker.book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
382 
383  me->setBinLabel(1,"MB1",2);
384  me->setBinLabel(2,"MB2",2);
385  me->setBinLabel(3,"MB3",2);
386  me->setBinLabel(4,"MB4",2);
387  me->setAxisTitle("Sector",1);
388 
389  wheelHistos[wheel][hTag + "_TrigEffCorrNum"] = me;
390 
391  return;
392 }
393 
394 
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
edm::EDGetTokenT< L1MuGMTReadoutCollection > gmt_Token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::EDGetTokenT< reco::MuonCollection > muons_Token_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void bookWheelHistos(DQMStore::IBooker &ibooker, int wheel, std::string histoTag, std::string folder="")
Book wheel granularity histograms.
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_Token_
std::map< int, std::map< std::string, MonitorElement * > > wheelHistos
#define nullptr
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void bookChamberHistos(DQMStore::IBooker &ibooker, const DTChamberId &dtCh, std::string histoTag, std::string folder="")
Book chamber granularity histograms.
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
const int mu
Definition: Constants.h:22
static const unsigned int BestInChamberByDR
T min(T a, T b)
Definition: MathUtil.h:58
#define LogTrace(id)
static const unsigned int BelongsToTrackByCleaning
edm::EDGetTokenT< DTLocalTriggerCollection > ddu_Token_
void phiRange(const DTChamberId &id, float &min, float &max, int &nbins, float step=15)
Compute phi range in local chamber coordinates.
bool hasRPCTriggers(const edm::Event &e)
checks for RPC Triggers
edm::ESHandle< DTGeometry > muonGeom
int nevents
To reset the MEs.
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
std::vector< DTLocalTrigger >::const_iterator const_iterator
Phi_Container const * getContainer() const
std::vector< std::string > processTags
static const unsigned int BelongsToTrackByDR
HLT enums.
int sector() const
Definition: DTChamberId.h:61
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
T get() const
Definition: EventSetup.h:68
std::pair< const_iterator, const_iterator > Range
static const int DT
Definition: MuonSubdetId.h:12
std::map< uint32_t, std::map< std::string, MonitorElement * > > chamberHistos
DTTriggerEfficiencyTask(const edm::ParameterSet &ps)
Constructor.
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
std::string topFolder(std::string source)
return the top folder
void computeSCCoordinates(const DTRecSegment4D *track, int &scsec, float &x, float &xdir, float &y, float &ydir)
Compute track coordinates with SC sector numbering.
~DTTriggerEfficiencyTask() override
Destructor.
Definition: Run.h:44