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  switch (innerLost) {
149  case validHitInFirstPixelBarrelLayer:
150  hp.set(PXBDetId(1,0,0), TrackingRecHit::valid, i);
151  i++;
152  break;
153  case noLostInnerHits:
154  break;
155  case oneLostInnerHit:
156  hpExpIn.set(PXBDetId(1,0,0), TrackingRecHit::missing, 0);
157  break;
158  case moreLostInnerHits:
159  hpExpIn.set(PXBDetId(1,0,0), TrackingRecHit::missing, 0);
160  hpExpIn.set(PXBDetId(2,0,0), TrackingRecHit::missing, 1);
161  break;
162  };
163  for(;i<numberOfPixelHits_; i++) {
164  hp.set( PXBDetId(i>1?3:2,0,0), TrackingRecHit::valid, i);
165  }
166  for(;i<numberOfHits_;i++) {
167  hp.set( TIBDetId(1,0,0,1,1,0), TrackingRecHit::valid, i);
168  }
169  reco::Track tk(normalizedChi2_*ndof,ndof,vertex_,math::XYZVector(p3.x(),p3.y(),p3.z()),charge(),m,reco::TrackBase::undefAlgorithm,reco::TrackBase::loose);
170  tk.setHitPattern(hp);
171  tk.setTrackerExpectedHitsInner(hpExpIn);
172  if (trackHighPurity()) tk.setQuality(reco::TrackBase::highPurity);
173  return tk;
174 }
175 
177 
180 }
181 
184 }
185 
187  return iterator( new iterator_imp_specific );
188 }
189 
191  return iterator( new iterator_imp_specific );
192 }
193 
195  throw cms::Exception("Invalid Reference")
196  << "this Candidate has no master clone reference."
197  << "Can't call masterClone() method.\n";
198 }
199 
201  return false;
202 }
203 
205  return false;
206 }
207 
208 
210  throw cms::Exception("Invalid Reference")
211  << "this Candidate has no master clone ptr."
212  << "Can't call masterClonePtr() method.\n";
213 }
214 
216  return 0;
217 }
218 
220  return 0;
221 }
222 
224  return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
225 // return p4() == o.p4() && charge() == o.charge();
226 }
227 
229  return 0;
230 }
231 
233  return 0;
234 }
235 
238  << "This Candidate type does not implement daughter(std::string). "
239  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
240 }
241 
244  << "This Candidate type does not implement daughter(std::string). "
245  << "Please use CompositeCandidate or NamedCompositeCandidate.\n";
246 }
247 
248 
249 
251  return 0;
252 }
253 
255  return 0;
256 }
257 
259  return 0;
260 }
261 
263  return 0;
264 }
265 
268  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
269 }
270 
273  << "reco::ConcreteCandidate does not implement vertex covariant matrix.\n";
274 }
275 
276 
277 bool pat::PackedCandidate::longLived() const {return false;}
278 
279 bool pat::PackedCandidate::massConstraint() const {return false;}
280 
281 
282 
283 
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:34
virtual const_iterator begin() const
first daughter const_iterator
double unpack8log(int8_t i, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:32
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
void set(const I &begin, const I &end)
Definition: HitPattern.h:152
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
double charge(const std::vector< uint8_t > &Ampls)
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)
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
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.
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:244
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
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:45
void pack(bool unpackAfterwards=true)
virtual float dxy() const
dxy with respect to the PV ref
virtual const_iterator end() const
last daughter const_iterator
virtual double vertexChi2() const
chi-squares
virtual ~PackedCandidate()
destructor
virtual reco::Track pseudoTrack() const
Return by value (no caching heavy function) a pseudo track made with candidate kinematics, parameterized error for eta,phi,pt and full IP covariance.
virtual float dz() const
dz with respect to the PV ref
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:70
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:43