From 3cc467e35f5ca04598e9a45705cc339d72dfe4a9 Mon Sep 17 00:00:00 2001 From: mmusich Date: Sun, 11 Feb 2024 17:19:53 +0100 Subject: [PATCH] improve test_payload_sanity --- .../test/AlignmentRcdChecker.cpp | 98 +++++++++++-------- .../test/test_payload_sanity.sh | 7 ++ 2 files changed, 63 insertions(+), 42 deletions(-) diff --git a/Alignment/MillePedeAlignmentAlgorithm/test/AlignmentRcdChecker.cpp b/Alignment/MillePedeAlignmentAlgorithm/test/AlignmentRcdChecker.cpp index 6f6ec550310d1..019e087d936b1 100644 --- a/Alignment/MillePedeAlignmentAlgorithm/test/AlignmentRcdChecker.cpp +++ b/Alignment/MillePedeAlignmentAlgorithm/test/AlignmentRcdChecker.cpp @@ -8,7 +8,10 @@ // system includes #include #include +#include #include +#include +#include // user includes #include "CondFormats/Alignment/interface/AlignTransform.h" @@ -27,6 +30,20 @@ // ROOT includes #include +namespace checker { + template + auto zip(const std::vector& v1, const std::vector& v2) { + std::vector> result; + + auto minSize = std::min(v1.size(), v2.size()); + for (size_t i = 0; i < minSize; ++i) { + result.emplace_back(v1[i], v2[i]); + } + + return result; + } +} // namespace checker + class AlignmentRcdChecker : public edm::one::EDAnalyzer<> { public: explicit AlignmentRcdChecker(const edm::ParameterSet& iConfig); @@ -40,12 +57,14 @@ class AlignmentRcdChecker : public edm::one::EDAnalyzer<> { const Alignments* refAlignments, const Alignments* alignments); - bool verbose_; - bool compareStrict_; - std::string label_; + const bool verbose_; + const bool compareStrict_; + const std::string label_; const edm::ESGetToken tkAliTokenRef_; const edm::ESGetToken tkAliTokenNew_; + + static constexpr double strictTolerance_ = 1e-4; // if in cm (i.e. 1 micron) }; AlignmentRcdChecker::AlignmentRcdChecker(const edm::ParameterSet& iConfig) @@ -69,41 +88,35 @@ void AlignmentRcdChecker::inspectRecord(const std::string& rcdname, edm::LogPrint("inspectRecord") << " with " << alignments->m_align.size() << " entries"; if (refAlignments && alignments) { - double meanX = 0; - double rmsX = 0; - double meanY = 0; - double rmsY = 0; - double meanZ = 0; - double rmsZ = 0; - double meanR = 0; - double rmsR = 0; - double dPhi; - double meanPhi = 0; - double rmsPhi = 0; - - std::vector::const_iterator iref = refAlignments->m_align.begin(); - for (std::vector::const_iterator i = alignments->m_align.begin(); i != alignments->m_align.end(); - ++i, ++iref) { - meanX += i->translation().x() - iref->translation().x(); - rmsX += pow(i->translation().x() - iref->translation().x(), 2); - - meanY += i->translation().y() - iref->translation().y(); - rmsY += pow(i->translation().y() - iref->translation().y(), 2); - - meanZ += i->translation().z() - iref->translation().z(); - rmsZ += pow(i->translation().z() - iref->translation().z(), 2); - - meanR += i->translation().perp() - iref->translation().perp(); - rmsR += pow(i->translation().perp() - iref->translation().perp(), 2); - - dPhi = i->translation().phi() - iref->translation().phi(); + double meanX = 0, rmsX = 0; + double meanY = 0, rmsY = 0; + double meanZ = 0, rmsZ = 0; + double meanR = 0, rmsR = 0; + double dPhi, meanPhi = 0, rmsPhi = 0; + + for (const auto& [alignment, refAlignment] : checker::zip(alignments->m_align, refAlignments->m_align)) { + auto delta = alignment.translation() - refAlignment.translation(); + + meanX += delta.x(); + rmsX += pow(delta.x(), 2); + + meanY += delta.y(); + rmsY += pow(delta.y(), 2); + + meanZ += delta.z(); + rmsZ += pow(delta.z(), 2); + + meanR += delta.perp(); + rmsR += pow(delta.perp(), 2); + + dPhi = alignment.translation().phi() - refAlignment.translation().phi(); if (dPhi > M_PI) dPhi -= 2.0 * M_PI; if (dPhi < -M_PI) dPhi += 2.0 * M_PI; meanPhi += dPhi; - rmsPhi += dPhi * dPhi; + rmsPhi += std::pow(dPhi, 2); } meanX /= alignments->m_align.size(); @@ -120,24 +133,25 @@ void AlignmentRcdChecker::inspectRecord(const std::string& rcdname, if (verbose_) { edm::LogPrint("inspectRecord") << " Compared to previous record:"; edm::LogPrint("inspectRecord") << " mean X shift: " << std::setw(12) << std::scientific - << std::setprecision(3) << meanX << " (RMS = " << sqrt(rmsX) << ")"; + << std::setprecision(3) << meanX << " [cm] (RMS = " << sqrt(rmsX) << " [cm])"; edm::LogPrint("inspectRecord") << " mean Y shift: " << std::setw(12) << std::scientific - << std::setprecision(3) << meanY << " (RMS = " << sqrt(rmsY) << ")"; + << std::setprecision(3) << meanY << " [cm] (RMS = " << sqrt(rmsY) << " [cm])"; edm::LogPrint("inspectRecord") << " mean Z shift: " << std::setw(12) << std::scientific - << std::setprecision(3) << meanZ << " (RMS = " << sqrt(rmsZ) << ")"; + << std::setprecision(3) << meanZ << " [cm] (RMS = " << sqrt(rmsZ) << " [cm])"; edm::LogPrint("inspectRecord") << " mean R shift: " << std::setw(12) << std::scientific - << std::setprecision(3) << meanR << " (RMS = " << sqrt(rmsR) << ")"; + << std::setprecision(3) << meanR << " [cm] (RMS = " << sqrt(rmsR) << " [cm])"; edm::LogPrint("inspectRecord") << " mean Phi shift: " << std::setw(12) << std::scientific - << std::setprecision(3) << meanPhi << " (RMS = " << sqrt(rmsPhi) << ")"; + << std::setprecision(3) << meanPhi << " [rad] (RMS = " << sqrt(rmsPhi) + << " [rad])"; } // verbose if (compareStrict_) { // do not let any of the coordinates to fluctuate less then 1um - assert(meanX < 1e-4); - assert(meanY < 1e-4); - assert(meanZ < 1e-4); - assert(meanR < 1e-4); - assert(meanPhi < 1e-4); + assert(meanX < strictTolerance_); // 1 micron + assert(meanY < strictTolerance_); // 1 micron + assert(meanZ < strictTolerance_); // 1 micron + assert(meanR < strictTolerance_); // 1 micron + assert(meanPhi < strictTolerance_); // 10 micro-rad } } else { diff --git a/Alignment/MillePedeAlignmentAlgorithm/test/test_payload_sanity.sh b/Alignment/MillePedeAlignmentAlgorithm/test/test_payload_sanity.sh index 9ee58beaa1475..a645d83677acf 100755 --- a/Alignment/MillePedeAlignmentAlgorithm/test/test_payload_sanity.sh +++ b/Alignment/MillePedeAlignmentAlgorithm/test/test_payload_sanity.sh @@ -3,5 +3,12 @@ function die { echo $1: status $2; exit $2; } echo -e "Content of the current directory is: "`ls .` INPUTFILE=alignments_MP.db + +# Check if the file exists +if [ ! -f "$INPUTFILE" ]; then + echo "Error: $INPUTFILE does not exist." + exit 1 +fi + (cmsRun ${SCRAM_TEST_PATH}/AlignmentRcdChecker_cfg.py inputSqliteFile=${INPUTFILE}) || die 'failed running AlignmentRcdChecker' $? rm $INPUTFILE