CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackListCombiner.cc
Go to the documentation of this file.
1 #include "TrackListCombiner.h"
2 
6 
8 
12 
15 
16 using namespace std;
17 
18 /*****************************************************************************/
20 {
21  trackProducers = ps.getParameter<vector<string> >("trackProducers");
22 
23  produces<reco::TrackCollection>();
24  produces<reco::TrackExtraCollection>();
25  produces<TrackingRecHitCollection>();
26  produces<vector<Trajectory> >();
27  produces<TrajTrackAssociationCollection>();
28 }
29 
30 /*****************************************************************************/
32 {
33 }
34 
35 /*****************************************************************************/
37 {
38  auto_ptr<reco::TrackCollection> recoTracks
40  auto_ptr<reco::TrackExtraCollection> recoTrackExtras
42  auto_ptr<TrackingRecHitCollection> recoHits
44  auto_ptr<vector<Trajectory> > recoTrajectories
45  (new vector<Trajectory>);
46  auto_ptr<TrajTrackAssociationCollection> recoTrajTrackMap
48 
49  LogTrace("MinBiasTracking")
50  << "[TrackListCombiner]";
51 
52  // Go through all track producers
53  int i = 1;
54  for(vector<string>::iterator trackProducer = trackProducers.begin();
55  trackProducer!= trackProducers.end();
56  trackProducer++, i++)
57  {
59  switch(i)
60  {
61  case 1: algo = reco::TrackBase::lowPtTripletStep; break;
62  case 2: algo = reco::TrackBase::pixelPairStep; break;
63  case 3: algo = reco::TrackBase::detachedTripletStep; break;
64  default: algo = reco::TrackBase::undefAlgorithm;
65  }
66 
67  edm::Handle<vector<Trajectory> > theTrajectoryCollection;
69 
70  ev.getByLabel(*trackProducer, theTrajectoryCollection);
71  ev.getByLabel(*trackProducer, theAssoMap);
72 
73  LogTrace("MinBiasTracking")
74  << " [TrackListCombiner] " << *trackProducer
75  << " : " << theAssoMap->size();
76 
77 
78  // The track collection iterators
81  anAssociation = theAssoMap->begin();
82  lastAssociation = theAssoMap->end();
83 
84  // Build the map of correspondance between reco tracks and sim tracks
85  for ( ; anAssociation != lastAssociation; ++anAssociation )
86  {
87  edm::Ref<vector<Trajectory> > aTrajectoryRef = anAssociation->key;
88  reco::TrackRef aTrackRef = anAssociation->val;
89 
90  // A copy of the track
91  reco::Track aRecoTrack(*aTrackRef);
92 
93  // Set algorithm
94  aRecoTrack.setAlgorithm(algo);
95 
96  recoTracks->push_back(aRecoTrack);
97 
98  // A copy of the hits
99  unsigned nh = aRecoTrack.recHitsSize();
100  for(unsigned ih=0; ih<nh; ++ih)
101  {
102  TrackingRecHit *hit = aRecoTrack.recHit(ih)->clone();
103  recoHits->push_back(hit);
104  }
105 
106  // A copy of the trajectories
107  recoTrajectories->push_back(*aTrajectoryRef);
108 
109  }
110  }
111 
112  LogTrace("MinBiasTracking")
113  << " [TrackListCombiner] allTracks : " << recoTracks->size()
114  << "|" << recoTrajectories->size();
115 
116  // Save the tracking recHits
117  edm::OrphanHandle<TrackingRecHitCollection> theRecoHits = ev.put(recoHits);
118 
119  edm::RefProd<TrackingRecHitCollection> theRecoHitsProd(theRecoHits);
120  // Create the track extras and add the references to the rechits
121  unsigned hits = 0;
122  unsigned nTracks = recoTracks->size();
123  recoTrackExtras->reserve(nTracks); // To save some time at push_back
124  for(unsigned index = 0; index < nTracks; ++index )
125  {
126  reco::Track& aTrack = recoTracks->at(index);
127  reco::TrackExtra aTrackExtra(aTrack.outerPosition(),
128  aTrack.outerMomentum(),
129  aTrack.outerOk(),
130  aTrack.innerPosition(),
131  aTrack.innerMomentum(),
132  aTrack.innerOk(),
133  aTrack.outerStateCovariance(),
134  aTrack.outerDetId(),
135  aTrack.innerStateCovariance(),
136  aTrack.innerDetId(),
137  aTrack.seedDirection(),
138  aTrack.seedRef());
139 
140  unsigned nHits = aTrack.recHitsSize();
141  aTrackExtra.setHits(theRecoHitsProd,hits,nHits);
142  hits +=nHits;
143 
144  recoTrackExtras->push_back(aTrackExtra);
145  }
146 
147  // Save the track extras
149  ev.put(recoTrackExtras);
150 
151  // Add the reference to the track extra in the tracks
152  for(unsigned index = 0; index<nTracks; ++index)
153  {
154  const reco::TrackExtraRef theTrackExtraRef(theRecoTrackExtras,index);
155  (recoTracks->at(index)).setExtra(theTrackExtraRef);
156  }
157 
158  // Save the tracks
159  edm::OrphanHandle<reco::TrackCollection> theRecoTracks = ev.put(recoTracks);
160 
161  // Save the trajectories
162  edm::OrphanHandle<vector<Trajectory> > theRecoTrajectories =
163  ev.put(recoTrajectories);
164 
165  // Create and set the trajectory/track association map
166  for(unsigned index = 0; index<nTracks; ++index)
167  {
168  edm::Ref<vector<Trajectory> > trajRef( theRecoTrajectories, index );
169  edm::Ref<reco::TrackCollection> tkRef( theRecoTracks, index );
170  recoTrajTrackMap->insert(trajRef,tkRef);
171  }
172 
173  // Save the association map
174  ev.put(recoTrajTrackMap);
175 }
176 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:50
bool ev
key_type key() const
Accessor for product key.
Definition: Ref.h:264
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
TrackAlgorithm
track algorithm
Definition: TrackBase.h:99
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:75
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
#define LogTrace(id)
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
edm::RefToBase< TrajectorySeed > seedRef() const
Definition: Track.h:213
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:45
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:80
TrackListCombiner(const edm::ParameterSet &ps)
void setAlgorithm(const TrackAlgorithm a)
Track algorithm.
Definition: TrackBase.h:810
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:114
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:204
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99