ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSGANEtaSlice Class Reference

#include <TFCSGANEtaSlice.h>

Inheritance diagram for TFCSGANEtaSlice:
Collaboration diagram for TFCSGANEtaSlice:

Public Types

typedef std::map< int, std::vector< double > > FitResultsPerLayer
typedef std::map< int, double > ExtrapolatorWeights
typedef std::map< std::string, std::map< std::string, double > > NetworkInputs
typedef std::map< std::string, double > NetworkOutputs

Public Member Functions

 TFCSGANEtaSlice ()
 TFCSGANEtaSlice (int pid, int etaMin, int etaMax, const TFCSGANXMLParameters &param)
virtual ~TFCSGANEtaSlice ()
 TFCSGANEtaSlice (const TFCSGANEtaSlice &)=delete
TFCSGANEtaSliceoperator= (const TFCSGANEtaSlice &)=delete
bool LoadGAN ()
void CalculateMeanPointFromDistributionOfR ()
void ExtractExtrapolatorMeansFromInputs ()
NetworkOutputs GetNetworkOutputs (const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol, TFCSSimulationState &simulstate) const
bool IsGanCorrectlyLoaded () const
const FitResultsPerLayerGetFitResults () const
const ExtrapolatorWeightsGetExtrapolatorWeights ()
void Print () const
bool msgLvl (const MSG::Level lvl) const
 Check whether the logging system is active at the provided verbosity level.
MsgStream & msg () const
 Return a stream for sending messages directly (no decoration)
MsgStream & msg (const MSG::Level lvl) const
 Return a decorated starting stream for sending messages.
MSG::Level level () const
 Retrieve output level.
virtual void setLevel (MSG::Level lvl)
 Update outputlevel.

Static Public Member Functions

static std::string startMsg (MSG::Level lvl, const std::string &file, int line)
 Make a message to decorate the start of logging.

Private Member Functions

VNetworkBaseGetNetAll () const
VNetworkBaseGetNetLow () const
VNetworkBaseGetNetHigh () const
bool LoadGANNoRange (std::string inputFileName)
bool LoadGANFromRange (std::string inputFileName, std::string energyRange)

Private Attributes

int m_pid {}
int m_etaMin {}
int m_etaMax {}
std::string m_inputFolderName
FitResultsPerLayer m_allFitResults
ExtrapolatorWeights m_extrapolatorWeights
TFCSGANLWTNNHandlerm_gan_all = nullptr
TFCSGANLWTNNHandlerm_gan_low = nullptr
TFCSGANLWTNNHandlerm_gan_high = nullptr
std::unique_ptr< VNetworkBasem_net_all = nullptr
std::unique_ptr< VNetworkBasem_net_low = nullptr
std::unique_ptr< VNetworkBasem_net_high = nullptr
TFCSGANXMLParameters m_param {}
std::string m_nm
 Message source name.

Static Private Attributes

static boost::thread_specific_ptr< MsgStream > m_msg_tls ATLAS_THREAD_SAFE
 Do not persistify!

Detailed Description

Definition at line 30 of file TFCSGANEtaSlice.h.

Member Typedef Documentation

◆ ExtrapolatorWeights

typedef std::map<int, double> TFCSGANEtaSlice::ExtrapolatorWeights

Definition at line 41 of file TFCSGANEtaSlice.h.

◆ FitResultsPerLayer

typedef std::map<int, std::vector<double> > TFCSGANEtaSlice::FitResultsPerLayer

Definition at line 40 of file TFCSGANEtaSlice.h.

◆ NetworkInputs

typedef std::map<std::string, std::map<std::string, double> > TFCSGANEtaSlice::NetworkInputs

Definition at line 42 of file TFCSGANEtaSlice.h.

◆ NetworkOutputs

typedef std::map<std::string, double> TFCSGANEtaSlice::NetworkOutputs

Definition at line 43 of file TFCSGANEtaSlice.h.

Constructor & Destructor Documentation

◆ TFCSGANEtaSlice() [1/3]

TFCSGANEtaSlice::TFCSGANEtaSlice ( )

Definition at line 27 of file TFCSGANEtaSlice.cxx.

27{}

◆ TFCSGANEtaSlice() [2/3]

TFCSGANEtaSlice::TFCSGANEtaSlice ( int pid,
int etaMin,
int etaMax,
const TFCSGANXMLParameters & param )

Definition at line 29 of file TFCSGANEtaSlice.cxx.

31 : m_pid(pid), m_etaMin(etaMin), m_etaMax(etaMax), m_param(param) {}
TFCSGANXMLParameters m_param

◆ ~TFCSGANEtaSlice()

TFCSGANEtaSlice::~TFCSGANEtaSlice ( )
virtual

Definition at line 33 of file TFCSGANEtaSlice.cxx.

33 {
34 // Deleting a nullptr is a noop
35 delete m_gan_all;
36 delete m_gan_low;
37 delete m_gan_high;
38}
TFCSGANLWTNNHandler * m_gan_all
TFCSGANLWTNNHandler * m_gan_low
TFCSGANLWTNNHandler * m_gan_high

◆ TFCSGANEtaSlice() [3/3]

TFCSGANEtaSlice::TFCSGANEtaSlice ( const TFCSGANEtaSlice & )
delete

Member Function Documentation

◆ CalculateMeanPointFromDistributionOfR()

void TFCSGANEtaSlice::CalculateMeanPointFromDistributionOfR ( )

Definition at line 121 of file TFCSGANEtaSlice.cxx.

121 {
122 std::string rootFileName = std::format("{}/rootFiles/pid{}_E1048576_eta_{}_{}.root",
123 m_param.GetInputFolder(),
124 m_pid,
125 m_etaMin,
126 m_etaMin + 5);
127 ATH_MSG_DEBUG("Opening file " << rootFileName);
128 std::unique_ptr<TFile> file (TFile::Open(rootFileName.c_str(), "read"));
129 if (!file || file->IsZombie()) {
130 throw std::runtime_error(std::format("Failed to open or initialize ROOT file: {}", rootFileName));
131 }
132 for (int layer : m_param.GetRelevantLayers()) {
133 ATH_MSG_DEBUG("Layer " << layer);
134 TFCSGANXMLParameters::Binning binsInLayers = m_param.GetBinning();
135 TH2D *h2 = &binsInLayers[layer];
136
137 std::string histoName = std::format("r{}w", layer);
138 TH1D *h1 = (TH1D *)file->Get(histoName.c_str());
139 if (std::isnan(h1->Integral())) {
140 histoName = std::format("r{}", layer);
141 h1 = (TH1D *)file->Get(histoName.c_str());
142 }
143
144 TAxis *x = (TAxis *)h2->GetXaxis();
145 for (int ix = 1; ix <= h2->GetNbinsX(); ++ix) {
146 ATH_MSG_DEBUG(ix);
147 h1->GetXaxis()->SetRangeUser(x->GetBinLowEdge(ix), x->GetBinUpEdge(ix));
148
149 double result = 0;
150 if (h1->Integral() > 0 && h1->GetNbinsX() > 2) {
151 TFitResultPtr res(0);
152
153 res = h1->Fit("expo", "SQ");
154 if (res >= 0 && !std::isnan(res->Parameter(0))) {
155 result = res->Parameter(1);
156 }
157 }
158 m_allFitResults[layer].push_back(result);
159 }
160 }
161 ATH_MSG_DEBUG("Done initialisaing fits");
162}
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
#define x
FitResultsPerLayer m_allFitResults
std::map< int, TH2D > Binning
@ layer
Definition HitInfo.h:79
TFile * file

◆ ExtractExtrapolatorMeansFromInputs()

void TFCSGANEtaSlice::ExtractExtrapolatorMeansFromInputs ( )

Definition at line 164 of file TFCSGANEtaSlice.cxx.

164 {
165 std::string rootFileName = std::format("{}/rootFiles/pid{}_E65536_eta_{}_{}_validation.root",
166 m_param.GetInputFolder(),
167 m_pid,
168 m_etaMin,
169 m_etaMin + 5);
170 ATH_MSG_DEBUG("Opening file " << rootFileName);
171 std::unique_ptr<TFile> file (TFile::Open(rootFileName.c_str(), "read"));
172 if (!file || file->IsZombie()) {
173 throw std::runtime_error(std::format("Failed to open or initialize ROOT file: {}", rootFileName));
174 }
175 for (int layer : m_param.GetRelevantLayers()) {
176 TH1D *h = new TH1D("h", "h", 100, 0.01, 1);
177 TTree *tree = (TTree *)file->Get("rootTree");
178 std::string command = std::format("extrapWeight_{}>>h", layer);
179 tree->Draw(command.c_str());
180 m_extrapolatorWeights[layer] = h->GetMean();
181 ATH_MSG_DEBUG("Extrapolation: layer " << layer << " mean "
182 << m_extrapolatorWeights[layer]);
183 }
184}
ExtrapolatorWeights m_extrapolatorWeights
TChain * tree

◆ GetExtrapolatorWeights()

const ExtrapolatorWeights & TFCSGANEtaSlice::GetExtrapolatorWeights ( )
inline

Definition at line 55 of file TFCSGANEtaSlice.h.

55{ return m_extrapolatorWeights; }

◆ GetFitResults()

const FitResultsPerLayer & TFCSGANEtaSlice::GetFitResults ( ) const
inline

Definition at line 54 of file TFCSGANEtaSlice.h.

54{ return m_allFitResults; }

◆ GetNetAll()

VNetworkBase * TFCSGANEtaSlice::GetNetAll ( ) const
private

Definition at line 40 of file TFCSGANEtaSlice.cxx.

40 {
41 if (m_net_all != nullptr)
42 return m_net_all.get();
43 return m_gan_all;
44}
std::unique_ptr< VNetworkBase > m_net_all

◆ GetNetHigh()

VNetworkBase * TFCSGANEtaSlice::GetNetHigh ( ) const
private

Definition at line 50 of file TFCSGANEtaSlice.cxx.

50 {
51 if (m_net_high != nullptr)
52 return m_net_high.get();
53 return m_gan_high;
54}
std::unique_ptr< VNetworkBase > m_net_high

◆ GetNetLow()

VNetworkBase * TFCSGANEtaSlice::GetNetLow ( ) const
private

Definition at line 45 of file TFCSGANEtaSlice.cxx.

45 {
46 if (m_net_low != nullptr)
47 return m_net_low.get();
48 return m_gan_low;
49}
std::unique_ptr< VNetworkBase > m_net_low

◆ GetNetworkOutputs()

VNetworkBase::NetworkOutputs TFCSGANEtaSlice::GetNetworkOutputs ( const TFCSTruthState * truth,
const TFCSExtrapolationState * extrapol,
TFCSSimulationState & simulstate ) const

Definition at line 187 of file TFCSGANEtaSlice.cxx.

189 {
190 double randUniformZ = 0.;
192
193 int maxExp = 0, minExp = 0;
194 if (m_pid == 22 || std::abs(m_pid) == 11) {
195 if (truth->P() >
196 4096) { // This is the momentum, not the energy, because the split is
197 // based on the samples which are produced with the momentum
198 maxExp = 22;
199 minExp = 12;
200 } else {
201 maxExp = 12;
202 minExp = 6;
203 }
204 } else if (std::abs(m_pid) == 211) {
205 maxExp = 22;
206 minExp = 8;
207 } else if (std::abs(m_pid) == 2212) {
208 maxExp = 22;
209 minExp = 10;
210 }
211
212 int p_min = std::pow(2, minExp);
213 int p_max = std::pow(2, maxExp);
214 // Keep min and max without mass offset as we do not train on antiparticles
215 double Ekin_min =
216 std::sqrt(std::pow(p_min, 2) + std::pow(truth->M(), 2)) - truth->M();
217 double Ekin_max =
218 std::sqrt(std::pow(p_max, 2) + std::pow(truth->M(), 2)) - truth->M();
219 for (int i = 0; i < m_param.GetLatentSpaceSize(); i++) {
220 randUniformZ = CLHEP::RandGauss::shoot(simulstate.randomEngine(), 0.5, 0.5);
221 inputs["Noise"].insert(std::pair<std::string, double>(
222 "variable_" + std::to_string(i), randUniformZ));
223 }
224
225 // double e = log(truth->Ekin()/Ekin_min)/log(Ekin_max/Ekin_min) ;
226 // Could be uncommented , but would need the line above too
227 // ATH_MSG_DEBUG( "Check label: " << e <<" Ekin:" << truth->Ekin() <<" p:" <<
228 // truth->P() <<" mass:" << truth->M() <<" Ekin_off:" <<
229 // truth->Ekin_off() << " Ekin_min:"<<Ekin_min<<"
230 // Ekin_max:"<<Ekin_max);
231 // inputs["mycond"].insert ( std::pair<std::string,double>("variable_0",
232 // truth->Ekin()/(std::pow(2,maxExp))) ); //Old conditioning using linear
233 // interpolation, now use logaritminc interpolation
234 inputs["mycond"].insert(std::pair<std::string, double>(
235 "variable_0", log(truth->Ekin() / Ekin_min) / log(Ekin_max / Ekin_min)));
236
237 if (m_param.GetGANVersion() >= 2) {
238 if (false) { // conditioning on eta, should only be needed in transition
239 // regions and added only to the GANs that use it, for now all
240 // GANs have 3 conditioning inputs so filling zeros
241 inputs["mycond"].insert(std::pair<std::string, double>(
242 "variable_1", std::abs(extrapol->IDCaloBoundary_eta())));
243 } else {
244 inputs["mycond"].insert(std::pair<std::string, double>("variable_1", 0));
245 }
246 }
247
249 if (m_param.GetGANVersion() == 1 || m_pid == 211 || m_pid == 2212) {
250 outputs = GetNetAll()->compute(inputs);
251 } else {
252 if (truth->P() >
253 4096) { // This is the momentum, not the energy, because the split is
254 // based on the samples which are produced with the momentum
255 ATH_MSG_DEBUG("Computing outputs given inputs for high");
256 outputs = GetNetHigh()->compute(inputs);
257 } else {
258 outputs = GetNetLow()->compute(inputs);
259 }
260 }
261 ATH_MSG_DEBUG("Start Network inputs ~~~~~~~~");
263 ATH_MSG_DEBUG("End Network inputs ~~~~~~~~");
264 ATH_MSG_DEBUG("Start Network outputs ~~~~~~~~");
266 ATH_MSG_DEBUG("End Network outputs ~~~~~~~~");
267 return outputs;
268}
VNetworkBase * GetNetAll() const
VNetworkBase * GetNetLow() const
std::map< std::string, std::map< std::string, double > > NetworkInputs
VNetworkBase * GetNetHigh() const
CLHEP::HepRandomEngine * randomEngine()
double Ekin() const
virtual NetworkOutputs compute(NetworkInputs const &inputs) const =0
Function to pass values to the network.
static std::string representNetworkOutputs(NetworkOutputs const &outputs, int maxValues=3)
String representation of network outputs.
std::map< std::string, double > NetworkOutputs
Format for network outputs.
static std::string representNetworkInputs(NetworkInputs const &inputs, int maxValues=3)
String representation of network inputs.

◆ IsGanCorrectlyLoaded()

bool TFCSGANEtaSlice::IsGanCorrectlyLoaded ( ) const

Definition at line 56 of file TFCSGANEtaSlice.cxx.

56 {
57 if (m_pid == 211 || m_pid == 2212) {
58 if (GetNetAll() == nullptr) {
59 return false;
60 }
61 } else {
62 if (GetNetHigh() == nullptr || GetNetLow() == nullptr) {
63 return false;
64 }
65 }
66 return true;
67}

◆ level()

MSG::Level ISF_FCS::MLogging::level ( ) const
inlineinherited

Retrieve output level.

Definition at line 201 of file MLogging.h.

201{ return msg().level(); }
MsgStream & msg() const
Return a stream for sending messages directly (no decoration)
Definition MLogging.h:231

◆ LoadGAN()

bool TFCSGANEtaSlice::LoadGAN ( )

Definition at line 69 of file TFCSGANEtaSlice.cxx.

69 {
70 // Now load new data
71 std::string inputFileName;
72
75
76 bool success = true;
77
78 if (m_pid == 211) {
79 inputFileName = std::format("{}/neural_net_{}_eta_{}_{}_All.*",
80 m_param.GetInputFolder(),
81 m_pid,
83 m_etaMax);
84 ATH_MSG_DEBUG("Gan input file name " << inputFileName);
85 m_net_all = TFCSNetworkFactory::create(std::move(inputFileName));
86 if (m_net_all == nullptr)
87 success = false;
88 } else if (m_pid == 2212) {
89 inputFileName = std::format("{}/neural_net_{}_eta_{}_{}_High10.*",
90 m_param.GetInputFolder(),
91 m_pid,
93 m_etaMax);
94 ATH_MSG_DEBUG("Gan input file name " << inputFileName);
95 m_net_all = TFCSNetworkFactory::create(std::move(inputFileName));
96 if (m_net_all == nullptr)
97 success = false;
98 } else {
99 inputFileName = std::format("{}/neural_net_{}_eta_{}_{}_High12.*",
100 m_param.GetInputFolder(),
101 m_pid,
102 m_etaMin,
103 m_etaMax);
104 ATH_MSG_DEBUG("Gan input file name " << inputFileName);
105 m_net_high = TFCSNetworkFactory::create(inputFileName);
106 if (m_net_high == nullptr)
107 success = false;
108
109 inputFileName = std::format("{}/neural_net_{}_eta_{}_{}_UltraLow12.*",
110 m_param.GetInputFolder(),
111 m_pid,
112 m_etaMin,
113 m_etaMax);
114 m_net_low = TFCSNetworkFactory::create(std::move(inputFileName));
115 if (m_net_low == nullptr)
116 success = false;
117 }
118 return success;
119}
void CalculateMeanPointFromDistributionOfR()
void ExtractExtrapolatorMeansFromInputs()
static std::unique_ptr< VNetworkBase > create(std::string input)
Given a string, make a network.

◆ LoadGANFromRange()

bool TFCSGANEtaSlice::LoadGANFromRange ( std::string inputFileName,
std::string energyRange )
private

◆ LoadGANNoRange()

bool TFCSGANEtaSlice::LoadGANNoRange ( std::string inputFileName)
private

◆ msg() [1/2]

MsgStream & ISF_FCS::MLogging::msg ( ) const
inlineinherited

Return a stream for sending messages directly (no decoration)

Definition at line 231 of file MLogging.h.

231 {
232 MsgStream *ms = m_msg_tls.get();
233 if (!ms) {
234 ms = new MsgStream(Athena::getMessageSvc(), m_nm);
235 m_msg_tls.reset(ms);
236 }
237 return *ms;
238}
std::string m_nm
Message source name.
Definition MLogging.h:211
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [2/2]

MsgStream & ISF_FCS::MLogging::msg ( const MSG::Level lvl) const
inlineinherited

Return a decorated starting stream for sending messages.

Definition at line 240 of file MLogging.h.

240 {
241 return msg() << lvl;
242}

◆ msgLvl()

bool ISF_FCS::MLogging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Check whether the logging system is active at the provided verbosity level.

Definition at line 222 of file MLogging.h.

222 {
223 if (msg().level() <= lvl) {
224 msg() << lvl;
225 return true;
226 } else {
227 return false;
228 }
229}
MSG::Level level() const
Retrieve output level.
Definition MLogging.h:201

◆ operator=()

TFCSGANEtaSlice & TFCSGANEtaSlice::operator= ( const TFCSGANEtaSlice & )
delete

◆ Print()

void TFCSGANEtaSlice::Print ( ) const

Definition at line 270 of file TFCSGANEtaSlice.cxx.

270 {
271 ATH_MSG_INFO("LWTNN Handler parameters");
272 ATH_MSG_INFO(" pid: " << m_pid);
273 ATH_MSG_INFO(" etaMin:" << m_etaMin);
274 ATH_MSG_INFO(" etaMax: " << m_etaMax);
275 m_param.Print();
276}
#define ATH_MSG_INFO(x)

◆ setLevel()

void ISF_FCS::MLogging::setLevel ( MSG::Level lvl)
virtualinherited

Update outputlevel.

Definition at line 105 of file MLogging.cxx.

105 {
106 lvl = (lvl >= MSG::NUM_LEVELS) ? MSG::ALWAYS
107 : (lvl < MSG::NIL) ? MSG::NIL
108 : lvl;
109 msg().setLevel(lvl);
110}

◆ startMsg()

std::string ISF_FCS::MLogging::startMsg ( MSG::Level lvl,
const std::string & file,
int line )
staticinherited

Make a message to decorate the start of logging.

Print a message for the start of logging.

Definition at line 116 of file MLogging.cxx.

116 {
117 int col1_len = 20;
118 int col2_len = 5;
119 int col3_len = 10;
120 auto last_slash = file.find_last_of('/');
121 int path_len = last_slash == std::string::npos ? 0 : last_slash;
122 int trim_point = path_len;
123 int total_len = file.length();
124 if (total_len - path_len > col1_len)
125 trim_point = total_len - col1_len;
126 std::string trimmed_name = file.substr(trim_point);
127 const char *LevelNames[MSG::NUM_LEVELS] = {
128 "NIL", "VERBOSE", "DEBUG", "INFO", "WARNING", "ERROR", "FATAL", "ALWAYS"};
129 std::string level = LevelNames[lvl];
130 std::string level_string = std::string("(") + level + ") ";
131 std::stringstream output;
132 output << std::setw(col1_len) << std::right << trimmed_name << ":"
133 << std::setw(col2_len) << std::left << line << std::setw(col3_len)
134 << std::right << level_string;
135 return output.str();
136}
output
Definition merge.py:16

Member Data Documentation

◆ ATLAS_THREAD_SAFE

boost::thread_specific_ptr<MsgStream> m_msg_tls ISF_FCS::MLogging::ATLAS_THREAD_SAFE
inlinestaticprivateinherited

Do not persistify!

MsgStream instance (a std::cout like with print-out levels)

Definition at line 215 of file MLogging.h.

◆ m_allFitResults

FitResultsPerLayer TFCSGANEtaSlice::m_allFitResults
private

Definition at line 66 of file TFCSGANEtaSlice.h.

◆ m_etaMax

int TFCSGANEtaSlice::m_etaMax {}
private

Definition at line 62 of file TFCSGANEtaSlice.h.

62{};

◆ m_etaMin

int TFCSGANEtaSlice::m_etaMin {}
private

Definition at line 61 of file TFCSGANEtaSlice.h.

61{};

◆ m_extrapolatorWeights

ExtrapolatorWeights TFCSGANEtaSlice::m_extrapolatorWeights
private

Definition at line 67 of file TFCSGANEtaSlice.h.

◆ m_gan_all

TFCSGANLWTNNHandler* TFCSGANEtaSlice::m_gan_all = nullptr
private

Definition at line 71 of file TFCSGANEtaSlice.h.

◆ m_gan_high

TFCSGANLWTNNHandler* TFCSGANEtaSlice::m_gan_high = nullptr
private

Definition at line 73 of file TFCSGANEtaSlice.h.

◆ m_gan_low

TFCSGANLWTNNHandler* TFCSGANEtaSlice::m_gan_low = nullptr
private

Definition at line 72 of file TFCSGANEtaSlice.h.

◆ m_inputFolderName

std::string TFCSGANEtaSlice::m_inputFolderName
private

Definition at line 64 of file TFCSGANEtaSlice.h.

◆ m_net_all

std::unique_ptr<VNetworkBase> TFCSGANEtaSlice::m_net_all = nullptr
private

Definition at line 75 of file TFCSGANEtaSlice.h.

◆ m_net_high

std::unique_ptr<VNetworkBase> TFCSGANEtaSlice::m_net_high = nullptr
private

Definition at line 77 of file TFCSGANEtaSlice.h.

◆ m_net_low

std::unique_ptr<VNetworkBase> TFCSGANEtaSlice::m_net_low = nullptr
private

Definition at line 76 of file TFCSGANEtaSlice.h.

◆ m_nm

std::string ISF_FCS::MLogging::m_nm
privateinherited

Message source name.

Definition at line 211 of file MLogging.h.

◆ m_param

TFCSGANXMLParameters TFCSGANEtaSlice::m_param {}
private

Definition at line 86 of file TFCSGANEtaSlice.h.

86{};

◆ m_pid

int TFCSGANEtaSlice::m_pid {}
private

Definition at line 60 of file TFCSGANEtaSlice.h.

60{};

The documentation for this class was generated from the following files: