53 using namespace ::helper;
54 size_t f = selection.find_first_not_of(
' ');
55 size_t n = selection.size();
58 for (; (c = selection[
f]) !=
' ' && f < n; ++
f) {
61 if (command[0] ==
'+') {
63 if (command[0] ==
'+') {
72 if (command[command.size() - 1] ==
'+') {
73 command.erase(command.size() - 1);
74 if (command[command.size() - 1] ==
'+') {
75 command.erase(command.size() - 1);
83 if (command ==
"keep")
85 else if (command ==
"drop")
91 if (selection[f] !=
' ')
94 cut =
string(selection, f);
96 cut =
string(cut, 0, cut.find_first_of(
' '));
97 code.
all_ = cut ==
"*";
104 keepOrDropAll_(
drop),
105 selection_(cfg.getParameter<
vector<
string>>(
"select")) {
106 using namespace ::helper;
107 produces<GenParticleCollection>();
108 produces<edm::Association<reco::GenParticleCollection>>();
126 std::vector<size_t> &allIndices) {
129 size_t cachedIndex =
index;
134 if (
find(allIndices.begin(), allIndices.end(),
index) == allIndices.end()) {
135 allIndices.push_back(index);
136 if (cachedIndex != index) {
147 std::vector<size_t> &allIndices) {
150 size_t cachedIndex =
index;
155 if (
find(allIndices.begin(), allIndices.end(),
index) == allIndices.end()) {
156 allIndices.push_back(index);
157 if (cachedIndex != index) {
171 ::helper::SelectCode code;
176 <<
"selections \"keep *\" and \"drop *\" can be used only as first options. Here used in position # "
179 switch (code.keepOrDrop_) {
180 case ::helper::SelectCode::kDrop:
183 case ::helper::SelectCode::kKeep:
194 using namespace ::helper;
197 const size_t n = src->size();
201 const pair<StringCutObjectSelector<GenParticle>, SelectCode> &
sel =
select_[
j];
202 SelectCode code = sel.second;
204 for (
size_t i = 0;
i <
n; ++
i) {
207 int keepOrDrop =
keep;
208 switch (code.keepOrDrop_) {
209 case SelectCode::kKeep:
212 case SelectCode::kDrop:
216 std::vector<size_t> allIndicesDa;
217 std::vector<size_t> allIndicesMo;
218 switch (code.daughtersDepth_) {
219 case SelectCode::kAll:
222 case SelectCode::kFirst:
227 switch (code.mothersDepth_) {
228 case SelectCode::kAll:
231 case SelectCode::kFirst:
241 for (
size_t i = 0;
i <
n; ++
i) {
250 auto out = std::make_unique<GenParticleCollection>();
252 out->reserve(counter);
267 vector<size_t> daIndxs, daNewIndxs;
269 std::sort(daNewIndxs.begin(), daNewIndxs.end());
270 for (
size_t i = 0;
i < daNewIndxs.size(); ++
i)
273 vector<size_t> moIndxs, moNewIndxs;
275 std::sort(moNewIndxs.begin(), moNewIndxs.end());
276 for (
size_t i = 0; i < moNewIndxs.size(); ++
i)
281 auto orig2new = std::make_unique<edm::Association<reco::GenParticleCollection>>(oh);
283 orig2newFiller.insert(src,
flags_.begin(),
flags_.end());
284 orig2newFiller.fill();
289 vector<size_t> &daNewIndxs,
293 if (
find(daIndxs.begin(), daIndxs.end(), dau.
key()) == daIndxs.end()) {
294 daIndxs.push_back(dau.
key());
297 daNewIndxs.push_back(idx);
308 vector<size_t> &moNewIndxs,
312 if (
find(moIndxs.begin(), moIndxs.end(), mom.
key()) == moIndxs.end()) {
313 moIndxs.push_back(mom.
key());
316 moNewIndxs.push_back(idx);
std::vector< std::pair< StringCutObjectSelector< reco::GenParticle >, helper::SelectCode > > select_
void flagDaughters(const reco::GenParticle &, int)
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::vector< int > flags_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const edm::EventSetup & c
void setCollisionId(int s)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
void flagMothers(const reco::GenParticle &, int)
void recursiveFlagMothers(size_t, const reco::GenParticleCollection &, int, std::vector< size_t > &)
std::string pdgEntryReplace(const std::string &, HepPDT::ParticleDataTable const &)
const daughters & daughterRefVector() const
references to daughtes
GenParticlePruner(const edm::ParameterSet &)
key_type key() const
Accessor for product key.
const_iterator end() const
Termination of iteration.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
bool empty() const
Is the RefVector empty.
void recursiveFlagDaughters(size_t, const reco::GenParticleCollection &, int, std::vector< size_t > &)
const_iterator begin() const
Initialize an iterator over the RefVector.
void addDaughter(const typename daughters::value_type &)
add a daughter via a reference
std::vector< size_t > indices_
bool getData(T &iHolder) const
const mothers & motherRefVector() const
references to mothers
FlagDepth daughtersDepth_
void parse(const std::string &selection, helper::SelectCode &code, std::string &cut) const
void addMother(const typename mothers::value_type &)
add a daughter via a reference
RefProd< PROD > getRefBeforePut()
const GenStatusFlags & statusFlags() const
edm::EDGetTokenT< reco::GenParticleCollection > srcToken_
static std::atomic< unsigned int > counter
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< std::string > selection_
void getDaughterKeys(std::vector< size_t > &, std::vector< size_t > &, const reco::GenParticleRefVector &) const
void getMotherKeys(std::vector< size_t > &, std::vector< size_t > &, const reco::GenParticleRefVector &) const
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > tableToken_