CMS 3D CMS Logo

MCParticleModuloFilter.cc
Go to the documentation of this file.
1 // description: select events where the multiplicity of specified particle is a multiple of provided number
2 
3 // system include files
4 #include <memory>
5 #include <string>
6 #include <cmath>
7 #include <vector>
8 #include <algorithm>
9 
10 // user include files
17 
19  public:
22 
23  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27  private:
28  // member data
30  std::vector<int> particleIDs_;
31  unsigned multipleOf_;
32  bool absID_;
33  unsigned min_;
34  int status_;
35 };
36 
38  token_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("moduleLabel"))),
39  particleIDs_(iConfig.getParameter<std::vector<int>>("particleIDs")),
40  multipleOf_(iConfig.getParameter<unsigned>("multipleOf")),
41  absID_(iConfig.getParameter<bool>("absID")),
42  min_(iConfig.getParameter<unsigned>("min")),
43  status_(iConfig.getParameter<int>("status"))
44 {
45  // allow binary search
46  std::sort(particleIDs_.begin(),particleIDs_.end());
47 }
48 
50  // get input
52  iEvent.getByToken(token_,h_evt);
53  const HepMC::GenEvent * myGenEvent = h_evt->GetEvent();
54 
55  unsigned sum_part = 0;
56  for(auto i_part = myGenEvent->particles_begin(); i_part != myGenEvent->particles_end(); ++i_part){
57  int id_part = (*i_part)->pdg_id();
58  if(absID_) id_part = std::abs(id_part);
59  if(std::binary_search(particleIDs_.begin(),particleIDs_.end(),id_part) and (status_==0 or (*i_part)->status()==status_)) ++sum_part;
60  }
61 
62  return (sum_part % multipleOf_ == 0) and (sum_part >= min_);
63 }
64 
67  desc.add<edm::InputTag>("moduleLabel",edm::InputTag("generator","unsmeared"));
68  desc.add<std::vector<int>>("particleIDs",{});
69  desc.add<unsigned>("multipleOf",1);
70  desc.add<bool>("absID",false);
71  desc.add<unsigned>("min",0);
72  desc.add<int>("status",0);
73 
74  descriptions.add("MCParticleModuloFilter",desc);
75 }
76 
77 //define this as a plug-in
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const edm::EDGetTokenT< edm::HepMCProduct > token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< int > particleIDs_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
MCParticleModuloFilter(const edm::ParameterSet &)