CMS 3D CMS Logo

PixelTracksProducer.cc
Go to the documentation of this file.
1 #include <memory>
3 
7 
10 
12 
13 //Pixel Specific stuff
16 
18 
22 
27 #include <vector>
28 
29 using namespace pixeltrackfitting;
30 
32  : theRegionProducer(nullptr), ttopoToken(esConsumes()) {
33  produces<reco::TrackCollection>();
34  produces<TrackingRecHitCollection>();
35  produces<reco::TrackExtraCollection>();
36 
37  const edm::ParameterSet& regfactoryPSet = conf.getParameter<edm::ParameterSet>("RegionFactoryPSet");
38  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
39  theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName, regfactoryPSet, consumesCollector());
40 
41  fitterToken = consumes<PixelFitter>(conf.getParameter<edm::InputTag>("Fitter"));
42  filterToken = consumes<PixelTrackFilter>(conf.getParameter<edm::InputTag>("Filter"));
43 
44  // The name of the seed producer
45  auto seedProducer = conf.getParameter<edm::InputTag>("SeedProducer");
46  seedProducerToken = consumes<TrajectorySeedCollection>(seedProducer);
47 }
48 
49 // Virtual destructor needed.
51 
52 // Functions that gets called by framework every event
54  std::unique_ptr<reco::TrackCollection> tracks(new reco::TrackCollection);
55  std::unique_ptr<TrackingRecHitCollection> recHits(new TrackingRecHitCollection);
56  std::unique_ptr<reco::TrackExtraCollection> trackExtras(new reco::TrackExtraCollection);
57  typedef std::vector<const TrackingRecHit*> RecHits;
58 
59  TracksWithRecHits pixeltracks;
60  TracksWithRecHits cleanedTracks;
61 
62  const TrackerTopology& ttopo = es.getData(ttopoToken);
63 
65  e.getByToken(fitterToken, hfitter);
66  const PixelFitter& fitter = *hfitter;
67 
69  e.getByToken(filterToken, hfilter);
70  const PixelTrackFilter& theFilter = *hfilter;
71 
73  e.getByToken(seedProducerToken, theSeeds);
74 
75  // No seed -> output an empty track collection
76  if (theSeeds->empty()) {
77  e.put(std::move(tracks));
78  e.put(std::move(recHits));
79  e.put(std::move(trackExtras));
80  return;
81  }
82 
83  //only one region Global, but it is called at every event...
84  //maybe there is a smarter way to set it only once
85  //NEED TO FIX
86  typedef std::vector<std::unique_ptr<TrackingRegion> > Regions;
87  typedef Regions::const_iterator IR;
88  Regions regions = theRegionProducer->regions(e, es);
89  for (IR ir = regions.begin(), irEnd = regions.end(); ir < irEnd; ++ir) {
90  const TrackingRegion& region = **ir;
91 
92  // Loop over the seeds
93  TrajectorySeedCollection::const_iterator aSeed = theSeeds->begin();
94  TrajectorySeedCollection::const_iterator lastSeed = theSeeds->end();
95  for (; aSeed != lastSeed; ++aSeed) {
96  // Loop over the rechits
97  std::vector<const TrackingRecHit*> TripletHits(3, static_cast<const TrackingRecHit*>(nullptr));
98  unsigned int iRecHit = 0;
99  for (auto const& recHit : aSeed->recHits()) {
100  TripletHits[iRecHit] = &recHit;
101  ++iRecHit;
102  }
103 
104  // fitting the triplet
105  std::unique_ptr<reco::Track> track = fitter.run(TripletHits, region);
106 
107  // decide if track should be skipped according to filter
108  if (!theFilter(track.get(), TripletHits)) {
109  continue;
110  }
111 
112  // add tracks
113  pixeltracks.push_back(TrackWithRecHits(track.release(), TripletHits));
114  }
115  }
116 
117  int cc = 0;
118  int nTracks = pixeltracks.size();
119  for (int i = 0; i < nTracks; ++i) {
120  reco::Track* track = pixeltracks.at(i).first;
121  const RecHits& hits = pixeltracks.at(i).second;
122 
123  for (unsigned int k = 0; k < hits.size(); k++) {
124  TrackingRecHit* hit = (hits.at(k))->clone();
125  track->appendHitPattern(*hit, ttopo);
126  recHits->push_back(hit);
127  }
128 
129  tracks->push_back(*track);
130  delete track;
131  }
132 
135 
136  for (int k = 0; k < nTracks; ++k) {
137  // reco::TrackExtra* theTrackExtra = new reco::TrackExtra();
138  reco::TrackExtra theTrackExtra;
139 
140  //fill the TrackExtra with TrackingRecHitRef
141  // unsigned int nHits = tracks->at(k).numberOfValidHits();
142  const unsigned nHits = 3; // We are dealing with triplets!
143  theTrackExtra.setHits(ohRHProd, cc, nHits);
144  cc += nHits;
145 
146  trackExtras->push_back(theTrackExtra);
147  //trackExtras->push_back(*theTrackExtra);
148  //delete theTrackExtra;
149  }
150 
152 
153  for (int k = 0; k < nTracks; k++) {
154  const reco::TrackExtraRef theTrackExtraRef(ohTE, k);
155  (tracks->at(k)).setExtra(theTrackExtraRef);
156  }
157 
158  e.put(std::move(tracks));
159 }
160 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void produce(edm::Event &ev, const edm::EventSetup &es) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
PixelTracksProducer(const edm::ParameterSet &conf)
std::pair< reco::Track *, std::vector< const TrackingRecHit * > > TrackWithRecHits
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::unique_ptr< reco::Track > run(const std::vector< const TrackingRecHit *> &hits, const TrackingRegion &region) const
Definition: PixelFitter.h:15
edm::EDGetTokenT< TrajectorySeedCollection > seedProducerToken
edm::EDGetTokenT< PixelTrackFilter > filterToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::unique_ptr< TrackingRegionProducer > theRegionProducer
std::vector< TrackWithRecHits > TracksWithRecHits
#define get
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
edm::EDGetTokenT< PixelFitter > fitterToken
def move(src, dest)
Definition: eostools.py:511
~PixelTracksProducer() override