CMS 3D CMS Logo

TrackDetectorAssociator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackAssociator
4 // Class: TrackDetectorAssociator
5 //
6 /*
7 
8  Description: <one line class summary>
9 
10  Implementation:
11  <Notes on implementation>
12 */
13 //
14 // Original Author: Dmytro Kovalskyi
15 // Created: Fri Apr 21 10:59:41 PDT 2006
16 //
17 //
18 
22 
23 // user include files
25 
33 
43 
44 // calorimeter info
51 
55 
58 
61 
64 
66 
67 
70 
72 #include <stack>
73 #include <set>
74 
76 #include "Math/VectorUtil.h"
77 #include <algorithm>
78 
81 // #include "TrackingTools/TrackAssociator/interface/CaloDetIdAssociator.h"
82 // #include "TrackingTools/TrackAssociator/interface/EcalDetIdAssociator.h"
83 // #include "TrackingTools/TrackAssociator/interface/PreshowerDetIdAssociator.h"
84 
91 
100 
102 
103 using namespace reco;
104 
106 {
107  ivProp_ = 0;
108  defProp_ = 0;
109  useDefaultPropagator_ = false;
110 }
111 
113 {
114  if (defProp_) delete defProp_;
115 }
116 
118 {
119  ivProp_ = ptr;
120  cachedTrajectory_.setPropagator(ivProp_);
121 }
122 
124 {
125  useDefaultPropagator_ = true;
126 }
127 
128 
130 {
131  // access the calorimeter geometry
132  iSetup.get<CaloGeometryRecord>().get(theCaloGeometry_);
133  if (!theCaloGeometry_.isValid())
134  throw cms::Exception("FatalError") << "Unable to find CaloGeometryRecord in event!\n";
135 
136  // get the tracking Geometry
137  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry_);
138  if (!theTrackingGeometry_.isValid())
139  throw cms::Exception("FatalError") << "Unable to find GlobalTrackingGeometryRecord in event!\n";
140 
141  if (useDefaultPropagator_ && (! defProp_ || theMagneticFeildWatcher_.check(iSetup) ) ) {
142  // setup propagator
144  iSetup.get<IdealMagneticFieldRecord>().get(bField);
145 
147  prop->setMaterialMode(false);
148  prop->applyRadX0Correction(true);
149  // prop->setDebug(true); // tmp
150  defProp_ = prop;
151  setPropagator(defProp_);
152  }
153 
154  iSetup.get<DetIdAssociatorRecord>().get("EcalDetIdAssociator", ecalDetIdAssociator_);
155  iSetup.get<DetIdAssociatorRecord>().get("HcalDetIdAssociator", hcalDetIdAssociator_);
156  iSetup.get<DetIdAssociatorRecord>().get("HODetIdAssociator", hoDetIdAssociator_);
157  iSetup.get<DetIdAssociatorRecord>().get("CaloDetIdAssociator", caloDetIdAssociator_);
158  iSetup.get<DetIdAssociatorRecord>().get("MuonDetIdAssociator", muonDetIdAssociator_);
159  iSetup.get<DetIdAssociatorRecord>().get("PreshowerDetIdAssociator", preshowerDetIdAssociator_);
160 }
161 
163  const edm::EventSetup& iSetup,
164  const FreeTrajectoryState& fts,
166 {
167  return associate(iEvent,iSetup,parameters,&fts);
168 }
169 
171  const edm::EventSetup& iSetup,
173  const FreeTrajectoryState* innerState,
174  const FreeTrajectoryState* outerState)
175 {
177  if (! parameters.useEcal && ! parameters.useCalo && ! parameters.useHcal &&
178  ! parameters.useHO && ! parameters.useMuon && !parameters.usePreshower)
179  throw cms::Exception("ConfigurationError") <<
180  "Configuration error! No subdetector was selected for the track association.";
181 
182  SteppingHelixStateInfo trackOrigin(*innerState);
183  info.stateAtIP = *innerState;
184  cachedTrajectory_.setStateAtIP(trackOrigin);
185 
186  init( iSetup );
187  // get track trajectory
188  // ECAL points (EB+EE)
189  // If the phi angle between a track entrance and exit points is more
190  // than 2 crystals, it is possible that the track will cross 3 crystals
191  // and therefore one has to check at least 3 points along the track
192  // trajectory inside ECAL. In order to have a chance to cross 4 crystalls
193  // in the barrel, a track should have P_t as low as 3 GeV or smaller
194  // If it's necessary, number of points along trajectory can be increased
195 
196  info.setCaloGeometry(theCaloGeometry_);
197 
198  cachedTrajectory_.reset_trajectory();
199  // estimate propagation outer boundaries based on
200  // requested sub-detector information. For now limit
201  // propagation region only if muon matching is not
202  // requested.
203  double HOmaxR = hoDetIdAssociator_->volume().maxR();
204  double HOmaxZ = hoDetIdAssociator_->volume().maxZ();
205  double minR = ecalDetIdAssociator_->volume().minR();
206  double minZ = preshowerDetIdAssociator_->volume().minZ();
207  cachedTrajectory_.setMaxHORadius(HOmaxR);
208  cachedTrajectory_.setMaxHOLength(HOmaxZ*2.);
209  cachedTrajectory_.setMinDetectorRadius(minR);
210  cachedTrajectory_.setMinDetectorLength(minZ*2.);
211 
212  if (parameters.useMuon) {
213  double maxR = muonDetIdAssociator_->volume().maxR();
214  double maxZ = muonDetIdAssociator_->volume().maxZ();
215  cachedTrajectory_.setMaxDetectorRadius(maxR);
216  cachedTrajectory_.setMaxDetectorLength(maxZ*2.);
217  }
218  else {
219  cachedTrajectory_.setMaxDetectorRadius(HOmaxR);
220  cachedTrajectory_.setMaxDetectorLength(HOmaxZ*2.);
221  }
222 
223  // If track extras exist and outerState is before HO maximum, then use outerState
224  if (outerState) {
225  if (outerState->position().perp()<HOmaxR && fabs(outerState->position().z())<HOmaxZ) {
226  LogTrace("TrackAssociator") << "Using outerState as trackOrigin at Rho=" << outerState->position().perp()
227  << " Z=" << outerState->position().z() << "\n";
228  trackOrigin = SteppingHelixStateInfo(*outerState);
229  }
230  else if(innerState) {
231  LogTrace("TrackAssociator") << "Using innerState as trackOrigin at Rho=" << innerState->position().perp()
232  << " Z=" << innerState->position().z() << "\n";
233  trackOrigin = SteppingHelixStateInfo(*innerState);
234  }
235  }
236 
237  if ( trackOrigin.momentum().mag() == 0 ) return info;
238  if ( edm::isNotFinite(trackOrigin.momentum().x()) or edm::isNotFinite(trackOrigin.momentum().y()) or edm::isNotFinite(trackOrigin.momentum().z()) ) return info;
239  if ( ! cachedTrajectory_.propagateAll(trackOrigin) ) return info;
240 
241  // get trajectory in calorimeters
242  cachedTrajectory_.findEcalTrajectory( ecalDetIdAssociator_->volume() );
243  cachedTrajectory_.findHcalTrajectory( hcalDetIdAssociator_->volume() );
244  cachedTrajectory_.findHOTrajectory( hoDetIdAssociator_->volume() );
245  cachedTrajectory_.findPreshowerTrajectory( preshowerDetIdAssociator_->volume() );
246 
247  info.trkGlobPosAtEcal = getPoint( cachedTrajectory_.getStateAtEcal().position() );
248  info.trkGlobPosAtHcal = getPoint( cachedTrajectory_.getStateAtHcal().position() );
249  info.trkGlobPosAtHO = getPoint( cachedTrajectory_.getStateAtHO().position() );
250 
251  info.trkMomAtEcal = cachedTrajectory_.getStateAtEcal().momentum();
252  info.trkMomAtHcal = cachedTrajectory_.getStateAtHcal().momentum();
253  info.trkMomAtHO = cachedTrajectory_.getStateAtHO().momentum();
254 
255  if (parameters.useEcal) fillEcal( iEvent, info, parameters);
256  if (parameters.useCalo) fillCaloTowers( iEvent, info, parameters);
257  if (parameters.useHcal) fillHcal( iEvent, info, parameters);
258  if (parameters.useHO) fillHO( iEvent, info, parameters);
259  if (parameters.usePreshower) fillPreshower( iEvent, info, parameters);
260  if (parameters.useMuon) fillMuon( iEvent, info, parameters);
261  if (parameters.truthMatch) fillCaloTruth( iEvent, info, parameters);
262 
263  return info;
264 }
265 
269 {
270  const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getEcalTrajectory();
271 
272  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
273  itr != trajectoryStates.end(); itr++)
274  LogTrace("TrackAssociator") << "ECAL trajectory point (rho, z, phi): " << itr->position().perp() <<
275  ", " << itr->position().z() << ", " << itr->position().phi();
276 
277  std::vector<GlobalPoint> coreTrajectory;
278  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
279  itr != trajectoryStates.end(); itr++) coreTrajectory.push_back(itr->position());
280 
281  if(coreTrajectory.empty()) {
282  LogTrace("TrackAssociator") << "ECAL track trajectory is empty; moving on\n";
283  info.isGoodEcal = 0;
284  return;
285  }
286  info.isGoodEcal = 1;
287 
288  // Find ECAL crystals
290  iEvent.getByToken(parameters.EBRecHitsToken, EBRecHits);
291  if (!EBRecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find EBRecHitCollection in the event!\n";
292 
294  iEvent.getByToken(parameters.EERecHitsToken, EERecHits);
295  if (!EERecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find EERecHitCollection in event!\n";
296 
297  std::set<DetId> ecalIdsInRegion;
298  if (parameters.accountForTrajectoryChangeCalo){
299  // get trajectory change with respect to initial state
300  DetIdAssociator::MapRange mapRange = getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToEcal),
301  parameters.dREcalPreselection);
302  ecalIdsInRegion = ecalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0],mapRange);
303  } else ecalIdsInRegion = ecalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], parameters.dREcalPreselection);
304  LogTrace("TrackAssociator") << "ECAL hits in the region: " << ecalIdsInRegion.size();
305  if (parameters.dREcalPreselection > parameters.dREcal)
306  ecalIdsInRegion = ecalDetIdAssociator_->getDetIdsInACone(ecalIdsInRegion, coreTrajectory, parameters.dREcal);
307  LogTrace("TrackAssociator") << "ECAL hits in the cone: " << ecalIdsInRegion.size();
308  info.crossedEcalIds = ecalDetIdAssociator_->getCrossedDetIds(ecalIdsInRegion, coreTrajectory);
309  const std::vector<DetId>& crossedEcalIds = info.crossedEcalIds;
310  LogTrace("TrackAssociator") << "ECAL crossed hits " << crossedEcalIds.size();
311 
312 
313  // add EcalRecHits
314  for(std::vector<DetId>::const_iterator itr=crossedEcalIds.begin(); itr!=crossedEcalIds.end();itr++)
315  {
316  std::vector<EcalRecHit>::const_iterator ebHit = (*EBRecHits).find(*itr);
317  std::vector<EcalRecHit>::const_iterator eeHit = (*EERecHits).find(*itr);
318  if(ebHit != (*EBRecHits).end())
319  info.crossedEcalRecHits.push_back(&*ebHit);
320  else if(eeHit != (*EERecHits).end())
321  info.crossedEcalRecHits.push_back(&*eeHit);
322  else
323  LogTrace("TrackAssociator") << "Crossed EcalRecHit is not found for DetId: " << itr->rawId();
324  }
325  for(std::set<DetId>::const_iterator itr=ecalIdsInRegion.begin(); itr!=ecalIdsInRegion.end();itr++)
326  {
327  std::vector<EcalRecHit>::const_iterator ebHit = (*EBRecHits).find(*itr);
328  std::vector<EcalRecHit>::const_iterator eeHit = (*EERecHits).find(*itr);
329  if(ebHit != (*EBRecHits).end())
330  info.ecalRecHits.push_back(&*ebHit);
331  else if(eeHit != (*EERecHits).end())
332  info.ecalRecHits.push_back(&*eeHit);
333  else
334  LogTrace("TrackAssociator") << "EcalRecHit from the cone is not found for DetId: " << itr->rawId();
335  }
336 }
337 
341 {
342  // use ECAL and HCAL trajectories to match a tower. (HO isn't used for matching).
343  std::vector<GlobalPoint> trajectory;
344  const std::vector<SteppingHelixStateInfo>& ecalTrajectoryStates = cachedTrajectory_.getEcalTrajectory();
345  const std::vector<SteppingHelixStateInfo>& hcalTrajectoryStates = cachedTrajectory_.getHcalTrajectory();
346  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = ecalTrajectoryStates.begin();
347  itr != ecalTrajectoryStates.end(); itr++) trajectory.push_back(itr->position());
348  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = hcalTrajectoryStates.begin();
349  itr != hcalTrajectoryStates.end(); itr++) trajectory.push_back(itr->position());
350 
351  if(trajectory.empty()) {
352  LogTrace("TrackAssociator") << "HCAL trajectory is empty; moving on\n";
353  info.isGoodCalo = 0;
354  return;
355  }
356  info.isGoodCalo = 1;
357 
358  // find crossed CaloTowers
360  iEvent.getByToken(parameters.caloTowersToken, caloTowers);
361  if (!caloTowers.isValid()) throw cms::Exception("FatalError") << "Unable to find CaloTowers in event!\n";
362 
363  std::set<DetId> caloTowerIdsInRegion;
364  if (parameters.accountForTrajectoryChangeCalo){
365  // get trajectory change with respect to initial state
366  DetIdAssociator::MapRange mapRange = getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToHcal),
367  parameters.dRHcalPreselection);
368  caloTowerIdsInRegion = caloDetIdAssociator_->getDetIdsCloseToAPoint(trajectory[0],mapRange);
369  } else caloTowerIdsInRegion = caloDetIdAssociator_->getDetIdsCloseToAPoint(trajectory[0], parameters.dRHcalPreselection);
370 
371  LogTrace("TrackAssociator") << "Towers in the region: " << caloTowerIdsInRegion.size();
372 
373  auto caloTowerIdsInAConeBegin = caloTowerIdsInRegion.begin();
374  auto caloTowerIdsInAConeEnd = caloTowerIdsInRegion.end();
375  std::set<DetId> caloTowerIdsInAConeTmp;
376  if (!caloDetIdAssociator_->selectAllInACone(parameters.dRHcal)){
377  caloTowerIdsInAConeTmp = caloDetIdAssociator_->getDetIdsInACone(caloTowerIdsInRegion, trajectory, parameters.dRHcal);
378  caloTowerIdsInAConeBegin = caloTowerIdsInAConeTmp.begin();
379  caloTowerIdsInAConeEnd = caloTowerIdsInAConeTmp.end();
380  }
381  LogTrace("TrackAssociator") << "Towers in the cone: " << std::distance(caloTowerIdsInAConeBegin, caloTowerIdsInAConeEnd);
382 
383  info.crossedTowerIds = caloDetIdAssociator_->getCrossedDetIds(caloTowerIdsInRegion, trajectory);
384  const std::vector<DetId>& crossedCaloTowerIds = info.crossedTowerIds;
385  LogTrace("TrackAssociator") << "Towers crossed: " << crossedCaloTowerIds.size();
386 
387  // add CaloTowers
388  for(std::vector<DetId>::const_iterator itr=crossedCaloTowerIds.begin(); itr!=crossedCaloTowerIds.end();itr++)
389  {
390  CaloTowerCollection::const_iterator tower = (*caloTowers).find(*itr);
391  if(tower != (*caloTowers).end())
392  info.crossedTowers.push_back(&*tower);
393  else
394  LogTrace("TrackAssociator") << "Crossed CaloTower is not found for DetId: " << (*itr).rawId();
395  }
396 
397  for(std::set<DetId>::const_iterator itr=caloTowerIdsInAConeBegin; itr!=caloTowerIdsInAConeEnd;itr++)
398  {
399  CaloTowerCollection::const_iterator tower = (*caloTowers).find(*itr);
400  if(tower != (*caloTowers).end())
401  info.towers.push_back(&*tower);
402  else
403  LogTrace("TrackAssociator") << "CaloTower from the cone is not found for DetId: " << (*itr).rawId();
404  }
405 
406 }
407 
411 {
412  std::vector<GlobalPoint> trajectory;
413  const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getPreshowerTrajectory();
414  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
415  itr != trajectoryStates.end(); itr++) trajectory.push_back(itr->position());
416 
417  if(trajectory.empty()) {
418  LogTrace("TrackAssociator") << "Preshower trajectory is empty; moving on\n";
419  return;
420  }
421 
422  std::set<DetId> idsInRegion =
423  preshowerDetIdAssociator_->getDetIdsCloseToAPoint(trajectory[0],
424  parameters.dRPreshowerPreselection);
425 
426  LogTrace("TrackAssociator") << "Number of Preshower Ids in the region: " << idsInRegion.size();
427  info.crossedPreshowerIds = preshowerDetIdAssociator_->getCrossedDetIds(idsInRegion, trajectory);
428  LogTrace("TrackAssociator") << "Number of Preshower Ids in crossed: " << info.crossedPreshowerIds.size();
429 }
430 
431 
435 {
436  const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getHcalTrajectory();
437 
438  std::vector<GlobalPoint> coreTrajectory;
439  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
440  itr != trajectoryStates.end(); itr++) coreTrajectory.push_back(itr->position());
441 
442  if(coreTrajectory.empty()) {
443  LogTrace("TrackAssociator") << "HCAL trajectory is empty; moving on\n";
444  info.isGoodHcal = 0;
445  return;
446  }
447  info.isGoodHcal = 1;
448 
449  // find crossed Hcals
451  iEvent.getByToken(parameters.HBHEcollToken, collection);
452  if ( ! collection.isValid() ) throw cms::Exception("FatalError") << "Unable to find HBHERecHits in event!\n";
453 
454  std::set<DetId> idsInRegion;
455  if (parameters.accountForTrajectoryChangeCalo){
456  // get trajectory change with respect to initial state
457  DetIdAssociator::MapRange mapRange = getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToHcal),
458  parameters.dRHcalPreselection);
459  idsInRegion = hcalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], mapRange);
460  } else idsInRegion = hcalDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], parameters.dRHcalPreselection);
461 
462  LogTrace("TrackAssociator") << "HCAL hits in the region: " << idsInRegion.size() << "\n" << DetIdInfo::info(idsInRegion,0);
463 
464  auto idsInAConeBegin = idsInRegion.begin();
465  auto idsInAConeEnd = idsInRegion.end();
466  std::set<DetId> idsInAConeTmp;
467  if (! hcalDetIdAssociator_->selectAllInACone(parameters.dRHcal)){
468  idsInAConeTmp = hcalDetIdAssociator_->getDetIdsInACone(idsInRegion, coreTrajectory, parameters.dRHcal);
469  idsInAConeBegin = idsInAConeTmp.begin();
470  idsInAConeEnd = idsInAConeTmp.end();
471  }
472  LogTrace("TrackAssociator") << "HCAL hits in the cone: " << std::distance(idsInAConeBegin, idsInAConeEnd) << "\n"
473  << DetIdInfo::info(std::set<DetId>(idsInAConeBegin, idsInAConeEnd), 0);
474  info.crossedHcalIds = hcalDetIdAssociator_->getCrossedDetIds(idsInRegion, coreTrajectory);
475  const std::vector<DetId>& crossedIds = info.crossedHcalIds;
476  LogTrace("TrackAssociator") << "HCAL hits crossed: " << crossedIds.size() << "\n" << DetIdInfo::info(crossedIds,0);
477 
478  // add Hcal
479  for(std::vector<DetId>::const_iterator itr=crossedIds.begin(); itr!=crossedIds.end();itr++)
480  {
481  HBHERecHitCollection::const_iterator hit = (*collection).find(*itr);
482  if( hit != (*collection).end() )
483  info.crossedHcalRecHits.push_back(&*hit);
484  else
485  LogTrace("TrackAssociator") << "Crossed HBHERecHit is not found for DetId: " << itr->rawId();
486  }
487  for(std::set<DetId>::const_iterator itr=idsInAConeBegin; itr!=idsInAConeEnd;itr++)
488  {
489  HBHERecHitCollection::const_iterator hit = (*collection).find(*itr);
490  if( hit != (*collection).end() )
491  info.hcalRecHits.push_back(&*hit);
492  else
493  LogTrace("TrackAssociator") << "HBHERecHit from the cone is not found for DetId: " << itr->rawId();
494  }
495 }
496 
500 {
501  const std::vector<SteppingHelixStateInfo>& trajectoryStates = cachedTrajectory_.getHOTrajectory();
502 
503  std::vector<GlobalPoint> coreTrajectory;
504  for(std::vector<SteppingHelixStateInfo>::const_iterator itr = trajectoryStates.begin();
505  itr != trajectoryStates.end(); itr++) coreTrajectory.push_back(itr->position());
506 
507  if(coreTrajectory.empty()) {
508  LogTrace("TrackAssociator") << "HO trajectory is empty; moving on\n";
509  info.isGoodHO = 0;
510  return;
511  }
512  info.isGoodHO = 1;
513 
514  // find crossed HOs
516  iEvent.getByToken(parameters.HOcollToken, collection);
517  if ( ! collection.isValid() ) throw cms::Exception("FatalError") << "Unable to find HORecHits in event!\n";
518 
519  std::set<DetId> idsInRegion;
520  if (parameters.accountForTrajectoryChangeCalo){
521  // get trajectory change with respect to initial state
522  DetIdAssociator::MapRange mapRange = getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::IpToHO),
523  parameters.dRHcalPreselection);
524  idsInRegion = hoDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], mapRange);
525  } else idsInRegion = hoDetIdAssociator_->getDetIdsCloseToAPoint(coreTrajectory[0], parameters.dRHcalPreselection);
526 
527  LogTrace("TrackAssociator") << "idsInRegion.size(): " << idsInRegion.size();
528 
529  auto idsInAConeBegin = idsInRegion.begin();
530  auto idsInAConeEnd = idsInRegion.end();
531  std::set<DetId> idsInAConeTmp;
532  if (! hoDetIdAssociator_->selectAllInACone(parameters.dRHcal)){
533  idsInAConeTmp = hoDetIdAssociator_->getDetIdsInACone(idsInRegion, coreTrajectory, parameters.dRHcal);
534  idsInAConeBegin = idsInAConeTmp.begin();
535  idsInAConeEnd = idsInAConeTmp.end();
536  }
537  LogTrace("TrackAssociator") << "idsInACone.size(): " << std::distance(idsInAConeBegin, idsInAConeEnd);
538  info.crossedHOIds = hoDetIdAssociator_->getCrossedDetIds(idsInRegion, coreTrajectory);
539  const std::vector<DetId>& crossedIds = info.crossedHOIds;
540 
541  // add HO
542  for(std::vector<DetId>::const_iterator itr=crossedIds.begin(); itr!=crossedIds.end();itr++)
543  {
544  HORecHitCollection::const_iterator hit = (*collection).find(*itr);
545  if( hit != (*collection).end() )
546  info.crossedHORecHits.push_back(&*hit);
547  else
548  LogTrace("TrackAssociator") << "Crossed HORecHit is not found for DetId: " << itr->rawId();
549  }
550 
551  for(std::set<DetId>::const_iterator itr=idsInAConeBegin; itr!=idsInAConeEnd;itr++)
552  {
553  HORecHitCollection::const_iterator hit = (*collection).find(*itr);
554  if( hit != (*collection).end() )
555  info.hoRecHits.push_back(&*hit);
556  else
557  LogTrace("TrackAssociator") << "HORecHit from the cone is not found for DetId: " << itr->rawId();
558  }
559 }
560 
562  const SimTrack& track,
563  const SimVertex& vertex )
564 {
565  GlobalVector vector( track.momentum().x(), track.momentum().y(), track.momentum().z() );
566  GlobalPoint point( vertex.position().x(), vertex.position().y(), vertex.position().z() );
567 
568  int charge = track.type( )> 0 ? -1 : 1; // lepton convention
569  if ( abs(track.type( )) == 211 || // pion
570  abs(track.type( )) == 321 || // kaon
571  abs(track.type( )) == 2212 )
572  charge = track.type( )< 0 ? -1 : 1;
573  return getFreeTrajectoryState(iSetup, vector, point, charge);
574 }
575 
577  const GlobalVector& momentum,
578  const GlobalPoint& vertex,
579  const int charge)
580 {
582  iSetup.get<IdealMagneticFieldRecord>().get(bField);
583 
584  GlobalTrajectoryParameters tPars(vertex, momentum, charge, &*bField);
585 
586  ROOT::Math::SMatrixIdentity id;
587  AlgebraicSymMatrix66 covT(id); covT *= 1e-6; // initialize to sigma=1e-3
588  CartesianTrajectoryError tCov(covT);
589 
590  return FreeTrajectoryState(tPars, tCov);
591 }
592 
593 
595  const reco::Track& track )
596 {
598  iSetup.get<IdealMagneticFieldRecord>().get(bField);
599 
600  GlobalVector vector( track.momentum().x(), track.momentum().y(), track.momentum().z() );
601 
602  GlobalPoint point( track.vertex().x(), track.vertex().y(), track.vertex().z() );
603 
604  GlobalTrajectoryParameters tPars(point, vector, track.charge(), &*bField);
605 
606  // FIX THIS !!!
607  // need to convert from perigee to global or helix (curvilinear) frame
608  // for now just an arbitrary matrix.
609  ROOT::Math::SMatrixIdentity id;
610  AlgebraicSymMatrix66 covT(id); covT *= 1e-6; // initialize to sigma=1e-3
611  CartesianTrajectoryError tCov(covT);
612 
613  return FreeTrajectoryState(tPars, tCov);
614 }
615 
617  const float dR )
618 {
619  DetIdAssociator::MapRange mapRange;
620  mapRange.dThetaPlus = dR;
621  mapRange.dThetaMinus = dR;
622  mapRange.dPhiPlus = dR;
623  mapRange.dPhiMinus = dR;
624  if ( delta.first > 0 )
625  mapRange.dThetaPlus += delta.first;
626  else
627  mapRange.dThetaMinus += fabs(delta.first);
628  if ( delta.second > 0 )
629  mapRange.dPhiPlus += delta.second;
630  else
631  mapRange.dPhiMinus += fabs(delta.second);
632  LogTrace("TrackAssociator") << "Selection range: (dThetaPlus, dThetaMinus, dPhiPlus, dPhiMinus, dRPreselection): " <<
633  mapRange.dThetaPlus << ", " << mapRange.dThetaMinus << ", " <<
634  mapRange.dPhiPlus << ", " << mapRange.dPhiMinus << ", " << dR;
635  return mapRange;
636 }
637 
638 void TrackDetectorAssociator::getTAMuonChamberMatches(std::vector<TAMuonChamberMatch>& matches,
640 {
641  // Strategy:
642  // Propagate through the whole detector, estimate change in eta and phi
643  // along the trajectory, add this to dRMuon and find DetIds around this
644  // direction using the map. Then propagate fast to each surface and apply
645  // final matching criteria.
646 
647  // get the direction first
648  SteppingHelixStateInfo trajectoryPoint = cachedTrajectory_.getStateAtHcal();
649  // If trajectory point at HCAL is not valid, try to use the outer most state of the
650  // trajectory instead.
651  if(! trajectoryPoint.isValid() ) trajectoryPoint = cachedTrajectory_.getOuterState();
652  if(! trajectoryPoint.isValid() ) {
653  LogTrace("TrackAssociator") <<
654  "trajectory position at HCAL is not valid. Assume the track cannot reach muon detectors and skip it";
655  return;
656  }
657 
658  GlobalVector direction = trajectoryPoint.momentum().unit();
659  LogTrace("TrackAssociator") << "muon direction: " << direction << "\n\t and corresponding point: " <<
660  trajectoryPoint.position() <<"\n";
661 
662  DetIdAssociator::MapRange mapRange = getMapRange(cachedTrajectory_.trajectoryDelta(CachedTrajectory::FullTrajectory),
663  parameters.dRMuonPreselection);
664 
665  // and find chamber DetIds
666 
667  std::set<DetId> muonIdsInRegion =
668  muonDetIdAssociator_->getDetIdsCloseToAPoint(trajectoryPoint.position(), mapRange);
669  LogTrace("TrackAssociator") << "Number of chambers to check: " << muonIdsInRegion.size();
670  for(std::set<DetId>::const_iterator detId = muonIdsInRegion.begin(); detId != muonIdsInRegion.end(); detId++)
671  {
672  const GeomDet* geomDet = muonDetIdAssociator_->getGeomDet(*detId);
673  TrajectoryStateOnSurface stateOnSurface = cachedTrajectory_.propagate( &geomDet->surface() );
674  if (! stateOnSurface.isValid()) {
675  LogTrace("TrackAssociator") << "Failed to propagate the track; moving on\n\t"<<
676  "Element is not crosssed: " << DetIdInfo::info(*detId,0) << "\n";
677  continue;
678  }
679  LocalPoint localPoint = geomDet->surface().toLocal(stateOnSurface.freeState()->position());
680  LocalError localError = stateOnSurface.localError().positionError();
681  float distanceX = 0;
682  float distanceY = 0;
683  float sigmaX = 0.0;
684  float sigmaY = 0.0;
685  if(const CSCChamber* cscChamber = dynamic_cast<const CSCChamber*>(geomDet) ) {
686  const CSCChamberSpecs* chamberSpecs = cscChamber->specs();
687  if(! chamberSpecs) {
688  LogTrace("TrackAssociator") << "Failed to get CSCChamberSpecs from CSCChamber; moving on\n";
689  continue;
690  }
691  const CSCLayerGeometry* layerGeometry = chamberSpecs->oddLayerGeometry(1);
692  if(! layerGeometry) {
693  LogTrace("TrackAssociator") << "Failed to get CSCLayerGeometry from CSCChamberSpecs; moving on\n";
694  continue;
695  }
696  const CSCWireTopology* wireTopology = layerGeometry->wireTopology();
697  if(! wireTopology) {
698  LogTrace("TrackAssociator") << "Failed to get CSCWireTopology from CSCLayerGeometry; moving on\n";
699  continue;
700  }
701 
702  float wideWidth = wireTopology->wideWidthOfPlane();
703  float narrowWidth = wireTopology->narrowWidthOfPlane();
704  float length = wireTopology->lengthOfPlane();
705  // If slanted, there is no y offset between local origin and symmetry center of wire plane
706  float yOfFirstWire = fabs(wireTopology->wireAngle())>1.E-06 ? -0.5*length : wireTopology->yOfWire(1);
707  // y offset between local origin and symmetry center of wire plane
708  float yCOWPOffset = yOfFirstWire+0.5*length;
709 
710  // tangent of the incline angle from inside the trapezoid
711  float tangent = (wideWidth-narrowWidth)/(2.*length);
712  // y position wrt bottom of trapezoid
713  float yPrime = localPoint.y()+fabs(yOfFirstWire);
714  // half trapezoid width at y' is 0.5 * narrowWidth + x side of triangle with the above tangent and side y'
715  float halfWidthAtYPrime = 0.5*narrowWidth+yPrime*tangent;
716  distanceX = fabs(localPoint.x()) - halfWidthAtYPrime;
717  distanceY = fabs(localPoint.y()-yCOWPOffset) - 0.5*length;
718  sigmaX = distanceX/sqrt(localError.xx());
719  sigmaY = distanceY/sqrt(localError.yy());
720  } else {
721  distanceX = fabs(localPoint.x()) - geomDet->surface().bounds().width()/2.;
722  distanceY = fabs(localPoint.y()) - geomDet->surface().bounds().length()/2.;
723  sigmaX = distanceX/sqrt(localError.xx());
724  sigmaY = distanceY/sqrt(localError.yy());
725  }
726  if ( (distanceX < parameters.muonMaxDistanceX && distanceY < parameters.muonMaxDistanceY) ||
727  (sigmaX < parameters.muonMaxDistanceSigmaX && sigmaY < parameters.muonMaxDistanceSigmaY) ) {
728  LogTrace("TrackAssociator") << "found a match: " << DetIdInfo::info(*detId,0) << "\n";
730  match.tState = stateOnSurface;
731  match.localDistanceX = distanceX;
732  match.localDistanceY = distanceY;
733  match.id = *detId;
734  matches.push_back(match);
735  } else {
736  LogTrace("TrackAssociator") << "chamber is too far: " <<
737  DetIdInfo::info(*detId,0) << "\n\tdistanceX: " << distanceX << "\t distanceY: " << distanceY <<
738  "\t sigmaX: " << sigmaX << "\t sigmaY: " << sigmaY << "\n";
739  }
740  }
741 
742 }
743 
747 {
748  // Get the segments from the event
750  iEvent.getByToken(parameters.dtSegmentsToken, dtSegments);
751  if (! dtSegments.isValid())
752  throw cms::Exception("FatalError") << "Unable to find DTRecSegment4DCollection in event!\n";
753 
755  iEvent.getByToken(parameters.cscSegmentsToken, cscSegments);
756  if (! cscSegments.isValid())
757  throw cms::Exception("FatalError") << "Unable to find CSCSegmentCollection in event!\n";
758 
760  if (parameters.useGEM) iEvent.getByToken(parameters.gemSegmentsToken, gemSegments );
762  if (parameters.useME0) iEvent.getByToken(parameters.me0SegmentsToken, me0Segments );
763 
765 
766  // check the map of available segments
767  // if there is no segments in a given direction at all,
768  // then there is no point to fly there.
769  //
770  // MISSING
771  // Possible solution: quick search for presence of segments
772  // for the set of DetIds
773 
774  // get a set of matches corresponding to muon chambers
775  std::vector<TAMuonChamberMatch> matchedChambers;
776  LogTrace("TrackAssociator") << "Trying to Get ChamberMatches" << std::endl;
777  getTAMuonChamberMatches(matchedChambers, parameters);
778  LogTrace("TrackAssociator") << "Chambers matched: " << matchedChambers.size() << "\n";
779 
780  // Iterate over all chamber matches and fill segment matching
781  // info if it's available
782  for(std::vector<TAMuonChamberMatch>::iterator matchedChamber = matchedChambers.begin();
783  matchedChamber != matchedChambers.end(); matchedChamber++)
784  {
785  const GeomDet* geomDet = muonDetIdAssociator_->getGeomDet((*matchedChamber).id);
786  // DT chamber
787  if(const DTChamber* chamber = dynamic_cast<const DTChamber*>(geomDet) ) {
788  // Get the range for the corresponding segments
789  DTRecSegment4DCollection::range range = dtSegments->get(chamber->id());
790  // Loop over the segments of this chamber
791  for (DTRecSegment4DCollection::const_iterator segment = range.first; segment!=range.second; segment++) {
792  if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
793  matchedChamber->segments.back().dtSegmentRef = DTRecSegment4DRef(dtSegments, segment - dtSegments->begin());
794  }
795  }
796  }
797  // CSC Chamber
798  else if(const CSCChamber* chamber = dynamic_cast<const CSCChamber*>(geomDet) ) {
799  // Get the range for the corresponding segments
800  CSCSegmentCollection::range range = cscSegments->get(chamber->id());
801  // Loop over the segments
802  for (CSCSegmentCollection::const_iterator segment = range.first; segment!=range.second; segment++) {
803  if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
804  matchedChamber->segments.back().cscSegmentRef = CSCSegmentRef(cscSegments, segment - cscSegments->begin());
805  }
806  }
807  }
808  else {
809  // GEM Chamber
810  if (parameters.useGEM){
811  if (const GEMSuperChamber* chamber = dynamic_cast<const GEMSuperChamber*>(geomDet) ) {
812  // Get the range for the corresponding segments
813  GEMSegmentCollection::range range = gemSegments->get(chamber->id());
814  // Loop over the segments
815  for (GEMSegmentCollection::const_iterator segment = range.first; segment!=range.second; segment++) {
816  if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
817  matchedChamber->segments.back().gemSegmentRef = GEMSegmentRef(gemSegments, segment - gemSegments->begin());
818  }
819  }
820  }
821  }
822  // ME0 Chamber
823  if (parameters.useME0){
824  if (const ME0Chamber* chamber = dynamic_cast<const ME0Chamber*>(geomDet) ) {
825  // Get the range for the corresponding segments
826  ME0SegmentCollection::range range = me0Segments->get(chamber->id());
827  // Loop over the segments
828  for (ME0SegmentCollection::const_iterator segment = range.first; segment!=range.second; segment++) {
829  if (addTAMuonSegmentMatch(*matchedChamber, &(*segment), parameters)) {
830  matchedChamber->segments.back().me0SegmentRef = ME0SegmentRef(me0Segments, segment - me0Segments->begin());
831  }
832  }
833  }
834  }
835  }
836  info.chambers.push_back(*matchedChamber);
837  }
838 }
839 
840 
842  const RecSegment* segment,
844 {
845  LogTrace("TrackAssociator")
846  << "Segment local position: " << segment->localPosition() << "\n"
847  << std::hex << segment->geographicalId().rawId() << "\n";
848 
849  const GeomDet* chamber = muonDetIdAssociator_->getGeomDet(matchedChamber.id);
850  TrajectoryStateOnSurface trajectoryStateOnSurface = matchedChamber.tState;
851  GlobalPoint segmentGlobalPosition = chamber->toGlobal(segment->localPosition());
852 
853  LogTrace("TrackAssociator")
854  << "Segment global position: " << segmentGlobalPosition << " \t (R_xy,eta,phi): "
855  << segmentGlobalPosition.perp() << "," << segmentGlobalPosition.eta() << "," << segmentGlobalPosition.phi() << "\n";
856 
857  LogTrace("TrackAssociator")
858  << "\teta hit: " << segmentGlobalPosition.eta() << " \tpropagator: " << trajectoryStateOnSurface.freeState()->position().eta() << "\n"
859  << "\tphi hit: " << segmentGlobalPosition.phi() << " \tpropagator: " << trajectoryStateOnSurface.freeState()->position().phi() << std::endl;
860 
861  bool isGood = false;
862  bool isDTWithoutY = false;
863  const DTRecSegment4D* dtseg = dynamic_cast<const DTRecSegment4D*>(segment);
864  if ( dtseg && (! dtseg->hasZed()) )
865  isDTWithoutY = true;
866 
867  double deltaPhi(fabs(segmentGlobalPosition.phi()-trajectoryStateOnSurface.freeState()->position().phi()));
868  if(deltaPhi>M_PI) deltaPhi = fabs(deltaPhi-M_PI*2.);
869 
870  if( isDTWithoutY )
871  {
872  isGood = deltaPhi < parameters.dRMuon;
873  // Be in chamber
874  isGood &= fabs(segmentGlobalPosition.eta()-trajectoryStateOnSurface.freeState()->position().eta()) < .3;
875  } else isGood = sqrt( pow(segmentGlobalPosition.eta()-trajectoryStateOnSurface.freeState()->position().eta(),2) +
876  deltaPhi*deltaPhi) < parameters.dRMuon;
877 
878  if(isGood) {
879  TAMuonSegmentMatch muonSegment;
880  muonSegment.segmentGlobalPosition = getPoint(segmentGlobalPosition);
881  muonSegment.segmentLocalPosition = getPoint( segment->localPosition() );
882  muonSegment.segmentLocalDirection = getVector( segment->localDirection() );
883  muonSegment.segmentLocalErrorXX = segment->localPositionError().xx();
884  muonSegment.segmentLocalErrorYY = segment->localPositionError().yy();
885  muonSegment.segmentLocalErrorXY = segment->localPositionError().xy();
886  muonSegment.segmentLocalErrorDxDz = segment->localDirectionError().xx();
887  muonSegment.segmentLocalErrorDyDz = segment->localDirectionError().yy();
888 
889  // DANGEROUS - compiler cannot guaranty parameters ordering
890  // AlgebraicSymMatrix segmentCovMatrix = segment->parametersError();
891  // muonSegment.segmentLocalErrorXDxDz = segmentCovMatrix[2][0];
892  // muonSegment.segmentLocalErrorYDyDz = segmentCovMatrix[3][1];
893  muonSegment.segmentLocalErrorXDxDz = -999;
894  muonSegment.segmentLocalErrorYDyDz = -999;
895  muonSegment.hasZed = true;
896  muonSegment.hasPhi = true;
897 
898  // timing information
899  muonSegment.t0 = 0;
900  if ( dtseg ) {
901  if ( (dtseg->hasPhi()) && (! isDTWithoutY) ) {
902  int phiHits = dtseg->phiSegment()->specificRecHits().size();
903  // int zHits = dtseg->zSegment()->specificRecHits().size();
904  int hits=0;
905  double t0=0.;
906  // TODO: cuts on hit numbers not optimized in any way yet...
907  if (phiHits>5 && dtseg->phiSegment()->ist0Valid()) {
908  t0+=dtseg->phiSegment()->t0()*phiHits;
909  hits+=phiHits;
910  LogTrace("TrackAssociator") << " Phi t0: " << dtseg->phiSegment()->t0() << " hits: " << phiHits;
911  }
912  // the z segments seem to contain little useful information...
913 // if (zHits>3) {
914 // t0+=s->zSegment()->t0()*zHits;
915 // hits+=zHits;
916 // LogTrace("TrackAssociator") << " Z t0: " << s->zSegment()->t0() << " hits: " << zHits << std::endl;
917 // }
918  if (hits) muonSegment.t0 = t0/hits;
919 // LogTrace("TrackAssociator") << " --- t0: " << muonSegment.t0 << std::endl;
920  } else {
921  // check and set dimensionality
922  if (isDTWithoutY) muonSegment.hasZed = false;
923  if (! dtseg->hasPhi()) muonSegment.hasPhi = false;
924  }
925  }
926  matchedChamber.segments.push_back(muonSegment);
927  }
928 
929  return isGood;
930 }
931 
932 //********************** NON-CORE CODE ******************************//
933 
937 {
938  // get list of simulated tracks and their vertices
939  using namespace edm;
941  iEvent.getByToken(parameters.simTracksToken, simTracks);
942  if (! simTracks.isValid() ) throw cms::Exception("FatalError") << "No simulated tracks found\n";
943 
944  Handle<SimVertexContainer> simVertices;
945  iEvent.getByToken(parameters.simVerticesToken, simVertices);
946  if (! simVertices.isValid() ) throw cms::Exception("FatalError") << "No simulated vertices found\n";
947 
948  // get sim calo hits
949  Handle<PCaloHitContainer> simEcalHitsEB;
950  iEvent.getByToken(parameters.simEcalHitsEBToken, simEcalHitsEB);
951  if (! simEcalHitsEB.isValid() ) throw cms::Exception("FatalError") << "No simulated ECAL EB hits found\n";
952 
953  Handle<PCaloHitContainer> simEcalHitsEE;
954  iEvent.getByToken(parameters.simEcalHitsEEToken, simEcalHitsEE);
955  if (! simEcalHitsEE.isValid() ) throw cms::Exception("FatalError") << "No simulated ECAL EE hits found\n";
956 
957  Handle<PCaloHitContainer> simHcalHits;
958  iEvent.getByToken(parameters.simHcalHitsToken, simHcalHits);
959  if (! simHcalHits.isValid() ) throw cms::Exception("FatalError") << "No simulated HCAL hits found\n";
960 
961  // find truth partner
962  SimTrackContainer::const_iterator simTrack = simTracks->begin();
963  for( ; simTrack != simTracks->end(); ++simTrack){
964  math::XYZVector simP3( simTrack->momentum().x(), simTrack->momentum().y(), simTrack->momentum().z() );
965  math::XYZVector recoP3( info.stateAtIP.momentum().x(), info.stateAtIP.momentum().y(), info.stateAtIP.momentum().z() );
966  if ( ROOT::Math::VectorUtil::DeltaR(recoP3, simP3) < 0.1 ) break;
967  }
968  if ( simTrack != simTracks->end() ) {
969  info.simTrack = &(*simTrack);
970  double ecalTrueEnergy(0);
971  double hcalTrueEnergy(0);
972 
973  // loop over calo hits
974  for( PCaloHitContainer::const_iterator hit = simEcalHitsEB->begin(); hit != simEcalHitsEB->end(); ++hit )
975  if ( hit->geantTrackId() == info.simTrack->genpartIndex() ) ecalTrueEnergy += hit->energy();
976 
977  for( PCaloHitContainer::const_iterator hit = simEcalHitsEE->begin(); hit != simEcalHitsEE->end(); ++hit )
978  if ( hit->geantTrackId() == info.simTrack->genpartIndex() ) ecalTrueEnergy += hit->energy();
979 
980  for( PCaloHitContainer::const_iterator hit = simHcalHits->begin(); hit != simHcalHits->end(); ++hit )
981  if ( hit->geantTrackId() == info.simTrack->genpartIndex() ) hcalTrueEnergy += hit->energy();
982 
983  info.ecalTrueEnergy = ecalTrueEnergy;
984  info.hcalTrueEnergy = hcalTrueEnergy;
985  info.hcalTrueEnergyCorrected = hcalTrueEnergy;
986  if ( fabs(info.trkGlobPosAtHcal.eta()) < 1.3 )
987  info.hcalTrueEnergyCorrected = hcalTrueEnergy*113.2;
988  else
989  if ( fabs(info.trkGlobPosAtHcal.eta()) < 3.0 )
990  info.hcalTrueEnergyCorrected = hcalTrueEnergy*167.2;
991  }
992 }
993 
995  const edm::EventSetup& iSetup,
996  const reco::Track& track,
998  Direction direction /*= Any*/ )
999 {
1000  double currentStepSize = cachedTrajectory_.getPropagationStep();
1001 
1003  iSetup.get<IdealMagneticFieldRecord>().get(bField);
1004 
1005  if(track.extra().isNull()) {
1006  if ( direction != InsideOut )
1007  throw cms::Exception("FatalError") <<
1008  "No TrackExtra information is available and association is done with something else than InsideOut track.\n" <<
1009  "Either change the parameter or provide needed data!\n";
1010  LogTrace("TrackAssociator") << "Track Extras not found\n";
1011  FreeTrajectoryState initialState = trajectoryStateTransform::initialFreeState(track,&*bField);
1012  return associate(iEvent, iSetup, parameters, &initialState); // 5th argument is null pointer
1013  }
1014 
1015  LogTrace("TrackAssociator") << "Track Extras found\n";
1018  FreeTrajectoryState referenceState = trajectoryStateTransform::initialFreeState(track,&*bField);
1019 
1020  LogTrace("TrackAssociator") << "inner track state (rho, z, phi):" <<
1021  track.innerPosition().Rho() << ", " << track.innerPosition().z() <<
1022  ", " << track.innerPosition().phi() << "\n";
1023  LogTrace("TrackAssociator") << "innerFreeState (rho, z, phi):" <<
1024  innerState.position().perp() << ", " << innerState.position().z() <<
1025  ", " << innerState.position().phi() << "\n";
1026 
1027  LogTrace("TrackAssociator") << "outer track state (rho, z, phi):" <<
1028  track.outerPosition().Rho() << ", " << track.outerPosition().z() <<
1029  ", " << track.outerPosition().phi() << "\n";
1030  LogTrace("TrackAssociator") << "outerFreeState (rho, z, phi):" <<
1031  outerState.position().perp() << ", " << outerState.position().z() <<
1032  ", " << outerState.position().phi() << "\n";
1033 
1034  // InsideOut first
1035  if ( crossedIP( track ) ) {
1036  switch ( direction ) {
1037  case InsideOut:
1038  case Any:
1039  return associate(iEvent, iSetup, parameters, &referenceState, &outerState);
1040  break;
1041  case OutsideIn:
1042  {
1043  cachedTrajectory_.setPropagationStep( -fabs(currentStepSize) );
1044  TrackDetMatchInfo result = associate(iEvent, iSetup, parameters, &innerState, &referenceState);
1045  cachedTrajectory_.setPropagationStep( currentStepSize );
1046  return result;
1047  break;
1048  }
1049  }
1050  } else {
1051  switch ( direction ) {
1052  case InsideOut:
1053  return associate(iEvent, iSetup, parameters, &innerState, &outerState);
1054  break;
1055  case OutsideIn:
1056  {
1057  cachedTrajectory_.setPropagationStep( -fabs(currentStepSize) );
1058  TrackDetMatchInfo result = associate(iEvent, iSetup, parameters, &outerState, &innerState);
1059  cachedTrajectory_.setPropagationStep( currentStepSize );
1060  return result;
1061  break;
1062  }
1063  case Any:
1064  {
1065  // check if we deal with clear outside-in case
1066  if ( track.innerPosition().Dot( track.innerMomentum() ) < 0 &&
1067  track.outerPosition().Dot( track.outerMomentum() ) < 0 )
1068  {
1069  cachedTrajectory_.setPropagationStep( -fabs(currentStepSize) );
1071  if ( track.innerPosition().R() < track.outerPosition().R() )
1072  result = associate(iEvent, iSetup, parameters, &innerState, &outerState);
1073  else
1074  result = associate(iEvent, iSetup, parameters, &outerState, &innerState);
1075  cachedTrajectory_.setPropagationStep( currentStepSize );
1076  return result;
1077  }
1078  }
1079  }
1080  }
1081 
1082  // all other cases
1083  return associate(iEvent, iSetup, parameters, &innerState, &outerState);
1084 }
1085 
1087  const edm::EventSetup& iSetup,
1088  const SimTrack& track,
1089  const SimVertex& vertex,
1091 {
1092  return associate(iEvent, iSetup, getFreeTrajectoryState(iSetup, track, vertex), parameters);
1093 }
1094 
1096  const edm::EventSetup& iSetup,
1097  const GlobalVector& momentum,
1098  const GlobalPoint& vertex,
1099  const int charge,
1101 {
1102  return associate(iEvent, iSetup, getFreeTrajectoryState(iSetup, momentum, vertex, charge), parameters);
1103 }
1104 
1106 {
1107  bool crossed = true;
1108  crossed &= (track.innerPosition().rho() > 3 ); // something close to active volume
1109  crossed &= (track.outerPosition().rho() > 3 ); // something close to active volume
1110  crossed &= ( ( track.innerPosition().x()*track.innerMomentum().x() +
1111  track.innerPosition().y()*track.innerMomentum().y() < 0 ) !=
1112  ( track.outerPosition().x()*track.outerMomentum().x() +
1113  track.outerPosition().y()*track.outerMomentum().y() < 0 ) );
1114  return crossed;
1115 }
dbl * delta
Definition: mlp_gen.cc:36
edm::EDGetTokenT< CaloTowerCollection > caloTowersToken
std::vector< DetId > crossedPreshowerIds
math::XYZPoint trkGlobPosAtHO
float xx() const
Definition: LocalError.h:24
virtual float length() const =0
virtual LocalError localDirectionError() const =0
Error on the local direction.
static const TGPicture * info(bool iBackgroundIsBlack)
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
const CSCWireTopology * wireTopology() const
T perp() const
Definition: PV3DBase.h:72
static bool crossedIP(const reco::Track &track)
std::vector< const CaloTower * > crossedTowers
std::vector< const CaloTower * > towers
TrajectoryStateOnSurface tState
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:189
std::vector< const HBHERecHit * > crossedHcalRecHits
std::vector< DetId > crossedTowerIds
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
math::XYZPoint segmentGlobalPosition
static FreeTrajectoryState getFreeTrajectoryState(const edm::EventSetup &, const reco::Track &)
get FreeTrajectoryState from different track representations
edm::Ref< CSCSegmentCollection > CSCSegmentRef
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
std::vector< const EcalRecHit * > ecalRecHits
hits in the cone
std::vector< DetId > crossedEcalIds
edm::Ref< ME0SegmentCollection > ME0SegmentRef
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
math::XYZPoint segmentLocalPosition
void setCaloGeometry(edm::ESHandle< CaloGeometry > geometry)
edm::EDGetTokenT< GEMSegmentCollection > gemSegmentsToken
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
void useDefaultPropagator()
use the default propagator
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< CaloTower >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:63
void fillHcal(const edm::Event &, TrackDetMatchInfo &, const AssociatorParameters &)
const Bounds & bounds() const
Definition: Surface.h:120
bool addTAMuonSegmentMatch(TAMuonChamberMatch &, const RecSegment *, const AssociatorParameters &)
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:670
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
std::vector< DetId > crossedHcalIds
GlobalVector momentum() const
std::vector< const EcalRecHit * > crossedEcalRecHits
hits in detector elements crossed by a track
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
math::XYZVector segmentLocalDirection
LocalError positionError() const
edm::EDGetTokenT< EBRecHitCollection > EBRecHitsToken
math::XYZPoint trkGlobPosAtHcal
FreeTrajectoryState stateAtIP
track info
void fillCaloTowers(const edm::Event &, TrackDetMatchInfo &, const AssociatorParameters &)
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void fillCaloTruth(const edm::Event &, TrackDetMatchInfo &, const AssociatorParameters &)
virtual LocalVector localDirection() const =0
Local direction.
virtual float width() const =0
edm::EDGetTokenT< edm::PCaloHitContainer > simEcalHitsEBToken
edm::EDGetTokenT< HORecHitCollection > HOcollToken
float xy() const
Definition: LocalError.h:25
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:682
float wireAngle() const
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
GlobalVector trkMomAtHO
void setPropagator(const Propagator *)
use a user configured propagator
void getTAMuonChamberMatches(std::vector< TAMuonChamberMatch > &matches, const AssociatorParameters &parameters)
float yy() const
Definition: LocalError.h:26
void applyRadX0Correction(bool applyRadX0Correction)
simTrack
per collection params
GlobalPoint position() const
T sqrt(T t)
Definition: SSEVec.h:18
LocalPoint toLocal(const GlobalPoint &gp) const
edm::Ref< GEMSegmentCollection > GEMSegmentRef
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
std::vector< TAMuonSegmentMatch > segments
distance sign convention: negative - crossed chamber, positive - missed chamber
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:33
edm::EDGetTokenT< ME0SegmentCollection > me0SegmentsToken
std::vector< TAMuonChamberMatch > chambers
std::vector< const HBHERecHit * > hcalRecHits
edm::EDGetTokenT< DTRecSegment4DCollection > dtSegmentsToken
std::vector< DetId > crossedHOIds
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:26
bool hasPhi() const
Does it have the Phi projection?
double lengthOfPlane() const
const LocalTrajectoryError & localError() const
edm::EDGetTokenT< edm::SimTrackContainer > simTracksToken
float yOfWire(float wire, float x=0.) const
virtual LocalPoint localPosition() const =0
edm::EDGetTokenT< EERecHitCollection > EERecHitsToken
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< HBHERecHitCollection > HBHEcollToken
void fillPreshower(const edm::Event &iEvent, TrackDetMatchInfo &info, const AssociatorParameters &)
bool isNull() const
Checks for null.
Definition: Ref.h:249
GlobalVector momentum() const
#define LogTrace(id)
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
bool ist0Valid() const
double narrowWidthOfPlane() const
#define M_PI
edm::Ref< DTRecSegment4DCollection > DTRecSegment4DRef
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
Vector3DBase unit() const
Definition: Vector3DBase.h:57
bool hasZed() const
Does it have the Z projection?
GlobalPoint position() const
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
double wideWidthOfPlane() const
GlobalVector trkMomAtEcal
edm::EDGetTokenT< edm::SimVertexContainer > simVerticesToken
static std::string info(const DetId &, const TrackerTopology *tTopo)
Definition: DetIdInfo.cc:25
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:56
void fillMuon(const edm::Event &, TrackDetMatchInfo &, const AssociatorParameters &)
const CSCLayerGeometry * oddLayerGeometry(int iendcap) const
Accessors for LayerGeometry&#39;s.
void init(const edm::EventSetup &)
DetIdAssociator::MapRange getMapRange(const std::pair< float, float > &delta, const float dR)
T eta() const
Definition: PV3DBase.h:76
GlobalVector trkMomAtHcal
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
fixed size matrix
HLT enums.
void fillEcal(const edm::Event &, TrackDetMatchInfo &, const AssociatorParameters &)
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
std::vector< const HORecHit * > crossedHORecHits
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
edm::EDGetTokenT< edm::PCaloHitContainer > simHcalHitsToken
int charge() const
track electric charge
Definition: TrackBase.h:562
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
DetId geographicalId() const
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
virtual LocalError localPositionError() const =0
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
std::vector< const HORecHit * > hoRecHits
T x() const
Definition: PV3DBase.h:62
FreeTrajectoryState outerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
const SimTrack * simTrack
MC truth info.
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
edm::EDGetTokenT< CSCSegmentCollection > cscSegmentsToken
void fillHO(const edm::Event &, TrackDetMatchInfo &, const AssociatorParameters &)
void setMaterialMode(bool noMaterial)
Switch for material effects mode: no material effects if true.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
edm::EDGetTokenT< edm::PCaloHitContainer > simEcalHitsEEToken