CMS 3D CMS Logo

DeepSCGraphEvaluation.h
Go to the documentation of this file.
1 #ifndef RecoEcal_EgammaCoreTools_DeepSCGraphEvaluation_h
2 #define RecoEcal_EgammaCoreTools_DeepSCGraphEvaluation_h
3 
5 #include <vector>
6 #include <array>
7 #include <memory>
8 #include <string>
9 #include <functional>
10 #include <cmath>
11 
12 //author: Davide Valsecchi
13 //description:
14 // Handles Tensorflow DNN graphs and variables scaler configuration.
15 // To be used for DeepSC.
16 
17 namespace reco {
18 
31  };
32 
33  /*
34  * Structure representing the detector windows of a single events, to be evaluated with the DeepSC model.
35  * The index structure is described in the following
36  */
37 
38  namespace DeepSCInputs {
39  enum ScalerType {
40  MeanRms, // scale as (var - mean)/rms
41  MinMax, // scale as (var - min) (max-min)
42  None // do nothing
43  };
44  struct InputConfig {
45  // Each input variable is represented by the tuple <varname, standardization_type, par1, par2>
48  float par1;
49  float par2;
50  };
51  typedef std::vector<InputConfig> InputConfigs;
52  typedef std::map<std::string, double> FeaturesMap;
53 
54  struct Inputs {
55  std::vector<std::vector<std::vector<float>>> clustersX;
56  std::vector<std::vector<std::vector<std::vector<float>>>> hitsX;
57  std::vector<std::vector<float>> windowX;
58  std::vector<std::vector<bool>> isSeed;
59  };
60 
61  }; // namespace DeepSCInputs
62 
64  public:
67 
68  std::vector<float> getScaledInputs(const DeepSCInputs::FeaturesMap& variables,
69  const DeepSCInputs::InputConfigs& config) const;
70 
71  std::vector<std::vector<float>> evaluate(const DeepSCInputs::Inputs& inputs) const;
72 
73  // List of input variables names used to check the variables request as
74  // inputs in a dynamic way from configuration file.
75  // If an input variables is not found at construction time an expection is thrown.
76  static const std::vector<std::string> availableClusterInputs;
77  static const std::vector<std::string> availableWindowInputs;
78  static const std::vector<std::string> availableHitsInputs;
79 
80  // Configuration of the input variables including the scaling parameters.
81  // The list is used to define the vector of input features passed to the tensorflow model.
85 
86  private:
89  const std::vector<std::string>& availableInputs) const;
90 
92  std::unique_ptr<tensorflow::GraphDef> graphDef_;
93  tensorflow::Session* session_;
94  };
95 
96 }; // namespace reco
97 
98 #endif
std::vector< float > getScaledInputs(const DeepSCInputs::FeaturesMap &variables, const DeepSCInputs::InputConfigs &config) const
const DeepSCConfiguration cfg_
std::vector< std::vector< float > > windowX
DeepSCGraphEvaluation(const DeepSCConfiguration &)
Definition: config.py:1
DeepSCInputs::InputConfigs inputFeaturesClusters
static const std::vector< std::string > availableClusterInputs
static const std::vector< std::string > availableWindowInputs
DeepSCInputs::InputConfigs inputFeaturesWindows
std::map< std::string, double > FeaturesMap
std::vector< InputConfig > InputConfigs
DeepSCInputs::InputConfigs readInputFeaturesConfig(std::string file, const std::vector< std::string > &availableInputs) const
DeepSCInputs::InputConfigs inputFeaturesHits
static const std::vector< std::string > availableHitsInputs
std::vector< std::vector< std::vector< float > > > clustersX
fixed size matrix
std::unique_ptr< tensorflow::GraphDef > graphDef_
tensorflow::Session * session_
std::vector< std::vector< bool > > isSeed
std::vector< std::vector< float > > evaluate(const DeepSCInputs::Inputs &inputs) const
std::vector< std::vector< std::vector< std::vector< float > > > > hitsX