From e52e4cbf84547a90d9bbb51f7cc4c9b9f445a7db Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 2 Aug 2024 17:35:31 +0200 Subject: [PATCH 1/7] create AnalysisTreeDiff.patch even if empty --- CMakeLists.txt | 1 - cmake/AnalysisTreeHashWriter.sh | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfc492b6..a150dee8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,5 +147,4 @@ install(FILES bin COMPONENT Devel - OPTIONAL ) diff --git a/cmake/AnalysisTreeHashWriter.sh b/cmake/AnalysisTreeHashWriter.sh index a3b24923..7d02f65e 100755 --- a/cmake/AnalysisTreeHashWriter.sh +++ b/cmake/AnalysisTreeHashWriter.sh @@ -3,7 +3,7 @@ FILE_HASH=AnalysisTreeHash.sh FILE_DIFF=AnalysisTreeDiff.patch if [ -f $FILE_HASH ]; then -rm $FILE_HASH +rm $FILE_HASH $FILE_DIFF fi SRC_DIR=${1} @@ -20,8 +20,8 @@ if [ -z "${GITSTATUS}" ]; then echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=TRUE" >> $FILE_HASH else echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=FALSE" >> $FILE_HASH -git diff >> $FILE_DIFF fi +git diff >> $FILE_DIFF else cd - echo "export ANALYSIS_TREE_TAG=NOT_A_GIT_REPO" >> $FILE_HASH From 3dee913664377072b7547331733b4766303970a9 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 2 Aug 2024 18:17:21 +0200 Subject: [PATCH 2/7] add title_ to BranchConfig for detailed description if needed --- core/BranchConfig.cpp | 15 ++++++++++----- core/BranchConfig.hpp | 11 +++++++++-- core/Configuration.cpp | 7 +++++++ core/Configuration.hpp | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/core/BranchConfig.cpp b/core/BranchConfig.cpp index 23e704c7..178e1304 100644 --- a/core/BranchConfig.cpp +++ b/core/BranchConfig.cpp @@ -14,7 +14,7 @@ void BranchConfig::GenerateId() { id_ = id_hasher(name_); } -BranchConfig::BranchConfig(std::string name, DetType type) : name_(std::move(name)), type_(type) { +BranchConfig::BranchConfig(std::string name, DetType type, std::string title) : name_(std::move(name)), type_(type), title_(std::move(title)) { GenerateId(); if (type_ == DetType::kTrack) { @@ -184,13 +184,18 @@ void BranchConfig::GuaranteeFieldNameVacancy(const std::string& name) const { } void BranchConfig::Print() const { - std::cout << "Branch " << name_ << " (id=" << id_ << ") consists of:" << std::endl; - std::cout << "Floating fields:" << std::endl; + std::cout << "Branch " << name_ << " (" << title_ << ") consists of:" << std::endl; + std::cout << "\nFloating fields:" << std::endl; VectorConfig::Print(); - std::cout << "Integer fields:" << std::endl; + std::cout << "\nInteger fields:" << std::endl; VectorConfig::Print(); - std::cout << "Boolean fields:" << std::endl; + std::cout << "\nBoolean fields:" << std::endl; VectorConfig::Print(); // std::cout << std::endl; } + +void BranchConfig::PrintBranchId() const { + std::cout << "Branch " << name_ << " (id=" << id_ << ")" << std::endl; +} + }// namespace AnalysisTree diff --git a/core/BranchConfig.hpp b/core/BranchConfig.hpp index 0a944aaf..7314c873 100644 --- a/core/BranchConfig.hpp +++ b/core/BranchConfig.hpp @@ -125,10 +125,12 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi BranchConfig& operator=(const BranchConfig&) = default; ~BranchConfig() override = default; - BranchConfig(std::string name, DetType type); + BranchConfig(std::string name, DetType type, std::string title=""); void Print() const override; + void PrintBranchId() const; + ANALYSISTREE_ATTR_NODISCARD Types GetFieldType(const std::string& sField) const; ANALYSISTREE_ATTR_NODISCARD ShortInt_t GetFieldId(const std::string& sField) const; @@ -159,6 +161,8 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi } } + void SetTitle(std::string title) { title_ = std::move(title); } + // Getters template ANALYSISTREE_ATTR_NODISCARD const MapType& GetMap() const { return VectorConfig::GetMap(); } @@ -166,6 +170,8 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi ANALYSISTREE_ATTR_NODISCARD ShortInt_t GetSize() const { return VectorConfig::GetSize(); } ANALYSISTREE_ATTR_NODISCARD std::string GetName() const { return name_; } + ANALYSISTREE_ATTR_NODISCARD std::string GetTitle() const { return title_; } + template ANALYSISTREE_ATTR_NODISCARD std::vector GetFieldsNamesT() const { std::vector result; @@ -193,10 +199,11 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi void GuaranteeFieldNameVacancy(const std::string& name) const; std::string name_; + std::string title_; size_t id_{0}; DetType type_{DetType(UndefValueShort)}; - ClassDefOverride(BranchConfig, 3); + ClassDefOverride(BranchConfig, 4); }; // BranchConfig Merge(const BranchConfig& primary, const BranchConfig& secondary); diff --git a/core/Configuration.cpp b/core/Configuration.cpp index d4b29aac..36eba277 100644 --- a/core/Configuration.cpp +++ b/core/Configuration.cpp @@ -87,6 +87,13 @@ void Configuration::Print(Option_t*) const { } } +void Configuration::PrintBranchIds() const { + for (const auto& branch : branches_) { + std::cout << std::endl; + branch.second.PrintBranchId(); + } +} + const std::string& Configuration::GetMatchName(const std::string& br1, const std::string& br2) const { auto search = matches_index_.find({br1, br2}); if (search != matches_index_.end()) { diff --git a/core/Configuration.hpp b/core/Configuration.hpp index 1379faa5..4cc2d7e4 100644 --- a/core/Configuration.hpp +++ b/core/Configuration.hpp @@ -98,6 +98,8 @@ class Configuration : public TObject { void Print(Option_t* = "") const; + void PrintBranchIds() const; + static MatchingIndex MakeMatchingIndex(const std::vector& matches) { MatchingIndex result; for (auto& match : matches) { From 6e15fe4abcbadd0673111cd8309a9db554f66473 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 11:30:59 +0200 Subject: [PATCH 3/7] apply clang format --- core/BranchConfig.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/BranchConfig.hpp b/core/BranchConfig.hpp index 7314c873..dca9f6e2 100644 --- a/core/BranchConfig.hpp +++ b/core/BranchConfig.hpp @@ -125,7 +125,7 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi BranchConfig& operator=(const BranchConfig&) = default; ~BranchConfig() override = default; - BranchConfig(std::string name, DetType type, std::string title=""); + BranchConfig(std::string name, DetType type, std::string title = ""); void Print() const override; From 49ba4abab8621f6ffe5f435d3497762042a04b6b Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 12:13:54 +0200 Subject: [PATCH 4/7] rename field titles --- core/BranchConfig.cpp | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/core/BranchConfig.cpp b/core/BranchConfig.cpp index 178e1304..c3e7f318 100644 --- a/core/BranchConfig.cpp +++ b/core/BranchConfig.cpp @@ -18,46 +18,46 @@ BranchConfig::BranchConfig(std::string name, DetType type, std::string title) : GenerateId(); if (type_ == DetType::kTrack) { - VectorConfig::AddField("px", TrackFields::kPx, "GeV/c"); - VectorConfig::AddField("py", TrackFields::kPy, "GeV/c"); - VectorConfig::AddField("pz", TrackFields::kPz, "GeV/c"); - VectorConfig::AddField("pT", TrackFields::kPt, "GeV/c"); - VectorConfig::AddField("phi", TrackFields::kPhi, "azimuthal angle"); - VectorConfig::AddField("eta", TrackFields::kEta, "pseudorapidity"); - VectorConfig::AddField("p", TrackFields::kP, "GeV/c"); + VectorConfig::AddField("px", TrackFields::kPx, "X-projection of the momentum of the track, GeV/c"); + VectorConfig::AddField("py", TrackFields::kPy, "Y-projection of the momentum of the track, GeV/c"); + VectorConfig::AddField("pz", TrackFields::kPz, "Z-projection of the momentum of the track, GeV/c"); + VectorConfig::AddField("pT", TrackFields::kPt, "Transverse momentum of the track, GeV/c"); + VectorConfig::AddField("phi", TrackFields::kPhi, "Azimuthal angle of the track, rad"); + VectorConfig::AddField("eta", TrackFields::kEta, "Pseudorapidity of the track"); + VectorConfig::AddField("p", TrackFields::kP, "Full momentum of the track, GeV/c"); VectorConfig::AddField("q", TrackFields::kQ, "Charge of the track (or its sign when absolute value unknown)"); - VectorConfig::AddField("id", TrackFields::kId, "unique id"); + VectorConfig::AddField("id", TrackFields::kId, "Unique id of the track within current event; assigned automatically (not by user)"); } else if (type_ == DetType::kParticle) { - VectorConfig::AddField("px", ParticleFields::kPx, "GeV/c"); - VectorConfig::AddField("py", ParticleFields::kPy, "GeV/c"); - VectorConfig::AddField("pz", ParticleFields::kPz, "GeV/c"); - VectorConfig::AddField("pT", ParticleFields::kPt, "GeV/c"); - VectorConfig::AddField("phi", ParticleFields::kPhi, "azimuthal angle"); - VectorConfig::AddField("eta", ParticleFields::kEta, "pseudorapidity"); - VectorConfig::AddField("mass", ParticleFields::kMass, "GeV/c^2"); - VectorConfig::AddField("p", ParticleFields::kP, "GeV/c"); - VectorConfig::AddField("E", ParticleFields::kEnergy, "full energy, GeV"); - VectorConfig::AddField("T", ParticleFields::kKineticEnergy, "kinetic energy, GeV"); - VectorConfig::AddField("rapidity", ParticleFields::kRapidity, "in Lab. frame"); - VectorConfig::AddField("q", ParticleFields::kQ, "Charge of the particle"); - VectorConfig::AddField("pid", ParticleFields::kPid, "PDG code"); - VectorConfig::AddField("id", ParticleFields::kId, "unique id"); + VectorConfig::AddField("px", ParticleFields::kPx, "X-projection of the momentum of the particle, GeV/c"); + VectorConfig::AddField("py", ParticleFields::kPy, "Y-projection of the momentum of the particle, GeV/c"); + VectorConfig::AddField("pz", ParticleFields::kPz, "Z-projection of the momentum of the particle, GeV/c"); + VectorConfig::AddField("pT", ParticleFields::kPt, "Transverse momentum of the particle, GeV/c"); + VectorConfig::AddField("phi", ParticleFields::kPhi, "Azimuthal angle of the particle, rad"); + VectorConfig::AddField("eta", ParticleFields::kEta, "Pseudorapidity of the particle"); + VectorConfig::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.)"); + VectorConfig::AddField("p", ParticleFields::kP, "Full momentum of the particle, GeV/c"); + VectorConfig::AddField("E", ParticleFields::kEnergy, "Full energy of the particle, GeV"); + VectorConfig::AddField("T", ParticleFields::kKineticEnergy, "Kinetic energy of the particle, GeV"); + VectorConfig::AddField("rapidity", ParticleFields::kRapidity, "Rapidity of the particle"); + VectorConfig::AddField("q", ParticleFields::kQ, "Charge of the particle (true charge of certain particle species)"); + VectorConfig::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.)"); + VectorConfig::AddField("id", ParticleFields::kId, "Unique id of the particle within current event; assigned automatically (not by user)"); } else if (type_ == DetType::kHit) { - VectorConfig::AddField("x", HitFields::kX, "cm"); - VectorConfig::AddField("y", HitFields::kY, "cm"); - VectorConfig::AddField("z", HitFields::kZ, "cm"); - VectorConfig::AddField("phi", HitFields::kPhi, "azimuthal angle"); - VectorConfig::AddField("signal", HitFields::kSignal, ""); - VectorConfig::AddField("id", HitFields::kId, "unique id"); + VectorConfig::AddField("x", HitFields::kX, "X coordinate of the hit, cm"); + VectorConfig::AddField("y", HitFields::kY, "Y coordinate of the hit, cm"); + VectorConfig::AddField("z", HitFields::kZ, "Z coordinate of the hit, cm"); + VectorConfig::AddField("phi", HitFields::kPhi, "Azimuthal angle of the hit, rad"); + VectorConfig::AddField("signal", HitFields::kSignal, "Energy deposit collected in the hit"); + VectorConfig::AddField("id", HitFields::kId, "Unique id of the hit within current event; assigned automatically (not by user)"); } else if (type_ == DetType::kModule) { - VectorConfig::AddField("number", ModuleFields::kNumber, "module number"); - VectorConfig::AddField("signal", ModuleFields::kSignal, ""); - VectorConfig::AddField("id", ModuleFields::kId, "unique id"); + VectorConfig::AddField("number", ModuleFields::kNumber, "Module number"); + VectorConfig::AddField("signal", ModuleFields::kSignal, "Energy deposit collected in the module"); + VectorConfig::AddField("id", ModuleFields::kId, "Unique id of the hit within current event; assigned automatically (not by user)"); } else if (type_ == DetType::kEventHeader) { - VectorConfig::AddField("vtx_x", EventHeaderFields::kVertexX, "cm"); - VectorConfig::AddField("vtx_y", EventHeaderFields::kVertexY, "cm"); - VectorConfig::AddField("vtx_z", EventHeaderFields::kVertexZ, "cm"); - VectorConfig::AddField("id", EventHeaderFields::kId, "unique id"); + VectorConfig::AddField("vtx_x", EventHeaderFields::kVertexX, "X coordinate of the vertex, cm"); + VectorConfig::AddField("vtx_y", EventHeaderFields::kVertexY, "Y coordinate of the vertex, cm"); + VectorConfig::AddField("vtx_z", EventHeaderFields::kVertexZ, "Z coordinate of the vertex, cm"); + VectorConfig::AddField("id", EventHeaderFields::kId, "Always 0, this field is not used for EventHeader and is needed for compatibility with other Container types"); } } From ae24214f731754a403b270c8f26c875322d3b5b1 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 15:49:58 +0200 Subject: [PATCH 5/7] allow call Particle:: SetMass() and SetCharge() only if user knows what one does --- core/Particle.cpp | 12 ++++++++++++ core/Particle.hpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/Particle.cpp b/core/Particle.cpp index ac3939b3..0000f38c 100644 --- a/core/Particle.cpp +++ b/core/Particle.cpp @@ -14,4 +14,16 @@ void Particle::SetPid(PdgCode_t pid) { charge_ = GetChargeByPdgId(pid); } } + +void Particle::CheckIsAllowedSetMassAndChargeExplicitly() const { + if(!is_allowed_set_charge_and_mass_explicitly_) { + std::string message = "Particle::CheckIsAllowedSetMassAndChargeExplicitly(): "; + message += "mass and charge of the particle are set automatically with SetPid() call "; + message += "(unless they were already assigned with some values, incl. when copied content from Track to Particle). "; + message += "Use SetMass() and SetCharge() only if you want to set them different from PDG-true values. "; + message += "To unblock this possibility use SetIsAllowedSetMassAndChargeExplicitly() function."; + throw std::runtime_error(message); + } +} + }// namespace AnalysisTree \ No newline at end of file diff --git a/core/Particle.hpp b/core/Particle.hpp index 95eeee06..93b85cbe 100644 --- a/core/Particle.hpp +++ b/core/Particle.hpp @@ -29,11 +29,21 @@ class Particle : public Track { ANALYSISTREE_ATTR_NODISCARD Floating_t GetMass() const { return mass_; } void SetMass(Floating_t mass) { + CheckIsAllowedSetMassAndChargeExplicitly(); mass_ = mass; } + void SetCharge(Int_t charge) { + CheckIsAllowedSetMassAndChargeExplicitly(); + Track::SetCharge(charge); + } + void SetPid(PdgCode_t pid); + void SetIsAllowedSetMassAndChargeExplicitly(bool is=true) { is_allowed_set_charge_and_mass_explicitly_ = is; } + + void CheckIsAllowedSetMassAndChargeExplicitly() const; + ANALYSISTREE_ATTR_NODISCARD Floating_t GetEnergy() const { return sqrt(mass_ * mass_ + GetP() * GetP()); } ANALYSISTREE_ATTR_NODISCARD Floating_t GetKineticEnergy() const { return GetEnergy() - mass_; } @@ -90,6 +100,7 @@ class Particle : public Track { protected: Floating_t mass_{-1000.f}; PdgCode_t pid_{0}; + bool is_allowed_set_charge_and_mass_explicitly_{false};//! ClassDefOverride(Particle, 2); }; From 15efd79deb7bf5fd0a19c2736b1357d922d1822c Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 15:53:14 +0200 Subject: [PATCH 6/7] apply clang format --- core/Particle.cpp | 2 +- core/Particle.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Particle.cpp b/core/Particle.cpp index 0000f38c..779fe837 100644 --- a/core/Particle.cpp +++ b/core/Particle.cpp @@ -16,7 +16,7 @@ void Particle::SetPid(PdgCode_t pid) { } void Particle::CheckIsAllowedSetMassAndChargeExplicitly() const { - if(!is_allowed_set_charge_and_mass_explicitly_) { + if (!is_allowed_set_charge_and_mass_explicitly_) { std::string message = "Particle::CheckIsAllowedSetMassAndChargeExplicitly(): "; message += "mass and charge of the particle are set automatically with SetPid() call "; message += "(unless they were already assigned with some values, incl. when copied content from Track to Particle). "; diff --git a/core/Particle.hpp b/core/Particle.hpp index 93b85cbe..ec00a2b9 100644 --- a/core/Particle.hpp +++ b/core/Particle.hpp @@ -40,7 +40,7 @@ class Particle : public Track { void SetPid(PdgCode_t pid); - void SetIsAllowedSetMassAndChargeExplicitly(bool is=true) { is_allowed_set_charge_and_mass_explicitly_ = is; } + void SetIsAllowedSetMassAndChargeExplicitly(bool is = true) { is_allowed_set_charge_and_mass_explicitly_ = is; } void CheckIsAllowedSetMassAndChargeExplicitly() const; From 16ebadc8a7f221382d35675c214577134c1be4ae Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 17:45:04 +0200 Subject: [PATCH 7/7] fix error with git diff in AnalysisTreeHashWriter.sh --- cmake/AnalysisTreeHashWriter.sh | 40 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/cmake/AnalysisTreeHashWriter.sh b/cmake/AnalysisTreeHashWriter.sh index 7d02f65e..c09da506 100755 --- a/cmake/AnalysisTreeHashWriter.sh +++ b/cmake/AnalysisTreeHashWriter.sh @@ -2,29 +2,31 @@ FILE_HASH=AnalysisTreeHash.sh FILE_DIFF=AnalysisTreeDiff.patch -if [ -f $FILE_HASH ]; then -rm $FILE_HASH $FILE_DIFF -fi +for F in $FILE_HASH $FILE_DIFF; do + if [ -f $F ]; then + rm $F + fi +done SRC_DIR=${1} cd $SRC_DIR if [ -d ".git" ]; then -GITTAG=$(git describe --tags) -GITCOMMIT=$(git rev-parse HEAD) -GITSTATUS=$(git status --porcelain) -cd - -echo "export ANALYSIS_TREE_TAG=\"${GITTAG}\"" >> $FILE_HASH -echo "export ANALYSIS_TREE_COMMIT_HASH=${GITCOMMIT}" >> $FILE_HASH -if [ -z "${GITSTATUS}" ]; then -echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=TRUE" >> $FILE_HASH -else -echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=FALSE" >> $FILE_HASH -fi -git diff >> $FILE_DIFF + GITTAG=$(git describe --tags) + GITCOMMIT=$(git rev-parse HEAD) + GITSTATUS=$(git status --porcelain) + cd - + echo "export ANALYSIS_TREE_TAG=\"${GITTAG}\"" >> $FILE_HASH + echo "export ANALYSIS_TREE_COMMIT_HASH=${GITCOMMIT}" >> $FILE_HASH + if [ -z "${GITSTATUS}" ]; then + echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=TRUE" >> $FILE_HASH + else + echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=FALSE" >> $FILE_HASH + git diff >> $FILE_DIFF + fi else -cd - -echo "export ANALYSIS_TREE_TAG=NOT_A_GIT_REPO" >> $FILE_HASH -echo "export ANALYSIS_TREE_COMMIT_HASH=NOT_A_GIT_REPO" >> $FILE_HASH -echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=NOT_A_GIT_REPO" >> $FILE_HASH + cd - + echo "export ANALYSIS_TREE_TAG=NOT_A_GIT_REPO" >> $FILE_HASH + echo "export ANALYSIS_TREE_COMMIT_HASH=NOT_A_GIT_REPO" >> $FILE_HASH + echo "export ANALYSIS_TREE_COMMIT_ORIGINAL=NOT_A_GIT_REPO" >> $FILE_HASH fi