Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:14:27

0001 // Class: ReadCuts
0002 // Automatically generated by MethodBase::MakeClass
0003 //
0004 
0005 /* configuration options =====================================================
0006 
0007 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
0008 
0009 Method         : Cuts::Cuts
0010 TMVA Release   : 4.2.0         [262656]
0011 ROOT Release   : 5.34/38       [336422]
0012 Creator        : vassalli
0013 Date           : Fri Aug 23 18:23:25 2019
0014 Host           : Linux cvmfswrite02.sdcc.bnl.gov 3.10.0-693.11.6.el7.x86_64 #1 SMP Wed Jan 3 18:09:42 CST 2018 x86_64 x86_64 x86_64 GNU/Linux
0015 Dir            : /direct/phenix+u/vassalli/sphenix/single/Training
0016 Training events: 7408
0017 Analysis type  : [Classification]
0018 
0019 
0020 #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
0021 
0022 # Set by User:
0023 # Default:
0024 V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
0025 VerbosityLevel: "Default" [Verbosity level]
0026 VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"]
0027 H: "False" [Print method-specific help message]
0028 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
0029 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
0030 FitMethod: "GA" [Minimisation Method (GA, SA, and MC are the primary methods to be used; the others have been introduced for testing purposes and are depreciated)]
0031 EffMethod: "EffSel" [Selection Method]
0032 CutRangeMin[0]: "-1.000000e+00" [Minimum of allowed cut range (set per variable)]
0033     CutRangeMin[1]: "-1.000000e+00"
0034     CutRangeMin[2]: "-1.000000e+00"
0035     CutRangeMin[3]: "-1.000000e+00"
0036 CutRangeMax[0]: "-1.000000e+00" [Maximum of allowed cut range (set per variable)]
0037     CutRangeMax[1]: "-1.000000e+00"
0038     CutRangeMax[2]: "-1.000000e+00"
0039     CutRangeMax[3]: "-1.000000e+00"
0040 VarProp[0]: "NotEnforced" [Categorisation of cuts]
0041     VarProp[1]: "NotEnforced"
0042     VarProp[2]: "NotEnforced"
0043     VarProp[3]: "NotEnforced"
0044 ##
0045 
0046 
0047 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
0048 
0049 NVar 4
0050 track_layer                   track_layer                   track_layer                   track_layer                                                     'I'    [0,23]
0051 track_pT                      track_pT                      track_pT                      track_pT                                                        'F'    [2.00562024117,23268.8671875]
0052 track_dca                     track_dca                     track_dca                     track_dca                                                       'F'    [1.9280396657e-07,64.1147155762]
0053 cluster_prob                  cluster_prob                  cluster_prob                  cluster_prob                                                    'F'    [0,0.999049782753]
0054 NSpec 0
0055 
0056 
0057 ============================================================================ */
0058 
0059 #include <vector>
0060 #include <cmath>
0061 #include <string>
0062 #include <iostream>
0063 
0064 #ifndef IClassifierReader__def
0065 #define IClassifierReader__def
0066 
0067 class IClassifierReader {
0068 
0069  public:
0070 
0071    // constructor
0072    IClassifierReader() : fStatusIsClean( true ) {}
0073    virtual ~IClassifierReader() {}
0074 
0075    // return classifier response
0076    virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
0077 
0078    // returns classifier status
0079    bool IsStatusClean() const { return fStatusIsClean; }
0080 
0081  protected:
0082 
0083    bool fStatusIsClean;
0084 };
0085 
0086 #endif
0087 
0088 class ReadCuts : public IClassifierReader {
0089 
0090  public:
0091 
0092    // constructor
0093    ReadCuts( std::vector<std::string>& theInputVars ) 
0094       : IClassifierReader(),
0095         fClassName( "ReadCuts" ),
0096         fNvars( 4 ),
0097         fIsNormalised( false )
0098    {      
0099       // the training input variables
0100       const char* inputVars[] = { "track_layer", "track_pT", "track_dca", "cluster_prob" };
0101 
0102       // sanity checks
0103       if (theInputVars.size() <= 0) {
0104          std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
0105          fStatusIsClean = false;
0106       }
0107 
0108       if (theInputVars.size() != fNvars) {
0109          std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
0110                    << theInputVars.size() << " != " << fNvars << std::endl;
0111          fStatusIsClean = false;
0112       }
0113 
0114       // validate input variables
0115       for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
0116          if (theInputVars[ivar] != inputVars[ivar]) {
0117             std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
0118                       << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
0119             fStatusIsClean = false;
0120          }
0121       }
0122 
0123       // initialize min and max vectors (for normalisation)
0124       fVmin[0] = 0;
0125       fVmax[0] = 0;
0126       fVmin[1] = 0;
0127       fVmax[1] = 0;
0128       fVmin[2] = 0;
0129       fVmax[2] = 0;
0130       fVmin[3] = 0;
0131       fVmax[3] = 0;
0132 
0133       // initialize input variable types
0134       fType[0] = 'I';
0135       fType[1] = 'F';
0136       fType[2] = 'F';
0137       fType[3] = 'F';
0138 
0139       // initialize constants
0140       Initialize();
0141 
0142    }
0143 
0144    // destructor
0145    virtual ~ReadCuts() {
0146       Clear(); // method-specific
0147    }
0148 
0149    // the classifier response
0150    // "inputValues" is a vector of input values in the same order as the 
0151    // variables given to the constructor
0152    double GetMvaValue( const std::vector<double>& inputValues ) const;
0153 
0154  private:
0155 
0156    // method-specific destructor
0157    void Clear();
0158 
0159    // common member variables
0160    const char* fClassName;
0161 
0162    const size_t fNvars;
0163    size_t GetNvar()           const { return fNvars; }
0164    char   GetType( int ivar ) const { return fType[ivar]; }
0165 
0166    // normalisation of input variables
0167    const bool fIsNormalised;
0168    bool IsNormalised() const { return fIsNormalised; }
0169    double fVmin[4];
0170    double fVmax[4];
0171    double NormVariable( double x, double xmin, double xmax ) const {
0172       // normalise to output range: [-1, 1]
0173       return 2*(x - xmin)/(xmax - xmin) - 1.0;
0174    }
0175 
0176    // type of input variable: 'F' or 'I'
0177    char   fType[4];
0178 
0179    // initialize internal variables
0180    void Initialize();
0181    double GetMvaValue__( const std::vector<double>& inputValues ) const;
0182 
0183    // private members (method specific)
0184    // not implemented for class: "ReadCuts"
0185 };
0186    inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
0187    {
0188       // classifier response value
0189       double retval = 0;
0190 
0191       // classifier response, sanity check first
0192       if (!IsStatusClean()) {
0193          std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
0194                    << " because status is dirty" << std::endl;
0195          retval = 0;
0196       }
0197       else {
0198          if (IsNormalised()) {
0199             // normalise variables
0200             std::vector<double> iV;
0201             iV.reserve(inputValues.size());
0202             int ivar = 0;
0203             for (std::vector<double>::const_iterator varIt = inputValues.begin();
0204                  varIt != inputValues.end(); varIt++, ivar++) {
0205                iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
0206             }
0207             retval = GetMvaValue__( iV );
0208          }
0209          else {
0210             retval = GetMvaValue__( inputValues );
0211          }
0212       }
0213 
0214       return retval;
0215    }