File indexing completed on 2024-04-06 12:04:49
0001 #ifndef ParticleFlowCandidate_PFCandidate_h
0002 #define ParticleFlowCandidate_PFCandidate_h
0003
0004
0005
0006
0007
0008
0009 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0010 #include <atomic>
0011 #endif
0012 #include <iosfwd>
0013 #include <array>
0014
0015 #include "DataFormats/Math/interface/Point3D.h"
0016
0017 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
0018 #include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h"
0019 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0020 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0021 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0022 #include "DataFormats/MuonReco/interface/Muon.h"
0023 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0024 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0025 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateElectronExtraFwd.h"
0026 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0027 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertexFwd.h"
0028 #include "DataFormats/EgammaCandidates/interface/ConversionFwd.h"
0029 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0030 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidatePhotonExtraFwd.h"
0031 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtraFwd.h"
0032 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0033 namespace reco {
0034
0035
0036
0037
0038
0039
0040
0041 class PFCandidate : public CompositeCandidate {
0042 public:
0043
0044 enum ParticleType {
0045 X = 0,
0046 h,
0047 e,
0048 mu,
0049 gamma,
0050 h0,
0051 h_HF,
0052 egamma_HF
0053 };
0054
0055 enum Flags {
0056 NORMAL = 0,
0057 E_PHI_SMODULES,
0058 E_ETA_0,
0059 E_ETA_MODULES,
0060 E_BARREL_ENDCAP,
0061 E_PRESHOWER_EDGE,
0062 E_PRESHOWER,
0063 E_ENDCAP_EDGE,
0064 H_ETA_0,
0065 H_BARREL_ENDCAP,
0066 H_ENDCAP_VFCAL,
0067 H_VFCAL_EDGE,
0068 T_TO_DISP,
0069 T_FROM_DISP,
0070 T_FROM_V0,
0071 T_FROM_GAMMACONV,
0072 GAMMA_TO_GAMMACONV
0073 };
0074
0075 enum PFVertexType {
0076 kCandVertex = 0,
0077 kTrkVertex = 1,
0078 kComMuonVertex = 2,
0079 kSAMuonVertex = 3,
0080 kTrkMuonVertex = 4,
0081 kGSFVertex = 5,
0082 kTPFMSMuonVertex = 6,
0083 kPickyMuonVertex = 7,
0084 kDYTMuonVertex = 8
0085 };
0086
0087
0088 PFCandidate();
0089
0090
0091 PFCandidate(const PFCandidatePtr& sourcePtr);
0092
0093
0094
0095
0096
0097 PFCandidate(Charge q, const LorentzVector& p4, ParticleType particleId);
0098
0099
0100 PFCandidate(const PFCandidate&);
0101
0102
0103 ~PFCandidate() override;
0104
0105 PFCandidate& operator=(PFCandidate const&);
0106
0107
0108 PFCandidate* clone() const override;
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 using reco::Candidate::setSourceCandidatePtr;
0120 void setSourceCandidatePtr(const PFCandidatePtr& ptr) { sourcePtr_ = ptr; }
0121
0122 size_t numberOfSourceCandidatePtrs() const override { return 1; }
0123
0124 CandidatePtr sourceCandidatePtr(size_type i) const override { return sourcePtr_; }
0125
0126
0127
0128
0129 int translateTypeToPdgId(ParticleType type) const;
0130 ParticleType translatePdgIdToType(int pdgid) const;
0131
0132
0133 void setParticleType(ParticleType type);
0134
0135
0136
0137
0138
0139 void addElementInBlock(const reco::PFBlockRef& blockref, unsigned elementIndex);
0140
0141
0142 void setTrackRef(const reco::TrackRef& ref);
0143
0144
0145
0146 reco::TrackRef trackRef() const;
0147
0148
0149
0150 const reco::Track* bestTrack() const override {
0151 if ((abs(pdgId()) == 11 || pdgId() == 22) && gsfTrackRef().isNonnull() && gsfTrackRef().isAvailable())
0152 return &(*gsfTrackRef());
0153 else if (trackRef().isNonnull() && trackRef().isAvailable())
0154 return &(*trackRef());
0155 else
0156 return nullptr;
0157 }
0158
0159 float dzError() const override {
0160 const Track* tr = bestTrack();
0161 if (tr != nullptr)
0162 return tr->dzError();
0163 else
0164 return 0;
0165 }
0166
0167 float dxyError() const override {
0168 const Track* tr = bestTrack();
0169 if (tr != nullptr)
0170 return tr->dxyError();
0171 else
0172 return 0;
0173 }
0174
0175
0176 void setGsfTrackRef(const reco::GsfTrackRef& ref);
0177
0178
0179
0180 reco::GsfTrackRef gsfTrackRef() const;
0181
0182
0183 void setMuonRef(const reco::MuonRef& ref);
0184
0185
0186
0187 reco::MuonRef muonRef() const;
0188
0189
0190 void setDisplacedVertexRef(const reco::PFDisplacedVertexRef& ref, Flags flag);
0191
0192
0193
0194 reco::PFDisplacedVertexRef displacedVertexRef(Flags type) const;
0195
0196
0197 void setConversionRef(const reco::ConversionRef& ref);
0198
0199
0200 reco::ConversionRef conversionRef() const;
0201
0202
0203 void setV0Ref(const reco::VertexCompositeCandidateRef& ref);
0204
0205
0206 reco::VertexCompositeCandidateRef v0Ref() const;
0207
0208
0209 reco::GsfElectronRef gsfElectronRef() const;
0210
0211
0212 reco::PFCandidateElectronExtraRef electronExtraRef() const;
0213
0214
0215 void setEcalEnergy(float eeRaw, float eeCorr) {
0216 rawEcalEnergy_ = eeRaw;
0217 ecalERatio_ = std::abs(eeRaw) < 1.e-6 ? 1.0 : eeCorr / eeRaw;
0218 }
0219
0220
0221 double ecalEnergy() const { return ecalERatio_ * rawEcalEnergy_; }
0222
0223
0224 double rawEcalEnergy() const { return rawEcalEnergy_; }
0225
0226
0227 void setHcalEnergy(float ehRaw, float ehCorr) {
0228 rawHcalEnergy_ = ehRaw;
0229 hcalERatio_ = std::abs(ehRaw) < 1.e-6 ? 1.0 : ehCorr / ehRaw;
0230 }
0231
0232
0233 double hcalEnergy() const { return hcalERatio_ * rawHcalEnergy_; }
0234
0235
0236 double rawHcalEnergy() const { return rawHcalEnergy_; }
0237
0238
0239 void setHoEnergy(float eoRaw, float eoCorr) {
0240 rawHoEnergy_ = eoRaw;
0241 hoERatio_ = std::abs(eoRaw) < 1.e-6 ? 1.0 : eoCorr / eoRaw;
0242 }
0243
0244
0245 double hoEnergy() const { return hoERatio_ * rawHoEnergy_; }
0246
0247
0248 double rawHoEnergy() const { return rawHoEnergy_; }
0249
0250
0251 void setGsfElectronRef(const reco::GsfElectronRef& ref);
0252
0253 void setSuperClusterRef(const reco::SuperClusterRef& scRef);
0254
0255
0256 reco::SuperClusterRef superClusterRef() const;
0257
0258
0259 void setPhotonRef(const reco::PhotonRef& phRef);
0260
0261
0262 reco::PhotonRef photonRef() const;
0263
0264
0265 void setPFPhotonExtraRef(const reco::PFCandidatePhotonExtraRef& ref);
0266
0267
0268 reco::PFCandidatePhotonExtraRef photonExtraRef() const;
0269
0270
0271 void setPFEGammaExtraRef(const reco::PFCandidateEGammaExtraRef& ref);
0272
0273
0274 reco::PFCandidateEGammaExtraRef egammaExtraRef() const;
0275
0276
0277 void setPs1Energy(float e1) { ps1Energy_ = e1; }
0278
0279
0280 double pS1Energy() const { return ps1Energy_; }
0281
0282
0283 void setPs2Energy(float e2) { ps2Energy_ = e2; }
0284
0285
0286 double pS2Energy() const { return ps2Energy_; }
0287
0288
0289 void rescaleMomentum(double rescaleFactor);
0290
0291
0292 void setFlag(Flags theFlag, bool value);
0293
0294
0295 bool flag(Flags theFlag) const;
0296
0297
0298 void setDeltaP(double dp) { deltaP_ = dp; }
0299
0300
0301 double deltaP() const { return deltaP_; }
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311 void set_mva_Isolated(float mvaI) { mva_Isolated_ = mvaI; }
0312
0313 float mva_Isolated() const { return mva_Isolated_; }
0314
0315 void set_mva_e_pi(float mvaNI) { mva_e_pi_ = mvaNI; }
0316
0317 float mva_e_pi() const { return mva_e_pi_; }
0318
0319
0320 void set_mva_e_mu(float mva) { mva_e_mu_ = mva; }
0321
0322
0323 float mva_e_mu() const { return mva_e_mu_; }
0324
0325
0326 void set_mva_pi_mu(float mva) { mva_pi_mu_ = mva; }
0327
0328
0329 float mva_pi_mu() const { return mva_pi_mu_; }
0330
0331
0332 void set_mva_nothing_gamma(float mva) { mva_nothing_gamma_ = mva; }
0333
0334
0335 float mva_nothing_gamma() const { return mva_nothing_gamma_; }
0336
0337
0338 void set_mva_nothing_nh(float mva) { mva_nothing_nh_ = mva; }
0339
0340
0341 float mva_nothing_nh() const { return mva_nothing_nh_; }
0342
0343
0344 void set_mva_gamma_nh(float mva) { mva_gamma_nh_ = mva; }
0345
0346
0347
0348 float dnn_e_sigIsolated() const { return dnn_e_sigIsolated_; }
0349 void set_dnn_e_sigIsolated(float mva) { dnn_e_sigIsolated_ = mva; }
0350
0351
0352 float dnn_e_sigNonIsolated() const { return dnn_e_sigNonIsolated_; }
0353 void set_dnn_e_sigNonIsolated(float mva) { dnn_e_sigNonIsolated_ = mva; }
0354
0355
0356 float dnn_e_bkgNonIsolated() const { return dnn_e_bkgNonIsolated_; }
0357 void set_dnn_e_bkgNonIsolated(float mva) { dnn_e_bkgNonIsolated_ = mva; }
0358
0359
0360 float dnn_e_bkgTau() const { return dnn_e_bkgTau_; }
0361 void set_dnn_e_bkgTau(float mva) { dnn_e_bkgTau_ = mva; }
0362
0363
0364 float dnn_e_bkgPhoton() const { return dnn_e_bkgPhoton_; }
0365 void set_dnn_e_bkgPhoton(float mva) { dnn_e_bkgPhoton_ = mva; }
0366
0367
0368 float dnn_gamma() const { return dnn_gamma_; }
0369 void set_dnn_gamma(float mva) { dnn_gamma_ = mva; }
0370
0371
0372 float mva_gamma_nh() const { return mva_gamma_nh_; }
0373
0374
0375 void setPositionAtECALEntrance(const math::XYZPointF& pos) { positionAtECALEntrance_ = pos; }
0376
0377
0378 void setPFElectronExtraRef(const reco::PFCandidateElectronExtraRef& ref);
0379
0380
0381 void setMuonTrackType(const reco::Muon::MuonTrackType& type) { muonTrackType_ = type; }
0382
0383
0384
0385 const reco::Muon::MuonTrackType bestMuonTrackType() const { return muonTrackType_; }
0386
0387
0388 const math::XYZPointF& positionAtECALEntrance() const { return positionAtECALEntrance_; }
0389
0390
0391
0392 virtual ParticleType particleId() const { return translatePdgIdToType(pdgId()); }
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403 typedef std::pair<reco::PFBlockRef, unsigned> ElementInBlock;
0404 typedef std::vector<ElementInBlock> ElementsInBlocks;
0405
0406 typedef edm::RefVector<reco::PFBlockCollection> Blocks;
0407 typedef std::vector<unsigned> Elements;
0408
0409 const ElementsInBlocks& elementsInBlocks() const;
0410
0411 static constexpr float bigMva_ = -999.;
0412
0413 friend std::ostream& operator<<(std::ostream& out, const PFCandidate& c);
0414
0415 const Point& vertex() const override;
0416 double vx() const override { return vertex().x(); }
0417 double vy() const override { return vertex().y(); }
0418 double vz() const override { return vertex().z(); }
0419
0420
0421 bool isTimeValid() const { return timeError_ >= 0.f; }
0422
0423 float time() const { return time_; }
0424
0425 float timeError() const { return timeError_; }
0426
0427 void setTime(float time, float timeError = 0.f) {
0428 time_ = time;
0429 timeError_ = timeError;
0430 }
0431
0432
0433 float hcalDepthEnergyFraction(unsigned int depth) const { return hcalDepthEnergyFractions_[depth - 1]; }
0434
0435 const std::array<float, 7>& hcalDepthEnergyFractions() const { return hcalDepthEnergyFractions_; }
0436
0437 void setHcalDepthEnergyFractions(const std::array<float, 7>& fracs) { hcalDepthEnergyFractions_ = fracs; }
0438
0439 private:
0440
0441 const math::XYZPoint& vertexLegacy(PFCandidate::PFVertexType vertexType) const;
0442
0443
0444 bool overlap(const Candidate&) const override;
0445
0446 void setFlag(unsigned shift, unsigned flag, bool value);
0447
0448 bool flag(unsigned shift, unsigned flag) const;
0449
0450 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0451 mutable std::atomic<ElementsInBlocks*> elementsInBlocks_;
0452 #else
0453 mutable ElementsInBlocks* elementsInBlocks_;
0454 #endif
0455 Blocks blocksStorage_;
0456 Elements elementsStorage_;
0457
0458
0459
0460 PFCandidatePtr sourcePtr_;
0461
0462
0463
0464 reco::Muon::MuonTrackType muonTrackType_;
0465
0466
0467 float ecalERatio_;
0468
0469
0470 float hcalERatio_;
0471
0472
0473 float hoERatio_;
0474
0475
0476 float rawEcalEnergy_;
0477
0478
0479 float rawHcalEnergy_;
0480
0481
0482 float rawHoEnergy_;
0483
0484
0485 float ps1Energy_;
0486
0487
0488 float ps2Energy_;
0489
0490
0491 unsigned flags_;
0492
0493
0494 float deltaP_;
0495
0496
0497 PFVertexType vertexType_;
0498
0499
0500 float mva_Isolated_;
0501
0502
0503 float mva_e_pi_;
0504
0505
0506 float mva_e_mu_;
0507
0508
0509 float mva_pi_mu_;
0510
0511
0512 float mva_nothing_gamma_;
0513
0514
0515 float mva_nothing_nh_;
0516
0517
0518 float mva_gamma_nh_;
0519
0520
0521 float dnn_e_sigIsolated_;
0522
0523
0524 float dnn_e_sigNonIsolated_;
0525
0526
0527 float dnn_e_bkgNonIsolated_;
0528
0529
0530 float dnn_e_bkgTau_;
0531
0532
0533 float dnn_e_bkgPhoton_;
0534
0535
0536 float dnn_gamma_;
0537
0538
0539 math::XYZPointF positionAtECALEntrance_;
0540
0541
0542 void storeRefInfo(unsigned int iMask,
0543 unsigned int iBit,
0544 bool iIsValid,
0545 const edm::RefCore& iCore,
0546 size_t iKey,
0547 const edm::EDProductGetter*);
0548 bool getRefInfo(
0549 unsigned int iMask, unsigned int iBit, edm::ProductID& oProdID, size_t& oIndex, size_t& aIndex) const;
0550
0551 const edm::EDProductGetter* getter_;
0552 unsigned short storedRefsBitPattern_;
0553 std::vector<unsigned long long> refsInfo_;
0554 std::vector<const void*> refsCollectionCache_;
0555
0556
0557 float time_;
0558
0559 float timeError_;
0560
0561 std::array<float, 7> hcalDepthEnergyFractions_;
0562 };
0563
0564
0565 struct PFParticleIdTag {};
0566
0567
0568
0569
0570
0571
0572
0573 GET_CANDIDATE_COMPONENT(PFCandidate, PFCandidate::ParticleType, particleId, PFParticleIdTag);
0574
0575 std::ostream& operator<<(std::ostream& out, const PFCandidate& c);
0576
0577 }
0578
0579 #endif