CMS 3D CMS Logo

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

Selects hadrons and partons from a collection of GenParticles. More...

#include <PhysicsTools/JetMCAlgos/plugins/HadronAndPartonSelector.cc>

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

Public Member Functions

 HadronAndPartonSelector (const edm::ParameterSet &)
 
 ~HadronAndPartonSelector ()
 
- 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
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) 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 void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- 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

virtual void beginJob ()
 
virtual void beginLuminosityBlock (edm::LuminosityBlock &, edm::EventSetup const &)
 
virtual void beginRun (edm::Run &, edm::EventSetup const &)
 
virtual void endJob ()
 
virtual void endLuminosityBlock (edm::LuminosityBlock &, edm::EventSetup const &)
 
virtual void endRun (edm::Run &, edm::EventSetup const &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 

Private Attributes

const edm::EDGetTokenT
< reco::GenParticleCollection
particlesToken_
 
std::string partonMode_
 
PartonSelectorPtr partonSelector_
 
const edm::EDGetTokenT
< GenEventInfoProduct
srcToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- 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

Selects hadrons and partons from a collection of GenParticles.

This producer selects hadrons, partons, and leptons from a collection of GenParticles and stores vectors of EDM references to these particles in the event. The following hadrons are selected:

Older Fortran Monte Carlo generators (Pythia6 and Herwig6) follow the HEPEVT [1] particle status code convention while newer C++ Monte Carlo generators (Pythia8, Herwig++, and Sherpa) follow the HepMC [2] particle status code convention. However, both conventions give considerable freedom in defining the status codes of intermediate particle states. Hence, the parton selection is generator-dependent and is described in each of the parton selectors separately.

Using the provenance information of the GenEventInfoProduct, the producer attempts to automatically determine what generator was used to hadronize events and based on that information decides what parton selection mode to use. It is also possible to enforce any of the supported parton selection modes.

The selected hadrons and partons are finally used by the JetFlavourClustering producer to determine the jet flavour.

The following leptons are selected:

[1] http://cepa.fnal.gov/psm/stdhep/ [2] http://lcgapp.cern.ch/project/simu/HepMC/

Definition at line 79 of file HadronAndPartonSelector.cc.

Constructor & Destructor Documentation

HadronAndPartonSelector::HadronAndPartonSelector ( const edm::ParameterSet iConfig)
explicit

Definition at line 111 of file HadronAndPartonSelector.cc.

111  :
112 
113  srcToken_(mayConsume<GenEventInfoProduct>( iConfig.getParameter<edm::InputTag>("src") )),
114  particlesToken_(consumes<reco::GenParticleCollection>( iConfig.getParameter<edm::InputTag>("particles") )),
115  partonMode_(iConfig.getParameter<std::string>("partonMode"))
116 
117 {
118  //register your products
119  produces<reco::GenParticleRefVector>( "bHadrons" );
120  produces<reco::GenParticleRefVector>( "cHadrons" );
121  produces<reco::GenParticleRefVector>( "algorithmicPartons" );
122  produces<reco::GenParticleRefVector>( "physicsPartons" );
123  produces<reco::GenParticleRefVector>( "leptons" );
124 }
T getParameter(std::string const &) const
const edm::EDGetTokenT< reco::GenParticleCollection > particlesToken_
const edm::EDGetTokenT< GenEventInfoProduct > srcToken_
HadronAndPartonSelector::~HadronAndPartonSelector ( )

Definition at line 127 of file HadronAndPartonSelector.cc.

128 {
129 
130  // do anything here that needs to be done at desctruction time
131  // (e.g. close files, deallocate resources etc.)
132 
133 }

Member Function Documentation

void HadronAndPartonSelector::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 273 of file HadronAndPartonSelector.cc.

274 {
275 }
void HadronAndPartonSelector::beginLuminosityBlock ( edm::LuminosityBlock ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 296 of file HadronAndPartonSelector.cc.

297 {
298 }
void HadronAndPartonSelector::beginRun ( edm::Run ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 284 of file HadronAndPartonSelector.cc.

285 {
286 }
void HadronAndPartonSelector::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 279 of file HadronAndPartonSelector.cc.

279  {
280 }
void HadronAndPartonSelector::endLuminosityBlock ( edm::LuminosityBlock ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 302 of file HadronAndPartonSelector.cc.

303 {
304 }
void HadronAndPartonSelector::endRun ( edm::Run ,
edm::EventSetup const &   
)
privatevirtual

Definition at line 290 of file HadronAndPartonSelector.cc.

291 {
292 }
void HadronAndPartonSelector::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 308 of file HadronAndPartonSelector.cc.

References edm::ConfigurationDescriptions::addDefault(), and edm::ParameterSetDescription::setUnknown().

308  {
309  //The following says we do not know what parameters are allowed so do no validation
310  // Please change this to state exactly what you do use, even if it is no parameters
312  desc.setUnknown();
313  descriptions.addDefault(desc);
314 }
void addDefault(ParameterSetDescription const &psetDescription)
void HadronAndPartonSelector::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 142 of file HadronAndPartonSelector.cc.

References edm::hlt::Exception, edm::Event::getByToken(), edm::Event::getProvenance(), CandMCTagUtils::hasBottom(), CandMCTagUtils::hasCharm(), i, edm::HandleBase::id(), reco::isElectron(), reco::isMuon(), CandMCTagUtils::isParton(), reco::isTau(), edm::HandleBase::isValid(), HLT_25ns14e33_v1_cff::leptons, edm::moduleName(), particlesToken_, partonMode_, partonSelector_, edm::Event::put(), srcToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

143 {
144  // determine hadronizer type (done only once per job)
145  if( partonMode_=="Auto" )
146  {
147  edm::Handle<GenEventInfoProduct> genEvtInfoProduct;
148  iEvent.getByToken(srcToken_, genEvtInfoProduct);
149 
150  std::string moduleName = "";
151  if( genEvtInfoProduct.isValid() ) {
152  const edm::Provenance& prov = iEvent.getProvenance(genEvtInfoProduct.id());
153  moduleName = edm::moduleName(prov);
154  }
155 
156  if( moduleName.find("Pythia6")!=std::string::npos )
157  partonMode_="Pythia6";
158  else if( moduleName.find("Pythia8")!=std::string::npos )
159  partonMode_="Pythia8";
160  else if( moduleName.find("Herwig6")!=std::string::npos )
161  partonMode_="Herwig6";
162  else if( moduleName.find("ThePEG")!=std::string::npos )
163  partonMode_="Herwig++";
164  else if( moduleName.find("Sherpa")!=std::string::npos )
165  partonMode_="Sherpa";
166  else
167  partonMode_="Undefined";
168  }
169 
170  // set the parton selection mode (done only once per job)
171  if( !partonSelector_ )
172  {
173  if ( partonMode_=="Undefined" )
174  edm::LogWarning("UndefinedPartonMode") << "Could not automatically determine the hadronizer type and set the correct parton selection mode. Parton-based jet flavour will not be defined.";
175  else if ( partonMode_=="Pythia6" )
176  {
178  edm::LogInfo("PartonModeDefined") << "Using Pythia6 parton selection mode.";
179  }
180  else if ( partonMode_=="Pythia8" )
181  {
183  edm::LogInfo("PartonModeDefined") << "Using Pythia8 parton selection mode.";
184  }
185  else if ( partonMode_=="Herwig6" )
186  {
188  edm::LogInfo("PartonModeDefined") << "Using Herwig6 parton selection mode.";
189  }
190  else if ( partonMode_=="Herwig++" )
191  {
193  edm::LogInfo("PartonModeDefined") << "Using Herwig++ parton selection mode.";
194  }
195  else if ( partonMode_=="Sherpa" )
196  {
198  edm::LogInfo("PartonModeDefined") << "Using Sherpa parton selection mode.";
199  }
200  else
201  throw cms::Exception("InvalidPartonMode") <<"Parton selection mode is invalid: " << partonMode_ << ", use Auto | Pythia6 | Pythia8 | Herwig6 | Herwig++ | Sherpa" << std::endl;
202  }
203 
205  iEvent.getByToken(particlesToken_, particles);
206 
207  std::auto_ptr<reco::GenParticleRefVector> bHadrons ( new reco::GenParticleRefVector );
208  std::auto_ptr<reco::GenParticleRefVector> cHadrons ( new reco::GenParticleRefVector );
209  std::auto_ptr<reco::GenParticleRefVector> partons ( new reco::GenParticleRefVector );
210  std::auto_ptr<reco::GenParticleRefVector> physicsPartons ( new reco::GenParticleRefVector );
211  std::auto_ptr<reco::GenParticleRefVector> leptons ( new reco::GenParticleRefVector );
212 
213  // loop over particles and select b and c hadrons and leptons
214  for(reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it)
215  {
216  // if b hadron
217  if( CandMCTagUtils::hasBottom( *it ) )
218  {
219  // check if any of the daughters is also a b hadron
220  bool hasbHadronDaughter = false;
221  for(size_t i=0; i < it->numberOfDaughters(); ++i)
222  {
223  if( CandMCTagUtils::hasBottom( *(it->daughter(i)) ) ) { hasbHadronDaughter = true; break; }
224  }
225  if( hasbHadronDaughter ) continue; // skip excited b hadrons that have other b hadrons as daughters
226 
227  bHadrons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
228  }
229 
230  // if c hadron
231  if( CandMCTagUtils::hasCharm( *it ) )
232  {
233  // check if any of the daughters is also a c hadron
234  bool hascHadronDaughter = false;
235  for(size_t i=0; i < it->numberOfDaughters(); ++i)
236  {
237  if( CandMCTagUtils::hasCharm( *(it->daughter(i)) ) ) { hascHadronDaughter = true; break; }
238  }
239  if( hascHadronDaughter ) continue; // skip excited c hadrons that have other c hadrons as daughters
240 
241  cHadrons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
242  }
243 
244  // status==1 electrons and muons
245  if( ( reco::isElectron( *it ) || reco::isMuon( *it ) ) && it->status()==1 )
246  leptons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
247 
248  // status==2 taus
249  if( reco::isTau( *it ) && it->status()==2 )
250  leptons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
251  }
252 
253  // select partons
254  if ( partonMode_!="Undefined" ) {
255  partonSelector_->run(particles,partons);
256  for(reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it)
257  {
258  if( !(it->status()==3 || (( partonMode_=="Pythia8" ) && (it->status()==23)))) continue;
259  if( !CandMCTagUtils::isParton( *it ) ) continue; // skip particle if not a parton
260  physicsPartons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
261  }
262  }
263 
264  iEvent.put( bHadrons, "bHadrons" );
265  iEvent.put( cHadrons, "cHadrons" );
266  iEvent.put( partons, "algorithmicPartons" );
267  iEvent.put( physicsPartons, "physicsPartons" );
268  iEvent.put( leptons, "leptons" );
269 }
int i
Definition: DBlmapReader.cc:9
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
bool hasCharm(const reco::Candidate &c)
Definition: CandMCTag.cc:37
Herwig++ parton selector derived from the base parton selector.
const edm::EDGetTokenT< reco::GenParticleCollection > particlesToken_
Herwig6 parton selector derived from the base parton selector.
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
Sherpa parton selector derived from the base parton selector.
bool isElectron(const Candidate &part)
Definition: pdgIdUtils.h:7
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool isValid() const
Definition: HandleBase.h:75
boost::shared_ptr< BasePartonSelector > PartonSelectorPtr
Pythia6 parton selector derived from the base parton selector.
Pythia8 parton selector derived from the base parton selector.
bool isParton(const reco::Candidate &c)
Definition: CandMCTag.cc:48
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:73
bool hasBottom(const reco::Candidate &c)
Definition: CandMCTag.cc:26
const edm::EDGetTokenT< GenEventInfoProduct > srcToken_
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:15

Member Data Documentation

const edm::EDGetTokenT<reco::GenParticleCollection> HadronAndPartonSelector::particlesToken_
private

Definition at line 98 of file HadronAndPartonSelector.cc.

Referenced by produce().

std::string HadronAndPartonSelector::partonMode_
private

Definition at line 100 of file HadronAndPartonSelector.cc.

Referenced by produce().

PartonSelectorPtr HadronAndPartonSelector::partonSelector_
private

Definition at line 101 of file HadronAndPartonSelector.cc.

Referenced by produce().

const edm::EDGetTokenT<GenEventInfoProduct> HadronAndPartonSelector::srcToken_
private

Definition at line 97 of file HadronAndPartonSelector.cc.

Referenced by produce().