CMS 3D CMS Logo

MuonDetLayerMeasurements.cc
Go to the documentation of this file.
1 
14 
17 
21 
22 
23 
26 
27 
28 
30  edm::InputTag csclabel,
31  edm::InputTag rpclabel,
32  edm::InputTag gemlabel,
33  edm::InputTag me0label,
35  bool enableDT, bool enableCSC, bool enableRPC, bool enableGEM, 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)
51 {
52 
54  cscToken_ = iC.consumes<CSCSegmentCollection>(csclabel);
55  rpcToken_ = iC.consumes<RPCRecHitCollection>(rpclabel);
56  gemToken_ = iC.consumes<GEMRecHitCollection>(gemlabel);
57  me0Token_ = iC.consumes<ME0SegmentCollection>(me0label);
58 
59  static std::atomic<int> procInstance{0};
60  std::ostringstream sDT;
61  sDT<<"MuonDetLayerMeasurements::checkDTRecHits::" << procInstance;
62  // theDTCheckName = sDT.str();
63  std::ostringstream sRPC;
64  sRPC<<"MuonDetLayerMeasurements::checkRPCRecHits::" << procInstance;
65  //theRPCCheckName = sRPC.str();
66  std::ostringstream sCSC;
67  sCSC<<"MuonDetLayerMeasurements::checkCSCRecHits::" << procInstance;
68  //theCSCCheckName = sCSC.str();
69  std::ostringstream sGEM;
70  sGEM<<"MuonDetLayerMeasurements::checkGEMRecHits::" << procInstance;
71  //theGEMCheckName = sGEM.str();
72  std::ostringstream sME0;
73  sME0<<"MuonDetLayerMeasurements::checkME0RecHits::" << procInstance;
74  //theME0CheckName = sME0.str();
75  procInstance++;
76 }
77 
79 
81  const edm::Event& iEvent)
82 {
83  DetId geoId = geomDet->geographicalId();
84  theEvent = &iEvent;
86 
87  if (geoId.subdetId() == MuonSubdetId::DT) {
89  {
91 
92  // Create the ChamberId
93  DTChamberId chamberId(geoId.rawId());
94  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(DT): "<<chamberId<<std::endl;
95 
96  // Get the DT-Segment which relies on this chamber
97  DTRecSegment4DCollection::range range = theDTRecHits->get(chamberId);
98 
99  // Create the MuonTransientTrackingRechit
100  for (DTRecSegment4DCollection::const_iterator rechit = range.first;
101  rechit!=range.second;++rechit)
102  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
103  }
104  }
105 
106  else if (geoId.subdetId() == MuonSubdetId::CSC) {
108  {
109  checkCSCRecHits();
110 
111  // Create the chamber Id
112  CSCDetId chamberId(geoId.rawId());
113  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(CSC): "<<chamberId<<std::endl;
114 
115  // Get the CSC-Segment which relies on this chamber
116  CSCSegmentCollection::range range = theCSCRecHits->get(chamberId);
117 
118  // Create the MuonTransientTrackingRecHit
119  for (CSCSegmentCollection::const_iterator rechit = range.first;
120  rechit!=range.second; ++rechit)
121  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
122  }
123  }
124 
125  else if (geoId.subdetId() == MuonSubdetId::RPC) {
127  {
128  checkRPCRecHits();
129 
130  // Create the chamber Id
131  RPCDetId chamberId(geoId.rawId());
132  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(RPC): "<<chamberId<<std::endl;
133 
134  // Get the RPC-Segment which relies on this chamber
135  RPCRecHitCollection::range range = theRPCRecHits->get(chamberId);
136 
137  // Create the MuonTransientTrackingRecHit
138  for (RPCRecHitCollection::const_iterator rechit = range.first;
139  rechit!=range.second; ++rechit)
140  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
141  }
142  }
143  else if (geoId.subdetId() == MuonSubdetId::GEM) {
145  {
146  checkGEMRecHits();
147 
148  // Create the chamber Id
149  GEMDetId chamberId(geoId.rawId());
150 
151  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(GEM): "<<chamberId<<std::endl;
152 
153  // Get the GEM-Segment which relies on this chamber
154  GEMRecHitCollection::range range = theGEMRecHits->get(chamberId);
155 
156  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Number of GEM rechits available = " << theGEMRecHits->size()
157  <<", from chamber: "<< chamberId<<std::endl;
158 
159  // Create the MuonTransientTrackingRecHit
160  for (GEMRecHitCollection::const_iterator rechit = range.first;
161  rechit!=range.second; ++rechit)
162  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
163  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Number of GEM rechits = " << result.size()<<std::endl;
164  }
165  }
166 
167  else if (geoId.subdetId() == MuonSubdetId::ME0) {
168  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(ME0): identified"<<std::endl;
170  {
171  checkME0RecHits();
172 
173  // Create the chamber Id
174  ME0DetId chamberId(geoId.rawId());
175 
176  // Get the ME0-Segment which relies on this chamber
177  // Getting rechits right now, not segments - maybe it should be segments?
178  ME0SegmentCollection::range range = theME0RecHits->get(chamberId);
179 
180  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Number of ME0 rechits available = " << theME0RecHits->size()
181  <<", from chamber: "<< chamberId<<std::endl;
182 
183  // Create the MuonTransientTrackingRecHit
184  for (ME0SegmentCollection::const_iterator rechit = range.first;
185  rechit!=range.second; ++rechit){
186  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "On ME0 iteration " <<std::endl;
187  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
188  }
189  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Number of ME0 rechits = " << result.size()<<std::endl;
190  }
191  }
192  else {
193  // wrong type
194  throw cms::Exception("MuonDetLayerMeasurements") << "The DetLayer with det " << geoId.det() << " subdet " << geoId.subdetId() << " is not a valid Muon DetLayer. ";
195  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements")<< "The DetLayer with det " << geoId.det() << " subdet " << geoId.subdetId() << " is not a valid Muon DetLayer. ";
196  }
198  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(ME0): enabled"<<std::endl;
199  }
200 
202  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "(GEM): enabled"<<std::endl;
203  }
204  return result;
205 }
206 
207 
209 {
210  checkEvent();
211  auto const cacheID = theEvent->cacheIdentifier();
212  if (cacheID == theDTEventCacheID) return;
213 
214  {
216  }
217  if(!theDTRecHits.isValid())
218  {
219  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get DT RecHits";
220  }
221 }
222 
223 
225 {
226  checkEvent();
227  auto cacheID = theEvent->cacheIdentifier();
228  if (cacheID == theCSCEventCacheID) return;
229 
230  {
232  theCSCEventCacheID = cacheID;
233  }
234  if(!theCSCRecHits.isValid())
235  {
236  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get CSC RecHits";
237  }
238 }
239 
240 
242 {
243  checkEvent();
244  auto cacheID = theEvent->cacheIdentifier();
245  if (cacheID == theRPCEventCacheID) return;
246 
247  {
249  theRPCEventCacheID = cacheID;
250  }
251  if(!theRPCRecHits.isValid())
252  {
253  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get RPC RecHits";
254  }
255 }
256 
258 {
259  checkEvent();
260  auto cacheID = theEvent->cacheIdentifier();
261  if (cacheID == theGEMEventCacheID) return;
262 
263  {
265  theGEMEventCacheID = cacheID;
266  }
267  if(!theGEMRecHits.isValid())
268  {
269  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get GEM RecHits";
270  }
271 }
272 
274 {
275  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Checking ME0 RecHits";
276  checkEvent();
277  auto cacheID = theEvent->cacheIdentifier();
278  if (cacheID == theME0EventCacheID) return;
279 
280  {
282  theME0EventCacheID = cacheID;
283  }
284  if(!theME0RecHits.isValid())
285  {
286  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get ME0 RecHits";
287  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "Cannot get ME0 RecHits";
288  }
289 }
290 
294  const TrajectoryStateOnSurface& startingState,
295  const Propagator& prop,
296  const MeasurementEstimator& est) {
297  checkEvent();
298  return measurements(layer, startingState, prop, est, *theEvent);
299 }
300 
301 
304  const TrajectoryStateOnSurface& startingState,
305  const Propagator& prop,
306  const MeasurementEstimator& est,
307  const edm::Event& iEvent) {
308 
310 
311 
312  std::vector<DetWithState> dss = layer->compatibleDets(startingState, prop, est);
313  LogDebug("RecoMuon")<<"compatibleDets: "<<dss.size()<<std::endl;
314 
315  for(std::vector<DetWithState>::const_iterator detWithStateItr = dss.begin();
316  detWithStateItr != dss.end(); ++detWithStateItr){
317 
318  MeasurementContainer detMeasurements
319  = measurements(layer, detWithStateItr->first,
320  detWithStateItr->second, est, iEvent);
321  result.insert(result.end(), detMeasurements.begin(), detMeasurements.end());
322  }
323 
324  if (!result.empty()) sort( result.begin(), result.end(), TrajMeasLessEstim());
325 
326  return result;
327 }
328 
329 
332  const GeomDet* det,
333  const TrajectoryStateOnSurface& stateOnDet,
334  const MeasurementEstimator& est,
335  const edm::Event& iEvent) {
337 
338  DetId geoId = det->geographicalId();
339  //no chamber here that is actually an me0....
340  if (geoId.subdetId() == MuonSubdetId::ME0) {
342  ME0DetId chamberId(geoId.rawId());
343  LogDebug("Muon|RecoMuon|MuonDetLayerMeasurements") << "ME0 Chamber ID in measurements: "<<chamberId<<std::endl;
344  }
345  }
346 
347 
348  // Get the Segments which relies on the GeomDet given by compatibleDets
349  MuonRecHitContainer muonRecHits = recHits(det, iEvent);
350 
351  // Create the Trajectory Measurement
352  for(MuonRecHitContainer::const_iterator rechit = muonRecHits.begin();
353  rechit != muonRecHits.end(); ++rechit) {
354 
355  MeasurementEstimator::HitReturnType estimate = est.estimate(stateOnDet,**rechit);
356  LogDebug("RecoMuon")<<"Dimension: "<<(*rechit)->dimension()
357  <<" Chi2: "<<estimate.second<<std::endl;
358  if (estimate.first) {
359  result.push_back(TrajectoryMeasurement(stateOnDet, *rechit,
360  estimate.second,layer));
361  }
362  }
363 
364  if (!result.empty()) sort( result.begin(), result.end(), TrajMeasLessEstim());
365 
366  return result;
367 }
368 
369 
370 
373  const TrajectoryStateOnSurface& theStateOnDet,
374  const TrajectoryStateOnSurface& startingState,
375  const Propagator& prop,
376  const MeasurementEstimator& est,
377  const edm::Event& iEvent) {
379  MuonRecHitContainer rhs = recHits(layer, iEvent);
380  for (MuonRecHitContainer::const_iterator irh = rhs.begin(); irh!=rhs.end(); irh++) {
381  MeasurementEstimator::HitReturnType estimate = est.estimate(theStateOnDet, (**irh));
382  if (estimate.first)
383  {
384  result.push_back(TrajectoryMeasurement(theStateOnDet,(*irh),
385  estimate.second,layer));
386  }
387  }
388 
389  if (!result.empty()) {
390  sort( result.begin(), result.end(), TrajMeasLessEstim());
391  }
392 
393  return result;
394 }
395 
399  const TrajectoryStateOnSurface& theStateOnDet,
400  const TrajectoryStateOnSurface& startingState,
401  const Propagator& prop,
402  const MeasurementEstimator& est) {
403  checkEvent();
404  return fastMeasurements(layer, theStateOnDet, startingState, prop, est, *theEvent);
405 }
406 
407 
408 std::vector<TrajectoryMeasurementGroup>
410  const TrajectoryStateOnSurface& startingState,
411  const Propagator& prop,
412  const MeasurementEstimator& est) {
413  checkEvent();
414  return groupedMeasurements(layer, startingState, prop, est, *theEvent);
415 }
416 
417 
418 std::vector<TrajectoryMeasurementGroup>
420  const TrajectoryStateOnSurface& startingState,
421  const Propagator& prop,
422  const MeasurementEstimator& est,
423  const edm::Event& iEvent) {
424 
425  std::vector<TrajectoryMeasurementGroup> result;
426  // if we want to use the concept of InvalidRecHits,
427  // we can reuse LayerMeasurements from TrackingTools/MeasurementDet
428  std::vector<DetGroup> groups(layer->groupedCompatibleDets(startingState, prop, est));
429 
430  // this should be fixed either in RecoMuon/MeasurementDet/MuonDetLayerMeasurements or
431  // RecoMuon/DetLayers/MuRingForwardDoubleLayer
432  // and removed the reverse operation in StandAloneMuonFilter::findBestMeasurements
433 
434  for (std::vector<DetGroup>::const_iterator grp=groups.begin(); grp!=groups.end(); ++grp) {
435 
436  std::vector<TrajectoryMeasurement> groupMeasurements;
437  for (DetGroup::const_iterator detAndStateItr=grp->begin();
438  detAndStateItr !=grp->end(); ++detAndStateItr) {
439 
440  std::vector<TrajectoryMeasurement> detMeasurements
441  = measurements(layer, detAndStateItr->det(), detAndStateItr->trajectoryState(), est, iEvent);
442  groupMeasurements.insert(groupMeasurements.end(), detMeasurements.begin(), detMeasurements.end());
443  }
444 
445  if (!groupMeasurements.empty())
446  std::sort( groupMeasurements.begin(), groupMeasurements.end(), TrajMeasLessEstim());
447 
448  result.push_back(TrajectoryMeasurementGroup(groupMeasurements, *grp));
449  }
450 
451  return result;
452 }
453 
456  theEvent = &event;
457 }
458 
459 
461  if(!theEvent)
462  throw cms::Exception("MuonDetLayerMeasurements") << "The event has not been set";
463 }
464 
466  const edm::Event& iEvent) {
468 
469  std::vector <const GeomDet*> gds = layer->basicComponents();
470 
471  for (std::vector<const GeomDet*>::const_iterator igd = gds.begin();
472  igd != gds.end(); igd++) {
473  MuonRecHitContainer detHits = recHits(*igd, iEvent);
474  rhs.insert(rhs.end(), detHits.begin(), detHits.end());
475  }
476  return rhs;
477 }
478 
480 {
481  checkEvent();
482  return recHits(layer, *theEvent);
483 }
484 
#define LogDebug(id)
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:15
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:517
edm::Event::CacheIdentifier_t theGEMEventCacheID
edm::Event::CacheIdentifier_t theDTEventCacheID
virtual const std::vector< const GeomDet * > & basicComponents() const =0
#define nullptr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
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_
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:35
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
static constexpr int ME0
Definition: MuonSubdetId.h:16
edm::Handle< RPCRecHitCollection > theRPCRecHits
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:74
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
std::pair< bool, double > HitReturnType
Definition: DetId.h:18
std::vector< TrajectoryMeasurement > MeasurementContainer
static constexpr int RPC
Definition: MuonSubdetId.h:14
edm::Handle< ME0SegmentCollection > theME0RecHits
edm::Event::CacheIdentifier_t theCSCEventCacheID
edm::EDGetTokenT< GEMRecHitCollection > gemToken_
void setEvent(const edm::Event &)
set event
edm::EDGetTokenT< RPCRecHitCollection > rpcToken_
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
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)
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
void checkEvent() const
check that the event is set, and throw otherwise
static constexpr int DT
Definition: MuonSubdetId.h:12
static constexpr int CSC
Definition: MuonSubdetId.h:13
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
std::vector< MuonRecHitPointer > MuonRecHitContainer
Definition: event.py:1
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 ...
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39