CMS 3D CMS Logo

TtDecayChannelSelector.cc
Go to the documentation of this file.
6 
7 // static const string for status check in
8 // TtDecayChannelSelector::search functions
9 static const std::string kGenParticles = "genParticles";
10 
11 // maximal number of possible leptonic decay
12 // channels
13 static const unsigned int kDecayChannels = 3;
14 
15 
17  invert_ ( cfg.getParameter<bool>("invert" ) ),
18  allowElectron_(false), allowMuon_(false), allow1Prong_(false),
19  allow3Prong_(false)
20 {
21  // tau decays are not restricted if this PSet does not exist at all
22  restrictTauDecays_=cfg.existsAs<edm::ParameterSet>("restrictTauDecays");
23  // determine allowed tau decays
25  edm::ParameterSet allowedTauDecays = cfg.getParameter<edm::ParameterSet>("restrictTauDecays");
26  // tau decays are not restricted if none of the following parameters exists
27  restrictTauDecays_=(allowedTauDecays.existsAs<bool>("electron" )||
28  allowedTauDecays.existsAs<bool>("muon" )||
29  allowedTauDecays.existsAs<bool>("oneProng" )||
30  allowedTauDecays.existsAs<bool>("threeProng") );
31  // specify the different possible restrictions of the tau decay channels
32  allowElectron_ = (allowedTauDecays.existsAs<bool>("electron" ) ? allowedTauDecays.getParameter<bool>("electron" ) : false);
33  allowMuon_ = (allowedTauDecays.existsAs<bool>("muon" ) ? allowedTauDecays.getParameter<bool>("muon" ) : false);
34  allow1Prong_ = (allowedTauDecays.existsAs<bool>("oneProng" ) ? allowedTauDecays.getParameter<bool>("oneProng" ) : false);
35  allow3Prong_ = (allowedTauDecays.existsAs<bool>("threeProng") ? allowedTauDecays.getParameter<bool>("threeProng") : false);
36  }
37  // allowed top decays PSet
39 
40  // fill decayBranchA_
41  edm::ParameterSet decayBranchA = allowedTopDecays.getParameter<edm::ParameterSet>("decayBranchA");
42  decayBranchA_.push_back(decayBranchA.getParameter<bool>("electron"));
43  decayBranchA_.push_back(decayBranchA.getParameter<bool>("muon" ));
44  decayBranchA_.push_back(decayBranchA.getParameter<bool>("tau" ));
45 
46  // fill decay branchB_
47  edm::ParameterSet decayBranchB = allowedTopDecays.getParameter<edm::ParameterSet>("decayBranchB");
48  decayBranchB_.push_back(decayBranchB.getParameter<bool>("electron"));
49  decayBranchB_.push_back(decayBranchB.getParameter<bool>("muon" ));
50  decayBranchB_.push_back(decayBranchB.getParameter<bool>("tau" ));
51 
52  // fill allowedDecays_
53  for(unsigned int d=0; d<kDecayChannels; ++d){
55  }
56 }
57 
59 {
60 }
61 
62 bool
64 {
65  bool verbose=false; // set this to true for debugging and add TtDecayChannelSelector category to the MessageLogger in your cfg file
66  unsigned int iLep=0;
67  unsigned int iTop=0,iBeauty=0,iElec=0,iMuon=0,iTau=0;
68  for(reco::GenParticleCollection::const_iterator top=parts.begin(); top!=parts.end(); ++top){
69  if( search(top, TopDecayID::tID, inputType) ){
70  ++iTop;
71  for(reco::GenParticle::const_iterator td=top->begin(); td!=top->end(); ++td){
72  if( search(td, TopDecayID::bID, inputType) ){
73  ++iBeauty;
74  }
75  if( search(td, TopDecayID::WID, inputType) ){
76  for(reco::GenParticle::const_iterator wd=td->begin(); wd!=td->end(); ++wd){
77  if( std::abs(wd->pdgId())==TopDecayID::elecID ){
78  ++iElec;
79  }
80  if( std::abs(wd->pdgId())==TopDecayID::muonID ){
81  ++iMuon;
82  }
83  if( std::abs(wd->pdgId())==TopDecayID::tauID ){
85  // count as iTau if it is leptonic, one-prong
86  // or three-prong and ignore increasing iLep
87  // though else
88  if(tauDecay(*wd)){
89  ++iTau;
90  } else{
91  ++iLep;
92  }
93  }
94  else{
95  ++iTau;
96  }
97  }
98  }
99  }
100  }
101  }
102  }
103  if(verbose) {
104  edm::LogVerbatim log("TtDecayChannelSelector");
105  log << "----------------------" << "\n"
106  << " iTop : " << iTop << "\n"
107  << " iBeauty : " << iBeauty << "\n"
108  << " iElec : " << iElec << "\n"
109  << " iMuon : " << iMuon << "\n"
110  << " iTau : " << iTau+iLep;
111  if(restrictTauDecays_ && (iTau+iLep)>0){
112  log << " (" << iTau << ")\n";
113  }
114  else{
115  log << "\n";
116  }
117  log << "- - - - - - - - - - - " << "\n";
118  }
119  iLep+=iElec+iMuon+iTau;
120 
121  bool accept=false;
122  unsigned int channel = decayChannel();
123  if( (iTop==2) && (iBeauty==2) ){
124  if( channel==iLep ){
125  if( channel==0 ){
126  // no lepton: accept without restriction we already
127  // know that the number of leptons is correct
128  accept=true;
129  }
130  if( channel==1 ){
131  // one lepton: check that this one is allowed
132  accept=(iElec&&allowedDecays_[Elec]) || (iMuon&&allowedDecays_[Muon]) || (iTau&&allowedDecays_[Tau]);
133  }
134  if( channel==2 ){
135  if( checkSum(allowedDecays_)==channel ){
136  // no redundancy
137  accept = (allowedDecays_[Elec]==(int)iElec) && (allowedDecays_[Muon]==(int)iMuon) && (allowedDecays_[Tau]==(int)iTau);
138  }
139  else{
140  // reject events with wrong tau decays
141  if(iElec+iMuon+iTau!=channel){
142  accept = false;
143  }
144  else {
145  if((iElec==2)||(iMuon==2)||(iTau==2)) {
146  // same lepton twice: check that this is allowed.
147  accept = (allowedDecays_[Elec]==(int)iElec)||(allowedDecays_[Muon]==(int)iMuon)||(allowedDecays_[Tau]==(int)iTau);
148  }
149  else {
150  // two different leptons: look if there is a possible combination
151  accept = ( ((iElec&&decayBranchA_[Elec])&&((iMuon&&decayBranchB_[Muon])||(iTau &&decayBranchB_[Tau ]))) ||
152  ((iMuon&&decayBranchA_[Muon])&&((iElec&&decayBranchB_[Elec])||(iTau &&decayBranchB_[Tau ]))) ||
153  ((iTau &&decayBranchA_[Tau ])&&((iElec&&decayBranchB_[Elec])||(iMuon&&decayBranchB_[Muon]))) );
154  }
155  }
156  }
157  }
158  }
159  accept=( (!invert_&& accept) || (!(!invert_)&& !accept) );
160  }
161  else{
162  edm::LogWarning ( "NoVtbDecay" ) << "Decay is not via Vtb";
163  }
164  if(verbose)
165  edm::LogVerbatim("TtDecayChannelSelector") << " accept : " << accept;
166  return accept;
167 }
168 
169 bool
170 TtDecayChannelSelector::search(reco::GenParticleCollection::const_iterator& part, int pdgId, std::string& inputType) const
171 {
172  if(inputType==kGenParticles){
173  return (std::abs(part->pdgId())==pdgId && part->status()==TopDecayID::unfrag) ? true : false;
174  }
175  else{
176  return (std::abs(part->pdgId())==pdgId) ? true : false;
177  }
178 }
179 
180 bool
182 {
183  if(inputType==kGenParticles){
184  return (std::abs(part->pdgId())==pdgId && part->status()==TopDecayID::unfrag) ? true : false;
185  }
186  else{
187  return (std::abs(part->pdgId())==pdgId) ? true : false;
188  }
189 }
190 
191 unsigned int
193 {
194  // if stable, return 1 or 0
195  if(part.status()==1){
196  return (part.charge()!=0);
197  }
198  // if unstable, call recursively on daughters
199  int prong =0;
200  for(reco::Candidate::const_iterator daughter=part.begin();daughter!=part.end(); ++daughter){
201  prong += countProngs(*daughter);
202  }
203  return prong;
204 }
205 
206 bool
208 {
209  bool electronTau = false;
210  bool muonTau = false;
211  unsigned int nch = 0;
212  // loop on tau decays, check for an elec
213  // or muon and count charged particles
214  for(reco::Candidate::const_iterator daughter=tau.begin();daughter!=tau.end(); ++daughter){
215  // if the tau daughter is again a tau, this means that the particle has
216  // still to be propagated; in that case, return the result of the same
217  // method applied on the daughter of the current particle
218  if(daughter->pdgId()==tau.pdgId()){
219  return tauDecay(*daughter);
220  }
221  // check for electron from tau decay
222  electronTau |= (std::abs(daughter->pdgId())==TopDecayID::elecID);
223  // check for muon from tau decay
224  muonTau |= (std::abs(daughter->pdgId())==TopDecayID::muonID);
225  // count charged particles
226  nch += countProngs(*daughter);
227  }
228  return ((allowElectron_ && electronTau) ||
229  (allowMuon_ && muonTau)||
230  (allow1Prong_ && !electronTau && !muonTau && nch==1)||
231  (allow3Prong_ && !electronTau && !muonTau && nch==3));
232 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
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:161
static const int bID
Definition: TopGenEvent.h:14
static const int unfrag
Definition: TopGenEvent.h:12
Decay decayBranchA_
top decay branch 1
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
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)
virtual int status() const =0
status word
static const int tauID
Definition: TopGenEvent.h:21
static const unsigned int kDecayChannels
Definition: Muon.py:1
bool restrictTauDecays_
restrict tau decays
virtual int pdgId() const =0
PDG identifier.
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TtDecayChannelSelector(const edm::ParameterSet &)
std contructor
unsigned int countProngs(const reco::Candidate &part) const
count the number of charged particles for tau decays
Decay decayBranchB_
top decay branch 2
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
Definition: Tau.py:1
bool allowMuon_
allow tau decays into muon
static const int muonID
Definition: TopGenEvent.h:20
part
Definition: HCALResponse.h:20
unsigned int decayChannel() const
return decay channel to select for from configuration
allowedTopDecays
allow given lepton in corresponding decay branch for a given decay-channel selection; all leptons to ...
unsigned int checkSum(const Decay &vec) const
static const int WID
Definition: TopGenEvent.h:18
~TtDecayChannelSelector()
default destructor
bool operator()(const reco::GenParticleCollection &parts, std::string inputType) const
operator for decay channel selection
static const std::string kGenParticles
virtual int charge() const =0
electric charge
static const int elecID
Definition: TopGenEvent.h:19
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
bool allow1Prong_
allow 1-prong tau decays
bool invert_
invert selection