38 #include <ext/algorithm> 85 std::vector<int> &genBarcodes,
86 bool &barcodesAreSorted)
const;
105 setStatus_(
cfg.getParameter<int32_t>(
"setStatus")),
112 if (
cfg.exists(
"particleTypes")) {
113 pdts_ =
cfg.getParameter<vector<PdtEntry>>(
"particleTypes");
114 if (!
pdts_.empty()) {
120 if (
cfg.existsAs<
string>(
"filter")) {
121 string filter =
cfg.getParameter<
string>(
"filter");
126 produces<GenParticleCollection>();
127 produces<vector<int>>();
137 std::vector<int> &genBarcodes,
138 bool &barcodesAreSorted)
const {
149 if (
filter_.get() !=
nullptr) {
155 genp.addMother(parentRef);
156 mergedGens.push_back(
genp);
158 unsigned int dauidx = mergedGens.size() - 1;
166 for (SimTrackContainer::const_iterator isimtrk = simtracksSorted.begin(); isimtrk != simtracksSorted.end();
168 if (!isimtrk->noVertex()) {
170 const SimVertex &
vtx = simvertices[isimtrk->vertIndex()];
173 if (!
vtx.noParent()) {
175 unsigned int idx =
vtx.parentIndex();
176 SimTrackContainer::const_iterator it =
178 if ((it != simtracksSorted.end()) && (it->trackId() ==
idx)) {
179 if (it->trackId() == stDau.
trackId()) {
182 stDau, *isimtrk, dauidx, simtracksSorted, simvertices, mergedGens, ref, genBarcodes, barcodesAreSorted);
192 if (!
pdts_.empty()) {
195 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
209 std::unique_ptr<SimTrackContainer> simtracksTmp;
211 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
212 simtracksTmp = std::make_unique<SimTrackContainer>(*simtracks);
214 simtracksSorted = &*simtracksTmp;
224 bool barcodesAreSorted =
true;
227 if (gens->size() != genBarcodes->size())
228 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
231 auto candsPtr = std::make_unique<GenParticleCollection>();
237 for (
size_t i = 0;
i < gens->size(); ++
i) {
243 auto newGenBarcodes = std::make_unique<vector<int>>();
244 for (
unsigned int i = 0;
i < genBarcodes->size(); ++
i) {
245 newGenBarcodes->push_back((*genBarcodes)[
i]);
247 barcodesAreSorted = __gnu_cxx::is_sorted(newGenBarcodes->begin(), newGenBarcodes->end());
249 for (
size_t i = 0;
i <
cands.size(); ++
i) {
251 size_t nDaus =
cand.numberOfDaughters();
253 cand.resetDaughters(ref.
id());
254 for (
size_t d = 0;
d < nDaus; ++
d) {
258 size_t nMoms =
cand.numberOfMothers();
260 cand.resetMothers(ref.
id());
261 for (
size_t m = 0;
m < nMoms; ++
m) {
266 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
268 if (isimtrk->genpartIndex() != -1)
279 if (!isimtrk->noVertex()) {
281 const SimVertex &
vtx = (*simvertices)[isimtrk->vertIndex()];
284 if (!
vtx.noParent()) {
286 unsigned int idx =
vtx.parentIndex();
287 SimTrackContainer::const_iterator it =
289 if ((it != simtracksSorted->end()) && (it->trackId() ==
idx)) {
290 if (it->genpartIndex() != -1) {
291 std::vector<int>::const_iterator itIndex;
292 if (barcodesAreSorted) {
293 itIndex =
std::lower_bound(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
295 itIndex =
std::find(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
300 if ((itIndex != genBarcodes->end()) && (*itIndex == it->genpartIndex())) {
303 unsigned int momidx = itIndex - genBarcodes->begin();
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
genp
produce generated paricles in acceptance #
edm::EDGetTokenT< edm::SimVertexContainer > simverticesToken_
#define DEFINE_FWK_MODULE(type)
std::vector< PdtEntry > pdts_
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > tableToken_
std::unique_ptr< StrFilter > filter_
bool operator()(unsigned int id, const SimTrack &tk2) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
float charge() const
charge
const math::XYZTLorentzVectorD & momentum() const
int type() const
particle type (HEP PDT convension)
StringCutObjectSelector< reco::GenParticle > StrFilter
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
bool operator()(const SimTrack &tk1, unsigned int id) const
Abs< T >::type abs(const T &t)
GenPlusSimParticleProducer(const edm::ParameterSet &)
bool getData(T &iHolder) const
Produces reco::GenParticle from SimTracks.
ProductID id() const
Accessor for product ID.
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
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
bool operator()(const SimTrack &tk1, const SimTrack &tk2) const
unsigned int trackId() 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
std::vector< SimTrack > SimTrackContainer
edm::EDGetTokenT< edm::SimTrackContainer > simtracksToken_