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