27 #include <ext/algorithm> 67 bool barcodesAreSorted1,
121 using namespace reco;
124 PATGenCandsFromSimTracksProducer::PATGenCandsFromSimTracksProducer(
const ParameterSet &
cfg)
128 setStatus_(
cfg.getParameter<int32_t>(
"setStatus")),
130 makeMotherLink_(
cfg.existsAs<
bool>(
"makeMotherLink") ?
cfg.getParameter<
bool>(
"makeMotherLink") :
false),
131 writeAncestors_(
cfg.existsAs<
bool>(
"writeAncestors") ?
cfg.getParameter<
bool>(
"writeAncestors") :
false),
136 if (
cfg.exists(
"particleTypes")) {
137 pdts_ =
cfg.getParameter<vector<PdtEntry> >(
"particleTypes");
139 if (
cfg.exists(
"motherTypes")) {
145 <<
"PATGenCandsFromSimTracksProducer: " 146 <<
"you have set 'writeAncestors' to 'true' and 'makeMotherLink' to false;" 147 <<
"GEANT particles with generator level (e.g.PYHIA) mothers won't have mother links.\n";
149 produces<GenParticleCollection>();
156 if (!
vtx.noParent()) {
157 unsigned int idx =
vtx.parentIndex();
159 if ((
it !=
g.simtks.end()) && (
it->trackId() ==
idx)) {
174 if (simMother !=
nullptr)
180 std::map<unsigned int, int>::const_iterator
it =
g.simTksProcessed.find(tk.
trackId());
181 if (
it !=
g.simTksProcessed.end()) {
188 g.output.push_back(
p);
189 g.simTksProcessed[tk.
trackId()] =
g.output.size();
202 std::vector<int>::const_iterator
it;
203 if (
g.barcodesAreSorted) {
228 gp.addMother(mother);
235 if (!
pdts_.empty()) {
237 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
259 std::unique_ptr<SimTrackContainer> simtracksTmp;
262 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
263 simtracksTmp = std::make_unique<SimTrackContainer>(*simtracks);
265 simtracksSorted = &*simtracksTmp;
276 bool barcodesAreSorted =
true;
280 if (gens->size() != genBarcodes->size())
281 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
282 barcodesAreSorted = __gnu_cxx::is_sorted(genBarcodes->begin(), genBarcodes->end());
286 auto cands = std::make_unique<GenParticleCollection>();
289 GlobalContext globals(*simtracksSorted, *simvertices, gens, genBarcodes, barcodesAreSorted, *
cands, refprod);
291 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
293 if (isimtrk->genpartIndex() != -1)
310 if (motherSimTk ==
nullptr)
319 if (mother !=
nullptr)
320 motherRef =
findRef(*mother, globals);
322 genp.addMother(motherRef);
331 #ifdef DEBUG_PATGenCandsFromSimTracksProducer 332 std::cout <<
"Produced a list of " << orphans->size() <<
" genParticles." << std::endl;
333 for (GenParticleCollection::const_iterator
it = orphans->begin(), ed = orphans->end();
it != ed; ++
it) {
335 std::cout <<
"GenParticle #" << (
it - orphans->begin()) <<
": pdgId " <<
it->pdgId() <<
", pt = " <<
it->pt()
336 <<
", eta = " <<
it->eta() <<
", phi = " <<
it->phi() <<
", rho = " <<
it->vertex().Rho()
337 <<
", z = " <<
it->vertex().Z() << std::endl;
341 if (mom.
id() == orphans.
id()) {
347 std::cout <<
"GenParticleRef [" << mom.
id() <<
"/" << mom.
key() <<
"]: pdgId " << mom->pdgId()
348 <<
", status = " << mom->status() <<
", pt = " << mom->pt() <<
", eta = " << mom->eta()
349 <<
", phi = " << mom->phi() <<
", rho = " << mom->vertex().Rho() <<
", z = " << mom->vertex().Z()
351 if (mom.
id() != orphans.
id())
353 if ((mom->motherRef().
id() == mom.
id()) && (mom->motherRef().
key() == mom.
key())) {
354 throw cms::Exception(
"Corrupt Data") <<
"A particle is it's own mother.\n";
356 mom = mom->motherRef();
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
genp
produce generated paricles in acceptance #
ProductID id() const
Accessor for product ID.
bool operator()(const SimTrack &tk1, const SimTrack &tk2) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const edm::Handle< reco::GenParticleCollection > & gens
PATGenCandsFromSimTracksProducer(const edm::ParameterSet &)
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of ba...
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
bool isNonnull() const
Checks for non-null.
bool writeAncestors_
If true, I'll save GenParticles corresponding to the ancestors of this GEANT particle. Common ancestors are only written once.
reco::GenParticleCollection & output
const edm::SimTrackContainer & simtks
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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 g
float charge() const
charge
key_type key() const
Accessor for product key.
GlobalContext(const edm::SimTrackContainer &simtks1, const edm::SimVertexContainer &simvtxs1, const edm::Handle< reco::GenParticleCollection > &gens1, const edm::Handle< std::vector< int > > &genBarcodes1, bool barcodesAreSorted1, reco::GenParticleCollection &output1, const edm::RefProd< reco::GenParticleCollection > &refprod1)
const math::XYZTLorentzVectorD & momentum() const
Produces reco::GenParticle from SimTracks.
bool operator()(unsigned int id, const SimTrack &tk2) const
edm::Ref< reco::GenParticleCollection > findRef(const SimTrack &tk, GlobalContext &g) const
int type() const
particle type (HEP PDT convension)
std::set< int > motherPdgIds_
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
reco::GenParticle makeGenParticle_(const SimTrack &tk, const edm::Ref< reco::GenParticleCollection > &mother, const GlobalContext &g) const
Make a GenParticle for this SimTrack, with a given mother.
Abs< T >::type abs(const T &t)
bool makeMotherLink_
If true, I'll try to make a link from the GEANT particle to a GenParticle.
std::vector< PdtEntry > pdts_
#define DEFINE_FWK_MODULE(type)
bool operator()(const SimTrack &tk1, unsigned int id) const
const edm::RefProd< reco::GenParticleCollection > & refprod
StringCutObjectSelector< reco::GenParticle > StrFilter
~PATGenCandsFromSimTracksProducer() override
const edm::Handle< std::vector< int > > & genBarcodes
std::vector< SimVertex > SimVertexContainer
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > tableToken_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Global context for all recursive methods.
const edm::SimVertexContainer & simvtxs
std::vector< PdtEntry > motherPdts_
unsigned int trackId() const
math::XYZPoint Point
point in the space
edm::Ref< reco::GenParticleCollection > generatorRef_(const SimTrack &tk, const GlobalContext &g) const
Used by findRef if the track is a PYTHIA particle.
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken_
edm::EDGetTokenT< edm::SimTrackContainer > simTracksToken_
Log< level::Warning, false > LogWarning
std::map< unsigned int, int > simTksProcessed
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< SimTrack > SimTrackContainer
const SimTrack * findGeantMother(const SimTrack &tk, const GlobalContext &g) const
Find the mother of a given GEANT track (or NULL if it can't be found).
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...