CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TtDecayChannelSelector.cc
Go to the documentation of this file.
5 
6 // static const string for status check in
7 // TtDecayChannelSelector::search functions
8 static const std::string kGenParticles = "genParticles";
9 
10 // number of top branches for decay selection
11 static const unsigned int kTopBranches = 2;
12 
13 // maximal number of possible leptonic decay
14 // channels
15 static const unsigned int kDecayChannels = 3;
16 
17 
19  invert_ ( cfg.getParameter<bool>("invert" ) ),
20  allowLepton_(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>("leptonic" )||
30  allowedTauDecays.existsAs<bool>("oneProng" )||
31  allowedTauDecays.existsAs<bool>("threeProng") );
32  // specify the different possible restrictions of the tau decay channels
33  allowLepton_ = (allowedTauDecays.existsAs<bool>("leptonic" ) ? allowedTauDecays.getParameter<bool>("leptonic" ) : 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
38  edm::ParameterSet allowedTopDecays = cfg.getParameter<edm::ParameterSet>("allowedTopDecays");
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 leptonic = false;
210  unsigned int nch = 0;
211  // loop on tau decays, check for an elec
212  // or muon and count charged particles
213  for(reco::Candidate::const_iterator daughter=tau.begin();daughter!=tau.end(); ++daughter){
214  // if the tau daughter is again a tau, this means that the particle has
215  // still to be propagated; in that case, return the result of the same
216  // method applied on the daughter of the current particle
217  if(daughter->pdgId()==tau.pdgId()){
218  return tauDecay(*daughter);
219  }
220  // check for leptons
221  leptonic |= (std::abs(daughter->pdgId())==TopDecayID::elecID || std::abs(daughter->pdgId())==TopDecayID::muonID);
222  // count charged particles
223  nch += countProngs(*daughter);
224  }
225  return ((allowLepton_ && leptonic) ||
226  (allow1Prong_ && !leptonic && nch==1)||
227  (allow3Prong_ && !leptonic && nch==3));
228 }
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:181
static const int bID
Definition: TopGenEvent.h:14
static const int unfrag
Definition: TopGenEvent.h:12
Decay decayBranchA_
top decay branch 1
virtual int status() const =0
status word
#define abs(x)
Definition: mlp_lapack.h:159
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:21
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
static const unsigned int kDecayChannels
virtual const_iterator end() const =0
last daughter const_iterator
static const unsigned int kTopBranches
bool restrictTauDecays_
restrict tau decays
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 tauDecay(const reco::Candidate &) const
check tau decay to be leptonic, 1-prong or 3-prong
bool allow3Prong_
allow 2-prong tau decays
static const int muonID
Definition: TopGenEvent.h:20
Log< T >::type log(const T &t)
Definition: Log.h:22
part
Definition: HCALResponse.h:21
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
~TtDecayChannelSelector()
default destructor
bool operator()(const reco::GenParticleCollection &parts, std::string inputType) const
operator for decay channel selection
static const std::string kGenParticles
virtual const_iterator begin() const =0
first daughter const_iterator
static const int elecID
Definition: TopGenEvent.h:19
bool allowLepton_
allow leptonic tau decays
bool allow1Prong_
allow 1-prong tau decays
bool invert_
invert selection