From 6c9ecc9f67ef91ee6f159327c664890a8b0991c8 Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Wed, 29 Jun 2016 19:02:32 +0200 Subject: [PATCH 1/8] replace DataAccessor::printParticleCombinations with to_string function --- include/DataAccessor.h | 3 --- include/ParticleCombination.h | 11 +++++++++++ src/DataAccessor.cxx | 7 ------- src/Model.cxx | 21 +++++++++------------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/include/DataAccessor.h b/include/DataAccessor.h index fc65d36f..3769138a 100644 --- a/include/DataAccessor.h +++ b/include/DataAccessor.h @@ -65,9 +65,6 @@ class DataAccessor const unsigned nSymmetrizationIndices() const { return NIndices_; } - /// print ParticleCombination map - void printParticleCombinations() const; - /// \return CachedDataValueSet const CachedDataValueSet& cachedDataValues() const { return CachedDataValues_; } diff --git a/include/ParticleCombination.h b/include/ParticleCombination.h index 9ee4cd16..da8d563d 100644 --- a/include/ParticleCombination.h +++ b/include/ParticleCombination.h @@ -236,6 +236,17 @@ std::string to_string(const ParticleCombination& pc); /// convert ParticleCombination with top-most parent to string std::string to_string_with_parent(const ParticleCombination& pc); +/// convert ParticleCombinationMap to string +template +inline std::string to_string(const ParticleCombinationMap& pcm) +{ + std::string s; + using std::to_string; + for (auto& kv : pcm) + s += to_string(kv.second) + " : " + to_string_with_parent(*(kv.first)); + return s; +} + /// streamer inline std::ostream& operator<<(std::ostream& os, const ParticleCombination& PC) { os << to_string(PC); return os; } diff --git a/src/DataAccessor.cxx b/src/DataAccessor.cxx index 69484089..6a5eeee9 100644 --- a/src/DataAccessor.cxx +++ b/src/DataAccessor.cxx @@ -15,13 +15,6 @@ DataAccessor::DataAccessor(const ParticleCombination::Equal& equal) : { } -//------------------------- -void DataAccessor::printParticleCombinations() const -{ - for (auto& kv : SymmetrizationIndices_) - LOG(INFO) << kv.second << " : " << to_string_with_parent(*(kv.first)); -} - //------------------------- bool DataAccessor::consistent() const { diff --git a/src/Model.cxx b/src/Model.cxx index 49e846ed..806fdfc8 100644 --- a/src/Model.cxx +++ b/src/Model.cxx @@ -359,18 +359,15 @@ void Model::prepareDataAccessors() } -#ifndef ELPP_DISABLE_DEBUG_LOGS - std::cout << "StaticDataAccessors:\n"; - for (auto& D : StaticDataAccessors_) { - std::cout << std::endl; - D->printParticleCombinations(); - } - std::cout << "DataAccessors:\n"; - for (auto& D : DataAccessors_) { - std::cout << std::endl; - D->printParticleCombinations(); - } -#endif + // print all DataAccessors + DEBUG("StaticDataAccessors:"); + std::for_each(StaticDataAccessors_.begin(), StaticDataAccessors_.end(), + [] (const StaticDataAccessor* da) {DEBUG(to_string(da->symmetrizationIndices()))}); + + DEBUG("DataAccessors:"); + DEBUG("StaticDataAccessors:"); + std::for_each(DataAccessors_.begin(), DataAccessors_.end(), + [] (const DataAccessor* da) {DEBUG(to_string(da->symmetrizationIndices()))}); lock(); } From 4f870ccd41d048c1cf2512d8ee9a50ae9c966dad Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Wed, 29 Jun 2016 19:05:27 +0200 Subject: [PATCH 2/8] make constructor explicit --- include/ParticleCombination.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ParticleCombination.h b/include/ParticleCombination.h index da8d563d..2081f625 100644 --- a/include/ParticleCombination.h +++ b/include/ParticleCombination.h @@ -107,7 +107,7 @@ class ParticleCombination : public std::enable_shared_from_this Date: Wed, 29 Jun 2016 19:34:31 +0200 Subject: [PATCH 3/8] replace FourMomenta::printMasses with masses_as_string --- examples/programs/DKKpiTest.cxx | 4 +-- include/FourMomenta.h | 6 ++--- src/FourMomenta.cxx | 47 +++++++++++++++++---------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/examples/programs/DKKpiTest.cxx b/examples/programs/DKKpiTest.cxx index cbba8b46..9464e364 100644 --- a/examples/programs/DKKpiTest.cxx +++ b/examples/programs/DKKpiTest.cxx @@ -79,7 +79,7 @@ int main( int argc, char** argv) auto data = M.createDataSet(1); DEBUG("BEFORE"); - M.fourMomenta()->printMasses(data[0]); + DEBUG(masses_as_string(*M.fourMomenta(), data[0])); LOG(INFO) << "setting squared mass ..."; auto P = M.calculateFourMomenta(massAxes, m2, D); @@ -91,7 +91,7 @@ int main( int argc, char** argv) } DEBUG("AFTER"); - M.fourMomenta()->printMasses(data[0]); + DEBUG(masses_as_string(*M.fourMomenta(), data[0])); std::cout << "alright! \n"; } diff --git a/include/FourMomenta.h b/include/FourMomenta.h index b89f7e03..d80df826 100644 --- a/include/FourMomenta.h +++ b/include/FourMomenta.h @@ -101,9 +101,6 @@ class FourMomenta : public StaticDataAccessor /// @} - /// print all masses - std::ostream& printMasses(const DataPoint& d, std::ostream& os = std::cout) const; - /// grant friend status to Model to call addParticleCombination and setFinalStateMomenta friend class Model; @@ -138,6 +135,9 @@ class FourMomenta : public StaticDataAccessor }; +/// print all masses +std::string masses_as_string(const FourMomenta& fm, const DataPoint& d); + } #endif diff --git a/src/FourMomenta.cxx b/src/FourMomenta.cxx index 2d4399bc..b84489e3 100644 --- a/src/FourMomenta.cxx +++ b/src/FourMomenta.cxx @@ -134,8 +134,9 @@ void FourMomenta::calculate(DataPoint& d, StatusManager& sm) const } //------------------------- -std::ostream& print_mp_string(std::ostream& os, unsigned n, unsigned m_p, std::shared_ptr pc, double m, FourVector p, std::shared_ptr M = nullptr) +std::string mp_string(unsigned n, unsigned m_p, std::shared_ptr pc, double m, FourVector p, std::shared_ptr M = nullptr) { + std::ostringstream os; os << std::setw(n) << indices_string(*pc) << " : " << "m = " << std::setprecision(m_p) << m << " GeV/c^2"; if (M) @@ -143,61 +144,61 @@ std::ostream& print_mp_string(std::ostream& os, unsigned n, unsigned m_p, std::s else os << " " << std::setw(m_p) << " " << " "; os << "\tp = " << p << " GeV"; - return os; + return os.str(); } //------------------------- -std::ostream& FourMomenta::printMasses(const DataPoint& d, std::ostream& os) const +std::string masses_as_string(const FourMomenta& fm, const DataPoint& d) { - os << "Invariant masses:" << std::endl; - unsigned n_fsp = model()->finalStateParticles().size(); + std::string s = "Invariant masses:\n"; + unsigned n_fsp = fm.model()->finalStateParticles().size(); unsigned n = n_fsp + 2; unsigned m_p = 6; std::set used; // print the ISP - for (auto& kv : symmetrizationIndices()) + for (auto& kv : fm.symmetrizationIndices()) // if ISP and not yet printed (should only print once) if (kv.first->indices().size() == n_fsp and used.find(kv.second) == used.end()) { - os << " ISP : "; - print_mp_string(os, n, m_p, kv.first, m(d, kv.first), p(d, kv.first)); - os << std::endl; + s += " ISP : "; + s += mp_string(n, m_p, kv.first, fm.m(d, kv.first), fm.p(d, kv.first)); + s += "\n"; used.insert(kv.second); } // print the FSP's - for (size_t i = 0; i < FSPIndices_.size(); ++i) - for (auto& kv : symmetrizationIndices()) + for (size_t i = 0; i < fm.model()->finalStateParticles().size(); ++i) + for (auto& kv : fm.symmetrizationIndices()) if (kv.first->isFinalStateParticle() and kv.first->indices()[0] == i and used.find(kv.second) == used.end()) { - os << " FSP : "; - print_mp_string(os, n, m_p, kv.first, m(d, kv.first), p(d, kv.first), model()->finalStateParticles()[i]->mass()); - os << std::endl; + s += " FSP : "; + s += mp_string(n, m_p, kv.first, fm.m(d, kv.first), fm.p(d, kv.first), fm.model()->finalStateParticles()[i]->mass()); + s += "\n"; used.insert(kv.second); } // print the rest in increasing number of particle content for (unsigned i = 2; i < n_fsp; ++i) - for (auto& kv : symmetrizationIndices()) + for (auto& kv : fm.symmetrizationIndices()) // if i-particle mass and not yet printed if (kv.first->indices().size() == i and used.find(kv.second) == used.end()) { - os << " " << i << "-p : "; - print_mp_string(os, n, m_p, kv.first, m(d, kv.first), p(d, kv.first)); - os << std::endl; + s += " " + std::to_string(i) + "-p : "; + s += mp_string(n, m_p, kv.first, fm.m(d, kv.first), fm.p(d, kv.first)); + s += "\n"; used.insert(kv.second); } // print unused - for (auto& kv : symmetrizationIndices()) + for (auto& kv : fm.symmetrizationIndices()) if (used.find(kv.second) == used.end()) { - os << " : "; - print_mp_string(os, n, m_p, kv.first, m(d, kv.first), p(d, kv.first)); - os << std::endl; + s += " : "; + s += mp_string(n, m_p, kv.first, fm.m(d, kv.first), fm.p(d, kv.first)); + s += "\n"; used.insert(kv.second); } - return os; + return s; } } From f425412f53be08c42d114170e7e19ed74efa68d1 Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Thu, 30 Jun 2016 11:19:45 +0200 Subject: [PATCH 4/8] use new function --- src/Model.cxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Model.cxx b/src/Model.cxx index 806fdfc8..f08faebd 100644 --- a/src/Model.cxx +++ b/src/Model.cxx @@ -638,9 +638,7 @@ void Model::printDataAccessors(bool printParticleCombinations) const if (printParticleCombinations) { std::cout << " \t"; - - for (const auto& pc_i : d->symmetrizationIndices()) - std::cout << *pc_i.first << ":" << pc_i.second << "; "; + to_string(d->symmetrizationIndices()); } std::cout << std::endl; From b0462df39002d0eb76fca0b314db867a8d9aa008 Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Thu, 30 Jun 2016 14:09:29 +0200 Subject: [PATCH 5/8] model's printXxx functions are now non-member Xxx_ as_string functions --- examples/programs/D3piTest.cxx | 5 ++-- examples/programs/D4piTest.cxx | 2 +- examples/programs/DKKpiTest.cxx | 2 +- include/CachedDataValue.h | 6 +++- include/CalculationStatus.h | 11 +++++--- include/Model.h | 12 ++++---- include/VariableStatus.h | 13 +++++---- src/CachedDataValue.cxx | 4 +-- src/Model.cxx | 49 +++++++++++++++++++++------------ 9 files changed, 63 insertions(+), 41 deletions(-) diff --git a/examples/programs/D3piTest.cxx b/examples/programs/D3piTest.cxx index f48dbc30..ca177751 100644 --- a/examples/programs/D3piTest.cxx +++ b/examples/programs/D3piTest.cxx @@ -118,7 +118,7 @@ int main( int argc, char** argv) std::cout << "\n"; std::cout << *M.spinAmplitudeCache() << std::endl; - M.printDataAccessors(false); + data_accessors_as_string(M, false); // get default Dalitz axes auto massAxes = M.massAxes(); @@ -136,8 +136,7 @@ int main( int argc, char** argv) data.push_back(P); } - LOG(INFO) << "AFTER"; - M.fourMomenta()->printMasses(data[0]); + masses_as_string(*M.fourMomenta(), data[0]); for (auto p : M.fourMomenta()->finalStateMomenta(data[0])) LOG(INFO) << p; diff --git a/examples/programs/D4piTest.cxx b/examples/programs/D4piTest.cxx index 0b8f6db3..5e01424d 100644 --- a/examples/programs/D4piTest.cxx +++ b/examples/programs/D4piTest.cxx @@ -116,7 +116,7 @@ int main( int argc, char** argv) std::cout << "\n"; std::cout << *M.spinAmplitudeCache() << std::endl; - M.printDataAccessors(false); + data_accessors_as_string(M, false); LOG(INFO) << "create dataPoints"; diff --git a/examples/programs/DKKpiTest.cxx b/examples/programs/DKKpiTest.cxx index 9464e364..e712ec19 100644 --- a/examples/programs/DKKpiTest.cxx +++ b/examples/programs/DKKpiTest.cxx @@ -68,7 +68,7 @@ int main( int argc, char** argv) std::cout << "\n"; std::cout << *M.spinAmplitudeCache() << std::endl; - M.printDataAccessors(false); + data_accessors_as_string(M, false); // choose default Dalitz coordinates const yap::MassAxes massAxes = M.massAxes(); diff --git a/include/CachedDataValue.h b/include/CachedDataValue.h index aa7fe9c9..e4c13ce4 100644 --- a/include/CachedDataValue.h +++ b/include/CachedDataValue.h @@ -185,8 +185,12 @@ inline bool operator==(const CachedDataValue::Status& S, const VariableStatus& s inline bool operator!=(const CachedDataValue::Status& S, const VariableStatus& s) { return S.Variable != s; } +/// to_string for CachedDataValue::Status +std::string to_string(const CachedDataValue::Status& S); + /// streaming operator for CachedDataValue::Status -std::ostream& operator<<(std::ostream& str, const CachedDataValue::Status& S); +inline std::ostream& operator<<(std::ostream& str, const CachedDataValue::Status& S) +{ return str << to_string(S); } /// \class RealCachedDataValue /// \brief Class for managing a single real cached value inside a #DataPoint diff --git a/include/CalculationStatus.h b/include/CalculationStatus.h index ea414dde..ae456273 100644 --- a/include/CalculationStatus.h +++ b/include/CalculationStatus.h @@ -31,18 +31,21 @@ enum class CalculationStatus : bool { uncalculated = false }; -inline std::ostream& operator<<(std::ostream& str, const CalculationStatus& c) +inline std::string to_string(const CalculationStatus& c) { switch (c) { case CalculationStatus::calculated: - return str << "calculated"; + return "calculated"; case CalculationStatus::uncalculated: - return str << "uncalculated"; + return "uncalculated"; default: - return str << (int) c; + return std::to_string(static_cast(c)); } } +inline std::ostream& operator<<(std::ostream& str, const CalculationStatus& c) +{ return str << to_string(c); } + } #endif diff --git a/include/Model.h b/include/Model.h index 902f6f3b..2f9c8216 100644 --- a/include/Model.h +++ b/include/Model.h @@ -209,12 +209,6 @@ class Model /// Set VariableStatus'es of all Parameter's to unchanged, or leave as fixed void setParameterFlagsToUnchanged(); - /// Print the list of DataAccessor's - void printDataAccessors(bool printParticleCombinations = true) const; - - /// Print all VariableStatus'es and CalculationStatus'es - void printFlags(const StatusManager& sm) const; - /// grant friend status to DataAccessor to register itself with this friend class DataAccessor; @@ -294,6 +288,12 @@ const double sumOfLogsOfSquaredAmplitudes(const Model& M, DataPartition& D); /// \param DP DataPartitionVector of partitions to use const double sumOfLogsOfSquaredAmplitudes(const Model& M, DataPartitionVector& DP); +/// Print the list of DataAccessor's +std::string data_accessors_as_string(const Model& m, bool printParticleCombinations = true); + +/// Print all VariableStatus'es and CalculationStatus'es +std::string flags_as_string(const Model& m, const StatusManager& sm); + } #endif diff --git a/include/VariableStatus.h b/include/VariableStatus.h index aec4a65b..e077b0e4 100644 --- a/include/VariableStatus.h +++ b/include/VariableStatus.h @@ -30,20 +30,23 @@ enum class VariableStatus : int { unchanged = +1, ///< Parameter is free but has not been changed }; -inline std::ostream& operator<<(std::ostream& str, const VariableStatus& s) +inline std::string to_string(const VariableStatus& s) { switch (s) { case VariableStatus::changed: - return str << "changed"; + return "changed"; case VariableStatus::fixed: - return str << "fixed"; + return "fixed"; case VariableStatus::unchanged: - return str << "unchanged"; + return "unchanged"; default: - return str << (int) s; + return std::to_string(static_cast(s)); } } +inline std::ostream& operator<<(std::ostream& str, const VariableStatus& c) +{ return str << to_string(c); } + } #endif diff --git a/src/CachedDataValue.cxx b/src/CachedDataValue.cxx index aea1f0b1..56875406 100644 --- a/src/CachedDataValue.cxx +++ b/src/CachedDataValue.cxx @@ -25,9 +25,9 @@ CachedDataValue::Status& CachedDataValue::Status::operator=(const VariableStatus } //------------------------- -std::ostream& operator<<(std::ostream& str, const CachedDataValue::Status& S) +std::string to_string(const CachedDataValue::Status& S) { - return str << S.Calculation << ", " << S.Variable; + return to_string(S.Calculation) + ", " + to_string(S.Variable); } //------------------------- diff --git a/src/Model.cxx b/src/Model.cxx index f08faebd..99f6421e 100644 --- a/src/Model.cxx +++ b/src/Model.cxx @@ -622,45 +622,58 @@ void Model::setParameterFlagsToUnchanged() } //------------------------- -void Model::printDataAccessors(bool printParticleCombinations) const +std::string data_accessors_as_string(const Model& m, bool printParticleCombinations) { + using std::to_string; + // header - std::cout << "DataAccessors of \n" - << "index \tnSymIndices \taddress \tname"; + std::string s = "DataAccessors of \nindex \tnSymIndices \taddress \tname"; if (printParticleCombinations) - std::cout << "\t\tparticleCombinations"; + s += "\t\tparticleCombinations"; - std::cout << std::endl; + s += "\n"; - for (const auto& d : DataAccessors_) { - std::cout << d->index() << " \t" << d->nSymmetrizationIndices() << " \t\t" << d << " \t(" << typeid(*d).name() << ") \t"; + for (const auto& d : m.dataAccessors()) { + std::stringstream ss; + ss << d; + s += to_string(d->index()) + " \t" + to_string(d->nSymmetrizationIndices()) + " \t\t" + + ss.str() + " \t(" + typeid(*d).name() + ") \t"; if (printParticleCombinations) { - std::cout << " \t"; - to_string(d->symmetrizationIndices()); + s += " \t"; + s += to_string(d->symmetrizationIndices()); } - std::cout << std::endl; + s += "\n"; } - std::cout << std::endl; + s += "\n"; + + return s; } //------------------------- -void Model::printFlags(const StatusManager& sm) const +std::string flags_as_string(const Model& m, const StatusManager& sm) { - for (const auto& d : DataAccessors_) { - std::cout << std::endl; + using std::to_string; + std::string s; + + for (const auto& d : m.dataAccessors()) { + s += "\n"; for (auto& c : d->cachedDataValues()) { - std::cout << " CachedDataValue " << c << ": "; + std::stringstream ss; + ss << c; + s += " CachedDataValue " + ss.str() + ": "; for (unsigned i = 0; i < d->nSymmetrizationIndices(); ++i) - std::cout << sm.status(*c, i) << "; "; - std::cout << "\n"; + s += to_string(sm.status(*c, i)) + "; "; + s += "\n"; } } - std::cout << std::endl; + s += "\n"; + + return s; } } From f499a1253e72854c94c4d8087bb0f43a6ee0748b Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Thu, 30 Jun 2016 14:52:10 +0200 Subject: [PATCH 6/8] printDecayChain becomes decayChainAsString; printDecayTrees becomes to_string(const std::map& decayTrees). Adapt the rest. --- examples/programs/D3piTest.cxx | 5 ++--- examples/programs/D4piTest.cxx | 6 +++--- examples/programs/DKKpiTest.cxx | 3 +-- include/DecayTree.h | 3 +++ include/DecayingParticle.h | 8 +++----- src/DecayTree.cxx | 11 +++++++++++ src/DecayingParticle.cxx | 35 +++++++++++++-------------------- src/Model.cxx | 3 ++- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/examples/programs/D3piTest.cxx b/examples/programs/D3piTest.cxx index ca177751..28134cb0 100644 --- a/examples/programs/D3piTest.cxx +++ b/examples/programs/D3piTest.cxx @@ -114,8 +114,7 @@ int main( int argc, char** argv) // std::cout << "\nHelicity angle symmetrizations with " << M.helicityAngles()->maxSymmetrizationIndex() + 1 << " indices \n"; - D->printDecayChain(); - std::cout << "\n"; + LOG(INFO) << D->decayChainAsString(); std::cout << *M.spinAmplitudeCache() << std::endl; data_accessors_as_string(M, false); @@ -173,7 +172,7 @@ int main( int argc, char** argv) [](const std::string & s, const std::complex& c) { return s + "\t" + std::to_string(real(c)) + " + " + std::to_string(imag(c));}).erase(0, 1); - LOG(INFO) << M.initialStateParticle()->printDecayTrees(); + LOG(INFO) << to_string(M.initialStateParticle()->decayTrees()); LOG(INFO) << "alright!"; } diff --git a/examples/programs/D4piTest.cxx b/examples/programs/D4piTest.cxx index 5e01424d..aeb642cc 100644 --- a/examples/programs/D4piTest.cxx +++ b/examples/programs/D4piTest.cxx @@ -3,6 +3,7 @@ #include "DataPoint.h" #include "DataSet.h" #include "DecayChannel.h" +#include "DecayTree.h" #include "FinalStateParticle.h" #include "FourMomenta.h" #include "FourVector.h" @@ -112,8 +113,7 @@ int main( int argc, char** argv) for (auto& pc_i : M.helicityAngles()->symmetrizationIndices()) std::cout << *pc_i.first << ": " << pc_i.second << "\n"; - D->printDecayChain(); - std::cout << "\n"; + LOG(INFO) << D->decayChainAsString(); std::cout << *M.spinAmplitudeCache() << std::endl; data_accessors_as_string(M, false); @@ -231,7 +231,7 @@ int main( int argc, char** argv) */ - LOG(INFO) << D->printDecayTrees(); + LOG(INFO) << to_string(M.initialStateParticle()->decayTrees()); std::cout << "alright! \n"; } diff --git a/examples/programs/DKKpiTest.cxx b/examples/programs/DKKpiTest.cxx index e712ec19..717f03af 100644 --- a/examples/programs/DKKpiTest.cxx +++ b/examples/programs/DKKpiTest.cxx @@ -64,8 +64,7 @@ int main( int argc, char** argv) std::cout << "\nHelicity angle symmetrizations with " << M.helicityAngles()->nSymmetrizationIndices() << " indices \n"; - D->printDecayChain(); - std::cout << "\n"; + LOG(INFO) << D->decayChainAsString(); std::cout << *M.spinAmplitudeCache() << std::endl; data_accessors_as_string(M, false); diff --git a/include/DecayTree.h b/include/DecayTree.h index 0890b388..3c54491f 100644 --- a/include/DecayTree.h +++ b/include/DecayTree.h @@ -162,6 +162,9 @@ FreeAmplitudeSet freeAmplitudes(const DecayTreeVector& DTV); /// \param vector of trees to check in const DecayTreeVector select_changed(const DecayTreeVector& dtv); +/// \return map of spin projections to decayTrees as string +std::string to_string(const std::map& decayTrees); + } #endif diff --git a/include/DecayingParticle.h b/include/DecayingParticle.h index 6a7cf984..818b213c 100644 --- a/include/DecayingParticle.h +++ b/include/DecayingParticle.h @@ -131,14 +131,12 @@ class DecayingParticle : public Particle /// @} /// Print complete decay chain - void printDecayChain() const - { printDecayChainLevel(0); } + std::string decayChainAsString() const + { return decayChainLevelAsString(0); } /// \return raw pointer to Model through first DecayChannel const Model* model() const override; - std::string printDecayTrees() const; - /// grant friend status to DecayChannel to call fixSolitaryFreeAmplitudes() /// and storeBlattWeisskopf() friend DecayChannel; @@ -165,7 +163,7 @@ class DecayingParticle : public Particle /// if only one decay channel is available, fix its free amplitude to the current value void fixSolitaryFreeAmplitudes(); - void printDecayChainLevel(int level) const; + std::string decayChainLevelAsString(int level) const; /// modify a DecayTree /// \param dt DecayTree to modify diff --git a/src/DecayTree.cxx b/src/DecayTree.cxx index 73bbcb86..b29c1b7a 100644 --- a/src/DecayTree.cxx +++ b/src/DecayTree.cxx @@ -176,4 +176,15 @@ const DecayTreeVector select_changed(const DecayTreeVector& dtv) return C; } +//------------------------- +std::string to_string(const std::map& decayTrees) +{ + std::string s; + for (const auto& m_dtv : decayTrees) { + for (const auto& dt : m_dtv.second) + s += "\ndepth = " + std::to_string(depth(*dt)) + "\n" + dt->asString() + "\n"; + } + return s; +} + } diff --git a/src/DecayingParticle.cxx b/src/DecayingParticle.cxx index 936a2c7d..b3ac26a5 100644 --- a/src/DecayingParticle.cxx +++ b/src/DecayingParticle.cxx @@ -260,8 +260,10 @@ std::vector< std::shared_ptr > DecayingParticle::finalStateP } //------------------------- -void DecayingParticle::printDecayChainLevel(int level) const +std::string DecayingParticle::decayChainLevelAsString(int level) const { + std::ostringstream os; + // get maximum length of particle names static size_t padding = 0; static size_t paddingSpinAmp = 0; @@ -271,33 +273,35 @@ void DecayingParticle::printDecayChainLevel(int level) const for (std::shared_ptr d : c->daughters()) { padding = std::max(padding, d->name().length()); if (std::dynamic_pointer_cast(d)) - std::static_pointer_cast(d)->printDecayChainLevel(-1); + os << std::static_pointer_cast(d)->decayChainLevelAsString(-1); paddingSpinAmp = std::max(paddingSpinAmp, to_string(c->spinAmplitudes()).length()); } } if (level == -1) - return; + return os.str(); } for (size_t i = 0; i < Channels_.size(); ++i) { if (i > 0) - std::cout << "\n" << std::setw(level * (padding * 3 + 8 + paddingSpinAmp)) << ""; + os << "\n" << std::setw(level * (padding * 3 + 8 + paddingSpinAmp)) << ""; - std::cout << std::left << std::setw(padding) << this->name() << " ->"; + os << std::left << std::setw(padding) << this->name() << " ->"; for (std::shared_ptr d : Channels_[i]->daughters()) - std::cout << " " << std::setw(padding) << d->name(); - std::cout << std::left << std::setw(paddingSpinAmp) + os << " " << std::setw(padding) << d->name(); + os << std::left << std::setw(paddingSpinAmp) << to_string(Channels_[i]->spinAmplitudes()); for (std::shared_ptr d : Channels_[i]->daughters()) if (std::dynamic_pointer_cast(d)) { - std::cout << ", "; - std::static_pointer_cast(d)->printDecayChainLevel(level + 1); + os << ", "; + os << std::static_pointer_cast(d)->decayChainLevelAsString(level + 1); } } if (level == 0) - std::cout << "\n"; + os << "\n"; + + return os.str(); } //------------------------- @@ -364,17 +368,6 @@ void DecayingParticle::modifyDecayTree(DecayTree& dt) const } } -//------------------------- -std::string DecayingParticle::printDecayTrees() const -{ - std::string s; - for (const auto& m_dtv : DecayTrees_) { - for (const auto& dt : m_dtv.second) - s += "\ndepth = " + std::to_string(depth(*dt)) + "\n" + dt->asString() + "\n"; - } - return s; -} - //------------------------- const std::complex amplitude(const std::map& m_dtv_map, const DataPoint& d) { diff --git a/src/Model.cxx b/src/Model.cxx index 99f6421e..c4ac8501 100644 --- a/src/Model.cxx +++ b/src/Model.cxx @@ -8,6 +8,7 @@ #include "DataSet.h" #include "DecayChannel.h" #include "DecayingParticle.h" +#include "DecayTree.h" #include "FinalStateParticle.h" #include "FourMomenta.h" #include "HelicityAngles.h" @@ -72,7 +73,7 @@ const double sum_of_logs_of_squared_amplitudes(const Model& M, DataPartition& D) // incoherently sum over initialStateParticles for (auto& kv : M.initialStateParticles()) { FDEBUG("calculate amplitude for " << to_string(*kv.first) << " with decay trees:"); - DEBUG(kv.first->printDecayTrees()); + DEBUG(to_string(kv.first->decayTrees())); L += log(kv.second->value() * norm(amplitude(kv.first->decayTrees(), d))); } } From c250d323ce9cb65e29ba50853c41bd6c34f4a377 Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Thu, 30 Jun 2016 14:59:12 +0200 Subject: [PATCH 7/8] doxy and comments --- include/DecayingParticle.h | 2 +- include/FourMomenta.h | 2 +- include/Model.h | 6 ++++-- src/FourMomenta.cxx | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/DecayingParticle.h b/include/DecayingParticle.h index 818b213c..634d993f 100644 --- a/include/DecayingParticle.h +++ b/include/DecayingParticle.h @@ -130,7 +130,7 @@ class DecayingParticle : public Particle /// @} - /// Print complete decay chain + /// \return complete decay chain as (multiline) string std::string decayChainAsString() const { return decayChainLevelAsString(0); } diff --git a/include/FourMomenta.h b/include/FourMomenta.h index d80df826..fced8e07 100644 --- a/include/FourMomenta.h +++ b/include/FourMomenta.h @@ -135,7 +135,7 @@ class FourMomenta : public StaticDataAccessor }; -/// print all masses +/// \return all masses as (multiline) string std::string masses_as_string(const FourMomenta& fm, const DataPoint& d); } diff --git a/include/Model.h b/include/Model.h index 2f9c8216..b9b75032 100644 --- a/include/Model.h +++ b/include/Model.h @@ -288,10 +288,12 @@ const double sumOfLogsOfSquaredAmplitudes(const Model& M, DataPartition& D); /// \param DP DataPartitionVector of partitions to use const double sumOfLogsOfSquaredAmplitudes(const Model& M, DataPartitionVector& DP); -/// Print the list of DataAccessor's +/// \return the list of DataAccessor's as (multiline) string +/// \param m Model to print DataAccessor's of +/// \param printParticleCombinations also print ParticleCombination's of each DataAccessor std::string data_accessors_as_string(const Model& m, bool printParticleCombinations = true); -/// Print all VariableStatus'es and CalculationStatus'es +/// \return all VariableStatus'es and CalculationStatus'es as (multiline) string std::string flags_as_string(const Model& m, const StatusManager& sm); } diff --git a/src/FourMomenta.cxx b/src/FourMomenta.cxx index b84489e3..744351f9 100644 --- a/src/FourMomenta.cxx +++ b/src/FourMomenta.cxx @@ -157,7 +157,7 @@ std::string masses_as_string(const FourMomenta& fm, const DataPoint& d) std::set used; - // print the ISP + // the ISP for (auto& kv : fm.symmetrizationIndices()) // if ISP and not yet printed (should only print once) if (kv.first->indices().size() == n_fsp and used.find(kv.second) == used.end()) { @@ -167,7 +167,7 @@ std::string masses_as_string(const FourMomenta& fm, const DataPoint& d) used.insert(kv.second); } - // print the FSP's + // the FSP's for (size_t i = 0; i < fm.model()->finalStateParticles().size(); ++i) for (auto& kv : fm.symmetrizationIndices()) if (kv.first->isFinalStateParticle() and kv.first->indices()[0] == i and used.find(kv.second) == used.end()) { @@ -178,7 +178,7 @@ std::string masses_as_string(const FourMomenta& fm, const DataPoint& d) } - // print the rest in increasing number of particle content + // the rest in increasing number of particle content for (unsigned i = 2; i < n_fsp; ++i) for (auto& kv : fm.symmetrizationIndices()) // if i-particle mass and not yet printed @@ -189,7 +189,7 @@ std::string masses_as_string(const FourMomenta& fm, const DataPoint& d) used.insert(kv.second); } - // print unused + // unused for (auto& kv : fm.symmetrizationIndices()) if (used.find(kv.second) == used.end()) { s += " : "; From 9b122da250c038ccbbe732c3aa2a8749c2a9c495 Mon Sep 17 00:00:00 2001 From: Johannes Rauch Date: Thu, 30 Jun 2016 15:11:47 +0200 Subject: [PATCH 8/8] forgot to output strings --- examples/programs/D3piTest.cxx | 6 +++--- examples/programs/D4piTest.cxx | 4 ++-- examples/programs/DKKpiTest.cxx | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/programs/D3piTest.cxx b/examples/programs/D3piTest.cxx index 28134cb0..af04623d 100644 --- a/examples/programs/D3piTest.cxx +++ b/examples/programs/D3piTest.cxx @@ -116,8 +116,8 @@ int main( int argc, char** argv) LOG(INFO) << D->decayChainAsString(); - std::cout << *M.spinAmplitudeCache() << std::endl; - data_accessors_as_string(M, false); + LOG(INFO) << *M.spinAmplitudeCache() << std::endl; + LOG(INFO) << data_accessors_as_string(M, false); // get default Dalitz axes auto massAxes = M.massAxes(); @@ -135,7 +135,7 @@ int main( int argc, char** argv) data.push_back(P); } - masses_as_string(*M.fourMomenta(), data[0]); + LOG(INFO) << masses_as_string(*M.fourMomenta(), data[0]); for (auto p : M.fourMomenta()->finalStateMomenta(data[0])) LOG(INFO) << p; diff --git a/examples/programs/D4piTest.cxx b/examples/programs/D4piTest.cxx index aeb642cc..d7c42741 100644 --- a/examples/programs/D4piTest.cxx +++ b/examples/programs/D4piTest.cxx @@ -115,8 +115,8 @@ int main( int argc, char** argv) LOG(INFO) << D->decayChainAsString(); - std::cout << *M.spinAmplitudeCache() << std::endl; - data_accessors_as_string(M, false); + LOG(INFO) << *M.spinAmplitudeCache() << std::endl; + LOG(INFO) << data_accessors_as_string(M, false); LOG(INFO) << "create dataPoints"; diff --git a/examples/programs/DKKpiTest.cxx b/examples/programs/DKKpiTest.cxx index 717f03af..d31a21ff 100644 --- a/examples/programs/DKKpiTest.cxx +++ b/examples/programs/DKKpiTest.cxx @@ -66,8 +66,8 @@ int main( int argc, char** argv) LOG(INFO) << D->decayChainAsString(); - std::cout << *M.spinAmplitudeCache() << std::endl; - data_accessors_as_string(M, false); + LOG(INFO) << *M.spinAmplitudeCache() << std::endl; + LOG(INFO) << data_accessors_as_string(M, false); // choose default Dalitz coordinates const yap::MassAxes massAxes = M.massAxes();