CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonDetLayerMeasurements.cc
Go to the documentation of this file.
1 
14 
17 
21 
24 
26  edm::InputTag csclabel,
27  edm::InputTag rpclabel,
28  edm::InputTag gemlabel,
29  edm::InputTag me0label,
31  bool enableDT,
32  bool enableCSC,
33  bool enableRPC,
34  bool enableGEM,
35  bool enableME0)
36  : enableDTMeasurement(enableDT),
37  enableCSCMeasurement(enableCSC),
38  enableRPCMeasurement(enableRPC),
39  enableGEMMeasurement(enableGEM),
40  enableME0Measurement(enableME0),
41  theDTRecHits(),
42  theCSCRecHits(),
43  theRPCRecHits(),
44  theGEMRecHits(),
45  theDTEventCacheID(0),
46  theCSCEventCacheID(0),
47  theRPCEventCacheID(0),
48  theGEMEventCacheID(0),
49  theME0EventCacheID(0),
50  theEvent(nullptr) {
52  cscToken_ = iC.consumes<CSCSegmentCollection>(csclabel);
53  rpcToken_ = iC.consumes<RPCRecHitCollection>(rpclabel);
54  gemToken_ = iC.consumes<GEMRecHitCollection>(gemlabel);
55  me0Token_ = iC.consumes<ME0SegmentCollection>(me0label);
56 
57  static std::atomic<int> procInstance{0};
58  std::ostringstream sDT;
59  sDT << "MuonDetLayerMeasurements::checkDTRecHits::" << procInstance;
60  // theDTCheckName = sDT.str();
61  std::ostringstream sRPC;
62  sRPC << "MuonDetLayerMeasurements::checkRPCRecHits::" << procInstance;
63  //theRPCCheckName = sRPC.str();
64  std::ostringstream sCSC;
65  sCSC << "MuonDetLayerMeasurements::checkCSCRecHits::" << procInstance;
66  //theCSCCheckName = sCSC.str();
67  std::ostringstream sGEM;
68  sGEM << "MuonDetLayerMeasurements::checkGEMRecHits::" << procInstance;
69  //theGEMCheckName = sGEM.str();
70  std::ostringstream sME0;
71  sME0 << "MuonDetLayerMeasurements::checkME0RecHits::" << procInstance;
72  //theME0CheckName = sME0.str();
73  procInstance++;
74 }
75 
77 
79  DetId geoId = geomDet->geographicalId();
80  theEvent = &iEvent;
82 
83  if (geoId.subdetId() == MuonSubdetId::DT) {
84  if (enableDTMeasurement) {
86 
87  // Create the ChamberId
88  DTChamberId chamberId(geoId.rawId());
89  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(DT): " << chamberId << std::endl;
90 
91  // Get the DT-Segment which relies on this chamber
93 
94  // Create the MuonTransientTrackingRechit
95  for (DTRecSegment4DCollection::const_iterator rechit = range.first; rechit != range.second; ++rechit)
96  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet, &*rechit));
97  }
98  }
99 
100  else if (geoId.subdetId() == MuonSubdetId::CSC) {
101  if (enableCSCMeasurement) {
102  checkCSCRecHits();
103 
104  // Create the chamber Id
105  CSCDetId chamberId(geoId.rawId());
106  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(CSC): " << chamberId << std::endl;
107 
108  // Get the CSC-Segment which relies on this chamber
110 
111  // Create the MuonTransientTrackingRecHit
112  for (CSCSegmentCollection::const_iterator rechit = range.first; rechit != range.second; ++rechit)
113  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet, &*rechit));
114  }
115  }
116 
117  else if (geoId.subdetId() == MuonSubdetId::RPC) {
118  if (enableRPCMeasurement) {
119  checkRPCRecHits();
120 
121  // Create the chamber Id
122  RPCDetId chamberId(geoId.rawId());
123  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(RPC): " << chamberId << std::endl;
124 
125  // Get the RPC-Segment which relies on this chamber
127 
128  // Create the MuonTransientTrackingRecHit
129  for (RPCRecHitCollection::const_iterator rechit = range.first; rechit != range.second; ++rechit)
130  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet, &*rechit));
131  }
132  } else if (geoId.subdetId() == MuonSubdetId::GEM) {
133  if (enableGEMMeasurement) {
134  checkGEMRecHits();
135 
136  // Create the chamber Id
137  GEMDetId chamberId(geoId.rawId());
138 
139  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(GEM): " << chamberId << std::endl;
140 
141  // Get the GEM-Segment which relies on this chamber
143 
144  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements")
145  << "Number of GEM rechits available = " << theGEMRecHits->size() << ", from chamber: " << chamberId
146  << std::endl;
147 
148  // Create the MuonTransientTrackingRecHit
149  for (GEMRecHitCollection::const_iterator rechit = range.first; rechit != range.second; ++rechit)
150  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet, &*rechit));
151  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Number of GEM rechits = " << result.size() << std::endl;
152  }
153  }
154 
155  else if (geoId.subdetId() == MuonSubdetId::ME0) {
156  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(ME0): identified" << std::endl;
157  if (enableME0Measurement) {
158  checkME0RecHits();
159 
160  // Create the chamber Id
161  ME0DetId chamberId(geoId.rawId());
162 
163  // Get the ME0-Segment which relies on this chamber
164  // Getting rechits right now, not segments - maybe it should be segments?
166 
167  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements")
168  << "Number of ME0 rechits available = " << theME0RecHits->size() << ", from chamber: " << chamberId
169  << std::endl;
170 
171  // Create the MuonTransientTrackingRecHit
172  for (ME0SegmentCollection::const_iterator rechit = range.first; rechit != range.second; ++rechit) {
173  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "On ME0 iteration " << std::endl;
174  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet, &*rechit));
175  }
176  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Number of ME0 rechits = " << result.size() << std::endl;
177  }
178  } else {
179  // wrong type
180  throw cms::Exception("MuonDetLayerMeasurements") << "The DetLayer with det " << geoId.det() << " subdet "
181  << geoId.subdetId() << " is not a valid Muon DetLayer. ";
182  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "The DetLayer with det " << geoId.det() << " subdet "
183  << geoId.subdetId() << " is not a valid Muon DetLayer. ";
184  }
185  if (enableME0Measurement) {
186  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(ME0): enabled" << std::endl;
187  }
188 
189  if (enableGEMMeasurement) {
190  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(GEM): enabled" << std::endl;
191  }
192  return result;
193 }
194 
196  checkEvent();
197  auto const cacheID = theEvent->cacheIdentifier();
198  if (cacheID == theDTEventCacheID)
199  return;
200 
202  if (!theDTRecHits.isValid()) {
203  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get DT RecHits";
204  }
205 }
206 
208  checkEvent();
209  auto cacheID = theEvent->cacheIdentifier();
210  if (cacheID == theCSCEventCacheID)
211  return;
212 
213  {
215  theCSCEventCacheID = cacheID;
216  }
217  if (!theCSCRecHits.isValid()) {
218  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get CSC RecHits";
219  }
220 }
221 
223  checkEvent();
224  auto cacheID = theEvent->cacheIdentifier();
225  if (cacheID == theRPCEventCacheID)
226  return;
227 
228  {
230  theRPCEventCacheID = cacheID;
231  }
232  if (!theRPCRecHits.isValid()) {
233  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get RPC RecHits";
234  }
235 }
236 
238  checkEvent();
239  auto cacheID = theEvent->cacheIdentifier();
240  if (cacheID == theGEMEventCacheID)
241  return;
242 
243  {
245  theGEMEventCacheID = cacheID;
246  }
247  if (!theGEMRecHits.isValid()) {
248  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get GEM RecHits";
249  }
250 }
251 
253  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Checking ME0 RecHits";
254  checkEvent();
255  auto cacheID = theEvent->cacheIdentifier();
256  if (cacheID == theME0EventCacheID)
257  return;
258 
259  {
261  theME0EventCacheID = cacheID;
262  }
263  if (!theME0RecHits.isValid()) {
264  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get ME0 RecHits";
265  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Cannot get ME0 RecHits";
266  }
267 }
268 
271  const TrajectoryStateOnSurface& startingState,
272  const Propagator& prop,
273  const MeasurementEstimator& est) {
274  checkEvent();
275  return measurements(layer, startingState, prop, est, *theEvent);
276 }
277 
279  const TrajectoryStateOnSurface& startingState,
280  const Propagator& prop,
281  const MeasurementEstimator& est,
282  const edm::Event& iEvent) {
284 
285  std::vector<DetWithState> dss = layer->compatibleDets(startingState, prop, est);
286  LogDebug("RecoMuon") << "compatibleDets: " << dss.size() << std::endl;
287 
288  for (std::vector<DetWithState>::const_iterator detWithStateItr = dss.begin(); detWithStateItr != dss.end();
289  ++detWithStateItr) {
290  MeasurementContainer detMeasurements =
291  measurements(layer, detWithStateItr->first, detWithStateItr->second, est, iEvent);
292  result.insert(result.end(), detMeasurements.begin(), detMeasurements.end());
293  }
294 
295  if (!result.empty())
296  sort(result.begin(), result.end(), TrajMeasLessEstim());
297 
298  return result;
299 }
300 
302  const GeomDet* det,
303  const TrajectoryStateOnSurface& stateOnDet,
304  const MeasurementEstimator& est,
305  const edm::Event& iEvent) {
307 
308  DetId geoId = det->geographicalId();
309  //no chamber here that is actually an me0....
310  if (geoId.subdetId() == MuonSubdetId::ME0) {
311  if (enableME0Measurement) {
312  ME0DetId chamberId(geoId.rawId());
313  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements")
314  << "ME0 Chamber ID in measurements: " << chamberId << std::endl;
315  }
316  }
317 
318  // Get the Segments which relies on the GeomDet given by compatibleDets
319  MuonRecHitContainer muonRecHits = recHits(det, iEvent);
320 
321  // Create the Trajectory Measurement
322  for (MuonRecHitContainer::const_iterator rechit = muonRecHits.begin(); rechit != muonRecHits.end(); ++rechit) {
323  MeasurementEstimator::HitReturnType estimate = est.estimate(stateOnDet, **rechit);
324  LogDebug("RecoMuon") << "Dimension: " << (*rechit)->dimension() << " Chi2: " << estimate.second << std::endl;
325  if (estimate.first) {
326  result.push_back(TrajectoryMeasurement(stateOnDet, *rechit, estimate.second, layer));
327  }
328  }
329 
330  if (!result.empty())
331  sort(result.begin(), result.end(), TrajMeasLessEstim());
332 
333  return result;
334 }
335 
337  const TrajectoryStateOnSurface& theStateOnDet,
338  const TrajectoryStateOnSurface& startingState,
339  const Propagator& prop,
340  const MeasurementEstimator& est,
341  const edm::Event& iEvent) {
343  MuonRecHitContainer rhs = recHits(layer, iEvent);
344  for (MuonRecHitContainer::const_iterator irh = rhs.begin(); irh != rhs.end(); irh++) {
345  MeasurementEstimator::HitReturnType estimate = est.estimate(theStateOnDet, (**irh));
346  if (estimate.first) {
347  result.push_back(TrajectoryMeasurement(theStateOnDet, (*irh), estimate.second, layer));
348  }
349  }
350 
351  if (!result.empty()) {
352  sort(result.begin(), result.end(), TrajMeasLessEstim());
353  }
354 
355  return result;
356 }
357 
360  const TrajectoryStateOnSurface& theStateOnDet,
361  const TrajectoryStateOnSurface& startingState,
362  const Propagator& prop,
363  const MeasurementEstimator& est) {
364  checkEvent();
365  return fastMeasurements(layer, theStateOnDet, startingState, prop, est, *theEvent);
366 }
367 
368 std::vector<TrajectoryMeasurementGroup> MuonDetLayerMeasurements::groupedMeasurements(
369  const DetLayer* layer,
370  const TrajectoryStateOnSurface& startingState,
371  const Propagator& prop,
372  const MeasurementEstimator& est) {
373  checkEvent();
374  return groupedMeasurements(layer, startingState, prop, est, *theEvent);
375 }
376 
377 std::vector<TrajectoryMeasurementGroup> MuonDetLayerMeasurements::groupedMeasurements(
378  const DetLayer* layer,
379  const TrajectoryStateOnSurface& startingState,
380  const Propagator& prop,
381  const MeasurementEstimator& est,
382  const edm::Event& iEvent) {
383  std::vector<TrajectoryMeasurementGroup> result;
384  // if we want to use the concept of InvalidRecHits,
385  // we can reuse LayerMeasurements from TrackingTools/MeasurementDet
386  std::vector<DetGroup> groups(layer->groupedCompatibleDets(startingState, prop, est));
387 
388  // this should be fixed either in RecoMuon/MeasurementDet/MuonDetLayerMeasurements or
389  // RecoMuon/DetLayers/MuRingForwardDoubleLayer
390  // and removed the reverse operation in StandAloneMuonFilter::findBestMeasurements
391 
392  for (std::vector<DetGroup>::const_iterator grp = groups.begin(); grp != groups.end(); ++grp) {
393  std::vector<TrajectoryMeasurement> groupMeasurements;
394  for (DetGroup::const_iterator detAndStateItr = grp->begin(); detAndStateItr != grp->end(); ++detAndStateItr) {
395  std::vector<TrajectoryMeasurement> detMeasurements =
396  measurements(layer, detAndStateItr->det(), detAndStateItr->trajectoryState(), est, iEvent);
397  groupMeasurements.insert(groupMeasurements.end(), detMeasurements.begin(), detMeasurements.end());
398  }
399 
400  if (!groupMeasurements.empty())
401  std::sort(groupMeasurements.begin(), groupMeasurements.end(), TrajMeasLessEstim());
402 
403  result.push_back(TrajectoryMeasurementGroup(groupMeasurements, *grp));
404  }
405 
406  return result;
407 }
408 
411 
413  if (!theEvent)
414  throw cms::Exception("MuonDetLayerMeasurements") << "The event has not been set";
415 }
416 
419 
420  std::vector<const GeomDet*> gds = layer->basicComponents();
421 
422  for (std::vector<const GeomDet*>::const_iterator igd = gds.begin(); igd != gds.end(); igd++) {
423  MuonRecHitContainer detHits = recHits(*igd, iEvent);
424  rhs.insert(rhs.end(), detHits.begin(), detHits.end());
425  }
426  return rhs;
427 }
428 
430  checkEvent();
431  return recHits(layer, *theEvent);
432 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::Event::CacheIdentifier_t theME0EventCacheID
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
static constexpr int GEM
Definition: MuonSubdetId.h:14
MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer
virtual std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
edm::Handle< DTRecSegment4DCollection > theDTRecHits
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::Event::CacheIdentifier_t theGEMEventCacheID
edm::Event::CacheIdentifier_t theDTEventCacheID
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::EDGetTokenT< ME0SegmentCollection > me0Token_
edm::EDGetTokenT< DTRecSegment4DCollection > dtToken_
edm::Handle< CSCSegmentCollection > theCSCRecHits
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
edm::EDGetTokenT< CSCSegmentCollection > cscToken_
constexpr std::array< uint8_t, layerIndexSize > layer
const uint16_t range(const Frame &aFrame)
tuple result
Definition: mps_fire.py:311
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
int iEvent
Definition: GenABIO.cc:224
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
edm::Event::CacheIdentifier_t theRPCEventCacheID
CacheIdentifier_t cacheIdentifier() const
Definition: Event.cc:37
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
static constexpr int ME0
Definition: MuonSubdetId.h:15
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
edm::Handle< RPCRecHitCollection > theRPCRecHits
bool isValid() const
Definition: HandleBase.h:70
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
Definition: DetId.h:17
std::vector< TrajectoryMeasurement > MeasurementContainer
static constexpr int RPC
Definition: MuonSubdetId.h:13
edm::Handle< ME0SegmentCollection > theME0RecHits
edm::Event::CacheIdentifier_t theCSCEventCacheID
virtual const std::vector< const GeomDet * > & basicComponents() const =0
edm::EDGetTokenT< GEMRecHitCollection > gemToken_
void setEvent(const edm::Event &)
set event
edm::EDGetTokenT< RPCRecHitCollection > rpcToken_
MuonDetLayerMeasurements(edm::InputTag dtlabel, edm::InputTag csclabel, edm::InputTag rpclabel, edm::InputTag gemlabel, edm::InputTag me0label, edm::ConsumesCollector &iC, bool enableDT=true, bool enableCSC=true, bool enableRPC=true, bool enableGEM=true, bool enableME0=true)
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
std::pair< bool, double > HitReturnType
void checkEvent() const
check that the event is set, and throw otherwise
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
std::vector< MuonRecHitPointer > MuonRecHitContainer
edm::Handle< GEMRecHitCollection > theGEMRecHits
MeasurementContainer fastMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &theStateOnDet, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
faster version in case the TrajectoryState on the surface of the GeomDet is already available ...
#define LogDebug(id)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46