ATLAS Offline Software
TFCSPredictExtrapWeights.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ISF_FASTCALOSIMEVENT_TFCSPREDICTEXTRAPWEIGHTS_h
6 #define ISF_FASTCALOSIMEVENT_TFCSPREDICTEXTRAPWEIGHTS_h
7 
10 #include <string>
11 #include "TH2D.h"
12 
13 // forward declare lwtnn dependencies
14 namespace lwt {
15 class LightweightNeuralNetwork;
16 }
17 
19 public:
20  TFCSPredictExtrapWeights(const char *name = nullptr,
21  const char *title = nullptr);
22  virtual ~TFCSPredictExtrapWeights();
23 
24  virtual bool operator==(const TFCSParametrizationBase &ref) const override;
25 
26  // Used to decorate simulstate with extrapolation weights
27  virtual FCSReturnCode
28  simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth,
29  const TFCSExtrapolationState *extrapol) const override;
30 
31  // Used to decorate Hit with extrapolated center positions
32  virtual FCSReturnCode
33  simulate_hit(Hit &hit, TFCSSimulationState &simulstate,
34  const TFCSTruthState *truth,
35  const TFCSExtrapolationState *extrapol) override;
36 
37  // Status bit for chain persistency
38  enum FCSfreemem {
39  kfreemem = BIT(17)
40  };
42  bool freemem() const { return TestBit(kfreemem); };
43  void set_freemem() { SetBit(kfreemem); };
44 
45  // Initialize Neural Network
46  bool initializeNetwork(int pid, const std::string &etaBin,
47  const std::string &FastCaloNNInputFolderName);
48 
49  // Get inputs needed to normalize data
50  bool getNormInputs(const std::string &etaBin,
51  const std::string &FastCaloTXTInputFolderName);
52 
53  // Test function
54  static void test_path(std::string &net_path, std::string const &norm_path,
55  TFCSSimulationState *simulstate = nullptr,
56  const TFCSTruthState *truth = nullptr,
57  const TFCSExtrapolationState *extrapol = nullptr);
58  static void unit_test(TFCSSimulationState *simulstate = nullptr,
59  const TFCSTruthState *truth = nullptr,
60  const TFCSExtrapolationState *extrapol = nullptr);
61 
62  // Prepare inputs to the Neural Network
63  std::map<std::string, double> prepareInputs(TFCSSimulationState &simulstate,
64  const float truthE) const;
65 
66  // Print()
67  void Print(Option_t *option = "") const override;
68 
69  // Use extrapWeight=0.5 or r and z when constructing a hit?
71  bool UseHardcodedWeight() const { return TestBit(kUseHardcodedWeight); };
74 
75 private:
76  // Persistify configuration in string m_input. A custom Streamer(...) builds
77  // m_nn on the fly when reading from file.
78  // Inside Athena, if freemem() is true, the content of m_input is deleted
79  // after reading in order to free memory
80  std::string *m_input = nullptr;
81  std::vector<int> *m_relevantLayers = nullptr;
82  lwt::LightweightNeuralNetwork *m_nn = nullptr;
83  std::vector<int> *m_normLayers =
84  nullptr; // vector of index layers (-1 corresponds to truth energy)
85  std::vector<float> *m_normMeans =
86  nullptr; // vector of mean values for normalizing energy fraction per
87  // layer, last index is for total energy
88  std::vector<float> *m_normStdDevs =
89  nullptr; // vector of std dev values for normalizing energy fraction per
90  // layer, last index is for total energy
91 
92  ClassDefOverride(TFCSPredictExtrapWeights, 1) // TFCSPredictExtrapWeights
93 };
94 
95 #endif
TFCSPredictExtrapWeights::initializeNetwork
bool initializeNetwork(int pid, const std::string &etaBin, const std::string &FastCaloNNInputFolderName)
Definition: TFCSPredictExtrapWeights.cxx:298
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
TFCSPredictExtrapWeights::~TFCSPredictExtrapWeights
virtual ~TFCSPredictExtrapWeights()
Definition: TFCSPredictExtrapWeights.cxx:55
TFCSPredictExtrapWeights
Definition: TFCSPredictExtrapWeights.h:18
TFCSPredictExtrapWeights::m_normMeans
std::vector< float > * m_normMeans
Definition: TFCSPredictExtrapWeights.h:85
TFCSPredictExtrapWeights::kUseHardcodedWeight
@ kUseHardcodedWeight
Definition: TFCSPredictExtrapWeights.h:70
TFCSPredictExtrapWeights::m_input
std::string * m_input
Definition: TFCSPredictExtrapWeights.h:80
TFCSPredictExtrapWeights::operator==
virtual bool operator==(const TFCSParametrizationBase &ref) const override
The == operator compares the content of instances.
Definition: TFCSPredictExtrapWeights.cxx:76
TFCSPredictExtrapWeights::TFCSPredictExtrapWeightsStatusBits
TFCSPredictExtrapWeightsStatusBits
Definition: TFCSPredictExtrapWeights.h:70
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
TFCSLateralShapeParametrizationHitBase::Hit
Definition: TFCSLateralShapeParametrizationHitBase.h:42
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:90
TFCSPredictExtrapWeights::m_normLayers
std::vector< int > * m_normLayers
Do not persistify.
Definition: TFCSPredictExtrapWeights.h:83
TFCSLateralShapeParametrizationHitBase
Definition: TFCSLateralShapeParametrizationHitBase.h:13
TFCSPredictExtrapWeights::simulate_hit
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
simulated one hit position with some energy.
Definition: TFCSPredictExtrapWeights.cxx:228
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
TFCSPredictExtrapWeights::freemem
bool freemem() const
Definition: TFCSPredictExtrapWeights.h:42
TFCSLateralShapeParametrizationHitBase.h
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:148
TFCSPredictExtrapWeights::m_normStdDevs
std::vector< float > * m_normStdDevs
Definition: TFCSPredictExtrapWeights.h:88
TFCSPredictExtrapWeights::UseHardcodedWeight
bool UseHardcodedWeight() const
Definition: TFCSPredictExtrapWeights.h:71
TFCSPredictExtrapWeights::simulate
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
Definition: TFCSPredictExtrapWeights.cxx:194
TFCSPredictExtrapWeights::set_freemem
void set_freemem()
Definition: TFCSPredictExtrapWeights.h:43
covarianceTool.title
title
Definition: covarianceTool.py:542
lwt
Definition: NnClusterizationFactory.h:52
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
TFCSPredictExtrapWeights::unit_test
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
Definition: TFCSPredictExtrapWeights.cxx:374
TFCSPredictExtrapWeights::set_UseHardcodedWeight
void set_UseHardcodedWeight()
Definition: TFCSPredictExtrapWeights.h:72
TFCSPredictExtrapWeights::m_relevantLayers
std::vector< int > * m_relevantLayers
Definition: TFCSPredictExtrapWeights.h:81
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TFCSPredictExtrapWeights::test_path
static void test_path(std::string &net_path, std::string const &norm_path, TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
Definition: TFCSPredictExtrapWeights.cxx:390
TFCSPredictExtrapWeights::prepareInputs
std::map< std::string, double > prepareInputs(TFCSSimulationState &simulstate, const float truthE) const
Definition: TFCSPredictExtrapWeights.cxx:158
TFCSPredictExtrapWeights::getNormInputs
bool getNormInputs(const std::string &etaBin, const std::string &FastCaloTXTInputFolderName)
Definition: TFCSPredictExtrapWeights.cxx:98
TFCSPredictExtrapWeights::Print
void Print(Option_t *option="") const override
Definition: TFCSPredictExtrapWeights.cxx:511
ref
const boost::regex ref(r_ef)
TFCSPredictExtrapWeights::TFCSPredictExtrapWeights
TFCSPredictExtrapWeights(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSPredictExtrapWeights.cxx:47
TFCSPredictExtrapWeights::m_nn
lwt::LightweightNeuralNetwork * m_nn
Definition: TFCSPredictExtrapWeights.h:82
TFCSPredictExtrapWeights::FCSfreemem
FCSfreemem
Definition: TFCSPredictExtrapWeights.h:38
TFCSSimulationState.h
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
TFCSPredictExtrapWeights::reset_UseHardcodedWeight
void reset_UseHardcodedWeight()
Definition: TFCSPredictExtrapWeights.h:73
TFCSPredictExtrapWeights::kfreemem
@ kfreemem
Set this bit in the TObject bit if the memory for m_input should be freed after reading in athena.
Definition: TFCSPredictExtrapWeights.h:39