196 algo->beginEvent(event,eventSetup);
203 auto output_recHits = std::make_unique<FastTrackerRecHitCollection>();
204 output_recHits->reserve(simHits->size());
207 auto output_recHitRefs = std::make_unique<FastTrackerRecHitRefCollection>(simHits->size(),
FastTrackerRecHitRef());
209 std::map<unsigned int,std::vector<std::pair<unsigned int,const PSimHit*>>> simHitsIdPairPerDetId;
210 for (
unsigned int ihit = 0; ihit < simHits->size(); ++ihit)
213 simHitsIdPairPerDetId[simHit->
detUnitId()].push_back(std::make_pair(ihit,simHit));
216 for (
auto simHitsIdPairIt = simHitsIdPairPerDetId.begin(); simHitsIdPairIt != simHitsIdPairPerDetId.end(); ++simHitsIdPairIt)
218 const DetId& detId = simHitsIdPairIt->first;
219 std::map<unsigned int, TrackingRecHitPipe>::const_iterator pipeIt =
_detIdPipes.find(detId);
222 auto& simHitIdPairList = simHitsIdPairIt->second;
227 product = pipe.
produce(product);
229 const std::vector<TrackingRecHitProduct::RecHitToSimHitIdPairs>& recHitToSimHitIdPairsList = product->getRecHitToSimHitIdPairs();
232 for (
unsigned int irecHit = 0; irecHit < recHitToSimHitIdPairsList.size(); ++irecHit)
234 output_recHits->push_back(recHitToSimHitIdPairsList[irecHit].
first);
235 const std::vector<TrackingRecHitProduct::SimHitIdPair>& simHitIdPairList = recHitToSimHitIdPairsList[irecHit].second;
236 double energyLoss_tot = 0;
237 for (
unsigned int isimHit = 0; isimHit < simHitIdPairList.size(); ++isimHit){
238 unsigned int simHitId = simHitIdPairList[isimHit].first;
239 const PSimHit * simHit = simHitIdPairList[isimHit].second;
241 if (not (*output_recHitRefs)[simHitId].isNull())
243 throw cms::Exception(
"FastSimulation/TrackingRecHitProducer",
"A PSimHit cannot lead to multiple FastTrackerRecHits");
253 throw cms::Exception(
"FastSimulation/TrackingRecHitProducer",
"A PSimHit carries a DetId which does not belong to the TrackerGeometry: "+std::to_string(detId));
258 for (
auto&
algo: _recHitAlgorithms)
260 algo->endEvent(event,eventSetup);
265 for(
unsigned recHitIndex = 0; recHitIndex < output_recHits->size(); ++recHitIndex)
271 event.put(
std::move(output_recHitRefs),
"simHit2RecHitMap");
void setupDetIdPipes(const edm::EventSetup &eventSetup)
std::map< unsigned int, TrackingRecHitPipe > _detIdPipes
edm::EDGetTokenT< std::vector< PSimHit > > _simHitToken
edm::Ref< FastTrackerRecHitCollection > FastTrackerRecHitRef
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
float energyLoss() const
The energy deposit in the PSimHit, in ???.
std::vector< std::unique_ptr< TrackingRecHitAlgorithm > > _recHitAlgorithms
TrackingRecHitProductPtr produce(TrackingRecHitProductPtr product) const
unsigned int detUnitId() const