CMS 3D CMS Logo

DTRecHitQuality.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Cerminara - INFN Torino
5  */
6 
7 #include <iostream>
8 #include <map>
9 
16 
17 #include "DTRecHitQuality.h"
18 #include "Histograms.h"
19 
20 using namespace std;
21 using namespace edm;
22 
23 namespace dtrechit {
24  struct Histograms {
25  std::unique_ptr<HRes1DHit> hRes_S1RPhi; // RecHits, 1. step, RPh
26  std::unique_ptr<HRes1DHit> hRes_S2RPhi; // RecHits, 2. step, RPhi
27  std::unique_ptr<HRes1DHit> hRes_S3RPhi; // RecHits, 3. step, RPhi
28  std::unique_ptr<HRes1DHit> hRes_S1RZ; // RecHits, 1. step, RZ
29  std::unique_ptr<HRes1DHit> hRes_S2RZ; // RecHits, 2. step, RZ
30  std::unique_ptr<HRes1DHit> hRes_S3RZ; // RecHits, 3. step, RZ
31  std::unique_ptr<HRes1DHit> hRes_S1RZ_W0; // RecHits, 1. step, RZ, wheel 0
32  std::unique_ptr<HRes1DHit> hRes_S2RZ_W0; // RecHits, 2. step, RZ, wheel 0
33  std::unique_ptr<HRes1DHit> hRes_S3RZ_W0; // RecHits, 3. step, RZ, wheel 0
34  std::unique_ptr<HRes1DHit> hRes_S1RZ_W1; // RecHits, 1. step, RZ, wheel +-1
35  std::unique_ptr<HRes1DHit> hRes_S2RZ_W1; // RecHits, 2. step, RZ, wheel +-1
36  std::unique_ptr<HRes1DHit> hRes_S3RZ_W1; // RecHits, 3. step, RZ, wheel +-1
37  std::unique_ptr<HRes1DHit> hRes_S1RZ_W2; // RecHits, 1. step, RZ, wheel +-2
38  std::unique_ptr<HRes1DHit> hRes_S2RZ_W2; // RecHits, 2. step, RZ, wheel +-2
39  std::unique_ptr<HRes1DHit> hRes_S3RZ_W2; // RecHits, 3. step, RZ, wheel +-2
40  std::unique_ptr<HRes1DHit> hRes_S1RPhi_W0; // RecHits, 1. step, RPhi, wheel 0
41  std::unique_ptr<HRes1DHit> hRes_S2RPhi_W0; // RecHits, 2. step, RPhi, wheel 0
42  std::unique_ptr<HRes1DHit> hRes_S3RPhi_W0; // RecHits, 3. step, RPhi, wheel 0
43  std::unique_ptr<HRes1DHit> hRes_S1RPhi_W1; // RecHits, 1. step, RPhi, wheel +-1
44  std::unique_ptr<HRes1DHit> hRes_S2RPhi_W1; // RecHits, 2. step, RPhi, wheel +-1
45  std::unique_ptr<HRes1DHit> hRes_S3RPhi_W1; // RecHits, 3. step, RPhi, wheel +-1
46  std::unique_ptr<HRes1DHit> hRes_S1RPhi_W2; // RecHits, 1. step, RPhi, wheel +-2
47  std::unique_ptr<HRes1DHit> hRes_S2RPhi_W2; // RecHits, 2. step, RPhi, wheel +-2
48  std::unique_ptr<HRes1DHit> hRes_S3RPhi_W2; // RecHits, 3. step, RPhi, wheel +-2
49  std::unique_ptr<HRes1DHit> hRes_S3RPhiWS[3][4]; // RecHits, 3. step, by wheel/station
50  std::unique_ptr<HRes1DHit> hRes_S3RZWS[3][4]; // RecHits, 3. step, by wheel/station
51 
52  std::unique_ptr<HEff1DHit> hEff_S1RPhi; // RecHits, 1. step, RPhi
53  std::unique_ptr<HEff1DHit> hEff_S2RPhi; // RecHits, 2. step, RPhi
54  std::unique_ptr<HEff1DHit> hEff_S3RPhi; // RecHits, 3. step, RPhi
55  std::unique_ptr<HEff1DHit> hEff_S1RZ; // RecHits, 1. step, RZ
56  std::unique_ptr<HEff1DHit> hEff_S2RZ; // RecHits, 2. step, RZ
57  std::unique_ptr<HEff1DHit> hEff_S3RZ; // RecHits, 3. step, RZ
58  std::unique_ptr<HEff1DHit> hEff_S1RZ_W0; // RecHits, 1. step, RZ, wheel 0
59  std::unique_ptr<HEff1DHit> hEff_S2RZ_W0; // RecHits, 2. step, RZ, wheel 0
60  std::unique_ptr<HEff1DHit> hEff_S3RZ_W0; // RecHits, 3. step, RZ, wheel 0
61  std::unique_ptr<HEff1DHit> hEff_S1RZ_W1; // RecHits, 1. step, RZ, wheel +-1
62  std::unique_ptr<HEff1DHit> hEff_S2RZ_W1; // RecHits, 2. step, RZ, wheel +-1
63  std::unique_ptr<HEff1DHit> hEff_S3RZ_W1; // RecHits, 3. step, RZ, wheel +-1
64  std::unique_ptr<HEff1DHit> hEff_S1RZ_W2; // RecHits, 1. step, RZ, wheel +-2
65  std::unique_ptr<HEff1DHit> hEff_S2RZ_W2; // RecHits, 2. step, RZ, wheel +-2
66  std::unique_ptr<HEff1DHit> hEff_S3RZ_W2; // RecHits, 3. step, RZ, wheel +-2
67  std::unique_ptr<HEff1DHit> hEff_S1RPhiWS[3][4]; // RecHits, 3. step, by wheel/station
68  std::unique_ptr<HEff1DHit> hEff_S3RPhiWS[3][4]; // RecHits, 3. step, by wheel/station
69  std::unique_ptr<HEff1DHit> hEff_S1RZWS[3][4]; // RecHits, 3. step, by wheel/station
70  std::unique_ptr<HEff1DHit> hEff_S3RZWS[3][4]; // RecHits, 3. step, by wheel/station
71  };
72 } // namespace dtrechit
73 
74 using namespace dtrechit;
75 
76 // In phi SLs, The dependency on X and angle is specular in positive
77 // and negative wheels. Since positive and negative wheels are filled
78 // together into the same plots, it is useful to mirror negative wheels
79 // so that the actual dependency can be observerd instead of an artificially
80 // simmetrized one.
81 // Set mirrorMinusWheels to avoid this.
82 namespace {
83  constexpr bool mirrorMinusWheels = true;
84 }
85 
86 // Constructor
88  // Get the debug parameter for verbose output
89  debug_ = pset.getUntrackedParameter<bool>("debug");
90  // the name of the simhit collection
91  simHitLabel_ = pset.getUntrackedParameter<InputTag>("simHitLabel");
92  simHitToken_ = consumes<PSimHitContainer>(pset.getUntrackedParameter<InputTag>("simHitLabel"));
93  // the name of the 1D rec hit collection
94  recHitLabel_ = pset.getUntrackedParameter<InputTag>("recHitLabel");
95  recHitToken_ = consumes<DTRecHitCollection>(pset.getUntrackedParameter<InputTag>("recHitLabel"));
96  // the name of the 2D rec hit collection
97  segment2DLabel_ = pset.getUntrackedParameter<InputTag>("segment2DLabel");
98  segment2DToken_ = consumes<DTRecSegment2DCollection>(pset.getUntrackedParameter<InputTag>("segment2DLabel"));
99  // the name of the 4D rec hit collection
100  segment4DLabel_ = pset.getUntrackedParameter<InputTag>("segment4DLabel");
101  segment4DToken_ = consumes<DTRecSegment4DCollection>(pset.getUntrackedParameter<InputTag>("segment4DLabel"));
102  // Switches for analysis at various steps
103  doStep1_ = pset.getUntrackedParameter<bool>("doStep1", false);
104  doStep2_ = pset.getUntrackedParameter<bool>("doStep2", false);
105  doStep3_ = pset.getUntrackedParameter<bool>("doStep3", false);
106  doall_ = pset.getUntrackedParameter<bool>("doall", false);
107  local_ = pset.getUntrackedParameter<bool>("local", true);
108 }
109 
111  edm::Run const &run,
112  edm::EventSetup const &setup,
113  Histograms &histograms) const {
114  if (doall_ && doStep1_) {
115  histograms.hRes_S1RPhi = std::make_unique<HRes1DHit>("S1RPhi", booker, true, local_); // RecHits, 1. step, RPhi
116  histograms.hRes_S1RPhi_W0 =
117  std::make_unique<HRes1DHit>("S1RPhi_W0", booker, true, local_); // RecHits, 1. step, RZ, wheel 0
118  histograms.hRes_S1RPhi_W1 =
119  std::make_unique<HRes1DHit>("S1RPhi_W1", booker, true, local_); // RecHits, 1. step, RZ, wheel +-1
120  histograms.hRes_S1RPhi_W2 =
121  std::make_unique<HRes1DHit>("S1RPhi_W2", booker, true, local_); // RecHits, 1. step, RZ, wheel +-2
122  histograms.hRes_S1RZ = std::make_unique<HRes1DHit>("S1RZ", booker, true, local_); // RecHits, 1. step, RZ
123  histograms.hRes_S1RZ_W0 =
124  std::make_unique<HRes1DHit>("S1RZ_W0", booker, true, local_); // RecHits, 1. step, RZ, wheel 0
125  histograms.hRes_S1RZ_W1 =
126  std::make_unique<HRes1DHit>("S1RZ_W1", booker, true, local_); // RecHits, 1. step, RZ, wheel +-1
127  histograms.hRes_S1RZ_W2 =
128  std::make_unique<HRes1DHit>("S1RZ_W2", booker, true, local_); // RecHits, 1. step, RZ, wheel +-2
129  histograms.hEff_S1RPhi = std::make_unique<HEff1DHit>("S1RPhi", booker); // RecHits, 1. step, RPhi
130  histograms.hEff_S1RZ = std::make_unique<HEff1DHit>("S1RZ", booker); // RecHits, 1. step, RZ
131  histograms.hEff_S1RZ_W0 = std::make_unique<HEff1DHit>("S1RZ_W0", booker); // RecHits, 1. step, RZ, wheel 0
132  histograms.hEff_S1RZ_W1 = std::make_unique<HEff1DHit>("S1RZ_W1", booker); // RecHits, 1. step, RZ, wheel +-1
133  histograms.hEff_S1RZ_W2 = std::make_unique<HEff1DHit>("S1RZ_W2", booker); // RecHits, 1. step, RZ, wheel +-2
134  }
135  if (doall_ && doStep2_) {
136  histograms.hRes_S2RPhi = std::make_unique<HRes1DHit>("S2RPhi", booker, true, local_); // RecHits, 2. step, RPhi
137  histograms.hRes_S2RPhi_W0 =
138  std::make_unique<HRes1DHit>("S2RPhi_W0", booker, true, local_); // RecHits, 2. step, RPhi, wheel 0
139  histograms.hRes_S2RPhi_W1 =
140  std::make_unique<HRes1DHit>("S2RPhi_W1", booker, true, local_); // RecHits, 2. step, RPhi, wheel +-1
141  histograms.hRes_S2RPhi_W2 =
142  std::make_unique<HRes1DHit>("S2RPhi_W2", booker, true, local_); // RecHits, 2. step, RPhi, wheel +-2
143  histograms.hRes_S2RZ = std::make_unique<HRes1DHit>("S2RZ", booker, true, local_); // RecHits, 2. step, RZ
144  histograms.hRes_S2RZ_W0 =
145  std::make_unique<HRes1DHit>("S2RZ_W0", booker, true, local_); // RecHits, 2. step, RZ, wheel 0
146  histograms.hRes_S2RZ_W1 =
147  std::make_unique<HRes1DHit>("S2RZ_W1", booker, true, local_); // RecHits, 2. step, RZ, wheel +-1
148  histograms.hRes_S2RZ_W2 =
149  std::make_unique<HRes1DHit>("S2RZ_W2", booker, true, local_); // RecHits, 2. step, RZ, wheel +-2
150  histograms.hEff_S2RPhi = std::make_unique<HEff1DHit>("S2RPhi", booker); // RecHits, 2. step, RPhi
151  histograms.hEff_S2RZ_W0 = std::make_unique<HEff1DHit>("S2RZ_W0", booker); // RecHits, 2. step, RZ, wheel 0
152  histograms.hEff_S2RZ_W1 = std::make_unique<HEff1DHit>("S2RZ_W1", booker); // RecHits, 2. step, RZ, wheel +-1
153  histograms.hEff_S2RZ_W2 = std::make_unique<HEff1DHit>("S2RZ_W2", booker); // RecHits, 2. step, RZ, wheel +-2
154  histograms.hEff_S2RZ = std::make_unique<HEff1DHit>("S2RZ", booker); // RecHits, 2. step, RZ
155  }
156  if (doStep3_) {
157  histograms.hRes_S3RPhi = std::make_unique<HRes1DHit>("S3RPhi", booker, doall_, local_); // RecHits, 3. step, RPhi
158  histograms.hRes_S3RPhi_W0 =
159  std::make_unique<HRes1DHit>("S3RPhi_W0", booker, doall_, local_); // RecHits, 3. step, RPhi, wheel 0
160  histograms.hRes_S3RPhi_W1 = std::make_unique<HRes1DHit>("S3RPhi_W1",
161  booker,
162  doall_,
163  local_); // RecHits, 3. step, RPhi, wheel +-1
164  histograms.hRes_S3RPhi_W2 = std::make_unique<HRes1DHit>("S3RPhi_W2",
165  booker,
166  doall_,
167  local_); // RecHits, 3. step, RPhi, wheel +-2
168  histograms.hRes_S3RZ = std::make_unique<HRes1DHit>("S3RZ", booker, doall_, local_); // RecHits, 3. step, RZ
169  histograms.hRes_S3RZ_W0 =
170  std::make_unique<HRes1DHit>("S3RZ_W0", booker, doall_, local_); // RecHits, 3. step, RZ, wheel 0
171  histograms.hRes_S3RZ_W1 =
172  std::make_unique<HRes1DHit>("S3RZ_W1", booker, doall_, local_); // RecHits, 3. step, RZ, wheel +-1
173  histograms.hRes_S3RZ_W2 =
174  std::make_unique<HRes1DHit>("S3RZ_W2", booker, doall_, local_); // RecHits, 3. step, RZ, wheel +-2
175 
176  if (local_) {
177  // Plots with finer granularity, not to be included in DQM
178  TString name1 = "RPhi_W";
179  TString name2 = "RZ_W";
180  for (long w = 0; w <= 2; ++w) {
181  for (long s = 1; s <= 4; ++s) {
182  histograms.hRes_S3RPhiWS[w][s - 1] =
183  std::make_unique<HRes1DHit>(("S3" + name1 + w + "_St" + s).Data(), booker, doall_, local_);
184  histograms.hEff_S1RPhiWS[w][s - 1] =
185  std::make_unique<HEff1DHit>(("S1" + name1 + w + "_St" + s).Data(), booker);
186  histograms.hEff_S3RPhiWS[w][s - 1] =
187  std::make_unique<HEff1DHit>(("S3" + name1 + w + "_St" + s).Data(), booker);
188  if (s != 4) {
189  histograms.hRes_S3RZWS[w][s - 1] =
190  std::make_unique<HRes1DHit>(("S3" + name2 + w + "_St" + s).Data(), booker, doall_, local_);
191  histograms.hEff_S1RZWS[w][s - 1] =
192  std::make_unique<HEff1DHit>(("S1" + name2 + w + "_St" + s).Data(), booker);
193  histograms.hEff_S3RZWS[w][s - 1] =
194  std::make_unique<HEff1DHit>(("S3" + name2 + w + "_St" + s).Data(), booker);
195  }
196  }
197  }
198  }
199 
200  if (doall_) {
201  histograms.hEff_S3RPhi = std::make_unique<HEff1DHit>("S3RPhi", booker); // RecHits, 3. step, RPhi
202  histograms.hEff_S3RZ = std::make_unique<HEff1DHit>("S3RZ", booker); // RecHits, 3. step, RZ
203  histograms.hEff_S3RZ_W0 = std::make_unique<HEff1DHit>("S3RZ_W0", booker); // RecHits, 3. step, RZ, wheel 0
204  histograms.hEff_S3RZ_W1 = std::make_unique<HEff1DHit>("S3RZ_W1", booker); // RecHits, 3. step, RZ, wheel +-1
205  histograms.hEff_S3RZ_W2 = std::make_unique<HEff1DHit>("S3RZ_W2", booker); // RecHits, 3. step, RZ, wheel +-2
206  }
207  }
208 }
209 
210 // The real analysis
212  edm::EventSetup const &setup,
213  Histograms const &histograms) const {
214  if (debug_) {
215  cout << "--- [DTRecHitQuality] Analysing Event: #Run: " << event.id().run() << " #Event: " << event.id().event()
216  << endl;
217  }
218 
219  // Get the DT Geometry
220  const DTGeometry &dtGeom = setup.getData(muonGeomToken_);
221 
222  // Get the SimHit collection from the event
224  event.getByToken(simHitToken_, simHits);
225 
226  // Map simhits per wire
227  map<DTWireId, PSimHitContainer> simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(*(simHits.product()));
228 
229  //=======================================================================================
230  // RecHit analysis at Step 1
231  if (doStep1_ && doall_) {
232  if (debug_) {
233  cout << " -- DTRecHit S1: begin analysis:" << endl;
234  }
235  // Get the rechit collection from the event
236  Handle<DTRecHitCollection> dtRecHits;
237  event.getByToken(recHitToken_, dtRecHits);
238 
239  if (!dtRecHits.isValid()) {
240  if (debug_) {
241  cout << "[DTRecHitQuality]**Warning: no 1DRechits with label: " << recHitLabel_ << " in this event, skipping!"
242  << endl;
243  }
244  return;
245  }
246 
247  // Map rechits per wire
248  auto const &recHitsPerWire = map1DRecHitsPerWire(dtRecHits.product());
249  compute(dtGeom, simHitsPerWire, recHitsPerWire, histograms, 1);
250  }
251 
252  //=======================================================================================
253  // RecHit analysis at Step 2
254  if (doStep2_ && doall_) {
255  if (debug_) {
256  cout << " -- DTRecHit S2: begin analysis:" << endl;
257  }
258 
259  // Get the 2D rechits from the event
261  event.getByToken(segment2DToken_, segment2Ds);
262 
263  if (!segment2Ds.isValid()) {
264  if (debug_) {
265  cout << "[DTRecHitQuality]**Warning: no 2DSegments with label: " << segment2DLabel_
266  << " in this event, skipping!" << endl;
267  }
268 
269  } else {
270  // Map rechits per wire
271  auto const &recHitsPerWire = map1DRecHitsPerWire(segment2Ds.product());
272  compute(dtGeom, simHitsPerWire, recHitsPerWire, histograms, 2);
273  }
274  }
275 
276  //=======================================================================================
277  // RecHit analysis at Step 3
278  if (doStep3_) {
279  if (debug_) {
280  cout << " -- DTRecHit S3: begin analysis:" << endl;
281  }
282 
283  // Get the 4D rechits from the event
285  event.getByToken(segment4DToken_, segment4Ds);
286 
287  if (!segment4Ds.isValid()) {
288  if (debug_) {
289  cout << "[DTRecHitQuality]**Warning: no 4D Segments with label: " << segment4DLabel_
290  << " in this event, skipping!" << endl;
291  }
292  return;
293  }
294 
295  // Map rechits per wire
296  auto const &recHitsPerWire = map1DRecHitsPerWire(segment4Ds.product());
297  compute(dtGeom, simHitsPerWire, recHitsPerWire, histograms, 3);
298  }
299 }
300 
301 // Return a map between DTRecHit1DPair and wireId
302 map<DTWireId, vector<DTRecHit1DPair>> DTRecHitQuality::map1DRecHitsPerWire(
303  const DTRecHitCollection *dt1DRecHitPairs) const {
304  map<DTWireId, vector<DTRecHit1DPair>> ret;
305 
306  for (const auto &dt1DRecHitPair : *dt1DRecHitPairs) {
307  ret[dt1DRecHitPair.wireId()].push_back(dt1DRecHitPair);
308  }
309 
310  return ret;
311 }
312 
313 // Return a map between DTRecHit1D at S2 and wireId
314 map<DTWireId, vector<DTRecHit1D>> DTRecHitQuality::map1DRecHitsPerWire(
315  const DTRecSegment2DCollection *segment2Ds) const {
316  map<DTWireId, vector<DTRecHit1D>> ret;
317 
318  // Loop over all 2D segments
319  for (const auto &segment2D : *segment2Ds) {
320  vector<DTRecHit1D> component1DHits = segment2D.specificRecHits();
321  // Loop over all component 1D hits
322  for (auto &component1DHit : component1DHits) {
323  ret[component1DHit.wireId()].push_back(component1DHit);
324  }
325  }
326  return ret;
327 }
328 
329 // Return a map between DTRecHit1D at S3 and wireId
330 map<DTWireId, std::vector<DTRecHit1D>> DTRecHitQuality::map1DRecHitsPerWire(
331  const DTRecSegment4DCollection *segment4Ds) const {
332  map<DTWireId, vector<DTRecHit1D>> ret;
333  // Loop over all 4D segments
334  for (const auto &segment4D : *segment4Ds) {
335  // Get component 2D segments
336  vector<const TrackingRecHit *> segment2Ds = segment4D.recHits();
337  // Loop over 2D segments:
338  for (auto &segment2D : segment2Ds) {
339  // Get 1D component rechits
340  vector<const TrackingRecHit *> hits = segment2D->recHits();
341  // Loop over them
342  for (auto &hit : hits) {
343  const auto *hit1D = dynamic_cast<const DTRecHit1D *>(hit);
344  ret[hit1D->wireId()].push_back(*hit1D);
345  }
346  }
347  }
348 
349  return ret;
350 }
351 
352 // Compute SimHit distance from wire (cm)
353 float DTRecHitQuality::simHitDistFromWire(const DTLayer *layer, const DTWireId &wireId, const PSimHit &hit) const {
354  float xwire = layer->specificTopology().wirePosition(wireId.wire());
355  LocalPoint entryP = hit.entryPoint();
356  LocalPoint exitP = hit.exitPoint();
357  float xEntry = entryP.x() - xwire;
358  float xExit = exitP.x() - xwire;
359 
360  return fabs(xEntry - (entryP.z() * (xExit - xEntry)) / (exitP.z() - entryP.z())); // FIXME: check...
361 }
362 
363 // Compute SimHit impact angle (in direction perp to wire), in the SL RF
364 float DTRecHitQuality::simHitImpactAngle(const DTLayer *layer, const DTWireId &wireId, const PSimHit &hit) const {
365  LocalPoint entryP = hit.entryPoint();
366  LocalPoint exitP = hit.exitPoint();
367  float theta = (exitP.x() - entryP.x()) / (exitP.z() - entryP.z());
368  return atan(theta);
369 }
370 
371 // Compute SimHit distance from FrontEnd
372 float DTRecHitQuality::simHitDistFromFE(const DTLayer *layer, const DTWireId &wireId, const PSimHit &hit) const {
373  LocalPoint entryP = hit.entryPoint();
374  LocalPoint exitP = hit.exitPoint();
375  float wireLenght = layer->specificTopology().cellLenght();
376  // FIXME: should take only wireLenght/2.;
377  // moreover, pos+cellLenght/2. is shorter than the distance from FE.
378  // In fact it would make more sense to make plots vs y.
379  return (entryP.y() + exitP.y()) / 2. + wireLenght;
380 }
381 
382 // Find the RecHit closest to the muon SimHit
383 template <typename type>
385  const DTWireId &wireId,
386  const vector<type> &recHits,
387  const float simHitDist) const {
388  float res = 99999;
389  const type *theBestRecHit = nullptr;
390  // Loop over RecHits within the cell
391  for (auto recHit = recHits.begin(); recHit != recHits.end(); recHit++) {
392  float distTmp = recHitDistFromWire(*recHit, layer);
393  if (fabs(distTmp - simHitDist) < res) {
394  res = fabs(distTmp - simHitDist);
395  theBestRecHit = &(*recHit);
396  }
397  } // End of loop over RecHits within the cell
398 
399  return theBestRecHit;
400 }
401 
402 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
404  // Compute the rechit distance from wire
405  return fabs(hitPair.localPosition(DTEnums::Left).x() - hitPair.localPosition(DTEnums::Right).x()) / 2.;
406 }
407 
408 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
410  return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
411 }
412 
413 template <typename type>
415  const std::map<DTWireId, std::vector<PSimHit>> &simHitsPerWire,
416  const std::map<DTWireId, std::vector<type>> &recHitsPerWire,
417  Histograms const &histograms,
418  int step) const {
419  // Loop over cells with a muon SimHit
420  for (const auto &wireAndSHits : simHitsPerWire) {
421  DTWireId wireId = wireAndSHits.first;
422  int wheel = wireId.wheel();
423  int sl = wireId.superLayer();
424 
425  vector<PSimHit> simHitsInCell = wireAndSHits.second;
426 
427  // Get the layer
428  const DTLayer *layer = dtGeom.layer(wireId);
429 
430  // Look for a mu hit in the cell
431  const PSimHit *muSimHit = DTHitQualityUtils::findMuSimHit(simHitsInCell);
432  if (muSimHit == nullptr) {
433  if (debug_) {
434  cout << " No mu SimHit in channel: " << wireId << ", skipping! " << endl;
435  }
436  continue; // Skip this cell
437  }
438 
439  // Find the distance of the simhit from the wire
440  float simHitWireDist = simHitDistFromWire(layer, wireId, *muSimHit);
441  // Skip simhits out of the cell
442  if (simHitWireDist > 2.1) {
443  if (debug_) {
444  cout << " [DTRecHitQuality]###Warning: The mu SimHit in out of the "
445  "cell, skipping!"
446  << endl;
447  }
448  continue; // Skip this cell
449  }
450  GlobalPoint simHitGlobalPos = layer->toGlobal(muSimHit->localPosition());
451 
452  // find SH impact angle
453  float simHitTheta = simHitImpactAngle(layer, wireId, *muSimHit);
454 
455  // find SH distance from FE
456  float simHitFEDist = simHitDistFromFE(layer, wireId, *muSimHit);
457 
458  bool recHitReconstructed = false;
459 
460  // Look for RecHits in the same cell
461  if (recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
462  // No RecHit found in this cell
463  if (debug_) {
464  cout << " No RecHit found at Step: " << step << " in cell: " << wireId << endl;
465  }
466  } else {
467  recHitReconstructed = true;
468  // vector<type> recHits = (*wireAndRecHits).second;
469  const vector<type> &recHits = recHitsPerWire.at(wireId);
470  if (debug_) {
471  cout << " " << recHits.size() << " RecHits, Step " << step << " in channel: " << wireId << endl;
472  }
473 
474  // Find the best RecHit
475  const type *theBestRecHit = findBestRecHit(layer, wireId, recHits, simHitWireDist);
476 
477  float recHitWireDist = recHitDistFromWire(*theBestRecHit, layer);
478  if (debug_) {
479  cout << " SimHit distance from wire: " << simHitWireDist << endl
480  << " SimHit distance from FE: " << simHitFEDist << endl
481  << " SimHit angle in layer RF: " << simHitTheta << endl
482  << " RecHit distance from wire: " << recHitWireDist << endl;
483  }
484  float recHitErr = recHitPositionError(*theBestRecHit);
485  HRes1DHit *hRes = nullptr;
486  HRes1DHit *hResTot = nullptr;
487 
488  // Mirror angle in phi so that + and - wheels can be plotted together
489  if (mirrorMinusWheels && wheel < 0 && sl != 2) {
490  simHitTheta *= -1.;
491  // Note: local X, if used, would have to be mirrored as well
492  }
493 
494  // Fill residuals and pulls
495  // Select the histo to be filled
496  if (step == 1) {
497  // Step 1
498  if (sl != 2) {
499  hResTot = histograms.hRes_S1RPhi.get();
500  if (wheel == 0) {
501  hRes = histograms.hRes_S1RPhi_W0.get();
502  }
503  if (abs(wheel) == 1) {
504  hRes = histograms.hRes_S1RPhi_W1.get();
505  }
506  if (abs(wheel) == 2) {
507  hRes = histograms.hRes_S1RPhi_W2.get();
508  }
509  } else {
510  hResTot = histograms.hRes_S1RZ.get();
511  if (wheel == 0) {
512  hRes = histograms.hRes_S1RZ_W0.get();
513  }
514  if (abs(wheel) == 1) {
515  hRes = histograms.hRes_S1RZ_W1.get();
516  }
517  if (abs(wheel) == 2) {
518  hRes = histograms.hRes_S1RZ_W2.get();
519  }
520  }
521 
522  } else if (step == 2) {
523  // Step 2
524  if (sl != 2) {
525  hRes = histograms.hRes_S2RPhi.get();
526  if (wheel == 0) {
527  hRes = histograms.hRes_S2RPhi_W0.get();
528  }
529  if (abs(wheel) == 1) {
530  hRes = histograms.hRes_S2RPhi_W1.get();
531  }
532  if (abs(wheel) == 2) {
533  hRes = histograms.hRes_S2RPhi_W2.get();
534  }
535  } else {
536  hResTot = histograms.hRes_S2RZ.get();
537  if (wheel == 0) {
538  hRes = histograms.hRes_S2RZ_W0.get();
539  }
540  if (abs(wheel) == 1) {
541  hRes = histograms.hRes_S2RZ_W1.get();
542  }
543  if (abs(wheel) == 2) {
544  hRes = histograms.hRes_S2RZ_W2.get();
545  }
546  }
547 
548  } else if (step == 3) {
549  // Step 3
550  if (sl != 2) {
551  hResTot = histograms.hRes_S3RPhi.get();
552  if (wheel == 0) {
553  hRes = histograms.hRes_S3RPhi_W0.get();
554  }
555  if (abs(wheel) == 1) {
556  hRes = histograms.hRes_S3RPhi_W1.get();
557  }
558  if (abs(wheel) == 2) {
559  hRes = histograms.hRes_S3RPhi_W2.get();
560  }
561  if (local_) {
562  histograms.hRes_S3RPhiWS[abs(wheel)][wireId.station() - 1]->fill(simHitWireDist,
563  simHitTheta,
564  simHitFEDist,
565  recHitWireDist,
566  simHitGlobalPos.eta(),
567  simHitGlobalPos.phi(),
568  recHitErr,
569  wireId.station());
570  }
571  } else {
572  hResTot = histograms.hRes_S3RZ.get();
573  if (wheel == 0) {
574  hRes = histograms.hRes_S3RZ_W0.get();
575  }
576  if (abs(wheel) == 1) {
577  hRes = histograms.hRes_S3RZ_W1.get();
578  }
579  if (abs(wheel) == 2) {
580  hRes = histograms.hRes_S3RZ_W2.get();
581  }
582  if (local_) {
583  histograms.hRes_S3RZWS[abs(wheel)][wireId.station() - 1]->fill(simHitWireDist,
584  simHitTheta,
585  simHitFEDist,
586  recHitWireDist,
587  simHitGlobalPos.eta(),
588  simHitGlobalPos.phi(),
589  recHitErr,
590  wireId.station());
591  }
592  }
593  }
594 
595  // Fill
596  hRes->fill(simHitWireDist,
597  simHitTheta,
598  simHitFEDist,
599  recHitWireDist,
600  simHitGlobalPos.eta(),
601  simHitGlobalPos.phi(),
602  recHitErr,
603  wireId.station());
604  if (hResTot != nullptr) {
605  hResTot->fill(simHitWireDist,
606  simHitTheta,
607  simHitFEDist,
608  recHitWireDist,
609  simHitGlobalPos.eta(),
610  simHitGlobalPos.phi(),
611  recHitErr,
612  wireId.station());
613  }
614  }
615 
616  // Fill Efficiencies
617  if (doall_) {
618  HEff1DHit *hEff = nullptr;
619  HEff1DHit *hEffTot = nullptr;
620  if (step == 1) {
621  // Step 1
622  if (sl != 2) {
623  hEff = histograms.hEff_S1RPhi.get();
624  if (local_) {
625  histograms.hEff_S1RPhiWS[abs(wheel)][wireId.station() - 1]->fill(
626  simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
627  }
628  } else {
629  hEffTot = histograms.hEff_S1RZ.get();
630  if (wheel == 0) {
631  hEff = histograms.hEff_S1RZ_W0.get();
632  }
633  if (abs(wheel) == 1) {
634  hEff = histograms.hEff_S1RZ_W1.get();
635  }
636  if (abs(wheel) == 2) {
637  hEff = histograms.hEff_S1RZ_W2.get();
638  }
639  if (local_) {
640  histograms.hEff_S1RZWS[abs(wheel)][wireId.station() - 1]->fill(
641  simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
642  }
643  }
644 
645  } else if (step == 2) {
646  // Step 2
647  if (sl != 2) {
648  hEff = histograms.hEff_S2RPhi.get();
649  } else {
650  hEffTot = histograms.hEff_S2RZ.get();
651  if (wheel == 0) {
652  hEff = histograms.hEff_S2RZ_W0.get();
653  }
654  if (abs(wheel) == 1) {
655  hEff = histograms.hEff_S2RZ_W1.get();
656  }
657  if (abs(wheel) == 2) {
658  hEff = histograms.hEff_S2RZ_W2.get();
659  }
660  }
661 
662  } else if (step == 3) {
663  // Step 3
664  if (sl != 2) {
665  hEff = histograms.hEff_S3RPhi.get();
666  if (local_) {
667  histograms.hEff_S3RPhiWS[abs(wheel)][wireId.station() - 1]->fill(
668  simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
669  }
670  } else {
671  hEffTot = histograms.hEff_S3RZ.get();
672  if (wheel == 0) {
673  hEff = histograms.hEff_S3RZ_W0.get();
674  }
675  if (abs(wheel) == 1) {
676  hEff = histograms.hEff_S3RZ_W1.get();
677  }
678  if (abs(wheel) == 2) {
679  hEff = histograms.hEff_S3RZ_W2.get();
680  }
681  if (local_) {
682  histograms.hEff_S3RZWS[abs(wheel)][wireId.station() - 1]->fill(
683  simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
684  }
685  }
686  }
687  // Fill
688  hEff->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
689  if (hEffTot != nullptr) {
690  hEffTot->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
691  }
692  }
693  }
694 }
695 
696 // Return the error on the measured (cm) coordinate
698  return sqrt(recHit.localPositionError(DTEnums::Left).xx());
699 }
700 
701 // Return the error on the measured (cm) coordinate
703  return sqrt(recHit.localPositionError().xx());
704 }
705 
706 // declare this as a framework plugin
int station() const
Return the station number.
Definition: DTChamberId.h:45
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
edm::InputTag recHitLabel_
int superLayer() const
Return the superlayer number.
std::unique_ptr< HRes1DHit > hRes_S3RPhi_W0
int wire() const
Return the wire number.
Definition: DTWireId.h:45
std::unique_ptr< HRes1DHit > hRes_S2RZ_W2
std::unique_ptr< HRes1DHit > hRes_S1RPhi
std::unique_ptr< HRes1DHit > hRes_S3RPhi_W2
edm::EDGetTokenT< DTRecHitCollection > recHitToken_
T w() const
T z() const
Definition: PV3DBase.h:61
float recHitDistFromWire(const DTRecHit1DPair &hitPair, const DTLayer *layer) const
edm::InputTag segment4DLabel_
ret
prodAgent to be discontinued
std::unique_ptr< HRes1DHit > hRes_S2RZ
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::unique_ptr< HEff1DHit > hEff_S3RPhi
A set of histograms fo efficiency computation for 1D RecHits (producer)
Definition: Histograms.h:138
T eta() const
Definition: PV3DBase.h:73
std::unique_ptr< HEff1DHit > hEff_S3RZ
std::unique_ptr< HRes1DHit > hRes_S2RPhi_W1
T const * product() const
Definition: Handle.h:70
std::unique_ptr< HRes1DHit > hRes_S1RPhi_W0
LocalPoint localPosition() const override
std::unique_ptr< HRes1DHit > hRes_S3RZ_W2
edm::EDGetTokenT< DTRecSegment4DCollection > segment4DToken_
std::unique_ptr< HEff1DHit > hEff_S3RZ_W1
std::unique_ptr< HEff1DHit > hEff_S2RZ_W1
std::unique_ptr< HRes1DHit > hRes_S1RPhi_W1
float recHitPositionError(const DTRecHit1DPair &recHit) const
edm::InputTag simHitLabel_
Definition: Electron.h:6
std::unique_ptr< HRes1DHit > hRes_S1RZ
std::map< DTWireId, std::vector< DTRecHit1DPair > > map1DRecHitsPerWire(const DTRecHitCollection *dt1DRecHitPairs) const
std::unique_ptr< HRes1DHit > hRes_S2RPhi_W2
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
void fill(float distSimHit, float thetaSimHit, float distFESimHit, float distRecHit, float etaSimHit, float phiSimHit, float errRecHit, int station)
Definition: Histograms.h:83
DTRecHitQuality(const edm::ParameterSet &pset)
Constructor.
std::unique_ptr< HRes1DHit > hRes_S1RZ_W2
edm::InputTag segment2DLabel_
T sqrt(T t)
Definition: SSEVec.h:23
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, dtrechit::Histograms &) const override
Book the DQM plots.
std::unique_ptr< HEff1DHit > hEff_S1RZ_W2
std::unique_ptr< HRes1DHit > hRes_S3RZ_W1
edm::EDGetTokenT< DTRecSegment2DCollection > segment2DToken_
float simHitImpactAngle(const DTLayer *layer, const DTWireId &wireId, const PSimHit &hit) const
std::unique_ptr< HRes1DHit > hRes_S3RZ
float simHitDistFromWire(const DTLayer *layer, const DTWireId &wireId, const PSimHit &hit) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const PSimHit * findMuSimHit(const edm::PSimHitContainer &hits)
Select the SimHit from a muon in a vector of SimHits.
A set of histograms of residuals and pulls for 1D RecHits.
Definition: Histograms.h:44
std::unique_ptr< HRes1DHit > hRes_S3RPhi
std::unique_ptr< HEff1DHit > hEff_S1RZ_W1
const type * findBestRecHit(const DTLayer *layer, const DTWireId &wireId, const std::vector< type > &recHits, float simHitDist) const
void compute(const DTGeometry &dtGeom, const std::map< DTWireId, std::vector< PSimHit >> &simHitsPerWire, const std::map< DTWireId, std::vector< type >> &recHitsPerWire, dtrechit::Histograms const &histograms, int step) const
std::unique_ptr< HEff1DHit > hEff_S1RZ_W0
std::unique_ptr< HRes1DHit > hRes_S2RPhi
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, dtrechit::Histograms const &) const override
Perform the real analysis.
Local3DPoint localPosition() const
Definition: PSimHit.h:54
std::unique_ptr< HEff1DHit > hEff_S2RPhi
std::unique_ptr< HRes1DHit > hRes_S1RPhi_W2
bool isValid() const
Definition: HandleBase.h:70
std::unique_ptr< HRes1DHit > hRes_S2RZ_W1
std::unique_ptr< HRes1DHit > hRes_S2RPhi_W0
std::unique_ptr< HRes1DHit > hRes_S1RZ_W0
std::unique_ptr< HEff1DHit > hEff_S1RZ
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
std::unique_ptr< HRes1DHit > hRes_S3RZ_W0
void fill(float distSimHit, float etaSimHit, float phiSimHit, bool fillRecHit)
Definition: Histograms.h:157
step
Definition: StallMonitor.cc:83
std::unique_ptr< HRes1DHit > hRes_S1RZ_W1
std::unique_ptr< HEff1DHit > hEff_S2RZ_W0
float simHitDistFromFE(const DTLayer *layer, const DTWireId &wireId, const PSimHit &hit) const
std::unique_ptr< HEff1DHit > hEff_S3RZ_W2
edm::EDGetTokenT< edm::PSimHitContainer > simHitToken_
std::unique_ptr< HEff1DHit > hEff_S1RPhi
std::unique_ptr< HRes1DHit > hRes_S3RPhi_W1
Definition: event.py:1
Definition: Run.h:45
std::unique_ptr< HEff1DHit > hEff_S2RZ_W2
std::unique_ptr< HEff1DHit > hEff_S2RZ
std::unique_ptr< HRes1DHit > hRes_S2RZ_W0
std::unique_ptr< HEff1DHit > hEff_S3RZ_W0
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96