CMS 3D CMS Logo

TrackingRecHitProducer.cc
Go to the documentation of this file.
11 
15 
18 
20 
23 
26 
29 
31 
34 
35 #include <map>
36 #include <memory>
37 #include <vector>
38 
41 {
42  private:
44  std::vector<TrackingRecHitAlgorithm*> _recHitAlgorithms;
45  unsigned long long _trackerGeometryCacheID = 0;
46  unsigned long long _trackerTopologyCacheID = 0;
47  std::map<unsigned int, TrackingRecHitPipe> _detIdPipes;
48  void setupDetIdPipes(const edm::EventSetup& eventSetup);
49 
50  public:
52 
53  void beginRun(edm::Run const&, const edm::EventSetup& eventSetup) override;
54 
55  void beginStream(edm::StreamID id) override;
56 
57  void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
58 
59  void endStream() override;
60 
61  ~TrackingRecHitProducer() override;
62 };
63 
64 
66 {
67  edm::ConsumesCollector consumeCollector = consumesCollector();
68  const std::vector<edm::ParameterSet>& pluginConfigs = config.getParameter<std::vector<edm::ParameterSet>>("plugins");
69 
70  for (unsigned int iplugin = 0; iplugin<pluginConfigs.size(); ++iplugin)
71  {
72  const edm::ParameterSet& pluginConfig = pluginConfigs[iplugin];
73  const std::string pluginType = pluginConfig.getParameter<std::string>("type");
74  const std::string pluginName = pluginConfig.getParameter<std::string>("name");
75 
76  TrackingRecHitAlgorithm* recHitAlgorithm = TrackingRecHitAlgorithmFactory::get()->tryToCreate(pluginType,pluginName,pluginConfig,consumeCollector);
77  if (recHitAlgorithm)
78  {
79  edm::LogInfo("TrackingRecHitProducer: ")<< "adding plugin type '"<<pluginType<<"' as '"<<pluginName<<"'"<<std::endl;
80  _recHitAlgorithms.push_back(recHitAlgorithm);
81  }
82  else
83  {
84  throw cms::Exception("TrackingRecHitAlgorithm plugin not found: ") << "plugin type = "<<pluginType<<"\nconfiguration=\n"<<pluginConfig.dump();
85  }
86  }
87 
89  _simHitToken = consumes<std::vector<PSimHit>>(simHitTag);
90 
91  produces<FastTrackerRecHitCollection>();
92  produces<FastTrackerRecHitRefCollection>("simHit2RecHitMap");
93 }
94 
96 {
98  {
99  delete algo;
100  }
101  _recHitAlgorithms.clear();
102 }
103 
105 {
107  {
108  algo->beginStream(id);
109  }
110 }
111 
113 {
114 
115 }
116 
118 {
119  auto const& trackerGeomRec = eventSetup.get<TrackerDigiGeometryRecord>();
120  auto const& trackerTopoRec = eventSetup.get<TrackerTopologyRcd>();
121  if (trackerGeomRec.cacheIdentifier() != _trackerGeometryCacheID or
122  trackerTopoRec.cacheIdentifier() != _trackerTopologyCacheID )
123  {
124  _trackerGeometryCacheID = trackerGeomRec.cacheIdentifier();
125  _trackerTopologyCacheID = trackerTopoRec.cacheIdentifier();
126  edm::ESHandle<TrackerGeometry> trackerGeometryHandle;
127  edm::ESHandle<TrackerTopology> trackerTopologyHandle;
128  trackerGeomRec.get(trackerGeometryHandle);
129  trackerTopoRec.get(trackerTopologyHandle);
130  const TrackerGeometry* trackerGeometry = trackerGeometryHandle.product();
131  const TrackerTopology* trackerTopology = trackerTopologyHandle.product();
132 
133  _detIdPipes.clear();
134 
135  //build pipes for all detIds
136  const std::vector<DetId>& detIds = trackerGeometry->detIds();
137  std::vector<unsigned int> numberOfDetIdsPerAlgorithm(_recHitAlgorithms.size(),0);
138 
139  for (const DetId& detId: detIds)
140  {
141  TrackerDetIdSelector selector(detId,*trackerTopology);
142 
144  for (unsigned int ialgo = 0; ialgo < _recHitAlgorithms.size(); ++ialgo)
145  {
147  if (selector.passSelection(algo->getSelectionString()))
148  {
149  numberOfDetIdsPerAlgorithm[ialgo]+=1;
150  pipe.addAlgorithm(algo);
151  }
152  }
153  if (pipe.size()==0)
154  {
155  throw cms::Exception("FastSimulation/TrackingRecHitProducer: DetId not configured! ("+trackerTopology->print(detId)+")");
156  }
157  _detIdPipes[detId.rawId()]=pipe;
158  }
159  }
160 }
161 
163 {
164 
165 
166  //resetup pipes if new iov
167  setupDetIdPipes(eventSetup);
168  //begin event
170  {
171  algo->beginEvent(event,eventSetup);
172  }
173 
174  //build DetId -> PSimHit map
176  event.getByToken(_simHitToken,simHits);
177 
178  std::unique_ptr<FastTrackerRecHitCollection> output_recHits(new FastTrackerRecHitCollection);
179  output_recHits->reserve(simHits->size());
180 
181  edm::RefProd<FastTrackerRecHitCollection> output_recHits_refProd = event.getRefBeforePut<FastTrackerRecHitCollection>();
182  std::unique_ptr<FastTrackerRecHitRefCollection> output_recHitRefs(new FastTrackerRecHitRefCollection(simHits->size(),FastTrackerRecHitRef()));
183 
184  std::map<unsigned int,std::vector<std::pair<unsigned int,const PSimHit*>>> simHitsIdPairPerDetId;
185  for (unsigned int ihit = 0; ihit < simHits->size(); ++ihit)
186  {
187  const PSimHit* simHit = &(*simHits)[ihit];
188  simHitsIdPairPerDetId[simHit->detUnitId()].push_back(std::make_pair(ihit,simHit));
189  }
190 
191  for (auto simHitsIdPairIt = simHitsIdPairPerDetId.begin(); simHitsIdPairIt != simHitsIdPairPerDetId.end(); ++simHitsIdPairIt)
192  {
193  const DetId& detId = simHitsIdPairIt->first;
194  std::map<unsigned int, TrackingRecHitPipe>::const_iterator pipeIt = _detIdPipes.find(detId);
195  if (pipeIt!=_detIdPipes.cend())
196  {
197  auto& simHitIdPairList = simHitsIdPairIt->second;
198  const TrackingRecHitPipe& pipe = pipeIt->second;
199 
200  TrackingRecHitProductPtr product = std::make_shared<TrackingRecHitProduct>(detId,simHitIdPairList);
201 
202  product = pipe.produce(product);
203 
204  const std::vector<TrackingRecHitProduct::RecHitToSimHitIdPairs>& recHitToSimHitIdPairsList = product->getRecHitToSimHitIdPairs();
205 
206 
207  for (unsigned int irecHit = 0; irecHit < recHitToSimHitIdPairsList.size(); ++irecHit)
208  {
209  output_recHits->push_back(recHitToSimHitIdPairsList[irecHit].first);
210  const std::vector<TrackingRecHitProduct::SimHitIdPair>& simHitIdPairList = recHitToSimHitIdPairsList[irecHit].second;
211  for (unsigned int isimHit = 0; isimHit < simHitIdPairList.size(); ++isimHit)
212  {
213  unsigned int simHitId = simHitIdPairList[isimHit].first;
214  if (not (*output_recHitRefs)[simHitId].isNull())
215  {
216  throw cms::Exception("FastSimulation/TrackingRecHitProducer","A PSimHit cannot lead to multiple FastTrackerRecHits");
217  }
218  (*output_recHitRefs)[simHitId] = FastTrackerRecHitRef(output_recHits_refProd,output_recHits->size()-1);
219  }
220  }
221  }
222  else
223  {
224  //there should be at least an empty pipe for each DetId
225  throw cms::Exception("FastSimulation/TrackingRecHitProducer","A PSimHit carries a DetId which does not belong to the TrackerGeometry: "+std::to_string(detId));
226  }
227  }
228 
229  //end event
230  for (TrackingRecHitAlgorithm* algo: _recHitAlgorithms)
231  {
232  algo->endEvent(event,eventSetup);
233  }
234 
235  // note from lukas:
236  // all rechits need a unique id numbers
237  for(unsigned recHitIndex = 0; recHitIndex < output_recHits->size(); ++recHitIndex)
238  {
239  ((FastSingleTrackerRecHit*)&(*output_recHits)[recHitIndex])->setId(recHitIndex);
240  }
241 
242  event.put(std::move(output_recHits));
243  event.put(std::move(output_recHitRefs),"simHit2RecHitMap");
244 
245 }
246 
248 {
250  {
251  algo->endStream();
252  }
253 }
254 
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
std::string dump(unsigned int indent=0) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setupDetIdPipes(const edm::EventSetup &eventSetup)
std::map< unsigned int, TrackingRecHitPipe > _detIdPipes
size_type size() const
Definition: OwnVector.h:264
void beginStream(edm::StreamID id) override
void addAlgorithm(TrackingRecHitAlgorithm *algorithm)
edm::EDGetTokenT< std::vector< PSimHit > > _simHitToken
Definition: config.py:1
std::string print(DetId detid) const
unsigned long long _trackerGeometryCacheID
edm::Ref< FastTrackerRecHitCollection > FastTrackerRecHitRef
bool passSelection(std::string selectionStr) const
const std::string & getSelectionString() const
std::vector< TrackingRecHitAlgorithm * > _recHitAlgorithms
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
unsigned int size() const
void get(HolderT &iHolder) const
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
def pipe(cmdline, input=None)
Definition: pipe.py:5
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
Definition: DetId.h:18
std::vector< FastTrackerRecHitRef > FastTrackerRecHitRefCollection
TrackingRecHitProducer(const edm::ParameterSet &config)
void beginRun(edm::Run const &, const edm::EventSetup &eventSetup) override
T get() const
Definition: EventSetup.h:63
unsigned long long _trackerTopologyCacheID
T const * product() const
Definition: ESHandle.h:86
Definition: pipe.py:1
TrackingRecHitProductPtr produce(TrackingRecHitProductPtr product) const
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55
unsigned int detUnitId() const
Definition: PSimHit.h:93
Definition: event.py:1
Definition: Run.h:44