Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-09 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.1         [262657]
0011 ROOT Release   : 6.16/00       [397312]
0012 Creator        : vassalli
0013 Date           : Mon Jul 22 19:11:42 2019
0014 Host           : Linux cvmfswrite01.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            : /home/condor/local/sdcc/execute/dir_48382/training
0016 Training events: 52985
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     CutRangeMin[4]: "-1.000000e+00"
0037     CutRangeMin[5]: "-1.000000e+00"
0038 CutRangeMax[0]: "-1.000000e+00" [Maximum of allowed cut range (set per variable)]
0039     CutRangeMax[1]: "-1.000000e+00"
0040     CutRangeMax[2]: "-1.000000e+00"
0041     CutRangeMax[3]: "-1.000000e+00"
0042     CutRangeMax[4]: "-1.000000e+00"
0043     CutRangeMax[5]: "-1.000000e+00"
0044 VarProp[0]: "NotEnforced" [Categorisation of cuts]
0045     VarProp[1]: "NotEnforced"
0046     VarProp[2]: "NotEnforced"
0047     VarProp[3]: "NotEnforced"
0048     VarProp[4]: "NotEnforced"
0049     VarProp[5]: "NotEnforced"
0050 ##
0051 
0052 
0053 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
0054 
0055 NVar 6
0056 track_deta                    track_deta                    track_deta                    track_deta                                                      'F'    [0,1.75113081932]
0057 track_pT                      track_pT                      track_pT                      track_pT                                                        'F'    [0.201775103807,270.302978516]
0058 approach_dist                 approach_dist                 approach_dist                 approach_dist                                                   'F'    [5.6726735238e-06,201.640762329]
0059 vtx_radius                    vtx_radius                    vtx_radius                    vtx_radius                                                      'F'    [2.12119351505e-32,335.550384521]
0060 vtx_chi2                      vtx_chi2                      vtx_chi2                      vtx_chi2                                                        'F'    [-0.0747850388288,305.772888184]
0061 cluster_prob                  cluster_prob                  cluster_prob                  cluster_prob                                                    'F'    [0,0.999983727932]
0062 NSpec 0
0063 
0064 
0065 ============================================================================ */
0066 
0067 #include <array>
0068 #include <vector>
0069 #include <cmath>
0070 #include <string>
0071 #include <iostream>
0072 
0073 #ifndef IClassifierReader__def
0074 #define IClassifierReader__def
0075 
0076 class IClassifierReader {
0077 
0078  public:
0079 
0080    // constructor
0081    IClassifierReader() : fStatusIsClean( true ) {}
0082    virtual ~IClassifierReader() {}
0083 
0084    // return classifier response
0085    virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
0086 
0087    // returns classifier status
0088    bool IsStatusClean() const { return fStatusIsClean; }
0089 
0090  protected:
0091 
0092    bool fStatusIsClean;
0093 };
0094 
0095 #endif
0096 
0097 class ReadCuts : public IClassifierReader {
0098 
0099  public:
0100 
0101    // constructor
0102    ReadCuts( std::vector<std::string>& theInputVars )
0103       : IClassifierReader(),
0104         fClassName( "ReadCuts" ),
0105         fNvars( 6 )
0106    {
0107       // the training input variables
0108       const char* inputVars[] = { "track_deta", "track_pT", "approach_dist", "vtx_radius", "vtx_chi2", "cluster_prob" };
0109 
0110       // sanity checks
0111       if (theInputVars.size() <= 0) {
0112          std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
0113          fStatusIsClean = false;
0114       }
0115 
0116       if (theInputVars.size() != fNvars) {
0117          std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
0118                    << theInputVars.size() << " != " << fNvars << std::endl;
0119          fStatusIsClean = false;
0120       }
0121 
0122       // validate input variables
0123       for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
0124          if (theInputVars[ivar] != inputVars[ivar]) {
0125             std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
0126                       << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
0127             fStatusIsClean = false;
0128          }
0129       }
0130 
0131       // initialize min and max vectors (for normalisation)
0132       fVmin[0] = 0;
0133       fVmax[0] = 0;
0134       fVmin[1] = 0;
0135       fVmax[1] = 0;
0136       fVmin[2] = 0;
0137       fVmax[2] = 0;
0138       fVmin[3] = 0;
0139       fVmax[3] = 0;
0140       fVmin[4] = 0;
0141       fVmax[4] = 0;
0142       fVmin[5] = 0;
0143       fVmax[5] = 0;
0144 
0145       // initialize input variable types
0146       fType[0] = 'F';
0147       fType[1] = 'F';
0148       fType[2] = 'F';
0149       fType[3] = 'F';
0150       fType[4] = 'F';
0151       fType[5] = 'F';
0152 
0153       // initialize constants
0154       Initialize();
0155 
0156    }
0157 
0158    // destructor
0159    virtual ~ReadCuts() {
0160       Clear(); // method-specific
0161    }
0162 
0163    // the classifier response
0164    // "inputValues" is a vector of input values in the same order as the
0165    // variables given to the constructor
0166    double GetMvaValue( const std::vector<double>& inputValues ) const override;
0167 
0168  private:
0169 
0170    // method-specific destructor
0171    void Clear();
0172 
0173    // common member variables
0174    const char* fClassName;
0175 
0176    const size_t fNvars;
0177    size_t GetNvar()           const { return fNvars; }
0178    char   GetType( int ivar ) const { return fType[ivar]; }
0179 
0180    // normalisation of input variables
0181    double fVmin[6];
0182    double fVmax[6];
0183    double NormVariable( double x, double xmin, double xmax ) const {
0184       // normalise to output range: [-1, 1]
0185       return 2*(x - xmin)/(xmax - xmin) - 1.0;
0186    }
0187 
0188    // type of input variable: 'F' or 'I'
0189    char   fType[6];
0190 
0191    // initialize internal variables
0192    void Initialize();
0193    double GetMvaValue__( const std::vector<double>& inputValues ) const;
0194 
0195    // private members (method specific)
0196    // not implemented for class: "ReadCuts"
0197 };
0198    inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
0199    {
0200       // classifier response value
0201       double retval = 0;
0202 
0203       // classifier response, sanity check first
0204       if (!IsStatusClean()) {
0205          std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
0206                    << " because status is dirty" << std::endl;
0207          retval = 0;
0208       }
0209       else {
0210             retval = GetMvaValue__( inputValues );
0211       }
0212 
0213       return retval;
0214    }