CMS 3D CMS Logo

PackedGenParticle.cc
Go to the documentation of this file.
4 
5 
6 
7 void pat::PackedGenParticle::pack(bool unpackAfterwards) {
9  packedY_ = int16_t(p4_.load()->Rapidity()/6.0f*std::numeric_limits<int16_t>::max());
10  packedPhi_ = int16_t(p4_.load()->Phi()/3.2f*std::numeric_limits<int16_t>::max());
12  if (unpackAfterwards) {
13  delete p4_.exchange(nullptr);
14  delete p4c_.exchange(nullptr);
15  unpack(); // force the values to match with the packed ones
16  }
17 }
18 
19 
21  float y = int16_t(packedY_)*6.0f/std::numeric_limits<int16_t>::max();
24  float pz = std::tanh(y)*std::sqrt((m*m+pt*pt)/(1.-std::tanh(y)*std::tanh(y)));
25  float eta = 0;
26  if(pt != 0.) {
27  eta = std::asinh(pz/pt);
28  }
29  double shift = (pt<1. ? 0.1*pt : 0.1/pt); // shift particle phi to break degeneracies in angular separations
30  double sign = ( ( int(pt*10) % 2 == 0 ) ? 1 : -1 ); // introduce a pseudo-random sign of the shift
31  double phi = int16_t(packedPhi_)*3.2f/std::numeric_limits<int16_t>::max() + sign*shift*3.2/std::numeric_limits<int16_t>::max();
32  auto p4 = std::make_unique<PolarLorentzVector>(pt,eta,phi,m);
33  PolarLorentzVector* expectp4 = nullptr;
34  if(p4_.compare_exchange_strong(expectp4,p4.get())) {
35  p4.release();
36  }
37  auto p4c = std::make_unique<LorentzVector>(*p4_);
38  LorentzVector* expectp4c = nullptr;
39  if(p4c_.compare_exchange_strong(expectp4c,p4c.get())) {
40  p4c.release();
41  }
42 }
43 
45  delete p4_.load();
46  delete p4c_.load();
47  }
48 
49 
50 float pat::PackedGenParticle::dxy(const Point &p) const {
51  unpack();
52  return -(vertex_.X()-p.X()) * std::sin(float(p4_.load()->Phi())) + (vertex_.Y()-p.Y()) * std::cos(float(p4_.load()->Phi()));
53 }
54 float pat::PackedGenParticle::dz(const Point &p) const {
55  unpack();
56  return (vertex_.Z()-p.X()) - ((vertex_.X()-p.X()) * std::cos(float(p4_.load()->Phi())) + (vertex_.Y()-p.Y()) * std::sin(float(p4_.load()->Phi()))) * p4_.load()->Pz()/p4_.load()->Pt();
57 }
58 
59 
61 
63  throw cms::Exception("Invalid Reference")
64  << "this Candidate has no master clone reference."
65  << "Can't call masterClone() method.\n";
66 }
67 
69  return false;
70 }
71 
73  return false;
74 }
75 
76 
78  throw cms::Exception("Invalid Reference")
79  << "this Candidate has no master clone ptr."
80  << "Can't call masterClonePtr() method.\n";
81 }
82 
84  return 0;
85 }
86 
88  if(motherRef().isNonnull()) return 1;
89  return 0;
90 }
91 
93  return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
94 // return p4() == o.p4() && charge() == o.charge();
95 }
96 
98  return nullptr;
99 }
100 
102  return motherRef().get();
103 }
104 
107  << "This Candidate type does not implement daughter(std::string). "
108  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
109 }
110 
113  << "This Candidate type does not implement daughter(std::string). "
114  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
115 }
116 
117 
118 
120  return nullptr;
121 }
122 
124  return 0;
125 }
126 
128  return 0;
129 }
130 
132  return 0;
133 }
134 
135 double pat::PackedGenParticle::vertexCovariance(int i, int j) const {
137  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
138 }
139 
142  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
143 }
144 
145 bool pat::PackedGenParticle::isElectron() const { return false; }
146 
147 bool pat::PackedGenParticle::isMuon() const { return false; }
148 
149 bool pat::PackedGenParticle::isGlobalMuon() const { return false; }
150 
151 bool pat::PackedGenParticle::isStandAloneMuon() const { return false; }
152 
153 bool pat::PackedGenParticle::isTrackerMuon() const { return false; }
154 
155 bool pat::PackedGenParticle::isCaloMuon() const { return false; }
156 
157 bool pat::PackedGenParticle::isPhoton() const { return false; }
158 
159 bool pat::PackedGenParticle::isConvertedPhoton() const { return false; }
160 
161 bool pat::PackedGenParticle::isJet() const { return false; }
162 
163 bool pat::PackedGenParticle::longLived() const {return false;}
164 
165 bool pat::PackedGenParticle::massConstraint() const {return false;}
166 
167 
168 
169 
bool isConvertedPhoton() const override
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
bool isTrackerMuon() const override
Point vertex_
vertex position
bool isElectron() const override
get a component
size_t size_type
Definition: Candidate.h:30
double eta() const override
momentum pseudorapidity
bool isGlobalMuon() const override
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
CovarianceMatrix vertexCovariance() const override
return SMatrix
bool massConstraint() const override
do mass constraint?
const reco::CandidatePtr & masterClonePtr() const override
bool isPhoton() const override
double pz() const override
z coordinate of momentum vector
static float float16to32(uint16_t h)
Definition: libminifloat.h:12
std::atomic< LorentzVector * > p4c_
void pack(bool unpackAfterwards=true)
reco::GenParticleRef motherRef() const
direct access to the mother reference (may be null)
double pt() const override
transverse momentum
double p() const override
magnitude of momentum vector
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
bool isCaloMuon() const override
T sqrt(T t)
Definition: SSEVec.h:18
static uint16_t float32to16(float x)
Definition: libminifloat.h:17
bool hasMasterClonePtr() const override
size_t numberOfDaughters() const override
number of daughters
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
~PackedGenParticle() override
destructor
bool longLived() const override
is long lived?
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
std::atomic< PolarLorentzVector * > p4_
the four vector
int charge() const override
electric charge
const Point & vertex() const override
vertex position
double vertexNdof() const override
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
bool isJet() const override
virtual int charge() const =0
electric charge
const reco::CandidateBaseRef & masterClone() const override
static unsigned int const shift
bool hasMasterClone() const override
double phi() const override
momentum azimuthal angle
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
virtual const Point & vertex() const =0
vertex position
double y() const override
rapidity
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
virtual float dz() const
dz with respect to the PV ref
size_t numberOfMothers() const override
number of mothers
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
virtual float dxy() const
dxy with respect to the PV ref
bool isStandAloneMuon() const override
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
double vertexChi2() const override
chi-squares
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39
bool isMuon() const override