CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PackedCandidate.cc
Go to the documentation of this file.
6 
8 using namespace logintpack;
9 
10 void pat::PackedCandidate::pack(bool unpackAfterwards) {
11  packedPt_ = MiniFloatConverter::float32to16(p4_.Pt());
12  packedEta_ = int16_t(std::round(p4_.Eta()/6.0f*std::numeric_limits<int16_t>::max()));
13  packedPhi_ = int16_t(std::round(p4_.Phi()/3.2f*std::numeric_limits<int16_t>::max()));
14  packedM_ = MiniFloatConverter::float32to16(p4_.M());
15  if (unpackAfterwards) unpack(); // force the values to match with the packed ones
16 }
17 
18 void pat::PackedCandidate::packVtx(bool unpackAfterwards) {
19  Point pv = pvRef_.isNonnull() ? pvRef_->position() : Point();
20  float dxPV = vertex_.X() - pv.X(), dyPV = vertex_.Y() - pv.Y(); //, rPV = std::hypot(dxPV, dyPV);
21  float s = std::sin(float(p4_.Phi())+dphi_), c = std::cos(float(p4_.Phi()+dphi_)); // not the fastest option, but we're in reduced precision already, so let's avoid more roundoffs
22  dxy_ = - dxPV * s + dyPV * c;
23  // if we want to go back to the full x,y,z we need to store also
24  // float dl = dxPV * c + dyPV * s;
25  // float xRec = - dxy_ * s + dl * c, yRec = dxy_ * c + dl * s;
26  float pzpt = p4_.Pz()/p4_.Pt();
27  dz_ = vertex_.Z() - pv.Z() - (dxPV*c + dyPV*s) * pzpt;
28  packedDxy_ = MiniFloatConverter::float32to16(dxy_*100);
29  packedDz_ = pvRef_.isNonnull() ? MiniFloatConverter::float32to16(dz_*100) : int16_t(std::round(dz_/40.f*std::numeric_limits<int16_t>::max()));
30  packedDPhi_ = int16_t(std::round(dphi_/3.2f*std::numeric_limits<int16_t>::max()));
31  packedCovarianceDxyDxy_ = MiniFloatConverter::float32to16(dxydxy_*10000.);
32  packedCovarianceDxyDz_ = MiniFloatConverter::float32to16(dxydz_*10000.);
33  packedCovarianceDzDz_ = MiniFloatConverter::float32to16(dzdz_*10000.);
34 // packedCovarianceDxyDxy_ = pack8log(dxydxy_,-15,-1); // MiniFloatConverter::float32to16(dxydxy_*10000.);
35 // packedCovarianceDxyDz_ = pack8log(dxydz_,-20,-1); //MiniFloatConverter::float32to16(dxydz_*10000.);
36 // packedCovarianceDzDz_ = pack8log(dzdz_,-13,-1); //MiniFloatConverter::float32to16(dzdz_*10000.);
37 
38  packedCovarianceDptDpt_ = pack8logCeil(dptdpt_,-15,0);
39  packedCovarianceDetaDeta_ = pack8logCeil(detadeta_,-20,-5);
40  packedCovarianceDphiDphi_ = pack8logCeil(dphidphi_,-15,0);
41  packedCovarianceDphiDxy_ = pack8log(dphidxy_,-17,-4); // MiniFloatConverter::float32to16(dphidxy_*10000.);
42  packedCovarianceDlambdaDz_ = pack8log(dlambdadz_,-17,-4); // MiniFloatConverter::float32to16(dlambdadz_*10000.);
43 
44  /*packedCovarianceDptDpt_ = pack8logCeil(dptdpt_,-15,5,32);
45  packedCovarianceDetaDeta_ = pack8logCeil(detadeta_,-20,0,32);
46  packedCovarianceDphiDphi_ = pack8logCeil(dphidphi_,-15,5,32);
47  packedCovarianceDphiDxy_ = pack8log(dphidxy_,-17,-4); // MiniFloatConverter::float32to16(dphidxy_*10000.);
48  packedCovarianceDlambdaDz_ = pack8log(dlambdadz_,-17,-4); // MiniFloatConverter::float32to16(dlambdadz_*10000.);
49 
50 */
51 /* packedCovarianceDphiDxy_ = MiniFloatConverter::float32to16(dphidxy_*10000.);
52  packedCovarianceDlambdaDz_ = MiniFloatConverter::float32to16(dlambdadz_*10000.);
53  packedCovarianceDetaDeta_ = MiniFloatConverter::float32to16(detadeta_*10000.);
54  packedCovarianceDphiDphi_ = MiniFloatConverter::float32to16(dphidphi_*10000.);
55  packedCovarianceDptDpt_ = MiniFloatConverter::float32to16(dptdpt_*10000.);
56 */
57 // packedCovarianceDphiDxy_ = pack8log(dphidxy_,-17,-4); // MiniFloatConverter::float32to16(dphidxy_*10000.);
58 // packedCovarianceDlambdaDz_ = pack8log(dlambdadz_,-17,-4); // MiniFloatConverter::float32to16(dlambdadz_*10000.);
59 
60  if (unpackAfterwards) unpackVtx();
61 }
62 
64  float pt = MiniFloatConverter::float16to32(packedPt_);
65  double shift = (pt<1. ? 0.1*pt : 0.1/pt); // shift particle phi to break degeneracies in angular separations
66  double sign = ( ( int(pt*10) % 2 == 0 ) ? 1 : -1 ); // introduce a pseudo-random sign of the shift
67  double phi = int16_t(packedPhi_)*3.2f/std::numeric_limits<int16_t>::max() + sign*shift*3.2/std::numeric_limits<int16_t>::max();
68  p4_ = PolarLorentzVector(pt,
69  int16_t(packedEta_)*6.0f/std::numeric_limits<int16_t>::max(),
70  phi,
72  p4c_ = p4_;
73  unpacked_ = true;
74 }
76  dphi_ = int16_t(packedDPhi_)*3.2f/std::numeric_limits<int16_t>::max(),
77  dxy_ = MiniFloatConverter::float16to32(packedDxy_)/100.;
78  dz_ = pvRef_.isNonnull() ? MiniFloatConverter::float16to32(packedDz_)/100. : int16_t(packedDz_)*40.f/std::numeric_limits<int16_t>::max();
79  Point pv = pvRef_.isNonnull() ? pvRef_->position() : Point();
80  float phi = p4_.Phi()+dphi_, s = std::sin(phi), c = std::cos(phi);
81  vertex_ = Point(pv.X() - dxy_ * s,
82  pv.Y() + dxy_ * c,
83  pv.Z() + dz_ ); // for our choice of using the PCA to the PV, by definition the remaining term -(dx*cos(phi) + dy*sin(phi))*(pz/pt) is zero
84 // dxydxy_ = unpack8log(packedCovarianceDxyDxy_,-15,-1);
85 // dxydz_ = unpack8log(packedCovarianceDxyDz_,-20,-1);
86 // dzdz_ = unpack8log(packedCovarianceDzDz_,-13,-1);
87  dphidxy_ = unpack8log(packedCovarianceDphiDxy_,-17,-4);
88  dlambdadz_ = unpack8log(packedCovarianceDlambdaDz_,-17,-4);
89  dptdpt_ = unpack8log(packedCovarianceDptDpt_,-15,0);
90  detadeta_ = unpack8log(packedCovarianceDetaDeta_,-20,-5);
91  dphidphi_ = unpack8log(packedCovarianceDphiDphi_,-15,0);
92 /*
93  dphidxy_ = unpack8log(packedCovarianceDphiDxy_,-17,-4);
94  dlambdadz_ = unpack8log(packedCovarianceDlambdaDz_,-17,-4);
95  dptdpt_ = unpack8log(packedCovarianceDptDpt_,-15,5,32);
96  detadeta_ = unpack8log(packedCovarianceDetaDeta_,-20,0,32);
97  dphidphi_ = unpack8log(packedCovarianceDphiDphi_,-15,5,32);
98 */
99 
100 /* dphidxy_ = MiniFloatConverter::float16to32(packedCovarianceDphiDxy_)/10000.;
101  dlambdadz_ = MiniFloatConverter::float16to32(packedCovarianceDlambdaDz_)/10000.;
102  dptdpt_ = MiniFloatConverter::float16to32(packedCovarianceDptDpt_)/10000.;
103  detadeta_ = MiniFloatConverter::float16to32(packedCovarianceDetaDeta_)/10000.;
104  dphidphi_ = MiniFloatConverter::float16to32(packedCovarianceDphiDphi_)/10000.;
105 */
106  dxydxy_ = MiniFloatConverter::float16to32(packedCovarianceDxyDxy_)/10000.;
107  dxydz_ =MiniFloatConverter::float16to32(packedCovarianceDxyDz_)/10000.;
108  dzdz_ =MiniFloatConverter::float16to32(packedCovarianceDzDz_)/10000.;
109 /* dphidxy_ = MiniFloatConverter::float16to32(packedCovarianceDphiDxy_)/10000.;
110  dlambdadz_ =MiniFloatConverter::float16to32(packedCovarianceDlambdaDz_)/10000.;
111 */
112  unpackedVtx_ = true;
113 }
114 
116 
117 
118 float pat::PackedCandidate::dxy(const Point &p) const {
119  maybeUnpackBoth();
120  return -(vertex_.X()-p.X()) * std::sin(float(p4_.Phi())) + (vertex_.Y()-p.Y()) * std::cos(float(p4_.Phi()));
121 }
122 float pat::PackedCandidate::dz(const Point &p) const {
123  maybeUnpackBoth();
124  return (vertex_.Z()-p.Z()) - ((vertex_.X()-p.X()) * std::cos(float(p4_.Phi())) + (vertex_.Y()-p.Y()) * std::sin(float(p4_.Phi()))) * p4_.Pz()/p4_.Pt();
125 }
126 
128  maybeUnpackBoth();
130 // m(0,0)=0.5e-4/pt()/pt(); //TODO: tune
131 // m(1,1)=6e-6; //TODO: tune
132 // m(2,2)=1.5e-5/pt()/pt(); //TODO: tune
133  m(0,0)=dptdpt_/pt()/pt(); //TODO: tune
134  m(1,1)=detadeta_; //TODO: tune
135  m(2,2)=dphidphi_/pt()/pt(); //TODO: tune
136  m(2,3)=dphidxy_;
137  m(3,2)=dphidxy_;
138  m(4,1)=dlambdadz_;
139  m(1,4)=dlambdadz_;
140  m(3,3)=dxydxy_;
141  m(3,4)=dxydz_;
142  m(4,3)=dxydz_;
143  m(4,4)=dzdz_;
144  math::RhoEtaPhiVector p3(p4_.pt(),p4_.eta(),phiAtVtx());
145  int numberOfPixelHits_ = packedHits_ & 0x7 ;
146  int numberOfHits_ = (packedHits_>>3) + numberOfPixelHits_;
147 
148  int ndof = numberOfHits_+numberOfPixelHits_-5;
149  reco::HitPattern hp, hpExpIn;
150  int i=0;
151  LostInnerHits innerLost = lostInnerHits();
152 
153  track_ = reco::Track(normalizedChi2_*ndof,ndof,vertex_,math::XYZVector(p3.x(),p3.y(),p3.z()),charge(),m,reco::TrackBase::undefAlgorithm,reco::TrackBase::loose);
154 
155  if(innerLost == validHitInFirstPixelBarrelLayer){
157  i++;
158  }
159  for(;i<numberOfPixelHits_; i++) {
160  track_.appendHitPattern(PXBDetId(i > 1 ? 3 : 2, 0, 0), TrackingRecHit::valid);
161  }
162 
163  for(;i<numberOfHits_;i++) {
164  track_.appendHitPattern(TIBDetId(1, 0, 0, 1, 1, 0), TrackingRecHit::valid);
165  }
166 
167  switch (innerLost) {
168  case validHitInFirstPixelBarrelLayer:
169  break;
170  case noLostInnerHits:
171  break;
172  case oneLostInnerHit:
173  track_.appendHitPattern(PXBDetId(1, 0, 0), TrackingRecHit::missing_inner);
174  break;
175  case moreLostInnerHits:
176  track_.appendHitPattern(PXBDetId(1, 0, 0), TrackingRecHit::missing_inner);
177  track_.appendHitPattern(PXBDetId(2, 0, 0), TrackingRecHit::missing_inner);
178  break;
179  };
180 
181  if (trackHighPurity()) track_.setQuality(reco::TrackBase::highPurity);
182 
183  unpackedTrk_ = true;
184 }
185 
187 
189  throw cms::Exception("Invalid Reference")
190  << "this Candidate has no master clone reference."
191  << "Can't call masterClone() method.\n";
192 }
193 
195  return false;
196 }
197 
199  return false;
200 }
201 
202 
204  throw cms::Exception("Invalid Reference")
205  << "this Candidate has no master clone ptr."
206  << "Can't call masterClonePtr() method.\n";
207 }
208 
210  return 0;
211 }
212 
214  return 0;
215 }
216 
218  return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
219 // return p4() == o.p4() && charge() == o.charge();
220 }
221 
223  return 0;
224 }
225 
227  return 0;
228 }
229 
232  << "This Candidate type does not implement daughter(std::string). "
233  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
234 }
235 
238  << "This Candidate type does not implement daughter(std::string). "
239  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
240 }
241 
242 
243 
245  return 0;
246 }
247 
249  return 0;
250 }
251 
253  return 0;
254 }
255 
257  return 0;
258 }
259 
262  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
263 }
264 
267  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
268 }
269 
270 
271 bool pat::PackedCandidate::longLived() const {return false;}
272 
273 bool pat::PackedCandidate::massConstraint() const {return false;}
274 
275 // puppiweight
276 // puppiweight
277 void pat::PackedCandidate::setPuppiWeight(float p, float p_nolep) {
278  // Set both weights at once to avoid misconfigured weights if called in the wrong order
279  packedPuppiweight_ = pack8logClosed((p-0.5)*2,-2,0,64);
280  packedPuppiweightNoLepDiff_ = pack8logClosed((p_nolep-0.5)*2,-2,0,64) - packedPuppiweight_;
281 }
282 
283 float pat::PackedCandidate::puppiWeight() const { return unpack8logClosed(packedPuppiweight_,-2,0,64)/2. + 0.5;}
284 
285 float pat::PackedCandidate::puppiWeightNoLep() const { return unpack8logClosed(packedPuppiweightNoLepDiff_+packedPuppiweight_,-2,0,64)/2. + 0.5;}
float puppiWeight() const
Set both weights at once (with option for only full PUPPI)
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
int i
Definition: DBlmapReader.cc:9
virtual size_t numberOfMothers() const
number of mothers
virtual bool hasMasterClonePtr() const
float puppiWeightNoLep() const
Weight from full PUPPI.
void setPuppiWeight(float p, float p_nolep=0.0)
size_t size_type
Definition: Candidate.h:30
double unpack8log(int8_t i, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:47
int8_t pack8log(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:20
virtual void fillVertexCovariance(CovarianceMatrix &v) const
fill SMatrix
double sign(double x)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
virtual double vertexNdof() const
virtual bool overlap(const reco::Candidate &) const
check overlap with another Candidate
std::pair< double, double > Point
Definition: CaloEllipse.h:18
void unpackVtx() const
RhoEtaPhiVectorD RhoEtaPhiVector
spatial vector with cylindrical internal representation using pseudorapidity
Definition: Vector3D.h:32
static float float16to32(uint16_t h)
Definition: libminifloat.h:10
int8_t pack8logCeil(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:8
virtual const reco::Candidate * daughter(size_type) const
return daughter at a given position (throws an exception)
int8_t pack8logClosed(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:34
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
double p4[4]
Definition: TauolaWrapper.h:92
static uint16_t float32to16(float x)
Definition: libminifloat.h:15
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual const reco::CandidateBaseRef & masterClone() const
int j
Definition: DBlmapReader.cc:9
bool appendHitPattern(const TrackingRecHit &hit)
append a single hit to the HitPattern
Definition: TrackBase.h:421
double f[11][100]
virtual const Point & vertex() const =0
vertex position
virtual double vertexNormalizedChi2() const
chi-squared divided by n.d.o.f.
virtual int charge() const =0
electric charge
virtual const reco::CandidatePtr & masterClonePtr() const
LostInnerHits
Enumerator specifying the.
virtual bool massConstraint() const
do mass constraint?
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
virtual size_t numberOfDaughters() const
number of daughters
CovarianceMatrix vertexCovariance() const
return SMatrix
double unpack8logClosed(int8_t i, double lmin, double lmax, uint8_t base=128)
reverse of pack8logClosed
Definition: liblogintpack.h:57
virtual bool longLived() const
is long lived?
virtual const reco::Candidate * mother(size_type) const
return mother at a given position (throws an exception)
void packVtx(bool unpackAfterwards=true)
static unsigned int const shift
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
void pack(bool unpackAfterwards=true)
virtual float dxy() const
dxy with respect to the PV ref
virtual double vertexChi2() const
chi-squares
virtual ~PackedCandidate()
destructor
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77
virtual bool hasMasterClone() const
double p3[4]
Definition: TauolaWrapper.h:91
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
Definition: DDAxes.h:10
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39