CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
InputGenJetsParticleSelector Class Reference

#include <InputGenJetsParticleSelector.h>

Inheritance diagram for InputGenJetsParticleSelector:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Types

typedef std::vector< bool > ParticleBitmap
 
typedef std::vector< const
reco::GenParticle * > 
ParticleVector
 
enum  ResonanceState { kNo = 0, kDirect, kIndirect }
 
- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 

Public Member Functions

ResonanceState fromResonance (ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
 
bool getExcludeResonances () const
 
const std::vector< unsigned int > & getIgnoredParticles () const
 
bool getPartonicFinalState () const
 
double getPtMin () const
 
bool getTausAndJets () const
 
bool hasPartonChildren (ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
 
 InputGenJetsParticleSelector (const edm::ParameterSet &)
 
bool isIgnored (int pdgId) const
 
bool isParton (int pdgId) const
 
virtual void produce (edm::Event &evt, const edm::EventSetup &evtSetup)
 
void setExcludeResonances (bool flag=true)
 
void setPartonicFinalState (bool flag=true)
 
void setPtMin (double ptMin)
 
void setTausAsJets (bool flag=true)
 
 ~InputGenJetsParticleSelector ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static bool isHadron (int pdgId)
 
static bool isResonance (int pdgId)
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

 InputGenJetsParticleSelector ()
 
bool isExcludedFromResonance (int pdgId) const
 
void setExcludeFromResonancePids (const std::vector< unsigned int > &particleIDs)
 
void setIgnoredParticles (const std::vector< unsigned int > &particleIDs)
 
int testPartonChildren (ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
 

Private Attributes

std::vector< unsigned int > excludeFromResonancePids
 
bool excludeResonances
 
std::vector< unsigned int > ignoreParticleIDs
 
edm::EDGetTokenT
< reco::GenParticleCollection
input_genpartcoll_token_
 
edm::InputTag inTag
 
bool partonicFinalState
 
double ptMin
 
bool tausAsJets
 

Additional Inherited Members

- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 28 of file InputGenJetsParticleSelector.h.

Member Typedef Documentation

Definition at line 31 of file InputGenJetsParticleSelector.h.

Definition at line 32 of file InputGenJetsParticleSelector.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

InputGenJetsParticleSelector::InputGenJetsParticleSelector ( const edm::ParameterSet params)

Definition at line 47 of file InputGenJetsParticleSelector.cc.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), input_genpartcoll_token_, inTag, setExcludeFromResonancePids(), and setIgnoredParticles().

47  :
48  inTag(params.getParameter<edm::InputTag>("src")),
49  partonicFinalState(params.getParameter<bool>("partonicFinalState")),
50  excludeResonances(params.getParameter<bool>("excludeResonances")),
51  tausAsJets(params.getParameter<bool>("tausAsJets")),
52  ptMin(0.0){
53  if (params.exists("ignoreParticleIDs"))
54  setIgnoredParticles(params.getParameter<std::vector<unsigned int> >
55  ("ignoreParticleIDs"));
56  setExcludeFromResonancePids(params.getParameter<std::vector<unsigned int> >
57  ("excludeFromResonancePids"));
58 
59  produces <reco::GenParticleRefVector> ();
60 
61  input_genpartcoll_token_ = consumes<reco::GenParticleCollection>(inTag);
62 
63 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
void setIgnoredParticles(const std::vector< unsigned int > &particleIDs)
edm::EDGetTokenT< reco::GenParticleCollection > input_genpartcoll_token_
void setExcludeFromResonancePids(const std::vector< unsigned int > &particleIDs)
InputGenJetsParticleSelector::~InputGenJetsParticleSelector ( )

Definition at line 65 of file InputGenJetsParticleSelector.cc.

65 {}
InputGenJetsParticleSelector::InputGenJetsParticleSelector ( )
inlineprivate

Definition at line 76 of file InputGenJetsParticleSelector.h.

76 {} //should not be used!

Member Function Documentation

InputGenJetsParticleSelector::ResonanceState InputGenJetsParticleSelector::fromResonance ( ParticleBitmap invalid,
const ParticleVector p,
const reco::GenParticle particle 
) const

Definition at line 178 of file InputGenJetsParticleSelector.cc.

References i, customizeTrackingMonitorSeedNumber::idx, isExcludedFromResonance(), isIgnored(), isParton(), isResonance(), kDirect, kIndirect, kNo, reco::CompositeRefCandidateT< D >::mother(), reco::CompositeRefCandidateT< D >::numberOfMothers(), partIdx(), benchmark_cfg::pdgId, reco::LeafCandidate::pdgId(), query::result, and reco::LeafCandidate::status().

Referenced by produce().

181 {
182  unsigned int idx = partIdx(p, particle);
183  int id = particle->pdgId();
184 
185  if (invalid[idx]) return kIndirect;
186 
187  if (isResonance(id) && (particle->status() == 3 || particle->status() == 22) ){
188  return kDirect;
189  }
190 
191 
192  if (!isIgnored(id) && (isParton(id)))
193  return kNo;
194 
195 
196 
197  unsigned int nMo=particle->numberOfMothers();
198  if (!nMo)
199  return kNo;
200 
201 
202  for(unsigned int i=0;i<nMo;++i){
203  ResonanceState result = fromResonance(invalid,p,dynamic_cast<const reco::GenParticle*>(particle->mother(i)));
204  switch(result) {
205  case kNo:
206  break;
207  case kDirect:
208  if (dynamic_cast<const reco::GenParticle*>(particle->mother(i))->pdgId()==id || isResonance(id))
209  return kDirect;
210  if(!isExcludedFromResonance(id))
211  break;
212  case kIndirect:
213  return kIndirect;
214  }
215  }
216 return kNo;
217 }
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
virtual int status() const
status word
virtual size_t numberOfMothers() const
number of mothers
tuple result
Definition: query.py:137
static unsigned int partIdx(const InputGenJetsParticleSelector::ParticleVector &p, const reco::GenParticle *particle)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
ResonanceState fromResonance(ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
bool InputGenJetsParticleSelector::getExcludeResonances ( ) const
inline
const std::vector<unsigned int>& InputGenJetsParticleSelector::getIgnoredParticles ( ) const
inline

Definition at line 44 of file InputGenJetsParticleSelector.h.

References ignoreParticleIDs.

45  { return ignoreParticleIDs; }
std::vector< unsigned int > ignoreParticleIDs
bool InputGenJetsParticleSelector::getPartonicFinalState ( ) const
inline
double InputGenJetsParticleSelector::getPtMin ( ) const
inline

Definition at line 43 of file InputGenJetsParticleSelector.h.

References ptMin.

bool InputGenJetsParticleSelector::getTausAndJets ( ) const
inline

Definition at line 42 of file InputGenJetsParticleSelector.h.

References tausAsJets.

bool InputGenJetsParticleSelector::hasPartonChildren ( ParticleBitmap invalid,
const ParticleVector p,
const reco::GenParticle particle 
) const

Definition at line 220 of file InputGenJetsParticleSelector.cc.

References testPartonChildren().

Referenced by produce().

222  {
223  return testPartonChildren(invalid, p, particle) > 0;
224 }
int testPartonChildren(ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
bool InputGenJetsParticleSelector::isExcludedFromResonance ( int  pdgId) const
private

Definition at line 111 of file InputGenJetsParticleSelector.cc.

References excludeFromResonancePids, and benchmark_cfg::pdgId.

Referenced by fromResonance().

112 {
113  pdgId = pdgId > 0 ? pdgId : -pdgId;
114  std::vector<unsigned int>::const_iterator pos =
115  std::lower_bound(excludeFromResonancePids.begin(),
117  (unsigned int)pdgId);
118  return pos != excludeFromResonancePids.end() && *pos == (unsigned int)pdgId;
119 
120 }
std::vector< unsigned int > excludeFromResonancePids
bool InputGenJetsParticleSelector::isHadron ( int  pdgId)
static

Definition at line 87 of file InputGenJetsParticleSelector.cc.

References benchmark_cfg::pdgId.

88 {
89  pdgId = (pdgId > 0 ? pdgId : -pdgId) % 10000;
90  return (pdgId > 100 && pdgId < 900) ||
91  (pdgId > 1000 && pdgId < 9000);
92 }
bool InputGenJetsParticleSelector::isIgnored ( int  pdgId) const

Definition at line 101 of file InputGenJetsParticleSelector.cc.

References ignoreParticleIDs, and benchmark_cfg::pdgId.

Referenced by fromResonance(), and produce().

102 {
103  pdgId = pdgId > 0 ? pdgId : -pdgId;
104  std::vector<unsigned int>::const_iterator pos =
105  std::lower_bound(ignoreParticleIDs.begin(),
106  ignoreParticleIDs.end(),
107  (unsigned int)pdgId);
108  return pos != ignoreParticleIDs.end() && *pos == (unsigned int)pdgId;
109 }
std::vector< unsigned int > ignoreParticleIDs
bool InputGenJetsParticleSelector::isParton ( int  pdgId) const

Definition at line 79 of file InputGenJetsParticleSelector.cc.

References benchmark_cfg::pdgId, and tausAsJets.

Referenced by fromResonance(), and produce().

79  {
80  pdgId = (pdgId > 0 ? pdgId : -pdgId) % 10000;
81  return (pdgId > 0 && pdgId < 6) ||
82  pdgId == 9 || (tausAsJets && pdgId == 15) || pdgId == 21;
83  // tops are not considered "regular" partons
84  // but taus eventually are (since they may hadronize later)
85 }
bool InputGenJetsParticleSelector::isResonance ( int  pdgId)
static

Definition at line 94 of file InputGenJetsParticleSelector.cc.

References benchmark_cfg::pdgId.

Referenced by fromResonance().

95 {
96  // gauge bosons and tops
97  pdgId = (pdgId > 0 ? pdgId : -pdgId) % 10000;
98  return (pdgId > 21 && pdgId <= 42) || pdgId == 6 || pdgId == 7 || pdgId == 8 ; //BUG! was 21. 22=gamma..
99 }
void InputGenJetsParticleSelector::produce ( edm::Event evt,
const edm::EventSetup evtSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 228 of file InputGenJetsParticleSelector.cc.

References excludeResonances, fromResonance(), genParticleCandidates2GenParticles_cfi::genParticles, edm::Event::getByToken(), hasPartonChildren(), i, customizeTrackingMonitorSeedNumber::idx, input_genpartcoll_token_, align::invalid, invalidateTree(), isIgnored(), isParton(), getDQMSummary::iter, reco::CompositeRefCandidateT< D >::numberOfDaughters(), partonicFinalState, reco::LeafCandidate::pdgId(), reco::LeafCandidate::pt(), ptMin, edm::Event::put(), findQualityFiles::size, python.multivaluedict::sort(), and reco::LeafCandidate::status().

228  {
229 
230 
231  std::auto_ptr<reco::GenParticleRefVector> selected_ (new reco::GenParticleRefVector);
232 
234  evt.getByToken(input_genpartcoll_token_, genParticles );
235 
236  std::map<const reco::GenParticle*,size_t> particlePtrIdxMap;
237  ParticleVector particles;
238  for (reco::GenParticleCollection::const_iterator iter=genParticles->begin();iter!=genParticles->end();++iter){
239  particles.push_back(&*iter);
240  particlePtrIdxMap[&*iter] = (iter - genParticles->begin());
241  }
242 
243  std::sort(particles.begin(), particles.end());
244  unsigned int size = particles.size();
245 
246  ParticleBitmap selected(size, false);
247  ParticleBitmap invalid(size, false);
248 
249  for(unsigned int i = 0; i < size; i++) {
250  const reco::GenParticle *particle = particles[i];
251  if (invalid[i])
252  continue;
253  if (particle->status() == 1)
254  selected[i] = true;
255  if (partonicFinalState && isParton(particle->pdgId())) {
256 
257  if (particle->numberOfDaughters()==0 &&
258  particle->status() != 1) {
259  // some brokenness in event...
260  invalid[i] = true;
261  }
262  else if (!hasPartonChildren(invalid, particles,
263  particle)) {
264  selected[i] = true;
265  invalidateTree(invalid, particles,particle); //this?!?
266  }
267  }
268 
269  }
270 
271  for(size_t idx = 0; idx < size; ++idx){
272  const reco::GenParticle *particle = particles[idx];
273  if (!selected[idx] || invalid[idx]){
274  continue;
275  }
276 
277  if (excludeResonances &&
278  fromResonance(invalid, particles, particle)) {
279  invalid[idx] = true;
280  //cout<<"[INPUTSELECTOR] Invalidates FROM RESONANCE!: ["<<setw(4)<<idx<<"] "<<particle->pdgId()<<" "<<particle->pt()<<endl;
281  continue;
282  }
283 
284  if (isIgnored(particle->pdgId())){
285  continue;
286  }
287 
288 
289  if (particle->pt() >= ptMin){
290  edm::Ref<reco::GenParticleCollection> particleRef(genParticles,particlePtrIdxMap[particle]);
291  selected_->push_back(particleRef);
292  //cout<<"Finally we have: ["<<setw(4)<<idx<<"] "<<setw(4)<<particle->pdgId()<<" "<<particle->pt()<<endl;
293  }
294  }
295  evt.put(selected_);
296 }
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
bool hasPartonChildren(ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
std::vector< const reco::GenParticle * > ParticleVector
virtual float pt() const
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual int status() const
status word
edm::EDGetTokenT< reco::GenParticleCollection > input_genpartcoll_token_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
static void invalidateTree(InputGenJetsParticleSelector::ParticleBitmap &invalid, const InputGenJetsParticleSelector::ParticleVector &p, const reco::GenParticle *particle)
virtual size_t numberOfDaughters() const
number of daughters
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
tuple size
Write out results.
ResonanceState fromResonance(ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
void InputGenJetsParticleSelector::setExcludeFromResonancePids ( const std::vector< unsigned int > &  particleIDs)
private
void InputGenJetsParticleSelector::setExcludeResonances ( bool  flag = true)
inline
void InputGenJetsParticleSelector::setIgnoredParticles ( const std::vector< unsigned int > &  particleIDs)
private

Definition at line 67 of file InputGenJetsParticleSelector.cc.

References ignoreParticleIDs, and python.multivaluedict::sort().

Referenced by InputGenJetsParticleSelector().

68 {
69  ignoreParticleIDs = particleIDs;
71 }
std::vector< unsigned int > ignoreParticleIDs
void InputGenJetsParticleSelector::setPartonicFinalState ( bool  flag = true)
inline
void InputGenJetsParticleSelector::setPtMin ( double  ptMin)
inline

Definition at line 52 of file InputGenJetsParticleSelector.h.

References ptMin.

void InputGenJetsParticleSelector::setTausAsJets ( bool  flag = true)
inline
int InputGenJetsParticleSelector::testPartonChildren ( InputGenJetsParticleSelector::ParticleBitmap invalid,
const ParticleVector p,
const reco::GenParticle particle 
) const
private

Definition at line 154 of file InputGenJetsParticleSelector.cc.

References reco::CompositeRefCandidateT< D >::daughter(), i, customizeTrackingMonitorSeedNumber::idx, CandMCTagUtils::isParton(), npart, reco::CompositeRefCandidateT< D >::numberOfDaughters(), partIdx(), reco::Candidate::pdgId(), and query::result.

Referenced by hasPartonChildren().

157 {
158  unsigned int npart=particle->numberOfDaughters();
159  if (!npart) {return 0;}
160 
161  for (unsigned int i=0;i<npart;++i){
162  unsigned int idx = partIdx(p,dynamic_cast<const reco::GenParticle*>(particle->daughter(i)));
163  if (invalid[idx])
164  continue;
165  if (isParton((particle->daughter(i)->pdgId()))){
166  return 1;
167  }
168  if (isHadron((particle->daughter(i)->pdgId()))){
169  return -1;
170  }
171  int result = testPartonChildren(invalid,p,dynamic_cast<const reco::GenParticle*>(particle->daughter(i)));
172  if (result) return result;
173  }
174  return 0;
175 }
int i
Definition: DBlmapReader.cc:9
int testPartonChildren(ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
double npart
Definition: HydjetWrapper.h:44
virtual size_t numberOfDaughters() const
number of daughters
tuple result
Definition: query.py:137
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
static unsigned int partIdx(const InputGenJetsParticleSelector::ParticleVector &p, const reco::GenParticle *particle)
virtual int pdgId() const =0
PDG identifier.
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...

Member Data Documentation

std::vector<unsigned int> InputGenJetsParticleSelector::excludeFromResonancePids
private
bool InputGenJetsParticleSelector::excludeResonances
private
std::vector<unsigned int> InputGenJetsParticleSelector::ignoreParticleIDs
private
edm::EDGetTokenT<reco::GenParticleCollection> InputGenJetsParticleSelector::input_genpartcoll_token_
private

Definition at line 94 of file InputGenJetsParticleSelector.h.

Referenced by InputGenJetsParticleSelector(), and produce().

edm::InputTag InputGenJetsParticleSelector::inTag
private

Definition at line 78 of file InputGenJetsParticleSelector.h.

Referenced by InputGenJetsParticleSelector().

bool InputGenJetsParticleSelector::partonicFinalState
private
double InputGenJetsParticleSelector::ptMin
private

Definition at line 92 of file InputGenJetsParticleSelector.h.

Referenced by getPtMin(), produce(), and setPtMin().

bool InputGenJetsParticleSelector::tausAsJets
private

Definition at line 91 of file InputGenJetsParticleSelector.h.

Referenced by getTausAndJets(), isParton(), and setTausAsJets().