9 #include "TMatrixDSym.h" 19 packedEta_ = int16_t(std::round(p4_.load()->Eta() / 6.0f *
21 packedPhi_ = int16_t(std::round(p4_.load()->Phi() / 3.2f *
24 if (unpackAfterwards) {
25 delete p4_.exchange(
nullptr);
26 delete p4c_.exchange(
nullptr);
34 float dxPV = vertex_.load()->X() - pv.X(),
35 dyPV = vertex_.load()->Y() - pv.Y();
36 float s =
std::sin(
float(p4_.load()->Phi()) + dphi_),
38 float(p4_.load()->Phi() +
41 dxy_ = -dxPV * s + dyPV *
c;
45 float pzpt = p4_.load()->Pz() / p4_.load()->Pt();
46 dz_ = vertex_.load()->Z() - pv.Z() - (dxPV * c + dyPV *
s) * pzpt;
50 : int16_t(std::round(dz_ / 40.
f *
57 if (unpackAfterwards) {
58 delete vertex_.exchange(
nullptr);
66 (pt < 1. ? 0.1 * pt : 0.1 /
pt);
68 double sign = ((
int(pt * 10) % 2 == 0)
74 auto p4 = std::make_unique<PolarLorentzVector>(
77 auto p4c = std::make_unique<LorentzVector>(*p4);
79 if (p4_.compare_exchange_strong(expectp4, p4.get())) {
86 if (p4c_.compare_exchange_strong(expectp4c, p4c.get())) {
93 packedCovariance_.dptdpt = packCovarianceElement(m, 0, 0);
94 packedCovariance_.detadeta = packCovarianceElement(m, 1, 1);
95 packedCovariance_.dphidphi = packCovarianceElement(m, 2, 2);
96 packedCovariance_.dxydxy = packCovarianceElement(m, 3, 3);
97 packedCovariance_.dzdz = packCovarianceElement(m, 4, 4);
98 packedCovariance_.dxydz = packCovarianceElement(m, 3, 4);
99 packedCovariance_.dlambdadz = packCovarianceElement(m, 1, 4);
100 packedCovariance_.dphidxy = packCovarianceElement(m, 2, 3);
102 if (unpackAfterwards)
109 auto m = std::make_unique<reco::TrackBase::CovarianceMatrix>();
110 for (
int i = 0;
i < 5;
i++)
111 for (
int j = 0; j < 5; j++) {
114 unpackCovarianceElement(*
m, packedCovariance_.dptdpt, 0, 0);
115 unpackCovarianceElement(*
m, packedCovariance_.detadeta, 1, 1);
116 unpackCovarianceElement(*
m, packedCovariance_.dphidphi, 2, 2);
117 unpackCovarianceElement(*
m, packedCovariance_.dxydxy, 3, 3);
118 unpackCovarianceElement(*
m, packedCovariance_.dzdz, 4, 4);
119 unpackCovarianceElement(*
m, packedCovariance_.dxydz, 3, 4);
120 unpackCovarianceElement(*
m, packedCovariance_.dlambdadz, 1, 4);
121 unpackCovarianceElement(*
m, packedCovariance_.dphidxy, 2, 3);
123 if (m_.compare_exchange_strong(expected,
m.get())) {
129 <<
"You do not have a valid track parameters file loaded. " 130 <<
"Please check that the release version is compatible with your " 132 <<
"or avoid accessing track parameter uncertainties. ";
147 auto vertex = std::make_unique<Point>(
148 pv.X() - dxy_ *
s, pv.Y() + dxy_ *
c,
153 Point *expected =
nullptr;
154 if (vertex_.compare_exchange_strong(expected, vertex.get())) {
162 delete vertex_.load();
163 delete track_.load();
169 const float phi =
float(p4_.load()->Phi()) + dphi_;
170 return -(vertex_.load()->X() - p.X()) *
std::sin(phi) +
171 (vertex_.load()->Y() - p.Y()) *
std::cos(phi);
175 const float phi =
float(p4_.load()->Phi()) + dphi_;
177 deta_ ? std::sinh(etaAtVtx()) : p4_.load()->Pz() / p4_.load()->Pt();
178 return (vertex_.load()->Z() - p.Z()) -
179 ((vertex_.load()->X() - p.X()) *
std::cos(phi) +
180 (vertex_.load()->Y() - p.Y()) *
std::sin(phi)) *
198 TMatrixDSym eigenCov(5);
199 for (
int i = 0;
i < 5;
i++) {
200 for (
int j = 0; j < 5; j++) {
202 eigenCov(
i, j) = 1
e-6;
204 eigenCov(
i, j) = (
m)(
i, j);
207 TVectorD eigenValues(5);
208 eigenCov.EigenVectors(eigenValues);
209 double minEigenValue = eigenValues.Min();
211 if (minEigenValue < 0) {
212 for (
int i = 0;
i < 5;
i++)
213 m(
i,
i) += delta - minEigenValue;
217 return reco::Track(normalizedChi2_ * (*track_).ndof(),
220 (*track_).momentum(),
234 maybeUnpackCovariance();
235 int numberOfStripLayers = stripLayersWithMeasurement(),
236 numberOfPixelLayers = pixelLayersWithMeasurement();
237 int numberOfPixelHits = this->numberOfPixelHits();
238 int numberOfHits = this->numberOfHits();
240 int ndof = numberOfHits + numberOfPixelHits - 5;
243 auto track = std::make_unique<reco::Track>(
244 normalizedChi2_ *
ndof,
ndof, *vertex_,
248 if (firstHit_ == 0) {
249 if (innerLost == validHitInFirstPixelBarrelLayer) {
262 if (innerLost == validHitInFirstPixelBarrelLayer) {
265 for (; i < numberOfPixelLayers; i++) {
286 for (; i < numberOfPixelLayers; i++) {
287 if (i + iOffset <= 2) {
293 i + iOffset - 3 + 1, 0,
300 for (; i < numberOfPixelHits; i++) {
302 track->appendTrackerHitPattern(
306 track->appendTrackerHitPattern(
308 (innerLost == validHitInFirstPixelBarrelLayer ? 1 : 2), 0,
329 for (
int sl = slOffset; sl < numberOfStripLayers + slOffset; ++sl, ++
i) {
339 else if (sl < 13 + 9)
348 for (; i < numberOfHits; i++) {
350 track->appendTrackerHitPattern(
360 case validHitInFirstPixelBarrelLayer:
362 case noLostInnerHits:
364 case oneLostInnerHit:
368 case moreLostInnerHits:
376 if (trackHighPurity())
380 if (track_.compare_exchange_strong(expected,
track.get())) {
389 <<
"this Candidate has no master clone reference." 390 <<
"Can't call masterClone() method.\n";
399 <<
"this Candidate has no master clone ptr." 400 <<
"Can't call masterClonePtr() method.\n";
423 <<
"This Candidate type does not implement daughter(std::string). " 424 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
429 <<
"This Candidate type does not implement daughter(std::string). " 430 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
443 <<
"reco::ConcreteCandidate does not implement vertex covariant " 449 <<
"reco::ConcreteCandidate does not implement vertex covariant " 462 packedPuppiweightNoLepDiff_ =
471 return 1.f * packedPuppiweightNoLepDiff_ /
481 rawCaloFraction_ = 100 *
p;
485 rawHcalFraction_ = 100 *
p;
493 isIsolatedChargedHadron_ =
p;
497 if (aTime == 0 && aTimeError == 0) {
499 packedTimeError_ = 0;
500 }
else if (aTimeError == 0) {
501 packedTimeError_ = 0;
502 packedTime_ = packTimeNoError(aTime);
504 packedTimeError_ = packTimeError(aTimeError);
505 aTimeError = unpackTimeError(packedTimeError_);
506 packedTime_ = packTimeWithError(aTime, aTimeError);
519 return std::max<uint8_t>(
520 std::min(std::round(std::ldexp(std::log2(timeError / MIN_TIMEERROR),
528 std::exp2(std::ldexp(
float(timeError), -EXPO_TIMEERROR))
534 return (time > 0 ? MIN_TIME_NOERROR : -MIN_TIME_NOERROR) *
535 std::exp2(std::ldexp(
float(
std::abs(time)), -EXPO_TIME_NOERROR));
544 if (
std::abs(time) < MIN_TIME_NOERROR)
546 float fpacked = std::ldexp(std::log2(
std::abs(time / MIN_TIME_NOERROR)),
548 return (time > 0 ? +1 : -1) *
std::min(std::round(fpacked), 2047.
f);
554 return std::ldexp(unpackTimeError(timeError), EXPO_TIME_WITHERROR) *
569 float fpacked = std::round(time / std::ldexp(timeError, EXPO_TIME_WITHERROR));
572 return int16_t(fpacked) * 2;
574 int16_t packed = packTimeNoError(time);
float puppiWeight() const
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
static uint32_t getLayer(uint16_t pattern)
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
bool isNonnull() const
Checks for non-null.
static bool pixelHitFilter(uint16_t pattern)
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > AlgebraicSymMatrix22
float puppiWeightNoLep() const
Weight from full PUPPI.
void setPuppiWeight(float p, float p_nolep=0.0)
CovarianceMatrix vertexCovariance() const override
return SMatrix
bool hasMasterClonePtr() const override
Sin< T >::type sin(const T &t)
double vertexChi2() const override
chi-squares
virtual const reco::Track pseudoPosDefTrack() const
bool longLived() const override
is long lived?
static float unpackTimeNoError(int16_t time)
double vertexNdof() const override
void setRawCaloFraction(float p)
Weight from PUPPI removing leptons.
const reco::CandidatePtr & masterClonePtr() const override
static int16_t packTimeNoError(float time)
static int16_t packTimeWithError(float time, float timeError)
static uint8_t packTimeError(float timeError)
static to allow unit testing
RhoEtaPhiVectorD RhoEtaPhiVector
spatial vector with cylindrical internal representation using pseudorapidity
static float float16to32(uint16_t h)
bool massConstraint() const override
do mass constraint?
size_t numberOfMothers() const override
number of mothers
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > AlgebraicSymMatrix44
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
void setHcalFraction(float p)
Fraction of ECAL+HCAL energy over candidate energy.
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
static uint16_t float32to16(float x)
Cos< T >::type cos(const T &t)
static bool stripHitFilter(uint16_t pattern)
static CovarianceParameterization covarianceParameterization_
Abs< T >::type abs(const T &t)
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
~PackedCandidate() override
destructor
static uint32_t getSubStructure(uint16_t pattern)
LostInnerHits
Enumerator specifying the.
void setRawHcalFraction(float p)
Raw ECAL+HCAL energy over candidate energy for isolated charged hadrons.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
static std::once_flag covariance_load_flag
math::XYZTLorentzVector LorentzVector
Lorentz vector.
void unpackCovariance() const
void setDTimeAssociatedPV(float aTime, float aTimeError=0)
set time measurement
virtual int charge() const =0
electric charge
Structure Point Contains parameters of Gaussian fits to DMRs.
size_t numberOfDaughters() const override
number of daughters
void packVtx(bool unpackAfterwards=true)
static unsigned int const shift
void setIsIsolatedChargedHadron(bool p)
Fraction of Hcal for HF, neutral hadrons, and charged particles.
virtual const Point & vertex() const =0
vertex position
void pack(bool unpackAfterwards=true)
void packCovariance(const reco::TrackBase::CovarianceMatrix &m, bool unpackAfterwards=true)
const reco::CandidateBaseRef & masterClone() const override
virtual float dxy() const
dxy with respect to the PV ref
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
static float unpackTimeWithError(int16_t time, uint8_t timeError)
bool hasMasterClone() const override
static float unpackTimeError(uint8_t timeError)
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
void setCaloFraction(float p)
Fraction of Hcal for isolated charged hadrons.
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.