26 #include <ext/algorithm>
63 bool barcodesAreSorted1,
113 using namespace reco;
116 PATGenCandsFromSimTracksProducer::PATGenCandsFromSimTracksProducer(
const ParameterSet& cfg) :
118 src_(cfg.getParameter<
InputTag>(
"src")),
119 setStatus_(cfg.getParameter<int32_t>(
"setStatus")),
120 makeMotherLink_(cfg.existsAs<bool>(
"makeMotherLink") ? cfg.getParameter<bool>(
"makeMotherLink") :
false),
121 writeAncestors_(cfg.existsAs<bool>(
"writeAncestors") ? cfg.getParameter<bool>(
"writeAncestors") :
false),
122 genParticles_(makeMotherLink_ ? cfg.getParameter<
InputTag>(
"genParticles") : edm::
InputTag())
125 if (cfg.
exists(
"particleTypes")) {
128 if (cfg.
exists(
"motherTypes")) {
133 if (cfg.
existsAs<
string>(
"filter")) {
135 if (!filter.empty()) {
141 edm::LogWarning(
"Configuration") <<
"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>();
155 SimTrackContainer::const_iterator it = std::lower_bound(g.
simtks.begin(), g.
simtks.end(), idx,
LessById());
156 if ((it != g.
simtks.end()) && (it->trackId() == idx)) {
170 if (simMother != 0) motherRef =
findRef(*simMother,g);
178 assert(it->second > 0);
197 std::vector<int>::const_iterator it;
230 if (!
pdts_.empty()) {
232 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
251 event.getByLabel(
src_, simtracks);
254 std::auto_ptr<SimTrackContainer> simtracksTmp;
257 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
260 simtracksSorted = &* simtracksTmp;
266 event.getByLabel(
src_, simvertices);
271 bool barcodesAreSorted =
true;
275 if (gens->size() != genBarcodes->size())
throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
276 barcodesAreSorted = __gnu_cxx::is_sorted(genBarcodes->begin(), genBarcodes->end());
284 GlobalContext globals(*simtracksSorted, *simvertices, gens, genBarcodes, barcodesAreSorted, *cands, refprod);
286 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin();
287 isimtrk != simtracks->end(); ++isimtrk) {
290 if (isimtrk->genpartIndex() != -1)
continue;
306 if (motherSimTk == 0)
continue;
313 if (mother != 0) motherRef =
findRef(*mother, globals);
317 cands->push_back(genp);
323 #ifdef DEBUG_PATGenCandsFromSimTracksProducer
324 std::cout <<
"Produced a list of " << orphans->size() <<
" genParticles." << std::endl;
325 for (GenParticleCollection::const_iterator it = orphans->begin(), ed = orphans->end(); it != ed; ++it) {
327 std::cout <<
"GenParticle #" << (it - orphans->begin()) <<
": pdgId " << it->pdgId()
328 <<
", pt = " << it->pt() <<
", eta = " << it->eta() <<
", phi = " << it->phi()
329 <<
", rho = " << it->vertex().Rho() <<
", z = " << it->vertex().Z() << std::endl;
333 if (mom.
id() == orphans.
id()) {
338 std::cout <<
"GenParticleRef [" << mom.
id() <<
"/" << mom.
key() <<
"]: pdgId " << mom->pdgId() <<
", status = " << mom->status()
339 <<
", pt = " << mom->pt() <<
", eta = " << mom->eta() <<
", phi = " << mom->phi()
340 <<
", rho = " << mom->vertex().Rho() <<
", z = " << mom->vertex().Z() << std::endl;
341 if (mom.
id() != orphans.
id())
break;
342 if ((mom->motherRef().
id() == mom.
id()) && (mom->motherRef().
key() == mom.
key())) {
343 throw cms::Exception(
"Corrupt Data") <<
"A particle is it's own mother.\n";
345 mom = mom->motherRef();
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
const edm::Handle< reco::GenParticleCollection > & gens
virtual void produce(edm::Event &, const edm::EventSetup &)
PATGenCandsFromSimTracksProducer(const edm::ParameterSet &)
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).
std::map< unsigned int, int > simTksProcessed
#define DEFINE_FWK_MODULE(type)
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::Ref< reco::GenParticleCollection > findRef(const SimTrack &tk, GlobalContext &g) const
std::auto_ptr< StrFilter > filter_
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
~PATGenCandsFromSimTracksProducer()
const edm::SimTrackContainer & simtks
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
float charge() const
charge
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
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)
Produces reco::GenParticle from SimTracks.
bool isNonnull() const
Checks for non-null.
std::set< int > motherPdgIds_
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
bool makeMotherLink_
If true, I'll try to make a link from the GEANT particle to a GenParticle.
std::vector< PdtEntry > pdts_
const edm::RefProd< reco::GenParticleCollection > & refprod
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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.
tuple genp
produce generated paricles in acceptance #
StringCutObjectSelector< reco::GenParticle > StrFilter
void addMother(const typename mothers::value_type &)
add a daughter via a reference
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
const edm::Handle< std::vector< int > > & genBarcodes
unsigned int trackId() const
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
bool operator()(const SimTrack &tk1, unsigned int id) const
std::vector< SimVertex > SimVertexContainer
key_type key() const
Accessor for product key.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::Ref< reco::GenParticleCollection > generatorRef_(const SimTrack &tk, const GlobalContext &g) const
Used by findRef if the track is a PYTHIA particle.
Global context for all recursive methods.
const edm::SimVertexContainer & simvtxs
int type() const
particle type (HEP PDT convension)
const math::XYZTLorentzVectorD & momentum() const
particle info...
std::vector< PdtEntry > motherPdts_
bool operator()(unsigned int id, const SimTrack &tk2) const
edm::InputTag genParticles_
Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of ba...
math::XYZPoint Point
point in the space
bool operator()(const SimTrack &tk1, const SimTrack &tk2) const
ProductID id() const
Accessor for product ID.
std::vector< SimTrack > SimTrackContainer