CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

TtDecayChannelSelector Class Reference

#include <TtDecayChannelSelector.h>

List of all members.

Public Types

enum  { Elec = 0, Muon = 1, Tau = 2 }
 

leafs of leptonic decay channel vector decay_

More...
typedef std::vector< int > Decay
 typedef to simplify the decay vectors

Public Member Functions

bool operator() (const reco::GenParticleCollection &parts, std::string inputType) const
 operator for decay channel selection
 TtDecayChannelSelector (const edm::ParameterSet &)
 std contructor
 ~TtDecayChannelSelector ()
 default destructor

Private Member Functions

unsigned int checkSum (const Decay &vec) const
unsigned int countProngs (const reco::Candidate &part) const
 count the number of charged particles for tau decays
unsigned int decayChannel () const
 return decay channel to select for from configuration
bool search (reco::GenParticle::const_iterator &part, int pdgId, std::string &inputType) const
 search for particle with pdgId in given listing (for top daughters)
bool search (reco::GenParticleCollection::const_iterator &part, int pdgId, std::string &inputType) const
 search for particle with pdgId in given listing (for top)
bool tauDecay (const reco::Candidate &) const
 check tau decay to be leptonic, 1-prong or 3-prong

Private Attributes

bool allow1Prong_
 allow 1-prong tau decays
bool allow3Prong_
 allow 2-prong tau decays
Decay allowedDecays_
bool allowElectron_
 allow tau decays into electron
bool allowMuon_
 allow tau decays into muon
Decay decayBranchA_
 top decay branch 1
Decay decayBranchB_
 top decay branch 2
bool invert_
 invert selection
bool restrictTauDecays_
 restrict tau decays

Detailed Description

Definition at line 8 of file TtDecayChannelSelector.h.


Member Typedef Documentation

typedef std::vector<int> TtDecayChannelSelector::Decay

typedef to simplify the decay vectors

Definition at line 15 of file TtDecayChannelSelector.h.


Member Enumeration Documentation

anonymous enum

leafs of leptonic decay channel vector decay_

Enumerator:
Elec 
Muon 
Tau 

Definition at line 13 of file TtDecayChannelSelector.h.

{Elec=0, Muon=1, Tau =2};

Constructor & Destructor Documentation

TtDecayChannelSelector::TtDecayChannelSelector ( const edm::ParameterSet cfg)

std contructor

Definition at line 18 of file TtDecayChannelSelector.cc.

References allow1Prong_, allow3Prong_, allowedDecays_, allowElectron_, allowMuon_, decayBranchA_, decayBranchB_, edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), kDecayChannels, and restrictTauDecays_.

                                                                        :
  invert_ ( cfg.getParameter<bool>("invert" ) ),
  allowElectron_(false), allowMuon_(false), allow1Prong_(false), 
  allow3Prong_(false)
{
  // tau decays are not restricted if this PSet does not exist at all
  restrictTauDecays_=cfg.existsAs<edm::ParameterSet>("restrictTauDecays");
  // determine allowed tau decays
  if(restrictTauDecays_){
    edm::ParameterSet allowedTauDecays = cfg.getParameter<edm::ParameterSet>("restrictTauDecays");
    // tau decays are not restricted if none of the following parameters exists
    restrictTauDecays_=(allowedTauDecays.existsAs<bool>("electron"  )|| 
                        allowedTauDecays.existsAs<bool>("muon"  )|| 
                        allowedTauDecays.existsAs<bool>("oneProng"  )|| 
                        allowedTauDecays.existsAs<bool>("threeProng") );
    // specify the different possible restrictions of the tau decay channels
    allowElectron_ = (allowedTauDecays.existsAs<bool>("electron"  ) ? allowedTauDecays.getParameter<bool>("electron"  ) : false);
    allowMuon_ = (allowedTauDecays.existsAs<bool>("muon"  ) ? allowedTauDecays.getParameter<bool>("muon"  ) : false);
    allow1Prong_ = (allowedTauDecays.existsAs<bool>("oneProng"  ) ? allowedTauDecays.getParameter<bool>("oneProng"  ) : false); 
    allow3Prong_ = (allowedTauDecays.existsAs<bool>("threeProng") ? allowedTauDecays.getParameter<bool>("threeProng") : false);
  }
  // allowed top decays PSet
  edm::ParameterSet allowedTopDecays = cfg.getParameter<edm::ParameterSet>("allowedTopDecays");

  // fill decayBranchA_
  edm::ParameterSet decayBranchA = allowedTopDecays.getParameter<edm::ParameterSet>("decayBranchA");
  decayBranchA_.push_back(decayBranchA.getParameter<bool>("electron"));
  decayBranchA_.push_back(decayBranchA.getParameter<bool>("muon"    ));
  decayBranchA_.push_back(decayBranchA.getParameter<bool>("tau"     ));

  // fill decay branchB_
  edm::ParameterSet decayBranchB = allowedTopDecays.getParameter<edm::ParameterSet>("decayBranchB");
  decayBranchB_.push_back(decayBranchB.getParameter<bool>("electron"));
  decayBranchB_.push_back(decayBranchB.getParameter<bool>("muon"    ));
  decayBranchB_.push_back(decayBranchB.getParameter<bool>("tau"     ));

  // fill allowedDecays_
  for(unsigned int d=0; d<kDecayChannels; ++d){
    allowedDecays_.push_back(decayBranchA_[d]+decayBranchB_[d]);
  }
}
TtDecayChannelSelector::~TtDecayChannelSelector ( )

default destructor

Definition at line 60 of file TtDecayChannelSelector.cc.

{ 
} 

Member Function Documentation

unsigned int TtDecayChannelSelector::checkSum ( const Decay vec) const [inline, private]

Definition at line 76 of file TtDecayChannelSelector.h.

Referenced by operator()().

{
  unsigned int sum=0;
  for(unsigned int d=0; d<vec.size(); ++d){
    sum+=vec[d];
  }
  return sum;
}
unsigned int TtDecayChannelSelector::countProngs ( const reco::Candidate part) const [private]

count the number of charged particles for tau decays

Definition at line 194 of file TtDecayChannelSelector.cc.

References reco::Candidate::begin(), reco::Candidate::charge(), reco::Candidate::end(), and reco::Candidate::status().

Referenced by tauDecay().

{
  // if stable, return 1 or 0
  if(part.status()==1){
    return (part.charge()!=0);
  }
  // if unstable, call recursively on daughters
  int prong =0;
  for(reco::Candidate::const_iterator daughter=part.begin();daughter!=part.end(); ++daughter){
    prong += countProngs(*daughter);
  }
  return prong;
}
unsigned int TtDecayChannelSelector::decayChannel ( ) const [inline, private]

return decay channel to select for from configuration

Definition at line 63 of file TtDecayChannelSelector.h.

References prof2calltree::count, decayBranchA_, and decayBranchB_.

Referenced by operator()().

{
  unsigned int channel=0;
  if( std::count(decayBranchA_.begin(), decayBranchA_.end(), 1) > 0 ){ 
    ++channel; 
  }
  if( std::count(decayBranchB_.begin(), decayBranchB_.end(), 1) > 0 ){ 
    ++channel; 
  }
  return channel;
}
bool TtDecayChannelSelector::operator() ( const reco::GenParticleCollection parts,
std::string  inputType 
) const

operator for decay channel selection

Definition at line 65 of file TtDecayChannelSelector.cc.

References abs, accept(), allowedDecays_, TopDecayID::bID, checkSum(), decayBranchA_, decayBranchB_, decayChannel(), Elec, TopDecayID::elecID, invert_, funct::log(), Muon, TopDecayID::muonID, restrictTauDecays_, search(), Tau, tauDecay(), TopDecayID::tauID, TopDecayID::tID, and TopDecayID::WID.

{
  bool verbose=false; // set this to true for debugging and add TtDecayChannelSelector category to the MessageLogger in your cfg file
  unsigned int iLep=0;
  unsigned int iTop=0,iBeauty=0,iElec=0,iMuon=0,iTau=0;
  for(reco::GenParticleCollection::const_iterator top=parts.begin(); top!=parts.end(); ++top){
    if( search(top, TopDecayID::tID, inputType) ){
      ++iTop;
      for(reco::GenParticle::const_iterator td=top->begin(); td!=top->end(); ++td){
        if( search(td, TopDecayID::bID, inputType) ){
          ++iBeauty;
        }
        if( search(td, TopDecayID::WID, inputType) ){
          for(reco::GenParticle::const_iterator wd=td->begin(); wd!=td->end(); ++wd){
            if( std::abs(wd->pdgId())==TopDecayID::elecID ){
              ++iElec;
            }
            if( std::abs(wd->pdgId())==TopDecayID::muonID ){
              ++iMuon;
            }
            if( std::abs(wd->pdgId())==TopDecayID::tauID  ){ 
              if(restrictTauDecays_){
                // count as iTau if it is leptonic, one-prong
                // or three-prong and ignore increasing iLep
                // though else
                if(tauDecay(*wd)){
                  ++iTau; 
                } else{
                  ++iLep; 
                }
              }
              else{
                ++iTau;
              }
            }
          }
        }
      }
    }
  }
  if(verbose) {
    edm::LogVerbatim log("TtDecayChannelSelector");
    log << "----------------------"   << "\n"
        << " iTop    : " << iTop      << "\n"
        << " iBeauty : " << iBeauty   << "\n"
        << " iElec   : " << iElec     << "\n"
        << " iMuon   : " << iMuon     << "\n"
        << " iTau    : " << iTau+iLep;
    if(restrictTauDecays_ && (iTau+iLep)>0){
      log << " (" << iTau << ")\n";
    }
    else{
      log << "\n";
    }
    log << "- - - - - - - - - - - "   << "\n";
  }
  iLep+=iElec+iMuon+iTau;

  bool accept=false;
  unsigned int channel = decayChannel();
  if( (iTop==2) && (iBeauty==2) ){
    if( channel==iLep ){
      if( channel==0 ){
        // no lepton: accept without restriction we already 
        // know that the number of leptons is correct
        accept=true;
      }
      if( channel==1 ){
        // one lepton: check that this one is allowed
        accept=(iElec&&allowedDecays_[Elec]) || (iMuon&&allowedDecays_[Muon]) || (iTau&&allowedDecays_[Tau]);
      }
      if( channel==2 ){
        if( checkSum(allowedDecays_)==channel ){
          // no redundancy
          accept = (allowedDecays_[Elec]==(int)iElec) && (allowedDecays_[Muon]==(int)iMuon) && (allowedDecays_[Tau]==(int)iTau);
        }
        else{
          // reject events with wrong tau decays
          if(iElec+iMuon+iTau!=channel){
            accept = false;
          }
          else {
            if((iElec==2)||(iMuon==2)||(iTau==2)) {
              // same lepton twice: check that this is allowed.
              accept = (allowedDecays_[Elec]==(int)iElec)||(allowedDecays_[Muon]==(int)iMuon)||(allowedDecays_[Tau]==(int)iTau);
            } 
            else {
              // two different leptons: look if there is a possible combination
              accept = ( ((iElec&&decayBranchA_[Elec])&&((iMuon&&decayBranchB_[Muon])||(iTau &&decayBranchB_[Tau ]))) ||
                         ((iMuon&&decayBranchA_[Muon])&&((iElec&&decayBranchB_[Elec])||(iTau &&decayBranchB_[Tau ]))) ||
                         ((iTau &&decayBranchA_[Tau ])&&((iElec&&decayBranchB_[Elec])||(iMuon&&decayBranchB_[Muon])))   );
            }
          }
        }
      }
    }
    accept=( (!invert_&& accept) || (!(!invert_)&& !accept) );
  }
  else{
    edm::LogWarning ( "NoVtbDecay" ) << "Decay is not via Vtb";
  }
  if(verbose)
    edm::LogVerbatim("TtDecayChannelSelector") << " accept  : " << accept;
  return accept;
}
bool TtDecayChannelSelector::search ( reco::GenParticleCollection::const_iterator &  part,
int  pdgId,
std::string &  inputType 
) const [private]

search for particle with pdgId in given listing (for top)

Definition at line 172 of file TtDecayChannelSelector.cc.

References abs, kGenParticles, and TopDecayID::unfrag.

Referenced by operator()().

{
  if(inputType==kGenParticles){
    return (std::abs(part->pdgId())==pdgId && part->status()==TopDecayID::unfrag) ? true : false;
  }
  else{
    return (std::abs(part->pdgId())==pdgId) ? true : false;
  }
}
bool TtDecayChannelSelector::search ( reco::GenParticle::const_iterator part,
int  pdgId,
std::string &  inputType 
) const [private]

search for particle with pdgId in given listing (for top daughters)

Definition at line 183 of file TtDecayChannelSelector.cc.

References abs, kGenParticles, and TopDecayID::unfrag.

{
  if(inputType==kGenParticles){
    return (std::abs(part->pdgId())==pdgId && part->status()==TopDecayID::unfrag) ? true : false;
  }
  else{
    return (std::abs(part->pdgId())==pdgId) ? true : false;
  }
}
bool TtDecayChannelSelector::tauDecay ( const reco::Candidate tau) const [private]

check tau decay to be leptonic, 1-prong or 3-prong

Definition at line 209 of file TtDecayChannelSelector.cc.

References abs, allow1Prong_, allow3Prong_, allowElectron_, allowMuon_, reco::Candidate::begin(), countProngs(), TopDecayID::elecID, reco::Candidate::end(), TopDecayID::muonID, and reco::Candidate::pdgId().

Referenced by operator()().

{
  bool electronTau = false;
  bool muonTau = false;
  unsigned int nch = 0;
  // loop on tau decays, check for an elec
  // or muon and count charged particles
  for(reco::Candidate::const_iterator daughter=tau.begin();daughter!=tau.end(); ++daughter){
    // if the tau daughter is again a tau, this means that the particle has 
    // still to be propagated; in that case, return the result of the same 
    // method applied on the daughter of the current particle
    if(daughter->pdgId()==tau.pdgId()){
      return tauDecay(*daughter);
    }
    // check for electron from tau decay
    electronTau |= (std::abs(daughter->pdgId())==TopDecayID::elecID);
    // check for muon from tau decay
    muonTau |= (std::abs(daughter->pdgId())==TopDecayID::muonID);
    // count charged particles
    nch += countProngs(*daughter);
  }
  return ((allowElectron_ &&  electronTau)          ||
          (allowMuon_ && muonTau)||
          (allow1Prong_ && !electronTau && !muonTau && nch==1)||
          (allow3Prong_ && !electronTau && !muonTau && nch==3));
}

Member Data Documentation

allow 1-prong tau decays

Definition at line 50 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

allow 2-prong tau decays

Definition at line 52 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

vector of allowed lepton decay channels; values may be 0,1,2 for the entries 'Elec','Muon','Tau'

Definition at line 59 of file TtDecayChannelSelector.h.

Referenced by operator()(), and TtDecayChannelSelector().

allow tau decays into electron

Definition at line 46 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

allow tau decays into muon

Definition at line 48 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

top decay branch 1

Definition at line 54 of file TtDecayChannelSelector.h.

Referenced by decayChannel(), operator()(), and TtDecayChannelSelector().

top decay branch 2

Definition at line 56 of file TtDecayChannelSelector.h.

Referenced by decayChannel(), operator()(), and TtDecayChannelSelector().

invert selection

Definition at line 42 of file TtDecayChannelSelector.h.

Referenced by operator()().

restrict tau decays

Definition at line 44 of file TtDecayChannelSelector.h.

Referenced by operator()(), and TtDecayChannelSelector().