CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrajectorySeedProducer.cc
Go to the documentation of this file.
1 
21 // system
22 #include <memory>
23 #include <vector>
24 #include <string>
25 
26 // framework
34 
35 // data formats
40 
41 // reco track classes
52 
53 // geometry
55 
56 // fastsim
61 
63  : public edm::stream::EDProducer<>
64 {
65 private:
66 
67  // tokens
68 
71 
72  // other data members
73 
74  std::vector<std::vector<TrackingLayer>> seedingLayers;
76 
77  std::unique_ptr<SeedCreator> seedCreator;
78  std::unique_ptr<TrackingRegionProducer> theRegionProducer;
80 
82 
83 public:
84 
86 
87  virtual void produce(edm::Event& e, const edm::EventSetup& es);
88 
89 };
90 
91 template class SeedingTree<TrackingLayer>;
92 template class SeedingNode<TrackingLayer>;
93 
95 {
96 
97  // produces
98  produces<TrajectorySeedCollection>();
99 
100  // consumes
101  recHitCombinationsToken = consumes<FastTrackerRecHitCombinationCollection>(conf.getParameter<edm::InputTag>("recHitCombinations"));
102  if (conf.exists("hitMasks")){
103  hitMasksToken = consumes<std::vector<bool> >(conf.getParameter<edm::InputTag>("hitMasks"));
104  }
105 
106  // read Layers
107  std::vector<std::string> layerStringList = conf.getParameter<std::vector<std::string>>("layerList");
108  for(auto it=layerStringList.cbegin(); it < layerStringList.cend(); ++it)
109  {
110  std::vector<TrackingLayer> trackingLayerList;
111  std::string line = *it;
113  while (pos != std::string::npos)
114  {
115  pos=line.find("+");
116  std::string layer = line.substr(0, pos);
118 
119  trackingLayerList.push_back(layerSpec);
120  line=line.substr(pos+1,std::string::npos);
121  }
122  _seedingTree.insert(trackingLayerList);
123  }
124 
126  edm::ParameterSet regfactoryPSet = conf.getParameter<edm::ParameterSet>("RegionFactoryPSet");
127  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
128  theRegionProducer.reset(TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet, consumesCollector()));
129 
130  // seed creator
131  const edm::ParameterSet & seedCreatorPSet = conf.getParameter<edm::ParameterSet>("SeedCreatorPSet");
132  std::string seedCreatorName = seedCreatorPSet.getParameter<std::string>("ComponentName");
133  seedCreator.reset(SeedCreatorFactory::get()->create( seedCreatorName, seedCreatorPSet));
134 
135  // other parameters
136  measurementTrackerLabel = conf.getParameter<std::string>("measurementTracker");
137  skipSeedFinderSelector = conf.getUntrackedParameter<bool>("skipSeedFinderSelector",false);
138 
139 }
140 
141 
143 {
144 
145  // services
147  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
148 
149  es.get<TrackerTopologyRcd>().get(trackerTopology);
150  es.get<CkfComponentsRecord>().get(measurementTrackerLabel, measurementTrackerHandle);
151  const MeasurementTracker * measurementTracker = &(*measurementTrackerHandle);
152 
153  // input data
155  e.getByToken(recHitCombinationsToken, recHitCombinations);
156  const std::vector<bool> * hitMasks = 0;
158  {
159  edm::Handle<std::vector<bool> > hitMasksHandle;
160  e.getByToken(hitMasksToken,hitMasksHandle);
161  hitMasks = &(*hitMasksHandle);
162  }
163 
164  // output data
165  std::unique_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
166 
167  // produce the regions;
168  const auto regions = theRegionProducer->regions(e,es);
169  // and make sure there is at least one region
170  if(regions.size() == 0)
171  {
172  e.put(std::move(output));
173  return;
174  }
175 
176  // pointer to selected region
177  TrackingRegion * selectedTrackingRegion = 0;
178 
179  // define a lambda function
180  // to select hit pairs, triplets, ... compatible with the region
181  SeedFinder::Selector selectorFunction = [&es,&measurementTracker,&selectedTrackingRegion](const std::vector<const FastTrackerRecHit*>& hits) -> bool
182  {
183  // criteria for hit pairs
184  // based on HitPairGeneratorFromLayerPair::doublets( const TrackingRegion& region, const edm::Event & iEvent, const edm::EventSetup& iSetup, Layers layers)
185  if (hits.size()==2)
186  {
187  const FastTrackerRecHit * innerHit = hits[0];
188  const FastTrackerRecHit * outerHit = hits[1];
189 
190  const DetLayer * innerLayer = measurementTracker->geometricSearchTracker()->detLayer(innerHit->det()->geographicalId());
191  const DetLayer * outerLayer = measurementTracker->geometricSearchTracker()->detLayer(outerHit->det()->geographicalId());
192 
193  std::vector<BaseTrackerRecHit const *> innerHits(1,(const BaseTrackerRecHit*) innerHit->hit());
194  std::vector<BaseTrackerRecHit const *> outerHits(1,(const BaseTrackerRecHit*) outerHit->hit());
195 
196  //const RecHitsSortedInPhi* ihm=new RecHitsSortedInPhi (innerHits, selectedTrackingRegion->origin(), innerLayer);
197  //const RecHitsSortedInPhi* ohm=new RecHitsSortedInPhi (outerHits, selectedTrackingRegion->origin(), outerLayer);
198  const RecHitsSortedInPhi ihm(innerHits, selectedTrackingRegion->origin(), innerLayer);
199  const RecHitsSortedInPhi ohm(outerHits, selectedTrackingRegion->origin(), outerLayer);
200 
201  HitDoublets result(ihm,ohm);
202  HitPairGeneratorFromLayerPair::doublets(*selectedTrackingRegion,*innerLayer,*outerLayer,ihm,ohm,es,0,result);
203 
204  if(result.size()!=0)
205  {
206  return true;
207  }
208  else
209  {
210  return false;
211  }
212  }
213  else
214  {
215 
216  // no criteria for hit combinations that are not pairs
217  return true;
218  }
219  };
220 
222  {
223  selectedTrackingRegion = regions[0].get();
224  selectorFunction = [](const std::vector<const FastTrackerRecHit*>& hits) -> bool
225  {
226  return true;
227  };
228  }
229 
230 
231  // instantiate the seed finder
232  SeedFinder seedFinder(_seedingTree,*trackerTopology.product());
233  seedFinder.setHitSelector(selectorFunction);
234 
235  // loop over the combinations
236  for ( unsigned icomb=0; icomb<recHitCombinations->size(); ++icomb)
237  {
238  FastTrackerRecHitCombination recHitCombination = (*recHitCombinations)[icomb];
239 
240  // create a list of hits cleaned from masked hits
241  std::vector<const FastTrackerRecHit * > seedHitCandidates;
242  for (const auto & _hit : recHitCombination )
243  {
244  if(hitMasks && fastTrackingUtilities::hitIsMasked(_hit.get(),hitMasks))
245  {
246  continue;
247  }
248  seedHitCandidates.push_back(_hit.get());
249  }
250 
251  // loop over the regions
252  for(auto region = regions.begin();region != regions.end(); ++region)
253  {
254 
255  // set the region
256  selectedTrackingRegion = region->get();
257 
258  // find the hits on the seeds
259  std::vector<unsigned int> seedHitNumbers = seedFinder.getSeed(seedHitCandidates);
260 
261  // create a seed from those hits
262  if (seedHitNumbers.size()>1)
263  {
264 
265  // copy the hits and make them aware of the combination they originate from
267  for(unsigned iIndex = 0;iIndex < seedHitNumbers.size();++iIndex)
268  {
269  seedHits.push_back(seedHitCandidates[seedHitNumbers[iIndex]]->clone());
270  }
272 
273  seedCreator->init(*selectedTrackingRegion,es,0);
274  seedCreator->makeSeed(
275  *output,
277  &seedHits[0],
278  &seedHits[1],
279  seedHits.size() >=3 ? &seedHits[2] : nullptr,
280  seedHits.size() >=4 ? &seedHits[3] : nullptr
281  )
282  );
283  break; // break the loop over the regions
284  }
285  }
286  }
287  e.put(std::move(output));
288 
289 }
290 
void setRecHitCombinationIndex(edm::OwnVector< T > &recHits, int32_t icomb)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< FastTrackerRecHitCombinationCollection > recHitCombinationsToken
TrajectorySeedProducer(const edm::ParameterSet &conf)
GlobalPoint const & origin() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
tuple measurementTracker
size_type size() const
Definition: OwnVector.h:264
BaseTrackerRecHit const * hit() const final
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual void produce(edm::Event &e, const edm::EventSetup &es)
bool hitIsMasked(const FastTrackerRecHit *hit, const std::vector< bool > *hitMasks)
std::unique_ptr< SeedCreator > seedCreator
#define nullptr
uint16_t size_type
std::function< bool(const std::vector< const FastTrackerRecHit * > &hits)> Selector
Definition: SeedFinder.h:19
edm::EDGetTokenT< std::vector< bool > > hitMasksToken
tuple result
Definition: mps_fire.py:95
std::vector< std::vector< TrackingLayer > > seedingLayers
bool insert(const std::vector< DATA > &dataList)
Definition: SeedingTree.h:178
std::unique_ptr< TrackingRegionProducer > theRegionProducer
void push_back(D *&d)
Definition: OwnVector.h:290
const TrackerTopology * trackerTopology
std::vector< TrajectorySeed > TrajectorySeedCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
const GeomDet * det() const
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def move
Definition: eostools.py:510
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
static TrackingLayer createFromString(std::string layerSpecification)
HitDoublets doublets(const TrackingRegion &reg, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
std::vector< FastTrackerRecHitRef > FastTrackerRecHitCombination
const T & get() const
Definition: EventSetup.h:56
SeedingTree< TrackingLayer > _seedingTree
T const * product() const
Definition: ESHandle.h:86
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
bool isUninitialized() const
Definition: EDGetToken.h:73
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:55