CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCPdgIndexFilter.cc
Go to the documentation of this file.
4 
6  token_(consumes<edm::HepMCProduct>(cfg.getUntrackedParameter("moduleLabel",std::string("generator")))),
7  pdgID(cfg.getParameter<std::vector<int> >("PdgId")),
8  index(cfg.getParameter<std::vector<unsigned> >("Index")),
9  maxIndex(*std::max_element(index.begin(),index.end())),
10  taggingMode(cfg.getUntrackedParameter<bool>("TagMode",false)),
11  tag(cfg.getUntrackedParameter<std::string>("Tag",""))
12 {
13  if (pdgID.size() != index.size())
14  edm::LogWarning("MCPdgIndexFilter")
15  << "Configuration Error :"
16  << "Sizes of array parameters 'PdgId' and 'Index' differ.";
17 
18  if (taggingMode) {
19  produces<bool>(tag);
20  edm::LogInfo("TagMode") << "Filter result in '" << tag << "', filtering disabled.";
21  }
22 }
23 
24 
26  bool result = pass(evt);
27  LogDebug("FilterResult") << (result?"Pass":"Fail");
28  if (!taggingMode) return result;
29  evt.put( std::auto_ptr<bool>(new bool(result)), tag);
30  return true;
31 }
32 
33 
36  evt.getByToken(token_, hepmc);
37 
38  const HepMC::GenEvent * genEvent = hepmc->GetEvent();
39 
40  HepMC::GenEvent::particle_const_iterator
41  p(genEvent->particles_begin()),
42  p_end(genEvent->particles_end());
43 
44  for ( unsigned i=0; p!=p_end && i<=maxIndex; ++p, i++ ) {
45  LogDebug("Particle") << "index: " << i << " pdgID: " << (*p)->pdg_id();
46  for (unsigned j = 0; j < pdgID.size(); j++) {
47  if (i==index[j] && pdgID[j] != (*p)->pdg_id())
48  return false;
49  }
50  }
51  return true;
52 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
const std::string tag
tuple cfg
Definition: looper.py:293
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
const bool taggingMode
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
MCPdgIndexFilter(const edm::ParameterSet &)
const std::vector< unsigned > index
tuple genEvent
Definition: MCTruth.py:33
#define end
Definition: vmac.h:37
const unsigned maxIndex
const edm::EDGetTokenT< edm::HepMCProduct > token_
#define begin
Definition: vmac.h:30
const std::vector< int > pdgID
volatile std::atomic< bool > shutdown_flag false
virtual bool filter(edm::Event &, const edm::EventSetup &)
bool pass(const edm::Event &)