Skip to content

Commit

Permalink
fix FastMTT memory leak (KIT-CMS#269)
Browse files Browse the repository at this point in the history
* fix FastMTT memory leak
  • Loading branch information
harrypuuter authored and zhiyuanlcern committed Jun 6, 2024
1 parent d69b4d9 commit b064351
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 253 deletions.
79 changes: 6 additions & 73 deletions include/SVFit/FastMTT.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Math/LorentzVector.h"
#include "TBenchmark.h"
#include "TMatrixD.h"
#include <Math/Vector4D.h>
#include <bitset>
#include <string>
#include <tuple>
Expand Down Expand Up @@ -72,7 +73,7 @@ class Likelihood {
std::vector<double> parameters;

/// Bit word coding enabled likelihood components
std::bitset<128> compnentsBitWord;
std::bitset<128> componentsBitWord;

// precomputed values used to reduce the number of redundant calculations
double mVis1OverTauSquare;
Expand All @@ -94,81 +95,19 @@ class FastMTT {
void initialize();

/// Run fastMTT algorithm for given input
void run(const std::vector<fastmtt::MeasuredTauLepton> &, const double &,
const double &, const TMatrixD &);

/// Set likelihood shape parameters. Two parameters are expected:
/// power of 1/mVis, and scaling factor of mTest
/// in case of less than two parameters the default values are used:
///{6, 1.0/1.15};
void setLikelihoodParams(const std::vector<double> &aPars);

/// Set the bit word for switching on particular likelihood components
void enableComponent(fastMTT::likelihoodComponent aCompIndex);

/// Set the bit word for switching off particular likelihood components
void disableComponent(fastMTT::likelihoodComponent aCompIndex);

/// Retrieve the four momentum corresponding to the likelihood maximum
const LorentzVector &getBestP4() const { return bestP4; }

/// Retrieve the tau1 four momentum corresponding to the likelihood maximum
const LorentzVector &getTau1P4() const { return tau1P4; }

/// Retrieve the tau1 four momentum corresponding to the likelihood maximum
const LorentzVector &getTau2P4() const { return tau2P4; }

/// Retrieve x values corresponding to the likelihood maximim
std::tuple<double, double> getBestX() const;

/// Retrieve the best likelihood value
double getBestLikelihood() const;

/// Retrieve the likelihood value for given x values
double getLikelihoodForX(double *x) const;

/// Retrieve the CPU timing for given methods
/// Possible values:
/// scan
/// minimize
double getCpuTime(const std::string &method);

/// Retrieve the CPU timing for given methods
/// Possible values:
/// scan
/// minimize
double getRealTime(const std::string &method);
ROOT::Math::PtEtaPhiMVector
run(const std::vector<fastmtt::MeasuredTauLepton> &, const double &,
const double &, const TMatrixD &);

private:
static bool
compareLeptons(const fastmtt::MeasuredTauLepton &measuredTauLepton1,
const fastmtt::MeasuredTauLepton &measuredTauLepton2);

/// Run the minimalization procedure for given inputs.
/// Results are stored in internal variables accesed by
/// relevant get methods.
void minimize();

/// Run a scan over x1 and x2 [0,1] rectangle for given inputs.
/// Results are stored in internal variables accesed by
/// relevant get methods.
void scan();

// Minimizer types and algorithms.
// minimizerName minimizerAlgorithm
// Minuit /Minuit2 Migrad, Simplex,Combined,Scan (default is
// Migrad)
// Minuit2 Fumili2
// Fumili
// GSLMultiMin ConjugateFR, ConjugatePR, BFGS,
// BFGS2, SteepestDescent
// GSLMultiFit
// GSLSimAn
// Genetic
std::string minimizerName;
std::string minimizerAlgorithm;

ROOT::Math::Minimizer *minimizer;
void scan(Likelihood &myLikelihood);

/// Minimum location
std::vector<double> minimumPosition;
Expand All @@ -189,14 +128,8 @@ class FastMTT {
/// Step sizes for each minimized variable
std::vector<double> stepSizes;

ROOT::Math::Functor *likelihoodFunctor;

Likelihood myLikelihood;

LorentzVector tau1P4, tau2P4, bestP4;

TBenchmark clock;

int verbosity;
};

Expand Down
Loading

0 comments on commit b064351

Please sign in to comment.