CMS 3D CMS Logo

PixelTracksProducer.cc
Go to the documentation of this file.
1 #include <memory>
3 
8 
11 
13 
16 
17 //Pixel Specific stuff
20 
22 
26 
31 #include <vector>
32 
33 using namespace pixeltrackfitting;
34 
36  theRegionProducer(nullptr)
37 {
38 
39  produces<reco::TrackCollection>();
40  produces<TrackingRecHitCollection>();
41  produces<reco::TrackExtraCollection>();
42 
43  const edm::ParameterSet& regfactoryPSet = conf.getParameter<edm::ParameterSet>("RegionFactoryPSet");
44  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
45  theRegionProducer = std::unique_ptr<TrackingRegionProducer>{TrackingRegionProducerFactory::get()->create(regfactoryName,
46  regfactoryPSet, consumesCollector())};
47 
48  fitterToken = consumes<PixelFitter>(conf.getParameter<edm::InputTag>("Fitter"));
49  filterToken = consumes<PixelTrackFilter>(conf.getParameter<edm::InputTag>("Filter"));
50 
51  // The name of the seed producer
52  auto seedProducer = conf.getParameter<edm::InputTag>("SeedProducer");
53  seedProducerToken = consumes<TrajectorySeedCollection>(seedProducer);
54 
55 }
56 
57 
58 // Virtual destructor needed.
60 
61 
62 // Functions that gets called by framework every event
63 void
65 
66  std::unique_ptr<reco::TrackCollection> tracks(new reco::TrackCollection);
67  std::unique_ptr<TrackingRecHitCollection> recHits(new TrackingRecHitCollection);
68  std::unique_ptr<reco::TrackExtraCollection> trackExtras(new reco::TrackExtraCollection);
69  typedef std::vector<const TrackingRecHit *> RecHits;
70 
71  TracksWithRecHits pixeltracks;
72  TracksWithRecHits cleanedTracks;
73 
75  es.get<TrackerTopologyRcd>().get(httopo);
76  const TrackerTopology& ttopo = *httopo;
77 
79  e.getByToken(fitterToken, hfitter);
80  const PixelFitter& fitter = *hfitter;
81 
83  e.getByToken(filterToken, hfilter);
84  const PixelTrackFilter& theFilter = *hfilter;
85 
87  e.getByToken(seedProducerToken,theSeeds);
88 
89  // No seed -> output an empty track collection
90  if(theSeeds->empty()) {
91  e.put(std::move(tracks));
92  e.put(std::move(recHits));
93  e.put(std::move(trackExtras));
94  return;
95  }
96 
97  //only one region Global, but it is called at every event...
98  //maybe there is a smarter way to set it only once
99  //NEED TO FIX
100  typedef std::vector<std::unique_ptr<TrackingRegion> > Regions;
101  typedef Regions::const_iterator IR;
102  Regions regions = theRegionProducer->regions(e,es);
103  for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) {
104  const TrackingRegion & region = **ir;
105 
106  // Loop over the seeds
107  TrajectorySeedCollection::const_iterator aSeed = theSeeds->begin();
108  TrajectorySeedCollection::const_iterator lastSeed = theSeeds->end();
109  for ( ; aSeed!=lastSeed; ++aSeed ) {
110 
111  // Find the first hit and last hit of the Seed
112  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
113  edm::OwnVector<TrackingRecHit>::const_iterator aSeedingRecHit = theSeedingRecHitRange.first;
114  edm::OwnVector<TrackingRecHit>::const_iterator theLastSeedingRecHit = theSeedingRecHitRange.second;
115 
116  // Loop over the rechits
117  std::vector<const TrackingRecHit*> TripletHits(3,static_cast<const TrackingRecHit*>(nullptr));
118  for ( unsigned i=0; aSeedingRecHit!=theLastSeedingRecHit; ++i,++aSeedingRecHit )
119  TripletHits[i] = &(*aSeedingRecHit);
120 
121  // fitting the triplet
122  std::unique_ptr<reco::Track> track = fitter.run(TripletHits, region, es);
123 
124  // decide if track should be skipped according to filter
125  if ( ! theFilter(track.get(), TripletHits) ) {
126  continue;
127  }
128 
129  // add tracks
130  pixeltracks.push_back(TrackWithRecHits(track.release(), TripletHits));
131 
132  }
133  }
134 
135  int cc=0;
136  int nTracks = pixeltracks.size();
137  for (int i = 0; i < nTracks; ++i) {
138 
139  reco::Track* track = pixeltracks.at(i).first;
140  const RecHits & hits = pixeltracks.at(i).second;
141 
142  for (unsigned int k = 0; k < hits.size(); k++) {
143  TrackingRecHit *hit = (hits.at(k))->clone();
144  track->appendHitPattern(*hit, ttopo);
145  recHits->push_back(hit);
146  }
147 
148  tracks->push_back(*track);
149  delete track;
150 
151  }
152 
155 
156  for (int k = 0; k < nTracks; ++k) {
157 
158  // reco::TrackExtra* theTrackExtra = new reco::TrackExtra();
159  reco::TrackExtra theTrackExtra;
160 
161  //fill the TrackExtra with TrackingRecHitRef
162  // unsigned int nHits = tracks->at(k).numberOfValidHits();
163  const unsigned nHits = 3; // We are dealing with triplets!
164  theTrackExtra.setHits( ohRHProd, cc, nHits);
165  cc += nHits;
166 
167  trackExtras->push_back(theTrackExtra);
168  //trackExtras->push_back(*theTrackExtra);
169  //delete theTrackExtra;
170  }
171 
173 
174  for (int k = 0; k < nTracks; k++) {
175 
176  const reco::TrackExtraRef theTrackExtraRef(ohTE,k);
177  (tracks->at(k)).setExtra(theTrackExtraRef);
178 
179  }
180 
181  e.put(std::move(tracks));
182 
183 }
184 
T getParameter(std::string const &) const
void produce(edm::Event &ev, const edm::EventSetup &es) override
const unsigned int nTracks(const reco::Vertex &sv)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
PixelTracksProducer(const edm::ParameterSet &conf)
#define nullptr
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< TrajectorySeedCollection > seedProducerToken
edm::EDGetTokenT< PixelTrackFilter > filterToken
std::pair< const_iterator, const_iterator > range
std::pair< reco::Track *, std::vector< const TrackingRecHit * > > TrackWithRecHits
std::unique_ptr< reco::Track > run(const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region, const edm::EventSetup &setup) const
Definition: PixelFitter.h:15
int k[5][pyjets_maxn]
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
bool appendHitPattern(const TrackingRecHit &hit, const TrackerTopology &ttopo)
append a single hit to the HitPattern
Definition: TrackBase.h:495
std::unique_ptr< TrackingRegionProducer > theRegionProducer
std::vector< TrackWithRecHits > TracksWithRecHits
T get() const
Definition: EventSetup.h:71
edm::EDGetTokenT< PixelFitter > fitterToken
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
~PixelTracksProducer() override