CMS 3D CMS Logo

HadronAndPartonSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HadronAndPartonSelector
4 // Class: HadronAndPartonSelector
5 //
37 //
38 // Original Author: Dinko Ferencek
39 // Created: Tue Nov 5 22:43:43 CET 2013
40 //
41 //
42 
43 // system include files
44 #include <memory>
45 
46 // user include files
49 
52 
54 
68 
69 //
70 // constants, enums and typedefs
71 //
72 typedef std::shared_ptr<BasePartonSelector> PartonSelectorPtr;
73 
74 //
75 // class declaration
76 //
77 
79 public:
81  ~HadronAndPartonSelector() override;
82 
83  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
84 
85 private:
86  void produce(edm::Event&, const edm::EventSetup&) override;
87 
88  // ----------member data ---------------------------
89  const edm::EDGetTokenT<GenEventInfoProduct> srcToken_; // To get handronizer module type
90  const edm::EDGetTokenT<reco::GenParticleCollection> particlesToken_; // Input GenParticle collection
91 
92  std::string partonMode_; // Parton selection mode
96 };
97 
98 //
99 // static data member definitions
100 //
101 
102 //
103 // constructors and destructor
104 //
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 }
124 
126  // do anything here that needs to be done at desctruction time
127  // (e.g. close files, deallocate resources etc.)
128 }
129 
130 //
131 // member functions
132 //
133 
134 // ------------ method called to produce the data ------------
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  }
146 
147  if (moduleName.find("Pythia6") != std::string::npos)
148  partonMode_ = "Pythia6";
149  else if (moduleName.find("Pythia8") != std::string::npos)
150  partonMode_ = "Pythia8";
151  else if (moduleName.find("Herwig6") != std::string::npos)
152  partonMode_ = "Herwig6";
153  else if (moduleName.find("ThePEG") != std::string::npos)
154  partonMode_ = "Herwig++";
155  else if (moduleName.find("Herwig7") != std::string::npos)
156  partonMode_ = "Herwig++";
157  else if (moduleName.find("Sherpa") != std::string::npos)
158  partonMode_ = "Sherpa";
159  else
160  partonMode_ = "Undefined";
161  }
162 
163  // set the parton selection mode (done only once per job)
164  if (!partonSelectorSet_) {
165  if (partonMode_ == "Undefined")
166  edm::LogWarning("UndefinedPartonMode")
167  << "Could not automatically determine the hadronizer type and set the correct parton selection mode. "
168  "Parton-based jet flavour will not be defined.";
169  else if (partonMode_ == "Pythia6") {
171  edm::LogInfo("PartonModeDefined") << "Using Pythia6 parton selection mode.";
172  } else if (partonMode_ == "Pythia8") {
174  edm::LogInfo("PartonModeDefined") << "Using Pythia8 parton selection mode.";
175  } else if (partonMode_ == "Herwig6") {
177  edm::LogInfo("PartonModeDefined") << "Using Herwig6 parton selection mode.";
178  } else if (partonMode_ == "Herwig++") {
180  edm::LogInfo("PartonModeDefined") << "Using Herwig++ parton selection mode.";
181  } else if (partonMode_ == "Sherpa") {
183  edm::LogInfo("PartonModeDefined") << "Using Sherpa parton selection mode.";
184  } else
185  throw cms::Exception("InvalidPartonMode")
186  << "Parton selection mode is invalid: " << partonMode_
187  << ", use Auto | Pythia6 | Pythia8 | Herwig6 | Herwig++ | Sherpa" << std::endl;
188 
189  partonSelectorSet_ = true;
190  }
191 
193  iEvent.getByToken(particlesToken_, particles);
194 
195  auto bHadrons = std::make_unique<reco::GenParticleRefVector>();
196  auto cHadrons = std::make_unique<reco::GenParticleRefVector>();
197  auto partons = std::make_unique<reco::GenParticleRefVector>();
198  auto physicsPartons = std::make_unique<reco::GenParticleRefVector>();
199  auto leptons = std::make_unique<reco::GenParticleRefVector>();
200 
201  // loop over particles and select b and c hadrons and leptons
202  for (reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it) {
203  // if b hadron
204  if (CandMCTagUtils::hasBottom(*it)) {
205  // check if any of the daughters is also a b hadron
206  bool hasbHadronDaughter = false;
207  for (size_t i = 0; i < it->numberOfDaughters(); ++i) {
208  if (CandMCTagUtils::hasBottom(*(it->daughter(i)))) {
209  hasbHadronDaughter = true;
210  break;
211  }
212  }
213  if (hasbHadronDaughter)
214  continue; // skip excited b hadrons that have other b hadrons as daughters
215 
216  bHadrons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
217  }
218 
219  // if c hadron
220  if (CandMCTagUtils::hasCharm(*it)) {
221  // check if any of the daughters is also a c hadron
222  bool hascHadronDaughter = false;
223  for (size_t i = 0; i < it->numberOfDaughters(); ++i) {
224  if (CandMCTagUtils::hasCharm(*(it->daughter(i)))) {
225  hascHadronDaughter = true;
226  break;
227  }
228  }
229  if (hascHadronDaughter)
230  continue; // skip excited c hadrons that have other c hadrons as daughters
231 
232  cHadrons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
233  }
234 
235  // status==1 electrons and muons
236  if ((reco::isElectron(*it) || reco::isMuon(*it)) && it->status() == 1)
237  leptons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
238 
239  // status==2 taus
240  if (reco::isTau(*it) && it->status() == 2)
241  leptons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
242  }
243 
244  // select algorithmic partons
245  if (partonMode_ != "Undefined") {
247  }
248 
249  // select physics partons
250  for (reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it) {
251  if (!fullChainPhysPartons_) {
252  if (!(it->status() == 3 || ((partonMode_ == "Pythia8") && (it->status() == 23))))
253  continue;
254  }
255  if (!CandMCTagUtils::isParton(*it))
256  continue; // skip particle if not a parton
257  physicsPartons->push_back(reco::GenParticleRef(particles, it - particles->begin()));
258  }
259 
260  iEvent.put(std::move(bHadrons), "bHadrons");
261  iEvent.put(std::move(cHadrons), "cHadrons");
262  iEvent.put(std::move(partons), "algorithmicPartons");
263  iEvent.put(std::move(physicsPartons), "physicsPartons");
264  iEvent.put(std::move(leptons), "leptons");
265 }
266 
267 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
269  //The following says we do not know what parameters are allowed so do no validation
270  // Please change this to state exactly what you do use, even if it is no parameters
272  desc.setUnknown();
273  descriptions.addDefault(desc);
274 }
275 
276 //define this as a plug-in
GenEventInfoProduct
Definition: GenEventInfoProduct.h:17
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
Pythia8PartonSelector.h
HerwigppPartonSelector
Herwig++ parton selector derived from the base parton selector.
Definition: HerwigppPartonSelector.h:10
reco::isElectron
bool isElectron(const Candidate &part)
Definition: pdgIdUtils.h:7
HLT_FULL_cff.leptons
leptons
Definition: HLT_FULL_cff.py:26277
CandMCTag.h
HadronAndPartonSelector::partonSelector_
PartonSelectorPtr partonSelector_
Definition: HadronAndPartonSelector.cc:95
edm::EDGetTokenT< GenEventInfoProduct >
CandMCTagUtils::hasBottom
bool hasBottom(const reco::Candidate &c)
Definition: CandMCTag.cc:24
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
edm::moduleName
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
HadronAndPartonSelector::partonSelectorSet_
bool partonSelectorSet_
Definition: HadronAndPartonSelector.cc:94
CandMCTagUtils::isParton
bool isParton(const reco::Candidate &c)
Definition: CandMCTag.cc:46
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
HadronAndPartonSelector::fullChainPhysPartons_
bool fullChainPhysPartons_
Definition: HadronAndPartonSelector.cc:93
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
edm::Ref< GenParticleCollection >
GenParticle.h
HadronAndPartonSelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HadronAndPartonSelector.cc:135
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Pythia6PartonSelector.h
GenParticleFwd.h
dqmAnalyzer_cff.partons
partons
Definition: dqmAnalyzer_cff.py:27
Herwig6PartonSelector.h
HadronAndPartonSelector::particlesToken_
const edm::EDGetTokenT< reco::GenParticleCollection > particlesToken_
Definition: HadronAndPartonSelector.cc:90
HadronAndPartonSelector
Selects hadrons and partons from a collection of GenParticles.
Definition: HadronAndPartonSelector.cc:78
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SherpaPartonSelector.h
edm::ParameterSet
Definition: ParameterSet.h:47
Herwig6PartonSelector
Herwig6 parton selector derived from the base parton selector.
Definition: Herwig6PartonSelector.h:10
HadronAndPartonSelector::~HadronAndPartonSelector
~HadronAndPartonSelector() override
Definition: HadronAndPartonSelector.cc:125
GenEventInfoProduct.h
Event.h
edm::StableProvenance
Definition: StableProvenance.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
EcalCalibMonitorClient_cfi.moduleName
moduleName
Definition: EcalCalibMonitorClient_cfi.py:17
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
pdgIdUtils.h
HadronAndPartonSelector::partonMode_
std::string partonMode_
Definition: HadronAndPartonSelector.cc:92
PartonSelectorPtr
std::shared_ptr< BasePartonSelector > PartonSelectorPtr
Definition: HadronAndPartonSelector.cc:72
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
AK4GenJetFlavourInfos_cfi.cHadrons
cHadrons
Definition: AK4GenJetFlavourInfos_cfi.py:7
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HadronAndPartonSelector::HadronAndPartonSelector
HadronAndPartonSelector(const edm::ParameterSet &)
Definition: HadronAndPartonSelector.cc:105
CandMCTagUtils::hasCharm
bool hasCharm(const reco::Candidate &c)
Definition: CandMCTag.cc:35
Pythia8PartonSelector
Pythia8 parton selector derived from the base parton selector.
Definition: Pythia8PartonSelector.h:10
Pythia6PartonSelector
Pythia6 parton selector derived from the base parton selector.
Definition: Pythia6PartonSelector.h:10
BasePartonSelector.h
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
Provenance.h
AK4GenJetFlavourInfos_cfi.bHadrons
bHadrons
Definition: AK4GenJetFlavourInfos_cfi.py:6
HadronAndPartonSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HadronAndPartonSelector.cc:268
reco::isTau
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:11
Candidate.h
ParameterSet.h
HerwigppPartonSelector.h
HadronAndPartonSelector::srcToken_
const edm::EDGetTokenT< GenEventInfoProduct > srcToken_
Definition: HadronAndPartonSelector.cc:89
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:29
SherpaPartonSelector
Sherpa parton selector derived from the base parton selector.
Definition: SherpaPartonSelector.h:10
reco::isMuon
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9