CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
46  Variable var_; double exp_;
47 
48 
49 };
50 template<typename T, typename IT>
51 double JetCharge::chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const {
52  double num = 0.0, den = 0.0;
53  for (IT it = begin; it != end ; ++it) {
54  const T & obj = *it;
55  double w = getWeight(lv, obj);
56  den += w;
57  num += w * obj.charge();
58  }
59  return (den > 0.0 ? num/den : 0.0);
60 }
61 
62 template<typename T, typename C>
63 double JetCharge::chargeFromVal(const LorentzVector &lv, const C &vec) const {
64  typedef typename C::const_iterator IT;
65  return JetCharge::chargeFromValIterator<T,IT>(lv, vec.begin(), vec.end());
66 }
67 
68 template<typename T, typename C>
69 double JetCharge::chargeFromRef(const LorentzVector &lv, const C &vec) const {
70  typedef typename C::const_iterator IT;
71  double num = 0.0, den = 0.0;
72  for (IT it = vec.begin(), end = vec.end(); it != end ; ++it) {
73  const T & obj = *it;
74  double w = getWeight(lv, *obj);
75  den += w;
76  num += w * obj->charge();
77  }
78  return (den > 0.0 ? num/den : 0.0);
79 }
80 
81 template <class T>
82 double JetCharge::getWeight(const LorentzVector &lv, const T& obj) const {
83  double ret;
84  switch (var_) {
85  case Pt:
86  ret = obj.pt();
87  break;
88  case DeltaR:
89  ret = ROOT::Math::VectorUtil::DeltaR(lv.Vect(), obj.momentum());
90  break;
91  case RelPt:
92  case RelEta:
93  ret = lv.Vect().Dot(obj.momentum())/(lv.P() * obj.p()); // cos(theta)
94  ret = (var_ == RelPt ?
95  std::sqrt(1 - ret*ret) * obj.p() : // p * sin(theta) = pt
96  - 0.5 * std::log((1-ret)/(1+ret))); // = - log tan theta/2 = eta
97  break;
98  case Unit:
99  default:
100  ret = 1.0;
101  }
102  return (exp_ == 1.0 ? ret : (ret > 0 ?
103  std::pow(ret,exp_) :
104  - std::pow(std::abs(ret), exp_)));
105 }
106 
107 
108 #endif
double charge(const LorentzVector &lv, const reco::TrackCollection &vec) const
Definition: JetCharge.cc:7
list parent
Definition: dbtoconf.py:74
double chargeFromRef(const LorentzVector &lv, const C &vec) const
Definition: JetCharge.h:69
const double w
Definition: UKUtility.cc:23
Definition: deltaR.h:79
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
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:48
double exp_
Definition: JetCharge.h:46
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:37
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:63
double chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const
Definition: JetCharge.h:51
double getWeight(const LorentzVector &lv, const T &obj) const
Definition: JetCharge.h:82
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > LorentzVector
Definition: analysisEnums.h:9
#define begin
Definition: vmac.h:30
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:40