CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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
33 
34 // data formats
39 
40 // reco track classes
45 
46 // geometry
48 
49 // fastsim
55 
56 class MeasurementTracker;
57 
59 private:
60  // tokens
61 
66 
67  // other data members
68  unsigned int nHitsPerSeed_;
69 
70  std::vector<std::vector<TrackingLayer>> seedingLayers;
72 
73  std::unique_ptr<SeedCreator> seedCreator;
75 
76  std::unique_ptr<SeedFinderSelector> seedFinderSelector;
77 
78 public:
80 
81  void produce(edm::Event&, const edm::EventSetup&) override;
82 };
83 
84 template class SeedingTree<TrackingLayer>;
85 template class SeedingNode<TrackingLayer>;
86 
88  // products
89  produces<TrajectorySeedCollection>();
90 
91  // consumes
93  consumes<FastTrackerRecHitCombinationCollection>(conf.getParameter<edm::InputTag>("recHitCombinations"));
94  if (conf.exists("hitMasks")) {
95  hitMasksToken = consumes<std::vector<bool>>(conf.getParameter<edm::InputTag>("hitMasks"));
96  }
97 
98  // read Layers
99  std::vector<std::string> layerStringList =
100  conf.getParameter<edm::ParameterSet>("seedFinderSelector").getParameter<std::vector<std::string>>("layerList");
101  std::string layerBegin = *(layerStringList.cbegin());
102  nHitsPerSeed_ = 0;
103  for (auto it = layerStringList.cbegin(); it < layerStringList.cend(); ++it) {
104  std::vector<TrackingLayer> trackingLayerList;
105  std::string line = *it;
106  std::string::size_type pos = 0;
107  unsigned int nHitsPerSeed = 0;
108  while (pos != std::string::npos) {
109  pos = line.find('+');
110  std::string layer = line.substr(0, pos);
112  trackingLayerList.push_back(layerSpec);
113  line = line.substr(pos + 1, std::string::npos);
114  nHitsPerSeed++;
115  }
116  if (it == layerStringList.cbegin()) {
117  nHitsPerSeed_ = nHitsPerSeed;
118  } else if (nHitsPerSeed_ != nHitsPerSeed) {
119  throw cms::Exception("FastSimTracking") << "All allowed seed layer definitions must have same elements";
120  }
121  _seedingTree.insert(trackingLayerList);
122  }
123 
124  // seed finder selector
125  if (conf.exists("seedFinderSelector")) {
126  seedFinderSelector = std::make_unique<SeedFinderSelector>(
127  conf.getParameter<edm::ParameterSet>("seedFinderSelector"), consumesCollector());
128  }
129 
131  trackingRegionToken = consumes<edm::OwnVector<TrackingRegion>>(conf.getParameter<edm::InputTag>("trackingRegions"));
132 
133  // seed creator
134  const edm::ParameterSet& seedCreatorPSet = conf.getParameter<edm::ParameterSet>("SeedCreatorPSet");
135  std::string seedCreatorName = seedCreatorPSet.getParameter<std::string>("ComponentName");
136  seedCreator = SeedCreatorFactory::get()->create(seedCreatorName, seedCreatorPSet, consumesCollector());
137 }
138 
140  // services
141  auto const& trackerTopology = es.getData(trackerTopologyESToken_);
142 
143  // input data
145  e.getByToken(recHitCombinationsToken, recHitCombinations);
146  const std::vector<bool>* hitMasks = nullptr;
148  edm::Handle<std::vector<bool>> hitMasksHandle;
149  e.getByToken(hitMasksToken, hitMasksHandle);
150  hitMasks = &(*hitMasksHandle);
151  }
152 
153  // output data
154  std::unique_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
155 
156  // read the regions;
158  e.getByToken(trackingRegionToken, hregions);
159  const auto& regions = *hregions;
160  // and make sure there is at least one region
161  if (regions.empty()) {
162  e.put(std::move(output));
163  return;
164  }
165 
166  // instantiate the seed finder
167  SeedFinder seedFinder(_seedingTree, trackerTopology);
168  if (seedFinderSelector) {
169  seedFinderSelector->initEvent(e, es);
171  }
172 
173  // loop over the combinations
174  for (unsigned icomb = 0; icomb < recHitCombinations->size(); ++icomb) {
175  FastTrackerRecHitCombination recHitCombination = (*recHitCombinations)[icomb];
176 
177  // create a list of hits cleaned from masked hits
178  std::vector<const FastTrackerRecHit*> seedHitCandidates;
179  for (const auto& _hit : recHitCombination) {
180  if (hitMasks && fastTrackingUtilities::hitIsMasked(_hit.get(), *hitMasks)) {
181  continue;
182  }
183  seedHitCandidates.push_back(_hit.get());
184  }
185 
186  // loop over the regions
187  for (const auto& region : regions) {
188  // set the region used in the selector
189  if (seedFinderSelector) {
190  seedFinderSelector->setTrackingRegion(&region);
191  }
192 
193  // find hits compatible with the seed requirements
194  std::vector<unsigned int> seedHitNumbers = seedFinder.getSeed(seedHitCandidates);
195 
196  // create a seed from those hits
197  if (seedHitNumbers.size() > 1) {
198  // copy the hits
200  for (unsigned iIndex = 0; iIndex < seedHitNumbers.size(); ++iIndex) {
201  seedHits.push_back(seedHitCandidates[seedHitNumbers[iIndex]]->clone());
202  }
203  // make them aware of the combination they originate from
205 
206  // create the seed
207  seedCreator->init(region, es, nullptr);
208  seedCreator->makeSeed(*output,
209  SeedingHitSet(&seedHits[0],
210  &seedHits[1],
211  seedHits.size() >= 3 ? &seedHits[2] : nullptr,
212  seedHits.size() >= 4 ? &seedHits[3] : nullptr));
213  break; // break the loop over the regions
214  }
215  }
216  }
217  e.put(std::move(output));
218 }
219 
void setRecHitCombinationIndex(edm::OwnVector< T > &recHits, int32_t icomb)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void produce(edm::Event &, const edm::EventSetup &) override
TrajectorySeedProducer(const edm::ParameterSet &conf)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< std::vector< bool > > hitMasksToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
size_type size() const
Definition: OwnVector.h:300
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::OwnVector< TrackingRegion > > trackingRegionToken
uint16_t size_type
constexpr std::array< uint8_t, layerIndexSize > layer
bool getData(T &iHolder) const
Definition: EventSetup.h:128
bool insert(const std::vector< DATA > &dataList)
Definition: SeedingTree.h:126
void push_back(D *&d)
Definition: OwnVector.h:326
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopologyESToken_
std::vector< TrajectorySeed > TrajectorySeedCollection
std::unique_ptr< SeedFinderSelector > seedFinderSelector
def move
Definition: eostools.py:511
std::vector< unsigned int > getSeed(const std::vector< const FastTrackerRecHit * > &trackerRecHits) const
Definition: SeedFinder.h:37
static TrackingLayer createFromString(std::string layerSpecification)
bool hitIsMasked(const FastTrackerRecHit *hit, const std::vector< bool > &hitMasks)
std::vector< FastTrackerRecHitRef > FastTrackerRecHitCombination
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::vector< TrackingLayer > > seedingLayers
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::EDGetTokenT< FastTrackerRecHitCombinationCollection > recHitCombinationsToken
void addHitSelector(SeedFinderSelector *seedFinderSelector, unsigned int nHits)
Definition: SeedFinder.h:28
#define get
SeedingTree< TrackingLayer > _seedingTree
std::unique_ptr< SeedCreator > seedCreator
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283