CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>(
51  dcc_Token_ = consumes<L1MuDTChambPhContainer>(
53  ddu_Token_ = consumes<DTLocalTriggerCollection>(
56  gmt_Token_ = consumes<L1MuGMTReadoutCollection>(
58 
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  nMinHitsPhi = parameters.getUntrackedParameter<int>("nMinHitsPhi");
68  phiAccRange = parameters.getUntrackedParameter<double>("phiAccRange");
69 
70  if (processTM) processTags.push_back("TM");
71  if (processDDU) processTags.push_back("DDU");
72 
73 }
74 
75 
77 
78  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: analyzed " << nevents << " events" << endl;
79 
80 }
81 
83 
84  // Get the geometry
85  context.get<MuonGeometryRecord>().get(muonGeom);
87 
88 }
89 
91  edm::Run const & run,
92  edm::EventSetup const & context) {
93 
94  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: bookHistograms" << endl;
95 
96  nevents = 0;
97 
98  for (int wh=-2;wh<=2;++wh){
99  vector<string>::const_iterator tagIt = processTags.begin();
100  vector<string>::const_iterator tagEnd = processTags.end();
101  for (; tagIt!=tagEnd; ++tagIt) {
102 
103  bookWheelHistos(ibooker,wh,(*tagIt),"Task");
104  if (detailedPlots) {
105  for (int stat=1;stat<=4;++stat){
106  for (int sect=1;sect<=12;++sect){
107  bookChamberHistos(ibooker,DTChamberId(wh,stat,sect),(*tagIt),"Segment");
108  }
109  }
110  }
111  }
112  }
113 }
114 
116 
117  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") <<"[DTTriggerEfficiencyTask]: Begin of LS transition"<<endl;
118 
119 }
120 
122 
123  nevents++;
124 
125  if (!hasRPCTriggers(e)) { return; }
126 
127  map<DTChamberId,const L1MuDTChambPhDigi*> phBestTM;
128  map<DTChamberId,const DTLocalTrigger*> phBestDDU;
129 
130  // Getting best TM Stuff
132  e.getByToken(dcc_Token_, l1DTTPGPh);
133  vector<L1MuDTChambPhDigi> const* phTrigs = l1DTTPGPh->getContainer();
134 
135  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
136  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
137  for(; iph !=iphe ; ++iph) {
138 
139  int phwheel = iph->whNum();
140  int phsec = iph->scNum() + 1; // DTTF numbering [0:11] -> DT numbering [1:12]
141  int phst = iph->stNum();
142  int phcode = iph->code();
143 
144  DTChamberId chId(phwheel,phst,phsec);
145 
146  if( phcode < 7 && (phBestTM.find(chId) == phBestTM.end() ||
147  phcode>phBestTM[chId]->code()) ) phBestTM[chId] = &(*iph);
148  }
149 
150  //Getting Best DDU Stuff
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 
171  //Getting Best Segments
172  vector<const DTRecSegment4D*> best4DSegments;
173 
175  e.getByToken(muons_Token_, muons);
176  reco::MuonCollection::const_iterator mu;
177 
178  for( mu = muons->begin(); mu != muons->end(); ++mu ) {
179 
180  // Make sure that is standalone muon
181  if( !((*mu).isStandAloneMuon()) ) {continue;}
182 
183  // Get the chambers compatible with the muon
184  const vector<reco::MuonChamberMatch> matchedChambers = (*mu).matches();
185  vector<reco::MuonChamberMatch>::const_iterator chamber;
186 
187  for( chamber = matchedChambers.begin(); chamber != matchedChambers.end(); ++chamber ) {
188 
189  // look only in DTs
190  if( chamber->detector() != MuonSubdetId::DT ) {continue;}
191 
192  // Get the matched segments in the chamber
193  const vector<reco::MuonSegmentMatch> matchedSegments = (*chamber).segmentMatches;
194  vector<reco::MuonSegmentMatch>::const_iterator segment;
195 
196  for( segment = matchedSegments.begin(); segment != matchedSegments.end(); ++segment ) {
197 
198  edm::Ref<DTRecSegment4DCollection> dtSegment = segment->dtSegmentRef;
199 
200  // Segment Arbitration
201  if( SegmArbitration == "SegmentArbitration"
202  && !((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ) {continue;}
203 
204  if( SegmArbitration == "SegmentAndTrackArbitration"
205  && (!((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ||
206  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByDR))) ) {continue;}
207 
208  if( SegmArbitration == "SegmentAndTrackArbitrationCleaned"
209  && (!((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ||
210  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByDR)) ||
211  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByCleaning))) ) {continue;}
212 
213 
214  if( (*dtSegment).hasPhi() ) {
215  best4DSegments.push_back(&(*dtSegment));
216  }
217 
218  }// end loop on matched segments
219  }// end loop on compatible chambers
220  }// end loop on muons
221 
222  // Plot filling
223  vector<const DTRecSegment4D*>::const_iterator btrack;
224  for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
225 
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 
239  vector<string>::const_iterator tagIt = processTags.begin();
240  vector<string>::const_iterator tagEnd = processTags.end();
241 
242  for (; tagIt!=tagEnd; ++tagIt) {
243 
244  int qual = (*tagIt) == "TM" ?
245  phBestTM.find(dtChId) != phBestTM.end() ? phBestTM[dtChId]->code() : -1 :
246  phBestDDU.find(dtChId) != phBestDDU.end() ? phBestDDU[dtChId]->quality() : -1;
247 
248  innerWhME.find((*tagIt) + "_TrigEffDenum")->second->Fill(scsector,station);
249  if ( qual>=0 && qual<7 ) {
250  innerWhME.find((*tagIt) + "_TrigEffNum")->second->Fill(scsector,station);
251  if ( qual>=4 ) {
252  innerWhME.find((*tagIt) + "_TrigEffCorrNum")->second->Fill(scsector,station);
253  }
254  }
255  if (detailedPlots) {
256  innerChME.find((*tagIt) + "_TrackPosvsAngle")->second->Fill(xdir,x);
257  if ( qual>=0 && qual<7 ) {
258  innerChME.find((*tagIt) + "_TrackPosvsAngleAnyQual")->second->Fill(xdir,x);
259  if ( qual>=4 ) {
260  innerChME.find((*tagIt) + "_TrackPosvsAngleCorr")->second->Fill(xdir,x);
261  }
262  }
263  }
264  }
265  }
266  }
267 
268 }
269 
271 
273  e.getByToken(gmt_Token_, gmtrc);
274 
275  std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
276  std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr = gmt_records.begin();
277  std::vector<L1MuGMTReadoutRecord>::const_iterator egmtrr = gmt_records.end();
278  for(; igmtrr!=egmtrr; igmtrr++) {
279 
280  std::vector<L1MuGMTExtendedCand> candsGMT = igmtrr->getGMTCands();
281  std::vector<L1MuGMTExtendedCand>::const_iterator candGMTIt = candsGMT.begin();
282  std::vector<L1MuGMTExtendedCand>::const_iterator candGMTEnd = candsGMT.end();
283 
284  for(; candGMTIt!=candGMTEnd; ++candGMTIt){
285  if(!candGMTIt->empty()) {
286  int quality = candGMTIt->quality();
287  if(candGMTIt->bx()==0 &&
288  (quality == 5 || quality == 7)){
289  return true;
290  }
291  }
292  }
293  }
294 
295  return false;
296 
297 }
298 
300  string histoType, string folder) {
301 
302  int wh = dtCh.wheel();
303  int sc = dtCh.sector();
304  int st = dtCh.station();
305  stringstream wheel; wheel << wh;
306  stringstream station; station << st;
307  stringstream sector; sector << sc;
308 
309  string hwFolder = topFolder(histoType);
310  string bookingFolder = hwFolder + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/" + folder;
311  string histoTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
312 
313  ibooker.setCurrentFolder(bookingFolder);
314 
315  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask")
316  << "[DTTriggerEfficiencyTask]: booking histos in " << bookingFolder << endl;
317 
318  float min, max;
319  int nbins;
320  trigGeomUtils->phiRange(dtCh,min,max,nbins,20);
321 
322  string histoName = histoType + "_TrackPosvsAngle" + histoTag;
323  string histoLabel = "Position vs Angle (phi)";
324 
325  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngle"] =
326  ibooker.book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
327 
328  histoName = histoType + "_TrackPosvsAngleAnyQual" + histoTag;
329  histoLabel = "Position vs Angle (phi) for any qual triggers";
330 
331  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngleAnyQual"] =
332  ibooker.book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
333 
334  histoName = histoType + "_TrackPosvsAngleCorr" + histoTag;
335  histoLabel = "Position vs Angle (phi) for correlated triggers";
336 
337  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngleCorr"] =
338  ibooker.book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
339 
340 }
341 
343  string folder) {
344 
345  stringstream wh; wh << wheel;
346  string basedir;
347  if (hTag.find("Summary") != string::npos ) {
348  basedir = topFolder(hTag); //Book summary histo outside folder directory
349  } else {
350  basedir = topFolder(hTag) + folder + "/" ;
351  }
352 
353  ibooker.setCurrentFolder(basedir);
354 
355  string hTagName = "_W" + wh.str();
356 
357  LogTrace("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask")
358  << "[DTTriggerEfficiencyTask]: booking histos in "<< basedir << endl;
359 
360  string hName = hTag + "_TrigEffDenum" + hTagName;
361 
362  MonitorElement* me = ibooker.book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
363 
364  me->setBinLabel(1,"MB1",2);
365  me->setBinLabel(2,"MB2",2);
366  me->setBinLabel(3,"MB3",2);
367  me->setBinLabel(4,"MB4",2);
368  me->setAxisTitle("Sector",1);
369 
370  wheelHistos[wheel][hTag + "_TrigEffDenum"] = me;
371 
372  hName = hTag + "_TrigEffNum" + hTagName;
373  me = ibooker.book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
374 
375  me->setBinLabel(1,"MB1",2);
376  me->setBinLabel(2,"MB2",2);
377  me->setBinLabel(3,"MB3",2);
378  me->setBinLabel(4,"MB4",2);
379  me->setAxisTitle("Sector",1);
380 
381  wheelHistos[wheel][hTag + "_TrigEffNum"] = me;
382 
383  hName = hTag + "_TrigEffCorrNum" + hTagName;
384  me = ibooker.book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
385 
386  me->setBinLabel(1,"MB1",2);
387  me->setBinLabel(2,"MB2",2);
388  me->setBinLabel(3,"MB3",2);
389  me->setBinLabel(4,"MB4",2);
390  me->setAxisTitle("Sector",1);
391 
392  wheelHistos[wheel][hTag + "_TrigEffCorrNum"] = me;
393 
394  return;
395 }
396 
397 
398 // Local Variables:
399 // show-trailing-whitespace: t
400 // truncate-lines: t
401 // End:
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< L1MuDTChambPhContainer > dcc_Token_
edm::EDGetTokenT< L1MuGMTReadoutCollection > gmt_Token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< reco::MuonCollection > muons_Token_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
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)
std::map< int, std::map< std::string, MonitorElement * > > wheelHistos
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
void bookChamberHistos(DQMStore::IBooker &ibooker, const DTChamberId &dtCh, std::string histoTag, std::string folder="")
Book chamber granularity histograms.
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
const T & get() const
Definition: EventSetup.h:56
virtual ~DTTriggerEfficiencyTask()
Destructor.
std::vector< DTLocalTrigger >::const_iterator const_iterator
std::vector< std::string > processTags
static const unsigned int BelongsToTrackByDR
tuple muons
Definition: patZpeak.py:38
int sector() const
Definition: DTChamberId.h:61
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.
Definition: Run.h:43