CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRecoTauDiscriminationByHPSSelection.cc
Go to the documentation of this file.
1 #include <boost/foreach.hpp>
2 
5 
8 
9 namespace {
10 // Apply a hypothesis on the mass of the strips.
11 math::XYZTLorentzVector applyMassConstraint(
12  const math::XYZTLorentzVector& vec,double mass) {
13  double factor = sqrt(vec.energy()*vec.energy()-mass*mass)/vec.P();
15  vec.px()*factor,vec.py()*factor,vec.pz()*factor,vec.energy());
16 }
17 }
18 
21  public:
24  double discriminate(const reco::PFTauRef&);
25 
26  private:
28 
29  struct DecayModeCuts
30  {
32  : maxMass_(0)
33  {}
34  ~DecayModeCuts() {} // CV: maxMass object gets deleted by PFRecoTauDiscriminationByHPSSelection destructor
35  double minMass_;
37  double minPi0Mass_;
38  double maxPi0Mass_;
40  };
41 
42  typedef std::pair<unsigned int, unsigned int> IntPair;
43  typedef std::pair<double, double> DoublePair;
44  typedef std::map<IntPair, DecayModeCuts> DecayModeCutMap;
45 
48  double matchingCone_;
49  double minPt_;
50 };
51 
54  signalConeFun_(pset.getParameter<std::string>("coneSizeFormula"))
55 {
56  // Get the matchign cut
57  matchingCone_ = pset.getParameter<double>("matchingCone");
58  minPt_ = pset.getParameter<double>("minTauPt");
59  // Get the mass cuts for each decay mode
60  typedef std::vector<edm::ParameterSet> VPSet;
61  const VPSet& decayModes = pset.getParameter<VPSet>("decayModes");
62  BOOST_FOREACH(const edm::ParameterSet &dm, decayModes) {
63  // The mass window(s)
65  cuts.minMass_ = dm.getParameter<double>("minMass");
66  cuts.maxMass_ = new TauFunc(dm.getParameter<std::string>("maxMass"));
67  if (dm.exists("minPi0Mass")) {
68  cuts.minPi0Mass_ = dm.getParameter<double>("minPi0Mass");
69  cuts.maxPi0Mass_ = dm.getParameter<double>("maxPi0Mass");
70  } else {
71  cuts.minPi0Mass_ = -1.e3;
72  cuts.maxPi0Mass_ = 1.e9;
73  }
74  if (dm.exists("assumeStripMass")) {
75  cuts.assumeStripMass_ = dm.getParameter<double>("assumeStripMass");
76  } else {
77  cuts.assumeStripMass_ = -1.0;
78  }
79  decayModeCuts_.insert(std::make_pair(
80  // The decay mode as a key
81  std::make_pair(
82  dm.getParameter<uint32_t>("nCharged"),
83  dm.getParameter<uint32_t>("nPiZeros")),
84  cuts
85  ));
86  }
87 }
88 
90 {
91  for ( DecayModeCutMap::iterator it = decayModeCuts_.begin();
92  it != decayModeCuts_.end(); ++it ) {
93  delete it->second.maxMass_;
94  }
95 }
96 
97 double
99 {
100  //std::cout << "<PFRecoTauDiscriminationByHPSSelection::discriminate>:" << std::endl;
101 
102  // Check if we pass the min pt
103  if (tau->pt() < minPt_)
104  return 0.0;
105 
106  // See if we select this decay mode
107  DecayModeCutMap::const_iterator massWindowIter =
108  decayModeCuts_.find(std::make_pair(tau->signalPFChargedHadrCands().size(),
109  tau->signalPiZeroCandidates().size()));
110  // Check if decay mode is supported
111  if (massWindowIter == decayModeCuts_.end()) {
112  return 0.0;
113  }
114  const DecayModeCuts& massWindow = massWindowIter->second;
115 
116  math::XYZTLorentzVector tauP4 = tau->p4();
117  //std::cout << "tau: Pt = " << tauP4.pt() << ", eta = " << tauP4.eta() << ", phi = " << tauP4.phi() << ", mass = " << tauP4.mass() << std::endl;
118  // Find the total pizero p4
120  BOOST_FOREACH(const reco::RecoTauPiZero& cand,
121  tau->signalPiZeroCandidates()){
122  math::XYZTLorentzVector candP4 = cand.p4();
123  stripsP4 += candP4;
124  }
125 
126  // Apply strip mass assumption corrections
127  if (massWindow.assumeStripMass_ >= 0) {
128  BOOST_FOREACH(const reco::RecoTauPiZero& cand,
129  tau->signalPiZeroCandidates()){
130  math::XYZTLorentzVector uncorrected = cand.p4();
131  math::XYZTLorentzVector corrected =
132  applyMassConstraint(uncorrected, massWindow.assumeStripMass_);
133  math::XYZTLorentzVector correction = corrected - uncorrected;
134  tauP4 += correction;
135  stripsP4 += correction;
136  }
137  }
138  //std::cout << "strips: Pt = " << stripsP4.pt() << ", eta = " << stripsP4.eta() << ", phi = " << stripsP4.phi() << ", mass = " << stripsP4.mass() << std::endl;
139 
140  // Check if tau fails mass cut
141  double maxMass_value = (*massWindow.maxMass_)(*tau);
142  if (tauP4.M() > maxMass_value || tauP4.M() < massWindow.minMass_) {
143  return 0.0;
144  }
145 
146  // Check if it fails the pi 0 IM cut
147  if (stripsP4.M() > massWindow.maxPi0Mass_ ||
148  stripsP4.M() < massWindow.minPi0Mass_) {
149  return 0.0;
150  }
151 
152  // Check if tau passes matching cone cut
153  //std::cout << "dR(tau, jet) = " << deltaR(tauP4, tau->jetRef()->p4()) << std::endl;
154  if (deltaR(tauP4, tau->jetRef()->p4()) > matchingCone_) {
155  return 0.0;
156  }
157 
158  // Check if tau passes cone cut
159  double cone_size = signalConeFun_(*tau);
160  // Check if any charged objects fail the signal cone cut
161  BOOST_FOREACH(const reco::PFCandidateRef& cand,
162  tau->signalPFChargedHadrCands()) {
163  //std::cout << "dR(tau, signalPFChargedHadr) = " << deltaR(cand->p4(), tauP4) << std::endl;
164  if (deltaR(cand->p4(), tauP4) > cone_size)
165  return 0.0;
166  }
167  // Now check the pizeros
168  BOOST_FOREACH(const reco::RecoTauPiZero& cand,
169  tau->signalPiZeroCandidates()) {
170  //std::cout << "dR(tau, signalPiZero) = " << deltaR(cand.p4(), tauP4) << std::endl;
171  if (deltaR(cand.p4(), tauP4) > cone_size)
172  return 0.0;
173  }
174 
175  // Otherwise, we pass!
176  return 1.0;
177 }
178 
T getParameter(std::string const &) const
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
T sqrt(T t)
Definition: SSEVec.h:48
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41