CMS 3D CMS Logo

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

#include <TtDecayChannelSelector.h>

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 More...
 

Public Member Functions

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

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 More...
 
unsigned int decayChannel () const
 return decay channel to select for from configuration More...
 
bool search (reco::GenParticleCollection::const_iterator &part, int pdgId, std::string &inputType) const
 search for particle with pdgId in given listing (for top) More...
 
bool search (reco::GenParticle::const_iterator &part, int pdgId, std::string &inputType) const
 search for particle with pdgId in given listing (for top daughters) More...
 
bool tauDecay (const reco::Candidate &) const
 check tau decay to be leptonic, 1-prong or 3-prong More...
 

Private Attributes

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

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.

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_.

18  :
19  invert_ ( cfg.getParameter<bool>("invert" ) ),
20  allowElectron_(false), allowMuon_(false), allow1Prong_(false),
21  allow3Prong_(false)
22 {
23  // tau decays are not restricted if this PSet does not exist at all
24  restrictTauDecays_=cfg.existsAs<edm::ParameterSet>("restrictTauDecays");
25  // determine allowed tau decays
27  edm::ParameterSet allowedTauDecays = cfg.getParameter<edm::ParameterSet>("restrictTauDecays");
28  // tau decays are not restricted if none of the following parameters exists
29  restrictTauDecays_=(allowedTauDecays.existsAs<bool>("electron" )||
30  allowedTauDecays.existsAs<bool>("muon" )||
31  allowedTauDecays.existsAs<bool>("oneProng" )||
32  allowedTauDecays.existsAs<bool>("threeProng") );
33  // specify the different possible restrictions of the tau decay channels
34  allowElectron_ = (allowedTauDecays.existsAs<bool>("electron" ) ? allowedTauDecays.getParameter<bool>("electron" ) : false);
35  allowMuon_ = (allowedTauDecays.existsAs<bool>("muon" ) ? allowedTauDecays.getParameter<bool>("muon" ) : false);
36  allow1Prong_ = (allowedTauDecays.existsAs<bool>("oneProng" ) ? allowedTauDecays.getParameter<bool>("oneProng" ) : false);
37  allow3Prong_ = (allowedTauDecays.existsAs<bool>("threeProng") ? allowedTauDecays.getParameter<bool>("threeProng") : false);
38  }
39  // allowed top decays PSet
40  edm::ParameterSet allowedTopDecays = cfg.getParameter<edm::ParameterSet>("allowedTopDecays");
41 
42  // fill decayBranchA_
43  edm::ParameterSet decayBranchA = allowedTopDecays.getParameter<edm::ParameterSet>("decayBranchA");
44  decayBranchA_.push_back(decayBranchA.getParameter<bool>("electron"));
45  decayBranchA_.push_back(decayBranchA.getParameter<bool>("muon" ));
46  decayBranchA_.push_back(decayBranchA.getParameter<bool>("tau" ));
47 
48  // fill decay branchB_
49  edm::ParameterSet decayBranchB = allowedTopDecays.getParameter<edm::ParameterSet>("decayBranchB");
50  decayBranchB_.push_back(decayBranchB.getParameter<bool>("electron"));
51  decayBranchB_.push_back(decayBranchB.getParameter<bool>("muon" ));
52  decayBranchB_.push_back(decayBranchB.getParameter<bool>("tau" ));
53 
54  // fill allowedDecays_
55  for(unsigned int d=0; d<kDecayChannels; ++d){
57  }
58 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
Decay decayBranchA_
top decay branch 1
static const unsigned int kDecayChannels
bool restrictTauDecays_
restrict tau decays
Decay decayBranchB_
top decay branch 2
bool allowElectron_
allow tau decays into electron
bool allow3Prong_
allow 2-prong tau decays
bool allowMuon_
allow tau decays into muon
bool allow1Prong_
allow 1-prong tau decays
bool invert_
invert selection
TtDecayChannelSelector::~TtDecayChannelSelector ( )

default destructor

Definition at line 60 of file TtDecayChannelSelector.cc.

61 {
62 }

Member Function Documentation

unsigned int TtDecayChannelSelector::checkSum ( const Decay vec) const
inlineprivate

Definition at line 76 of file TtDecayChannelSelector.h.

Referenced by operator()().

77 {
78  unsigned int sum=0;
79  for(unsigned int d=0; d<vec.size(); ++d){
80  sum+=vec[d];
81  }
82  return sum;
83 }
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().

195 {
196  // if stable, return 1 or 0
197  if(part.status()==1){
198  return (part.charge()!=0);
199  }
200  // if unstable, call recursively on daughters
201  int prong =0;
202  for(reco::Candidate::const_iterator daughter=part.begin();daughter!=part.end(); ++daughter){
203  prong += countProngs(*daughter);
204  }
205  return prong;
206 }
virtual int status() const =0
status word
virtual const_iterator end() const =0
last daughter const_iterator
virtual int charge() const =0
electric charge
unsigned int countProngs(const reco::Candidate &part) const
count the number of charged particles for tau decays
virtual const_iterator begin() const =0
first daughter const_iterator
unsigned int TtDecayChannelSelector::decayChannel ( ) const
inlineprivate

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()().

64 {
65  unsigned int channel=0;
66  if( std::count(decayBranchA_.begin(), decayBranchA_.end(), 1) > 0 ){
67  ++channel;
68  }
69  if( std::count(decayBranchB_.begin(), decayBranchB_.end(), 1) > 0 ){
70  ++channel;
71  }
72  return channel;
73 }
Decay decayBranchA_
top decay branch 1
Decay decayBranchB_
top decay branch 2
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 funct::abs(), accept(), allowedDecays_, reco::Candidate::begin(), TopDecayID::bID, checkSum(), decayBranchA_, decayBranchB_, decayChannel(), Elec, TopDecayID::elecID, reco::Candidate::end(), invert_, create_public_lumi_plots::log, Muon, TopDecayID::muonID, restrictTauDecays_, search(), Tau, tauDecay(), TopDecayID::tauID, TopDecayID::tID, and TopDecayID::WID.

66 {
67  bool verbose=false; // set this to true for debugging and add TtDecayChannelSelector category to the MessageLogger in your cfg file
68  unsigned int iLep=0;
69  unsigned int iTop=0,iBeauty=0,iElec=0,iMuon=0,iTau=0;
70  for(reco::GenParticleCollection::const_iterator top=parts.begin(); top!=parts.end(); ++top){
71  if( search(top, TopDecayID::tID, inputType) ){
72  ++iTop;
73  for(reco::GenParticle::const_iterator td=top->begin(); td!=top->end(); ++td){
74  if( search(td, TopDecayID::bID, inputType) ){
75  ++iBeauty;
76  }
77  if( search(td, TopDecayID::WID, inputType) ){
78  for(reco::GenParticle::const_iterator wd=td->begin(); wd!=td->end(); ++wd){
79  if( std::abs(wd->pdgId())==TopDecayID::elecID ){
80  ++iElec;
81  }
82  if( std::abs(wd->pdgId())==TopDecayID::muonID ){
83  ++iMuon;
84  }
85  if( std::abs(wd->pdgId())==TopDecayID::tauID ){
87  // count as iTau if it is leptonic, one-prong
88  // or three-prong and ignore increasing iLep
89  // though else
90  if(tauDecay(*wd)){
91  ++iTau;
92  } else{
93  ++iLep;
94  }
95  }
96  else{
97  ++iTau;
98  }
99  }
100  }
101  }
102  }
103  }
104  }
105  if(verbose) {
106  edm::LogVerbatim log("TtDecayChannelSelector");
107  log << "----------------------" << "\n"
108  << " iTop : " << iTop << "\n"
109  << " iBeauty : " << iBeauty << "\n"
110  << " iElec : " << iElec << "\n"
111  << " iMuon : " << iMuon << "\n"
112  << " iTau : " << iTau+iLep;
113  if(restrictTauDecays_ && (iTau+iLep)>0){
114  log << " (" << iTau << ")\n";
115  }
116  else{
117  log << "\n";
118  }
119  log << "- - - - - - - - - - - " << "\n";
120  }
121  iLep+=iElec+iMuon+iTau;
122 
123  bool accept=false;
124  unsigned int channel = decayChannel();
125  if( (iTop==2) && (iBeauty==2) ){
126  if( channel==iLep ){
127  if( channel==0 ){
128  // no lepton: accept without restriction we already
129  // know that the number of leptons is correct
130  accept=true;
131  }
132  if( channel==1 ){
133  // one lepton: check that this one is allowed
134  accept=(iElec&&allowedDecays_[Elec]) || (iMuon&&allowedDecays_[Muon]) || (iTau&&allowedDecays_[Tau]);
135  }
136  if( channel==2 ){
137  if( checkSum(allowedDecays_)==channel ){
138  // no redundancy
139  accept = (allowedDecays_[Elec]==(int)iElec) && (allowedDecays_[Muon]==(int)iMuon) && (allowedDecays_[Tau]==(int)iTau);
140  }
141  else{
142  // reject events with wrong tau decays
143  if(iElec+iMuon+iTau!=channel){
144  accept = false;
145  }
146  else {
147  if((iElec==2)||(iMuon==2)||(iTau==2)) {
148  // same lepton twice: check that this is allowed.
149  accept = (allowedDecays_[Elec]==(int)iElec)||(allowedDecays_[Muon]==(int)iMuon)||(allowedDecays_[Tau]==(int)iTau);
150  }
151  else {
152  // two different leptons: look if there is a possible combination
153  accept = ( ((iElec&&decayBranchA_[Elec])&&((iMuon&&decayBranchB_[Muon])||(iTau &&decayBranchB_[Tau ]))) ||
154  ((iMuon&&decayBranchA_[Muon])&&((iElec&&decayBranchB_[Elec])||(iTau &&decayBranchB_[Tau ]))) ||
155  ((iTau &&decayBranchA_[Tau ])&&((iElec&&decayBranchB_[Elec])||(iMuon&&decayBranchB_[Muon]))) );
156  }
157  }
158  }
159  }
160  }
161  accept=( (!invert_&& accept) || (!(!invert_)&& !accept) );
162  }
163  else{
164  edm::LogWarning ( "NoVtbDecay" ) << "Decay is not via Vtb";
165  }
166  if(verbose)
167  edm::LogVerbatim("TtDecayChannelSelector") << " accept : " << accept;
168  return accept;
169 }
static const int bID
Definition: TopGenEvent.h:14
Decay decayBranchA_
top decay branch 1
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
static const int tID
Definition: TopGenEvent.h:13
bool search(reco::GenParticleCollection::const_iterator &part, int pdgId, std::string &inputType) const
search for particle with pdgId in given listing (for top)
static const int tauID
Definition: TopGenEvent.h:21
virtual const_iterator end() const =0
last daughter const_iterator
bool restrictTauDecays_
restrict tau decays
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Decay decayBranchB_
top decay branch 2
bool tauDecay(const reco::Candidate &) const
check tau decay to be leptonic, 1-prong or 3-prong
static const int muonID
Definition: TopGenEvent.h:20
unsigned int decayChannel() const
return decay channel to select for from configuration
unsigned int checkSum(const Decay &vec) const
static const int WID
Definition: TopGenEvent.h:18
virtual const_iterator begin() const =0
first daughter const_iterator
static const int elecID
Definition: TopGenEvent.h:19
bool invert_
invert selection
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 funct::abs(), kGenParticles, and TopDecayID::unfrag.

Referenced by operator()().

173 {
174  if(inputType==kGenParticles){
175  return (std::abs(part->pdgId())==pdgId && part->status()==TopDecayID::unfrag) ? true : false;
176  }
177  else{
178  return (std::abs(part->pdgId())==pdgId) ? true : false;
179  }
180 }
static const int unfrag
Definition: TopGenEvent.h:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20
static const std::string kGenParticles
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 funct::abs(), kGenParticles, reco::Candidate::pdgId(), reco::Candidate::status(), and TopDecayID::unfrag.

184 {
185  if(inputType==kGenParticles){
186  return (std::abs(part->pdgId())==pdgId && part->status()==TopDecayID::unfrag) ? true : false;
187  }
188  else{
189  return (std::abs(part->pdgId())==pdgId) ? true : false;
190  }
191 }
static const int unfrag
Definition: TopGenEvent.h:12
virtual int status() const =0
status word
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual int pdgId() const =0
PDG identifier.
static const std::string kGenParticles
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 funct::abs(), allow1Prong_, allow3Prong_, allowElectron_, allowMuon_, reco::Candidate::begin(), countProngs(), TopDecayID::elecID, reco::Candidate::end(), TopDecayID::muonID, and reco::Candidate::pdgId().

Referenced by operator()().

210 {
211  bool electronTau = false;
212  bool muonTau = false;
213  unsigned int nch = 0;
214  // loop on tau decays, check for an elec
215  // or muon and count charged particles
216  for(reco::Candidate::const_iterator daughter=tau.begin();daughter!=tau.end(); ++daughter){
217  // if the tau daughter is again a tau, this means that the particle has
218  // still to be propagated; in that case, return the result of the same
219  // method applied on the daughter of the current particle
220  if(daughter->pdgId()==tau.pdgId()){
221  return tauDecay(*daughter);
222  }
223  // check for electron from tau decay
224  electronTau |= (std::abs(daughter->pdgId())==TopDecayID::elecID);
225  // check for muon from tau decay
226  muonTau |= (std::abs(daughter->pdgId())==TopDecayID::muonID);
227  // count charged particles
228  nch += countProngs(*daughter);
229  }
230  return ((allowElectron_ && electronTau) ||
231  (allowMuon_ && muonTau)||
232  (allow1Prong_ && !electronTau && !muonTau && nch==1)||
233  (allow3Prong_ && !electronTau && !muonTau && nch==3));
234 }
virtual const_iterator end() const =0
last daughter const_iterator
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int countProngs(const reco::Candidate &part) const
count the number of charged particles for tau decays
virtual int pdgId() const =0
PDG identifier.
bool allowElectron_
allow tau decays into electron
bool tauDecay(const reco::Candidate &) const
check tau decay to be leptonic, 1-prong or 3-prong
bool allow3Prong_
allow 2-prong tau decays
bool allowMuon_
allow tau decays into muon
static const int muonID
Definition: TopGenEvent.h:20
virtual const_iterator begin() const =0
first daughter const_iterator
static const int elecID
Definition: TopGenEvent.h:19
bool allow1Prong_
allow 1-prong tau decays

Member Data Documentation

bool TtDecayChannelSelector::allow1Prong_
private

allow 1-prong tau decays

Definition at line 50 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

bool TtDecayChannelSelector::allow3Prong_
private

allow 2-prong tau decays

Definition at line 52 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

Decay TtDecayChannelSelector::allowedDecays_
private

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().

bool TtDecayChannelSelector::allowElectron_
private

allow tau decays into electron

Definition at line 46 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

bool TtDecayChannelSelector::allowMuon_
private

allow tau decays into muon

Definition at line 48 of file TtDecayChannelSelector.h.

Referenced by tauDecay(), and TtDecayChannelSelector().

Decay TtDecayChannelSelector::decayBranchA_
private

top decay branch 1

Definition at line 54 of file TtDecayChannelSelector.h.

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

Decay TtDecayChannelSelector::decayBranchB_
private

top decay branch 2

Definition at line 56 of file TtDecayChannelSelector.h.

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

bool TtDecayChannelSelector::invert_
private

invert selection

Definition at line 42 of file TtDecayChannelSelector.h.

Referenced by operator()().

bool TtDecayChannelSelector::restrictTauDecays_
private

restrict tau decays

Definition at line 44 of file TtDecayChannelSelector.h.

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