Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand MCTrack to contain proper energy property #11884

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions DataFormats/simulation/include/SimulationDataFormat/MCTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MCTrackT

/// Standard constructor
MCTrackT(Int_t pdgCode, Int_t motherID, Int_t secondMotherID, Int_t firstDaughterID, Int_t lastDaughterID,
Double_t px, Double_t py, Double_t pz, Double_t x, Double_t y, Double_t z, Double_t t,
Double_t px, Double_t py, Double_t pz, Double_t energy, Double_t x, Double_t y, Double_t z, Double_t t,
Int_t nPoints);

/// Copy constructor
Expand Down Expand Up @@ -93,7 +93,10 @@ class MCTrackT
/// return particle weight
_T getWeight() const { return mWeight; }

/// get known or calculated energy
Double_t GetEnergy() const;
/// returns energy that is stored (could be -1)
Double_t GetEnergyVal() const { return mEnergy; }

// Alternative accessors with TParticle like shorter names
Double_t Px() const { return mStartVertexMomentumX; }
Expand Down Expand Up @@ -230,8 +233,8 @@ class MCTrackT
const char* getProdProcessAsString() const;

private:
/// Momentum components at start vertex [GeV]
_T mStartVertexMomentumX, mStartVertexMomentumY, mStartVertexMomentumZ;
/// 4-Momentum components at start vertex [GeV] (energy only kept if mass not known)
_T mStartVertexMomentumX, mStartVertexMomentumY, mStartVertexMomentumZ, mEnergy;

/// Coordinates of start vertex [cm, ns]
_T mStartVertexCoordinatesX, mStartVertexCoordinatesY, mStartVertexCoordinatesZ, mStartVertexCoordinatesT;
Expand Down Expand Up @@ -274,15 +277,36 @@ class MCTrackT
// such as part of mProp (process) or mPDG
Int_t mStatusCode = 0;

ClassDefNV(MCTrackT, 8);
/// updates the energy property based on whether PDG mass is available or not
void updateEnergy();

ClassDefNV(MCTrackT, 9);
};

template <typename T>
inline void MCTrackT<T>::updateEnergy()
{
bool success{false};
// if this query is too slow we can add an additional cache layer
auto mass = O2DatabasePDG::Mass(mPdgCode, success);
if (success == true) {
// mass available --> no need to keep energy
mEnergy = -1.;
}
}

template <typename T>
inline Double_t MCTrackT<T>::GetEnergy() const
{
const auto mass = GetMass();
return std::sqrt(mass * mass + mStartVertexMomentumX * mStartVertexMomentumX +
mStartVertexMomentumY * mStartVertexMomentumY + mStartVertexMomentumZ * mStartVertexMomentumZ);
if (mEnergy < 0) {
// this means that the particle should have a well defined mass from
// which we calculate the energy
const auto mass = GetMass();
return std::sqrt(mass * mass + mStartVertexMomentumX * mStartVertexMomentumX +
mStartVertexMomentumY * mStartVertexMomentumY + mStartVertexMomentumZ * mStartVertexMomentumZ);
}
// the case for primary particles
return mEnergy;
}

template <typename T>
Expand Down Expand Up @@ -318,13 +342,14 @@ inline MCTrackT<T>::MCTrackT()
mStartVertexCoordinatesZ(0.),
mStartVertexCoordinatesT(0.),
mProp(0),
mWeight(0)
mWeight(0),
mEnergy(-1.)
{
}

template <typename T>
inline MCTrackT<T>::MCTrackT(Int_t pdgCode, Int_t motherId, Int_t secondMotherId, Int_t firstDaughterId, Int_t lastDaughterId,
Double_t px, Double_t py, Double_t pz, Double_t x,
Double_t px, Double_t py, Double_t pz, Double_t energy, Double_t x,
Double_t y, Double_t z, Double_t t, Int_t mask)
: mPdgCode(pdgCode),
mMotherTrackId(motherId),
Expand All @@ -339,8 +364,10 @@ inline MCTrackT<T>::MCTrackT(Int_t pdgCode, Int_t motherId, Int_t secondMotherId
mStartVertexCoordinatesZ(z),
mStartVertexCoordinatesT(t),
mProp(mask),
mWeight(0)
mWeight(0),
mEnergy(energy)
{
updateEnergy();
}

template <typename T>
Expand All @@ -357,6 +384,7 @@ inline MCTrackT<T>::MCTrackT(const TParticle& part)
mStartVertexCoordinatesY(part.Vy()),
mStartVertexCoordinatesZ(part.Vz()),
mStartVertexCoordinatesT(part.T() * 1e09),
mEnergy(part.Energy()),
mWeight(part.GetWeight()),
mProp(0),
mStatusCode(0)
Expand All @@ -374,6 +402,7 @@ inline MCTrackT<T>::MCTrackT(const TParticle& part)
}
// set MC generator status code only for primaries
mStatusCode = part.TestBit(ParticleStatus::kPrimary) ? part.GetStatusCode() : -1;
updateEnergy();
}

template <typename T>
Expand Down
Loading