CMS 3D CMS Logo

DTLocalTriggerLutTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTLocalLutTriggerTask.cc
3  *
4  * \author D. Fasanella - INFN Bologna
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 <math.h>
30 
31 
32 using namespace edm;
33 using namespace std;
34 
36 
37  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Constructor"<<endl;
38 
39  tm_TokenIn_ = consumes<L1MuDTChambPhContainer>(
40  ps.getUntrackedParameter<InputTag>("inputTagTMin"));
41  tm_TokenOut_ = consumes<L1MuDTChambPhContainer>(
42  ps.getUntrackedParameter<InputTag>("inputTagTMout"));
43  seg_Token_ = consumes<DTRecSegment4DCollection>(
44  ps.getUntrackedParameter<InputTag>("inputTagSEG"));
45 
46  overUnderIn = ps.getUntrackedParameter<bool>("rebinOutFlowsInGraph");
47  detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis");
48  theGeomLabel = ps.getUntrackedParameter<string>("geomLabel");
49 
50  if (detailedAnalysis){
51  nPhiBins = 401;
52  rangePhi = 10.025;
53  nPhibBins = 401;
54  rangePhiB = 10.025;
55  } else {
56  nPhiBins = 51;
57  rangePhi = 5.1;
58  nPhibBins = 51;
59  rangePhiB = 10.2;
60  }
61 
62  baseFolder = "DT/03-LocalTrigger-TM/";
63  parameters = ps;
64 
65  nEvents = 0;
66  nLumis = 0;
67 
68 }
69 
70 
72 
73  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: analyzed " << nEvents << " events" << endl;
74  if (trigGeomUtils) { delete trigGeomUtils; }
75 
76 }
77 
79 
80  // Get the geometry
83 }
84 
86 
87  stringstream wheel; wheel << chId.wheel();
88  stringstream sector; sector << chId.sector();
89  stringstream station; station << chId.station();
90 
91  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() +
92  "/Station" + station.str() + "/Segment");
93 
94  string chTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
95  std::map<std::string, MonitorElement*> &chambMap = chHistos[chId.rawId()];
96 
97  string hName = "TM_PhiResidualIn";
98 
99  chambMap[hName] = ibooker.book1D(hName+chTag,"Trigger local position In - Segment local position (correlated triggers)",nPhiBins,-rangePhi,rangePhi);
100 
101  hName = "TM_PhiResidualOut";
102 
103  chambMap[hName] = ibooker.book1D(hName+chTag,"Trigger local position Out - Segment local position (correlated triggers)",nPhiBins,-rangePhi,rangePhi);
104 
105  hName = "TM_PhibResidualIn";
106 
107  chambMap[hName] = ibooker.book1D(hName+chTag,"Trigger local direction In - Segment local direction (correlated triggers)",nPhibBins,-rangePhiB,rangePhiB);
108 
109  hName = "TM_PhibResidualOut";
110 
111  chambMap[hName] = ibooker.book1D(hName+chTag,"Trigger local direction Out - Segment local direction (correlated triggers)",nPhibBins,-rangePhiB,rangePhiB);
112 
113 
114  if (detailedAnalysis) {
115 
116  hName = "TM_PhitkvsPhitrig";
117 
118  chambMap[hName] = ibooker.book2D(hName+chTag,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
119  hName = "TM_PhibtkvsPhibtrig";
120 
121  chambMap[hName] =ibooker.book2D(hName+chTag,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
122  hName = "TM_PhibResidualvsTkPos";
123 
124  chambMap[hName] =ibooker.book2D(hName+chTag,"Local direction residual vs Segment Position",100,-500.,500.,200,-10.,10.);
125  hName = "TM_PhiResidualvsTkPos";
126 
127  chambMap[hName] =ibooker.book2D(hName+chTag,"Local Position residual vs Segment Position",100,-500.,500.,200,-10.,10.);
128 
129  }
130 
131 }
132 
134  edm::Run const & run,
135  edm::EventSetup const & context) {
136 
137  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: bookHistograms" << endl;
138 
139  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
140  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
141 
142  for (; chambIt!=chambEnd; ++chambIt)
143  bookHistos(ibooker,(*chambIt)->id());
144 
145 }
146 
147 
149 
150  nLumis++;
151  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Begin of LS transition" << endl;
152 
153  if(nLumis%parameters.getUntrackedParameter<int>("ResetCycle") == 0) {
154 
155  LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Cleaning histos" << endl;
156  map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambIt = chHistos.begin();
157  map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambEnd = chHistos.end();
158 
159  for(; chambIt!=chambEnd; ++chambIt) {
160  map<string, MonitorElement*> ::const_iterator histoIt = chambIt->second.begin();
161  map<string, MonitorElement*> ::const_iterator histoEnd = chambIt->second.end();
162  for(; histoIt!=histoEnd; ++ histoIt) {
163  histoIt->second->Reset();
164  }
165  }
166 
167  }
168 
169 }
170 
171 
172 
174 
175  nEvents++;
176 
178  e.getByToken(tm_TokenIn_, trigHandleIn);
180  e.getByToken(tm_TokenOut_, trigHandleOut);
181 
182  vector<L1MuDTChambPhDigi> const* trigsIn = trigHandleIn->getContainer();
183  searchTMBestIn(trigsIn);
184  vector<L1MuDTChambPhDigi> const* trigsOut = trigHandleOut->getContainer();
185  searchTMBestOut(trigsOut);
186 
188  e.getByToken(seg_Token_, segments4D);
189  DTRecSegment4DCollection::id_iterator chamberId;
190 
191  // Preliminary loop finds best 4D Segment and high quality ones
192  vector<const DTRecSegment4D*> best4DSegments;
193 
194  for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
195 
196  DTRecSegment4DCollection::range rangeInCh = segments4D->get(*chamberId);
197  DTRecSegment4DCollection::const_iterator trackIt = rangeInCh.first;
198  DTRecSegment4DCollection::const_iterator trackEnd = rangeInCh.second;
199 
200  const DTRecSegment4D* tmpBest = 0;
201  int tmpdof = 0;
202  int dof = 0;
203 
204  for (; trackIt!=trackEnd; ++trackIt){
205 
206  if(trackIt->hasPhi()) {
207  dof = trackIt->phiSegment()->degreesOfFreedom();
208  if (dof>tmpdof) {
209  tmpBest = &(*trackIt);
210  tmpdof = dof;
211  }
212  }
213 
214  }
215 
216  if (tmpBest) best4DSegments.push_back(tmpBest);
217 
218  }
219 
220  vector<const DTRecSegment4D*>::const_iterator bestTrackIt = best4DSegments.begin();
221  vector<const DTRecSegment4D*>::const_iterator bestTrackEnd = best4DSegments.end();
222 
223  for (; bestTrackIt!=bestTrackEnd; ++bestTrackIt) {
224 
225  if((*bestTrackIt)->hasPhi()) {
226 
227  DTChamberId chId = (*bestTrackIt)->chamberId();
228  int nHitsPhi = (*bestTrackIt)->phiSegment()->degreesOfFreedom()+2;
229 
230  int wheel = chId.wheel();
231  int station = chId.station();
232  int scsector = 0;
233  float trackPosPhi, trackPosEta, trackDirPhi, trackDirEta;
234  trigGeomUtils->computeSCCoordinates((*bestTrackIt),scsector,trackPosPhi,trackDirPhi,trackPosEta,trackDirEta);
235 
236  map<string, MonitorElement*> &chMap = chHistos[chId.rawId()];
237  // In part
238  if (trigQualBestIn[wheel+3][station][scsector] > 3 && // residuals only for correlate triggers
239  trigQualBestIn[wheel+3][station][scsector] < 7 &&
240  nHitsPhi>=7 ) {
241 
242  float trigPos = trigGeomUtils->trigPos(trigBestIn[wheel+3][station][scsector]);
243  float trigDir = trigGeomUtils->trigDir(trigBestIn[wheel+3][station][scsector]);
244  trigGeomUtils->trigToSeg(station,trigPos,trackDirPhi);
245 
246  double deltaPos = trigPos-trackPosPhi;
247  deltaPos = overUnderIn ? max(min(deltaPos,rangePhi-0.01),-rangePhi+0.01) : deltaPos;
248  double deltaDir = trigDir-trackDirPhi;
249  deltaDir = overUnderIn ? max(min(deltaDir,rangePhiB-0.01),-rangePhiB+0.01) : deltaDir;
250  chMap.find("TM_PhiResidualIn")->second->Fill(deltaPos);
251  chMap.find("TM_PhibResidualIn")->second->Fill(deltaDir);
252 
253  if (detailedAnalysis){
254  chMap.find("TM_PhitkvsPhitrig")->second->Fill(trigPos,trackPosPhi);
255  chMap.find("TM_PhibtkvsPhibtrig")->second->Fill(trigDir,trackDirPhi);
256  chMap.find("TM_PhibResidualvsTkPos")->second->Fill(trackPosPhi,trigDir-trackDirPhi);
257  chMap.find("TM_PhiResidualvsTkPos")->second->Fill(trackPosPhi,trigPos-trackPosPhi);
258  }
259  }
260 
261  // Out part
262  if (trigQualBestOut[wheel+3][station][scsector] > 3 && // residuals only for correlate triggers
263  trigQualBestOut[wheel+3][station][scsector] < 7 &&
264  nHitsPhi>=7 ) {
265 
266  float trigPos = trigGeomUtils->trigPos(trigBestOut[wheel+3][station][scsector]);
267  float trigDir = trigGeomUtils->trigDir(trigBestOut[wheel+3][station][scsector]);
268  trigGeomUtils->trigToSeg(station,trigPos,trackDirPhi);
269 
270  double deltaPos = trigPos-trackPosPhi;
271  deltaPos = overUnderIn ? max(min(deltaPos,rangePhi-0.01),-rangePhi+0.01) : deltaPos;
272  double deltaDir = trigDir-trackDirPhi;
273  deltaDir = overUnderIn ? max(min(deltaDir,rangePhiB-0.01),-rangePhiB+0.01) : deltaDir;
274  chMap.find("TM_PhiResidualOut")->second->Fill(deltaPos);
275  chMap.find("TM_PhibResidualOut")->second->Fill(deltaDir);
276  }
277 
278  }
279  }
280 }
281 
282 void DTLocalTriggerLutTask::searchTMBestIn( std::vector<L1MuDTChambPhDigi> const* trigs) {
283 
284  string histoType ;
285  string histoTag ;
286 
287  // define best quality trigger segment
288  // start from 1 and zero is kept empty
289  for (int st=0;st<=4;++st)
290  for (int wh=0;wh<=5;++wh)
291  for (int sec=0;sec<=12;++sec)
292  trigQualBestIn[wh][st][sec] = -1;
293 
294  vector<L1MuDTChambPhDigi>::const_iterator trigIt = trigs->begin();
295  vector<L1MuDTChambPhDigi>::const_iterator trigEnd = trigs->end();
296  for(; trigIt!=trigEnd; ++trigIt) {
297 
298  int wh = trigIt->whNum();
299  int sec = trigIt->scNum() + 1; // DTTF -> DT sector range transform
300  int st = trigIt->stNum();
301  int qual = trigIt->code();
302 
303  if(qual>trigQualBestIn[wh+wheelArrayShift][st][sec] && qual<7) {
304  trigQualBestIn[wh+wheelArrayShift][st][sec]=qual;
305  trigBestIn[wh+wheelArrayShift][st][sec] = &(*trigIt);
306  }
307 
308  }
309 
310 }
311 
312 
313 void DTLocalTriggerLutTask::searchTMBestOut( std::vector<L1MuDTChambPhDigi> const* trigs) {
314 
315  string histoType ;
316  string histoTag ;
317 
318 // define best quality trigger segment
319 // // start from 1 and zero is kept empty
320  for (int st=0;st<=4;++st)
321  for (int wh=0;wh<=5;++wh)
322  for (int sec=0;sec<=12;++sec)
323  trigQualBestOut[wh][st][sec] = -1;
324 
325  vector<L1MuDTChambPhDigi>::const_iterator trigIt = trigs->begin();
326  vector<L1MuDTChambPhDigi>::const_iterator trigEnd = trigs->end();
327  for(; trigIt!=trigEnd; ++trigIt) {
328 
329  int wh = trigIt->whNum();
330  int sec = trigIt->scNum() + 1; // DTTF -> DT sector range transform
331  int st = trigIt->stNum();
332  int qual = trigIt->code();
333 
334  if(qual>trigQualBestOut[wh+wheelArrayShift][st][sec] && qual<7) {
335  trigQualBestOut[wh+wheelArrayShift][st][sec]=qual;
336  trigBestOut[wh+wheelArrayShift][st][sec] = &(*trigIt);
337  }
338 
339  }
340 
341 }
342 
343 // Local Variables:
344 // show-trailing-whitespace: t
345 // truncate-lines: t
346 // End:
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chId)
Book histos.
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
To reset the MEs.
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:85
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
void searchTMBestOut(std::vector< L1MuDTChambPhDigi > const *trigs)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::string & topFolder()
Get the top folder.
float trigDir(const L1MuDTChambPhDigi *trig)
Return local direction (trigger RF) for a given trigger primitive.
DTLocalTriggerLutTask(const edm::ParameterSet &ps)
Constructor.
edm::ParameterSet parameters
edm::ESHandle< DTGeometry > muonGeom
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual ~DTLocalTriggerLutTask()
Destructor.
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_TokenOut_
void trigToSeg(int st, float &x, float dir)
Compute Trigger x coordinate in chamber RF.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void searchTMBestIn(std::vector< L1MuDTChambPhDigi > const *trigs)
Find best (highest qual) TM trigger segments.
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_TokenIn_
T min(T a, T b)
Definition: MathUtil.h:58
#define LogTrace(id)
std::map< uint32_t, std::map< std::string, MonitorElement * > > chHistos
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
DTTrigGeomUtils * trigGeomUtils
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bookHistograms
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
Phi_Container const * getContainer() const
HLT enums.
int sector() const
Definition: DTChamberId.h:61
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
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:42