CMS 3D CMS Logo

JetCharge.h
Go to the documentation of this file.
1 #ifndef RecoJets_JetCharge_JetCharge_H
2 #define RecoJets_JetCharge_JetCharge_H
3 
6 //#include "DataFormats/Candidate/interface/CandidateFwd.h"
12 #include <Math/VectorUtil.h>
13 #include <Math/Rotation3D.h>
14 #include <Math/RotationZ.h>
15 #include <Math/RotationY.h>
16 #include <cmath>
17 
18 class JetCharge {
19 public:
23 
24  JetCharge(Variable var, double exponent = 1.0) : var_(var), exp_(exponent) {}
25  JetCharge(const edm::ParameterSet &iCfg);
26 
27  double charge(const LorentzVector &lv, const reco::TrackCollection &vec) const;
28  double charge(const LorentzVector &lv, const reco::TrackRefVector &vec) const;
29  double charge(const LorentzVector &lv, const reco::CandidateCollection &vec) const;
30  double charge(const reco::Candidate &parent) const;
31  //double charge(const LorentzVector &lv, const reco::CandidateRefVector &vec) const ;
32 
33 private:
34  // functions
35  template <typename T, typename C>
36  double chargeFromRef(const LorentzVector &lv, const C &vec) const;
37  template <typename T, typename C>
38  double chargeFromVal(const LorentzVector &lv, const C &vec) const;
39  template <typename T, typename IT>
40  double chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const;
41 
42  template <class T>
43  double getWeight(const LorentzVector &lv, const T &obj) const;
44 
45  // data members
47  double exp_;
48 };
49 template <typename T, typename IT>
50 double JetCharge::chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const {
51  double num = 0.0, den = 0.0;
52  for (IT it = begin; it != end; ++it) {
53  const T &obj = *it;
54  double w = getWeight(lv, obj);
55  den += w;
56  num += w * obj.charge();
57  }
58  return (den > 0.0 ? num / den : 0.0);
59 }
60 
61 template <typename T, typename C>
62 double JetCharge::chargeFromVal(const LorentzVector &lv, const C &vec) const {
63  typedef typename C::const_iterator IT;
64  return JetCharge::chargeFromValIterator<T, IT>(lv, vec.begin(), vec.end());
65 }
66 
67 template <typename T, typename C>
68 double JetCharge::chargeFromRef(const LorentzVector &lv, const C &vec) const {
69  typedef typename C::const_iterator IT;
70  double num = 0.0, den = 0.0;
71  for (IT it = vec.begin(), end = vec.end(); it != end; ++it) {
72  const T &obj = *it;
73  double w = getWeight(lv, *obj);
74  den += w;
75  num += w * obj->charge();
76  }
77  return (den > 0.0 ? num / den : 0.0);
78 }
79 
80 template <class T>
81 double JetCharge::getWeight(const LorentzVector &lv, const T &obj) const {
82  double ret;
83  switch (var_) {
84  case Pt:
85  ret = obj.pt();
86  break;
87  case DeltaR:
88  ret = ROOT::Math::VectorUtil::DeltaR(lv.Vect(), obj.momentum());
89  break;
90  case RelPt:
91  case RelEta:
92  ret = lv.Vect().Dot(obj.momentum()) / (lv.P() * obj.p()); // cos(theta)
93  ret = (var_ == RelPt ? std::sqrt(1 - ret * ret) * obj.p() : // p * sin(theta) = pt
94  -0.5 * std::log((1 - ret) / (1 + ret))); // = - log tan theta/2 = eta
95  break;
96  case Unit:
97  default:
98  ret = 1.0;
99  }
100  return (exp_ == 1.0 ? ret : (ret > 0 ? std::pow(ret, exp_) : -std::pow(std::abs(ret), exp_)));
101 }
102 
103 #endif
Definition: DeltaR.py:1
double charge(const LorentzVector &lv, const reco::TrackCollection &vec) const
Definition: JetCharge.cc:7
double chargeFromRef(const LorentzVector &lv, const C &vec) const
Definition: JetCharge.h:68
const double w
Definition: UKUtility.cc:23
ret
prodAgent to be discontinued
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
JetCharge(Variable var, double exponent=1.0)
Definition: JetCharge.h:24
Variable var_
Definition: JetCharge.h:46
reco::Particle::Vector Vector
Definition: JetCharge.h:22
T sqrt(T t)
Definition: SSEVec.h:19
double exp_
Definition: JetCharge.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:39
reco::Particle::LorentzVector LorentzVector
Definition: JetCharge.h:21
std::vector< LinkConnSpec >::const_iterator IT
double chargeFromVal(const LorentzVector &lv, const C &vec) const
Definition: JetCharge.h:62
double chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const
Definition: JetCharge.h:50
double getWeight(const LorentzVector &lv, const T &obj) const
Definition: JetCharge.h:81
#define begin
Definition: vmac.h:32
math::XYZVector Vector
point in the space
Definition: Particle.h:27
long double T
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30