119 desc.addUntracked<
bool>(
"MCTruthMatchingInfo",
false);
124 desc.addUntracked<
bool>(
"process_RecTracks",
false);
127 desc.addUntracked<
bool>(
"process_Particles",
true);
130 desc.addUntracked<
bool>(
"verbose",
false);
131 descriptions.
add(
"particleFlowSimParticle",
desc);
141 tokenSim_ = consumes<std::vector<SimTrack> >(inputTagSim_);
142 tokenSimVertices_ = consumes<std::vector<SimVertex> >(inputTagSim_);
148 tokenFastSimProducer_ = consumes<edm::PCaloHitContainer>(inputTagFastSimProducer_);
153 tokenRecTracks_ = consumes<reco::PFRecTrackCollection>(inputTagRecTracks_);
156 tokenEcalRecHitsEB_ = consumes<EcalRecHitCollection>(inputTagEcalRecHitsEB_);
158 tokenEcalRecHitsEE_ = consumes<EcalRecHitCollection>(inputTagEcalRecHitsEE_);
165 produces<reco::PFSimParticleCollection>();
169 mySimEvent = std::make_unique<FSimEvent>(particleFilter_);
174 mySimEvent->initializePdt(&iSetup.
getData(pdtToken_));
176 LogDebug(
"PFSimParticleProducer") <<
"START event: " <<
iEvent.id().event() <<
" in run " <<
iEvent.id().run()
183 std::vector<unsigned> recTrackSimID;
189 typedef std::pair<double, unsigned> hitSimID;
190 std::vector<std::list<hitSimID> > caloHitsEBID(62000);
191 std::vector<double> caloHitsEBTotE(62000, 0.0);
193 if (mctruthMatchingInfo_) {
195 auto pcalohits =
iEvent.getHandle(tokenFastSimProducer_);
199 err <<
"could not find pcaloHit " 200 <<
"fastSimProducer:EcalHitsEB";
201 LogError(
"PFSimParticleProducer") <<
err.str() << endl;
205 assert(pcalohits.isValid());
207 edm::PCaloHitContainer::const_iterator
it = pcalohits.product()->begin();
208 edm::PCaloHitContainer::const_iterator itend = pcalohits.product()->end();
211 for (;
it != itend; ++
it) {
214 if (
it->energy() > 0.0) {
215 std::pair<double, unsigned> phitsimid = make_pair(
it->energy(),
it->geantTrackId());
216 caloHitsEBID[detid.hashedIndex()].push_back(phitsimid);
217 caloHitsEBTotE[detid.hashedIndex()] +=
it->energy();
227 LogDebug(
"PFSimParticleProducer") <<
"getting PFRecTracks" << endl;
228 iEvent.getByToken(tokenRecTracks_, recTracks);
231 LogError(
"PFSimParticleProducer") <<
err <<
" cannot get collection " 232 <<
"particleFlowBlock" 239 getSimIDs(recTracks, recTrackSimID);
244 if (processParticles_) {
245 auto pOutputPFSimParticleCollection = std::make_unique<reco::PFSimParticleCollection>();
251 err <<
"cannot find sim tracks: " << inputTagSim_;
252 LogError(
"PFSimParticleProducer") <<
err.str() << endl;
260 LogError(
"PFSimParticleProducer") <<
"cannot find sim vertices: " << inputTagSim_ << endl;
269 for (
unsigned i = 0;
i < mySimEvent->nTracks();
i++) {
280 unsigned recTrackID = 99999;
281 vector<unsigned> recHitContrib;
282 vector<double> recHitContribFrac;
284 if (mctruthMatchingInfo_) {
286 for (
unsigned lo = 0; lo < recTrackSimID.size(); lo++) {
287 if (
i == recTrackSimID[lo]) {
294 bool found =
iEvent.getByToken(tokenEcalRecHitsEB_, rhcHandle);
297 err <<
"could not find rechits " << inputTagEcalRecHitsEB_;
298 LogError(
"PFSimParticleProducer") <<
err.str() << endl;
307 for (; it_rh != itend_rh; ++it_rh) {
311 auto it_phit = caloHitsEBID[rhit_hi].begin();
312 auto itend_phit = caloHitsEBID[rhit_hi].end();
313 for (; it_phit != itend_phit; ++it_phit) {
314 if (
i == it_phit->second) {
317 bool alreadyin =
false;
318 for (
unsigned ihit = 0; ihit < recHitContrib.size(); ++ihit)
319 if (detid.rawId() == recHitContrib[ihit])
323 double pcalofraction = 0.0;
324 if (caloHitsEBTotE[rhit_hi] != 0.0)
325 pcalofraction = (it_phit->first / caloHitsEBTotE[rhit_hi]) * 100.0;
328 recHitContrib.push_back(it_rh->id());
329 recHitContribFrac.push_back(pcalofraction);
345 math::XYZPoint posOrig(originVtx.position().x(), originVtx.position().y(), originVtx.position().z());
352 particle.addPoint(pointOrig);
363 particle.addPoint(pointEnd);
366 particle.addPoint(
dummy);
376 particle.addPoint(layer1Pt);
381 particle.addPoint(
dummy);
391 particle.addPoint(layer2Pt);
396 particle.addPoint(
dummy);
406 particle.addPoint(ecalPt);
411 particle.addPoint(
dummy);
416 particle.addPoint(
dummy);
425 particle.addPoint(hcalPtin);
433 particle.addPoint(hcalPtout);
441 particle.addPoint(hoPtin);
445 particle.addPoint(
dummy);
448 pOutputPFSimParticleCollection->push_back(particle);
454 LogDebug(
"PFSimParticleProducer") <<
"STOP event: " <<
iEvent.id().event() <<
" in run " <<
iEvent.id().run() << endl;
459 for (
unsigned i = 0;
i < trackh->size();
i++) {
462 for (
auto const&
hit : ref->trackRef()->recHits()) {
463 if (
hit->isValid()) {
466 for (
unsigned int st_index = 0; st_index < rechit->nSimTrackIds(); ++st_index) {
467 recTrackSimID.push_back(rechit->simTrackId(st_index));
PFSimParticleProducer(const edm::ParameterSet &)
bool noMother() const
no mother particle
std::unique_ptr< FSimEvent > mySimEvent
bool processParticles_
process particles on/off
edm::InputTag inputTagEcalRecHitsEE_
T getParameter(std::string const &) const
double x() const
x of vertex
edm::EDGetTokenT< EcalRecHitCollection > tokenEcalRecHitsEE_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const RawParticle & hcalEntrance() const
The particle at HCAL entrance.
const RawParticle & layer2Entrance() const
The particle at Preshower Layer 2.
edm::Handle< reco::PFRecTrackCollection > TrackHandle
const RawParticle & ecalEntrance() const
The particle at ECAL entrance.
edm::ParameterSet particleFilter_
T const * product() const
std::vector< EcalRecHit >::const_iterator const_iterator
edm::InputTag inputTagEcalRecHitsEB_
const RawParticle & hoEntrance() const
The particle at HCAL exir.
Log< level::Error, false > LogError
bool noEndVertex() const
no end vertex
Producer for PFRecTracks and PFSimParticles.
const FSimVertex vertex() const
Origin vertex.
edm::EDGetTokenT< reco::PFRecTrackCollection > tokenRecTracks_
double px() const
x of the momentum
const FSimVertex & endVertex() const
end vertex
T getUntrackedParameter(std::string const &, T const &) const
void produce(edm::Event &, const edm::EventSetup &) override
int type() const
particle type (HEP PDT convension)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
int hashedIndex(int ieta, int iphi)
const XYZTLorentzVector & momentum() const
Temporary (until move of SimTrack to Mathcore) - No! Actually very useful.
edm::InputTag inputTagSim_
module label for retrieving input simtrack and simvertex
const RawParticle & hcalExit() const
The particle at HCAL exir.
Point of closest approach from beam axis (initial point in the case of PFSimParticle) ...
edm::EDGetTokenT< std::vector< SimTrack > > tokenSim_
float charge() const
charge
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > pdtToken_
double z() const
z of vertex
const std::vector< int > & daughters() const
Vector of daughter indices.
#define DEFINE_FWK_MODULE(type)
double py() const
y of the momentum
const_iterator begin() const
double y() const
y of vertex
bool mctruthMatchingInfo_
true particle for particle flow
double pz() const
z of the momentum
edm::EDGetTokenT< edm::PCaloHitContainer > tokenFastSimProducer_
const_iterator end() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XYZPointD XYZPoint
point in space with cartesian internal representation
edm::EDGetTokenT< EcalRecHitCollection > tokenEcalRecHitsEB_
const math::XYZTLorentzVector & position() const
Temporary (until CMSSW moves to Mathcore) - No ! Actually very useful.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::InputTag inputTagRecTracks_
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
const RawParticle & layer1Entrance() const
The particle at Preshower Layer 1.
double e() const
energy of the momentum
void getSimIDs(const TrackHandle &trackh, std::vector< unsigned > &recTrackSimID)
int id() const
the index in FBaseSimEvent and other vectors
edm::EDGetTokenT< std::vector< SimVertex > > tokenSimVertices_
const FSimTrack & mother() const
mother
edm::InputTag inputTagFastSimProducer_