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