85 size_t f = selection.find_first_not_of(
' ');
86 size_t n = selection.size();
89 for (; (c = selection[
f]) !=
' ' && f < n; ++
f) {
92 if (command[0] ==
'+') {
94 if (command[0] ==
'+') {
103 if (command[command.size() - 1] ==
'+') {
104 command.erase(command.size() - 1);
105 if (command[command.size() - 1] ==
'+') {
106 command.erase(command.size() - 1);
114 if (command ==
"keep")
116 else if (command ==
"drop")
122 if (selection[f] !=
' ')
125 cut =
string(selection, f);
127 cut =
string(cut, 0, cut.find_first_of(
' '));
128 code.
all_ = cut ==
"*";
135 keepOrDropAll_(
drop),
136 selection_(iConfig.getParameter<vector<
string>>(
"select")) {
137 produces<TrackingParticleCollection>();
155 std::vector<size_t> &allIndices) {
158 size_t cachedIndex =
index;
163 if (
find(allIndices.begin(), allIndices.end(),
index) == allIndices.end()) {
164 allIndices.push_back(index);
165 if (cachedIndex != index) {
176 std::vector<size_t> &allIndices) {
179 size_t cachedIndex =
index;
184 if (
find(allIndices.begin(), allIndices.end(),
index) == allIndices.end()) {
185 allIndices.push_back(index);
186 if (cachedIndex != index) {
195 vector<size_t> &daNewIndxs,
199 if (
find(daIndxs.begin(), daIndxs.end(), dau.
key()) == daIndxs.end()) {
200 daIndxs.push_back(dau.
key());
203 daNewIndxs.push_back(idx);
214 vector<size_t> &moNewIndxs,
218 if (
find(moIndxs.begin(), moIndxs.end(), mom.
key()) == moIndxs.end()) {
219 moIndxs.push_back(mom.
key());
222 moNewIndxs.push_back(idx);
244 <<
"selections \"keep *\" and \"drop *\" can be used only as first options. Here used in position # " 248 case ::helper::SelectCode::kDrop:
251 case ::helper::SelectCode::kKeep:
267 const size_t n = gps.size();
270 for (
size_t j = 0; j <
select_.size(); ++j) {
271 const pair<StringCutObjectSelector<GenParticle>, SelectCode> &
sel =
select_[j];
272 SelectCode code = sel.second;
274 for (
size_t i = 0;
i <
n; ++
i) {
277 int keepOrDrop =
keep;
278 switch (code.keepOrDrop_) {
279 case SelectCode::kKeep:
282 case SelectCode::kDrop:
286 std::vector<size_t> allIndicesDa;
287 std::vector<size_t> allIndicesMo;
288 switch (code.daughtersDepth_) {
289 case SelectCode::kAll:
292 case SelectCode::kFirst:
297 switch (code.mothersDepth_) {
298 case SelectCode::kAll:
301 case SelectCode::kFirst:
310 auto out = std::make_unique<TrackingParticleCollection>();
313 for (
auto &&tp : tps) {
314 auto &associatedGenParticles = tp.genParticles();
316 bool isSelected =
false;
317 for (
auto &&assocGen : associatedGenParticles) {
323 out->emplace_back(tp);
333 desc.
add<vector<string>>(
"select");
335 descriptions.
add(
"tpSelectorByGenDefault", desc);
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void produce(edm::Event &, const edm::EventSetup &) override
void flagDaughters(const reco::GenParticle &, int)
std::vector< TrackingParticle > TrackingParticleCollection
edm::EDGetTokenT< TrackingParticleCollection > tpToken_
std::string replace(const std::string &) const
void parse(const std::string &selection, helper::SelectCode &code, std::string &cut) const
void getMotherKeys(std::vector< size_t > &, std::vector< size_t > &, const reco::GenParticleRefVector &) const
void flagMothers(const reco::GenParticle &, int)
const daughters & daughterRefVector() const
references to daughtes
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.
std::vector< int > flags_
void recursiveFlagMothers(size_t, const reco::GenParticleCollection &, int, std::vector< size_t > &)
const_iterator begin() const
Initialize an iterator over the RefVector.
void recursiveFlagDaughters(size_t, const reco::GenParticleCollection &, int, std::vector< size_t > &)
#define DEFINE_FWK_MODULE(type)
const mothers & motherRefVector() const
references to mothers
void getDaughterKeys(std::vector< size_t > &, std::vector< size_t > &, const reco::GenParticleRefVector &) const
bool get(ProductID const &oid, Handle< PROD > &result) const
FlagDepth daughtersDepth_
TrackingParticleSelectorByGen(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< std::pair< StringCutObjectSelector< reco::GenParticle >, helper::SelectCode > > select_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::GenParticleCollection > gpToken_
std::vector< std::string > selection_