CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
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) {
145  }
146  (*sc)[0].setPreshowerClusters(clusters);
147  }
149  }
151  } else {
153  }
154  //relink caloclusters if needed
156  } else {
158  }
159 }
160 
165  } else {
167  }
168 }
169 
172  if (embeddedSeedCluster_) {
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()) {
197  }
198 }
199 
202  gsfTrack_.clear();
203  if (reco::GsfElectron::gsfTrack().isNonnull()) {
205  embeddedGsfTrack_ = true;
206  }
207 }
208 
211  superCluster_.clear();
212  if (reco::GsfElectron::superCluster().isNonnull()) {
214  embeddedSuperCluster_ = true;
215  }
216 }
217 
220  pflowSuperCluster_.clear();
221  if (reco::GsfElectron::parentSuperCluster().isNonnull()) {
224  }
225 }
226 
229  seedCluster_.clear();
230  if (reco::GsfElectron::superCluster().isNonnull() && reco::GsfElectron::superCluster()->seed().isNonnull()) {
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()) {
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 
331 bool Electron::isElectronIDAvailable(const std::string& name) const {
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();
352  pfCandidate_.push_back(*pfCandidateRef_);
353  embeddedPFCandidate_ = true;
354  }
355 }
356 
360  if (pfCandidateRef_.isNonnull()) {
361  if (i == 0) {
363  } else {
364  i--;
365  }
366  }
367  if (i >= associatedPackedFCandidateIndices_.size()) {
368  return reco::CandidatePtr();
369  } else {
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) {
423  ip3d_ = ip3d;
424 }
425 
428  for (uint16_t idx : associatedPackedFCandidateIndices_) {
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
bool isAvailable() const
Definition: Ref.h:537
uint8_t cachedIP_
True if the IP (former dB) has been cached.
Definition: Electron.h:369
void embedRecHits(const EcalRecHitCollection *rechits)
method to store the RecHits internally - can be called from the PATElectronProducer ...
tuple ret
prodAgent to be discontinued
bool embeddedTrack_
True if electron&#39;s track is stored internally.
Definition: Electron.h:305
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
get the source candidate pointer with index i
std::vector< reco::GsfTrack > gsfTrack_
Place to store electron&#39;s gsfTrack internally.
Definition: Electron.h:285
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
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
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 pt() const final
transverse momentum
double dB() const
the version without arguments returns PD2D, but with an absolute value (for backwards compatibility) ...
Definition: Electron.h:196
reco::SuperClusterRef parentSuperCluster() const override
override the reco::GsfElectron::pflowSuperCluster method, to access the internal storage of the pflow...
double ip3d() const
ip3d
Definition: Electron.h:215
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
reco::TrackRef closestCtfTrackRef() const override
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
void embedSuperCluster()
method to store the electron&#39;s SuperCluster internally
void embedGsfElectronCore()
method to store the electron&#39;s core internally
std::vector< reco::SuperCluster > superCluster_
Place to store electron&#39;s supercluster internally.
Definition: Electron.h:291
reco::GsfTrackRef gsfTrack() const override
override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster ...
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
edm::Ptr< CaloCluster > CaloClusterPtr
std::vector< reco::Track > track_
Place to store electron&#39;s track internally.
Definition: Electron.h:307
bool embeddedGsfElectronCore_
True if electron&#39;s gsfElectronCore is stored internally.
Definition: Electron.h:279
uint16_t size_type
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
bool isSet() const
std::vector< reco::CaloCluster > pflowBasicClusters_
Place to store electron&#39;s pflow basic clusters internally.
Definition: Electron.h:299
void embedPflowSuperCluster()
method to store the electron&#39;s PflowSuperCluster internally
edm::RefProd< pat::PackedCandidateCollection > packedPFCandidates_
Definition: Electron.h:376
std::vector< reco::CaloCluster > basicClusters_
Place to store electron&#39;s basic clusters internally.
Definition: Electron.h:295
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
std::vector< uint16_t > associatedPackedFCandidateIndices_
Definition: Electron.h:377
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
std::vector< reco::CaloCluster > preshowerClusters_
Place to store electron&#39;s preshower clusters internally.
Definition: Electron.h:297
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates; null if this has been built from a standard electron ...
bool embeddedRecHits_
True if RecHits stored internally.
Definition: Electron.h:313
~Electron() override
destructor
double edB() const
the version without arguments returns PD2D, but with an absolute value (for backwards compatibility) ...
Definition: Electron.h:198
Analysis-level lepton class.
Definition: Lepton.h:29
def move
Definition: eostools.py:511
float electronID(const std::string &name) const
Returns a specific electron ID associated to the pat::Electron given its name.
bool embeddedSeedCluster_
True if seed cluster is stored internally.
Definition: Electron.h:309
edm::AtomicPtrCache< std::vector< reco::SuperCluster > > superClusterRelinked_
Place to temporarily store the electron&#39;s supercluster after relinking the seed to it...
Definition: Electron.h:293
math::XYZTLorentzVector LorentzVector
std::vector< reco::GsfElectronCore > gsfElectronCore_
Place to store electron&#39;s gsfElectronCore internally.
Definition: Electron.h:281
float eip_[IpTypeSize]
Impact parameter uncertainty as recommended by the tracking group.
Definition: Electron.h:373
double ip3d_
Definition: Electron.h:336
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
EcalRecHitCollection recHits_
Place to store electron&#39;s RecHits internally (5x5 around seed+ all RecHits)
Definition: Electron.h:315
reco::PFCandidateCollection pfCandidate_
A copy of the source IsolatedPFCandidate is stored in this vector if embeddedPFCandidate_ if True...
Definition: Electron.h:326
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
bool embeddedGsfTrack_
True if electron&#39;s gsfTrack is stored internally.
Definition: Electron.h:283
reco::TrackRef track() const override
returns nothing. Use either gsfTrack or closestCtfTrack
bool set(std::unique_ptr< T > iNewValue) const
bool embeddedPflowSuperCluster_
True if electron&#39;s pflowsupercluster is stored internally.
Definition: Electron.h:289
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
Analysis-level electron class.
Definition: Electron.h:51
std::vector< IdPair > electronIDs_
Electron IDs.
Definition: Electron.h:319
reco::PFCandidateRef pfCandidateRef_
reference to the IsolatedPFCandidate this has been built from; null if this has been built from a sta...
Definition: Electron.h:328
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
float ip_[IpTypeSize]
Impact parameter at the primary vertex,.
Definition: Electron.h:371
bool embeddedSuperCluster_
True if electron&#39;s supercluster is stored internally.
Definition: Electron.h:287
void embedPreshowerClusters()
method to store the electron&#39;s preshower clusters
std::vector< reco::CaloCluster > pflowPreshowerClusters_
Place to store electron&#39;s pflow preshower clusters internally.
Definition: Electron.h:301
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
float sigmaIetaIphi() const
Definition: Electron.h:211
reco::CaloClusterPtr seed() const
direct access to the seed cluster
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
bool embeddedPFCandidate_
true if the IsolatedPFCandidate is embedded
Definition: Electron.h:324
void embedTrack()
method to store the electron&#39;s Track internally
double phi() const final
momentum azimuthal angle
reco::GsfElectronCoreRef core() const override
override the virtual reco::GsfElectron::core method, so that the embedded core can be used by GsfElec...
edm::RefVector< pat::PackedCandidateCollection > associatedPackedPFCandidates() const
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155
void embedPFCandidate()
embed the PFCandidate pointed to by pfCandidateRef_
std::vector< reco::SuperCluster > pflowSuperCluster_
Place to store electron&#39;s pflow supercluster internally.
Definition: Electron.h:303
float sigmaIetaIphi_
additional missing mva variables : 14/04/2012
Definition: Electron.h:335
double energy() const final
energy
double eta() const final
momentum pseudorapidity
std::vector< reco::CaloCluster > seedCluster_
Place to store electron&#39;s seed cluster internally.
Definition: Electron.h:311