CMS 3D CMS Logo

DTCalibValidationFromMuons.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
17 
18 // Geometry
20 
21 // RecHit
25 
26 #include <iterator>
27 
28 using namespace edm;
29 using namespace std;
30 
32  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
33  parameters = pset;
34 
35  // the name of the 4D segments
37  consumes<DTRecSegment4DCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("segment4DLabel")));
38  // muon collection for matching 4D segments to muons
39  muonToken_ = consumes<reco::MuonCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("muonLabel")));
40  // the counter of segments not used to compute residuals
41  wrongSegment = 0;
42  // the counter of segments used to compute residuals
43  rightSegment = 0;
44 
45  nevent = 0;
46 }
47 
49  // FR the following was previously in the endJob
50 
51  LogVerbatim("DTCalibValidationFromMuons") << "Segments used to compute residuals: " << rightSegment;
52  LogVerbatim("DTCalibValidationFromMuons") << "Segments not used to compute residuals: " << wrongSegment;
53 }
54 
56  // get the geometry
57  dtGeom = &setup.getData(muonGeomToken_);
58 }
59 
61  ++nevent;
62  LogTrace("DTCalibValidationFromMuons") << "[DTCalibValidationFromMuons] Analyze #Run: " << event.id().run()
63  << " #Event: " << nevent;
64 
65  // RecHit mapping at Step 3 ---------------------------------
66  LogTrace("DTCalibValidationFromMuons") << " -- DTRecHit S3: begin analysis:";
67  // Get the 4D rechits from the event
69  event.getByToken(muonToken_, muonH);
70  const vector<reco::Muon> *muons = muonH.product();
71 
72  // Get the 4D rechits from the event
74  event.getByToken(segment4DToken_, segment4Ds);
75 
76  vector<const DTRecSegment4D *> selectedSegment4Ds;
77 
78  for (auto &imuon : *muons) {
79  for (const auto &ch : imuon.matches()) {
80  DetId chId(ch.id.rawId());
81  if (chId.det() != DetId::Muon)
82  continue;
83  if (chId.subdetId() != MuonSubdetId::DT)
84  continue;
85  if (imuon.pt() < 15)
86  continue;
87  if (!imuon.isGlobalMuon())
88  continue;
89 
90  int nsegs = ch.segmentMatches.size();
91  if (!nsegs)
92  continue;
93 
94  // get the DT segments that were used to construct the muon
95  DTChamberId matchId = ch.id();
96  DTRecSegment4DCollection::range segs = segment4Ds->get(matchId);
97  for (DTRecSegment4DCollection::const_iterator segment = segs.first; segment != segs.second; ++segment) {
98  LocalPoint posHit = segment->localPosition();
99  float dx = (posHit.x() ? posHit.x() - ch.x : 0);
100  float dy = (posHit.y() ? posHit.y() - ch.y : 0);
101  float dr = sqrt(dx * dx + dy * dy);
102  if (dr < 5)
103  selectedSegment4Ds.push_back(&(*segment));
104  }
105  }
106  }
107 
108  // Loop over all 4D segments
109  for (auto segment : selectedSegment4Ds) {
110  LogTrace("DTCalibValidationFromMuons") << "Anlysis on recHit at step 3";
111  compute(dtGeom, *segment);
112  }
113 }
114 
115 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
117  return fabs(hitPair.localPosition(DTEnums::Left).x() - hitPair.localPosition(DTEnums::Right).x()) / 2.;
118 }
119 
120 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
122  return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
123 }
124 
125 // Compute the position (cm) of a hits in a DTRecHit1DPair
127  const DTRecHit1DPair &hitPair, const DTLayer *layer, const DTChamber *chamber, float segmentPos, int sl) {
128  // Get the layer and the wire position
129  GlobalPoint hitPosGlob_right = layer->toGlobal(hitPair.localPosition(DTEnums::Right));
130  LocalPoint hitPosInChamber_right = chamber->toLocal(hitPosGlob_right);
131  GlobalPoint hitPosGlob_left = layer->toGlobal(hitPair.localPosition(DTEnums::Left));
132  LocalPoint hitPosInChamber_left = chamber->toLocal(hitPosGlob_left);
133 
134  float recHitPos = -1;
135  if (sl != 2) {
136  if (fabs(hitPosInChamber_left.x() - segmentPos) < fabs(hitPosInChamber_right.x() - segmentPos))
137  recHitPos = hitPosInChamber_left.x();
138  else
139  recHitPos = hitPosInChamber_right.x();
140  } else {
141  if (fabs(hitPosInChamber_left.y() - segmentPos) < fabs(hitPosInChamber_right.y() - segmentPos))
142  recHitPos = hitPosInChamber_left.y();
143  else
144  recHitPos = hitPosInChamber_right.y();
145  }
146 
147  return recHitPos;
148 }
149 
150 // Compute the position (cm) of a hits in a DTRecHit1D
152  const DTRecHit1D &recHit, const DTLayer *layer, const DTChamber *chamber, float segmentPos, int sl) {
153  // Get the layer and the wire position
154  GlobalPoint recHitPosGlob = layer->toGlobal(recHit.localPosition());
155  LocalPoint recHitPosInChamber = chamber->toLocal(recHitPosGlob);
156 
157  float recHitPos = -1;
158  if (sl != 2)
159  recHitPos = recHitPosInChamber.x();
160  else
161  recHitPos = recHitPosInChamber.y();
162 
163  return recHitPos;
164 }
165 
166 // Compute the residuals
167 void DTCalibValidationFromMuons::compute(const DTGeometry *dtGeom, const DTRecSegment4D &segment) {
168  bool computeResidual = true;
169 
170  // Get all 1D RecHits at step 3 within the 4D segment
171  vector<DTRecHit1D> recHits1D_S3;
172 
173  // Get 1D RecHits at Step 3 and select only events with
174  // >=7 hits in phi and 4 hits in theta (if any)
175  const DTChamberRecSegment2D *phiSeg = segment.phiSegment();
176  if (phiSeg) {
177  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
178  if (phiRecHits.size() < 7) {
179  LogTrace("DTCalibValidationFromMuons") << "[DTCalibValidationFromMuons] Phi segments has: " << phiRecHits.size()
180  << " hits, skipping"; // FIXME: info output
181  computeResidual = false;
182  }
183  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
184  }
185  if (!phiSeg) {
186  LogTrace("DTCalibValidationFromMuons") << " [DTCalibValidationFromMuons] 4D segment has no phi segment! ";
187  computeResidual = false;
188  }
189 
190  if (segment.dimension() == 4) {
191  const DTSLRecSegment2D *zSeg = segment.zSegment();
192  if (zSeg) {
193  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
194  if (zRecHits.size() != 4) {
195  LogTrace("DTCalibValidationFromMuons") << "[DTCalibValidationFromMuons] Theta segments has: " << zRecHits.size()
196  << " hits, skipping"; // FIXME: info output
197  computeResidual = false;
198  }
199  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
200  }
201  if (!zSeg) {
202  LogTrace("DTCalibValidationFromMuons") << " [DTCalibValidationFromMuons] 4D segment has not the z segment! ";
203  computeResidual = false;
204  }
205  }
206 
207  if (!computeResidual)
208  ++wrongSegment;
209 
210  if (computeResidual) {
211  ++rightSegment;
212 
213  // Loop over 1D RecHit inside 4D segment
214  for (vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin(); recHit1D != recHits1D_S3.end();
215  ++recHit1D) {
216  const DTWireId wireId = (*recHit1D).wireId();
217 
218  // Get the layer and the wire position
219  const DTLayer *layer = dtGeom->layer(wireId);
220  float wireX = layer->specificTopology().wirePosition(wireId.wire());
221 
222  // Extrapolate the segment to the z of the wire
223  // Get wire position in chamber RF
224  // (y and z must be those of the hit to be coherent in the transf. of RF
225  // in case of rotations of the layer alignment)
226  LocalPoint wirePosInLay(wireX, (*recHit1D).localPosition().y(), (*recHit1D).localPosition().z());
227  GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
228  const DTChamber *chamber = dtGeom->chamber((*recHit1D).wireId().layerId().chamberId());
229  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
230 
231  // Segment position at Wire z in chamber local frame
232  LocalPoint segPosAtZWire = segment.localPosition() + segment.localDirection() * wirePosInChamber.z() /
233  cos(segment.localDirection().theta());
234 
235  // Compute the distance of the segment from the wire
236  int sl = wireId.superlayer();
237  float SegmDistance = -1;
238  if (sl == 1 || sl == 3) {
239  // RPhi SL
240  SegmDistance = fabs(wirePosInChamber.x() - segPosAtZWire.x());
241  LogTrace("DTCalibValidationFromMuons") << "SegmDistance: " << SegmDistance;
242  } else if (sl == 2) {
243  // RZ SL
244  SegmDistance = fabs(segPosAtZWire.y() - wirePosInChamber.y());
245  LogTrace("DTCalibValidationFromMuons") << "SegmDistance: " << SegmDistance;
246  }
247 
248  if (SegmDistance > 2.1)
249  LogTrace("DTCalibValidationFromMuons") << " Warning: dist segment-wire: " << SegmDistance;
250 
251  // Compute the distance of the recHit from the wire
252  float recHitWireDist = recHitDistFromWire(*recHit1D, layer);
253  LogTrace("DTCalibValidationFromMuons") << "recHitWireDist: " << recHitWireDist;
254 
255  // Compute the residuals
256  float residualOnDistance = recHitWireDist - SegmDistance;
257  LogTrace("DTCalibValidationFromMuons") << "WireId: " << wireId << " ResidualOnDistance: " << residualOnDistance;
258  float residualOnPosition = -1;
259  float recHitPos = -1;
260  if (sl == 1 || sl == 3) {
261  recHitPos = recHitPosition(*recHit1D, layer, chamber, segPosAtZWire.x(), sl);
262  residualOnPosition = recHitPos - segPosAtZWire.x();
263  } else {
264  recHitPos = recHitPosition(*recHit1D, layer, chamber, segPosAtZWire.y(), sl);
265  residualOnPosition = recHitPos - segPosAtZWire.y();
266  }
267  LogTrace("DTCalibValidationFromMuons") << "WireId: " << wireId << " ResidualOnPosition: " << residualOnPosition;
268 
269  // Fill the histos
270  if (sl == 1 || sl == 3)
271  fillHistos(wireId.superlayerId(),
272  SegmDistance,
273  residualOnDistance,
274  (wirePosInChamber.x() - segPosAtZWire.x()),
275  residualOnPosition,
276  3);
277  else
278  fillHistos(wireId.superlayerId(),
279  SegmDistance,
280  residualOnDistance,
281  (wirePosInChamber.y() - segPosAtZWire.y()),
282  residualOnPosition,
283  3);
284  }
285  }
286 }
287 
289  edm::Run const &iRun,
290  edm::EventSetup const &iSetup) {
291  // FR substitute the DQMStore instance by ibooker
292  ibooker.setCurrentFolder("DT/DTCalibValidationFromMuons");
293 
294  DTSuperLayerId slId;
295 
296  // Loop over all the chambers
297  vector<const DTChamber *>::const_iterator ch_it = dtGeom->chambers().begin();
298  vector<const DTChamber *>::const_iterator ch_end = dtGeom->chambers().end();
299  for (; ch_it != ch_end; ++ch_it) {
300  vector<const DTSuperLayer *>::const_iterator sl_it = (*ch_it)->superLayers().begin();
301  vector<const DTSuperLayer *>::const_iterator sl_end = (*ch_it)->superLayers().end();
302  // Loop over the SLs
303  for (; sl_it != sl_end; ++sl_it) {
304  slId = (*sl_it)->id();
305 
306  // TODO! fix this is a leftover
307  int firstStep = 3;
308  // Loop over the 3 steps
309  for (int step = firstStep; step <= 3; ++step) {
310  LogTrace("DTCalibValidationFromMuons") << " Booking histos for SL: " << slId;
311 
312  // Compose the chamber name
313  stringstream wheel;
314  wheel << slId.wheel();
315  stringstream station;
316  station << slId.station();
317  stringstream sector;
318  sector << slId.sector();
319  stringstream superLayer;
320  superLayer << slId.superlayer();
321  // Define the step
322  stringstream Step;
323  Step << step;
324 
325  string slHistoName = "_STEP" + Step.str() + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() +
326  "_SL" + superLayer.str();
327 
328  ibooker.setCurrentFolder("DT/DTCalibValidationFromMuons/Wheel" + wheel.str() + "/Station" + station.str() +
329  "/Sector" + sector.str());
330  // Create the monitor elements
331  vector<MonitorElement *> histos;
332  // Note the order matters
333  histos.push_back(ibooker.book1D(
334  "hResDist" + slHistoName, "Residuals on the distance from wire (rec_hit - segm_extr) (cm)", 200, -0.4, 0.4));
335  histos.push_back(ibooker.book2D("hResDistVsDist" + slHistoName,
336  "Residuals on the distance (cm) from wire (rec_hit "
337  "- segm_extr) vs distance (cm)",
338  100,
339  0,
340  2.5,
341  200,
342  -0.4,
343  0.4));
344 
345  histosPerSL[make_pair(slId, step)] = histos;
346  }
347  }
348  }
349 }
350 
351 // Fill a set of histograms for a given SL
353  DTSuperLayerId slId, float distance, float residualOnDistance, float position, float residualOnPosition, int step) {
354  // FIXME: optimization of the number of searches
355  vector<MonitorElement *> histos = histosPerSL[make_pair(slId, step)];
356  histos[0]->Fill(residualOnDistance);
357  histos[1]->Fill(distance, residualOnDistance);
358 }
359 
360 // Local Variables:
361 // show-trailing-whitespace: t
362 // truncate-lines: t
363 // End:
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:45
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
int wire() const
Return the wire number.
Definition: DTWireId.h:45
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
T const * product() const
Definition: Handle.h:70
LocalVector localDirection() const override
Local direction in Chamber frame.
void fillHistos(DTSuperLayerId slId, float distance, float residualOnDistance, float position, float residualOnPosition, int step)
float recHitPosition(const DTRecHit1DPair &hitPair, const DTLayer *layer, const DTChamber *chamber, float segmPos, int sl)
DTCalibValidationFromMuons(const edm::ParameterSet &pset)
Constructor.
LocalPoint localPosition() const override
int dimension() const override
Dimension (in parameter space)
edm::EDGetTokenT< reco::MuonCollection > muonToken_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
LocalPoint localPosition() const override
Local position in Chamber frame.
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
BeginRun.
#define LogTrace(id)
void compute(const DTGeometry *dtGeom, const DTRecSegment4D &segment)
T getUntrackedParameter(std::string const &, T const &) const
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
float recHitDistFromWire(const DTRecHit1DPair &hitPair, const DTLayer *layer)
T sqrt(T t)
Definition: SSEVec.h:23
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Transition
Definition: Transition.h:12
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DetId.h:17
std::map< std::pair< DTSuperLayerId, int >, std::vector< MonitorElement * > > histosPerSL
int superlayer() const
Return the superlayer number (deprecated method name)
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
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:221
~DTCalibValidationFromMuons() override
Destructor.
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
int sector() const
Definition: DTChamberId.h:52
static int position[264][3]
Definition: ReadPGInfo.cc:289
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:48
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
step
Definition: StallMonitor.cc:83
static constexpr int DT
Definition: MuonSubdetId.h:11
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::EDGetTokenT< DTRecSegment4DCollection > segment4DToken_
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
Definition: event.py:1
Definition: Run.h:45
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96