CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelTracksProducer.cc
Go to the documentation of this file.
1 #include <memory>
3 
6 
9 
12 
13 //Pixel Specific stuff
16 
19 
23 
28 #include <vector>
29 
30 using namespace pixeltrackfitting;
31 
33  theFitter(0),
34  theFilter(0),
35  theRegionProducer(0)
36 {
37 
38  produces<reco::TrackCollection>();
39  produces<TrackingRecHitCollection>();
40  produces<reco::TrackExtraCollection>();
41 
42  const edm::ParameterSet& regfactoryPSet = conf.getParameter<edm::ParameterSet>("RegionFactoryPSet");
43  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
44  theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
45 
46  const edm::ParameterSet& fitterPSet = conf.getParameter<edm::ParameterSet>("FitterPSet");
47  std::string fitterName = fitterPSet.getParameter<std::string>("ComponentName");
48  theFitter = PixelFitterFactory::get()->create( fitterName, fitterPSet);
49 
50  const edm::ParameterSet& filterPSet = conf.getParameter<edm::ParameterSet>("FilterPSet");
51  std::string filterName = filterPSet.getParameter<std::string>("ComponentName");
52  theFilter = PixelTrackFilterFactory::get()->create( filterName, filterPSet);
53 
54  // The name of the seed producer
55  seedProducer = conf.getParameter<edm::InputTag>("SeedProducer");
56 
57 }
58 
59 
60 // Virtual destructor needed.
62 
63  delete theFilter;
64  delete theFitter;
65  delete theRegionProducer;
66 
67 }
68 
69 
70 // Functions that gets called by framework every event
71 void
73 
74  std::auto_ptr<reco::TrackCollection> tracks(new reco::TrackCollection);
75  std::auto_ptr<TrackingRecHitCollection> recHits(new TrackingRecHitCollection);
76  std::auto_ptr<reco::TrackExtraCollection> trackExtras(new reco::TrackExtraCollection);
77  typedef std::vector<const TrackingRecHit *> RecHits;
78 
79  TracksWithRecHits pixeltracks;
80  TracksWithRecHits cleanedTracks;
81 
83  e.getByLabel(seedProducer,theSeeds);
84 
85  // No seed -> output an empty track collection
86  if(theSeeds->size() == 0) {
87  e.put(tracks);
88  e.put(recHits);
89  e.put(trackExtras);
90  return;
91  }
92 
93  //only one region Global, but it is called at every event...
94  //maybe there is a smarter way to set it only once
95  //NEED TO FIX
96  typedef std::vector<TrackingRegion* > Regions;
97  typedef Regions::const_iterator IR;
98  Regions regions = theRegionProducer->regions(e,es);
99  for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) {
100  const TrackingRegion & region = **ir;
101 
102  // Loop over the seeds
103  TrajectorySeedCollection::const_iterator aSeed = theSeeds->begin();
104  TrajectorySeedCollection::const_iterator lastSeed = theSeeds->end();
105  for ( ; aSeed!=lastSeed; ++aSeed ) {
106 
107  // Find the first hit and last hit of the Seed
108  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
109  edm::OwnVector<TrackingRecHit>::const_iterator aSeedingRecHit = theSeedingRecHitRange.first;
110  edm::OwnVector<TrackingRecHit>::const_iterator theLastSeedingRecHit = theSeedingRecHitRange.second;
111 
112  // Loop over the rechits
113  std::vector<const TrackingRecHit*> TripletHits(3,static_cast<const TrackingRecHit*>(0));
114  for ( unsigned i=0; aSeedingRecHit!=theLastSeedingRecHit; ++i,++aSeedingRecHit )
115  TripletHits[i] = &(*aSeedingRecHit);
116 
117  // fitting the triplet
118  reco::Track* track = theFitter->run(es, TripletHits, region);
119 
120  // decide if track should be skipped according to filter
121  if ( ! (*theFilter)(track) ) {
122  delete track;
123  continue;
124  }
125 
126  // add tracks
127  pixeltracks.push_back(TrackWithRecHits(track, TripletHits));
128 
129  }
130  }
131 
132  int cc=0;
133  int nTracks = pixeltracks.size();
134  for (int i = 0; i < nTracks; ++i) {
135 
136  reco::Track* track = pixeltracks.at(i).first;
137  const RecHits & hits = pixeltracks.at(i).second;
138 
139  for (unsigned int k = 0; k < hits.size(); k++) {
140  TrackingRecHit *hit = (hits.at(k))->clone();
141  track->setHitPattern(*hit, k);
142  recHits->push_back(hit);
143  }
144 
145  tracks->push_back(*track);
146  delete track;
147 
148  }
149 
151 
152  for (int k = 0; k < nTracks; ++k) {
153 
154  // reco::TrackExtra* theTrackExtra = new reco::TrackExtra();
155  reco::TrackExtra theTrackExtra;
156 
157  //fill the TrackExtra with TrackingRecHitRef
158  // unsigned int nHits = tracks->at(k).numberOfValidHits();
159  unsigned nHits = 3; // We are dealing with triplets!
160  for(unsigned int i = 0; i < nHits; ++i) {
161  theTrackExtra.add(TrackingRecHitRef(ohRH,cc++));
162  //theTrackExtra->add(TrackingRecHitRef(ohRH,cc));
163  //cc++;
164  }
165 
166  trackExtras->push_back(theTrackExtra);
167  //trackExtras->push_back(*theTrackExtra);
168  //delete theTrackExtra;
169  }
170 
172 
173  for (int k = 0; k < nTracks; k++) {
174 
175  const reco::TrackExtraRef theTrackExtraRef(ohTE,k);
176  (tracks->at(k)).setExtra(theTrackExtraRef);
177 
178  }
179 
180  e.put(tracks);
181 
182  // Avoid a memory leak !
183  unsigned nRegions = regions.size();
184  for ( unsigned iRegions=0; iRegions<nRegions; ++iRegions ) {
185  delete regions[iRegions];
186  }
187 
188 }
189 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual reco::Track * run(const edm::EventSetup &es, const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const =0
edm::InputTag seedProducer
PixelTracksProducer(const edm::ParameterSet &conf)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
virtual void produce(edm::Event &ev, const edm::EventSetup &es)
TrackingRegionProducer * theRegionProducer
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
const PixelTrackFilter * theFilter
std::pair< const_iterator, const_iterator > range
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
std::pair< reco::Track *, std::vector< const TrackingRecHit * > > TrackWithRecHits
tuple conf
Definition: dbtoconf.py:185
int k[5][pyjets_maxn]
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:246
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
tuple tracks
Definition: testEve_cfg.py:39
T * clone(const T *tp)
Definition: Ptr.h:42
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
const PixelFitter * theFitter
std::vector< TrackWithRecHits > TracksWithRecHits
T get(const Candidate &c)
Definition: component.h:56
virtual std::vector< TrackingRegion * > regions(const edm::Event &ev, const edm::EventSetup &es) const =0