Commit ae24214 1 parent 49ba4ab commit ae24214 Copy full SHA for ae24214
File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -14,4 +14,16 @@ void Particle::SetPid(PdgCode_t pid) {
14
14
charge_ = GetChargeByPdgId (pid);
15
15
}
16
16
}
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
+
17
29
}// namespace AnalysisTree
Original file line number Diff line number Diff line change @@ -29,11 +29,21 @@ class Particle : public Track {
29
29
ANALYSISTREE_ATTR_NODISCARD Floating_t GetMass () const { return mass_; }
30
30
31
31
void SetMass (Floating_t mass) {
32
+ CheckIsAllowedSetMassAndChargeExplicitly ();
32
33
mass_ = mass;
33
34
}
34
35
36
+ void SetCharge (Int_t charge) {
37
+ CheckIsAllowedSetMassAndChargeExplicitly ();
38
+ Track::SetCharge (charge);
39
+ }
40
+
35
41
void SetPid (PdgCode_t pid);
36
42
43
+ void SetIsAllowedSetMassAndChargeExplicitly (bool is=true ) { is_allowed_set_charge_and_mass_explicitly_ = is; }
44
+
45
+ void CheckIsAllowedSetMassAndChargeExplicitly () const ;
46
+
37
47
ANALYSISTREE_ATTR_NODISCARD Floating_t GetEnergy () const { return sqrt (mass_ * mass_ + GetP () * GetP ()); }
38
48
ANALYSISTREE_ATTR_NODISCARD Floating_t GetKineticEnergy () const { return GetEnergy () - mass_; }
39
49
@@ -90,6 +100,7 @@ class Particle : public Track {
90
100
protected:
91
101
Floating_t mass_{-1000 .f };
92
102
PdgCode_t pid_{0 };
103
+ bool is_allowed_set_charge_and_mass_explicitly_{false };// !
93
104
94
105
ClassDefOverride (Particle, 2 );
95
106
};
You can’t perform that action at this time.
0 commit comments