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:
DTLocalTriggerLutTask::trigBestOut
DTArr3Digi trigBestOut
Definition: DTLocalTriggerLutTask.h:98
DTLocalTriggerLutTask::searchTMBestIn
void searchTMBestIn(std::vector< L1MuDTChambPhDigi > const *trigs)
Find best (highest qual) TM trigger segments.
Definition: DTLocalTriggerLutTask.cc:273
DTRecSegment4D
Definition: DTRecSegment4D.h:23
DTLocalTriggerLutTask::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
Definition: DTLocalTriggerLutTask.cc:175
DTTrigGeomUtils.h
DOFs::dof
dof
Definition: AlignPCLThresholdsWriter.cc:37
DTTrigGeomUtils::trigDir
float trigDir(const L1MuDTChambPhDigi *trig)
Return local direction (trigger RF) for a given trigger primitive.
Definition: DTTrigGeomUtils.cc:138
DTLocalTriggerLutTask::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
To reset the MEs.
Definition: DTLocalTriggerLutTask.cc:156
DTLocalTriggerLutTask::chHistos
std::map< uint32_t, std::map< std::string, MonitorElement * > > chHistos
Definition: DTLocalTriggerLutTask.h:106
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
min
T min(T a, T b)
Definition: MathUtil.h:58
relativeConstraints.station
station
Definition: relativeConstraints.py:67
DTLocalTriggerLutTask::parameters
edm::ParameterSet parameters
Definition: DTLocalTriggerLutTask.h:101
edm
HLT enums.
Definition: AlignableModifier.h:19
DTLocalTriggerLutTask::wheelArrayShift
const int wheelArrayShift
Definition: DTLocalTriggerLutTask.h:72
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DTLocalTriggerLutTask::rangePhi
double rangePhi
Definition: DTLocalTriggerLutTask.h:85
DTLocalTriggerLutTask::detailedAnalysis
bool detailedAnalysis
Definition: DTLocalTriggerLutTask.h:88
DTLocalTriggerLutTask::nPhibBins
int nPhibBins
Definition: DTLocalTriggerLutTask.h:84
DTLocalTriggerLutTask::trigBestIn
DTArr3Digi trigBestIn
Definition: DTLocalTriggerLutTask.h:97
DTTrigGeomUtils::trigPos
float trigPos(const L1MuDTChambPhDigi *trig)
Return local position (trigger RF) for a given trigger primitive.
Definition: DTTrigGeomUtils.cc:98
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle< L1MuDTChambPhContainer >
edm::RangeMap::id_iterator
identifier iterator
Definition: RangeMap.h:130
L1MuDTChambPhContainer::getContainer
Phi_Container const * getContainer() const
Definition: L1MuDTChambPhContainer.cc:41
DTLocalTriggerLutTask::nPhiBins
int nPhiBins
Definition: DTLocalTriggerLutTask.h:84
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DTLocalTriggerLutTask::muonGeom
edm::ESHandle< DTGeometry > muonGeom
Definition: DTLocalTriggerLutTask.h:102
DTGeometry::chambers
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
DTLocalTriggerLutTask::baseFolder
std::string baseFolder
Definition: DTLocalTriggerLutTask.h:87
DTLocalTriggerLutTask.h
DTLocalTriggerLutTask::trigQualBestIn
DTArr3int trigQualBestIn
Definition: DTLocalTriggerLutTask.h:95
DTLayer.h
DTGeometry.h
DTLocalTriggerLutTask::trigQualBestOut
DTArr3int trigQualBestOut
Definition: DTLocalTriggerLutTask.h:96
edm::ParameterSet
Definition: ParameterSet.h:47
DTLocalTriggerLutTask::trigGeomUtils
DTTrigGeomUtils * trigGeomUtils
Definition: DTLocalTriggerLutTask.h:104
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Pi.h
DTLocalTriggerLutTask::searchTMBestOut
void searchTMBestOut(std::vector< L1MuDTChambPhDigi > const *trigs)
Definition: DTLocalTriggerLutTask.cc:299
DTTrigGeomUtils::trigToSeg
void trigToSeg(int st, float &x, float dir)
Compute Trigger x coordinate in chamber RF.
Definition: DTTrigGeomUtils.h:45
DTLocalTriggerLutTask::nEvents
int nEvents
Definition: DTLocalTriggerLutTask.h:82
edm::RangeMap::const_iterator
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
dtResolutionTest_cfi.histoTag
histoTag
Definition: dtResolutionTest_cfi.py:21
DTLocalTriggerLutTask::overUnderIn
bool overUnderIn
Definition: DTLocalTriggerLutTask.h:89
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
DTTrigGeomUtils::computeSCCoordinates
void computeSCCoordinates(const DTRecSegment4D *track, int &scsec, float &x, float &xdir, float &y, float &ydir)
Compute track coordinates with SC sector numbering.
Definition: DTTrigGeomUtils.cc:52
DTLocalTriggerLutTask::tm_TokenIn_
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_TokenIn_
Definition: DTLocalTriggerLutTask.h:91
DTLocalTriggerLutTask::bookHistos
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chId)
Book histos.
Definition: DTLocalTriggerLutTask.cc:78
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
DTLocalTriggerLutTask::seg_Token_
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
Definition: DTLocalTriggerLutTask.h:93
get
#define get
fileinputsource_cfi.sec
sec
Definition: fileinputsource_cfi.py:87
DTLocalTriggerLutTask::topFolder
std::string & topFolder()
Get the top folder.
Definition: DTLocalTriggerLutTask.h:76
DTLocalTriggerLutTask::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bookHistograms
Definition: DTLocalTriggerLutTask.cc:144
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
edm::RangeMap::range
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DTLocalTriggerLutTask::theGeomLabel
std::string theGeomLabel
Definition: DTLocalTriggerLutTask.h:103
DTTrigGeomUtils
Definition: DTTrigGeomUtils.h:21
dqm::implementation::IBooker::book2D
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
DTLocalTriggerLutTask::rangePhiB
double rangePhiB
Definition: DTLocalTriggerLutTask.h:85
EventSetup.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
DTChamberId
Definition: DTChamberId.h:14
DTLocalTriggerLutTask::tm_TokenOut_
edm::EDGetTokenT< L1MuDTChambPhContainer > tm_TokenOut_
Definition: DTLocalTriggerLutTask.h:92
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
DTLocalTriggerLutTask::DTLocalTriggerLutTask
DTLocalTriggerLutTask(const edm::ParameterSet &ps)
Constructor.
Definition: DTLocalTriggerLutTask.cc:34
DTLocalTriggerLutTask::nLumis
int nLumis
Definition: DTLocalTriggerLutTask.h:83
MuonGeometryRecord.h
edm::Event
Definition: Event.h:73
DTTopology.h
DTLocalTriggerLutTask::dqmBeginRun
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
Definition: DTLocalTriggerLutTask.cc:72
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
edm::InputTag
Definition: InputTag.h:15
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
DTLocalTriggerLutTask::~DTLocalTriggerLutTask
~DTLocalTriggerLutTask() override
Destructor.
Definition: DTLocalTriggerLutTask.cc:64