74 tokenSim_ = consumes<std::vector<SimTrack> >(inputTagSim_);
75 tokenSimVertices_ = consumes<std::vector<SimVertex> >(inputTagSim_);
81 tokenFastSimProducer_ = consumes<edm::PCaloHitContainer>(inputTagFastSimProducer_);
82 mctruthMatchingInfo_ =
87 tokenRecTracks_ = consumes<reco::PFRecTrackCollection>(inputTagRecTracks_);
90 tokenEcalRecHitsEB_ = consumes<EcalRecHitCollection>(inputTagEcalRecHitsEB_);
93 = consumes<EcalRecHitCollection>(inputTagEcalRecHitsEE_);
100 produces<reco::PFSimParticleCollection>();
103 (
"ParticleFilter" );
105 mySimEvent =
new FSimEvent( particleFilter_ );
122 mySimEvent->initializePdt(&(*pdt));
124 LogDebug(
"PFSimParticleProducer")<<
"START event: "<<iEvent.
id().
event()
125 <<
" in run "<<iEvent.
id().
run()<<endl;
131 std::vector<unsigned> recTrackSimID;
137 typedef std::pair<double, unsigned> hitSimID;
138 typedef std::list< std::pair<double, unsigned> >::iterator ITM;
139 std::vector< std::list <hitSimID> > caloHitsEBID(62000);
140 std::vector<double> caloHitsEBTotE(62000,0.0);
142 if(mctruthMatchingInfo_){
151 = iEvent.
getByToken(tokenFastSimProducer_,pcalohits);
156 err<<
"could not find pcaloHit "<<
"fastSimProducer:EcalHitsEB";
157 LogError(
"PFSimParticleProducer")<<err.str()<<endl;
164 edm::PCaloHitContainer::const_iterator it
165 = pcalohits.
product()->begin();
166 edm::PCaloHitContainer::const_iterator itend
174 if(it->energy() > 0.0) {
175 std::pair<double, unsigned> phitsimid
176 = make_pair(it->energy(),it->geantTrackId());
177 caloHitsEBID[detid.hashedIndex()].push_back(phitsimid);
178 caloHitsEBTotE[detid.hashedIndex()]
189 LogDebug(
"PFSimParticleProducer")<<
"getting PFRecTracks"<<endl;
190 iEvent.
getByToken(tokenRecTracks_, recTracks);
193 LogError(
"PFSimParticleProducer")<<err
194 <<
" cannot get collection " 195 <<
"particleFlowBlock"<<
":" 202 getSimIDs( recTracks, recTrackSimID );
207 if( processParticles_) {
209 auto pOutputPFSimParticleCollection = std::make_unique<reco::PFSimParticleCollection>();
216 err<<
"cannot find sim tracks: "<<inputTagSim_;
217 LogError(
"PFSimParticleProducer")<<err.str()<<endl;
225 found = iEvent.
getByToken(tokenSimVertices_,simVertices);
228 <<
"cannot find sim vertices: "<<inputTagSim_<<endl;
232 mySimEvent->fill( *simTracks, *simVertices );
237 for(
unsigned i=0;
i<mySimEvent->nTracks();
i++) {
249 unsigned recTrackID = 99999;
250 vector<unsigned> recHitContrib;
251 vector<double> recHitContribFrac;
253 if(mctruthMatchingInfo_){
255 for(
unsigned lo=0; lo<recTrackSimID.size();
257 if(
i == recTrackSimID[lo] ) {
265 bool found = iEvent.
getByToken(tokenEcalRecHitsEB_,
269 err<<
"could not find rechits "<< inputTagEcalRecHitsEB_;
270 LogError(
"PFSimParticleProducer")<<err.str()<<endl;
282 for(;it_rh!=itend_rh;++it_rh)
288 ITM it_phit = caloHitsEBID[rhit_hi].begin();
289 ITM itend_phit = caloHitsEBID[rhit_hi].end();
290 for(;it_phit!=itend_phit;++it_phit)
292 if(
i == it_phit->second)
296 bool alreadyin =
false;
297 for(
unsigned ihit = 0; ihit < recHitContrib.size();
299 if(detid.rawId() == recHitContrib[ihit])
303 double pcalofraction = 0.0;
304 if(caloHitsEBTotE[rhit_hi] != 0.0)
306 = (it_phit->first/caloHitsEBTotE[rhit_hi])*100.0;
309 recHitContrib.push_back(it_rh->id());
310 recHitContribFrac.push_back(pcalofraction);
334 originVtx.position().y(),
335 originVtx.position().z() );
347 particle.addPoint(pointOrig);
364 particle.addPoint(pointEnd);
368 particle.addPoint(dummy);
378 posLayer1, momLayer1);
380 particle.addPoint( layer1Pt );
386 particle.addPoint(dummy);
395 posLayer2, momLayer2);
397 particle.addPoint( layer2Pt );
403 particle.addPoint(dummy);
415 particle.addPoint( ecalPt );
421 particle.addPoint(dummy);
426 particle.addPoint(dummy);
437 posHCALin, momHCALin);
439 particle.addPoint( hcalPtin );
448 posHCALout, momHCALout);
450 particle.addPoint( hcalPtout );
459 posHOEntrance, momHOEntrance);
461 particle.addPoint( hoPtin );
469 particle.addPoint(dummy);
472 pOutputPFSimParticleCollection->push_back( particle );
480 <<
" in run "<<iEvent.
id().
run()<<endl;
484 std::vector<unsigned>& recTrackSimID )
489 for(
unsigned i=0;
i<trackh->size();
i++) {
493 for(
auto const&
hit : ref->trackRef()->recHits())
495 if(
hit->isValid() ) {
499 for(
unsigned int st_index=0;st_index<rechit->nSimTrackIds();++st_index){
500 recTrackSimID.push_back(rechit->simTrackId(st_index));
PFSimParticleProducer(const edm::ParameterSet &)
double pz() const
z of the momentum
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
bool noEndVertex() const
no end vertex
float charge() const
charge
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const RawParticle & hoEntrance() const
The particle at HCAL exir.
const FSimVertex & endVertex() const
end vertex
const RawParticle & hcalExit() const
The particle at HCAL exir.
double y() const
y of vertex
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double z() const
z of vertex
const XYZTLorentzVector & momentum() const
Temporary (until move of SimTrack to Mathcore) - No! Actually very useful.
const RawParticle & layer1Entrance() const
The particle at Preshower Layer 1.
std::vector< EcalRecHit >::const_iterator const_iterator
const std::vector< int > & daughters() const
Vector of daughter indices.
~PFSimParticleProducer() override
double x() const
x of vertex
void produce(edm::Event &, const edm::EventSetup &) override
bool getData(T &iHolder) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
int hashedIndex(int ieta, int iphi)
double e() const
energy of the momentum
Point of closest approach from beam axis (initial point in the case of PFSimParticle) ...
const math::XYZTLorentzVector & position() const
Temporary (until CMSSW moves to Mathcore) - No ! Actually very useful.
const RawParticle & ecalEntrance() const
The particle at ECAL entrance.
true particle for particle flow
const_iterator end() const
T const * product() const
XYZPointD XYZPoint
point in space with cartesian internal representation
int type() const
particle type (HEP PDT convension)
int id() const
the index in FBaseSimEvent and other vectors
const RawParticle & layer2Entrance() const
The particle at Preshower Layer 2.
bool noMother() const
no mother particle
const RawParticle & hcalEntrance() const
The particle at HCAL entrance.
double px() const
x of the momentum
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
const FSimVertex vertex() const
Origin vertex.
double py() const
y of the momentum
void getSimIDs(const TrackHandle &trackh, std::vector< unsigned > &recTrackSimID)
const FSimTrack & mother() const
mother
const_iterator begin() const