CMS 3D CMS Logo

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
46 
47 // geometry
49 
50 // fastsim
56 
57 class MeasurementTracker;
58 
61 {
62 private:
63 
64  // tokens
65 
69 
70  // other data members
71  unsigned int nHitsPerSeed_;
72 
73  std::vector<std::vector<TrackingLayer>> seedingLayers;
75 
76  std::unique_ptr<SeedCreator> seedCreator;
78 
79  std::unique_ptr<SeedFinderSelector> seedFinderSelector;
80 public:
82 
83  void produce(edm::Event& e, const edm::EventSetup& es) override;
84 
85 
86 };
87 
88 
89 template class SeedingTree<TrackingLayer>;
90 template class SeedingNode<TrackingLayer>;
91 
93 {
94  // products
95  produces<TrajectorySeedCollection>();
96 
97  // consumes
98  recHitCombinationsToken = consumes<FastTrackerRecHitCombinationCollection>(conf.getParameter<edm::InputTag>("recHitCombinations"));
99  if (conf.exists("hitMasks"))
100  {
101  hitMasksToken = consumes<std::vector<bool> >(conf.getParameter<edm::InputTag>("hitMasks"));
102  }
103 
104  // read Layers
105  std::vector<std::string> layerStringList = conf.getParameter<edm::ParameterSet>("seedFinderSelector").getParameter<std::vector<std::string>>("layerList");
106  std::string layerBegin = *(layerStringList.cbegin());
107  nHitsPerSeed_ = 0;
108  for(auto it=layerStringList.cbegin(); it < layerStringList.cend(); ++it)
109  {
110  std::vector<TrackingLayer> trackingLayerList;
111  std::string line = *it;
113  unsigned int nHitsPerSeed = 0;
114  while (pos != std::string::npos)
115  {
116  pos=line.find("+");
117  std::string layer = line.substr(0, pos);
119  trackingLayerList.push_back(layerSpec);
120  line=line.substr(pos+1,std::string::npos);
121  nHitsPerSeed++;
122  }
123  if(it==layerStringList.cbegin())
124  {
125  nHitsPerSeed_ = nHitsPerSeed;
126  }
127  else if(nHitsPerSeed_!=nHitsPerSeed)
128  {
129  throw cms::Exception("FastSimTracking") << "All allowed seed layer definitions must have same elements";
130  }
131  _seedingTree.insert(trackingLayerList);
132  }
133 
134  // seed finder selector
135  if(conf.exists("seedFinderSelector"))
136  {
137  seedFinderSelector = std::make_unique<SeedFinderSelector>(conf.getParameter<edm::ParameterSet>("seedFinderSelector"),consumesCollector());
138  }
139 
141  trackingRegionToken = consumes<edm::OwnVector<TrackingRegion> >(conf.getParameter<edm::InputTag>("trackingRegions"));
142 
143  // seed creator
144  const edm::ParameterSet & seedCreatorPSet = conf.getParameter<edm::ParameterSet>("SeedCreatorPSet");
145  std::string seedCreatorName = seedCreatorPSet.getParameter<std::string>("ComponentName");
146  seedCreator = std::unique_ptr<SeedCreator>{SeedCreatorFactory::get()->create( seedCreatorName, seedCreatorPSet)};
147 
148 }
149 
150 
152 {
153 
154  // services
155  edm::ESHandle<TrackerTopology> trackerTopology;
156 
157  es.get<TrackerTopologyRcd>().get(trackerTopology);
158 
159  // input data
161  e.getByToken(recHitCombinationsToken, recHitCombinations);
162  const std::vector<bool> * hitMasks = nullptr;
164  {
165  edm::Handle<std::vector<bool> > hitMasksHandle;
166  e.getByToken(hitMasksToken,hitMasksHandle);
167  hitMasks = &(*hitMasksHandle);
168  }
169 
170  // output data
171  std::unique_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
172 
173  // read the regions;
175  e.getByToken(trackingRegionToken, hregions);
176  const auto& regions = *hregions;
177  // and make sure there is at least one region
178  if(regions.empty())
179  {
180  e.put(std::move(output));
181  return;
182  }
183 
184  // instantiate the seed finder
185  SeedFinder seedFinder(_seedingTree,*trackerTopology.product());
187  {
188  seedFinderSelector->initEvent(e,es);
189  seedFinder.addHitSelector(seedFinderSelector.get(),nHitsPerSeed_);
190  }
191 
192  // loop over the combinations
193  for ( unsigned icomb=0; icomb<recHitCombinations->size(); ++icomb)
194  {
195  FastTrackerRecHitCombination recHitCombination = (*recHitCombinations)[icomb];
196 
197  // create a list of hits cleaned from masked hits
198  std::vector<const FastTrackerRecHit * > seedHitCandidates;
199  for (const auto & _hit : recHitCombination )
200  {
201  if(hitMasks && fastTrackingUtilities::hitIsMasked(_hit.get(),*hitMasks))
202  {
203  continue;
204  }
205  seedHitCandidates.push_back(_hit.get());
206  }
207 
208  // loop over the regions
209  for(const auto& region: regions)
210  {
211  // set the region used in the selector
213  {
214  seedFinderSelector->setTrackingRegion(&region);
215  }
216 
217  // find hits compatible with the seed requirements
218  std::vector<unsigned int> seedHitNumbers = seedFinder.getSeed(seedHitCandidates);
219 
220  // create a seed from those hits
221  if (seedHitNumbers.size()>1)
222  {
223 
224  // copy the hits
226  for(unsigned iIndex = 0;iIndex < seedHitNumbers.size();++iIndex)
227  {
228  seedHits.push_back(seedHitCandidates[seedHitNumbers[iIndex]]->clone());
229  }
230  // make them aware of the combination they originate from
232 
233  // create the seed
234  seedCreator->init(region,es,nullptr);
235  seedCreator->makeSeed(
236  *output,
238  &seedHits[0],
239  &seedHits[1],
240  seedHits.size() >=3 ? &seedHits[2] : nullptr,
241  seedHits.size() >=4 ? &seedHits[3] : nullptr
242  )
243  );
244  break; // break the loop over the regions
245  }
246  }
247  }
248  e.put(std::move(output));
249 
250 }
251 
void setRecHitCombinationIndex(edm::OwnVector< T > &recHits, int32_t icomb)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
TrajectorySeedProducer(const edm::ParameterSet &conf)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< std::vector< bool > > hitMasksToken
#define nullptr
size_type size() const
Definition: OwnVector.h:264
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::OwnVector< TrackingRegion > > trackingRegionToken
uint16_t size_type
bool insert(const std::vector< DATA > &dataList)
Definition: SeedingTree.h:172
void push_back(D *&d)
Definition: OwnVector.h:290
void produce(edm::Event &e, const edm::EventSetup &es) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TrajectorySeed > TrajectorySeedCollection
std::unique_ptr< SeedFinderSelector > seedFinderSelector
static TrackingLayer createFromString(std::string layerSpecification)
bool hitIsMasked(const FastTrackerRecHit *hit, const std::vector< bool > &hitMasks)
std::vector< FastTrackerRecHitRef > FastTrackerRecHitCombination
std::vector< std::vector< TrackingLayer > > seedingLayers
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::EDGetTokenT< FastTrackerRecHitCombinationCollection > recHitCombinationsToken
T get() const
Definition: EventSetup.h:71
bool isUninitialized() const
Definition: EDGetToken.h:70
SeedingTree< TrackingLayer > _seedingTree
T const * product() const
Definition: ESHandle.h:86
std::unique_ptr< SeedCreator > seedCreator
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55