CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonDetLayerMeasurements.cc
Go to the documentation of this file.
1 
12 
15 
19 
20 
21 
24 
25 
26 
28  edm::InputTag csclabel,
29  edm::InputTag rpclabel,
30  edm::InputTag gemlabel,
32  bool enableDT, bool enableCSC, bool enableRPC, bool enableGEM):
33  enableDTMeasurement(enableDT),
34  enableCSCMeasurement(enableCSC),
35  enableRPCMeasurement(enableRPC),
36  enableGEMMeasurement(enableGEM),
37 
38  theDTRecHits(),
39  theCSCRecHits(),
40  theRPCRecHits(),
41  theGEMRecHits(),
42  theDTEventCacheID(0),
43  theCSCEventCacheID(0),
44  theRPCEventCacheID(0),
45  theGEMEventCacheID(0),
46  theEvent(0)
47 {
48 
50  cscToken_ = iC.consumes<CSCSegmentCollection>(csclabel);
51  rpcToken_ = iC.consumes<RPCRecHitCollection>(rpclabel);
52  gemToken_ = iC.consumes<GEMRecHitCollection>(gemlabel);
53 
54  static int procInstance(0);
55  std::ostringstream sDT;
56  sDT<<"MuonDetLayerMeasurements::checkDTRecHits::" << procInstance;
57  // theDTCheckName = sDT.str();
58  std::ostringstream sRPC;
59  sRPC<<"MuonDetLayerMeasurements::checkRPCRecHits::" << procInstance;
60  //theRPCCheckName = sRPC.str();
61  std::ostringstream sCSC;
62  sCSC<<"MuonDetLayerMeasurements::checkCSCRecHits::" << procInstance;
63  //theCSCCheckName = sCSC.str();
64  std::ostringstream sGEM;
65  sGEM<<"MuonDetLayerMeasurements::checkGEMRecHits::" << procInstance;
66  //theGEMCheckName = sGEM.str();
67  procInstance++;
68 }
69 
71 
73  const edm::Event& iEvent)
74 {
75  DetId geoId = geomDet->geographicalId();
76  theEvent = &iEvent;
78 
79  if (geoId.subdetId() == MuonSubdetId::DT) {
81  {
83 
84  // Create the ChamberId
85  DTChamberId chamberId(geoId.rawId());
86  // LogTrace("Muon|RecoMuon|MuonDetLayerMeasurements") << "(DT): "<<chamberId<<std::endl;
87 
88  // Get the DT-Segment which relies on this chamber
89  DTRecSegment4DCollection::range range = theDTRecHits->get(chamberId);
90 
91  // Create the MuonTransientTrackingRechit
92  for (DTRecSegment4DCollection::const_iterator rechit = range.first;
93  rechit!=range.second;++rechit)
94  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
95  }
96  }
97 
98  else if (geoId.subdetId() == MuonSubdetId::CSC) {
100  {
101  checkCSCRecHits();
102 
103  // Create the chamber Id
104  CSCDetId chamberId(geoId.rawId());
105  // LogTrace("Muon|RecoMuon|MuonDetLayerMeasurements") << "(CSC): "<<chamberId<<std::endl;
106 
107  // Get the CSC-Segment which relies on this chamber
108  CSCSegmentCollection::range range = theCSCRecHits->get(chamberId);
109 
110  // Create the MuonTransientTrackingRecHit
111  for (CSCSegmentCollection::const_iterator rechit = range.first;
112  rechit!=range.second; ++rechit)
113  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
114  }
115  }
116 
117  else if (geoId.subdetId() == MuonSubdetId::RPC) {
119  {
120  checkRPCRecHits();
121 
122  // Create the chamber Id
123  RPCDetId chamberId(geoId.rawId());
124  // LogTrace("Muon|RecoMuon|MuonDetLayerMeasurements") << "(RPC): "<<chamberId<<std::endl;
125 
126  // Get the RPC-Segment which relies on this chamber
127  RPCRecHitCollection::range range = theRPCRecHits->get(chamberId);
128 
129  // Create the MuonTransientTrackingRecHit
130  for (RPCRecHitCollection::const_iterator rechit = range.first;
131  rechit!=range.second; ++rechit)
132  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
133  }
134  }
135 
136  else if (geoId.subdetId() == MuonSubdetId::GEM) {
138  {
139  checkGEMRecHits();
140 
141  // Create the chamber Id
142  GEMDetId chamberId(geoId.rawId());
143 
144  // LogTrace("Muon|RecoMuon|MuonDetLayerMeasurements") << "(GEM): "<<chamberId<<std::endl;
145 
146  // Get the GEM-Segment which relies on this chamber
147  GEMRecHitCollection::range range = theGEMRecHits->get(chamberId);
148 
149  // Create the MuonTransientTrackingRecHit
150  for (GEMRecHitCollection::const_iterator rechit = range.first;
151  rechit!=range.second; ++rechit)
152  result.push_back(MuonTransientTrackingRecHit::specificBuild(geomDet,&*rechit));
153  }
154  }
155 
156  else {
157  // wrong type
158  throw cms::Exception("MuonDetLayerMeasurements") << "The DetLayer with det " << geoId.det() << " subdet " << geoId.subdetId() << " is not a valid Muon DetLayer. ";
159  }
160  return result;
161 }
162 
163 
165 {
166  checkEvent();
167  auto const cacheID = theEvent->cacheIdentifier();
168  if (cacheID == theDTEventCacheID) return;
169 
170  {
172  }
173  if(!theDTRecHits.isValid())
174  {
175  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get DT RecHits";
176  }
177 }
178 
179 
181 {
182  checkEvent();
183  auto cacheID = theEvent->cacheIdentifier();
184  if (cacheID == theCSCEventCacheID) return;
185 
186  {
188  theCSCEventCacheID = cacheID;
189  }
190  if(!theCSCRecHits.isValid())
191  {
192  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get CSC RecHits";
193  }
194 }
195 
196 
198 {
199  checkEvent();
200  auto cacheID = theEvent->cacheIdentifier();
201  if (cacheID == theRPCEventCacheID) return;
202 
203  {
205  theRPCEventCacheID = cacheID;
206  }
207  if(!theRPCRecHits.isValid())
208  {
209  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get RPC RecHits";
210  }
211 }
212 
214 {
215  checkEvent();
216  auto cacheID = theEvent->cacheIdentifier();
217  if (cacheID == theGEMEventCacheID) return;
218 
219  {
221  theGEMEventCacheID = cacheID;
222  }
223  if(!theGEMRecHits.isValid())
224  {
225  throw cms::Exception("MuonDetLayerMeasurements") << "Cannot get GEM RecHits";
226  }
227 }
228 
232  const TrajectoryStateOnSurface& startingState,
233  const Propagator& prop,
234  const MeasurementEstimator& est) {
235  checkEvent();
236  return measurements(layer, startingState, prop, est, *theEvent);
237 }
238 
239 
242  const TrajectoryStateOnSurface& startingState,
243  const Propagator& prop,
244  const MeasurementEstimator& est,
245  const edm::Event& iEvent) {
246 
248 
249  std::vector<DetWithState> dss = layer->compatibleDets(startingState, prop, est);
250  LogTrace("RecoMuon")<<"compatibleDets: "<<dss.size()<<std::endl;
251 
252  for(std::vector<DetWithState>::const_iterator detWithStateItr = dss.begin();
253  detWithStateItr != dss.end(); ++detWithStateItr){
254 
255  MeasurementContainer detMeasurements
256  = measurements(layer, detWithStateItr->first,
257  detWithStateItr->second, est, iEvent);
258  result.insert(result.end(), detMeasurements.begin(), detMeasurements.end());
259  }
260 
261  if (!result.empty()) sort( result.begin(), result.end(), TrajMeasLessEstim());
262 
263  return result;
264 }
265 
266 
269  const GeomDet* det,
270  const TrajectoryStateOnSurface& stateOnDet,
271  const MeasurementEstimator& est,
272  const edm::Event& iEvent) {
274 
275  // Get the Segments which relies on the GeomDet given by compatibleDets
276  MuonRecHitContainer muonRecHits = recHits(det, iEvent);
277 
278  // Create the Trajectory Measurement
279  for(MuonRecHitContainer::const_iterator rechit = muonRecHits.begin();
280  rechit != muonRecHits.end(); ++rechit) {
281 
282  MeasurementEstimator::HitReturnType estimate = est.estimate(stateOnDet,**rechit);
283  LogTrace("RecoMuon")<<"Dimension: "<<(*rechit)->dimension()
284  <<" Chi2: "<<estimate.second<<std::endl;
285  if (estimate.first) {
286  result.push_back(TrajectoryMeasurement(stateOnDet, *rechit,
287  estimate.second,layer));
288  }
289  }
290 
291  if (!result.empty()) sort( result.begin(), result.end(), TrajMeasLessEstim());
292 
293  return result;
294 }
295 
296 
297 
300  const TrajectoryStateOnSurface& theStateOnDet,
301  const TrajectoryStateOnSurface& startingState,
302  const Propagator& prop,
303  const MeasurementEstimator& est,
304  const edm::Event& iEvent) {
306  MuonRecHitContainer rhs = recHits(layer, iEvent);
307  for (MuonRecHitContainer::const_iterator irh = rhs.begin(); irh!=rhs.end(); irh++) {
308  MeasurementEstimator::HitReturnType estimate = est.estimate(theStateOnDet, (**irh));
309  if (estimate.first)
310  {
311  result.push_back(TrajectoryMeasurement(theStateOnDet,(*irh),
312  estimate.second,layer));
313  }
314  }
315 
316  if (!result.empty()) {
317  sort( result.begin(), result.end(), TrajMeasLessEstim());
318  }
319 
320  return result;
321 }
322 
326  const TrajectoryStateOnSurface& theStateOnDet,
327  const TrajectoryStateOnSurface& startingState,
328  const Propagator& prop,
329  const MeasurementEstimator& est) {
330  checkEvent();
331  return fastMeasurements(layer, theStateOnDet, startingState, prop, est, *theEvent);
332 }
333 
334 
335 std::vector<TrajectoryMeasurementGroup>
337  const TrajectoryStateOnSurface& startingState,
338  const Propagator& prop,
339  const MeasurementEstimator& est) {
340  checkEvent();
341  return groupedMeasurements(layer, startingState, prop, est, *theEvent);
342 }
343 
344 
345 std::vector<TrajectoryMeasurementGroup>
347  const TrajectoryStateOnSurface& startingState,
348  const Propagator& prop,
349  const MeasurementEstimator& est,
350  const edm::Event& iEvent) {
351 
352  std::vector<TrajectoryMeasurementGroup> result;
353  // if we want to use the concept of InvalidRecHits,
354  // we can reuse LayerMeasurements from TrackingTools/MeasurementDet
355  std::vector<DetGroup> groups(layer->groupedCompatibleDets(startingState, prop, est));
356 
357  // this should be fixed either in RecoMuon/MeasurementDet/MuonDetLayerMeasurements or
358  // RecoMuon/DetLayers/MuRingForwardDoubleLayer
359  // and removed the reverse operation in StandAloneMuonFilter::findBestMeasurements
360 
361  for (std::vector<DetGroup>::const_iterator grp=groups.begin(); grp!=groups.end(); ++grp) {
362 
363  std::vector<TrajectoryMeasurement> groupMeasurements;
364  for (DetGroup::const_iterator detAndStateItr=grp->begin();
365  detAndStateItr !=grp->end(); ++detAndStateItr) {
366 
367  std::vector<TrajectoryMeasurement> detMeasurements
368  = measurements(layer, detAndStateItr->det(), detAndStateItr->trajectoryState(), est, iEvent);
369  groupMeasurements.insert(groupMeasurements.end(), detMeasurements.begin(), detMeasurements.end());
370  }
371 
372  if (!groupMeasurements.empty())
373  std::sort( groupMeasurements.begin(), groupMeasurements.end(), TrajMeasLessEstim());
374 
375  result.push_back(TrajectoryMeasurementGroup(groupMeasurements, *grp));
376  }
377 
378  return result;
379 }
380 
383  theEvent = &event;
384 }
385 
386 
388  if(!theEvent)
389  throw cms::Exception("MuonDetLayerMeasurements") << "The event has not been set";
390 }
391 
393  const edm::Event& iEvent) {
395 
396  std::vector <const GeomDet*> gds = layer->basicComponents();
397 
398  for (std::vector<const GeomDet*>::const_iterator igd = gds.begin();
399  igd != gds.end(); igd++) {
400  MuonRecHitContainer detHits = recHits(*igd, iEvent);
401  rhs.insert(rhs.end(), detHits.begin(), detHits.end());
402  }
403  return rhs;
404 }
405 
407 {
408  checkEvent();
409  return recHits(layer, *theEvent);
410 }
411 
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
MuonDetLayerMeasurements(edm::InputTag dtlabel, edm::InputTag csclabel, edm::InputTag rpclabel, edm::InputTag gemlabel, edm::ConsumesCollector &iC, bool enableDT=true, bool enableCSC=true, bool enableRPC=true, bool enableGEM=true)
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:464
edm::Event::CacheIdentifier_t theGEMEventCacheID
edm::Event::CacheIdentifier_t theDTEventCacheID
static const int GEM
Definition: MuonSubdetId.h:15
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_
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
static const int CSC
Definition: MuonSubdetId.h:13
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
edm::Event::CacheIdentifier_t theRPCEventCacheID
tuple result
Definition: query.py:137
CacheIdentifier_t cacheIdentifier() const
Definition: Event.cc:32
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
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:75
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
#define LogTrace(id)
Definition: DetId.h:18
std::pair< bool, double > HitReturnType
std::vector< TrajectoryMeasurement > MeasurementContainer
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_
static const int RPC
Definition: MuonSubdetId.h:14
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
static const int DT
Definition: MuonSubdetId.h:12
void checkEvent() const
check that the event is set, and throw otherwise
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
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 ...