51 size_t f = selection.find_first_not_of(
' ');
52 size_t n = selection.size();
55 for(; (c = selection[
f]) !=
' ' && f < n; ++
f) {
58 if(command[0] ==
'+') {
60 if(command[0] ==
'+') {
69 if(command[command.size() - 1] ==
'+') {
70 command.erase(command.size() - 1);
71 if(command[command.size()-1] ==
'+') {
72 command.erase(command.size() - 1);
84 <<
"invalid selection command: " << command <<
"\n" << endl;
87 if(selection[f] !=
' ')
break;
89 cut =
string(selection, f);
91 cut =
string(cut, 0, cut.find_first_of(
' '));
92 code.
all_ = cut ==
"*";
98 selection_(cfg.getParameter<vector<
string> >(
"select")) {
100 produces<GenParticleCollection>();
101 produces<edm::Association<reco::GenParticleCollection> >();
117 std::vector<size_t> & allIndices ) {
120 size_t cachedIndex =
index;
125 if (
find( allIndices.begin(), allIndices.end(),
index ) == allIndices.end() ) {
126 allIndices.push_back( index );
127 if ( cachedIndex != index ) {
136 std::vector<size_t> & allIndices ) {
139 size_t cachedIndex =
index;
144 if (
find( allIndices.begin(), allIndices.end(),
index ) == allIndices.end() ) {
145 allIndices.push_back( index );
146 if ( cachedIndex != index ) {
164 <<
"selections \"keep *\" and \"drop *\" can be used only as first options. Here used in position # " 167 case ::helper::SelectCode::kDrop :
169 case ::helper::SelectCode::kKeep :
183 const size_t n = src->size();
186 for(
size_t j = 0; j <
select_.size(); ++j) {
187 const pair<StringCutObjectSelector<GenParticle>, SelectCode> &
sel =
select_[j];
188 SelectCode code = sel.second;
190 for(
size_t i = 0;
i <
n; ++
i) {
193 int keepOrDrop =
keep;
194 switch(code.keepOrDrop_) {
195 case SelectCode::kKeep:
196 keepOrDrop =
keep;
break;
197 case SelectCode::kDrop:
201 std::vector<size_t> allIndicesDa;
202 std::vector<size_t> allIndicesMo;
203 switch(code.daughtersDepth_) {
204 case SelectCode::kAll :
206 case SelectCode::kFirst :
211 switch(code.mothersDepth_) {
212 case SelectCode::kAll :
214 case SelectCode::kFirst :
224 for(
size_t i = 0;
i <
n; ++
i) {
234 auto out = std::make_unique<GenParticleCollection>();
236 out->reserve(counter);
250 vector<size_t> daIndxs, daNewIndxs;
252 std::sort(daNewIndxs.begin(),daNewIndxs.end());
253 for(
size_t i=0;
i<daNewIndxs.size(); ++
i)
256 vector<size_t> moIndxs, moNewIndxs;
258 std::sort(moNewIndxs.begin(),moNewIndxs.end());
259 for(
size_t i=0; i<moNewIndxs.size(); ++
i)
265 auto orig2new = std::make_unique<edm::Association<reco::GenParticleCollection>>(oh);
267 orig2newFiller.insert(src,
flags_.begin(),
flags_.end());
268 orig2newFiller.fill();
278 j != daughters.
end(); ++j) {
280 if (
find(daIndxs.begin(), daIndxs.end(), dau.
key()) == daIndxs.end()) {
281 daIndxs.push_back( dau.
key() );
284 daNewIndxs.push_back( idx );
299 j != mothers.
end(); ++j) {
301 if (
find(moIndxs.begin(), moIndxs.end(), mom.
key()) == moIndxs.end()) {
302 moIndxs.push_back( mom.
key() );
305 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.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
void flagMothers(const reco::GenParticle &, int)
std::string replace(const std::string &) const
void recursiveFlagMothers(size_t, const reco::GenParticleCollection &, int, std::vector< size_t > &)
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_
const mothers & motherRefVector() const
references to mothers
FlagDepth daughtersDepth_
def gen(fragment, howMuch)
Production test section ####.
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_
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