Skip to content

Commit ae24214

Browse files
committed
allow call Particle:: SetMass() and SetCharge() only if user knows what one does
1 parent 49ba4ab commit ae24214

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

core/Particle.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ void Particle::SetPid(PdgCode_t pid) {
1414
charge_ = GetChargeByPdgId(pid);
1515
}
1616
}
17+
18+
void Particle::CheckIsAllowedSetMassAndChargeExplicitly() const {
19+
if(!is_allowed_set_charge_and_mass_explicitly_) {
20+
std::string message = "Particle::CheckIsAllowedSetMassAndChargeExplicitly(): ";
21+
message += "mass and charge of the particle are set automatically with SetPid() call ";
22+
message += "(unless they were already assigned with some values, incl. when copied content from Track to Particle). ";
23+
message += "Use SetMass() and SetCharge() only if you want to set them different from PDG-true values. ";
24+
message += "To unblock this possibility use SetIsAllowedSetMassAndChargeExplicitly() function.";
25+
throw std::runtime_error(message);
26+
}
27+
}
28+
1729
}// namespace AnalysisTree

core/Particle.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@ class Particle : public Track {
2929
ANALYSISTREE_ATTR_NODISCARD Floating_t GetMass() const { return mass_; }
3030

3131
void SetMass(Floating_t mass) {
32+
CheckIsAllowedSetMassAndChargeExplicitly();
3233
mass_ = mass;
3334
}
3435

36+
void SetCharge(Int_t charge) {
37+
CheckIsAllowedSetMassAndChargeExplicitly();
38+
Track::SetCharge(charge);
39+
}
40+
3541
void SetPid(PdgCode_t pid);
3642

43+
void SetIsAllowedSetMassAndChargeExplicitly(bool is=true) { is_allowed_set_charge_and_mass_explicitly_ = is; }
44+
45+
void CheckIsAllowedSetMassAndChargeExplicitly() const;
46+
3747
ANALYSISTREE_ATTR_NODISCARD Floating_t GetEnergy() const { return sqrt(mass_ * mass_ + GetP() * GetP()); }
3848
ANALYSISTREE_ATTR_NODISCARD Floating_t GetKineticEnergy() const { return GetEnergy() - mass_; }
3949

@@ -90,6 +100,7 @@ class Particle : public Track {
90100
protected:
91101
Floating_t mass_{-1000.f};
92102
PdgCode_t pid_{0};
103+
bool is_allowed_set_charge_and_mass_explicitly_{false};//!
93104

94105
ClassDefOverride(Particle, 2);
95106
};

0 commit comments

Comments
 (0)