Go to the documentation of this file.00001 #ifndef RecoJets_JetCharge_JetCharge_H
00002 #define RecoJets_JetCharge_JetCharge_H
00003
00004 #include "DataFormats/Math/interface/LorentzVector.h"
00005 #include "DataFormats/Math/interface/Vector.h"
00006
00007 #include "DataFormats/TrackReco/interface/Track.h"
00008 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00009 #include "DataFormats/Candidate/interface/Candidate.h"
00010 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include <Math/VectorUtil.h>
00013 #include <Math/Rotation3D.h>
00014 #include <Math/RotationZ.h>
00015 #include <Math/RotationY.h>
00016 #include <cmath>
00017
00018 class JetCharge {
00019 public:
00020 enum Variable { Pt, RelPt, RelEta, DeltaR, Unit };
00021 typedef reco::Particle::LorentzVector LorentzVector;
00022 typedef reco::Particle::Vector Vector;
00023
00024 JetCharge(Variable var, double exponent=1.0) : var_(var), exp_(exponent) { }
00025 JetCharge(const edm::ParameterSet &iCfg) ;
00026
00027 double charge(const LorentzVector &lv, const reco::TrackCollection &vec) const ;
00028 double charge(const LorentzVector &lv, const reco::TrackRefVector &vec) const ;
00029 double charge(const LorentzVector &lv, const reco::CandidateCollection &vec) const ;
00030 double charge(const reco::Candidate &parent) const ;
00031
00032
00033 private:
00034
00035 template<typename T, typename C>
00036 double chargeFromRef(const LorentzVector &lv, const C &vec) const ;
00037 template<typename T, typename C>
00038 double chargeFromVal(const LorentzVector &lv, const C &vec) const ;
00039 template<typename T, typename IT>
00040 double chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const ;
00041
00042 template <class T>
00043 double getWeight(const LorentzVector &lv, const T& obj) const ;
00044
00045
00046 Variable var_; double exp_;
00047
00048
00049 };
00050 template<typename T, typename IT>
00051 double JetCharge::chargeFromValIterator(const LorentzVector &lv, const IT &begin, const IT &end) const {
00052 double num = 0.0, den = 0.0;
00053 for (IT it = begin; it != end ; ++it) {
00054 const T & obj = *it;
00055 double w = getWeight(lv, obj);
00056 den += w;
00057 num += w * obj.charge();
00058 }
00059 return (den > 0.0 ? num/den : 0.0);
00060 }
00061
00062 template<typename T, typename C>
00063 double JetCharge::chargeFromVal(const LorentzVector &lv, const C &vec) const {
00064 typedef typename C::const_iterator IT;
00065 return JetCharge::chargeFromValIterator<T,IT>(lv, vec.begin(), vec.end());
00066 }
00067
00068 template<typename T, typename C>
00069 double JetCharge::chargeFromRef(const LorentzVector &lv, const C &vec) const {
00070 typedef typename C::const_iterator IT;
00071 double num = 0.0, den = 0.0;
00072 for (IT it = vec.begin(), end = vec.end(); it != end ; ++it) {
00073 const T & obj = *it;
00074 double w = getWeight(lv, *obj);
00075 den += w;
00076 num += w * obj->charge();
00077 }
00078 return (den > 0.0 ? num/den : 0.0);
00079 }
00080
00081 template <class T>
00082 double JetCharge::getWeight(const LorentzVector &lv, const T& obj) const {
00083 double ret;
00084 switch (var_) {
00085 case Pt:
00086 ret = obj.pt();
00087 break;
00088 case DeltaR:
00089 ret = ROOT::Math::VectorUtil::DeltaR(lv.Vect(), obj.momentum());
00090 break;
00091 case RelPt:
00092 case RelEta:
00093 ret = lv.Vect().Dot(obj.momentum())/(lv.P() * obj.p());
00094 ret = (var_ == RelPt ?
00095 std::sqrt(1 - ret*ret) * obj.p() :
00096 - 0.5 * std::log((1-ret)/(1+ret)));
00097 break;
00098 case Unit:
00099 default:
00100 ret = 1.0;
00101 }
00102 return (exp_ == 1.0 ? ret : (ret > 0 ?
00103 std::pow(ret,exp_) :
00104 - std::pow(std::abs(ret), exp_)));
00105 }
00106
00107
00108 #endif