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 }
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  if (doall_ && doStep1_) {
113  histograms.hRes_S1RPhi = std::make_unique<HRes1DHit>("S1RPhi", booker, true, local_); // RecHits, 1. step, RPhi
114  histograms.hRes_S1RPhi_W0 = std::make_unique<HRes1DHit>("S1RPhi_W0", booker, true, local_); // RecHits, 1. step, RZ, wheel 0
115  histograms.hRes_S1RPhi_W1 = std::make_unique<HRes1DHit>("S1RPhi_W1", booker, true, local_); // RecHits, 1. step, RZ, wheel +-1
116  histograms.hRes_S1RPhi_W2 = std::make_unique<HRes1DHit>("S1RPhi_W2", booker, true, local_); // RecHits, 1. step, RZ, wheel +-2
117  histograms.hRes_S1RZ = std::make_unique<HRes1DHit>("S1RZ", booker, true, local_); // RecHits, 1. step, RZ
118  histograms.hRes_S1RZ_W0 = std::make_unique<HRes1DHit>("S1RZ_W0", booker, true, local_); // RecHits, 1. step, RZ, wheel 0
119  histograms.hRes_S1RZ_W1 = std::make_unique<HRes1DHit>("S1RZ_W1", booker, true, local_); // RecHits, 1. step, RZ, wheel +-1
120  histograms.hRes_S1RZ_W2 = std::make_unique<HRes1DHit>("S1RZ_W2", booker, true, local_); // RecHits, 1. step, RZ, wheel +-2
121  histograms.hEff_S1RPhi = std::make_unique<HEff1DHit>("S1RPhi", booker); // RecHits, 1. step, RPhi
122  histograms.hEff_S1RZ = std::make_unique<HEff1DHit>("S1RZ", booker); // RecHits, 1. step, RZ
123  histograms.hEff_S1RZ_W0 = std::make_unique<HEff1DHit>("S1RZ_W0", booker); // RecHits, 1. step, RZ, wheel 0
124  histograms.hEff_S1RZ_W1 = std::make_unique<HEff1DHit>("S1RZ_W1", booker); // RecHits, 1. step, RZ, wheel +-1
125  histograms.hEff_S1RZ_W2 = std::make_unique<HEff1DHit>("S1RZ_W2", booker); // RecHits, 1. step, RZ, wheel +-2
126  }
127  if (doall_ && doStep2_) {
128  histograms.hRes_S2RPhi = std::make_unique<HRes1DHit>("S2RPhi", booker, true, local_); // RecHits, 2. step, RPhi
129  histograms.hRes_S2RPhi_W0 = std::make_unique<HRes1DHit>("S2RPhi_W0", booker, true, local_); // RecHits, 2. step, RPhi, wheel 0
130  histograms.hRes_S2RPhi_W1 = std::make_unique<HRes1DHit>("S2RPhi_W1", booker, true, local_); // RecHits, 2. step, RPhi, wheel +-1
131  histograms.hRes_S2RPhi_W2 = std::make_unique<HRes1DHit>("S2RPhi_W2", booker, true, local_); // RecHits, 2. step, RPhi, wheel +-2
132  histograms.hRes_S2RZ = std::make_unique<HRes1DHit>("S2RZ", booker, true, local_); // RecHits, 2. step, RZ
133  histograms.hRes_S2RZ_W0 = std::make_unique<HRes1DHit>("S2RZ_W0", booker, true, local_); // RecHits, 2. step, RZ, wheel 0
134  histograms.hRes_S2RZ_W1 = std::make_unique<HRes1DHit>("S2RZ_W1", booker, true, local_); // RecHits, 2. step, RZ, wheel +-1
135  histograms.hRes_S2RZ_W2 = std::make_unique<HRes1DHit>("S2RZ_W2", booker, true, local_); // RecHits, 2. step, RZ, wheel +-2
136  histograms.hEff_S2RPhi = std::make_unique<HEff1DHit>("S2RPhi", booker); // RecHits, 2. step, RPhi
137  histograms.hEff_S2RZ_W0 = std::make_unique<HEff1DHit>("S2RZ_W0", booker); // RecHits, 2. step, RZ, wheel 0
138  histograms.hEff_S2RZ_W1 = std::make_unique<HEff1DHit>("S2RZ_W1", booker); // RecHits, 2. step, RZ, wheel +-1
139  histograms.hEff_S2RZ_W2 = std::make_unique<HEff1DHit>("S2RZ_W2", booker); // RecHits, 2. step, RZ, wheel +-2
140  histograms.hEff_S2RZ = std::make_unique<HEff1DHit>("S2RZ", booker); // RecHits, 2. step, RZ
141  }
142  if (doStep3_) {
143  histograms.hRes_S3RPhi = std::make_unique<HRes1DHit>("S3RPhi", booker, doall_, local_); // RecHits, 3. step, RPhi
144  histograms.hRes_S3RPhi_W0 = std::make_unique<HRes1DHit>("S3RPhi_W0", booker, doall_, local_); // RecHits, 3. step, RPhi, wheel 0
145  histograms.hRes_S3RPhi_W1 = std::make_unique<HRes1DHit>("S3RPhi_W1", booker, doall_, local_); // RecHits, 3. step, RPhi, wheel +-1
146  histograms.hRes_S3RPhi_W2 = std::make_unique<HRes1DHit>("S3RPhi_W2", booker, doall_, local_); // RecHits, 3. step, RPhi, wheel +-2
147  histograms.hRes_S3RZ = std::make_unique<HRes1DHit>("S3RZ", booker, doall_, local_); // RecHits, 3. step, RZ
148  histograms.hRes_S3RZ_W0 = std::make_unique<HRes1DHit>("S3RZ_W0", booker, doall_, local_); // RecHits, 3. step, RZ, wheel 0
149  histograms.hRes_S3RZ_W1 = std::make_unique<HRes1DHit>("S3RZ_W1", booker, doall_, local_); // RecHits, 3. step, RZ, wheel +-1
150  histograms.hRes_S3RZ_W2 = std::make_unique<HRes1DHit>("S3RZ_W2", booker, doall_, local_); // RecHits, 3. step, RZ, wheel +-2
151 
152  if (local_) {
153  // Plots with finer granularity, not to be included in DQM
154  TString name1 = "RPhi_W";
155  TString name2 = "RZ_W";
156  for (long w = 0; w <= 2; ++w) {
157  for (long s = 1;s <= 4; ++s) {
158  histograms.hRes_S3RPhiWS[w][s-1] = std::make_unique<HRes1DHit>(("S3"+name1+w+"_St"+s).Data(), booker, doall_, local_);
159  histograms.hEff_S1RPhiWS[w][s-1] = std::make_unique<HEff1DHit>(("S1"+name1+w+"_St"+s).Data(), booker);
160  histograms.hEff_S3RPhiWS[w][s-1] = std::make_unique<HEff1DHit>(("S3"+name1+w+"_St"+s).Data(), booker);
161  if (s != 4) {
162  histograms.hRes_S3RZWS[w][s-1] = std::make_unique<HRes1DHit>(("S3"+name2+w+"_St"+s).Data(), booker, doall_, local_);
163  histograms.hEff_S1RZWS[w][s-1] = std::make_unique<HEff1DHit>(("S1"+name2+w+"_St"+s).Data(), booker);
164  histograms.hEff_S3RZWS[w][s-1] = std::make_unique<HEff1DHit>(("S3"+name2+w+"_St"+s).Data(), booker);
165  }
166  }
167  }
168  }
169 
170  if (doall_) {
171  histograms.hEff_S3RPhi = std::make_unique<HEff1DHit>("S3RPhi", booker); // RecHits, 3. step, RPhi
172  histograms.hEff_S3RZ = std::make_unique<HEff1DHit>("S3RZ", booker); // RecHits, 3. step, RZ
173  histograms.hEff_S3RZ_W0 = std::make_unique<HEff1DHit>("S3RZ_W0", booker); // RecHits, 3. step, RZ, wheel 0
174  histograms.hEff_S3RZ_W1 = std::make_unique<HEff1DHit>("S3RZ_W1", booker); // RecHits, 3. step, RZ, wheel +-1
175  histograms.hEff_S3RZ_W2 = std::make_unique<HEff1DHit>("S3RZ_W2", booker); // RecHits, 3. step, RZ, wheel +-2
176  }
177  }
178 }
179 
180 // The real analysis
182  if (debug_) {
183  cout << "--- [DTRecHitQuality] Analysing Event: #Run: " << event.id().run()
184  << " #Event: " << event.id().event() << endl;
185 }
186 
187  // Get the DT Geometry
188  ESHandle<DTGeometry> dtGeom;
189  setup.get<MuonGeometryRecord>().get(dtGeom);
190 
191  // Get the SimHit collection from the event
193  event.getByToken(simHitToken_, simHits);
194 
195  // Map simhits per wire
196  map<DTWireId, PSimHitContainer > simHitsPerWire =
198 
199  //=======================================================================================
200  // RecHit analysis at Step 1
201  if (doStep1_ && doall_) {
202  if (debug_) {
203  cout << " -- DTRecHit S1: begin analysis:" << endl;
204 }
205  // Get the rechit collection from the event
206  Handle<DTRecHitCollection> dtRecHits;
207  event.getByToken(recHitToken_, dtRecHits);
208 
209  if (!dtRecHits.isValid()) {
210  if (debug_) { cout << "[DTRecHitQuality]**Warning: no 1DRechits with label: " << recHitLabel_ << " in this event, skipping!" << endl;
211 }
212  return;
213  }
214 
215  // Map rechits per wire
216  auto const& recHitsPerWire = map1DRecHitsPerWire(dtRecHits.product());
217  compute(dtGeom.product(), simHitsPerWire, recHitsPerWire, histograms, 1);
218  }
219 
220  //=======================================================================================
221  // RecHit analysis at Step 2
222  if (doStep2_ && doall_) {
223  if (debug_) {
224  cout << " -- DTRecHit S2: begin analysis:" << endl;
225 }
226 
227  // Get the 2D rechits from the event
229  event.getByToken(segment2DToken_, segment2Ds);
230 
231  if (!segment2Ds.isValid()) {
232  if (debug_) {
233  cout << "[DTRecHitQuality]**Warning: no 2DSegments with label: " << segment2DLabel_
234  << " in this event, skipping!" << endl;
235 }
236 
237  }
238  else{
239  // Map rechits per wire
240  auto const& recHitsPerWire = map1DRecHitsPerWire(segment2Ds.product());
241  compute(dtGeom.product(), simHitsPerWire, recHitsPerWire, histograms, 2);
242  }
243  }
244 
245  //=======================================================================================
246  // RecHit analysis at Step 3
247  if (doStep3_) {
248  if (debug_) {
249  cout << " -- DTRecHit S3: begin analysis:" << endl;
250 }
251 
252  // Get the 4D rechits from the event
254  event.getByToken(segment4DToken_, segment4Ds);
255 
256  if (!segment4Ds.isValid()) {
257  if (debug_) { cout << "[DTRecHitQuality]**Warning: no 4D Segments with label: " << segment4DLabel_
258  << " in this event, skipping!" << endl;
259 }
260  return;
261  }
262 
263  // Map rechits per wire
264  auto const& recHitsPerWire = map1DRecHitsPerWire(segment4Ds.product());
265  compute(dtGeom.product(), simHitsPerWire, recHitsPerWire, histograms, 3);
266  }
267 }
268 
269 // Return a map between DTRecHit1DPair and wireId
270 map<DTWireId, vector<DTRecHit1DPair>>
272  map<DTWireId, vector<DTRecHit1DPair>> ret;
273 
274  for (const auto & dt1DRecHitPair : *dt1DRecHitPairs) {
275  ret[dt1DRecHitPair.wireId()].push_back(dt1DRecHitPair);
276  }
277 
278  return ret;
279 }
280 
281 
282 // Return a map between DTRecHit1D at S2 and wireId
283 map<DTWireId, vector<DTRecHit1D>>
285  map<DTWireId, vector<DTRecHit1D>> ret;
286 
287  // Loop over all 2D segments
288  for (const auto & segment2D : *segment2Ds) {
289  vector<DTRecHit1D> component1DHits = segment2D.specificRecHits();
290  // Loop over all component 1D hits
291  for (auto & component1DHit : component1DHits) {
292  ret[component1DHit.wireId()].push_back(component1DHit);
293  }
294  }
295  return ret;
296 }
297 
298 // Return a map between DTRecHit1D at S3 and wireId
299 map<DTWireId, std::vector<DTRecHit1D>>
301  map<DTWireId, vector<DTRecHit1D>> ret;
302  // Loop over all 4D segments
303  for (const auto & segment4D : *segment4Ds) {
304  // Get component 2D segments
305  vector<const TrackingRecHit*> segment2Ds = segment4D.recHits();
306  // Loop over 2D segments:
307  for (auto & segment2D : segment2Ds) {
308  // Get 1D component rechits
309  vector<const TrackingRecHit*> hits = segment2D->recHits();
310  // Loop over them
311  for (auto & hit : hits) {
312  const auto* hit1D = dynamic_cast<const DTRecHit1D*>(hit);
313  ret[hit1D->wireId()].push_back(*hit1D);
314  }
315  }
316  }
317 
318  return ret;
319 }
320 
321 // Compute SimHit distance from wire (cm)
323  const DTWireId& wireId,
324  const PSimHit& hit) const {
325  float xwire = layer->specificTopology().wirePosition(wireId.wire());
326  LocalPoint entryP = hit.entryPoint();
327  LocalPoint exitP = hit.exitPoint();
328  float xEntry = entryP.x() - xwire;
329  float xExit = exitP.x() - xwire;
330 
331  return fabs(xEntry - (entryP.z()*(xExit-xEntry))/(exitP.z()-entryP.z())); // FIXME: check...
332 }
333 
334 // Compute SimHit impact angle (in direction perp to wire), in the SL RF
336  const DTWireId& wireId,
337  const PSimHit& hit) const {
338  LocalPoint entryP = hit.entryPoint();
339  LocalPoint exitP = hit.exitPoint();
340  float theta =(exitP.x()-entryP.x())/(exitP.z()-entryP.z());
341  return atan(theta);
342 }
343 
344 // Compute SimHit distance from FrontEnd
346  const DTWireId& wireId,
347  const PSimHit& hit) const {
348  LocalPoint entryP = hit.entryPoint();
349  LocalPoint exitP = hit.exitPoint();
350  float wireLenght = layer->specificTopology().cellLenght();
351  // FIXME: should take only wireLenght/2.;
352  // moreover, pos+cellLenght/2. is shorter than the distance from FE.
353  // In fact it would make more sense to make plots vs y.
354  return (entryP.y()+exitP.y())/2.+wireLenght;
355 }
356 
357 
358 // Find the RecHit closest to the muon SimHit
359 template <typename type>
360 const type*
362  const DTWireId& wireId,
363  const vector<type>& recHits,
364  const float simHitDist) const {
365  float res = 99999;
366  const type* theBestRecHit = nullptr;
367  // Loop over RecHits within the cell
368  for (auto recHit = recHits.begin();
369  recHit != recHits.end();
370  recHit++) {
371  float distTmp = recHitDistFromWire(*recHit, layer);
372  if (fabs(distTmp-simHitDist) < res) {
373  res = fabs(distTmp-simHitDist);
374  theBestRecHit = &(*recHit);
375  }
376  } // End of loop over RecHits within the cell
377 
378  return theBestRecHit;
379 }
380 
381 
382 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
383 float
384 DTRecHitQuality::recHitDistFromWire(const DTRecHit1DPair& hitPair, const DTLayer* layer) const {
385  // Compute the rechit distance from wire
386  return fabs(hitPair.localPosition(DTEnums::Left).x() -
387  hitPair.localPosition(DTEnums::Right).x())/2.;
388 }
389 
390 
391 
392 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
393 float
395  return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
396 }
397 
398 
399 template <typename type>
401  const std::map<DTWireId, std::vector<PSimHit>>& simHitsPerWire,
402  const std::map<DTWireId, std::vector<type>>& recHitsPerWire,
403  Histograms const& histograms, int step) const {
404  // Loop over cells with a muon SimHit
405  for (const auto & wireAndSHits : simHitsPerWire) {
406  DTWireId wireId = wireAndSHits.first;
407  int wheel = wireId.wheel();
408  int sl = wireId.superLayer();
409 
410  vector<PSimHit> simHitsInCell = wireAndSHits.second;
411 
412  // Get the layer
413  const DTLayer* layer = dtGeom->layer(wireId);
414 
415  // Look for a mu hit in the cell
416  const PSimHit* muSimHit = DTHitQualityUtils::findMuSimHit(simHitsInCell);
417  if (muSimHit == nullptr) {
418  if (debug_) {
419  cout << " No mu SimHit in channel: " << wireId << ", skipping! " << endl;
420 }
421  continue; // Skip this cell
422  }
423 
424  // Find the distance of the simhit from the wire
425  float simHitWireDist = simHitDistFromWire(layer, wireId, *muSimHit);
426  // Skip simhits out of the cell
427  if (simHitWireDist>2.1) {
428  if (debug_) {
429  cout << " [DTRecHitQuality]###Warning: The mu SimHit in out of the cell, skipping!" << endl;
430 }
431  continue; // Skip this cell
432  }
433  GlobalPoint simHitGlobalPos = layer->toGlobal(muSimHit->localPosition());
434 
435  // find SH impact angle
436  float simHitTheta = simHitImpactAngle(layer, wireId, *muSimHit);
437 
438  // find SH distance from FE
439  float simHitFEDist = simHitDistFromFE(layer, wireId, *muSimHit);
440 
441  bool recHitReconstructed = false;
442 
443  // Look for RecHits in the same cell
444  if (recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
445  // No RecHit found in this cell
446  if (debug_) {
447  cout << " No RecHit found at Step: " << step << " in cell: " << wireId << endl;
448 }
449  } else {
450  recHitReconstructed = true;
451  // vector<type> recHits = (*wireAndRecHits).second;
452  const vector<type>& recHits = recHitsPerWire.at(wireId);
453  if (debug_) {
454  cout << " " << recHits.size() << " RecHits, Step " << step << " in channel: " << wireId << endl;
455 }
456 
457  // Find the best RecHit
458  const type* theBestRecHit = findBestRecHit(layer, wireId, recHits, simHitWireDist);
459 
460 
461  float recHitWireDist = recHitDistFromWire(*theBestRecHit, layer);
462  if (debug_) {
463  cout << " SimHit distance from wire: " << simHitWireDist << endl
464  << " SimHit distance from FE: " << simHitFEDist << endl
465  << " SimHit angle in layer RF: " << simHitTheta << endl
466  << " RecHit distance from wire: " << recHitWireDist << endl;
467 }
468  float recHitErr = recHitPositionError(*theBestRecHit);
469  HRes1DHit *hRes = nullptr;
470  HRes1DHit *hResTot = nullptr;
471 
472  // Mirror angle in phi so that + and - wheels can be plotted together
473  if (mirrorMinusWheels && wheel<0 && sl!= 2) {
474  simHitTheta *= -1.;
475  // Note: local X, if used, would have to be mirrored as well
476  }
477 
478  // Fill residuals and pulls
479  // Select the histo to be filled
480  if (step == 1) {
481  // Step 1
482  if (sl != 2) {
483  hResTot = histograms.hRes_S1RPhi.get();
484  if (wheel == 0) {
485  hRes = histograms.hRes_S1RPhi_W0.get();
486 }
487  if (abs(wheel) == 1) {
488  hRes = histograms.hRes_S1RPhi_W1.get();
489 }
490  if (abs(wheel) == 2) {
491  hRes = histograms.hRes_S1RPhi_W2.get();
492 }
493  } else {
494  hResTot = histograms.hRes_S1RZ.get();
495  if (wheel == 0) {
496  hRes = histograms.hRes_S1RZ_W0.get();
497 }
498  if (abs(wheel) == 1) {
499  hRes = histograms.hRes_S1RZ_W1.get();
500 }
501  if (abs(wheel) == 2) {
502  hRes = histograms.hRes_S1RZ_W2.get();
503 }
504  }
505 
506  } else if (step == 2) {
507  // Step 2
508  if (sl != 2) {
509  hRes = histograms.hRes_S2RPhi.get();
510  if (wheel == 0) {
511  hRes = histograms.hRes_S2RPhi_W0.get();
512 }
513  if (abs(wheel) == 1) {
514  hRes = histograms.hRes_S2RPhi_W1.get();
515 }
516  if (abs(wheel) == 2) {
517  hRes = histograms.hRes_S2RPhi_W2.get();
518 }
519  } else {
520  hResTot = histograms.hRes_S2RZ.get();
521  if (wheel == 0) {
522  hRes = histograms.hRes_S2RZ_W0.get();
523 }
524  if (abs(wheel) == 1) {
525  hRes = histograms.hRes_S2RZ_W1.get();
526 }
527  if (abs(wheel) == 2) {
528  hRes = histograms.hRes_S2RZ_W2.get();
529 }
530  }
531 
532  } else if (step == 3) {
533  // Step 3
534  if (sl != 2) {
535  hResTot = histograms.hRes_S3RPhi.get();
536  if (wheel == 0) {
537  hRes = histograms.hRes_S3RPhi_W0.get();
538 }
539  if (abs(wheel) == 1) {
540  hRes = histograms.hRes_S3RPhi_W1.get();
541 }
542  if (abs(wheel) == 2) {
543  hRes = histograms.hRes_S3RPhi_W2.get();
544 }
545  if (local_) {
546  histograms.hRes_S3RPhiWS[abs(wheel)][wireId.station()-1]->fill(simHitWireDist, simHitTheta, simHitFEDist, recHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitErr, wireId.station());
547 }
548  } else {
549  hResTot = histograms.hRes_S3RZ.get();
550  if (wheel == 0) {
551  hRes = histograms.hRes_S3RZ_W0.get();
552 }
553  if (abs(wheel) == 1) {
554  hRes = histograms.hRes_S3RZ_W1.get();
555 }
556  if (abs(wheel) == 2) {
557  hRes = histograms.hRes_S3RZ_W2.get();
558 }
559  if (local_) {
560  histograms.hRes_S3RZWS[abs(wheel)][wireId.station()-1]->fill(simHitWireDist, simHitTheta, simHitFEDist, recHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitErr, wireId.station());
561 }
562  }
563  }
564 
565  // Fill
566  hRes->fill(simHitWireDist, simHitTheta, simHitFEDist, recHitWireDist, simHitGlobalPos.eta(),
567  simHitGlobalPos.phi(), recHitErr, wireId.station());
568  if (hResTot != nullptr) {
569  hResTot->fill(simHitWireDist, simHitTheta, simHitFEDist, recHitWireDist, simHitGlobalPos.eta(),
570  simHitGlobalPos.phi(), recHitErr, wireId.station());
571 }
572  }
573 
574  // Fill Efficiencies
575  if (doall_) {
576  HEff1DHit *hEff = nullptr;
577  HEff1DHit *hEffTot = nullptr;
578  if (step == 1) {
579  // Step 1
580  if (sl != 2) {
581  hEff = histograms.hEff_S1RPhi.get();
582  if (local_) { histograms.hEff_S1RPhiWS[abs(wheel)][wireId.station()-1]->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
583 }
584  } else {
585  hEffTot = histograms.hEff_S1RZ.get();
586  if (wheel == 0) {
587  hEff = histograms.hEff_S1RZ_W0.get();
588 }
589  if (abs(wheel) == 1) {
590  hEff = histograms.hEff_S1RZ_W1.get();
591 }
592  if (abs(wheel) == 2) {
593  hEff = histograms.hEff_S1RZ_W2.get();
594 }
595  if (local_) { histograms.hEff_S1RZWS[abs(wheel)][wireId.station()-1]->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
596 }
597  }
598 
599  } else if (step == 2) {
600  // Step 2
601  if (sl != 2) {
602  hEff = histograms.hEff_S2RPhi.get();
603  } else {
604  hEffTot = histograms.hEff_S2RZ.get();
605  if (wheel == 0) {
606  hEff = histograms.hEff_S2RZ_W0.get();
607 }
608  if (abs(wheel) == 1) {
609  hEff = histograms.hEff_S2RZ_W1.get();
610 }
611  if (abs(wheel) == 2) {
612  hEff = histograms.hEff_S2RZ_W2.get();
613 }
614  }
615 
616  } else if (step == 3) {
617  // Step 3
618  if (sl != 2) {
619  hEff = histograms.hEff_S3RPhi.get();
620  if (local_) { histograms.hEff_S3RPhiWS[abs(wheel)][wireId.station()-1]->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
621 }
622  } else {
623  hEffTot = histograms.hEff_S3RZ.get();
624  if (wheel == 0) {
625  hEff = histograms.hEff_S3RZ_W0.get();
626 }
627  if (abs(wheel) == 1) {
628  hEff = histograms.hEff_S3RZ_W1.get();
629 }
630  if (abs(wheel) == 2) {
631  hEff = histograms.hEff_S3RZ_W2.get();
632 }
633  if (local_) { histograms.hEff_S3RZWS[abs(wheel)][wireId.station()-1]->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
634 }
635  }
636 
637  }
638  // Fill
639  hEff->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
640  if (hEffTot != nullptr) {
641  hEffTot->fill(simHitWireDist, simHitGlobalPos.eta(), simHitGlobalPos.phi(), recHitReconstructed);
642 }
643  }
644  }
645 }
646 
647 // Return the error on the measured (cm) coordinate
649  return sqrt(recHit.localPositionError(DTEnums::Left).xx());
650 }
651 
652 // Return the error on the measured (cm) coordinate
654  return sqrt(recHit.localPositionError().xx());
655 }
656 
657 // 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::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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:133
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:1
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
#define constexpr
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:38
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::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
std::unique_ptr< HRes1DHit > hRes_S1RZ_W2
Local3DPoint localPosition() const
Definition: PSimHit.h:44
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:46
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:81
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:63
std::unique_ptr< HRes1DHit > hRes_S3RZ_W0
void fill(float distSimHit, float etaSimHit, float phiSimHit, bool fillRecHit)
Definition: Histograms.h:148
LocalPoint localPosition() const override
step
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:109
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:35
float recHitPositionError(const DTRecHit1DPair &recHit) const
std::unique_ptr< HEff1DHit > hEff_S3RZ_W2
std::unique_ptr< HEff1DHit > hEff_S1RPhi
std::unique_ptr< HRes1DHit > hRes_S3RPhi_W1
Definition: event.py:1
Definition: Run.h:44
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