10 #include "TMatrixDSym.h" 23 if (unpackAfterwards) {
24 delete p4_.exchange(
nullptr);
25 delete p4c_.exchange(
nullptr);
33 float dxPV = vertex_.load()->X() -
pv.X(),
34 dyPV = vertex_.load()->Y() -
pv.Y();
35 float s =
std::sin(
float(p4_.load()->Phi()) + dphi_),
36 c =
std::cos(
float(p4_.load()->Phi() + dphi_));
38 dxy_ = -dxPV *
s + dyPV *
c;
42 float pzpt = p4_.load()->Pz() / p4_.load()->Pt();
43 dz_ = vertex_.load()->Z() -
pv.Z() - (dxPV *
c + dyPV *
s) * pzpt;
51 if (unpackAfterwards) {
52 delete vertex_.exchange(
nullptr);
61 double sign = ((
int(
pt * 10) % 2 == 0) ? 1 : -1);
64 auto p4 = std::make_unique<PolarLorentzVector>(
pt,
68 auto p4c = std::make_unique<LorentzVector>(*p4);
70 if (p4_.compare_exchange_strong(expectp4, p4.get())) {
77 if (p4c_.compare_exchange_strong(expectp4c, p4c.get())) {
83 packedCovariance_.dptdpt = packCovarianceElement(
m, 0, 0);
84 packedCovariance_.detadeta = packCovarianceElement(
m, 1, 1);
85 packedCovariance_.dphidphi = packCovarianceElement(
m, 2, 2);
86 packedCovariance_.dxydxy = packCovarianceElement(
m, 3, 3);
87 packedCovariance_.dzdz = packCovarianceElement(
m, 4, 4);
88 packedCovariance_.dxydz = packCovarianceElement(
m, 3, 4);
89 packedCovariance_.dlambdadz = packCovarianceElement(
m, 1, 4);
90 packedCovariance_.dphidxy = packCovarianceElement(
m, 2, 3);
99 auto m = std::make_unique<reco::TrackBase::CovarianceMatrix>();
100 for (
int i = 0;
i < 5;
i++)
101 for (
int j = 0;
j < 5;
j++) {
104 unpackCovarianceElement(*
m, packedCovariance_.dptdpt, 0, 0);
105 unpackCovarianceElement(*
m, packedCovariance_.detadeta, 1, 1);
106 unpackCovarianceElement(*
m, packedCovariance_.dphidphi, 2, 2);
107 unpackCovarianceElement(*
m, packedCovariance_.dxydxy, 3, 3);
108 unpackCovarianceElement(*
m, packedCovariance_.dzdz, 4, 4);
109 unpackCovarianceElement(*
m, packedCovariance_.dxydz, 3, 4);
110 unpackCovarianceElement(*
m, packedCovariance_.dlambdadz, 1, 4);
111 unpackCovarianceElement(*
m, packedCovariance_.dphidxy, 2, 3);
114 if (m_.compare_exchange_strong(expected,
m.get())) {
120 <<
"You do not have a valid track parameters file loaded. " 121 <<
"Please check that the release version is compatible with your " 123 <<
"or avoid accessing track parameter uncertainties. ";
137 auto vertex = std::make_unique<Point>(
pv.X() - dxy_ *
s,
142 Point *expected =
nullptr;
143 if (vertex_.compare_exchange_strong(expected,
vertex.get())) {
151 delete vertex_.load();
152 delete track_.load();
158 const float phi =
float(p4_.load()->Phi()) + dphi_;
163 const float phi =
float(p4_.load()->Phi()) + dphi_;
164 const float pzpt = deta_ ? std::sinh(etaAtVtx()) : p4_.load()->Pz() / p4_.load()->Pt();
165 return (vertex_.load()->Z() -
p.Z()) -
183 TMatrixDSym eigenCov(5);
184 for (
int i = 0;
i < 5;
i++) {
185 for (
int j = 0;
j < 5;
j++) {
187 eigenCov(
i,
j) = 1
e-6;
189 eigenCov(
i,
j) = (
m)(
i,
j);
192 TVectorD eigenValues(5);
193 eigenCov.EigenVectors(eigenValues);
194 double minEigenValue = eigenValues.Min();
196 if (minEigenValue < 0) {
197 for (
int i = 0;
i < 5;
i++)
202 return reco::Track(normalizedChi2_ * (*track_).ndof(),
205 (*track_).momentum(),
219 maybeUnpackCovariance();
220 int numberOfStripLayers = stripLayersWithMeasurement(), numberOfPixelLayers = pixelLayersWithMeasurement();
221 int numberOfPixelHits = this->numberOfPixelHits();
222 int numberOfHits = this->numberOfHits();
224 int ndof = numberOfHits + numberOfPixelHits - 5;
227 auto track = std::make_unique<reco::Track>(normalizedChi2_ *
ndof,
236 if (firstHit_ == 0) {
237 if (innerLost == validHitInFirstPixelBarrelLayer) {
249 if (innerLost == validHitInFirstPixelBarrelLayer) {
252 for (;
i < numberOfPixelLayers;
i++) {
270 for (;
i < numberOfPixelLayers;
i++) {
271 if (
i + iOffset <= 2) {
280 for (;
i < numberOfPixelHits;
i++) {
288 (innerLost == validHitInFirstPixelBarrelLayer ? 1 : 2),
310 for (
int sl = slOffset; sl < numberOfStripLayers + slOffset; ++sl, ++
i) {
317 else if (sl < 13 + 9)
325 for (;
i < numberOfHits;
i++) {
337 case validHitInFirstPixelBarrelLayer:
339 case noLostInnerHits:
341 case oneLostInnerHit:
344 case moreLostInnerHits:
350 if (trackHighPurity())
354 if (track_.compare_exchange_strong(expected,
track.get())) {
362 throw cms::Exception(
"Invalid Reference") <<
"this Candidate has no master clone reference." 363 <<
"Can't call masterClone() method.\n";
371 throw cms::Exception(
"Invalid Reference") <<
"this Candidate has no master clone ptr." 372 <<
"Can't call masterClonePtr() method.\n";
380 return p4() ==
o.p4() &&
vertex() ==
o.vertex() &&
charge() ==
o.charge();
390 <<
"This Candidate type does not implement daughter(std::string). " 391 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
396 <<
"This Candidate type does not implement daughter(std::string). " 397 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
410 <<
"reco::ConcreteCandidate does not implement vertex covariant " 416 <<
"reco::ConcreteCandidate does not implement vertex covariant " 445 rawCaloFraction_ = 100 *
p;
457 if (aTime == 0 && aTimeError == 0) {
459 packedTimeError_ = 0;
460 }
else if (aTimeError == 0) {
461 packedTimeError_ = 0;
462 packedTime_ = packTimeNoError(aTime);
464 packedTimeError_ = packTimeError(aTimeError);
465 aTimeError = unpackTimeError(packedTimeError_);
466 packedTime_ = packTimeWithError(aTime, aTimeError);
479 return std::max<uint8_t>(
480 std::min(std::round(std::ldexp(std::log2(timeError / MIN_TIMEERROR), +EXPO_TIMEERROR)), 255.
f), 1);
483 return timeError > 0 ? MIN_TIMEERROR * std::exp2(std::ldexp(
float(timeError), -EXPO_TIMEERROR)) : -1.0f;
488 return (
time > 0 ? MIN_TIME_NOERROR : -MIN_TIME_NOERROR) *
489 std::exp2(std::ldexp(
float(
std::abs(
time)), -EXPO_TIME_NOERROR));
500 float fpacked = std::ldexp(std::log2(
std::abs(
time / MIN_TIME_NOERROR)), +EXPO_TIME_NOERROR);
501 return (
time > 0 ? +1 : -1) *
std::min(std::round(fpacked), 2047.
f);
506 return std::ldexp(unpackTimeError(timeError), EXPO_TIME_WITHERROR) *
float(
time / 2);
520 float fpacked = std::round(
time / std::ldexp(timeError, EXPO_TIME_WITHERROR));
523 return int16_t(fpacked) * 2;
525 int16_t packed = packTimeNoError(
time);
526 return packed * 2 + (
time > 0 ? +1 : -1);
float puppiWeight() const
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
static constexpr auto TEC
bool massConstraint() const override
do mass constraint?
static uint32_t getLayer(uint16_t pattern)
float puppiWeightNoLep() const
Weight from full PUPPI.
double vertexNdof() const override
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
static bool pixelHitFilter(uint16_t pattern)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
void setPuppiWeight(float p, float p_nolep=0.0)
constexpr bool isNotFinite(T x)
bool hasMasterClonePtr() const override
Sin< T >::type sin(const T &t)
static float unpackTimeNoError(int16_t time)
void setRawCaloFraction(float p)
Weight from PUPPI removing leptons.
static int16_t packTimeNoError(float time)
bool isNonnull() const
Checks for non-null.
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)
size_t numberOfMothers() const override
number of mothers
const reco::CandidateBaseRef & masterClone() const override
const reco::CandidatePtr & masterClonePtr() const override
void unpackCovariance() const
virtual const reco::Track pseudoPosDefTrack() const
void setHcalFraction(float p)
Fraction of ECAL+HCAL energy over candidate energy.
static uint16_t float32to16(float x)
Cos< T >::type cos(const T &t)
static bool stripHitFilter(uint16_t pattern)
size_t numberOfDaughters() const override
number of daughters
static CovarianceParameterization covarianceParameterization_
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
Abs< T >::type abs(const T &t)
~PackedCandidate() override
destructor
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > AlgebraicSymMatrix44
static constexpr auto TOB
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.
static constexpr auto TIB
XYZVectorD XYZVector
spatial vector with cartesian internal representation
static std::once_flag covariance_load_flag
math::XYZTLorentzVector LorentzVector
Lorentz vector.
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > AlgebraicSymMatrix22
void setDTimeAssociatedPV(float aTime, float aTimeError=0)
set time measurement
Structure Point Contains parameters of Gaussian fits to DMRs.
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
void packVtx(bool unpackAfterwards=true)
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
static unsigned int const shift
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
void setIsIsolatedChargedHadron(bool p)
Fraction of Hcal for HF, neutral hadrons, and charged particles.
double vertexChi2() const override
chi-squares
CovarianceMatrix vertexCovariance() const override
return SMatrix
virtual float dxy() const
dxy with respect to the PV ref
void pack(bool unpackAfterwards=true)
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
void packCovariance(const reco::TrackBase::CovarianceMatrix &m, bool unpackAfterwards=true)
static float unpackTimeWithError(int16_t time, uint8_t timeError)
bool hasMasterClone() const override
static constexpr auto TID
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.
bool longLived() const override
is long lived?
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.