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 
65  int16_t(packedEta_)*6.0f/std::numeric_limits<int16_t>::max(),
66  int16_t(packedPhi_)*3.2f/std::numeric_limits<int16_t>::max(),
68  p4c_ = p4_;
69  unpacked_ = true;
70 }
72  dphi_ = int16_t(packedDPhi_)*3.2f/std::numeric_limits<int16_t>::max(),
73  dxy_ = MiniFloatConverter::float16to32(packedDxy_)/100.;
74  dz_ = pvRef_.isNonnull() ? MiniFloatConverter::float16to32(packedDz_)/100. : int16_t(packedDz_)*40.f/std::numeric_limits<int16_t>::max();
75  Point pv = pvRef_.isNonnull() ? pvRef_->position() : Point();
76  float phi = p4_.Phi()+dphi_, s = std::sin(phi), c = std::cos(phi);
77  vertex_ = Point(pv.X() - dxy_ * s,
78  pv.Y() + dxy_ * c,
79  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
80 // dxydxy_ = unpack8log(packedCovarianceDxyDxy_,-15,-1);
81 // dxydz_ = unpack8log(packedCovarianceDxyDz_,-20,-1);
82 // dzdz_ = unpack8log(packedCovarianceDzDz_,-13,-1);
83  dphidxy_ = unpack8log(packedCovarianceDphiDxy_,-17,-4);
84  dlambdadz_ = unpack8log(packedCovarianceDlambdaDz_,-17,-4);
85  dptdpt_ = unpack8log(packedCovarianceDptDpt_,-15,0);
86  detadeta_ = unpack8log(packedCovarianceDetaDeta_,-20,-5);
87  dphidphi_ = unpack8log(packedCovarianceDphiDphi_,-15,0);
88 /*
89  dphidxy_ = unpack8log(packedCovarianceDphiDxy_,-17,-4);
90  dlambdadz_ = unpack8log(packedCovarianceDlambdaDz_,-17,-4);
91  dptdpt_ = unpack8log(packedCovarianceDptDpt_,-15,5,32);
92  detadeta_ = unpack8log(packedCovarianceDetaDeta_,-20,0,32);
93  dphidphi_ = unpack8log(packedCovarianceDphiDphi_,-15,5,32);
94 */
95 
96 /* dphidxy_ = MiniFloatConverter::float16to32(packedCovarianceDphiDxy_)/10000.;
97  dlambdadz_ = MiniFloatConverter::float16to32(packedCovarianceDlambdaDz_)/10000.;
98  dptdpt_ = MiniFloatConverter::float16to32(packedCovarianceDptDpt_)/10000.;
99  detadeta_ = MiniFloatConverter::float16to32(packedCovarianceDetaDeta_)/10000.;
100  dphidphi_ = MiniFloatConverter::float16to32(packedCovarianceDphiDphi_)/10000.;
101 */
102  dxydxy_ = MiniFloatConverter::float16to32(packedCovarianceDxyDxy_)/10000.;
103  dxydz_ =MiniFloatConverter::float16to32(packedCovarianceDxyDz_)/10000.;
104  dzdz_ =MiniFloatConverter::float16to32(packedCovarianceDzDz_)/10000.;
105 /* dphidxy_ = MiniFloatConverter::float16to32(packedCovarianceDphiDxy_)/10000.;
106  dlambdadz_ =MiniFloatConverter::float16to32(packedCovarianceDlambdaDz_)/10000.;
107 */
108  unpackedVtx_ = true;
109 }
110 
112 
113 
114 float pat::PackedCandidate::dxy(const Point &p) const {
115  maybeUnpackBoth();
116  return -(vertex_.X()-p.X()) * std::sin(float(p4_.Phi())) + (vertex_.Y()-p.Y()) * std::cos(float(p4_.Phi()));
117 }
118 float pat::PackedCandidate::dz(const Point &p) const {
119  maybeUnpackBoth();
120  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();
121 }
122 
124  maybeUnpackBoth();
126 // m(0,0)=0.5e-4/pt()/pt(); //TODO: tune
127 // m(1,1)=6e-6; //TODO: tune
128 // m(2,2)=1.5e-5/pt()/pt(); //TODO: tune
129  m(0,0)=dptdpt_/pt()/pt(); //TODO: tune
130  m(1,1)=detadeta_; //TODO: tune
131  m(2,2)=dphidphi_/pt()/pt(); //TODO: tune
132  m(2,3)=dphidxy_;
133  m(3,2)=dphidxy_;
134  m(4,1)=dlambdadz_;
135  m(1,4)=dlambdadz_;
136  m(3,3)=dxydxy_;
137  m(3,4)=dxydz_;
138  m(4,3)=dxydz_;
139  m(4,4)=dzdz_;
140  math::RhoEtaPhiVector p3(p4_.pt(),p4_.eta(),phiAtVtx());
141  int numberOfPixelHits_ = packedHits_ & 0x7 ;
142  int numberOfHits_ = (packedHits_>>3) + numberOfPixelHits_;
143 
144  int ndof = numberOfHits_+numberOfPixelHits_-5;
145  reco::HitPattern hp, hpExpIn;
146  int i=0;
147  LostInnerHits innerLost = lostInnerHits();
148 
149  track_ = reco::Track(normalizedChi2_*ndof,ndof,vertex_,math::XYZVector(p3.x(),p3.y(),p3.z()),charge(),m,reco::TrackBase::undefAlgorithm,reco::TrackBase::loose);
150 
151  if(innerLost == validHitInFirstPixelBarrelLayer){
153  i++;
154  }
155  for(;i<numberOfPixelHits_; i++) {
156  track_.appendHitPattern(PXBDetId(i > 1 ? 3 : 2, 0, 0), TrackingRecHit::valid);
157  }
158 
159  for(;i<numberOfHits_;i++) {
160  track_.appendHitPattern(TIBDetId(1, 0, 0, 1, 1, 0), TrackingRecHit::valid);
161  }
162 
163  switch (innerLost) {
164  case validHitInFirstPixelBarrelLayer:
165  break;
166  case noLostInnerHits:
167  break;
168  case oneLostInnerHit:
169  track_.appendHitPattern(PXBDetId(1, 0, 0), TrackingRecHit::missing_inner);
170  break;
171  case moreLostInnerHits:
172  track_.appendHitPattern(PXBDetId(1, 0, 0), TrackingRecHit::missing_inner);
173  track_.appendHitPattern(PXBDetId(2, 0, 0), TrackingRecHit::missing_inner);
174  break;
175  };
176 
177  if (trackHighPurity()) track_.setQuality(reco::TrackBase::highPurity);
178 
179  unpackedTrk_ = true;
180 }
181 
183 
185  throw cms::Exception("Invalid Reference")
186  << "this Candidate has no master clone reference."
187  << "Can't call masterClone() method.\n";
188 }
189 
191  return false;
192 }
193 
195  return false;
196 }
197 
198 
200  throw cms::Exception("Invalid Reference")
201  << "this Candidate has no master clone ptr."
202  << "Can't call masterClonePtr() method.\n";
203 }
204 
206  return 0;
207 }
208 
210  return 0;
211 }
212 
214  return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
215 // return p4() == o.p4() && charge() == o.charge();
216 }
217 
219  return 0;
220 }
221 
223  return 0;
224 }
225 
228  << "This Candidate type does not implement daughter(std::string). "
229  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
230 }
231 
234  << "This Candidate type does not implement daughter(std::string). "
235  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
236 }
237 
238 
239 
241  return 0;
242 }
243 
245  return 0;
246 }
247 
249  return 0;
250 }
251 
253  return 0;
254 }
255 
258  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
259 }
260 
263  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
264 }
265 
266 
267 bool pat::PackedCandidate::longLived() const {return false;}
268 
269 bool pat::PackedCandidate::massConstraint() const {return false;}
270 
271 // puppiweight
272 void pat::PackedCandidate::setPuppiWeight(float p) { packedPuppiweight_ = pack8logClosed((p-0.5)*2,-2,0,64);}
273 
274 float pat::PackedCandidate::puppiWeight() const { return unpack8logClosed(packedPuppiweight_,-2,0,64)/2. + 0.5;}
275 
float puppiWeight() const
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
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
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
void setPuppiWeight(float p)
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)
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