|
|
Go to the documentation of this file.
26 #include <ext/algorithm>
64 bool barcodesAreSorted1,
118 using namespace reco;
121 PATGenCandsFromSimTracksProducer::PATGenCandsFromSimTracksProducer(
const ParameterSet &
cfg)
125 setStatus_(
cfg.getParameter<int32_t>(
"setStatus")),
127 makeMotherLink_(
cfg.existsAs<
bool>(
"makeMotherLink") ?
cfg.getParameter<
bool>(
"makeMotherLink") :
false),
128 writeAncestors_(
cfg.existsAs<
bool>(
"writeAncestors") ?
cfg.getParameter<
bool>(
"writeAncestors") :
false),
130 genBarcodesToken_(mayConsume<
std::vector<
int> >(
cfg.getParameter<
InputTag>(
"genParticles"))) {
132 if (
cfg.exists(
"particleTypes")) {
133 pdts_ =
cfg.getParameter<vector<PdtEntry> >(
"particleTypes");
135 if (
cfg.exists(
"motherTypes")) {
141 <<
"PATGenCandsFromSimTracksProducer: "
142 <<
"you have set 'writeAncestors' to 'true' and 'makeMotherLink' to false;"
143 <<
"GEANT particles with generator level (e.g.PYHIA) mothers won't have mother links.\n";
145 produces<GenParticleCollection>();
152 if (!
vtx.noParent()) {
153 unsigned int idx =
vtx.parentIndex();
155 if ((it !=
g.simtks.end()) && (it->trackId() ==
idx)) {
170 if (simMother !=
nullptr)
176 std::map<unsigned int, int>::const_iterator it =
g.simTksProcessed.find(tk.
trackId());
177 if (it !=
g.simTksProcessed.end()) {
184 g.output.push_back(
p);
185 g.simTksProcessed[tk.
trackId()] =
g.output.size();
198 std::vector<int>::const_iterator it;
199 if (
g.barcodesAreSorted) {
207 if ((it !=
g.genBarcodes->end()) && (*it == st.
genpartIndex())) {
224 gp.addMother(mother);
230 if (!
pdts_.empty()) {
232 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
254 std::unique_ptr<SimTrackContainer> simtracksTmp;
257 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
259 std::sort(simtracksTmp->begin(), simtracksTmp->end(),
LessById());
260 simtracksSorted = &*simtracksTmp;
271 bool barcodesAreSorted =
true;
275 if (gens->size() != genBarcodes->size())
276 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
277 barcodesAreSorted = __gnu_cxx::is_sorted(genBarcodes->begin(), genBarcodes->end());
281 auto cands = std::make_unique<GenParticleCollection>();
284 GlobalContext globals(*simtracksSorted, *simvertices, gens, genBarcodes, barcodesAreSorted, *
cands, refprod);
286 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
288 if (isimtrk->genpartIndex() != -1)
305 if (motherSimTk ==
nullptr)
314 if (mother !=
nullptr)
315 motherRef =
findRef(*mother, globals);
317 genp.addMother(motherRef);
326 #ifdef DEBUG_PATGenCandsFromSimTracksProducer
327 std::cout <<
"Produced a list of " << orphans->size() <<
" genParticles." << std::endl;
328 for (GenParticleCollection::const_iterator it = orphans->begin(), ed = orphans->end(); it != ed; ++it) {
330 std::cout <<
"GenParticle #" << (it - orphans->begin()) <<
": pdgId " << it->pdgId() <<
", pt = " << it->pt()
331 <<
", eta = " << it->eta() <<
", phi = " << it->phi() <<
", rho = " << it->vertex().Rho()
332 <<
", z = " << it->vertex().Z() << std::endl;
336 if (mom.
id() == orphans.
id()) {
342 std::cout <<
"GenParticleRef [" << mom.
id() <<
"/" << mom.
key() <<
"]: pdgId " << mom->pdgId()
343 <<
", status = " << mom->status() <<
", pt = " << mom->pt() <<
", eta = " << mom->eta()
344 <<
", phi = " << mom->phi() <<
", rho = " << mom->vertex().Rho() <<
", z = " << mom->vertex().Z()
346 if (mom.
id() != orphans.
id())
348 if ((mom->motherRef().
id() == mom.
id()) && (mom->motherRef().
key() == mom.
key())) {
349 throw cms::Exception(
"Corrupt Data") <<
"A particle is it's own mother.\n";
351 mom = mom->motherRef();
const edm::Handle< std::vector< int > > & genBarcodes
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
const math::XYZTLorentzVectorD & momentum() const
std::map< unsigned int, int > simTksProcessed
bool makeMotherLink_
If true, I'll try to make a link from the GEANT particle to a GenParticle.
const edm::Handle< reco::GenParticleCollection > & gens
genp
produce generated paricles in acceptance #
std::vector< PdtEntry > motherPdts_
const edm::SimTrackContainer & simtks
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
edm::EDGetTokenT< edm::SimTrackContainer > simTracksToken_
float charge() const
charge
std::vector< PdtEntry > pdts_
edm::Ref< reco::GenParticleCollection > findRef(const SimTrack &tk, GlobalContext &g) const
const edm::SimVertexContainer & simvtxs
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Produces reco::GenParticle from SimTracks.
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).
const edm::RefProd< reco::GenParticleCollection > & refprod
#define DEFINE_FWK_MODULE(type)
void produce(edm::Event &, const edm::EventSetup &) override
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken_
bool isNonnull() const
Checks for non-null.
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.
std::set< int > motherPdgIds_
int type() const
particle type (HEP PDT convension)
reco::GenParticleCollection & output
PATGenCandsFromSimTracksProducer(const edm::ParameterSet &)
unsigned int trackId() const
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)
ProductID id() const
Accessor for product ID.
~PATGenCandsFromSimTracksProducer() override
std::vector< SimTrack > SimTrackContainer
bool operator()(const SimTrack &tk1, unsigned int id) const
bool writeAncestors_
If true, I'll save GenParticles corresponding to the ancestors of this GEANT particle....
Global context for all recursive methods.
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of ba...
bool operator()(const SimTrack &tk1, const SimTrack &tk2) const
key_type key() const
Accessor for product key.
Abs< T >::type abs(const T &t)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
StringCutObjectSelector< reco::GenParticle > StrFilter
math::XYZPoint Point
point in the space
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart)
std::vector< SimVertex > SimVertexContainer
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
bool operator()(unsigned int id, const SimTrack &tk2) const
edm::Ref< reco::GenParticleCollection > generatorRef_(const SimTrack &tk, const GlobalContext &g) const
Used by findRef if the track is a PYTHIA particle.