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  * $Date: 2011/10/21 18:10:23 $
5  * $Revision: 1.9 $
6  * \author C.Battilana - CIEMAT
7  *
8  */
9 
11 
12 // Framework
14 
15 // DT trigger
19 
20 // Geometry
27 
28 // DT Digi
31 
32 // Muon tracks
35 
36 //Root
37 #include"TH1.h"
38 #include"TAxis.h"
39 
40 #include <sstream>
41 #include <iostream>
42 #include <fstream>
43 
44 
45 using namespace edm;
46 using namespace std;
47 
49 
50  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: Constructor" << endl;
51 
52  parameters = ps;
54 
55 }
56 
57 
59 
60  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: analyzed " << nevents << " events" << endl;
61 
62 }
63 
64 
66 
67  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: BeginJob" << endl;
68 
70 
75 
76  SegmArbitration = parameters.getUntrackedParameter<std::string>("SegmArbitration");
77 
78  detailedPlots = parameters.getUntrackedParameter<bool>("detailedAnalysis");
79  processDCC = parameters.getUntrackedParameter<bool>("processDCC");
80  processDDU = parameters.getUntrackedParameter<bool>("processDDU");
81  minBXDDU = parameters.getUntrackedParameter<int>("minBXDDU");
82  maxBXDDU = parameters.getUntrackedParameter<int>("maxBXDDU");
83 
84  nMinHitsPhi = parameters.getUntrackedParameter<int>("nMinHitsPhi");
85  phiAccRange = parameters.getUntrackedParameter<double>("phiAccRange");
86 
87  if (processDCC) processTags.push_back("DCC");
88  if (processDDU) processTags.push_back("DDU");
89 
90 }
91 
93 
94  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: BeginRun" << 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  bookWheelHistos(wh,(*tagIt),"Task");
103  if (detailedPlots) {
104  for (int stat=1;stat<=4;++stat){
105  for (int sect=1;sect<=12;++sect){
106  bookChamberHistos(DTChamberId(wh,stat,sect),(*tagIt),"Segment");
107  }
108  }
109  }
110  }
111  }
112 
113  context.get<MuonGeometryRecord>().get(muonGeom);
115 
116 }
117 
119 
120  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") <<"[DTTriggerEfficiencyTask]: Begin of LS transition"<<endl;
121 
122 }
123 
124 
126 
127  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: analyzed " << nevents << " events" << endl;
128 
129 }
130 
131 
133 
134  nevents++;
135 
136  if (!hasRPCTriggers(e)) { return; }
137 
138  map<DTChamberId,const L1MuDTChambPhDigi*> phBestDCC;
139  map<DTChamberId,const DTLocalTrigger*> phBestDDU;
140 
141  // Getting best DCC Stuff
143  e.getByLabel(inputTagDCC,l1DTTPGPh);
144  vector<L1MuDTChambPhDigi>* phTrigs = l1DTTPGPh->getContainer();
145 
146  vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
147  vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
148  for(; iph !=iphe ; ++iph) {
149 
150  int phwheel = iph->whNum();
151  int phsec = iph->scNum() + 1; // DTTF numbering [0:11] -> DT numbering [1:12]
152  int phst = iph->stNum();
153  int phcode = iph->code();
154 
155  DTChamberId chId(phwheel,phst,phsec);
156 
157  if( phcode < 7 && (phBestDCC.find(chId) == phBestDCC.end() ||
158  phcode>phBestDCC[chId]->code()) ) phBestDCC[chId] = &(*iph);
159  }
160 
161  //Getting Best DDU Stuff
163  e.getByLabel(inputTagDDU,trigsDDU);
165 
166  for (detUnitIt=trigsDDU->begin();detUnitIt!=trigsDDU->end();++detUnitIt){
167 
168  const DTChamberId& id = (*detUnitIt).first;
169  const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
170 
171  DTLocalTriggerCollection::const_iterator trigIt = range.first;
172  DTLocalTriggerCollection::const_iterator trigEnd = range.second;
173  for (; trigIt!= trigEnd;++trigIt){
174  int quality = trigIt->quality();
175  if(quality>-1 && quality<7 &&
176  (phBestDDU.find(id) == phBestDDU.end() ||
177  quality>phBestDDU[id]->quality()) ) phBestDDU[id] = &(*trigIt);
178  }
179 
180  }
181 
182  //Getting Best Segments
183  vector<const DTRecSegment4D*> best4DSegments;
184 
186  e.getByLabel(inputTagMuons, muons);
187  reco::MuonCollection::const_iterator mu;
188 
189  for( mu = muons->begin(); mu != muons->end(); ++mu ) {
190 
191  // Make sure that is standalone muon
192  if( !((*mu).isStandAloneMuon()) ) {continue;}
193 
194  // Get the chambers compatible with the muon
195  const vector<reco::MuonChamberMatch> matchedChambers = (*mu).matches();
196  vector<reco::MuonChamberMatch>::const_iterator chamber;
197 
198  for( chamber = matchedChambers.begin(); chamber != matchedChambers.end(); ++chamber ) {
199 
200  // look only in DTs
201  if( chamber->detector() != MuonSubdetId::DT ) {continue;}
202 
203  // Get the matched segments in the chamber
204  const vector<reco::MuonSegmentMatch> matchedSegments = (*chamber).segmentMatches;
205  vector<reco::MuonSegmentMatch>::const_iterator segment;
206 
207  for( segment = matchedSegments.begin(); segment != matchedSegments.end(); ++segment ) {
208 
209  edm::Ref<DTRecSegment4DCollection> dtSegment = segment->dtSegmentRef;
210 
211  // Segment Arbitration
212  if( SegmArbitration == "SegmentArbitration"
213  && !((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ) {continue;}
214 
215  if( SegmArbitration == "SegmentAndTrackArbitration"
216  && (!((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ||
217  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByDR))) ) {continue;}
218 
219  if( SegmArbitration == "SegmentAndTrackArbitrationCleaned"
220  && (!((*segment).isMask(reco::MuonSegmentMatch::BestInChamberByDR)) ||
221  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByDR)) ||
222  !((*segment).isMask(reco::MuonSegmentMatch::BelongsToTrackByCleaning))) ) {continue;}
223 
224 
225  if( (*dtSegment).hasPhi() ) {
226  best4DSegments.push_back(&(*dtSegment));
227  }
228 
229  }// end loop on matched segments
230  }// end loop on compatible chambers
231  }// end loop on muons
232 
233  // Plot filling
234  vector<const DTRecSegment4D*>::const_iterator btrack;
235  for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
236 
237  int wheel = (*btrack)->chamberId().wheel();
238  int station = (*btrack)->chamberId().station();
239  int scsector = 0;
240  float x, xdir, y, ydir;
241  trigGeomUtils->computeSCCoordinates((*btrack),scsector,x,xdir,y,ydir);
242  int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom()+2;
243  DTChamberId dtChId(wheel,station,scsector);
244  uint32_t indexCh = dtChId.rawId();
245  map<string, MonitorElement*> &innerChME = chamberHistos[indexCh];
246  map<string, MonitorElement*> &innerWhME = wheelHistos[wheel];
247 
248  if (fabs(xdir)<phiAccRange && nHitsPhi>=nMinHitsPhi){
249 
250  vector<string>::const_iterator tagIt = processTags.begin();
251  vector<string>::const_iterator tagEnd = processTags.end();
252 
253  for (; tagIt!=tagEnd; ++tagIt) {
254 
255  int qual = (*tagIt) == "DCC" ?
256  phBestDCC.find(dtChId) != phBestDCC.end() ? phBestDCC[dtChId]->code() : -1 :
257  phBestDDU.find(dtChId) != phBestDDU.end() ? phBestDDU[dtChId]->quality() : -1;
258 
259  innerWhME.find((*tagIt) + "_TrigEffDenum")->second->Fill(scsector,station);
260  if ( qual>=0 && qual<7 ) {
261  innerWhME.find((*tagIt) + "_TrigEffNum")->second->Fill(scsector,station);
262  if ( qual>=4 ) {
263  innerWhME.find((*tagIt) + "_TrigEffCorrNum")->second->Fill(scsector,station);
264  }
265  }
266  if (detailedPlots) {
267  innerChME.find((*tagIt) + "_TrackPosvsAngle")->second->Fill(xdir,x);
268  if ( qual>=0 && qual<7 ) {
269  innerChME.find((*tagIt) + "_TrackPosvsAngleAnyQual")->second->Fill(xdir,x);
270  if ( qual>=4 ) {
271  innerChME.find((*tagIt) + "_TrackPosvsAngleCorr")->second->Fill(xdir,x);
272  }
273  }
274  }
275  }
276  }
277  }
278 
279 }
280 
282 
284  e.getByLabel(inputTagGMT,gmtrc);
285 
286  std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
287  std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr = gmt_records.begin();
288  std::vector<L1MuGMTReadoutRecord>::const_iterator egmtrr = gmt_records.end();
289  for(; igmtrr!=egmtrr; igmtrr++) {
290 
291  std::vector<L1MuGMTExtendedCand> candsGMT = igmtrr->getGMTCands();
292  std::vector<L1MuGMTExtendedCand>::const_iterator candGMTIt = candsGMT.begin();
293  std::vector<L1MuGMTExtendedCand>::const_iterator candGMTEnd = candsGMT.end();
294 
295  for(; candGMTIt!=candGMTEnd; ++candGMTIt){
296  if(!candGMTIt->empty()) {
297  int quality = candGMTIt->quality();
298  if(candGMTIt->bx()==0 &&
299  (quality == 5 || quality == 7)){
300  return true;
301  }
302  }
303  }
304  }
305 
306  return false;
307 
308 }
309 
310 void DTTriggerEfficiencyTask::bookChamberHistos(const DTChamberId& dtCh, string histoType, string folder) {
311 
312  int wh = dtCh.wheel();
313  int sc = dtCh.sector();
314  int st = dtCh.station();
315  stringstream wheel; wheel << wh;
316  stringstream station; station << st;
317  stringstream sector; sector << sc;
318 
319  string hwFolder = topFolder(histoType);
320  string bookingFolder = hwFolder + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/" + folder;
321  string histoTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
322 
323  dbe->setCurrentFolder(bookingFolder);
324 
325  LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask")
326  << "[DTTriggerEfficiencyTask]: booking histos in " << bookingFolder << endl;
327 
328  float min, max;
329  int nbins;
330  trigGeomUtils->phiRange(dtCh,min,max,nbins,20);
331 
332  string histoName = histoType + "_TrackPosvsAngle" + histoTag;
333  string histoLabel = "Position vs Angle (phi)";
334  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngle"] =
335  dbe->book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
336 
337  histoName = histoType + "_TrackPosvsAngleAnyQual" + histoTag;
338  histoLabel = "Position vs Angle (phi) for any qual triggers";
339  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngleAnyQual"] =
340  dbe->book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
341 
342  histoName = histoType + "_TrackPosvsAngleCorr" + histoTag;
343  histoLabel = "Position vs Angle (phi) for correlated triggers";
344  (chamberHistos[dtCh.rawId()])[histoType + "_TrackPosvsAngleCorr"] =
345  dbe->book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
346 
347 }
348 
349 void DTTriggerEfficiencyTask::bookWheelHistos(int wheel,string hTag,string folder) {
350 
351  stringstream wh; wh << wheel;
352  string basedir;
353  if (hTag.find("Summary") != string::npos ) {
354  basedir = topFolder(hTag); //Book summary histo outside folder directory
355  } else {
356  basedir = topFolder(hTag) + folder + "/" ;
357  }
358 
359  dbe->setCurrentFolder(basedir);
360 
361  string hTagName = "_W" + wh.str();
362 
363  LogTrace("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask")
364  << "[DTTriggerEfficiencyTask]: booking histos in "<< basedir << endl;
365 
366  string hName = hTag + "_TrigEffDenum" + hTagName;
367  MonitorElement* me = dbe->book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
368 
369  me->setBinLabel(1,"MB1",2);
370  me->setBinLabel(2,"MB2",2);
371  me->setBinLabel(3,"MB3",2);
372  me->setBinLabel(4,"MB4",2);
373  me->setAxisTitle("Sector",1);
374 
375  wheelHistos[wheel][hTag + "_TrigEffDenum"] = me;
376 
377  hName = hTag + "_TrigEffNum" + hTagName;
378  me = dbe->book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
379 
380  me->setBinLabel(1,"MB1",2);
381  me->setBinLabel(2,"MB2",2);
382  me->setBinLabel(3,"MB3",2);
383  me->setBinLabel(4,"MB4",2);
384  me->setAxisTitle("Sector",1);
385 
386  wheelHistos[wheel][hTag + "_TrigEffNum"] = me;
387 
388  hName = hTag + "_TrigEffCorrNum" + hTagName;
389  me = dbe->book2D(hName.c_str(),hName.c_str(),12,1,13,4,1,5);
390 
391  me->setBinLabel(1,"MB1",2);
392  me->setBinLabel(2,"MB2",2);
393  me->setBinLabel(3,"MB3",2);
394  me->setBinLabel(4,"MB4",2);
395  me->setAxisTitle("Sector",1);
396 
397  wheelHistos[wheel][hTag + "_TrigEffCorrNum"] = me;
398 
399  return;
400 
401 }
402 
T getUntrackedParameter(std::string const &, T const &) const
void bookChamberHistos(const DTChamberId &dtCh, std::string histoTag, std::string folder="")
Book chamber 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)
#define min(a, b)
Definition: mlp_lapack.h:161
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:45
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
void beginRun(const edm::Run &run, const edm::EventSetup &context)
BeginRun.
const T & max(const T &a, const T &b)
const int mu
Definition: Constants.h:23
static const unsigned int BestInChamberByDR
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
#define LogTrace(id)
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
edm::ESHandle< DTGeometry > muonGeom
const T & get() const
Definition: EventSetup.h:55
virtual ~DTTriggerEfficiencyTask()
Destructor.
std::vector< DigiType >::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:63
void bookWheelHistos(int wheel, std::string histoTag, std::string folder="")
Book wheel granularity histograms.
std::pair< const_iterator, const_iterator > Range
static const int DT
Definition: MuonSubdetId.h:14
std::map< uint32_t, std::map< std::string, MonitorElement * > > chamberHistos
DTTriggerEfficiencyTask(const edm::ParameterSet &ps)
Constructor.
Definition: DDAxes.h:10
int station() const
Return the station number.
Definition: DTChamberId.h:53
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
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.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33