13 addRadiation_(cfg.getParameter<bool>(
"addRadiation")),
14 showerModel_ (kStart),
22 else if(mode==
"kStable")
25 throw cms::Exception(
"Configuration") << mode <<
" is not a supported FillMode!\n";
33 throw cms::Exception(
"Configuration") << mode <<
" is not a supported RunMode!\n";
38 produces<reco::GenParticleCollection>();
63 std::vector<const reco::GenParticle*> tops;
92 std::vector<const reco::GenParticle*> decaying_tops =
findDecayingTops(*src);
105 std::vector<const reco::GenParticle*>
108 std::vector<const reco::GenParticle*> tops;
109 for(reco::GenParticleCollection::const_iterator
t=parts.begin();
t!=parts.end(); ++
t){
111 tops.push_back( &(*
t) );
120 std::vector<const reco::GenParticle*> tops;
121 for (reco::GenParticleCollection::const_iterator
t = parts.begin();
122 t != parts.end(); ++
t) {
126 bool hasTopMother =
false;
127 for (
unsigned idx = 0;
idx <
t->numberOfMothers(); ++
idx) {
134 tops.push_back(&(*
t));
144 std::vector<const reco::GenParticle*> tops;
145 for (reco::GenParticleCollection::const_iterator
t = parts.begin();
146 t != parts.end(); ++
t) {
150 bool hasTopDaughter =
false;
151 for (
unsigned idx = 0;
idx <
t->numberOfDaughters(); ++
idx) {
153 hasTopDaughter =
true;
158 tops.push_back(&(*
t));
168 unsigned int w_index = 0;
193 bool containsItself =
false;
194 unsigned int d_idx = 0;
197 containsItself =
true;
221 for(std::vector<const reco::GenParticle*>::const_iterator it=tops.begin(); it!=tops.end(); ++it){
234 bool containsWBoson=
false, containsQuarkDaughter=
false;
239 if(containsQuarkDaughter && containsWBoson)
246 <<
" Failed to find top quarks in decay chain. Will assume that this a \n" 247 <<
" non-top sample and produce an empty decaySubset.\n";
250 " Can not find back any of the supported hadronization models. Models \n" 251 " which are supported are: \n" 252 " Pythia LO(+PS): Top(status 3) --> WBoson(status 3), Quark(status 3)\n" 253 " Herwig NLO(+PS): Top(status 2) --> Top(status 3) --> Top(status 2) \n");
264 if (genEvtInfoProduct.
isValid()) {
266 genEvtInfoProduct.
id());
271 if (moduleName.find(
"Pythia6") != std::string::npos)
273 else if (moduleName.find(
"Pythia8") != std::string::npos)
275 else if (moduleName.find(
"Herwig6") != std::string::npos)
277 else if (moduleName.find(
"ThePEG") != std::string::npos)
280 else if (moduleName.find(
"Sherpa") != std::string::npos)
290 unsigned nTops = tops.size();
291 for(std::vector<const reco::GenParticle*>::iterator it=tops.begin(); it!=tops.end();) {
293 bool isContained=
false;
294 bool expectedStatus=
false;
297 "showerModel_!=kPythia && top->begin()==top->end()\n");
309 if(!expectedStatus) {
313 <<
" W boson does not have the expected status. This happens, e.g., \n" 314 <<
" with MC@NLO in the case of additional ttbar pairs from radiated \n" 315 <<
" gluons. We hope everything is fine, remove the correspdonding top \n" 316 <<
" quark from our list since it is not part of the primary ttbar pair \n" 317 <<
" and try to continue. \n";
322 if(tops.size()==0 && nTops!=0)
324 " Did not find a W boson with appropriate status for any of the top \n" 325 " quarks in this event. This means that the hadronization of the W \n" 326 " boson might be screwed up or there is another problem with the \n" 327 " particle listing in this MC sample. Please contact an expert. \n");
334 unsigned int statusFlag;
339 for(std::vector<const reco::GenParticle*>::const_iterator it=tops.begin(); it!=tops.end(); ++it){
343 target.push_back( *topPtr );
347 std::vector<int> topDaughters;
351 std::vector<int> wDaughters;
355 "showerModel_!=kPythia && t->begin()==t->end()\n");
360 std::unique_ptr<reco::GenParticle> bPtr(
new reco::GenParticle( td->threeCharge(),
p4( td, statusFlag ), td->vertex(), td->pdgId(), statusFlag,
false ) );
361 target.push_back( *bPtr );
371 "showerModel_!=kPythia && td->begin()==td->end()\n");
376 target.push_back( *wPtr );
386 "showerModel_!=kPythia && buffer->begin()==buffer->end()\n");
391 std::unique_ptr<reco::GenParticle> qPtr(
new reco::GenParticle( wd->threeCharge(),
p4( wd, statusFlag ), wd->vertex(), wd->pdgId(), statusFlag,
false) );
392 target.push_back( *qPtr );
410 target.push_back( *radPtr );
425 std::unique_ptr<reco::GenParticle> sPtr( cand );
426 target.push_back( *sPtr );
427 if(ts->begin()!=ts->end()){
437 refs_[ iTop ] = topDaughters;
438 refs_[ iW ] = wDaughters;
443 const std::vector<const reco::GenParticle*>& primalTops,
444 const std::vector<const reco::GenParticle*>& decayingTops,
446 std::vector<const reco::GenParticle*>::const_iterator top_start;
447 std::vector<const reco::GenParticle*>::const_iterator top_end;
449 top_start = primalTops.begin();
450 top_end = primalTops.end();
452 top_start = decayingTops.begin();
453 top_end = decayingTops.end();
455 for (std::vector<const reco::GenParticle*>::const_iterator it =
456 top_start; it != top_end; ++it) {
463 target.push_back(*topPtr);
468 std::vector<int> topDaughters;
472 std::vector<int> wDaughters;
477 td != final_top->
end(); ++td) {
483 td->p4(), td->vertex(), td->pdgId(),
484 td->status(),
false));
485 target.push_back(*qPtr);
500 td->p4(), td->vertex(), td->pdgId(),
501 td->status(),
false));
502 target.push_back(*WPtr);
513 wd != decaying_W->
end(); ++wd) {
518 wd->p4(), wd->vertex(),
519 wd->pdgId(), wd->status(),
521 target.push_back(*qPtr);
540 std::unique_ptr<reco::GenParticle> radPtr(
542 td->p4(), td->vertex(), td->pdgId(), td->status(),
false ) );
543 target.push_back( *radPtr );
554 refs_[iTop] = topDaughters;
555 refs_[iW] = wDaughters;
575 vec+=
p4(
p, statusFlag );
588 if( vec.mass()-(*top)->mass()>0 ){
625 vec+=
p4(
p, statusFlag);
644 std::unique_ptr<reco::GenParticle> ptr(
new reco::GenParticle( daughter->threeCharge(), daughter->p4(), daughter->vertex(), daughter->pdgId(), daughter->status(),
false) );
645 target.push_back( *ptr );
646 daughters.push_back( ++idx );
649 if(daughters.size()) {
659 daughter != part->
end(); ++daughter) {
662 if (daughter->pdgId() != part->
pdgId()) {
666 daughter->p4(), daughter->vertex(),
667 daughter->pdgId(), daughter->status(),
669 target.push_back(*ptr);
670 daughters.push_back(++idx);
673 if (daughters.size()) {
685 std::unique_ptr<reco::GenParticle> ptr(
new reco::GenParticle( daughter->threeCharge(), daughter->p4(), daughter->vertex(), daughter->pdgId(), daughter->status(),
false) );
686 target.push_back( *ptr );
688 daughters.push_back( ++idx );
694 if(daughters.size()) {
715 for(reco::GenParticleCollection::iterator
p=sel.begin();
p!=sel.end(); ++
p, ++
idx){
717 std::map<int, std::vector<int> >::const_iterator
daughters=
refs_.find( idx );
718 if( daughters!=
refs_.end() ){
719 for(std::vector<int>::const_iterator daughter = daughters->second.begin();
720 daughter!=daughters->second.end(); ++daughter){
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
void addDaughters(int &idx, const reco::GenParticle::const_iterator part, reco::GenParticleCollection &target, bool recursive=true)
recursively fill vector for all further decay particles of a given particle
ShowerModel checkShowerModel(const std::vector< const reco::GenParticle * > &tops) const
check the decay chain for the used shower model
ShowerModel showerModel_
parton shower mode (filled in checkShowerModel)
virtual void produce(edm::Event &event, const edm::EventSetup &setup)
write output into the event
virtual const Point & vertex() const
vertex position (overwritten by PF...)
void addRadiation(int &idx, const reco::GenParticle::const_iterator part, reco::GenParticleCollection &target)
fill vector including all radiations from quarks originating from W/top
def setup(process, global_tag, zero_tesla=False)
virtual int status() const final
status word
virtual int threeCharge() const =0
electric charge
std::vector< const reco::GenParticle * > findTops(const reco::GenParticleCollection &parts)
find top quarks in list of input particles
void addDaughter(const typename daughters::value_type &)
add a daughter via a reference
void clearReferences()
clear references
virtual int status() const =0
status word
edm::EDGetTokenT< GenEventInfoProduct > genEventInfo_srcToken_
input tag for the genEventInfo source
std::string moduleName(Provenance const &provenance)
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual size_t numberOfMothers() const
number of mothers
virtual int pdgId() const =0
PDG identifier.
const_iterator end() const
last daughter const_iterator
virtual size_t numberOfDaughters() const
number of daughters
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual int pdgId() const final
PDG identifier.
reco::Particle::LorentzVector p4(const std::vector< const reco::GenParticle * >::const_iterator top, int statusFlag)
calculate lorentz vector from input (dedicated to top reconstruction)
void checkWBosons(std::vector< const reco::GenParticle * > &tops) const
check whether W bosons are contained in the original gen particle listing
Abs< T >::type abs(const T &t)
bool addRadiation_
add radiation or not?
ShowerModel
classification of potential shower types
std::vector< const reco::GenParticle * > findDecayingTops(const reco::GenParticleCollection &parts)
edm::EDGetTokenT< reco::GenParticleCollection > srcToken_
input tag for the genParticle source
void fillReferences(const reco::GenParticleRefProd &refProd, reco::GenParticleCollection &target)
fill references for output vector
std::vector< const reco::GenParticle * > findPrimalTops(const reco::GenParticleCollection &parts)
virtual int threeCharge() const final
electric charge
TopDecaySubset(const edm::ParameterSet &cfg)
default constructor
RunMode runMode_
run mode (Run1 || Run2)
std::map< int, std::vector< int > > refs_
management of daughter indices for fillRefs
void fillListing(const std::vector< const reco::GenParticle * > &tops, reco::GenParticleCollection &target)
fill output vector for full decay chain
const_iterator begin() const
first daughter const_iterator
virtual const Point & vertex() const =0
vertex position
~TopDecaySubset()
default destructor
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
virtual size_type numberOfDaughters() const =0
number of daughters
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
const reco::GenParticle * findPrimalW(const reco::GenParticle *top)
const reco::GenParticle * findLastParticleInChain(const reco::GenParticle *p)