CMS 3D CMS Logo

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