CMS 3D CMS Logo

PFCandidateElectronExtra.cc
Go to the documentation of this file.
3 #include <ostream>
4 #include <iomanip>
5 
6 using namespace reco;
7 
9  status_ = 0;
10  mvaStatus_ = 0;
11  pout_ = math::XYZTLorentzVector(0., 0., 0., 0.);
12  hadEnergy_ = -9999.;
13  sigmaEtaEta_ = -9999.;
14 
15  for (MvaVariable m = MVA_FIRST; m < MVA_LAST; m = MvaVariable(m + 1))
16  mvaVariables_.push_back(-9999.);
17 
20 }
21 
23  status_ = 0;
24  mvaStatus_ = 0;
25  pout_ = math::XYZTLorentzVector(0., 0., 0., 0.);
26  hadEnergy_ = -9999.;
27  sigmaEtaEta_ = -9999.;
28 
29  for (MvaVariable m = MVA_FIRST; m < MVA_LAST; m = MvaVariable(m + 1))
30  mvaVariables_.push_back(-9999.);
31 
32  gsfTrackRef_ = gsfTrack;
34 
36  setVariable(MVA_EtaGsf, gsfTrackRef_->etaMode());
37  setVariable(MVA_Chi2Gsf, gsfTrackRef_->normalizedChi2());
38  float ptmodeerror = gsfTrackRef_->ptModeError();
39  if (ptmodeerror > 0.)
40  setVariable(MVA_SigmaPtOverPt, ptmodeerror / gsfTrackRef_->ptMode());
41  else
43 
44  setVariable(MVA_Fbrem, (gsfTrackRef_->ptMode() - pout_.pt()) / gsfTrackRef_->ptMode());
45 }
46 
48 
50 
52  kfTrackRef_ = ref;
53  float nhit_kf = 0;
54  float chi2_kf = -0.01;
55  // if the reference is null, it does not mean that the variables have not been set
56  if (kfTrackRef_.isNonnull()) {
57  nhit_kf = (float)kfTrackRef_->hitPattern().trackerLayersWithMeasurement();
58  chi2_kf = kfTrackRef_->normalizedChi2();
59  }
60  setVariable(MVA_NhitsKf, nhit_kf);
61  setVariable(MVA_Chi2Kf, chi2_kf);
62 }
63 
65  lateBrem_ = val;
67 }
68 
70  earlyBrem_ = val;
72 }
73 
75  hadEnergy_ = val;
76  if (!clusterEnergies_.empty())
78 }
79 
81  sigmaEtaEta_ = val;
83 }
84 
86  deltaEta_ = val;
88 }
89 
90 void PFCandidateElectronExtra::setClusterEnergies(const std::vector<float>& energies) {
91  clusterEnergies_ = energies;
92 
93  if (pout_.t() != 0.)
95 
96  const float m_el2 = 0.00051 * 0.00051;
97  float Ein_gsf = sqrt(gsfTrackRef_->pMode() * gsfTrackRef_->pMode() + m_el2);
98 
99  float etot = 0;
100  unsigned size = clusterEnergies_.size();
101  // std::cout << " N clusters " << size << std::endl;
102  float ebrem = 0.;
103  for (unsigned ic = 0; ic < size; ++ic) {
104  etot += clusterEnergies_[ic];
105  if (ic > 0)
106  ebrem += clusterEnergies_[ic];
107  }
108  setVariable(MVA_EtotOverPin, etot / Ein_gsf);
109  setVariable(MVA_EbremOverDeltaP, ebrem / (Ein_gsf - pout_.t()));
110 
111  // recompute - as in PFElectronAglo, the had energy is filled before the cluster energies
112  if (hadEnergy_ != -9999.)
114 }
115 
117 
120  mvaStatus_ |= (1 << (type));
121 }
122 
124  if (status) {
125  status_ |= (1 << type);
126  } else {
127  status_ &= ~(1 << type);
128  }
129 }
130 
132 
134 
136  return (mvaStatus(var) ? mvaVariables_[var] : -9999.);
137 }
138 
139 #include <string>
140 
141 static char const* const listVar[] = {"LogPt",
142  "Eta",
143  "SigmaPtOverPt",
144  "fbrem",
145  "Chi2Gsf",
146  "NhitsKf",
147  "Chi2Kf",
148  "EtotOverPin",
149  "EseedOverPout",
150  "EbremOverDeltaP",
151  "DeltaEtaTrackCluster",
152  "LogSigmaEtaEta",
153  "H/(H+E)",
154  "LateBrem",
155  "FirstBrem",
156  "MVA"};
157 
158 std::ostream& reco::operator<<(std::ostream& out, const PFCandidateElectronExtra& extra) {
159  if (!out)
160  return out;
161 
162  out << std::setiosflags(std::ios::left) << std::setw(20) << "Variable index" << std::setw(20) << "Name"
163  << std::setw(10) << "Set(0/1)" << std::setw(8) << "value" << std::endl;
167  out << std::setw(20) << i << std::setw(20) << listVar[i] << std::setw(10) << extra.mvaStatus(i) << std::setw(8)
168  << extra.mvaVariable(i) << std::endl;
169  }
170 
171  return out;
172 }
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
std::vector< float > clusterEnergies_
energy of individual clusters (corrected). The first cluster is the seed
void setGsfTrackRef(const reco::GsfTrackRef &ref)
set gsftrack reference
void setMVA(float val)
set the result (mostly for debugging)
void setLateBrem(float val)
set LateBrem
void setVariable(MvaVariable type, float var)
math::XYZTLorentzVector pout_
Variables entering the MVA that should be saved.
void setSigmaEtaEta(float val)
set the sigmaetaeta
void setGsfTrackPout(const math::XYZTLorentzVector &pout)
set the pout (not trivial to get from the GSF track)
void setClusterEnergies(const std::vector< float > &energies)
set the cluster energies. the Pout should be saved first
float mvaVariable(MvaVariable var) const
access to any variable
void setEarlyBrem(float val)
set EarlyBrem
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:232
int mvaStatus_
status of mva variables
int electronStatus() const
access to the status
static char const *const listVar[]
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
reco::TrackRef kfTrackRef_
Ref to the KF track.
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:66
T sqrt(T t)
Definition: SSEVec.h:23
reco::GsfTrackRef gsfTrackRef_
Ref to the GSF track.
void setStatus(StatusFlag type, bool status=true)
set status
void setDeltaEta(float val)
set the delta eta
int status_
Status of the electron.
std::vector< float > mvaVariables_
mva variables - transient !
void setKfTrackRef(const reco::TrackRef &ref)
set kf track reference
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
fixed size matrix
bool mvaStatus(MvaVariable flag) const
access to mva variable status
void setHadEnergy(float val)
set the had energy. The cluster energies should be entered before