From 82ae17ed399960de99a67f34445fadd1561305c7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 May 2022 17:19:28 +0200 Subject: [PATCH 1/3] add punch through classifier, calibrated NN model, fist commit --- .../IPunchThroughClassifier.h | 43 ++++ .../python/AdditionalConfig.py | 7 + .../python/ISF_FastCaloSimServicesConfigDb.py | 1 + .../src/FastCaloSimSvcV2.cxx | 54 ++-- .../ISF_PunchThroughTools/CMakeLists.txt | 11 +- .../src/PunchThroughClassifier.cxx | 235 ++++++++++++++++++ .../src/PunchThroughClassifier.h | 67 +++++ .../src/PunchThroughTool.cxx | 22 +- .../src/PunchThroughTool.h | 8 +- .../ISF_PunchThroughTools_entries.cxx | 6 +- .../components/ISF_PunchThroughTools_load.cxx | 2 +- 11 files changed, 424 insertions(+), 32 deletions(-) create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h new file mode 100644 index 00000000000..dde5dad09d3 --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ISF_FASTCALOSIMINTERFACES_IPUNCHTHROUGHCLASSIFIER_H +#define ISF_FASTCALOSIMINTERFACES_IPUNCHTHROUGHCLASSIFIER_H 1 + +// Gaudi +#include "GaudiKernel/IAlgTool.h" + +// ISF includes +#include "ISF_Event/ISFParticle.h" + +#include "ISF_FastCaloSimEvent/TFCSSimulationState.h" + + +namespace ISF { + + /** + @class IPunchThroughClassifier + + Interface for a tool which takes simulstate and particle + and predicts whether it should result in a muon segment. + + @author thomas.michael.carter@cern.ch + */ + + class IPunchThroughClassifier : virtual public IAlgTool { + public: + + /** Virtual destructor */ + virtual ~IPunchThroughClassifier(){} + + /// Creates the InterfaceID and interfaceID() method + DeclareInterfaceID(IPunchThroughClassifier, 1, 0); + + virtual double computePunchThroughProbability(const ISFParticle& isfp, const TFCSSimulationState& simulstate ) const = 0; + + }; + +} // end of namespace + +#endif diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py index 9e85c2bbb5c..921494663f6 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py @@ -684,6 +684,13 @@ def getPunchThroughTool(name="ISF_PunchThroughTool", **kwargs): from ISF_PunchThroughTools.ISF_PunchThroughToolsConf import ISF__PunchThroughTool return ISF__PunchThroughTool(name, **kwargs ) +def getPunchThroughClassifier(name="ISF_PunchThroughClassifier", **kwargs): + kwargs.setdefault("ScalerConfigFileName" , "./" ) + kwargs.setdefault("NetworkConfigFileName" , "test" ) + kwargs.setdefault("CalibratorConfigFileName" , "test" ) + from ISF_PunchThroughClassifier.ISF_PunchThroughClassifierConf import ISF__PunchThroughClassifier + return ISF__PunchThroughClassifier(name, **kwargs ) + def getEmptyCellBuilderTool(name="ISF_EmptyCellBuilderTool", **kwargs): from FastCaloSim.FastCaloSimConf import EmptyCellBuilderTool return EmptyCellBuilderTool(name, **kwargs ) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigDb.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigDb.py index 90d0ce67218..9d8871886c3 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigDb.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigDb.py @@ -12,6 +12,7 @@ addTool("ISF_FastCaloSimServices.AdditionalConfig.getNIPropagator", addTool("ISF_FastCaloSimServices.AdditionalConfig.getNITimedExtrapolator", "ISF_NITimedExtrapolator") addTool("ISF_FastCaloSimServices.AdditionalConfig.getTimedExtrapolator", "TimedExtrapolator") addTool("ISF_FastCaloSimServices.AdditionalConfig.getPunchThroughTool", "ISF_PunchThroughTool") +addTool("ISF_FastCaloSimServices.AdditionalConfig.getPunchThroughClassifier", "ISF_PunchThroughClassifier") addTool("ISF_FastCaloSimServices.AdditionalConfig.getEmptyCellBuilderTool", "ISF_EmptyCellBuilderTool") addTool("ISF_FastCaloSimServices.AdditionalConfig.getFastShowerCellBuilderTool", "ISF_FastShowerCellBuilderTool") addTool("ISF_FastCaloSimServices.AdditionalConfig.getLegacyFastShowerCellBuilderTool", "ISF_LegacyFastShowerCellBuilderTool") diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcV2.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcV2.cxx index 8185e59fc22..80909249d7e 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcV2.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcV2.cxx @@ -16,6 +16,8 @@ #include "ISF_FastCaloSimEvent/TFCSTruthState.h" #include "ISF_FastCaloSimEvent/TFCSExtrapolationState.h" #include "ISF_FastCaloSimParametrization/CaloGeometryFromCaloDDM.h" +#include "ISF_FastCaloSimParametrization/FCS_Cell.h" + //! #include "AtlasDetDescr/AtlasDetectorID.h" @@ -175,31 +177,6 @@ StatusCode ISF::FastCaloSimSvcV2::simulate(const ISF::ISFParticle& isfp) Amg::Vector3D particle_position = isfp.position(); Amg::Vector3D particle_direction(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z()); - if (m_doPunchThrough) { - - Barcode::PhysicsProcessCode process = 201; - - // call punch-through simulation - const ISF::ISFParticleVector* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp); - - // add punch-through particles to the ISF particle broker - if (isfpVec) { - - //Record truth incident for created punch through particles - ISF::ISFTruthIncident truth( const_cast(isfp), - *isfpVec, - process, - isfp.nextGeoID(), // inherits from the parent - ISF::fKillsPrimary); - m_truthRecordSvc->registerTruthIncident( truth, true ); - - for (ISF::ISFParticle *particle : *isfpVec) { - m_particleBroker->push( particle, &isfp); - } - - } - } - //int barcode=isfp.barcode(); // isfp barcode, eta and phi: in case we need them // float eta_isfp = particle_position.eta(); // float phi_isfp = particle_position.phi(); @@ -244,6 +221,33 @@ StatusCode ISF::FastCaloSimSvcV2::simulate(const ISF::ISFParticle& isfp) CaloCell* theCell = (CaloCell*)m_theContainer->findCell(iter.first->calo_hash()); theCell->addEnergy(iter.second); } + + //now perform punch through + if (m_doPunchThrough) { + + Barcode::PhysicsProcessCode process = 201; + + // call punch-through simulation + const ISF::ISFParticleVector* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp, simulstate); + + // add punch-through particles to the ISF particle broker + if (isfpVec) { + + //Record truth incident for created punch through particles + ISF::ISFTruthIncident truth( const_cast(isfp), + *isfpVec, + process, + isfp.nextGeoID(), // inherits from the parent + ISF::fKillsPrimary); + m_truthRecordSvc->registerTruthIncident( truth, true ); + + for (ISF::ISFParticle *particle : *isfpVec) { + m_particleBroker->push( particle, &isfp); + } + + } + } + } else ATH_MSG_DEBUG("Skipping simulation as extrapolation to ID-Calo boundary failed."); diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/CMakeLists.txt b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/CMakeLists.txt index 8877996e744..6bfdb05847d 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/CMakeLists.txt +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/CMakeLists.txt @@ -28,13 +28,20 @@ find_package( Eigen ) find_package( HepMC ) find_package( HepPDT ) find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) +find_package( LibXml2 REQUIRED) + +include_directories( + ${LIBXML2_INCLUDE_DIR} + ) + + # Component(s) in the package: atlas_add_component( ISF_PunchThroughTools src/*.cxx src/components/*.cxx - INCLUDE_DIRS ${HEPPDT_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} - LINK_LIBRARIES ${HEPPDT_LIBRARIES} ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} ${HEPMC_LIBRARIES} ${EIGEN_LIBRARIES} AthenaBaseComps AthenaKernel GeoPrimitives ISF_FastCaloSimInterfaces ISF_FastCaloSimEvent DataModel GaudiKernel ISF_Event ISF_Interfaces PathResolver ) + INCLUDE_DIRS ${HEPPDT_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} ${LWTNN_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} + LINK_LIBRARIES ${HEPPDT_LIBRARIES} ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} ${HEPMC_LIBRARIES} ${EIGEN_LIBRARIES} ${LWTNN_LIBRARIES} ${LIBXML2_LIBRARIES} AthenaBaseComps AthenaKernel GeoPrimitives ISF_FastCaloSimInterfaces ISF_FastCaloSimEvent DataModel GaudiKernel ISF_Event ISF_Interfaces PathResolver ) # Install files from the package: atlas_install_headers( ISF_PunchThroughTools ) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx new file mode 100644 index 00000000000..9d61ab118fe --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx @@ -0,0 +1,235 @@ +#include "PunchThroughClassifier.h" + +#include +#include + +//LWTNN +#include "lwtnn/LightweightGraph.hh" +#include "lwtnn/parse_json.hh" + +//libXML +#include +#include +#include +#include +#include +#include + +ISF::PunchThroughClassifier::PunchThroughClassifier(const std::string& type, const std::string& name, const IInterface* parent) + : base_class(type, name, parent) { + + declareProperty( "ScalerConfigFileName", m_scalerConfigFileName ); + declareProperty( "NetworkConfigFileName", m_networkConfigFileName ); + declareProperty( "calibratorConfigFileName", m_calibratorConfigFileName ); +} + +ISF::PunchThroughClassifier::~PunchThroughClassifier() +{} + +double ISF::PunchThroughClassifier::computePunchThroughProbability(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const { + + std::map > networkInputs = computeInputs(isfp, simulstate); + + networkInputs = scaleInputs(networkInputs); + + std::map networkOutputs = m_graph->compute(networkInputs); + + double calibratedOutput = calibrateOutput(networkOutputs["out_0"]); + + return calibratedOutput; +} + + +StatusCode ISF::PunchThroughClassifier::initialize(){ + + std::cout << "initialising PunchThroughClassifier "<< std::endl; + + initializeScaler("./scaler.xml"); + + initializeNetwork("./network.json"); //initialise Network + + initializeCalibrator("./iso_calib.xml"); //initialise calibrator + + return StatusCode::SUCCESS; +} + +StatusCode ISF::PunchThroughClassifier::finalize(){ + + ATH_MSG_INFO( "[punchthroughclassifier] finalize() successful" ); + + return StatusCode::SUCCESS; +} + +StatusCode ISF::PunchThroughClassifier::initializeScaler(std::string scalerConfigFile){ + + //parse xml that contains config for MinMaxScaler for each of the network inputs + + xmlDocPtr doc = xmlParseFile( scalerConfigFile.c_str() ); + + std::cout << "Initializing scaler " << scalerConfigFile << std::endl; + + for( xmlNodePtr nodeRoot = doc->children; nodeRoot != nullptr; nodeRoot = nodeRoot->next) { + + if (xmlStrEqual( nodeRoot->name, BAD_CAST "Transformations" )) { + for( xmlNodePtr nodeTransform = nodeRoot->children; nodeTransform != nullptr; nodeTransform = nodeTransform->next ) { + + //Get min and max values that we normalise values to + if (xmlStrEqual( nodeTransform->name, BAD_CAST "ScalerValues" )) { + m_scalerMin = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "min" ) ); + m_scalerMax = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "max" ) ); + } + + //Get values necessary to normalise each input variable + if (xmlStrEqual( nodeTransform->name, BAD_CAST "VarScales" )) { + std::string name = (const char*) xmlGetProp( nodeTransform, BAD_CAST "name" ); + double min = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "min" ) ); + double max = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "max" ) ); + m_scalerMinMap.insert ( std::pair(name, min) ); + m_scalerMaxMap.insert ( std::pair(name, max) ); + } + } + } + } + + return StatusCode::SUCCESS; +} + +StatusCode ISF::PunchThroughClassifier::initializeNetwork(std::string networkConfigFile){ + + ATH_MSG_INFO( "[ punchthroughclassifier ] Loading classifier: " << networkConfigFile); + + std::cout << "initialising PunchThroughClassifier network "<< std::endl; + + + std::ifstream input(networkConfigFile); + if(!input){ + std::cout << "here0" << std::endl; + ATH_MSG_ERROR("Could not find json file " << networkConfigFile ); + return StatusCode::FAILURE; + } + + std::cout << "here" << std::endl; + + m_graph = new lwt::LightweightGraph(lwt::parse_json_graph(input)); + if(!m_graph){ + ATH_MSG_ERROR("Could not find parse graph json file " << networkConfigFile ); + return StatusCode::FAILURE; + } + + + return StatusCode::SUCCESS; +} + + +StatusCode ISF::PunchThroughClassifier::initializeCalibrator(std::string calibratorConfigFile){ + + //parse xml that contains config for isotonic regressor used to calibrate the network output + ATH_MSG_INFO( "[ punchthroughclassifier ] Loading calibrator: " << calibratorConfigFile); + + xmlDocPtr doc = xmlParseFile( calibratorConfigFile.c_str() ); + + + for( xmlNodePtr nodeRoot = doc->children; nodeRoot != nullptr; nodeRoot = nodeRoot->next) { + + if (xmlStrEqual( nodeRoot->name, BAD_CAST "Transformations" )) { + for( xmlNodePtr nodeTransform = nodeRoot->children; nodeTransform != nullptr; nodeTransform = nodeTransform->next ) { + + //get lower and upper bounds of isotonic regressor + if (xmlStrEqual( nodeTransform->name, BAD_CAST "LimitValues" )) { + m_calibrationMin = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "min" ) ); + m_calibrationMax = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "max" ) ); + } + + //get defined points where isotonic regressor knows transform + if (xmlStrEqual( nodeTransform->name, BAD_CAST "LinearNorm" )) { + double orig = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "orig" ) ); + double norm = atof( (const char*) xmlGetProp( nodeTransform, BAD_CAST "norm" ) ); + m_calibrationMap.insert ( std::pair(orig, norm) ); + } + } + } + } + + return StatusCode::SUCCESS; +} + +std::map > ISF::PunchThroughClassifier::computeInputs(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const{ + + std::map > networkInputs; + + networkInputs["node_0"] = { + {"variable_0", isfp.momentum().mag() }, + {"variable_1", fabs(isfp.position().eta()) }, + {"variable_2", isfp.position().phi() }, + {"variable_3", simulstate.E()}, + {"variable_4", simulstate.Efrac(0) }, + {"variable_5", simulstate.Efrac(1) }, + {"variable_6", simulstate.Efrac(2) }, + {"variable_7", simulstate.Efrac(3) }, + {"variable_8", simulstate.Efrac(4) }, + {"variable_9", simulstate.Efrac(5) }, + {"variable_10", simulstate.Efrac(6) }, + {"variable_11", simulstate.Efrac(7) }, + {"variable_12", simulstate.Efrac(8) }, + {"variable_13", simulstate.Efrac(9) }, + {"variable_14", simulstate.Efrac(10) }, + {"variable_15", simulstate.Efrac(11) }, + {"variable_16", simulstate.Efrac(12) }, + {"variable_17", simulstate.Efrac(13) }, + {"variable_18", simulstate.Efrac(14) }, + {"variable_19", simulstate.Efrac(15) }, + {"variable_20", simulstate.Efrac(16) }, + {"variable_21", simulstate.Efrac(17) }, + {"variable_22", simulstate.Efrac(18) }, + {"variable_23", simulstate.Efrac(19) }, + {"variable_24", simulstate.Efrac(20) }, + {"variable_25", simulstate.Efrac(21) }, + {"variable_26", simulstate.Efrac(22) }, + {"variable_27", simulstate.Efrac(23) }, + }; + + return networkInputs; +} + +std::map > ISF::PunchThroughClassifier::scaleInputs(std::map >& inputs) const{ + + //apply MinMaxScaler to network inputs + + for (auto var = inputs["node_0"].begin(); var != inputs["node_0"].end(); ++var) { + + double x_std; + if(m_scalerMaxMap.at(var->first) != m_scalerMinMap.at(var->first)){ + x_std = (var->second - m_scalerMinMap.at(var->first)) / (m_scalerMaxMap.at(var->first) - m_scalerMinMap.at(var->first)); + } + else{ + x_std = (var->second - m_scalerMinMap.at(var->first)); + } + var->second = x_std * (m_scalerMax - m_scalerMin) + m_scalerMin; + } + + return inputs; +} + +double ISF::PunchThroughClassifier::calibrateOutput(double& networkOutput) const { + + //calibrate output of network using isotonic regressor model + + //if network output is outside of the range of isotonic regressor then return min and max values + if (networkOutput < m_calibrationMin){ + return m_calibrationMin; + } + if (networkOutput > m_calibrationMax){ + return m_calibrationMax; + } + + //otherwise find neighbouring points in isotonic regressor + auto upper = m_calibrationMap.upper_bound(networkOutput); + auto lower = upper--; + + //Perform linear interpolation between points + double m = (upper->second - lower->second)/(upper->first - lower->first); + double c = lower->second - m * lower->first; + double calibrated = m * networkOutput + c; + + return calibrated; +} diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h new file mode 100644 index 00000000000..8db292ce75e --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h @@ -0,0 +1,67 @@ +#ifndef ISF_PUNCHTHROUGHTOOLS_SRC_PUNCHTHROUGHCLASSIFIER_H +#define ISF_PUNCHTHROUGHTOOLS_SRC_PUNCHTHROUGHCLASSIFIER_H 1 + +// ISF includes +#include "ISF_Event/ISFParticle.h" + +#include "ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h" + +#include "ISF_FastCaloSimEvent/TFCSSimulationState.h" + +#include "AthenaBaseComps/AthAlgTool.h" + + +#include + +namespace lwt +{ + class LightweightGraph; +} + +namespace ISF { + +class PunchThroughClassifier : public extends { +public: + + PunchThroughClassifier(const std::string&,const std::string&,const IInterface*); + + virtual ~PunchThroughClassifier(); + + virtual StatusCode initialize() override final; + virtual StatusCode finalize() override final; + + StatusCode initializeScaler(std::string scalerConfigFile); + StatusCode initializeNetwork(std::string networkConfigFile); + StatusCode initializeCalibrator(std::string calibratorConfigFile); + + double computePunchThroughProbability(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const; + + std::map > computeInputs(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const; + std::map > scaleInputs(std::map >& inputs) const; + + double calibrateOutput(double& networkOutput) const; + +private: + const char* m_name=nullptr; + + lwt::LightweightGraph* m_graph=nullptr; + + double m_scalerMin; + double m_scalerMax; + std::map m_scalerMinMap; + std::map m_scalerMaxMap; + + std::string m_calibratorConfigFile; + double m_calibrationMin; + double m_calibrationMax; + std::map m_calibrationMap; + + //properties + std::string m_networkConfigFileName; + std::string m_scalerConfigFileName; + std::string m_calibratorConfigFileName; + +}; +} + +#endif //ISF_PUNCHTHROUGHTOOLS_SRC_PUNCHTHROUGHCLASSIFIER_H diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx index d8edfd18a38..4bb94d23a29 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx @@ -52,6 +52,7 @@ #include "ISF_Event/ISFParticle.h" #include "PDFcreator.h" #include "PunchThroughParticle.h" +#include "PunchThroughClassifier.h" #include "ISF_Interfaces/IGeoIDSvc.h" #include "ISF_FastCaloSimEvent/TFCS1DFunctionInt32Histogram.h" @@ -76,6 +77,7 @@ ISF::PunchThroughTool::PunchThroughTool( const std::string& type, const IInterface* parent ) : base_class(type, name, parent), m_randomSvc("AtDSFMTGenSvc", name), + m_punchThroughClassifier("ISF_PunchThroughClassifier"), m_pdgInitiators(), m_initiatorsMinEnergy(), m_initiatorsEtaRange(), @@ -136,6 +138,12 @@ StatusCode ISF::PunchThroughTool::initialize() { ATH_MSG_INFO( "initialize()" ); + if (m_punchThroughClassifier.retrieve().isFailure() ) + { + ATH_MSG_ERROR (m_punchThroughClassifier.propertyName() << ": Failed to retrieve tool " << m_punchThroughClassifier.type()); + return StatusCode::FAILURE; + } + // resolving lookuptable file std::string resolvedFileName = PathResolverFindCalibFile (m_filenameLookupTable); if (resolvedFileName != "") @@ -346,7 +354,7 @@ StatusCode ISF::PunchThroughTool::finalize() * ==> see headerfile *=======================================================================*/ -const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticles(const ISF::ISFParticle &isfp) const +const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticles(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate ) const { ATH_MSG_DEBUG( "[ punchthrough ] starting punch-through simulation"); @@ -408,7 +416,17 @@ const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticle return 0; } - //if initial particle is on ID surface, points to the calorimeter, is a punch-through initiator, meets initiator min enery and eta range + double punchThroughProbability = m_punchThroughClassifier->computePunchThroughProbability(isfp, simulstate); + + double punchThroughClassifierRand = CLHEP::RandFlat::shoot(m_randomEngine); + + if( punchThroughClassifierRand > punchThroughProbability){ + ATH_MSG_DEBUG("[ punchthrough ] particle not classified to create punch through. Dropping it in the calo."); + ATH_MSG_DEBUG("[ punchthrough ] punchThroughClassifier output: " << punchThroughProbability << " RandFlat: " << punchThroughClassifierRand ); + return 0; + } + + //if initial particle is on ID surface, points to the calorimeter, is a punch-through initiator, meets initiator min enery and eta range, and passes punchThroughClassifier // store initial particle mass const double mass = m_initPs->mass(); diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h index dd5c8060721..5fc79bebc36 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h @@ -6,6 +6,9 @@ #define ISF_PUNCHTHROUGHTOOLS_SRC_PUNCHTHROUGHTOOL_H 1 #include "ISF_FastCaloSimInterfaces/IPunchThroughTool.h" + +#include "ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h" + #include // Athena Base @@ -16,6 +19,7 @@ #include "GeoPrimitives/GeoPrimitives.h" #include "ISF_Event/ISFParticleVector.h" + /*------------------------------------------------------------------------- * Forward declarations *-------------------------------------------------------------------------*/ @@ -44,6 +48,7 @@ namespace Barcode { namespace ISF { class PunchThroughParticle; + class PunchThroughClassifier; class PDFcreator; class IGeoIDSvc; } @@ -64,7 +69,7 @@ namespace ISF { /** AlgTool finalize method */ virtual StatusCode finalize (); /** interface function: fill a vector with the punch-through particles */ - const ISF::ISFParticleVector* computePunchThroughParticles(const ISF::ISFParticle &isfp) const; + const ISF::ISFParticleVector* computePunchThroughParticles(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const; private: /*--------------------------------------------------------------------- @@ -157,6 +162,7 @@ namespace ISF { /** Properties */ std::string m_filenameLookupTable{"CaloPunchThroughParametrisation.root"}; //!< holds the filename of the lookup table (property) + ToolHandle< IPunchThroughClassifier > m_punchThroughClassifier; std::vector m_pdgInitiators; //!< vector of punch-through initiator pgds std::vector m_initiatorsMinEnergy; //!< vector of punch-through initiator min energyies to create punch through std::vector m_initiatorsEtaRange; //!< vector of min and max abs eta range to allow punch through initiators diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx index 2610be68343..03f79862512 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx @@ -1,8 +1,12 @@ #include "GaudiKernel/DeclareFactoryEntries.h" #include "../PunchThroughTool.h" +#include "../PunchThroughClassifier.h" DECLARE_NAMESPACE_TOOL_FACTORY( ISF,PunchThroughTool) DECLARE_FACTORY_ENTRIES( ISF_PunchThroughTools ) { DECLARE_NAMESPACE_TOOL( ISF,PunchThroughTool) } - +DECLARE_NAMESPACE_TOOL_FACTORY( ISF,PunchThroughClassifier) +DECLARE_FACTORY_ENTRIES( ISF_PunchThroughClassifier ) { + DECLARE_NAMESPACE_TOOL( ISF,PunchThroughClassifier) +} diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx index 428a49e6599..a59d7e262d8 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx @@ -2,4 +2,4 @@ #include "GaudiKernel/LoadFactoryEntries.h" LOAD_FACTORY_ENTRIES( ISF_PunchThroughTools ) - +LOAD_FACTORY_ENTRIES( ISF_PunchThroughClassifier ) -- GitLab From 1583282537f84a031d70ca98654169a16c39151c Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 3 May 2022 11:02:34 +0200 Subject: [PATCH 2/3] mpt classifier: fix final issues, clean up, comments --- .../IPunchThroughClassifier.h | 1 + .../python/AdditionalConfig.py | 8 ++-- .../python/ISF_FastCaloSimJobProperties.py | 22 ++++++++++ .../src/PunchThroughClassifier.cxx | 40 ++++++++++--------- .../src/PunchThroughClassifier.h | 17 ++++++++ .../src/PunchThroughTool.cxx | 9 ++++- .../src/PunchThroughTool.h | 2 - .../ISF_PunchThroughTools_entries.cxx | 5 +-- .../components/ISF_PunchThroughTools_load.cxx | 1 - 9 files changed, 75 insertions(+), 30 deletions(-) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h index dde5dad09d3..9e81b43ad58 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughClassifier.h @@ -34,6 +34,7 @@ namespace ISF { /// Creates the InterfaceID and interfaceID() method DeclareInterfaceID(IPunchThroughClassifier, 1, 0); + /** calculates probability of punch through from ispf and simulstate */ virtual double computePunchThroughProbability(const ISFParticle& isfp, const TFCSSimulationState& simulstate ) const = 0; }; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py index 921494663f6..8489deb8480 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py @@ -685,10 +685,10 @@ def getPunchThroughTool(name="ISF_PunchThroughTool", **kwargs): return ISF__PunchThroughTool(name, **kwargs ) def getPunchThroughClassifier(name="ISF_PunchThroughClassifier", **kwargs): - kwargs.setdefault("ScalerConfigFileName" , "./" ) - kwargs.setdefault("NetworkConfigFileName" , "test" ) - kwargs.setdefault("CalibratorConfigFileName" , "test" ) - from ISF_PunchThroughClassifier.ISF_PunchThroughClassifierConf import ISF__PunchThroughClassifier + kwargs.setdefault("ScalerConfigFileName" , ISF_FastCaloSimFlags.PunchThroughClassifierScalerFilename() ) + kwargs.setdefault("NetworkConfigFileName" , ISF_FastCaloSimFlags.PunchThroughClassifierNetworkFilename() ) + kwargs.setdefault("CalibratorConfigFileName" , ISF_FastCaloSimFlags.PunchThroughClassifierCalibratorFilename()) + from ISF_PunchThroughTools.ISF_PunchThroughToolsConf import ISF__PunchThroughClassifier return ISF__PunchThroughClassifier(name, **kwargs ) def getEmptyCellBuilderTool(name="ISF_EmptyCellBuilderTool", **kwargs): diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py index 9320b380485..910b6f14543 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py @@ -74,6 +74,24 @@ class PunchThroughParamsInputFilename(JobProperty): allowedTypes = ['str'] StoredValue = 'FastCaloSim/MC16/TFCSparam_mpt_v01.root' +class PunchThroughClassifierScalerFilename(JobProperty): + """ Filename of the muon punch through classifier input variable MinMaxScaler. """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'FastCaloSim/MC16/TFCSparam_mpt_classScaler_v01.xml' + +class PunchThroughClassifierNetworkFilename(JobProperty): + """ Filename of the muon punch through classifier neural network. """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'FastCaloSim/MC16/TFCSparam_mpt_classNet_v01.json' + +class PunchThroughClassifierCalibratorFilename(JobProperty): + """ Filename of the muon punch through classifier calibrator. """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'FastCaloSim/MC16/TFCSparam_mpt_classCalib_v01.xml' + ##----------------------------------------------------------------------------- ## 2nd step ## Definition of the InDet flag container @@ -99,6 +117,10 @@ jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( DoRandomFluctuations jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( ParamsInputFilename ) jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( DoPunchThroughSimulation ) jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( PunchThroughParamsInputFilename) +jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( PunchThroughClassifierScalerFilename) +jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( PunchThroughClassifierNetworkFilename) +jobproperties.ISF_FastCaloSimJobProperties.add_JobProperty( PunchThroughClassifierCalibratorFilename) + ##----------------------------------------------------------------------------- ## 5th step diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx index 9d61ab118fe..575b3803c38 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx @@ -20,7 +20,7 @@ ISF::PunchThroughClassifier::PunchThroughClassifier(const std::string& type, con declareProperty( "ScalerConfigFileName", m_scalerConfigFileName ); declareProperty( "NetworkConfigFileName", m_networkConfigFileName ); - declareProperty( "calibratorConfigFileName", m_calibratorConfigFileName ); + declareProperty( "CalibratorConfigFileName", m_calibratorConfigFileName ); } ISF::PunchThroughClassifier::~PunchThroughClassifier() @@ -28,13 +28,13 @@ ISF::PunchThroughClassifier::~PunchThroughClassifier() double ISF::PunchThroughClassifier::computePunchThroughProbability(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const { - std::map > networkInputs = computeInputs(isfp, simulstate); + std::map > networkInputs = computeInputs(isfp, simulstate); //compute inputs - networkInputs = scaleInputs(networkInputs); + networkInputs = scaleInputs(networkInputs); //scale inputs - std::map networkOutputs = m_graph->compute(networkInputs); + std::map networkOutputs = m_graph->compute(networkInputs); //call neural network on inputs - double calibratedOutput = calibrateOutput(networkOutputs["out_0"]); + double calibratedOutput = calibrateOutput(networkOutputs["out_0"]); //calibrate neural network output return calibratedOutput; } @@ -42,13 +42,22 @@ double ISF::PunchThroughClassifier::computePunchThroughProbability(const ISF::IS StatusCode ISF::PunchThroughClassifier::initialize(){ - std::cout << "initialising PunchThroughClassifier "<< std::endl; + ATH_MSG_INFO( "[ punchthroughclassifier ] initialize()" ); - initializeScaler("./scaler.xml"); + if ( initializeScaler(m_scalerConfigFileName) != StatusCode::SUCCESS) + { + ATH_MSG_ERROR("[ punchthroughclassifier ] unable to load punchthroughclassifier input scaler"); + } - initializeNetwork("./network.json"); //initialise Network + if ( initializeNetwork(m_networkConfigFileName) != StatusCode::SUCCESS) + { + ATH_MSG_ERROR("[ punchthroughclassifier ] unable to load punchthroughclassifier network"); + } - initializeCalibrator("./iso_calib.xml"); //initialise calibrator + if ( initializeCalibrator(m_calibratorConfigFileName) != StatusCode::SUCCESS) + { + ATH_MSG_ERROR("[ punchthroughclassifier ] unable to load punchthroughclassifier calibrator"); + } return StatusCode::SUCCESS; } @@ -66,7 +75,7 @@ StatusCode ISF::PunchThroughClassifier::initializeScaler(std::string scalerConfi xmlDocPtr doc = xmlParseFile( scalerConfigFile.c_str() ); - std::cout << "Initializing scaler " << scalerConfigFile << std::endl; + ATH_MSG_INFO( "[ punchthroughclassifier ] Loading scaler: " << scalerConfigFile); for( xmlNodePtr nodeRoot = doc->children; nodeRoot != nullptr; nodeRoot = nodeRoot->next) { @@ -98,21 +107,15 @@ StatusCode ISF::PunchThroughClassifier::initializeNetwork(std::string networkCon ATH_MSG_INFO( "[ punchthroughclassifier ] Loading classifier: " << networkConfigFile); - std::cout << "initialising PunchThroughClassifier network "<< std::endl; - - std::ifstream input(networkConfigFile); if(!input){ - std::cout << "here0" << std::endl; ATH_MSG_ERROR("Could not find json file " << networkConfigFile ); return StatusCode::FAILURE; } - std::cout << "here" << std::endl; - m_graph = new lwt::LightweightGraph(lwt::parse_json_graph(input)); if(!m_graph){ - ATH_MSG_ERROR("Could not find parse graph json file " << networkConfigFile ); + ATH_MSG_ERROR("Could not parse graph json file " << networkConfigFile ); return StatusCode::FAILURE; } @@ -128,7 +131,6 @@ StatusCode ISF::PunchThroughClassifier::initializeCalibrator(std::string calibra xmlDocPtr doc = xmlParseFile( calibratorConfigFile.c_str() ); - for( xmlNodePtr nodeRoot = doc->children; nodeRoot != nullptr; nodeRoot = nodeRoot->next) { if (xmlStrEqual( nodeRoot->name, BAD_CAST "Transformations" )) { @@ -155,6 +157,8 @@ StatusCode ISF::PunchThroughClassifier::initializeCalibrator(std::string calibra std::map > ISF::PunchThroughClassifier::computeInputs(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const{ + //calculate inputs for NN + std::map > networkInputs; networkInputs["node_0"] = { diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h index 8db292ce75e..e6161e31928 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.h @@ -23,34 +23,51 @@ namespace ISF { class PunchThroughClassifier : public extends { public: + /** Constructor */ PunchThroughClassifier(const std::string&,const std::string&,const IInterface*); + /** Destructor */ virtual ~PunchThroughClassifier(); + /** AlgTool initialize method */ virtual StatusCode initialize() override final; + /** AlgTool finalize method */ virtual StatusCode finalize() override final; + /** input variable MinMaxScaler initialize method */ StatusCode initializeScaler(std::string scalerConfigFile); + + /** neural network initialize method */ StatusCode initializeNetwork(std::string networkConfigFile); + + /** isotonic regressor calibrator initialize method */ StatusCode initializeCalibrator(std::string calibratorConfigFile); + /** interface method to return probability prediction of punch through */ double computePunchThroughProbability(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const; + /** calcalate NN inputs based on isfp and simulstate */ std::map > computeInputs(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate) const; + + /** scale NN inputs using MinMaxScaler */ std::map > scaleInputs(std::map >& inputs) const; + /** calibrate NN output using isotonic regressor */ double calibrateOutput(double& networkOutput) const; private: const char* m_name=nullptr; + /** NN graph */ lwt::LightweightGraph* m_graph=nullptr; + /** input variable MinMaxScaler members */ double m_scalerMin; double m_scalerMax; std::map m_scalerMinMap; std::map m_scalerMaxMap; + /** isotonic regressor calibrator members */ std::string m_calibratorConfigFile; double m_calibrationMin; double m_calibrationMax; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx index 4bb94d23a29..f11fa336283 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx @@ -52,7 +52,6 @@ #include "ISF_Event/ISFParticle.h" #include "PDFcreator.h" #include "PunchThroughParticle.h" -#include "PunchThroughClassifier.h" #include "ISF_Interfaces/IGeoIDSvc.h" #include "ISF_FastCaloSimEvent/TFCS1DFunctionInt32Histogram.h" @@ -99,6 +98,7 @@ ISF::PunchThroughTool::PunchThroughTool( const std::string& type, { // property definition and initialization - allows to set variables from python + declareProperty( "PunchThroughClassifier", m_punchThroughClassifier); declareProperty( "FilenameLookupTable", m_filenameLookupTable ); declareProperty( "PunchThroughInitiators", m_pdgInitiators ); declareProperty( "InitiatorsMinEnergy", m_initiatorsMinEnergy ); @@ -416,13 +416,18 @@ const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticle return 0; } + + //Calculate probability of punch through using punchThroughClassifier double punchThroughProbability = m_punchThroughClassifier->computePunchThroughProbability(isfp, simulstate); + //Draw random number to compare to probability double punchThroughClassifierRand = CLHEP::RandFlat::shoot(m_randomEngine); + ATH_MSG_INFO("[ punchthrough ] punchThroughProbability output: " << punchThroughProbability << " RandFlat: " << punchThroughClassifierRand ); + + //If probability < random number then don't simulate punch through if( punchThroughClassifierRand > punchThroughProbability){ ATH_MSG_DEBUG("[ punchthrough ] particle not classified to create punch through. Dropping it in the calo."); - ATH_MSG_DEBUG("[ punchthrough ] punchThroughClassifier output: " << punchThroughProbability << " RandFlat: " << punchThroughClassifierRand ); return 0; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h index 5fc79bebc36..66fa0c16ade 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h @@ -46,9 +46,7 @@ namespace Barcode { } namespace ISF { - class PunchThroughParticle; - class PunchThroughClassifier; class PDFcreator; class IGeoIDSvc; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx index 03f79862512..6ae958e3b6d 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_entries.cxx @@ -3,10 +3,9 @@ #include "../PunchThroughClassifier.h" DECLARE_NAMESPACE_TOOL_FACTORY( ISF,PunchThroughTool) +DECLARE_NAMESPACE_TOOL_FACTORY( ISF,PunchThroughClassifier) + DECLARE_FACTORY_ENTRIES( ISF_PunchThroughTools ) { DECLARE_NAMESPACE_TOOL( ISF,PunchThroughTool) -} -DECLARE_NAMESPACE_TOOL_FACTORY( ISF,PunchThroughClassifier) -DECLARE_FACTORY_ENTRIES( ISF_PunchThroughClassifier ) { DECLARE_NAMESPACE_TOOL( ISF,PunchThroughClassifier) } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx index a59d7e262d8..6d6b378c82a 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/components/ISF_PunchThroughTools_load.cxx @@ -2,4 +2,3 @@ #include "GaudiKernel/LoadFactoryEntries.h" LOAD_FACTORY_ENTRIES( ISF_PunchThroughTools ) -LOAD_FACTORY_ENTRIES( ISF_PunchThroughClassifier ) -- GitLab From af363593559650142f2ad33fe8751cf1701af308 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 May 2022 16:53:20 +0200 Subject: [PATCH 3/3] FCS mpt classifier: add path resolver, update param file and IPunchThroughTool --- .../ISF_FastCaloSimInterfaces/IPunchThroughTool.h | 5 ++++- .../python/ISF_FastCaloSimJobProperties.py | 2 +- .../src/PunchThroughClassifier.cxx | 12 +++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h index 5cab36a2716..ad701b8286b 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h @@ -12,6 +12,9 @@ #include "ISF_Event/ISFParticle.h" #include "ISF_Event/ISFParticleVector.h" +#include "ISF_FastCaloSimEvent/TFCSSimulationState.h" + + namespace Trk{ class Track; } @@ -37,7 +40,7 @@ namespace ISF { DeclareInterfaceID(IPunchThroughTool, 1, 0); /** Creates new vector of ISFParticle out of a given ISFParticle */ - virtual const ISF::ISFParticleVector* computePunchThroughParticles(const ISFParticle& isfp ) const = 0; + virtual const ISF::ISFParticleVector* computePunchThroughParticles(const ISFParticle& isfp, const TFCSSimulationState& simulstate ) const = 0; }; } // end of namespace diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py index 910b6f14543..79ad4703fce 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimJobProperties.py @@ -72,7 +72,7 @@ class PunchThroughParamsInputFilename(JobProperty): """ Filename of the muon punch through input parametrizations file. """ statusOn = True allowedTypes = ['str'] - StoredValue = 'FastCaloSim/MC16/TFCSparam_mpt_v01.root' + StoredValue = 'FastCaloSim/MC16/TFCSparam_mpt_v03.root' class PunchThroughClassifierScalerFilename(JobProperty): """ Filename of the muon punch through classifier input variable MinMaxScaler. """ diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx index 575b3803c38..d190e11cf8f 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughClassifier.cxx @@ -3,6 +3,9 @@ #include #include +// PathResolver +#include "PathResolver/PathResolver.h" + //LWTNN #include "lwtnn/LightweightGraph.hh" #include "lwtnn/parse_json.hh" @@ -44,17 +47,20 @@ StatusCode ISF::PunchThroughClassifier::initialize(){ ATH_MSG_INFO( "[ punchthroughclassifier ] initialize()" ); - if ( initializeScaler(m_scalerConfigFileName) != StatusCode::SUCCESS) + std::string resolvedScalerFileName = PathResolverFindCalibFile (m_scalerConfigFileName); + if ( initializeScaler(resolvedScalerFileName) != StatusCode::SUCCESS) { ATH_MSG_ERROR("[ punchthroughclassifier ] unable to load punchthroughclassifier input scaler"); } - if ( initializeNetwork(m_networkConfigFileName) != StatusCode::SUCCESS) + std::string resolvedNetworkFileName = PathResolverFindCalibFile (m_networkConfigFileName); + if ( initializeNetwork(resolvedNetworkFileName) != StatusCode::SUCCESS) { ATH_MSG_ERROR("[ punchthroughclassifier ] unable to load punchthroughclassifier network"); } - if ( initializeCalibrator(m_calibratorConfigFileName) != StatusCode::SUCCESS) + std::string resolvedCalibratorFileName = PathResolverFindCalibFile (m_calibratorConfigFileName); + if ( initializeCalibrator(resolvedCalibratorFileName) != StatusCode::SUCCESS) { ATH_MSG_ERROR("[ punchthroughclassifier ] unable to load punchthroughclassifier calibrator"); } -- GitLab