CMS 3D CMS Logo

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