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