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
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:
DTLocalTriggerLutTask::trigBestOut
DTArr3Digi trigBestOut
Definition: DTLocalTriggerLutTask.h:99
DTLocalTriggerLutTask::searchTMBestIn
void searchTMBestIn(std::vector< L1MuDTChambPhDigi > const *trigs)
Find best (highest qual) TM trigger segments.
Definition: DTLocalTriggerLutTask.cc:274
DTRecSegment4D
Definition: DTRecSegment4D.h:23
DTLocalTriggerLutTask::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
Definition: DTLocalTriggerLutTask.cc:176
DTTrigGeomUtils.h
DOFs::dof
dof
Definition: AlignPCLThresholdsWriter.cc:37
edm::ESInputTag
Definition: ESInputTag.h:87
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:157
DTLocalTriggerLutTask::chHistos
std::map< uint32_t, std::map< std::string, MonitorElement * > > chHistos
Definition: DTLocalTriggerLutTask.h:107
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:102
edm
HLT enums.
Definition: AlignableModifier.h:19
DTLocalTriggerLutTask::wheelArrayShift
const int wheelArrayShift
Definition: DTLocalTriggerLutTask.h:73
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DTLocalTriggerLutTask::rangePhi
double rangePhi
Definition: DTLocalTriggerLutTask.h:86
DTLocalTriggerLutTask::detailedAnalysis
bool detailedAnalysis
Definition: DTLocalTriggerLutTask.h:89
DTLocalTriggerLutTask::nPhibBins
int nPhibBins
Definition: DTLocalTriggerLutTask.h:85
DTLocalTriggerLutTask::trigBestIn
DTArr3Digi trigBestIn
Definition: DTLocalTriggerLutTask.h:98
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
visDQMUpload.context
context
Definition: visDQMUpload.py:37
DTLocalTriggerLutTask::nPhiBins
int nPhiBins
Definition: DTLocalTriggerLutTask.h:85
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:88
DTLocalTriggerLutTask.h
DTLocalTriggerLutTask::trigQualBestIn
DTArr3int trigQualBestIn
Definition: DTLocalTriggerLutTask.h:96
DTLayer.h
DTGeometry.h
DTLocalTriggerLutTask::trigQualBestOut
DTArr3int trigQualBestOut
Definition: DTLocalTriggerLutTask.h:97
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
DTLocalTriggerLutTask::trigGeomUtils
DTTrigGeomUtils * trigGeomUtils
Definition: DTLocalTriggerLutTask.h:105
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Pi.h
DTLocalTriggerLutTask::searchTMBestOut
void searchTMBestOut(std::vector< L1MuDTChambPhDigi > const *trigs)
Definition: DTLocalTriggerLutTask.cc:300
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:83
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:90
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:92
DTLocalTriggerLutTask::bookHistos
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chId)
Book histos.
Definition: DTLocalTriggerLutTask.cc:79
DTLocalTriggerLutTask::muonGeom
const DTGeometry * muonGeom
Definition: DTLocalTriggerLutTask.h:104
edm::EventSetup
Definition: EventSetup.h:58
DTLocalTriggerLutTask::seg_Token_
edm::EDGetTokenT< DTRecSegment4DCollection > seg_Token_
Definition: DTLocalTriggerLutTask.h:94
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fileinputsource_cfi.sec
sec
Definition: fileinputsource_cfi.py:94
DTLocalTriggerLutTask::topFolder
std::string & topFolder()
Get the top folder.
Definition: DTLocalTriggerLutTask.h:77
DTLocalTriggerLutTask::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bookHistograms
Definition: DTLocalTriggerLutTask.cc:145
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::muonGeomToken_
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
Definition: DTLocalTriggerLutTask.h:103
DTTrigGeomUtils
Definition: DTTrigGeomUtils.h:21
edm::Transition::BeginRun
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:86
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:93
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
DTLocalTriggerLutTask::DTLocalTriggerLutTask
DTLocalTriggerLutTask(const edm::ParameterSet &ps)
Constructor.
Definition: DTLocalTriggerLutTask.cc:33
DTLocalTriggerLutTask::nLumis
int nLumis
Definition: DTLocalTriggerLutTask.h:84
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
DTTopology.h
DTLocalTriggerLutTask::dqmBeginRun
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
Definition: DTLocalTriggerLutTask.cc:73
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:65