CMS 3D CMS Logo

GenParticlePruner Class Reference

Inheritance diagram for GenParticlePruner:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 GenParticlePruner (const edm::ParameterSet &)

Private Member Functions

void addDaughterRefs (reco::GenParticle &, reco::GenParticleRefProd, const reco::GenParticleRefVector &) const
void addMotherRefs (reco::GenParticle &, reco::GenParticleRefProd, const reco::GenParticleRefVector &) const
void beginJob (const edm::EventSetup &)
void flagDaughters (const reco::GenParticle &, int)
void flagMothers (const reco::GenParticle &, int)
void parse (const std::string &selection, helper::SelectCode &code, std::string &cut) const
void produce (edm::Event &, const edm::EventSetup &)
void recursiveFlagDaughters (size_t, const reco::GenParticleCollection &, int)
void recursiveFlagMothers (size_t, const reco::GenParticleCollection &, int)

Private Attributes

std::vector< intflags_
std::vector< size_t > indices_
int keepOrDropAll_
std::vector< std::pair
< StringCutObjectSelector
< reco::GenParticle >,
helper::SelectCode > > 
select_
std::vector< std::string > selection_
edm::InputTag src_


Detailed Description

Definition at line 21 of file GenParticlePruner.cc.


Constructor & Destructor Documentation

GenParticlePruner::GenParticlePruner ( const edm::ParameterSet cfg  ) 

Definition at line 94 of file GenParticlePruner.cc.

00094                                                             :
00095   src_(cfg.getParameter<InputTag>("src")), keepOrDropAll_(drop),
00096   selection_(cfg.getParameter<vector<string> >("select")) {
00097   using namespace ::helper;
00098   produces<GenParticleCollection>();
00099 }


Member Function Documentation

void GenParticlePruner::addDaughterRefs ( reco::GenParticle newGen,
reco::GenParticleRefProd  outRef,
const reco::GenParticleRefVector daughters 
) const [private]

Definition at line 222 of file GenParticlePruner.cc.

References reco::CompositeRefCandidateT< D >::addDaughter(), edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), flags_, j, edm::Ref< C, T, F >::key(), and edm::RefVector< C, T, F >::size().

Referenced by produce().

00223                                                                                      {
00224   for(GenParticleRefVector::const_iterator j = daughters.begin();
00225       j != daughters.end(); ++j) {
00226     GenParticleRef dau = *j;
00227     int idx = flags_[dau.key()];
00228     if(idx > 0) {
00229       GenParticleRef newDau(outRef, static_cast<size_t>(idx));
00230       newGen.addDaughter(newDau);
00231     } else {
00232       const GenParticleRefVector daus = dau->daughterRefVector();
00233       if(daus.size()>0)
00234         addDaughterRefs(newGen, outRef, daus);
00235     }
00236   }
00237 }

void GenParticlePruner::addMotherRefs ( reco::GenParticle newGen,
reco::GenParticleRefProd  outRef,
const reco::GenParticleRefVector mothers 
) const [private]

Definition at line 239 of file GenParticlePruner.cc.

References reco::CompositeRefCandidateT< D >::addMother(), edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), flags_, j, edm::Ref< C, T, F >::key(), and edm::RefVector< C, T, F >::size().

Referenced by produce().

00240                                                                                  {
00241   for(GenParticleRefVector::const_iterator j = mothers.begin();
00242       j != mothers.end(); ++j) {
00243     GenParticleRef mom = *j;
00244     int idx = flags_[mom.key()];
00245     if(idx > 0) {
00246       GenParticleRef newMom(outRef, static_cast<size_t>(idx));
00247       newGen.addMother(newMom);
00248     } else {
00249       const GenParticleRefVector moms = mom->motherRefVector();
00250       if(moms.size()>0)
00251         addMotherRefs(newGen, outRef, moms);
00252     }
00253   }
00254 }

void GenParticlePruner::beginJob ( const edm::EventSetup es  )  [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 101 of file GenParticlePruner.cc.

References code, edm::errors::Configuration, EgammaValidation_Zee_cff::cut, drop, lat::endl(), Exception, i, keep, keepOrDropAll_, parse(), PdgEntryReplacer::replace(), select_, and selection_.

00101                                                      {
00102   PdgEntryReplacer rep(es);
00103   for(vector<string>::const_iterator i = selection_.begin(); i != selection_.end(); ++i) {
00104     string cut;
00105     ::helper::SelectCode code;
00106     parse(*i, code, cut);
00107     if(code.all_) {
00108       if(i != selection_.begin()) 
00109         throw Exception(errors::Configuration)
00110           << "selections \"keep *\" and \"drop *\" can be used only as first options. Here used in position # " 
00111           << (i - selection_.begin()) + 1 << "\n" << endl;
00112       switch(code.keepOrDrop_) {
00113           case ::helper::SelectCode::kDrop :
00114               keepOrDropAll_ = drop; break;
00115           case ::helper::SelectCode::kKeep :
00116               keepOrDropAll_ = keep; 
00117       };
00118     } else {
00119       cut = rep.replace(cut);
00120       select_.push_back(make_pair(StringCutObjectSelector<GenParticle>(cut), code));
00121     }
00122   }
00123 }

void GenParticlePruner::flagDaughters ( const reco::GenParticle gen,
int  keepOrDrop 
) [private]

Definition at line 125 of file GenParticlePruner.cc.

References edm::RefVector< C, T, F >::begin(), reco::CompositeRefCandidateT< D >::daughterRefVector(), edm::RefVector< C, T, F >::end(), flags_, and i.

Referenced by produce().

00125                                                                                  {
00126   GenParticleRefVector daughters = gen.daughterRefVector();
00127   for(GenParticleRefVector::const_iterator i = daughters.begin(); i != daughters.end(); ++i) 
00128     flags_[i->key()] = keepOrDrop;
00129 }

void GenParticlePruner::flagMothers ( const reco::GenParticle gen,
int  keepOrDrop 
) [private]

Definition at line 131 of file GenParticlePruner.cc.

References edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), flags_, i, and reco::CompositeRefCandidateT< D >::motherRefVector().

Referenced by produce().

00131                                                                                {
00132   GenParticleRefVector mothers = gen.motherRefVector();
00133   for(GenParticleRefVector::const_iterator i = mothers.begin(); i != mothers.end(); ++i) 
00134     flags_[i->key()] = keepOrDrop;
00135 }

void GenParticlePruner::parse ( const std::string &  selection,
helper::SelectCode code,
std::string &  cut 
) const [private]

Referenced by beginJob().

void GenParticlePruner::produce ( edm::Event evt,
const edm::EventSetup  
) [private, virtual]

Implements edm::EDProducer.

Definition at line 155 of file GenParticlePruner.cc.

References addDaughterRefs(), addMotherRefs(), code, counter(), EgammaValidation_Zee_cff::cut, reco::CompositeRefCandidateT< D >::daughterRefVector(), drop, flagDaughters(), flagMothers(), flags_, edm::Event::getByLabel(), edm::Event::getRefBeforePut(), i, index, indices_, j, keep, keepOrDropAll_, WDecay::kNone, reco::CompositeRefCandidateT< D >::motherRefVector(), n, out, p, edm::Event::put(), recursiveFlagDaughters(), recursiveFlagMothers(), EgammaValidation_Zee_cff::sel, select_, HLT_VtxMuL3::src, and src_.

00155                                                              {
00156   using namespace ::helper;
00157   Handle<GenParticleCollection> src;
00158   evt.getByLabel(src_, src);
00159   const size_t n = src->size();
00160   flags_.clear();
00161   flags_.resize(n, keepOrDropAll_);
00162   for(size_t j = 0; j < select_.size(); ++j) { 
00163     const pair<StringCutObjectSelector<GenParticle>, SelectCode> & sel = select_[j];
00164     SelectCode code = sel.second;
00165     const StringCutObjectSelector<GenParticle> & cut = sel.first;
00166     for(size_t i = 0; i < n; ++i) {
00167       const GenParticle & p = (*src)[i];
00168       if(cut(p)) {
00169         int keepOrDrop = keep;
00170         switch(code.keepOrDrop_) {
00171         case SelectCode::kKeep:
00172           keepOrDrop = keep; break;
00173         case SelectCode::kDrop:
00174           keepOrDrop = drop; 
00175         };
00176         flags_[i] = keepOrDrop;
00177         switch(code.daughtersDepth_) {
00178         case SelectCode::kAll : 
00179           recursiveFlagDaughters(i, *src, keepOrDrop); break;
00180         case SelectCode::kFirst :
00181           flagDaughters(p, keepOrDrop); break;
00182         case SelectCode::kNone:
00183           ;
00184         };
00185         switch(code.mothersDepth_) {
00186         case SelectCode::kAll :
00187           recursiveFlagMothers(i, *src, keepOrDrop); break;
00188         case SelectCode::kFirst :
00189           flagMothers(p, keepOrDrop); break;
00190         case SelectCode::kNone:
00191           ;
00192         };
00193       }
00194     }
00195   }
00196   indices_.clear();
00197   int counter = 0;
00198   for(size_t i = 0; i < n; ++i) {
00199     if(flags_[i] == keep) {
00200       indices_.push_back(i);
00201       flags_[i] = counter++;
00202     }
00203   }
00204 
00205   auto_ptr<GenParticleCollection> out(new GenParticleCollection);
00206   GenParticleRefProd outRef = evt.getRefBeforePut<GenParticleCollection>();
00207   out->reserve(counter);
00208   for(vector<size_t>::const_iterator i = indices_.begin(); i != indices_.end(); ++i) {
00209     size_t index = *i;
00210     const GenParticle & gen = (*src)[index];
00211     const Particle & part = gen;
00212     out->push_back(GenParticle(part));
00213     GenParticle & newGen = out->back();
00214     addDaughterRefs(newGen, outRef, gen.daughterRefVector());
00215     addMotherRefs(newGen, outRef, gen.motherRefVector());
00216   }
00217 
00218   evt.put(out);
00219 }

void GenParticlePruner::recursiveFlagDaughters ( size_t  index,
const reco::GenParticleCollection src,
int  keepOrDrop 
) [private]

Definition at line 137 of file GenParticlePruner.cc.

References edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), flags_, and i.

Referenced by produce().

00137                                                                                                                   {
00138   GenParticleRefVector daughters = src[index].daughterRefVector();
00139   for(GenParticleRefVector::const_iterator i = daughters.begin(); i != daughters.end(); ++i) {
00140     index = i->key();
00141     flags_[index] = keepOrDrop;
00142     recursiveFlagDaughters(index, src, keepOrDrop);
00143   }
00144 }

void GenParticlePruner::recursiveFlagMothers ( size_t  index,
const reco::GenParticleCollection src,
int  keepOrDrop 
) [private]

Definition at line 146 of file GenParticlePruner.cc.

References edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), flags_, and i.

Referenced by produce().

00146                                                                                                                 {
00147   GenParticleRefVector mothers = src[index].motherRefVector();
00148   for(GenParticleRefVector::const_iterator i = mothers.begin(); i != mothers.end(); ++i) {
00149     index = i->key();
00150     flags_[index] = keepOrDrop;
00151     recursiveFlagMothers(index, src, keepOrDrop);
00152   }
00153 }


Member Data Documentation

std::vector<int> GenParticlePruner::flags_ [private]

Definition at line 31 of file GenParticlePruner.cc.

Referenced by addDaughterRefs(), addMotherRefs(), flagDaughters(), flagMothers(), produce(), recursiveFlagDaughters(), and recursiveFlagMothers().

std::vector<size_t> GenParticlePruner::indices_ [private]

Definition at line 32 of file GenParticlePruner.cc.

Referenced by produce().

int GenParticlePruner::keepOrDropAll_ [private]

Definition at line 28 of file GenParticlePruner.cc.

Referenced by beginJob(), and produce().

std::vector<std::pair<StringCutObjectSelector<reco::GenParticle>, helper::SelectCode> > GenParticlePruner::select_ [private]

Definition at line 30 of file GenParticlePruner.cc.

Referenced by beginJob(), and produce().

std::vector<std::string> GenParticlePruner::selection_ [private]

Definition at line 29 of file GenParticlePruner.cc.

Referenced by beginJob().

edm::InputTag GenParticlePruner::src_ [private]

Definition at line 27 of file GenParticlePruner.cc.

Referenced by produce().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:21:22 2009 for CMSSW by  doxygen 1.5.4