CMS 3D CMS Logo

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 {
37  initImpactParameters();
38 }
39 
41 Electron::Electron(const reco::GsfElectron & anElectron) :
42  Lepton<reco::GsfElectron>(anElectron),
43  embeddedGsfElectronCore_(false),
44  embeddedGsfTrack_(false),
45  embeddedSuperCluster_(false),
46  embeddedPflowSuperCluster_(false),
47  embeddedTrack_(false),
48  embeddedSeedCluster_(false),
49  embeddedRecHits_(false),
50  embeddedPFCandidate_(false),
51  ecalDrivenMomentum_(anElectron.p4())
52 {
53  initImpactParameters();
54 }
55 
58  Lepton<reco::GsfElectron>(anElectronRef),
59  embeddedGsfElectronCore_(false),
60  embeddedGsfTrack_(false),
61  embeddedSuperCluster_(false),
62  embeddedPflowSuperCluster_(false),
63  embeddedTrack_(false),
64  embeddedSeedCluster_(false),
65  embeddedRecHits_(false),
66  embeddedPFCandidate_(false),
67  ecalDrivenMomentum_(anElectronRef->p4())
68 {
69  initImpactParameters();
70 }
71 
73 Electron::Electron(const edm::Ptr<reco::GsfElectron> & anElectronRef) :
74  Lepton<reco::GsfElectron>(anElectronRef),
75  embeddedGsfElectronCore_(false),
76  embeddedGsfTrack_(false),
77  embeddedSuperCluster_(false),
78  embeddedPflowSuperCluster_(false),
79  embeddedTrack_(false),
80  embeddedSeedCluster_(false),
81  embeddedRecHits_(false),
82  embeddedPFCandidate_(false),
83  ecalDrivenMomentum_(anElectronRef->p4())
84 {
85  initImpactParameters();
86 }
87 
90 }
91 
93 std::ostream&
94 reco::operator<<(std::ostream& out, const pat::Electron& obj)
95 {
96  if(!out) return out;
97 
98  out << "\tpat::Electron: ";
99  out << std::setiosflags(std::ios::right);
100  out << std::setiosflags(std::ios::fixed);
101  out << std::setprecision(3);
102  out << " E/pT/eta/phi "
103  << obj.energy()<<"/"
104  << obj.pt()<<"/"
105  << obj.eta()<<"/"
106  << obj.phi();
107  return out;
108 }
109 
112  std::fill(ip_, ip_+IpTypeSize, 0.0f);
113  std::fill(eip_, eip_+IpTypeSize, 0.0f);
114  cachedIP_ = 0;
115 }
116 
117 
120  if (embeddedGsfTrack_) {
121  return reco::GsfTrackRef(&gsfTrack_, 0);
122  } else {
124  }
125 }
126 
129  if (embeddedGsfElectronCore_) {
130  return reco::GsfElectronCoreRef(&gsfElectronCore_, 0);
131  } else {
132  return reco::GsfElectron::core();
133  }
134 }
135 
136 
139  if (embeddedSuperCluster_) {
140  if (embeddedSeedCluster_ || !basicClusters_.empty() || !preshowerClusters_.empty()) {
141  if (!superClusterRelinked_.isSet()) {
142  std::unique_ptr<std::vector<reco::SuperCluster> > sc(new std::vector<reco::SuperCluster>(superCluster_));
143  if (embeddedSeedCluster_ && !(*sc)[0].seed().isAvailable()) {
144  (*sc)[0].setSeed(seed());
145  }
146  if (!basicClusters_.empty() && !(*sc)[0].clusters().isAvailable()) {
148  for (unsigned int iclus=0; iclus<basicClusters_.size(); ++iclus) {
149  clusters.push_back(reco::CaloClusterPtr(&basicClusters_,iclus));
150  }
151  (*sc)[0].setClusters(clusters);
152  }
153  if (!preshowerClusters_.empty() && !(*sc)[0].preshowerClusters().isAvailable()) {
155  for (unsigned int iclus=0; iclus<preshowerClusters_.size(); ++iclus) {
156  clusters.push_back(reco::CaloClusterPtr(&preshowerClusters_,iclus));
157  }
158  (*sc)[0].setPreshowerClusters(clusters);
159  }
160  superClusterRelinked_.set(std::move(sc));
161  }
162  return reco::SuperClusterRef(&*superClusterRelinked_, 0);
163  } else {
164  return reco::SuperClusterRef(&superCluster_, 0);
165  }
166  //relink caloclusters if needed
167  return reco::SuperClusterRef(&superCluster_, 0);
168  } else {
170  }
171 }
172 
175  if (embeddedPflowSuperCluster_) {
176  return reco::SuperClusterRef(&pflowSuperCluster_, 0);
177  } else {
179  }
180 }
181 
184  if(embeddedSeedCluster_){
185  return reco::CaloClusterPtr(&seedCluster_,0);
186  } else {
187  return reco::GsfElectron::superCluster()->seed();
188  }
189 }
190 
193  if (embeddedTrack_) {
194  return reco::TrackRef(&track_, 0);
195  } else {
197  }
198 }
199 
200 // the name of the method is misleading, users should use gsfTrack of closestCtfTrack
202  return reco::TrackRef();
203 }
204 
207  gsfElectronCore_.clear();
208  if (reco::GsfElectron::core().isNonnull()) {
209  gsfElectronCore_.push_back(*reco::GsfElectron::core());
210  embeddedGsfElectronCore_ = true;
211  }
212 }
213 
216  gsfTrack_.clear();
217  if (reco::GsfElectron::gsfTrack().isNonnull()) {
218  gsfTrack_.push_back(*reco::GsfElectron::gsfTrack());
219  embeddedGsfTrack_ = true;
220  }
221 }
222 
223 
226  superCluster_.clear();
227  if (reco::GsfElectron::superCluster().isNonnull()) {
228  superCluster_.push_back(*reco::GsfElectron::superCluster());
229  embeddedSuperCluster_ = true;
230  }
231 }
232 
235  pflowSuperCluster_.clear();
236  if (reco::GsfElectron::parentSuperCluster().isNonnull()) {
237  pflowSuperCluster_.push_back(*reco::GsfElectron::parentSuperCluster());
238  embeddedPflowSuperCluster_ = true;
239  }
240 }
241 
244  seedCluster_.clear();
245  if (reco::GsfElectron::superCluster().isNonnull() && reco::GsfElectron::superCluster()->seed().isNonnull()) {
246  seedCluster_.push_back(*reco::GsfElectron::superCluster()->seed());
247  embeddedSeedCluster_ = true;
248  }
249 }
250 
253  basicClusters_.clear();
254  if (reco::GsfElectron::superCluster().isNonnull()){
257  for(;itscl!=itsclE;++itscl){
258  basicClusters_.push_back( **itscl ) ;
259  }
260  }
261 }
262 
265  preshowerClusters_.clear();
266  if (reco::GsfElectron::superCluster().isNonnull()){
267  reco::CaloCluster_iterator itscl = reco::GsfElectron::superCluster()->preshowerClustersBegin();
268  reco::CaloCluster_iterator itsclE = reco::GsfElectron::superCluster()->preshowerClustersEnd();
269  for(;itscl!=itsclE;++itscl){
270  preshowerClusters_.push_back( **itscl ) ;
271  }
272  }
273 }
274 
277  pflowBasicClusters_.clear();
278  if (reco::GsfElectron::parentSuperCluster().isNonnull()){
281  for(;itscl!=itsclE;++itscl){
282  pflowBasicClusters_.push_back( **itscl ) ;
283  }
284  }
285 }
286 
289  pflowPreshowerClusters_.clear();
290  if (reco::GsfElectron::parentSuperCluster().isNonnull()){
291  reco::CaloCluster_iterator itscl = reco::GsfElectron::parentSuperCluster()->preshowerClustersBegin();
292  reco::CaloCluster_iterator itsclE = reco::GsfElectron::parentSuperCluster()->preshowerClustersEnd();
293  for(;itscl!=itsclE;++itscl){
294  pflowPreshowerClusters_.push_back( **itscl ) ;
295  }
296  }
297 }
298 
300 void Electron::embedTrack() {
301  track_.clear();
302  if (reco::GsfElectron::closestCtfTrackRef().isNonnull()) {
303  track_.push_back(*reco::GsfElectron::closestCtfTrackRef());
304  embeddedTrack_ = true;
305  }
306 }
307 
308 // method to store the RecHits internally
310  if (rechits!=nullptr) {
311  recHits_ = *rechits;
312  embeddedRecHits_ = true;
313  }
314 }
315 
330 float Electron::electronID(const std::string& name) const {
331  for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
332  if (it->first == name) return it->second;
333  }
334  cms::Exception ex("Key not found");
335  ex << "pat::Electron: the ID " << name << " can't be found in this pat::Electron.\n";
336  ex << "The available IDs are: ";
337  for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
338  ex << "'" << it->first << "' ";
339  }
340  ex << ".\n";
341  throw ex;
342 }
343 
346  for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
347  if (it->first == name) return true;
348  }
349  return false;
350 }
351 
352 
355  if (embeddedPFCandidate_) {
357  } else {
358  return pfCandidateRef_;
359  }
360 }
361 
364  pfCandidate_.clear();
365  if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
366  pfCandidate_.push_back( *pfCandidateRef_ );
367  embeddedPFCandidate_ = true;
368  }
369 }
370 
374  if (pfCandidateRef_.isNonnull()) {
375  if (i == 0) {
376  return reco::CandidatePtr(edm::refToPtr(pfCandidateRef_));
377  } else {
378  i--;
379  }
380  }
381  if (i >= associatedPackedFCandidateIndices_.size()) {
382  return reco::CandidatePtr();
383  } else {
384  return reco::CandidatePtr(edm::refToPtr(edm::Ref<pat::PackedCandidateCollection>(packedPFCandidates_, associatedPackedFCandidateIndices_[i])));
385  }
386 }
387 
388 
389 
400 double Electron::dB(IpType type_) const {
401  // more IP types (new)
402  if ( cachedIP_ & (1 << int(type_))) {
403  return ip_[type_];
404  } else {
406  }
407 }
408 
419 double Electron::edB(IpType type_) const {
420  // more IP types (new)
421  if ( cachedIP_ & (1 << int(type_))) {
422  return eip_[type_];
423  } else {
425  }
426 }
427 
429 void Electron::setDB(double dB, double edB, IpType type){
430  ip_[type] = dB; eip_[type] = edB; cachedIP_ |= (1 << int(type));
431 }
432 
434 void Electron::setMvaVariables( double sigmaIetaIphi, double ip3d){
435  sigmaIetaIphi_ = sigmaIetaIphi;
436  ip3d_ = ip3d;
437 }
438 
440  edm::RefVector<pat::PackedCandidateCollection> ret(packedPFCandidates_.id());
441  for (uint16_t idx : associatedPackedFCandidateIndices_) {
442  ret.push_back(edm::Ref<pat::PackedCandidateCollection>(packedPFCandidates_, idx));
443  }
444  return ret;
445 }
446 
447 
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:185
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:201
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:190
double dB() const
the version without arguments returns PD2D, but with an absolute value (for backwards compatibility) ...
Definition: Electron.h:207
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
void embedSuperCluster()
method to store the electron&#39;s SuperCluster internally
reco::PFCandidatePtr pfCandidate_
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:71
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:209
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:52
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:184
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
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:510
void embedPFCandidate()
embed the PFCandidate pointed to by pfCandidateRef_