CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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::stream::EDProducer<>

Public Member Functions

 HadronAndPartonSelector (const edm::ParameterSet &)
 
 ~HadronAndPartonSelector () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T...>
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T...>
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

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 78 of file HadronAndPartonSelector.cc.

Constructor & Destructor Documentation

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

Definition at line 105 of file HadronAndPartonSelector.cc.

References partonSelector_, and partonSelectorSet_.

106  :
107 
108  srcToken_(mayConsume<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("src"))),
109  particlesToken_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("particles"))),
110  partonMode_(iConfig.getParameter<std::string>("partonMode")),
111  fullChainPhysPartons_(iConfig.getParameter<bool>("fullChainPhysPartons"))
112 
113 {
114  //register your products
115  produces<reco::GenParticleRefVector>("bHadrons");
116  produces<reco::GenParticleRefVector>("cHadrons");
117  produces<reco::GenParticleRefVector>("algorithmicPartons");
118  produces<reco::GenParticleRefVector>("physicsPartons");
119  produces<reco::GenParticleRefVector>("leptons");
120 
121  partonSelectorSet_ = false;
122  partonSelector_ = nullptr;
123 }
const edm::EDGetTokenT< reco::GenParticleCollection > particlesToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::EDGetTokenT< GenEventInfoProduct > srcToken_
HadronAndPartonSelector::~HadronAndPartonSelector ( )
override

Definition at line 125 of file HadronAndPartonSelector.cc.

125  {
126  // do anything here that needs to be done at desctruction time
127  // (e.g. close files, deallocate resources etc.)
128 }

Member Function Documentation

void HadronAndPartonSelector::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 273 of file HadronAndPartonSelector.cc.

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

273  {
274  //The following says we do not know what parameters are allowed so do no validation
275  // Please change this to state exactly what you do use, even if it is no parameters
277  desc.setUnknown();
278  descriptions.addDefault(desc);
279 }
void addDefault(ParameterSetDescription const &psetDescription)
void HadronAndPartonSelector::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 135 of file HadronAndPartonSelector.cc.

References Exception, fullChainPhysPartons_, edm::Event::getByToken(), edm::Event::getStableProvenance(), CandMCTagUtils::hasBottom(), CandMCTagUtils::hasCharm(), mps_fire::i, edm::HandleBase::id(), reco::isElectron(), reco::isMuon(), CandMCTagUtils::isParton(), reco::isTau(), edm::HandleBase::isValid(), HLT_FULL_cff::leptons, edm::moduleName(), convertParamsToOnlineFormat::moduleName, eostools::move(), edm::parameterSet(), particlesToken_, partonMode_, jetFlavourId_cff::partons, partonSelector_, partonSelectorSet_, edm::Event::processHistory(), edm::Event::put(), srcToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

135  {
136  // determine hadronizer type (done only once per job)
137  if (partonMode_ == "Auto") {
138  edm::Handle<GenEventInfoProduct> genEvtInfoProduct;
139  iEvent.getByToken(srcToken_, genEvtInfoProduct);
140 
141  std::string moduleName = "";
142  if (genEvtInfoProduct.isValid()) {
143  const edm::StableProvenance& prov = iEvent.getStableProvenance(genEvtInfoProduct.id());
144  moduleName = edm::moduleName(prov, iEvent.processHistory());
145  if (moduleName == "ExternalGeneratorFilter") {
146  moduleName = edm::parameterSet(prov, iEvent.processHistory()).getParameter<std::string>("@external_type");
147  edm::LogInfo("SpecialModule") << "GEN events are produced by ExternalGeneratorFilter, "
148  << "which is a wrapper of the original module: " << moduleName;
149  }
150  }
151 
152  if (moduleName.find("Pythia6") != std::string::npos)
153  partonMode_ = "Pythia6";
154  else if (moduleName.find("Pythia8") != std::string::npos)
155  partonMode_ = "Pythia8";
156  else if (moduleName.find("Herwig6") != std::string::npos)
157  partonMode_ = "Herwig6";
158  else if (moduleName.find("ThePEG") != std::string::npos)
159  partonMode_ = "Herwig++";
160  else if (moduleName.find("Herwig7") != std::string::npos)
161  partonMode_ = "Herwig++";
162  else if (moduleName.find("Sherpa") != std::string::npos)
163  partonMode_ = "Sherpa";
164  else
165  partonMode_ = "Undefined";
166  }
167 
168  // set the parton selection mode (done only once per job)
169  if (!partonSelectorSet_) {
170  if (partonMode_ == "Undefined")
171  edm::LogWarning("UndefinedPartonMode")
172  << "Could not automatically determine the hadronizer type and set the correct parton selection mode. "
173  "Parton-based jet flavour will not be defined.";
174  else if (partonMode_ == "Pythia6") {
176  edm::LogInfo("PartonModeDefined") << "Using Pythia6 parton selection mode.";
177  } else if (partonMode_ == "Pythia8") {
179  edm::LogInfo("PartonModeDefined") << "Using Pythia8 parton selection mode.";
180  } else if (partonMode_ == "Herwig6") {
182  edm::LogInfo("PartonModeDefined") << "Using Herwig6 parton selection mode.";
183  } else if (partonMode_ == "Herwig++") {
185  edm::LogInfo("PartonModeDefined") << "Using Herwig++ parton selection mode.";
186  } else if (partonMode_ == "Sherpa") {
188  edm::LogInfo("PartonModeDefined") << "Using Sherpa parton selection mode.";
189  } else
190  throw cms::Exception("InvalidPartonMode")
191  << "Parton selection mode is invalid: " << partonMode_
192  << ", use Auto | Pythia6 | Pythia8 | Herwig6 | Herwig++ | Sherpa" << std::endl;
193 
194  partonSelectorSet_ = true;
195  }
196 
198  iEvent.getByToken(particlesToken_, particles);
199 
200  auto bHadrons = std::make_unique<reco::GenParticleRefVector>();
201  auto cHadrons = std::make_unique<reco::GenParticleRefVector>();
202  auto partons = std::make_unique<reco::GenParticleRefVector>();
203  auto physicsPartons = std::make_unique<reco::GenParticleRefVector>();
204  auto leptons = std::make_unique<reco::GenParticleRefVector>();
205 
206  // loop over particles and select b and c hadrons and leptons
207  for (reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it) {
208  // if b hadron
209  if (CandMCTagUtils::hasBottom(*it)) {
210  // check if any of the daughters is also a b hadron
211  bool hasbHadronDaughter = false;
212  for (size_t i = 0; i < it->numberOfDaughters(); ++i) {
213  if (CandMCTagUtils::hasBottom(*(it->daughter(i)))) {
214  hasbHadronDaughter = true;
215  break;
216  }
217  }
218  if (hasbHadronDaughter)
219  continue; // skip excited b hadrons that have other b hadrons as daughters
220 
221  bHadrons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
222  }
223 
224  // if c hadron
225  if (CandMCTagUtils::hasCharm(*it)) {
226  // check if any of the daughters is also a c hadron
227  bool hascHadronDaughter = false;
228  for (size_t i = 0; i < it->numberOfDaughters(); ++i) {
229  if (CandMCTagUtils::hasCharm(*(it->daughter(i)))) {
230  hascHadronDaughter = true;
231  break;
232  }
233  }
234  if (hascHadronDaughter)
235  continue; // skip excited c hadrons that have other c hadrons as daughters
236 
237  cHadrons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
238  }
239 
240  // status==1 electrons and muons
241  if ((reco::isElectron(*it) || reco::isMuon(*it)) && it->status() == 1)
242  leptons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
243 
244  // status==2 taus
245  if (reco::isTau(*it) && it->status() == 2)
246  leptons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
247  }
248 
249  // select algorithmic partons
250  if (partonMode_ != "Undefined") {
251  partonSelector_->run(particles, partons);
252  }
253 
254  // select physics partons
255  for (reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it) {
256  if (!fullChainPhysPartons_) {
257  if (!(it->status() == 3 || ((partonMode_ == "Pythia8") && (it->status() == 23))))
258  continue;
259  }
260  if (!CandMCTagUtils::isParton(*it))
261  continue; // skip particle if not a parton
262  physicsPartons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
263  }
264 
265  iEvent.put(std::move(bHadrons), "bHadrons");
266  iEvent.put(std::move(cHadrons), "cHadrons");
267  iEvent.put(std::move(partons), "algorithmicPartons");
268  iEvent.put(std::move(physicsPartons), "physicsPartons");
269  iEvent.put(std::move(leptons), "leptons");
270 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9
ProductID id() const
Definition: HandleBase.cc:29
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::shared_ptr< BasePartonSelector > PartonSelectorPtr
bool hasCharm(const reco::Candidate &c)
Definition: CandMCTag.cc:35
Herwig++ parton selector derived from the base parton selector.
const edm::EDGetTokenT< reco::GenParticleCollection > particlesToken_
Herwig6 parton selector derived from the base parton selector.
Sherpa parton selector derived from the base parton selector.
bool isElectron(const Candidate &part)
Definition: pdgIdUtils.h:7
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
def move
Definition: eostools.py:511
bool isValid() const
Definition: HandleBase.h:70
Pythia6 parton selector derived from the base parton selector.
Pythia8 parton selector derived from the base parton selector.
Log< level::Info, false > LogInfo
ProcessHistory const & processHistory() const override
Definition: Event.cc:250
bool isParton(const reco::Candidate &c)
Definition: CandMCTag.cc:46
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
Log< level::Warning, false > LogWarning
StableProvenance const & getStableProvenance(BranchID const &theID) const
Definition: Event.cc:124
bool hasBottom(const reco::Candidate &c)
Definition: CandMCTag.cc:24
const edm::EDGetTokenT< GenEventInfoProduct > srcToken_
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:11

Member Data Documentation

bool HadronAndPartonSelector::fullChainPhysPartons_
private

Definition at line 93 of file HadronAndPartonSelector.cc.

Referenced by produce().

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

Definition at line 90 of file HadronAndPartonSelector.cc.

Referenced by produce().

std::string HadronAndPartonSelector::partonMode_
private

Definition at line 92 of file HadronAndPartonSelector.cc.

Referenced by produce().

PartonSelectorPtr HadronAndPartonSelector::partonSelector_
private

Definition at line 95 of file HadronAndPartonSelector.cc.

Referenced by HadronAndPartonSelector(), and produce().

bool HadronAndPartonSelector::partonSelectorSet_
private

Definition at line 94 of file HadronAndPartonSelector.cc.

Referenced by HadronAndPartonSelector(), and produce().

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

Definition at line 89 of file HadronAndPartonSelector.cc.

Referenced by produce().