CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Electron.cc
Go to the documentation of this file.
1 //
2 //
3 
7 
8 #include <limits>
9 
10 using namespace pat;
11 
14  : Lepton<reco::GsfElectron>(),
15  embeddedGsfElectronCore_(false),
16  embeddedGsfTrack_(false),
17  embeddedSuperCluster_(false),
18  embeddedPflowSuperCluster_(false),
19  embeddedTrack_(false),
20  embeddedSeedCluster_(false),
21  embeddedRecHits_(false),
22  embeddedPFCandidate_(false),
23  ecalDrivenMomentum_(Candidate::LorentzVector(0., 0., 0., 0.)),
24  ecalRegressionEnergy_(0.0),
25  ecalTrackRegressionEnergy_(0.0),
26  ecalRegressionError_(0.0),
27  ecalTrackRegressionError_(0.0),
28  ecalScale_(-99999.),
29  ecalSmear_(-99999.),
30  ecalRegressionScale_(-99999.),
31  ecalRegressionSmear_(-99999.),
32  ecalTrackRegressionScale_(-99999.),
33  ecalTrackRegressionSmear_(-99999.),
34  packedPFCandidates_(),
35  associatedPackedFCandidateIndices_() {
36  initImpactParameters();
37 }
38 
40 Electron::Electron(const reco::GsfElectron& anElectron)
41  : Lepton<reco::GsfElectron>(anElectron),
42  embeddedGsfElectronCore_(false),
43  embeddedGsfTrack_(false),
44  embeddedSuperCluster_(false),
45  embeddedPflowSuperCluster_(false),
46  embeddedTrack_(false),
47  embeddedSeedCluster_(false),
48  embeddedRecHits_(false),
49  embeddedPFCandidate_(false),
50  ecalDrivenMomentum_(anElectron.p4()) {
51  initImpactParameters();
52 }
53 
56  : Lepton<reco::GsfElectron>(anElectronRef),
57  embeddedGsfElectronCore_(false),
58  embeddedGsfTrack_(false),
59  embeddedSuperCluster_(false),
60  embeddedPflowSuperCluster_(false),
61  embeddedTrack_(false),
62  embeddedSeedCluster_(false),
63  embeddedRecHits_(false),
64  embeddedPFCandidate_(false),
65  ecalDrivenMomentum_(anElectronRef->p4()) {
66  initImpactParameters();
67 }
68 
71  : Lepton<reco::GsfElectron>(anElectronRef),
72  embeddedGsfElectronCore_(false),
73  embeddedGsfTrack_(false),
74  embeddedSuperCluster_(false),
75  embeddedPflowSuperCluster_(false),
76  embeddedTrack_(false),
77  embeddedSeedCluster_(false),
78  embeddedRecHits_(false),
79  embeddedPFCandidate_(false),
80  ecalDrivenMomentum_(anElectronRef->p4()) {
81  initImpactParameters();
82 }
83 
86 
88 std::ostream& reco::operator<<(std::ostream& out, const pat::Electron& obj) {
89  if (!out)
90  return out;
91 
92  out << "\tpat::Electron: ";
93  out << std::setiosflags(std::ios::right);
94  out << std::setiosflags(std::ios::fixed);
95  out << std::setprecision(3);
96  out << " E/pT/eta/phi " << obj.energy() << "/" << obj.pt() << "/" << obj.eta() << "/" << obj.phi();
97  return out;
98 }
99 
102  std::fill(ip_, ip_ + IpTypeSize, 0.0f);
103  std::fill(eip_, eip_ + IpTypeSize, 0.0f);
104  cachedIP_ = 0;
105 }
106 
109  if (embeddedGsfTrack_) {
110  return reco::GsfTrackRef(&gsfTrack_, 0);
111  } else {
113  }
114 }
115 
118  if (embeddedGsfElectronCore_) {
119  return reco::GsfElectronCoreRef(&gsfElectronCore_, 0);
120  } else {
121  return reco::GsfElectron::core();
122  }
123 }
124 
127  if (embeddedSuperCluster_) {
128  if (embeddedSeedCluster_ || !basicClusters_.empty() || !preshowerClusters_.empty()) {
129  if (!superClusterRelinked_.isSet()) {
130  std::unique_ptr<std::vector<reco::SuperCluster> > sc(new std::vector<reco::SuperCluster>(superCluster_));
131  if (embeddedSeedCluster_ && !(*sc)[0].seed().isAvailable()) {
132  (*sc)[0].setSeed(seed());
133  }
134  if (!basicClusters_.empty() && !(*sc)[0].clusters().isAvailable()) {
136  for (unsigned int iclus = 0; iclus < basicClusters_.size(); ++iclus) {
137  clusters.push_back(reco::CaloClusterPtr(&basicClusters_, iclus));
138  }
139  (*sc)[0].setClusters(clusters);
140  }
141  if (!preshowerClusters_.empty() && !(*sc)[0].preshowerClusters().isAvailable()) {
143  for (unsigned int iclus = 0; iclus < preshowerClusters_.size(); ++iclus) {
144  clusters.push_back(reco::CaloClusterPtr(&preshowerClusters_, iclus));
145  }
146  (*sc)[0].setPreshowerClusters(clusters);
147  }
148  superClusterRelinked_.set(std::move(sc));
149  }
150  return reco::SuperClusterRef(&*superClusterRelinked_, 0);
151  } else {
152  return reco::SuperClusterRef(&superCluster_, 0);
153  }
154  //relink caloclusters if needed
155  return reco::SuperClusterRef(&superCluster_, 0);
156  } else {
158  }
159 }
160 
163  if (embeddedPflowSuperCluster_) {
164  return reco::SuperClusterRef(&pflowSuperCluster_, 0);
165  } else {
167  }
168 }
169 
172  if (embeddedSeedCluster_) {
173  return reco::CaloClusterPtr(&seedCluster_, 0);
174  } else {
175  return reco::GsfElectron::superCluster()->seed();
176  }
177 }
178 
181  if (embeddedTrack_) {
182  return reco::TrackRef(&track_, 0);
183  } else {
185  }
186 }
187 
188 // the name of the method is misleading, users should use gsfTrack of closestCtfTrack
189 reco::TrackRef Electron::track() const { return reco::TrackRef(); }
190 
193  gsfElectronCore_.clear();
194  if (reco::GsfElectron::core().isNonnull()) {
195  gsfElectronCore_.push_back(*reco::GsfElectron::core());
196  embeddedGsfElectronCore_ = true;
197  }
198 }
199 
202  gsfTrack_.clear();
203  if (reco::GsfElectron::gsfTrack().isNonnull()) {
204  gsfTrack_.push_back(*reco::GsfElectron::gsfTrack());
205  embeddedGsfTrack_ = true;
206  }
207 }
208 
211  superCluster_.clear();
212  if (reco::GsfElectron::superCluster().isNonnull()) {
213  superCluster_.push_back(*reco::GsfElectron::superCluster());
214  embeddedSuperCluster_ = true;
215  }
216 }
217 
220  pflowSuperCluster_.clear();
221  if (reco::GsfElectron::parentSuperCluster().isNonnull()) {
222  pflowSuperCluster_.push_back(*reco::GsfElectron::parentSuperCluster());
223  embeddedPflowSuperCluster_ = true;
224  }
225 }
226 
229  seedCluster_.clear();
230  if (reco::GsfElectron::superCluster().isNonnull() && reco::GsfElectron::superCluster()->seed().isNonnull()) {
231  seedCluster_.push_back(*reco::GsfElectron::superCluster()->seed());
232  embeddedSeedCluster_ = true;
233  }
234 }
235 
238  basicClusters_.clear();
239  if (reco::GsfElectron::superCluster().isNonnull()) {
242  for (; itscl != itsclE; ++itscl) {
243  basicClusters_.push_back(**itscl);
244  }
245  }
246 }
247 
250  preshowerClusters_.clear();
251  if (reco::GsfElectron::superCluster().isNonnull()) {
252  reco::CaloCluster_iterator itscl = reco::GsfElectron::superCluster()->preshowerClustersBegin();
253  reco::CaloCluster_iterator itsclE = reco::GsfElectron::superCluster()->preshowerClustersEnd();
254  for (; itscl != itsclE; ++itscl) {
255  preshowerClusters_.push_back(**itscl);
256  }
257  }
258 }
259 
262  pflowBasicClusters_.clear();
263  if (reco::GsfElectron::parentSuperCluster().isNonnull()) {
266  for (; itscl != itsclE; ++itscl) {
267  pflowBasicClusters_.push_back(**itscl);
268  }
269  }
270 }
271 
274  pflowPreshowerClusters_.clear();
275  if (reco::GsfElectron::parentSuperCluster().isNonnull()) {
276  reco::CaloCluster_iterator itscl = reco::GsfElectron::parentSuperCluster()->preshowerClustersBegin();
277  reco::CaloCluster_iterator itsclE = reco::GsfElectron::parentSuperCluster()->preshowerClustersEnd();
278  for (; itscl != itsclE; ++itscl) {
279  pflowPreshowerClusters_.push_back(**itscl);
280  }
281  }
282 }
283 
285 void Electron::embedTrack() {
286  track_.clear();
287  if (reco::GsfElectron::closestCtfTrackRef().isNonnull()) {
288  track_.push_back(*reco::GsfElectron::closestCtfTrackRef());
289  embeddedTrack_ = true;
290  }
291 }
292 
293 // method to store the RecHits internally
295  if (rechits != nullptr) {
296  recHits_ = *rechits;
297  embeddedRecHits_ = true;
298  }
299 }
300 
315 float Electron::electronID(const std::string& name) const {
316  for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
317  if (it->first == name)
318  return it->second;
319  }
320  cms::Exception ex("Key not found");
321  ex << "pat::Electron: the ID " << name << " can't be found in this pat::Electron.\n";
322  ex << "The available IDs are: ";
323  for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
324  ex << "'" << it->first << "' ";
325  }
326  ex << ".\n";
327  throw ex;
328 }
329 
332  for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
333  if (it->first == name)
334  return true;
335  }
336  return false;
337 }
338 
341  if (embeddedPFCandidate_) {
343  } else {
344  return pfCandidateRef_;
345  }
346 }
347 
350  pfCandidate_.clear();
351  if (pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
352  pfCandidate_.push_back(*pfCandidateRef_);
353  embeddedPFCandidate_ = true;
354  }
355 }
356 
360  if (pfCandidateRef_.isNonnull()) {
361  if (i == 0) {
362  return reco::CandidatePtr(edm::refToPtr(pfCandidateRef_));
363  } else {
364  i--;
365  }
366  }
367  if (i >= associatedPackedFCandidateIndices_.size()) {
368  return reco::CandidatePtr();
369  } else {
371  edm::Ref<pat::PackedCandidateCollection>(packedPFCandidates_, associatedPackedFCandidateIndices_[i])));
372  }
373 }
374 
385 double Electron::dB(IpType type_) const {
386  // more IP types (new)
387  if (cachedIP_ & (1 << int(type_))) {
388  return ip_[type_];
389  } else {
391  }
392 }
393 
404 double Electron::edB(IpType type_) const {
405  // more IP types (new)
406  if (cachedIP_ & (1 << int(type_))) {
407  return eip_[type_];
408  } else {
410  }
411 }
412 
414 void Electron::setDB(double dB, double edB, IpType type) {
415  ip_[type] = dB;
416  eip_[type] = edB;
417  cachedIP_ |= (1 << int(type));
418 }
419 
421 void Electron::setMvaVariables(double sigmaIetaIphi, double ip3d) {
422  sigmaIetaIphi_ = sigmaIetaIphi;
423  ip3d_ = ip3d;
424 }
425 
427  edm::RefVector<pat::PackedCandidateCollection> ret(packedPFCandidates_.id());
428  for (uint16_t idx : associatedPackedFCandidateIndices_) {
429  ret.push_back(edm::Ref<pat::PackedCandidateCollection>(packedPFCandidates_, idx));
430  }
431  return ret;
432 }
void setMvaVariables(double sigmaIetaIphi, double ip3d)
set missing mva input variables
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
type
Definition: HCALResponse.h:21
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
void embedRecHits(const EcalRecHitCollection *rechits)
method to store the RecHits internally - can be called from the PATElectronProducer ...
bool isElectronIDAvailable(const std::string &name) const
Returns true if a specific ID is available in this pat::Electron.
edm::Ref< GsfElectronCoreCollection > GsfElectronCoreRef
virtual TrackRef closestCtfTrackRef() const
Definition: GsfElectron.h:180
double eta() const final
momentum pseudorapidity
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
virtual SuperClusterRef parentSuperCluster() const
Definition: GsfElectron.h:160
double dB() const
the version without arguments returns PD2D, but with an absolute value (for backwards compatibility) ...
Definition: Electron.h:196
reco::CandidatePtr pfCandidate_
ret
prodAgent to be discontinued
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
void embedSuperCluster()
method to store the electron&#39;s SuperCluster internally
void embedGsfElectronCore()
method to store the electron&#39;s core internally
double pt() const final
transverse momentum
edm::Ptr< CaloCluster > CaloClusterPtr
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
get the source candidate pointer with index i
uint16_t size_type
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
reco::TrackRef track() const override
returns nothing. Use either gsfTrack or closestCtfTrack
void embedPflowSuperCluster()
method to store the electron&#39;s PflowSuperCluster internally
Definition: HeavyIon.h:7
void setDB(double dB, double edB, IPTYPE type)
Set impact parameter of a certain type and its uncertainty.
void embedSeedCluster()
method to store the electron&#39;s seedcluster internally
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:66
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates; null if this has been built from a standard electron ...
~Electron() override
destructor
double p4[4]
Definition: TauolaWrapper.h:92
double edB() const
the version without arguments returns PD2D, but with an absolute value (for backwards compatibility) ...
Definition: Electron.h:198
float electronID(const std::string &name) const
Returns a specific electron ID associated to the pat::Electron given its name.
double energy() const final
energy
math::XYZTLorentzVector LorentzVector
double f[11][100]
void embedPflowBasicClusters()
method to store the electron&#39;s pflow basic clusters
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
void embedBasicClusters()
method to store the electron&#39;s basic clusters
void embedGsfTrack()
method to store the electron&#39;s GsfTrack internally
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
Analysis-level electron class.
Definition: Electron.h:51
reco::TrackRef closestCtfTrackRef() const override
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
void embedPreshowerClusters()
method to store the electron&#39;s preshower clusters
reco::GsfElectronCoreRef core() const override
override the virtual reco::GsfElectron::core method, so that the embedded core can be used by GsfElec...
fixed size matrix
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155
reco::CaloClusterPtr seed() const
direct access to the seed cluster
reco::GsfTrackRef gsfTrack() const override
override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster ...
Definition: Lepton.py:1
void initImpactParameters()
init impact parameter defaults (for use in a constructor)
void embedPflowPreshowerClusters()
method to store the electron&#39;s pflow preshower clusters
Electron()
default constructor
void embedTrack()
method to store the electron&#39;s Track internally
double phi() const final
momentum azimuthal angle
edm::RefVector< pat::PackedCandidateCollection > associatedPackedPFCandidates() const
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
reco::SuperClusterRef parentSuperCluster() const override
override the reco::GsfElectron::pflowSuperCluster method, to access the internal storage of the pflow...
def move(src, dest)
Definition: eostools.py:511
void embedPFCandidate()
embed the PFCandidate pointed to by pfCandidateRef_