69 tokenSim_ = consumes<std::vector<SimTrack> >(inputTagSim_);
70 tokenSimVertices_ = consumes<std::vector<SimVertex> >(inputTagSim_);
76 tokenFastSimProducer_ = consumes<edm::PCaloHitContainer>(inputTagFastSimProducer_);
81 tokenRecTracks_ = consumes<reco::PFRecTrackCollection>(inputTagRecTracks_);
84 tokenEcalRecHitsEB_ = consumes<EcalRecHitCollection>(inputTagEcalRecHitsEB_);
86 tokenEcalRecHitsEE_ = consumes<EcalRecHitCollection>(inputTagEcalRecHitsEE_);
91 produces<reco::PFSimParticleCollection>();
95 mySimEvent =
new FSimEvent(particleFilter_);
105 mySimEvent->initializePdt(&(*pdt));
107 LogDebug(
"PFSimParticleProducer") <<
"START event: " <<
iEvent.id().event() <<
" in run " <<
iEvent.id().run()
114 std::vector<unsigned> recTrackSimID;
120 typedef std::pair<double, unsigned> hitSimID;
121 typedef std::list<std::pair<double, unsigned> >::iterator ITM;
122 std::vector<std::list<hitSimID> > caloHitsEBID(62000);
123 std::vector<double> caloHitsEBTotE(62000, 0.0);
125 if (mctruthMatchingInfo_) {
132 bool found_phit =
iEvent.getByToken(tokenFastSimProducer_, pcalohits);
137 err <<
"could not find pcaloHit "
138 <<
"fastSimProducer:EcalHitsEB";
139 LogError(
"PFSimParticleProducer") <<
err.str() << endl;
145 edm::PCaloHitContainer::const_iterator it = pcalohits.
product()->begin();
146 edm::PCaloHitContainer::const_iterator itend = pcalohits.
product()->end();
149 for (; it != itend; ++it) {
152 if (it->energy() > 0.0) {
153 std::pair<double, unsigned> phitsimid = make_pair(it->energy(), it->geantTrackId());
154 caloHitsEBID[detid.hashedIndex()].push_back(phitsimid);
155 caloHitsEBTotE[detid.hashedIndex()] += it->energy();
165 LogDebug(
"PFSimParticleProducer") <<
"getting PFRecTracks" << endl;
169 LogError(
"PFSimParticleProducer") <<
err <<
" cannot get collection "
170 <<
"particleFlowBlock"
182 if (processParticles_) {
183 auto pOutputPFSimParticleCollection = std::make_unique<reco::PFSimParticleCollection>();
189 err <<
"cannot find sim tracks: " << inputTagSim_;
190 LogError(
"PFSimParticleProducer") <<
err.str() << endl;
198 LogError(
"PFSimParticleProducer") <<
"cannot find sim vertices: " << inputTagSim_ << endl;
207 for (
unsigned i = 0;
i < mySimEvent->nTracks();
i++) {
218 unsigned recTrackID = 99999;
219 vector<unsigned> recHitContrib;
220 vector<double> recHitContribFrac;
222 if (mctruthMatchingInfo_) {
224 for (
unsigned lo = 0; lo < recTrackSimID.size(); lo++) {
225 if (
i == recTrackSimID[lo]) {
232 bool found =
iEvent.getByToken(tokenEcalRecHitsEB_, rhcHandle);
235 err <<
"could not find rechits " << inputTagEcalRecHitsEB_;
236 LogError(
"PFSimParticleProducer") <<
err.str() << endl;
245 for (; it_rh != itend_rh; ++it_rh) {
249 ITM it_phit = caloHitsEBID[rhit_hi].begin();
250 ITM itend_phit = caloHitsEBID[rhit_hi].end();
251 for (; it_phit != itend_phit; ++it_phit) {
252 if (
i == it_phit->second) {
255 bool alreadyin =
false;
256 for (
unsigned ihit = 0; ihit < recHitContrib.size(); ++ihit)
257 if (detid.rawId() == recHitContrib[ihit])
261 double pcalofraction = 0.0;
262 if (caloHitsEBTotE[rhit_hi] != 0.0)
263 pcalofraction = (it_phit->first / caloHitsEBTotE[rhit_hi]) * 100.0;
266 recHitContrib.push_back(it_rh->id());
267 recHitContribFrac.push_back(pcalofraction);
283 math::XYZPoint posOrig(originVtx.position().x(), originVtx.position().y(), originVtx.position().z());
290 particle.addPoint(pointOrig);
301 particle.addPoint(pointEnd);
304 particle.addPoint(
dummy);
314 particle.addPoint(layer1Pt);
319 particle.addPoint(
dummy);
329 particle.addPoint(layer2Pt);
334 particle.addPoint(
dummy);
344 particle.addPoint(ecalPt);
349 particle.addPoint(
dummy);
354 particle.addPoint(
dummy);
363 particle.addPoint(hcalPtin);
371 particle.addPoint(hcalPtout);
379 particle.addPoint(hoPtin);
383 particle.addPoint(
dummy);
386 pOutputPFSimParticleCollection->push_back(particle);
392 LogDebug(
"PFSimParticleProducer") <<
"STOP event: " <<
iEvent.id().event() <<
" in run " <<
iEvent.id().run() << endl;
397 for (
unsigned i = 0;
i < trackh->size();
i++) {
400 for (
auto const&
hit : ref->trackRef()->recHits()) {
401 if (
hit->isValid()) {
402 auto rechit = dynamic_cast<const FastTrackerRecHit*>(
hit);
404 for (
unsigned int st_index = 0; st_index < rechit->nSimTrackIds(); ++st_index) {
405 recTrackSimID.push_back(rechit->simTrackId(st_index));