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::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
 
typedef WorkerT< EDProducerWorkerType
 
- 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 ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

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::InputTag inTag
 
bool partonicFinalState
 
double ptMin
 
bool tausAsJets
 

Additional Inherited Members

- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

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 42 of file InputGenJetsParticleSelector.cc.

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

42  :
43  inTag(params.getParameter<edm::InputTag>("src")),
44  partonicFinalState(params.getParameter<bool>("partonicFinalState")),
45  excludeResonances(params.getParameter<bool>("excludeResonances")),
46  tausAsJets(params.getParameter<bool>("tausAsJets")),
47  ptMin(0.0){
48  if (params.exists("ignoreParticleIDs"))
49  setIgnoredParticles(params.getParameter<std::vector<unsigned int> >
50  ("ignoreParticleIDs"));
51  setExcludeFromResonancePids(params.getParameter<std::vector<unsigned int> >
52  ("excludeFromResonancePids"));
53 
54  produces <reco::GenParticleRefVector> ();
55 
56 }
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)
void setExcludeFromResonancePids(const std::vector< unsigned int > &particleIDs)
InputGenJetsParticleSelector::~InputGenJetsParticleSelector ( )

Definition at line 58 of file InputGenJetsParticleSelector.cc.

58 {}
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 172 of file InputGenJetsParticleSelector.cc.

References i, 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().

175 {
176  unsigned int idx = partIdx(p, particle);
177  int id = particle->pdgId();
178 
179  if (invalid[idx]) return kIndirect;
180 
181  if (isResonance(id) && particle->status() == 3){
182  return kDirect;
183  }
184 
185 
186  if (!isIgnored(id) && (isParton(id)))
187  return kNo;
188 
189 
190 
191  unsigned int nMo=particle->numberOfMothers();
192  if (!nMo)
193  return kNo;
194 
195 
196  for(unsigned int i=0;i<nMo;++i){
197  ResonanceState result = fromResonance(invalid,p,dynamic_cast<const reco::GenParticle*>(particle->mother(i)));
198  switch(result) {
199  case kNo:
200  break;
201  case kDirect:
202  if (dynamic_cast<const reco::GenParticle*>(particle->mother(i))->pdgId()==id || isResonance(id))
203  return kDirect;
204  if(!isExcludedFromResonance(id))
205  break;
206  case kIndirect:
207  return kIndirect;
208  }
209  }
210 return kNo;
211 }
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)
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 214 of file InputGenJetsParticleSelector.cc.

References testPartonChildren().

Referenced by produce().

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

Definition at line 104 of file InputGenJetsParticleSelector.cc.

References excludeFromResonancePids, benchmark_cfg::pdgId, and pos.

Referenced by fromResonance().

105 {
106  pdgId = pdgId > 0 ? pdgId : -pdgId;
107  std::vector<unsigned int>::const_iterator pos =
108  std::lower_bound(excludeFromResonancePids.begin(),
110  (unsigned int)pdgId);
111  return pos != excludeFromResonancePids.end() && *pos == (unsigned int)pdgId;
112 
113 }
std::vector< unsigned int > excludeFromResonancePids
bool InputGenJetsParticleSelector::isHadron ( int  pdgId)
static

Definition at line 80 of file InputGenJetsParticleSelector.cc.

References benchmark_cfg::pdgId.

81 {
82  pdgId = (pdgId > 0 ? pdgId : -pdgId) % 10000;
83  return (pdgId > 100 && pdgId < 900) ||
84  (pdgId > 1000 && pdgId < 9000);
85 }
bool InputGenJetsParticleSelector::isIgnored ( int  pdgId) const

Definition at line 94 of file InputGenJetsParticleSelector.cc.

References ignoreParticleIDs, benchmark_cfg::pdgId, and pos.

Referenced by fromResonance(), and produce().

95 {
96  pdgId = pdgId > 0 ? pdgId : -pdgId;
97  std::vector<unsigned int>::const_iterator pos =
98  std::lower_bound(ignoreParticleIDs.begin(),
99  ignoreParticleIDs.end(),
100  (unsigned int)pdgId);
101  return pos != ignoreParticleIDs.end() && *pos == (unsigned int)pdgId;
102 }
std::vector< unsigned int > ignoreParticleIDs
bool InputGenJetsParticleSelector::isParton ( int  pdgId) const

Definition at line 72 of file InputGenJetsParticleSelector.cc.

References benchmark_cfg::pdgId, and tausAsJets.

Referenced by fromResonance(), and produce().

72  {
73  pdgId = (pdgId > 0 ? pdgId : -pdgId) % 10000;
74  return (pdgId > 0 && pdgId < 6) || pdgId == 7 ||
75  pdgId == 9 || (tausAsJets && pdgId == 15) || pdgId == 21;
76  // tops are not considered "regular" partons
77  // but taus eventually are (since they may hadronize later)
78 }
bool InputGenJetsParticleSelector::isResonance ( int  pdgId)
static

Definition at line 87 of file InputGenJetsParticleSelector.cc.

References benchmark_cfg::pdgId.

Referenced by fromResonance().

88 {
89  // gauge bosons and tops
90  pdgId = (pdgId > 0 ? pdgId : -pdgId) % 10000;
91  return (pdgId > 21 && pdgId <= 42) || pdgId == 6 || pdgId == 8 ; //BUG! war 21. 22=gamma..
92 }
void InputGenJetsParticleSelector::produce ( edm::Event evt,
const edm::EventSetup evtSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 222 of file InputGenJetsParticleSelector.cc.

References prof2calltree::count, excludeResonances, fromResonance(), genParticleCandidates2GenParticles_cfi::genParticles, edm::Event::getByLabel(), hasPartonChildren(), i, inTag, align::invalid, invalidateTree(), isIgnored(), isParton(), reco::CompositeRefCandidateT< D >::numberOfDaughters(), partonicFinalState, reco::LeafCandidate::pdgId(), reco::LeafCandidate::pt(), ptMin, edm::Event::put(), findQualityFiles::size, python.multivaluedict::sort(), and reco::LeafCandidate::status().

222  {
223 
224 
225  std::auto_ptr<reco::GenParticleRefVector> selected_ (new reco::GenParticleRefVector);
226 
228  // evt.getByLabel("genParticles", genParticles );
229  evt.getByLabel(inTag, genParticles );
230 
231 
232  ParticleVector particles;
233  for (reco::GenParticleCollection::const_iterator iter=genParticles->begin();iter!=genParticles->end();++iter){
234  particles.push_back(&*iter);
235  }
236 
237  std::sort(particles.begin(), particles.end());
238  unsigned int size = particles.size();
239 
240  ParticleBitmap selected(size, false);
241  ParticleBitmap invalid(size, false);
242 
243  for(unsigned int i = 0; i < size; i++) {
244  const reco::GenParticle *particle = particles[i];
245  if (invalid[i])
246  continue;
247  if (particle->status() == 1)
248  selected[i] = true;
249  if (partonicFinalState && isParton(particle->pdgId())) {
250 
251  if (particle->numberOfDaughters()==0 &&
252  particle->status() != 1) {
253  // some brokenness in event...
254  invalid[i] = true;
255  }
256  else if (!hasPartonChildren(invalid, particles,
257  particle)) {
258  selected[i] = true;
259  invalidateTree(invalid, particles,particle); //this?!?
260  }
261  }
262 
263  }
264  unsigned int count=0;
265  for(size_t idx=0;idx<genParticles->size();++idx){
266  const reco::GenParticle *particle = particles[idx];
267  if (!selected[idx] || invalid[idx]){
268  continue;
269  }
270 
271  if (excludeResonances &&
272  fromResonance(invalid, particles, particle)) {
273  invalid[idx] = true;
274  //cout<<"[INPUTSELECTOR] Invalidates FROM RESONANCE!: ["<<setw(4)<<idx<<"] "<<particle->pdgId()<<" "<<particle->pt()<<endl;
275  continue;
276  }
277 
278  if (isIgnored(particle->pdgId())){
279  continue;
280  }
281 
282 
283  if (particle->pt() >= ptMin){
284  edm::Ref<reco::GenParticleCollection> particleRef(genParticles,idx);
285  selected_->push_back(particleRef);
286  //cout<<"Finally we have: ["<<setw(4)<<idx<<"] "<<setw(4)<<particle->pdgId()<<" "<<particle->pt()<<endl;
287  count++;
288  }
289  }
290  evt.put(selected_);
291 }
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 int status() const
status word
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
static void invalidateTree(InputGenJetsParticleSelector::ParticleBitmap &invalid, const InputGenJetsParticleSelector::ParticleVector &p, const reco::GenParticle *particle)
virtual size_t numberOfDaughters() const
number of daughters
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual double pt() const
transverse momentum
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

Definition at line 49 of file InputGenJetsParticleSelector.h.

References excludeResonances.

void InputGenJetsParticleSelector::setIgnoredParticles ( const std::vector< unsigned int > &  particleIDs)
private

Definition at line 60 of file InputGenJetsParticleSelector.cc.

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

Referenced by InputGenJetsParticleSelector().

61 {
62  ignoreParticleIDs = particleIDs;
64 }
std::vector< unsigned int > ignoreParticleIDs
void InputGenJetsParticleSelector::setPartonicFinalState ( bool  flag = true)
inline

Definition at line 47 of file InputGenJetsParticleSelector.h.

References partonicFinalState.

void InputGenJetsParticleSelector::setPtMin ( double  ptMin)
inline

Definition at line 52 of file InputGenJetsParticleSelector.h.

References ptMin.

void InputGenJetsParticleSelector::setTausAsJets ( bool  flag = true)
inline

Definition at line 51 of file InputGenJetsParticleSelector.h.

References tausAsJets.

int InputGenJetsParticleSelector::testPartonChildren ( InputGenJetsParticleSelector::ParticleBitmap invalid,
const ParticleVector p,
const reco::GenParticle particle 
) const
private

Definition at line 148 of file InputGenJetsParticleSelector.cc.

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

Referenced by hasPartonChildren().

151 {
152  unsigned int npart=particle->numberOfDaughters();
153  if (!npart) {return 0;}
154 
155  for (unsigned int i=0;i<npart;++i){
156  unsigned int idx = partIdx(p,dynamic_cast<const reco::GenParticle*>(particle->daughter(i)));
157  if (invalid[idx])
158  continue;
159  if (isParton((particle->daughter(i)->pdgId()))){
160  return 1;
161  }
162  if (isHadron((particle->daughter(i)->pdgId()))){
163  return -1;
164  }
165  int result = testPartonChildren(invalid,p,dynamic_cast<const reco::GenParticle*>(particle->daughter(i)));
166  if (result) return result;
167  }
168  return 0;
169 }
int i
Definition: DBlmapReader.cc:9
int testPartonChildren(ParticleBitmap &invalid, const ParticleVector &p, const reco::GenParticle *particle) const
double npart
Definition: HydjetWrapper.h:45
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.

Member Data Documentation

std::vector<unsigned int> InputGenJetsParticleSelector::excludeFromResonancePids
private
bool InputGenJetsParticleSelector::excludeResonances
private
std::vector<unsigned int> InputGenJetsParticleSelector::ignoreParticleIDs
private
edm::InputTag InputGenJetsParticleSelector::inTag
private

Definition at line 78 of file InputGenJetsParticleSelector.h.

Referenced by produce().

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().