36 #include <ext/algorithm> 83 std::vector<int> &genBarcodes,
84 bool &barcodesAreSorted )
const ;
103 setStatus_(cfg.getParameter<int32_t>(
"setStatus")),
108 if (cfg.
exists(
"particleTypes")) {
113 if (cfg.
existsAs<
string>(
"filter")) {
115 if (!filter.empty()) {
119 produces<GenParticleCollection>();
120 produces<vector<int> >();
130 std::vector<int> &genBarcodes,
131 bool &barcodesAreSorted)
const 142 if (
filter_.get() !=
nullptr) {
147 genp.addMother(parentRef);
148 mergedGens.push_back(genp);
150 unsigned int dauidx = mergedGens.size()-1;
158 for (SimTrackContainer::const_iterator isimtrk = simtracksSorted.begin();
159 isimtrk != simtracksSorted.end(); ++isimtrk) {
160 if (!isimtrk->noVertex()) {
162 const SimVertex &vtx = simvertices[isimtrk->vertIndex()];
169 SimTrackContainer::const_iterator it = std::lower_bound(simtracksSorted.begin(), simtracksSorted.end(),
idx,
LessById());
170 if ((it != simtracksSorted.end()) && (it->trackId() ==
idx)) {
171 if (it->trackId()==stDau.
trackId()) {
173 addGenParticle(stDau, *isimtrk, dauidx, simtracksSorted, simvertices, mergedGens, ref, genBarcodes, barcodesAreSorted);
184 if (!
pdts_.empty()) {
186 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
200 std::unique_ptr<SimTrackContainer> simtracksTmp;
202 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
204 std::sort(simtracksTmp->begin(), simtracksTmp->end(),
LessById());
205 simtracksSorted = &* simtracksTmp;
215 bool barcodesAreSorted =
true;
218 if (gens->size() != genBarcodes->size())
throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
221 auto candsPtr = std::make_unique<GenParticleCollection>();
227 for(
size_t i = 0;
i < gens->size(); ++
i ) {
229 cands.push_back(cand);
233 auto newGenBarcodes = std::make_unique<vector<int>>();
234 for (
unsigned int i = 0;
i < genBarcodes->size(); ++
i) {
235 newGenBarcodes->push_back((*genBarcodes)[
i]);
237 barcodesAreSorted = __gnu_cxx::is_sorted(newGenBarcodes->begin(), newGenBarcodes->end());
239 for(
size_t i = 0;
i < cands.size(); ++
i ) {
244 for (
size_t d = 0;
d < nDaus; ++
d) {
251 for (
size_t m = 0;
m < nMoms; ++
m) {
256 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin();
257 isimtrk != simtracks->end(); ++isimtrk) {
260 if (isimtrk->genpartIndex() != -1)
continue;
269 if (!isimtrk->noVertex()) {
272 const SimVertex &
vtx = (*simvertices)[isimtrk->vertIndex()];
279 SimTrackContainer::const_iterator it = std::lower_bound(simtracksSorted->begin(), simtracksSorted->end(),
idx,
LessById());
280 if ((it != simtracksSorted->end()) && (it->trackId() ==
idx)) {
281 if (it->genpartIndex() != -1) {
282 std::vector<int>::const_iterator itIndex;
283 if (barcodesAreSorted) {
284 itIndex = std::lower_bound(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
286 itIndex =
std::find( genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
291 if ((itIndex != genBarcodes->end()) && (*itIndex == it->genpartIndex())) {
294 unsigned int momidx = itIndex - genBarcodes->begin();
295 addGenParticle(*it, *isimtrk, momidx, *simtracksSorted, *simvertices, *candsPtr, ref, *newGenBarcodes, barcodesAreSorted);
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
bool operator()(const SimTrack &tk1, const SimTrack &tk2) const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
edm::EDGetTokenT< edm::SimVertexContainer > simverticesToken_
std::vector< PdtEntry > pdts_
size_t numberOfMothers() const override
number of mothers
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~GenPlusSimParticleProducer() override
const daughters & daughterRefVector() const
references to daughtes
std::unique_ptr< StrFilter > filter_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
float charge() const
charge
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void addDaughter(const typename daughters::value_type &)
add a daughter via a reference
void resetDaughters(const edm::ProductID &id)
set daughters product ID
StringCutObjectSelector< reco::GenParticle > StrFilter
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
#define DEFINE_FWK_MODULE(type)
const mothers & motherRefVector() const
references to mothers
Abs< T >::type abs(const T &t)
bool operator()(unsigned int id, const SimTrack &tk2) const
GenPlusSimParticleProducer(const edm::ParameterSet &)
Produces reco::GenParticle from SimTracks.
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)
bool operator()(const SimTrack &tk1, unsigned int id) const
ProductID id() const
Accessor for product ID.
unsigned int trackId() const
size_t numberOfDaughters() const override
number of daughters
edm::EDGetTokenT< reco::GenParticleCollection > gensToken_
Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of ba...
std::vector< SimVertex > SimVertexContainer
math::XYZTLorentzVector LorentzVector
Lorentz vector.
void produce(edm::Event &, const edm::EventSetup &) override
int type() const
particle type (HEP PDT convension)
const math::XYZTLorentzVectorD & momentum() const
void addGenParticle(const SimTrack &stMom, const SimTrack &stDau, unsigned int momidx, const edm::SimTrackContainer &simtks, const edm::SimVertexContainer &simvtxs, reco::GenParticleCollection &mergedGens, const reco::GenParticleRefProd ref, std::vector< int > &genBarcodes, bool &barcodesAreSorted) const
Try to link the GEANT particle to the generator particle it came from.
math::XYZPoint Point
point in the space
void resetMothers(const edm::ProductID &id)
set mother product ID
std::vector< SimTrack > SimTrackContainer
edm::EDGetTokenT< edm::SimTrackContainer > simtracksToken_