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 
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 }
electrons_cff.bool
bool
Definition: electrons_cff.py:372
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
TtDecayChannelSelector::allow3Prong_
bool allow3Prong_
allow 2-prong tau decays
Definition: TtDecayChannelSelector.h:48
metsig::tau
Definition: SignAlgoResolutions.h:49
TtDecayChannelSelector::allowMuon_
bool allowMuon_
allow tau decays into muon
Definition: TtDecayChannelSelector.h:44
TopGenEvent.h
TtDecayChannelSelector::TtDecayChannelSelector
TtDecayChannelSelector(const edm::ParameterSet &)
std contructor
Definition: TtDecayChannelSelector.cc:15
TtDecayChannelSelector::decayChannel
unsigned int decayChannel() const
return decay channel to select for from configuration
Definition: TtDecayChannelSelector.h:58
TtDecayChannelSelector::Muon
Definition: TtDecayChannelSelector.h:11
TopDecayID::bID
static const int bID
Definition: TopGenEvent.h:13
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
TtDecayChannelSelector::decayBranchB_
Decay decayBranchB_
top decay branch 2
Definition: TtDecayChannelSelector.h:52
reco::candidate::const_iterator
Definition: const_iterator.h:14
TtDecayChannelSelector::allowElectron_
bool allowElectron_
allow tau decays into electron
Definition: TtDecayChannelSelector.h:42
TtDecayChannelSelector::~TtDecayChannelSelector
~TtDecayChannelSelector()
default destructor
Definition: TtDecayChannelSelector.cc:59
kGenParticles
static const std::string kGenParticles
Definition: TtDecayChannelSelector.cc:9
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
Tau
Definition: Tau.py:1
TopDecayID::elecID
static const int elecID
Definition: TopGenEvent.h:18
TtDecayChannelSelector::Elec
Definition: TtDecayChannelSelector.h:11
Muon
Definition: Muon.py:1
EDMException.h
TopDecayID::muonID
static const int muonID
Definition: TopGenEvent.h:19
accept
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
contentValuesFiles.parts
parts
Definition: contentValuesFiles.py:58
part
part
Definition: HCALResponse.h:20
TtDecayChannelFilter_cfi.decayBranchA
decayBranchA
Definition: TtDecayChannelFilter_cfi.py:14
TtDecayChannelSelector::Tau
Definition: TtDecayChannelSelector.h:11
TtDecayChannelSelector::allow1Prong_
bool allow1Prong_
allow 1-prong tau decays
Definition: TtDecayChannelSelector.h:46
TopDecayID::tID
static const int tID
Definition: TopGenEvent.h:12
TtDecayChannelSelector::invert_
bool invert_
invert selection
Definition: TtDecayChannelSelector.h:38
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
funct::true
true
Definition: Factorize.h:173
TtDecayChannelSelector::search
bool search(reco::GenParticleCollection::const_iterator &part, int pdgId, std::string &inputType) const
search for particle with pdgId in given listing (for top)
Definition: TtDecayChannelSelector.cc:168
edm::ParameterSet
Definition: ParameterSet.h:36
createfilelist.int
int
Definition: createfilelist.py:10
edm::LogVerbatim
Definition: MessageLogger.h:297
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
kDecayChannels
static const unsigned int kDecayChannels
Definition: TtDecayChannelSelector.cc:13
TtDecayChannelSelector::checkSum
unsigned int checkSum(const Decay &vec) const
Definition: TtDecayChannelSelector.h:69
TtDecayChannelSelector::allowedDecays_
Decay allowedDecays_
Definition: TtDecayChannelSelector.h:55
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
TopDecayID::WID
static const int WID
Definition: TopGenEvent.h:17
TopDecayID::tauID
static const int tauID
Definition: TopGenEvent.h:20
TtDecayChannelSelector::decayBranchA_
Decay decayBranchA_
top decay branch 1
Definition: TtDecayChannelSelector.h:50
TtDecayChannelSelector.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TtDecayChannelFilter_cfi.allowedTopDecays
allowedTopDecays
allow given lepton in corresponding decay branch for a given decay-channel selection; all leptons to ...
Definition: TtDecayChannelFilter_cfi.py:13
TtDecayChannelSelector::operator()
bool operator()(const reco::GenParticleCollection &parts, std::string inputType) const
operator for decay channel selection
Definition: TtDecayChannelSelector.cc:61
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
TtDecayChannelFilter_cfi.decayBranchB
decayBranchB
Definition: TtDecayChannelFilter_cfi.py:19
TopDecayID::unfrag
static const int unfrag
Definition: TopGenEvent.h:11
ztail.d
d
Definition: ztail.py:151
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TtDecayChannelSelector::countProngs
unsigned int countProngs(const reco::Candidate &part) const
count the number of charged particles for tau decays
Definition: TtDecayChannelSelector.cc:186
TtDecayChannelSelector::restrictTauDecays_
bool restrictTauDecays_
restrict tau decays
Definition: TtDecayChannelSelector.h:40
TtDecayChannelSelector::tauDecay
bool tauDecay(const reco::Candidate &) const
check tau decay to be leptonic, 1-prong or 3-prong
Definition: TtDecayChannelSelector.cc:199