Skip to content

Commit 6df77c1

Browse files
authored
Dev (#134)
* create AnalysisTreeDiff.patch even if empty * add title_ to BranchConfig for detailed description if needed * apply clang format * rename field titles * allow call Particle:: SetMass() and SetCharge() only if user knows what one does * apply clang format * fix error with git diff in AnalysisTreeHashWriter.sh
1 parent 82fc593 commit 6df77c1

8 files changed

Lines changed: 107 additions & 62 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,4 @@ install(FILES
147147
bin
148148
COMPONENT
149149
Devel
150-
OPTIONAL
151150
)

cmake/AnalysisTreeHashWriter.sh

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22

33
FILE_HASH=AnalysisTreeHash.sh
44
FILE_DIFF=AnalysisTreeDiff.patch
5-
if [ -f $FILE_HASH ]; then
6-
rm $FILE_HASH
7-
fi
5+
for F in $FILE_HASH $FILE_DIFF; do
6+
if [ -f $F ]; then
7+
rm $F
8+
fi
9+
done
810

911
SRC_DIR=${1}
1012

1113
cd $SRC_DIR
1214
if [ -d ".git" ]; then
13-
GITTAG=$(git describe --tags)
14-
GITCOMMIT=$(git rev-parse HEAD)
15-
GITSTATUS=$(git status --porcelain)
16-
cd -
17-
echo "export ANALYSIS_TREE_TAG=\"${GITTAG}\"" >> $FILE_HASH
18-
echo "export ANALYSIS_TREE_COMMIT_HASH=${GITCOMMIT}" >> $FILE_HASH
19-
if [ -z "${GITSTATUS}" ]; then
20-
echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=TRUE" >> $FILE_HASH
21-
else
22-
echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=FALSE" >> $FILE_HASH
23-
git diff >> $FILE_DIFF
24-
fi
15+
GITTAG=$(git describe --tags)
16+
GITCOMMIT=$(git rev-parse HEAD)
17+
GITSTATUS=$(git status --porcelain)
18+
cd -
19+
echo "export ANALYSIS_TREE_TAG=\"${GITTAG}\"" >> $FILE_HASH
20+
echo "export ANALYSIS_TREE_COMMIT_HASH=${GITCOMMIT}" >> $FILE_HASH
21+
if [ -z "${GITSTATUS}" ]; then
22+
echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=TRUE" >> $FILE_HASH
23+
else
24+
echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=FALSE" >> $FILE_HASH
25+
git diff >> $FILE_DIFF
26+
fi
2527
else
26-
cd -
27-
echo "export ANALYSIS_TREE_TAG=NOT_A_GIT_REPO" >> $FILE_HASH
28-
echo "export ANALYSIS_TREE_COMMIT_HASH=NOT_A_GIT_REPO" >> $FILE_HASH
29-
echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=NOT_A_GIT_REPO" >> $FILE_HASH
28+
cd -
29+
echo "export ANALYSIS_TREE_TAG=NOT_A_GIT_REPO" >> $FILE_HASH
30+
echo "export ANALYSIS_TREE_COMMIT_HASH=NOT_A_GIT_REPO" >> $FILE_HASH
31+
echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=NOT_A_GIT_REPO" >> $FILE_HASH
3032
fi

core/BranchConfig.cpp

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,50 @@ void BranchConfig::GenerateId() {
1414
id_ = id_hasher(name_);
1515
}
1616

17-
BranchConfig::BranchConfig(std::string name, DetType type) : name_(std::move(name)), type_(type) {
17+
BranchConfig::BranchConfig(std::string name, DetType type, std::string title) : name_(std::move(name)), type_(type), title_(std::move(title)) {
1818
GenerateId();
1919

2020
if (type_ == DetType::kTrack) {
21-
VectorConfig<float>::AddField("px", TrackFields::kPx, "GeV/c");
22-
VectorConfig<float>::AddField("py", TrackFields::kPy, "GeV/c");
23-
VectorConfig<float>::AddField("pz", TrackFields::kPz, "GeV/c");
24-
VectorConfig<float>::AddField("pT", TrackFields::kPt, "GeV/c");
25-
VectorConfig<float>::AddField("phi", TrackFields::kPhi, "azimuthal angle");
26-
VectorConfig<float>::AddField("eta", TrackFields::kEta, "pseudorapidity");
27-
VectorConfig<float>::AddField("p", TrackFields::kP, "GeV/c");
21+
VectorConfig<float>::AddField("px", TrackFields::kPx, "X-projection of the momentum of the track, GeV/c");
22+
VectorConfig<float>::AddField("py", TrackFields::kPy, "Y-projection of the momentum of the track, GeV/c");
23+
VectorConfig<float>::AddField("pz", TrackFields::kPz, "Z-projection of the momentum of the track, GeV/c");
24+
VectorConfig<float>::AddField("pT", TrackFields::kPt, "Transverse momentum of the track, GeV/c");
25+
VectorConfig<float>::AddField("phi", TrackFields::kPhi, "Azimuthal angle of the track, rad");
26+
VectorConfig<float>::AddField("eta", TrackFields::kEta, "Pseudorapidity of the track");
27+
VectorConfig<float>::AddField("p", TrackFields::kP, "Full momentum of the track, GeV/c");
2828
VectorConfig<int>::AddField("q", TrackFields::kQ, "Charge of the track (or its sign when absolute value unknown)");
29-
VectorConfig<int>::AddField("id", TrackFields::kId, "unique id");
29+
VectorConfig<int>::AddField("id", TrackFields::kId, "Unique id of the track within current event; assigned automatically (not by user)");
3030
} else if (type_ == DetType::kParticle) {
31-
VectorConfig<float>::AddField("px", ParticleFields::kPx, "GeV/c");
32-
VectorConfig<float>::AddField("py", ParticleFields::kPy, "GeV/c");
33-
VectorConfig<float>::AddField("pz", ParticleFields::kPz, "GeV/c");
34-
VectorConfig<float>::AddField("pT", ParticleFields::kPt, "GeV/c");
35-
VectorConfig<float>::AddField("phi", ParticleFields::kPhi, "azimuthal angle");
36-
VectorConfig<float>::AddField("eta", ParticleFields::kEta, "pseudorapidity");
37-
VectorConfig<float>::AddField("mass", ParticleFields::kMass, "GeV/c^2");
38-
VectorConfig<float>::AddField("p", ParticleFields::kP, "GeV/c");
39-
VectorConfig<float>::AddField("E", ParticleFields::kEnergy, "full energy, GeV");
40-
VectorConfig<float>::AddField("T", ParticleFields::kKineticEnergy, "kinetic energy, GeV");
41-
VectorConfig<float>::AddField("rapidity", ParticleFields::kRapidity, "in Lab. frame");
42-
VectorConfig<int>::AddField("q", ParticleFields::kQ, "Charge of the particle");
43-
VectorConfig<int>::AddField("pid", ParticleFields::kPid, "PDG code");
44-
VectorConfig<int>::AddField("id", ParticleFields::kId, "unique id");
31+
VectorConfig<float>::AddField("px", ParticleFields::kPx, "X-projection of the momentum of the particle, GeV/c");
32+
VectorConfig<float>::AddField("py", ParticleFields::kPy, "Y-projection of the momentum of the particle, GeV/c");
33+
VectorConfig<float>::AddField("pz", ParticleFields::kPz, "Z-projection of the momentum of the particle, GeV/c");
34+
VectorConfig<float>::AddField("pT", ParticleFields::kPt, "Transverse momentum of the particle, GeV/c");
35+
VectorConfig<float>::AddField("phi", ParticleFields::kPhi, "Azimuthal angle of the particle, rad");
36+
VectorConfig<float>::AddField("eta", ParticleFields::kEta, "Pseudorapidity of the particle");
37+
VectorConfig<float>::AddField("mass", ParticleFields::kMass, "Mass of the particle, GeV/c^2 (true mass of certain particle species; deprecated to use for invariant mass, mass from TOF etc.)");
38+
VectorConfig<float>::AddField("p", ParticleFields::kP, "Full momentum of the particle, GeV/c");
39+
VectorConfig<float>::AddField("E", ParticleFields::kEnergy, "Full energy of the particle, GeV");
40+
VectorConfig<float>::AddField("T", ParticleFields::kKineticEnergy, "Kinetic energy of the particle, GeV");
41+
VectorConfig<float>::AddField("rapidity", ParticleFields::kRapidity, "Rapidity of the particle");
42+
VectorConfig<int>::AddField("q", ParticleFields::kQ, "Charge of the particle (true charge of certain particle species)");
43+
VectorConfig<int>::AddField("pid", ParticleFields::kPid, "PDG code of the particle (e.g. by simulation for MC-particles or the most probable one for reconstructed particles with performed PID etc.)");
44+
VectorConfig<int>::AddField("id", ParticleFields::kId, "Unique id of the particle within current event; assigned automatically (not by user)");
4545
} else if (type_ == DetType::kHit) {
46-
VectorConfig<float>::AddField("x", HitFields::kX, "cm");
47-
VectorConfig<float>::AddField("y", HitFields::kY, "cm");
48-
VectorConfig<float>::AddField("z", HitFields::kZ, "cm");
49-
VectorConfig<float>::AddField("phi", HitFields::kPhi, "azimuthal angle");
50-
VectorConfig<float>::AddField("signal", HitFields::kSignal, "");
51-
VectorConfig<int>::AddField("id", HitFields::kId, "unique id");
46+
VectorConfig<float>::AddField("x", HitFields::kX, "X coordinate of the hit, cm");
47+
VectorConfig<float>::AddField("y", HitFields::kY, "Y coordinate of the hit, cm");
48+
VectorConfig<float>::AddField("z", HitFields::kZ, "Z coordinate of the hit, cm");
49+
VectorConfig<float>::AddField("phi", HitFields::kPhi, "Azimuthal angle of the hit, rad");
50+
VectorConfig<float>::AddField("signal", HitFields::kSignal, "Energy deposit collected in the hit");
51+
VectorConfig<int>::AddField("id", HitFields::kId, "Unique id of the hit within current event; assigned automatically (not by user)");
5252
} else if (type_ == DetType::kModule) {
53-
VectorConfig<int>::AddField("number", ModuleFields::kNumber, "module number");
54-
VectorConfig<float>::AddField("signal", ModuleFields::kSignal, "");
55-
VectorConfig<int>::AddField("id", ModuleFields::kId, "unique id");
53+
VectorConfig<int>::AddField("number", ModuleFields::kNumber, "Module number");
54+
VectorConfig<float>::AddField("signal", ModuleFields::kSignal, "Energy deposit collected in the module");
55+
VectorConfig<int>::AddField("id", ModuleFields::kId, "Unique id of the hit within current event; assigned automatically (not by user)");
5656
} else if (type_ == DetType::kEventHeader) {
57-
VectorConfig<float>::AddField("vtx_x", EventHeaderFields::kVertexX, "cm");
58-
VectorConfig<float>::AddField("vtx_y", EventHeaderFields::kVertexY, "cm");
59-
VectorConfig<float>::AddField("vtx_z", EventHeaderFields::kVertexZ, "cm");
60-
VectorConfig<int>::AddField("id", EventHeaderFields::kId, "unique id");
57+
VectorConfig<float>::AddField("vtx_x", EventHeaderFields::kVertexX, "X coordinate of the vertex, cm");
58+
VectorConfig<float>::AddField("vtx_y", EventHeaderFields::kVertexY, "Y coordinate of the vertex, cm");
59+
VectorConfig<float>::AddField("vtx_z", EventHeaderFields::kVertexZ, "Z coordinate of the vertex, cm");
60+
VectorConfig<int>::AddField("id", EventHeaderFields::kId, "Always 0, this field is not used for EventHeader and is needed for compatibility with other Container types");
6161
}
6262
}
6363

@@ -184,13 +184,18 @@ void BranchConfig::GuaranteeFieldNameVacancy(const std::string& name) const {
184184
}
185185

186186
void BranchConfig::Print() const {
187-
std::cout << "Branch " << name_ << " (id=" << id_ << ") consists of:" << std::endl;
188-
std::cout << "Floating fields:" << std::endl;
187+
std::cout << "Branch " << name_ << " (" << title_ << ") consists of:" << std::endl;
188+
std::cout << "\nFloating fields:" << std::endl;
189189
VectorConfig<float>::Print();
190-
std::cout << "Integer fields:" << std::endl;
190+
std::cout << "\nInteger fields:" << std::endl;
191191
VectorConfig<int>::Print();
192-
std::cout << "Boolean fields:" << std::endl;
192+
std::cout << "\nBoolean fields:" << std::endl;
193193
VectorConfig<bool>::Print();
194194
// std::cout << std::endl;
195195
}
196+
197+
void BranchConfig::PrintBranchId() const {
198+
std::cout << "Branch " << name_ << " (id=" << id_ << ")" << std::endl;
199+
}
200+
196201
}// namespace AnalysisTree

core/BranchConfig.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
125125
BranchConfig& operator=(const BranchConfig&) = default;
126126
~BranchConfig() override = default;
127127

128-
BranchConfig(std::string name, DetType type);
128+
BranchConfig(std::string name, DetType type, std::string title = "");
129129

130130
void Print() const override;
131131

132+
void PrintBranchId() const;
133+
132134
ANALYSISTREE_ATTR_NODISCARD Types GetFieldType(const std::string& sField) const;
133135
ANALYSISTREE_ATTR_NODISCARD ShortInt_t GetFieldId(const std::string& sField) const;
134136

@@ -159,13 +161,17 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
159161
}
160162
}
161163

164+
void SetTitle(std::string title) { title_ = std::move(title); }
165+
162166
// Getters
163167
template<typename T>
164168
ANALYSISTREE_ATTR_NODISCARD const MapType& GetMap() const { return VectorConfig<T>::GetMap(); }
165169
template<typename T>
166170
ANALYSISTREE_ATTR_NODISCARD ShortInt_t GetSize() const { return VectorConfig<T>::GetSize(); }
167171

168172
ANALYSISTREE_ATTR_NODISCARD std::string GetName() const { return name_; }
173+
ANALYSISTREE_ATTR_NODISCARD std::string GetTitle() const { return title_; }
174+
169175
template<typename T>
170176
ANALYSISTREE_ATTR_NODISCARD std::vector<std::string> GetFieldsNamesT() const {
171177
std::vector<std::string> result;
@@ -193,10 +199,11 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
193199
void GuaranteeFieldNameVacancy(const std::string& name) const;
194200

195201
std::string name_;
202+
std::string title_;
196203
size_t id_{0};
197204
DetType type_{DetType(UndefValueShort)};
198205

199-
ClassDefOverride(BranchConfig, 3);
206+
ClassDefOverride(BranchConfig, 4);
200207
};
201208

202209
// BranchConfig Merge(const BranchConfig& primary, const BranchConfig& secondary);

core/Configuration.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ void Configuration::Print(Option_t*) const {
8787
}
8888
}
8989

90+
void Configuration::PrintBranchIds() const {
91+
for (const auto& branch : branches_) {
92+
std::cout << std::endl;
93+
branch.second.PrintBranchId();
94+
}
95+
}
96+
9097
const std::string& Configuration::GetMatchName(const std::string& br1, const std::string& br2) const {
9198
auto search = matches_index_.find({br1, br2});
9299
if (search != matches_index_.end()) {

core/Configuration.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class Configuration : public TObject {
9898

9999
void Print(Option_t* = "") const;
100100

101+
void PrintBranchIds() const;
102+
101103
static MatchingIndex MakeMatchingIndex(const std::vector<MatchingConfig>& matches) {
102104
MatchingIndex result;
103105
for (auto& match : matches) {

core/Particle.cpp

Lines changed: 12 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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)