Skip to content

Commit

Permalink
Move find_ndf to the header and .cpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored and tmadlener committed Jun 28, 2024
1 parent fe9bc39 commit 7f1f063
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ void resolveRelationsTracks(TrackMapT& tracksMap, const TrackHitMapT& trackerHit
template <typename VertexMapT, typename RecoParticleMapT>
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <UTIL/PIDHandler.h>
#include <edm4hep/ParticleIDCollection.h>

#include "TMath.h"

namespace LCIO2EDM4hepConv {
template <typename LCIOType>
void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) {
Expand Down Expand Up @@ -176,31 +174,6 @@ std::vector<CollNamePair> 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 <typename VertexMapT>
std::unique_ptr<edm4hep::VertexCollection> convertVertices(const std::string& name, EVENT::LCCollection* LCCollection,
VertexMapT& vertexMap) {
Expand Down
26 changes: 25 additions & 1 deletion k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <UTIL/PIDHandler.h>

#include <iostream>
#include "TMath.h"

namespace LCIO2EDM4hepConv {

Expand Down Expand Up @@ -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

0 comments on commit 7f1f063

Please sign in to comment.