15 #include "HepPDT/ParticleData.hh"
16 #include "HepPDT/ParticleDataTable.hh"
18 #include "CLHEP/Random/RandGauss.h"
19 #include "CLHEP/Random/RandFlat.h"
21 #if defined(__FastCaloSimStandAlone__)
22 #include "CLHEP/Random/TRandomEngine.h"
24 #include <CLHEP/Random/RanluxEngine.h>
31 #include "lwtnn/LightweightGraph.hh"
32 #include "lwtnn/LightweightNeuralNetwork.hh"
33 #include "lwtnn/parse_json.hh"
36 #include <libxml/xmlmemory.h>
37 #include <libxml/parser.h>
38 #include <libxml/tree.h>
39 #include <libxml/xmlreader.h>
40 #include <libxml/xpath.h>
41 #include <libxml/xpathInternals.h>
71 if (
m_nn !=
nullptr) {
80 <<
IsA()->GetName() <<
" != " <<
ref.IsA()->GetName());
99 const std::string &
etaBin,
const std::string &FastCaloTXTInputFolderName) {
118 std::string inputFileName = FastCaloTXTInputFolderName +
119 "MeanStdDevEnergyFractions_eta_" +
etaBin +
122 std::ifstream inputTXT(inputFileName);
123 if (inputTXT.is_open()) {
125 while (getline(inputTXT,
line)) {
126 std::stringstream
ss(
line);
130 getline(
ss, substr,
' ');
132 if (substr !=
"etrue") {
133 int index = std::stoi(substr.substr(substr.find(
'_') + 1));
157 std::map<std::string, double>
159 const float truthE)
const {
160 std::map<std::string, double> inputVariables;
170 inputVariables[
"ef_" +
layer] =
174 ATH_MSG_ERROR(
"Normalization information not found for layer "
182 inputVariables[
"etrue"] = (truthE - std::as_const(
m_normMeans)->at(
index)) /
185 inputVariables[
"pdgId"] = 1;
187 inputVariables[
"pdgId"] = 0;
189 return inputVariables;
199 std::map<std::string, double> inputVariables =
208 << ilayer <<
" weight: "
237 extrapWeight = simulstate.
getAuxInfo<
float>(cs);
240 "Simulstate is not decorated with extrapolation weights for cs = "
249 float extrapWeight_for_r_z = extrapWeight;
251 extrapWeight_for_r_z = 0.5;
253 "Will use extrapWeight=0.5 for r and z when constructing a hit");
255 ATH_MSG_DEBUG(
"Will use predicted extrapWeight also for r and z when "
256 "constructing a hit");
263 if (!std::isfinite(
r) || !std::isfinite(
z) || !std::isfinite(
eta) ||
264 !std::isfinite(
phi)) {
265 ATH_MSG_WARNING(
"Extrapolator contains NaN or infinite number.\nSetting "
266 "center position to calo boundary.");
268 <<
r <<
" center_z: " <<
z <<
" center_phi: " <<
phi
269 <<
" center_eta: " <<
eta <<
" weight: " << extrapWeight
277 <<
r <<
" center_z: " <<
z <<
" center_phi: " <<
phi
278 <<
" center_eta: " <<
eta <<
" weight: " << extrapWeight
291 <<
" weight: " << extrapWeight <<
" cs: " << cs);
300 const std::string &FastCaloNNInputFolderName) {
303 "Using FastCaloNNInputFolderName: " << FastCaloNNInputFolderName);
306 std::string inputFileName =
307 FastCaloNNInputFolderName +
"NN_" +
etaBin +
".json";
309 if (inputFileName.empty()) {
314 <<
", loading json file " << inputFileName);
315 std::ifstream
input(inputFileName);
316 std::stringstream
sin;
322 if (
m_nn ==
nullptr) {
323 ATH_MSG_ERROR(
"Could not create LightWeightNeuralNetwork from "
334 int layer = std::stoi(
343 void TFCSPredictExtrapWeights::Streamer(TBuffer &R__b) {
346 if (R__b.IsReading()) {
347 R__b.ReadClassBuffer(TFCSPredictExtrapWeights::Class(),
this);
348 if (
m_nn !=
nullptr) {
353 std::stringstream
sin;
359 #ifndef __FastCaloSimStandAlone__
368 R__b.WriteClassBuffer(TFCSPredictExtrapWeights::Class(),
this);
377 const std::string this_file = __FILE__;
378 const std::string parent_dir = this_file.substr(0, this_file.find(
"/src/"));
379 const std::string norm_path = parent_dir +
"/share/NormPredExtrapSample/";
380 std::string net_path =
"/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/"
381 "FastCaloSim/LWTNNPredExtrapSample/";
391 std::string &net_path, std::string
const &norm_path,
396 << net_path.substr(net_path.length() - 20)
397 <<
" and norm path ..."
398 << norm_path.substr(norm_path.length() - 20));
401 #if defined(__FastCaloSimStandAlone__)
409 t->SetPtEtaPhiM(524288000, 0, 0, 130);
415 e->set_IDCaloBoundary_eta(truth->Eta());
416 for (
int i = 0;
i < 24; ++
i) {
434 simulstate->
set_E(0, 1028.77124023);
435 simulstate->
set_E(1, 68199.0625);
436 simulstate->
set_E(2, 438270.78125);
437 simulstate->
set_E(3, 3024.02929688);
438 simulstate->
set_E(12, 1330.10131836);
439 simulstate->
set_E(1028.77124023 + 68199.0625 + 438270.78125 + 3024.02929688 +
441 simulstate->
set_Efrac(0, simulstate->
E(0) / simulstate->
E());
442 simulstate->
set_Efrac(1, simulstate->
E(1) / simulstate->
E());
443 simulstate->
set_Efrac(2, simulstate->
E(2) / simulstate->
E());
444 simulstate->
set_Efrac(3, simulstate->
E(3) / simulstate->
E());
445 simulstate->
set_Efrac(12, simulstate->
E(12) / simulstate->
E());
447 const int pdgId = truth->
pdgid();
448 const float Ekin = truth->
Ekin();
449 const float eta = truth->Eta();
457 for (
int i = 0;
i <= 25; ++
i) {
459 if (
Eta >= etaTmp &&
Eta < (etaTmp + 5)) {
475 std::map<std::string, double> inputVariables =
481 const std::vector<int>
layers = {0, 1, 2, 3, 12};
482 for (
int ilayer :
layers) {
494 TFile *fNN =
new TFile(
"FCSNNtest.root",
"RECREATE");
501 fNN = TFile::Open(
"FCSNNtest.root");
513 bool shortprint =
opt.Index(
"short") >= 0;
515 TString optprint =
opt;
516 optprint.ReplaceAll(
"short",
"");
520 ATH_MSG_INFO(optprint <<
" m_input (TFCSPredictExtrapWeights): "