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