File indexing completed on 2024-04-06 12:04:58
0001 #include "DataFormats/PatCandidates/interface/PackedGenParticle.h"
0002 #include "DataFormats/Math/interface/libminifloat.h"
0003 #include "DataFormats/Math/interface/deltaPhi.h"
0004
0005 void pat::PackedGenParticle::pack(bool unpackAfterwards) {
0006 packedPt_ = MiniFloatConverter::float32to16(p4_.load()->Pt());
0007 packedY_ = int16_t(p4_.load()->Rapidity() / 6.0f * std::numeric_limits<int16_t>::max());
0008 packedPhi_ = int16_t(p4_.load()->Phi() / 3.2f * std::numeric_limits<int16_t>::max());
0009 packedM_ = MiniFloatConverter::float32to16(p4_.load()->M());
0010 if (unpackAfterwards) {
0011 delete p4_.exchange(nullptr);
0012 delete p4c_.exchange(nullptr);
0013 unpack();
0014 }
0015 }
0016
0017 void pat::PackedGenParticle::unpack() const {
0018 float y = int16_t(packedY_) * 6.0f / std::numeric_limits<int16_t>::max();
0019 float pt = MiniFloatConverter::float16to32(packedPt_);
0020 float m = MiniFloatConverter::float16to32(packedM_);
0021 float pz = std::tanh(y) * std::sqrt((m * m + pt * pt) / (1. - std::tanh(y) * std::tanh(y)));
0022 float eta = 0;
0023 if (pt != 0.) {
0024 eta = std::asinh(pz / pt);
0025 }
0026 double shift = (pt < 1. ? 0.1 * pt : 0.1 / pt);
0027 double sign = ((int(pt * 10) % 2 == 0) ? 1 : -1);
0028 double phi = int16_t(packedPhi_) * 3.2f / std::numeric_limits<int16_t>::max() +
0029 sign * shift * 3.2 / std::numeric_limits<int16_t>::max();
0030 auto p4 = std::make_unique<PolarLorentzVector>(pt, eta, phi, m);
0031 PolarLorentzVector* expectp4 = nullptr;
0032 if (p4_.compare_exchange_strong(expectp4, p4.get())) {
0033 p4.release();
0034 }
0035 auto p4c = std::make_unique<LorentzVector>(*p4_);
0036 LorentzVector* expectp4c = nullptr;
0037 if (p4c_.compare_exchange_strong(expectp4c, p4c.get())) {
0038 p4c.release();
0039 }
0040 }
0041
0042 pat::PackedGenParticle::~PackedGenParticle() {
0043 delete p4_.load();
0044 delete p4c_.load();
0045 }
0046
0047 float pat::PackedGenParticle::dxy(const Point& p) const {
0048 unpack();
0049 return -(vertex_.X() - p.X()) * std::sin(float(p4_.load()->Phi())) +
0050 (vertex_.Y() - p.Y()) * std::cos(float(p4_.load()->Phi()));
0051 }
0052 float pat::PackedGenParticle::dz(const Point& p) const {
0053 unpack();
0054 return (vertex_.Z() - p.X()) - ((vertex_.X() - p.X()) * std::cos(float(p4_.load()->Phi())) +
0055 (vertex_.Y() - p.Y()) * std::sin(float(p4_.load()->Phi()))) *
0056 p4_.load()->Pz() / p4_.load()->Pt();
0057 }
0058
0059
0060
0061 const reco::CandidateBaseRef& pat::PackedGenParticle::masterClone() const {
0062 throw cms::Exception("Invalid Reference") << "this Candidate has no master clone reference."
0063 << "Can't call masterClone() method.\n";
0064 }
0065
0066 bool pat::PackedGenParticle::hasMasterClone() const { return false; }
0067
0068 bool pat::PackedGenParticle::hasMasterClonePtr() const { return false; }
0069
0070 const reco::CandidatePtr& pat::PackedGenParticle::masterClonePtr() const {
0071 throw cms::Exception("Invalid Reference") << "this Candidate has no master clone ptr."
0072 << "Can't call masterClonePtr() method.\n";
0073 }
0074
0075 size_t pat::PackedGenParticle::numberOfDaughters() const { return 0; }
0076
0077 size_t pat::PackedGenParticle::numberOfMothers() const {
0078 if (motherRef().isNonnull())
0079 return 1;
0080 return 0;
0081 }
0082
0083 bool pat::PackedGenParticle::overlap(const reco::Candidate& o) const {
0084 return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
0085
0086 }
0087
0088 const reco::Candidate* pat::PackedGenParticle::daughter(size_type) const { return nullptr; }
0089
0090 const reco::Candidate* pat::PackedGenParticle::mother(size_type) const { return motherRef().get(); }
0091
0092 const reco::Candidate* pat::PackedGenParticle::daughter(const std::string&) const {
0093 throw edm::Exception(edm::errors::UnimplementedFeature)
0094 << "This Candidate type does not implement daughter(std::string). "
0095 << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
0096 }
0097
0098 reco::Candidate* pat::PackedGenParticle::daughter(const std::string&) {
0099 throw edm::Exception(edm::errors::UnimplementedFeature)
0100 << "This Candidate type does not implement daughter(std::string). "
0101 << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
0102 }
0103
0104 reco::Candidate* pat::PackedGenParticle::daughter(size_type) { return nullptr; }
0105
0106 double pat::PackedGenParticle::vertexChi2() const { return 0; }
0107
0108 double pat::PackedGenParticle::vertexNdof() const { return 0; }
0109
0110 double pat::PackedGenParticle::vertexNormalizedChi2() const { return 0; }
0111
0112 double pat::PackedGenParticle::vertexCovariance(int i, int j) const {
0113 throw edm::Exception(edm::errors::UnimplementedFeature)
0114 << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
0115 }
0116
0117 void pat::PackedGenParticle::fillVertexCovariance(CovarianceMatrix& err) const {
0118 throw edm::Exception(edm::errors::UnimplementedFeature)
0119 << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
0120 }
0121
0122 bool pat::PackedGenParticle::isElectron() const { return false; }
0123
0124 bool pat::PackedGenParticle::isMuon() const { return false; }
0125
0126 bool pat::PackedGenParticle::isGlobalMuon() const { return false; }
0127
0128 bool pat::PackedGenParticle::isStandAloneMuon() const { return false; }
0129
0130 bool pat::PackedGenParticle::isTrackerMuon() const { return false; }
0131
0132 bool pat::PackedGenParticle::isCaloMuon() const { return false; }
0133
0134 bool pat::PackedGenParticle::isPhoton() const { return false; }
0135
0136 bool pat::PackedGenParticle::isConvertedPhoton() const { return false; }
0137
0138 bool pat::PackedGenParticle::isJet() const { return false; }
0139
0140 bool pat::PackedGenParticle::longLived() const { return false; }
0141
0142 bool pat::PackedGenParticle::massConstraint() const { return false; }