9 #include "TMatrixDSym.h" 22 if (unpackAfterwards) {
23 delete p4_.exchange(
nullptr);
24 delete p4c_.exchange(
nullptr);
32 float dxPV = vertex_.load()->X() -
pv.X(),
33 dyPV = vertex_.load()->Y() -
pv.Y();
34 float s =
std::sin(
float(p4_.load()->Phi()) + dphi_),
35 c =
std::cos(
float(p4_.load()->Phi() + dphi_));
37 dxy_ = -dxPV *
s + dyPV *
c;
41 float pzpt = p4_.load()->Pz() / p4_.load()->Pt();
42 dz_ = vertex_.load()->Z() -
pv.Z() - (dxPV *
c + dyPV *
s) * pzpt;
50 if (unpackAfterwards) {
51 delete vertex_.exchange(
nullptr);
60 double sign = ((
int(
pt * 10) % 2 == 0) ? 1 : -1);
63 auto p4 = std::make_unique<PolarLorentzVector>(
pt,
67 auto p4c = std::make_unique<LorentzVector>(*p4);
69 if (p4_.compare_exchange_strong(expectp4, p4.get())) {
76 if (p4c_.compare_exchange_strong(expectp4c, p4c.get())) {
82 packedCovariance_.dptdpt = packCovarianceElement(
m, 0, 0);
83 packedCovariance_.detadeta = packCovarianceElement(
m, 1, 1);
84 packedCovariance_.dphidphi = packCovarianceElement(
m, 2, 2);
85 packedCovariance_.dxydxy = packCovarianceElement(
m, 3, 3);
86 packedCovariance_.dzdz = packCovarianceElement(
m, 4, 4);
87 packedCovariance_.dxydz = packCovarianceElement(
m, 3, 4);
88 packedCovariance_.dlambdadz = packCovarianceElement(
m, 1, 4);
89 packedCovariance_.dphidxy = packCovarianceElement(
m, 2, 3);
98 auto m = std::make_unique<reco::TrackBase::CovarianceMatrix>();
99 for (
int i = 0;
i < 5;
i++)
100 for (
int j = 0;
j < 5;
j++) {
103 unpackCovarianceElement(*
m, packedCovariance_.dptdpt, 0, 0);
104 unpackCovarianceElement(*
m, packedCovariance_.detadeta, 1, 1);
105 unpackCovarianceElement(*
m, packedCovariance_.dphidphi, 2, 2);
106 unpackCovarianceElement(*
m, packedCovariance_.dxydxy, 3, 3);
107 unpackCovarianceElement(*
m, packedCovariance_.dzdz, 4, 4);
108 unpackCovarianceElement(*
m, packedCovariance_.dxydz, 3, 4);
109 unpackCovarianceElement(*
m, packedCovariance_.dlambdadz, 1, 4);
110 unpackCovarianceElement(*
m, packedCovariance_.dphidxy, 2, 3);
113 if (m_.compare_exchange_strong(expected,
m.get())) {
119 <<
"You do not have a valid track parameters file loaded. " 120 <<
"Please check that the release version is compatible with your " 122 <<
"or avoid accessing track parameter uncertainties. ";
136 auto vertex = std::make_unique<Point>(
pv.X() - dxy_ *
s,
141 Point *expected =
nullptr;
142 if (vertex_.compare_exchange_strong(expected,
vertex.get())) {
150 delete vertex_.load();
151 delete track_.load();
157 const float phi =
float(p4_.load()->Phi()) + dphi_;
162 const float phi =
float(p4_.load()->Phi()) + dphi_;
163 const float pzpt = deta_ ? std::sinh(etaAtVtx()) : p4_.load()->Pz() / p4_.load()->Pt();
164 return (vertex_.load()->Z() -
p.Z()) -
182 TMatrixDSym eigenCov(5);
183 for (
int i = 0;
i < 5;
i++) {
184 for (
int j = 0;
j < 5;
j++) {
186 eigenCov(
i,
j) = 1
e-6;
188 eigenCov(
i,
j) = (
m)(
i,
j);
191 TVectorD eigenValues(5);
192 eigenCov.EigenVectors(eigenValues);
193 double minEigenValue = eigenValues.Min();
195 if (minEigenValue < 0) {
196 for (
int i = 0;
i < 5;
i++)
201 return reco::Track(normalizedChi2_ * (*track_).ndof(),
204 (*track_).momentum(),
218 maybeUnpackCovariance();
219 int numberOfStripLayers = stripLayersWithMeasurement(), numberOfPixelLayers = pixelLayersWithMeasurement();
220 int numberOfPixelHits = this->numberOfPixelHits();
221 int numberOfHits = this->numberOfHits();
223 int ndof = numberOfHits + numberOfPixelHits - 5;
226 auto track = std::make_unique<reco::Track>(normalizedChi2_ *
ndof,
235 if (firstHit_ == 0) {
236 if (innerLost == validHitInFirstPixelBarrelLayer) {
248 if (innerLost == validHitInFirstPixelBarrelLayer) {
251 for (;
i < numberOfPixelLayers;
i++) {
269 for (;
i < numberOfPixelLayers;
i++) {
270 if (
i + iOffset <= 2) {
279 for (;
i < numberOfPixelHits;
i++) {
287 (innerLost == validHitInFirstPixelBarrelLayer ? 1 : 2),
309 for (
int sl = slOffset; sl < numberOfStripLayers + slOffset; ++sl, ++
i) {
316 else if (sl < 13 + 9)
324 for (;
i < numberOfHits;
i++) {
336 case validHitInFirstPixelBarrelLayer:
338 case noLostInnerHits:
340 case oneLostInnerHit:
343 case moreLostInnerHits:
349 if (trackHighPurity())
353 if (track_.compare_exchange_strong(expected,
track.get())) {
361 throw cms::Exception(
"Invalid Reference") <<
"this Candidate has no master clone reference." 362 <<
"Can't call masterClone() method.\n";
370 throw cms::Exception(
"Invalid Reference") <<
"this Candidate has no master clone ptr." 371 <<
"Can't call masterClonePtr() method.\n";
379 return p4() ==
o.p4() &&
vertex() ==
o.vertex() &&
charge() ==
o.charge();
389 <<
"This Candidate type does not implement daughter(std::string). " 390 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
395 <<
"This Candidate type does not implement daughter(std::string). " 396 <<
"Please use CompositeCandidate or NamedCompositeCandidate.\n";
409 <<
"reco::ConcreteCandidate does not implement vertex covariant " 415 <<
"reco::ConcreteCandidate does not implement vertex covariant " 444 rawCaloFraction_ = 100 *
p;
456 if (aTime == 0 && aTimeError == 0) {
458 packedTimeError_ = 0;
459 }
else if (aTimeError == 0) {
460 packedTimeError_ = 0;
461 packedTime_ = packTimeNoError(aTime);
463 packedTimeError_ = packTimeError(aTimeError);
464 aTimeError = unpackTimeError(packedTimeError_);
465 packedTime_ = packTimeWithError(aTime, aTimeError);
478 return std::max<uint8_t>(
479 std::min(std::round(std::ldexp(std::log2(timeError / MIN_TIMEERROR), +EXPO_TIMEERROR)), 255.
f), 1);
482 return timeError > 0 ? MIN_TIMEERROR * std::exp2(std::ldexp(
float(timeError), -EXPO_TIMEERROR)) : -1.0f;
487 return (
time > 0 ? MIN_TIME_NOERROR : -MIN_TIME_NOERROR) *
488 std::exp2(std::ldexp(
float(
std::abs(
time)), -EXPO_TIME_NOERROR));
499 float fpacked = std::ldexp(std::log2(
std::abs(
time / MIN_TIME_NOERROR)), +EXPO_TIME_NOERROR);
500 return (
time > 0 ? +1 : -1) *
std::min(std::round(fpacked), 2047.
f);
505 return std::ldexp(unpackTimeError(timeError), EXPO_TIME_WITHERROR) *
float(
time / 2);
519 float fpacked = std::round(
time / std::ldexp(timeError, EXPO_TIME_WITHERROR));
522 return int16_t(fpacked) * 2;
524 int16_t packed = packTimeNoError(
time);
525 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)
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.