From 7f1f063fee8c3b457e1596f8f0161fda60460fc1 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 20 Jun 2024 15:55:38 +0200 Subject: [PATCH] Move find_ndf to the header and .cpp file --- .../k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h | 5 ++++ .../k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp | 27 ------------------- k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp | 26 +++++++++++++++++- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h index 11826eb..1004649 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h @@ -397,6 +397,11 @@ void resolveRelationsTracks(TrackMapT& tracksMap, const TrackHitMapT& trackerHit template void resolveRelationsVertices(VertexMapT& vertexMap, const RecoParticleMapT& recoparticleMap); +/** + * Go from chi^2 and probability (1 - CDF(chi^2, ndf)) to ndf by a binary search + */ +int find_ndf(double chi2, double prob); + } // namespace LCIO2EDM4hepConv #include "k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp" diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp index 9c28bba..915859f 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp @@ -3,8 +3,6 @@ #include #include -#include "TMath.h" - namespace LCIO2EDM4hepConv { template void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) { @@ -176,31 +174,6 @@ std::vector convertReconstructedParticles(const std::string& name, return results; } -// Go from chi^2 and probability (1 - CDF(chi^2, ndf)) -// to ndf by a binary search -int find_ndf(double chi2, double prob) { - int lower = 0; - // Initial guess for the upper bound. If it's not enough, it will be increased - int upper = 100; - while (TMath::Prob(chi2, upper) < prob) { - lower = upper; - upper *= 2; - } - while (lower < upper - 1) { - int mid = (lower + upper) / 2; - if (TMath::Prob(chi2, mid) < prob) { - lower = mid; - } else { - upper = mid; - } - } - if (std::abs(TMath::Prob(chi2, lower) - prob) < std::abs(TMath::Prob(chi2, upper) - prob)) { - return lower; - } else { - return upper; - } -} - template std::unique_ptr convertVertices(const std::string& name, EVENT::LCCollection* LCCollection, VertexMapT& vertexMap) { diff --git a/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp b/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp index ce7ce4d..ecf0b9e 100644 --- a/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp +++ b/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp @@ -2,7 +2,7 @@ #include -#include +#include "TMath.h" namespace LCIO2EDM4hepConv { @@ -152,4 +152,28 @@ podio::Frame convertRunHeader(EVENT::LCRunHeader* rheader) { return runHeaderFrame; } +int find_ndf(double chi2, double prob) { + int lower = 0; + // Initial guess for the upper bound. If it's not enough, it will be increased + int upper = 100; + while (TMath::Prob(chi2, upper) < prob) { + lower = upper; + upper *= 2; + } + while (lower < upper - 1) { + int mid = (lower + upper) / 2; + if (TMath::Prob(chi2, mid) < prob) { + lower = mid; + } else { + upper = mid; + } + } + if (std::abs(TMath::Prob(chi2, lower) - prob) < std::abs(TMath::Prob(chi2, upper) - prob)) { + return lower; + } else { + return upper; + } +} + + } // namespace LCIO2EDM4hepConv