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