Skip to content

Commit

Permalink
Moved declaration of TMVAReader to header; Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarianaT27 authored and Mariana Tenorio Pita committed Jan 14, 2025
1 parent 2ae3b9d commit 7ee9977
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 40 deletions.
23 changes: 1 addition & 22 deletions src/iguana/algorithms/clas12/LeptonIDFilter/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@ namespace iguana::clas12 {

double LeptonIDFilter::CalculateScore(LeptonIDVars lepton_vars) const{

//Get TMVA reader
TString silent_opt = m_log->GetLevel() <= Logger::Level::trace ? "!Silent" : "Silent";
TMVA::Reader *readerTMVA = new TMVA::Reader( "!Color" + silent_opt );
// Create a set of variables and declare them to the reader
Float_t P, Theta, Phi, PCAL,ECIN,ECOUT,m2PCAL,m2ECIN,m2ECOUT;
@doxygen_off
///Assing variables from lepton_vars for TMVA method
P=lepton_vars.P;
Theta=lepton_vars.Theta;
Phi=lepton_vars.Phi;
Expand All @@ -135,24 +130,8 @@ namespace iguana::clas12 {
m2PCAL=lepton_vars.m2pcal;
m2ECIN=lepton_vars.m2ecin;
m2ECOUT=lepton_vars.m2ecout;
@doxygen_on

readerTMVA->AddVariable( "P",&P );
readerTMVA->AddVariable( "Theta",&Theta);
readerTMVA->AddVariable( "Phi",&Phi);
readerTMVA->AddVariable( "SFPCAL",&PCAL);
readerTMVA->AddVariable( "SFECIN",&ECIN);
readerTMVA->AddVariable( "SFECOUT",&ECOUT );
readerTMVA->AddVariable( "m2PCAL",&m2PCAL);
readerTMVA->AddVariable( "m2ECIN",&m2ECIN);
readerTMVA->AddVariable( "m2ECOUT",&m2ECOUT);

m_log->Debug("Add variables to readerTMVA");

readerTMVA->BookMVA( "BDT", o_weightfile_fullpath );

m_log->Debug("TMVA method booked");

auto score=readerTMVA->EvaluateMVA("BDT");

return score;
Expand Down
83 changes: 65 additions & 18 deletions src/iguana/algorithms/clas12/LeptonIDFilter/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
#include "iguana/algorithms/Algorithm.h"

namespace iguana::clas12 {

/// Set of lepton ID variables
struct LeptonIDVars {
double P;
double Theta;
double Phi;
double SFpcal;
double SFecin;
double SFecout;
double m2pcal;
double m2ecin;
double m2ecout;
double score;
};

///
/// @brief_algo Filter the leptons from the pion contamination using TMVA models
///
Expand Down Expand Up @@ -70,15 +55,77 @@ namespace iguana::clas12 {


private:

/// `hipo::banklist` index for the particle bank (as an example)
///Struct to store variables
struct LeptonIDVars {
/// @brief momentum
double P;
/// @brief Theta angle
double Theta;
/// @brief Phi angle
double Phi;
/// @brief Sampling fraction on the PCAL
double SFpcal;
/// @brief Sampling fraction on the ECIN
double SFecin;
/// @brief Sampling fraction on the ECOUT
double SFecout;
/// @brief Second-momenta of PCAL
double m2pcal;
/// @brief Second-momenta of ECIN
double m2ecin;
/// @brief Second-momenta of ECOUT
double m2ecout;
/// @brief Score
double score;
};

/// `hipo::banklist`
hipo::banklist::size_type b_particle;
hipo::banklist::size_type b_calorimeter;

/// Example integer configuration option
//Create TMVA reader
TMVA::Reader *readerTMVA = new TMVA::Reader();

///Set of variables for the reader
///Momentum
Float_t P;
///Theta angle
Float_t Theta;
///Phi angle
Float_t Phi;
///Sampling fraction on the PCAL
Float_t PCAL;
///Sampling fraction on the ECIN
Float_t ECIN;
///Sampling fraction on the ECOUT
Float_t ECOUT;
///Second-momenta of PCAL
Float_t m2PCAL;
///Second-momenta of ECIN
Float_t m2ECIN;
///Second-momenta of ECOUT
Float_t m2ECOUT;

/// @brief Add variables to the readerTMVA
readerTMVA->AddVariable( "P",&P );
readerTMVA->AddVariable( "Theta",&Theta);
readerTMVA->AddVariable( "Phi",&Phi);
readerTMVA->AddVariable( "SFPCAL",&PCAL);
readerTMVA->AddVariable( "SFECIN",&ECIN);
readerTMVA->AddVariable( "SFECOUT",&ECOUT );
readerTMVA->AddVariable( "m2PCAL",&m2PCAL);
readerTMVA->AddVariable( "m2ECIN",&m2ECIN);
readerTMVA->AddVariable( "m2ECOUT",&m2ECOUT);

readerTMVA->BookMVA( "BDT", o_weightfile_fullpath );


/// pid of the lepton
int o_pid;
/// Location of the weight file
std::string o_weightfile;
std::string o_weightfile_fullpath;
/// Value of the cut
double o_cut;
};

Expand Down

0 comments on commit 7ee9977

Please sign in to comment.