CMS 3D CMS Logo

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