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 
24 
29 #include <vector>
30 
31 using namespace pixeltrackfitting;
32 
34  theFitter(0),
35  theFilter(0),
36  theRegionProducer(0)
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 = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
46 
47  const edm::ParameterSet& fitterPSet = conf.getParameter<edm::ParameterSet>("FitterPSet");
48  std::string fitterName = fitterPSet.getParameter<std::string>("ComponentName");
49  theFitter = PixelFitterFactory::get()->create( fitterName, fitterPSet);
50 
51  const edm::ParameterSet& filterPSet = conf.getParameter<edm::ParameterSet>("FilterPSet");
52  std::string filterName = filterPSet.getParameter<std::string>("ComponentName");
53  theFilter = PixelTrackFilterFactory::get()->create( filterName, filterPSet);
54 
55  // The name of the seed producer
56  seedProducer = conf.getParameter<edm::InputTag>("SeedProducer");
57 
58 }
59 
60 
61 // Virtual destructor needed.
63 
64  delete theFilter;
65  delete theFitter;
66  delete theRegionProducer;
67 
68 }
69 
70 
71 // Functions that gets called by framework every event
72 void
74 
75  std::auto_ptr<reco::TrackCollection> tracks(new reco::TrackCollection);
76  std::auto_ptr<TrackingRecHitCollection> recHits(new TrackingRecHitCollection);
77  std::auto_ptr<reco::TrackExtraCollection> trackExtras(new reco::TrackExtraCollection);
78  typedef std::vector<const TrackingRecHit *> RecHits;
79 
80  TracksWithRecHits pixeltracks;
81  TracksWithRecHits cleanedTracks;
82 
84  e.getByLabel(seedProducer,theSeeds);
85 
86  // No seed -> output an empty track collection
87  if(theSeeds->size() == 0) {
88  e.put(tracks);
89  e.put(recHits);
90  e.put(trackExtras);
91  return;
92  }
93 
94  //only one region Global, but it is called at every event...
95  //maybe there is a smarter way to set it only once
96  //NEED TO FIX
97  typedef std::vector<TrackingRegion* > Regions;
98  typedef Regions::const_iterator IR;
99  Regions regions = theRegionProducer->regions(e,es);
100  for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) {
101  const TrackingRegion & region = **ir;
102 
103  // Loop over the seeds
104  TrajectorySeedCollection::const_iterator aSeed = theSeeds->begin();
105  TrajectorySeedCollection::const_iterator lastSeed = theSeeds->end();
106  for ( ; aSeed!=lastSeed; ++aSeed ) {
107 
108  // Find the first hit and last hit of the Seed
109  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
110  edm::OwnVector<TrackingRecHit>::const_iterator aSeedingRecHit = theSeedingRecHitRange.first;
111  edm::OwnVector<TrackingRecHit>::const_iterator theLastSeedingRecHit = theSeedingRecHitRange.second;
112 
113  // Loop over the rechits
114  std::vector<const TrackingRecHit*> TripletHits(3,static_cast<const TrackingRecHit*>(0));
115  for ( unsigned i=0; aSeedingRecHit!=theLastSeedingRecHit; ++i,++aSeedingRecHit )
116  TripletHits[i] = &(*aSeedingRecHit);
117 
118  // fitting the triplet
119  reco::Track* track = theFitter->run(es, TripletHits, region);
120 
121  // decide if track should be skipped according to filter
122  if ( ! (*theFilter)(track) ) {
123  delete track;
124  continue;
125  }
126 
127  // add tracks
128  pixeltracks.push_back(TrackWithRecHits(track, TripletHits));
129 
130  }
131  }
132 
133  int cc=0;
134  int nTracks = pixeltracks.size();
135  for (int i = 0; i < nTracks; ++i) {
136 
137  reco::Track* track = pixeltracks.at(i).first;
138  const RecHits & hits = pixeltracks.at(i).second;
139 
140  for (unsigned int k = 0; k < hits.size(); k++) {
141  TrackingRecHit *hit = (hits.at(k))->clone();
142  track->setHitPattern(*hit, k);
143  recHits->push_back(hit);
144  }
145 
146  tracks->push_back(*track);
147  delete track;
148 
149  }
150 
152 
153  for (int k = 0; k < nTracks; ++k) {
154 
155  // reco::TrackExtra* theTrackExtra = new reco::TrackExtra();
156  reco::TrackExtra theTrackExtra;
157 
158  //fill the TrackExtra with TrackingRecHitRef
159  // unsigned int nHits = tracks->at(k).numberOfValidHits();
160  unsigned nHits = 3; // We are dealing with triplets!
161  for(unsigned int i = 0; i < nHits; ++i) {
162  theTrackExtra.add(TrackingRecHitRef(ohRH,cc++));
163  //theTrackExtra->add(TrackingRecHitRef(ohRH,cc));
164  //cc++;
165  }
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(tracks);
182 
183  // Avoid a memory leak !
184  unsigned nRegions = regions.size();
185  for ( unsigned iRegions=0; iRegions<nRegions; ++iRegions ) {
186  delete regions[iRegions];
187  }
188 
189 }
190 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::InputTag seedProducer
PixelTracksProducer(const edm::ParameterSet &conf)
virtual reco::Track * run(const edm::EventSetup &es, const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const
Definition: PixelFitter.h:17
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:85
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:356
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
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
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