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;
43 if (p4_.load()->Pt() != 0.f) {
44 float pzpt = p4_.load()->Pz() / p4_.load()->Pt();
45 dz_ = vertex_.load()->Z() -
pv.Z() - (dxPV *
c + dyPV *
s) * pzpt;
54 if (unpackAfterwards) {
55 delete vertex_.exchange(
nullptr);
64 double sign = ((
int(
pt * 10) % 2 == 0) ? 1 : -1);
67 auto p4 = std::make_unique<PolarLorentzVector>(
pt,
71 auto p4c = std::make_unique<LorentzVector>(*p4);
73 if (p4_.compare_exchange_strong(expectp4, p4.get())) {
80 if (p4c_.compare_exchange_strong(expectp4c, p4c.get())) {
86 packedCovariance_.dptdpt = packCovarianceElement(
m, 0, 0);
87 packedCovariance_.detadeta = packCovarianceElement(
m, 1, 1);
88 packedCovariance_.dphidphi = packCovarianceElement(
m, 2, 2);
89 packedCovariance_.dxydxy = packCovarianceElement(
m, 3, 3);
90 packedCovariance_.dzdz = packCovarianceElement(
m, 4, 4);
91 packedCovariance_.dxydz = packCovarianceElement(
m, 3, 4);
92 packedCovariance_.dlambdadz = packCovarianceElement(
m, 1, 4);
93 packedCovariance_.dphidxy = packCovarianceElement(
m, 2, 3);
102 auto m = std::make_unique<reco::TrackBase::CovarianceMatrix>();
103 for (
int i = 0;
i < 5;
i++)
104 for (
int j = 0;
j < 5;
j++) {
107 unpackCovarianceElement(*
m, packedCovariance_.dptdpt, 0, 0);
108 unpackCovarianceElement(*
m, packedCovariance_.detadeta, 1, 1);
109 unpackCovarianceElement(*
m, packedCovariance_.dphidphi, 2, 2);
110 unpackCovarianceElement(*
m, packedCovariance_.dxydxy, 3, 3);
111 unpackCovarianceElement(*
m, packedCovariance_.dzdz, 4, 4);
112 unpackCovarianceElement(*
m, packedCovariance_.dxydz, 3, 4);
113 unpackCovarianceElement(*
m, packedCovariance_.dlambdadz, 1, 4);
114 unpackCovarianceElement(*
m, packedCovariance_.dphidxy, 2, 3);
117 if (m_.compare_exchange_strong(expected,
m.get())) {
123 <<
"You do not have a valid track parameters file loaded. " 124 <<
"Please check that the release version is compatible with your " 126 <<
"or avoid accessing track parameter uncertainties. ";
140 auto vertex = std::make_unique<Point>(
pv.X() - dxy_ *
s,
145 Point *expected =
nullptr;
146 if (vertex_.compare_exchange_strong(expected,
vertex.get())) {
154 delete vertex_.load();
155 delete track_.load();
161 const float phi =
float(p4_.load()->Phi()) + dphi_;
166 const float phi =
float(p4_.load()->Phi()) + dphi_;
167 const float pzpt = deta_ ? std::sinh(
etaAtVtx()) : p4_.load()->Pz() / p4_.load()->Pt();
168 return (vertex_.load()->Z() -
p.Z()) -
186 TMatrixDSym eigenCov(5);
187 for (
int i = 0;
i < 5;
i++) {
188 for (
int j = 0;
j < 5;
j++) {
190 eigenCov(
i,
j) = 1
e-6;
192 eigenCov(
i,
j) = (
m)(
i,
j);
195 TVectorD eigenValues(5);
196 eigenCov.EigenVectors(eigenValues);
197 double minEigenValue = eigenValues.Min();
199 if (minEigenValue < 0) {
200 for (
int i = 0;
i < 5;
i++)
205 return reco::Track(normalizedChi2_ * (*track_).ndof(),
208 (*track_).momentum(),
222 maybeUnpackCovariance();
223 int numberOfStripLayers = stripLayersWithMeasurement(), numberOfPixelLayers = pixelLayersWithMeasurement();
224 int numberOfPixelHits = this->numberOfPixelHits();
225 int numberOfHits = this->numberOfHits();
227 int ndof = numberOfHits + numberOfPixelHits - 5;
230 auto track = std::make_unique<reco::Track>(normalizedChi2_ *
ndof,
239 if (firstHit_ == 0) {
240 if (innerLost == validHitInFirstPixelBarrelLayer) {
252 if (innerLost == validHitInFirstPixelBarrelLayer) {
255 for (;
i < numberOfPixelLayers;
i++) {
273 for (;
i < numberOfPixelLayers;
i++) {
274 if (
i + iOffset <= 2) {
283 for (;
i < numberOfPixelHits;
i++) {
291 (innerLost == validHitInFirstPixelBarrelLayer ? 1 : 2),
313 for (
int sl = slOffset; sl < numberOfStripLayers + slOffset; ++sl, ++
i) {
320 else if (sl < 13 + 9)
328 for (;
i < numberOfHits;
i++) {
340 case validHitInFirstPixelBarrelLayer:
342 case noLostInnerHits:
344 case oneLostInnerHit:
347 case moreLostInnerHits:
353 if (trackHighPurity())
357 if (track_.compare_exchange_strong(expected,
track.get())) {
365 throw cms::Exception(
"Invalid Reference") <<
"this Candidate has no master clone reference." 366 <<
"Can't call masterClone() method.\n";
374 throw cms::Exception(
"Invalid Reference") <<
"this Candidate has no master clone ptr." 375 <<
"Can't call masterClonePtr() method.\n";
383 return p4() ==
o.p4() &&
vertex() ==
o.vertex() &&
charge() ==
o.charge();
393 <<
"This Candidate type does not implement daughter(std::string). " 394 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
399 <<
"This Candidate type does not implement daughter(std::string). " 400 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
413 <<
"reco::ConcreteCandidate does not implement vertex covariant " 419 <<
"reco::ConcreteCandidate does not implement vertex covariant " 448 rawCaloFraction_ = 100 *
p;
460 if (aTime == 0 && aTimeError == 0) {
462 packedTimeError_ = 0;
463 }
else if (aTimeError == 0) {
464 packedTimeError_ = 0;
465 packedTime_ = packTimeNoError(aTime);
467 packedTimeError_ = packTimeError(aTimeError);
468 aTimeError = unpackTimeError(packedTimeError_);
469 packedTime_ = packTimeWithError(aTime, aTimeError);
482 return std::max<uint8_t>(
483 std::min(std::round(std::ldexp(std::log2(timeError / MIN_TIMEERROR), +EXPO_TIMEERROR)), 255.
f), 1);
486 return timeError > 0 ? MIN_TIMEERROR * std::exp2(std::ldexp(
float(timeError), -EXPO_TIMEERROR)) : -1.0f;
491 return (
time > 0 ? MIN_TIME_NOERROR : -MIN_TIME_NOERROR) *
492 std::exp2(std::ldexp(
float(
std::abs(
time)), -EXPO_TIME_NOERROR));
503 float fpacked = std::ldexp(std::log2(
std::abs(
time / MIN_TIME_NOERROR)), +EXPO_TIME_NOERROR);
504 return (
time > 0 ? +1 : -1) *
std::min(std::round(fpacked), 2047.
f);
509 return std::ldexp(unpackTimeError(timeError), EXPO_TIME_WITHERROR) *
float(
time / 2);
523 float fpacked = std::round(
time / std::ldexp(timeError, EXPO_TIME_WITHERROR));
526 return int16_t(fpacked) * 2;
528 int16_t packed = packTimeNoError(
time);
529 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)
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.
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
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.