ATLAS Offline Software
Loading...
Searching...
No Matches
ISF::DNNCaloSimSvc Class Referencefinal

#include <DNNCaloSimSvc.h>

Inheritance diagram for ISF::DNNCaloSimSvc:
Collaboration diagram for ISF::DNNCaloSimSvc:

Public Types

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

Public Member Functions

 DNNCaloSimSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters.
virtual ~DNNCaloSimSvc () final
 Destructor.
virtual StatusCode initialize () override final
 Athena algorithm's interface methods.
virtual StatusCode finalize () override final
 framework methods
StatusCode initializeNetwork ()
 helper for initialize
virtual StatusCode simulate (ISFParticle &isp, McEventCollection *) override final
 Simulation Call.
StatusCode fillNetworkInputs (const ISF::ISFParticle &isfp, NetworkInputs &inputs, double &trueEnergy)
StatusCode fillWindowCells (const double etaExtrap, const double phiExtrap, const CaloDetDescrElement *&impactCellDDE)
virtual StatusCode setupEvent () override final
 Setup Event chain - in case of a begin-of event action is needed.
virtual StatusCode releaseEvent () override final
 Release Event chain - in case of an end-of event action is needed.
virtual StatusCode sysInitialize () override
 Gaudi sysInitialize() methods.
const std::string & simSvcDescriptor () override
 Return the simulation service descriptor.
virtual StatusCode setParticleBroker (IParticleBroker *broker) override
 Inform the SimulationSvc about the ParticleBroker svc.
virtual StatusCode simulateVector (const ISFParticleVector &particles, McEventCollection *mcEventCollection, McEventCollection *) override
 Simulation call for vectors of particles.
const ChronoEntity * chronoStart (const IChronoSvc::ChronoTag &tag)
 wrapper call to start chrono with given tag
const ChronoEntity * chronoStop (const IChronoSvc::ChronoTag &tag)
 wrapper call to stop chrono with given tag
const ServiceHandle< StoreGateSvc > & evtStore () const
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
ServiceHandle< StoreGateSvc > & evtStore ()
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
ServiceHandle< StoreGateSvc > & detStore ()
template<class T>
StatusCode retrieveTool (ToolHandle< T > &thandle)
 templated Tool retrieval - gives unique handling & look and feel
template<class T>
StatusCode retrieveTools (ToolHandleArray< T > &thandleArray)
 templated Tool retrieval - gives unique handling & look and feel
template<class T>
StatusCode recordCollection (T *&coll, const std::string &collName) const
 templated record collection method, will create a new one if not existing
template<class T>
StatusCode retrieveCollection (T *&coll, const std::string &collName, bool forceBreak=true) const
 templated retrieve collection method, boolean steers that force break

Public Attributes

std::string m_paramsFilename
std::string m_paramsInputArchitecture
std::unique_ptr< lwt::LightweightGraph > m_graph
ToolHandleArray< ICaloCellMakerToolm_caloCellMakerToolsSetup
ToolHandleArray< ICaloCellMakerToolm_caloCellMakerToolsRelease
ToolHandle< IFastCaloSimCaloExtrapolationm_FastCaloSimCaloExtrapolation
ToolHandle< Trk::ITimedExtrapolatorm_extrapolator
CaloCellContainerm_theContainer
ServiceHandle< IAtRndmGenSvcm_rndGenSvc
CLHEP::HepRandomEngine * m_randomEngine
std::string m_randomEngineName
const CaloDetDescrManagerm_caloDetDescrManager
std::unique_ptr< CaloGeometryFromCaloDDMm_caloGeo
const LArEM_IDm_emID = nullptr
std::vector< CaloCell * > m_windowCells
int m_GANLatentSize = 0
double m_logTrueEnergyMean = 0.
double m_logTrueEnergyScale = 0.
double m_riImpactEtaMean = 0.
double m_riImpactEtaScale = 0.
double m_riImpactPhiMean = 0.
double m_riImpactPhiScale = 0.
const int m_numberOfCellsForDNN = 266
const double m_middleCellWidthEta = 0.025
const double m_middleCellWidthPhi = CLHEP::pi / std::pow(2,7)
const double m_etaRawMiddleCut = m_middleCellWidthEta * 3.5
const double m_etaRawBackCut = m_middleCellWidthEta * 4.
const double m_phiRawMiddleCut = m_middleCellWidthPhi * 3.5
const double m_phiRawStripCut = m_middleCellWidthPhi * 6.0
std::string m_caloCellsOutputName

Protected Attributes

Gaudi::Property< std::string > m_simDescr
 The simulator service descriptor.
Gaudi::Property< std::string > m_screenOutputPrefix
 Screen output refinement.
ServiceHandle< IChronoStatSvc > m_chrono {this, "ChronoStatService", "ChronoStatSvc"}
 The timing service for general usage.
IParticleBrokerm_particleBroker {}
 The particle service used to push particles into the simulation.

Private Attributes

ServiceHandle< StoreGateSvcm_evtStore
 Handle to StoreGate (event store by default)
ServiceHandle< StoreGateSvcm_detStore
 Handle to StoreGate (detector store by default)

Detailed Description

Author
Aishik.Ghosh -at- cern.ch, David Rousseau -at- cern.ch,

Definition at line 56 of file DNNCaloSimSvc.h.

Member Typedef Documentation

◆ NetworkInputs

typedef std::map<std::string, std::map<std::string, double> > ISF::DNNCaloSimSvc::NetworkInputs

Definition at line 75 of file DNNCaloSimSvc.h.

◆ NetworkOutputs

typedef std::map<std::string, double> ISF::DNNCaloSimSvc::NetworkOutputs

Definition at line 76 of file DNNCaloSimSvc.h.

Constructor & Destructor Documentation

◆ DNNCaloSimSvc()

ISF::DNNCaloSimSvc::DNNCaloSimSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Constructor with parameters.

Constructor.

Definition at line 55 of file DNNCaloSimSvc.cxx.

55 :
56 BaseSimulationSvc(name, svc),
57 m_graph(nullptr),
58 m_theContainer(nullptr),
59 m_rndGenSvc("AtRndmGenSvc", name),
60 m_randomEngine(nullptr),
61 m_caloDetDescrManager(nullptr),
62 m_caloGeo(nullptr)
63{
64 declareProperty("ParamsInputFilename" , m_paramsFilename="DNNCaloSim/DNNCaloSim_GAN_nn_v0.json"," lwtnn json output describing the trained network");
65 declareProperty("ParamsInputArchitecture" , m_paramsInputArchitecture="GANv0","tag describing additional parameters necessary for the network");
66 declareProperty("CaloCellsOutputName" , m_caloCellsOutputName) ;
67 declareProperty("CaloCellMakerTools_setup" , m_caloCellMakerToolsSetup) ;
68 declareProperty("CaloCellMakerTools_release" , m_caloCellMakerToolsRelease) ;
69 declareProperty("RandomSvc" , m_rndGenSvc );
70 declareProperty("RandomStream" , m_randomEngineName );
71 declareProperty("FastCaloSimCaloExtrapolation" , m_FastCaloSimCaloExtrapolation );
72
73}
BaseSimulationSvc()
Default constructor.
const CaloDetDescrManager * m_caloDetDescrManager
std::string m_caloCellsOutputName
CaloCellContainer * m_theContainer
std::string m_paramsInputArchitecture
std::string m_randomEngineName
ServiceHandle< IAtRndmGenSvc > m_rndGenSvc
std::unique_ptr< lwt::LightweightGraph > m_graph
CLHEP::HepRandomEngine * m_randomEngine
ToolHandleArray< ICaloCellMakerTool > m_caloCellMakerToolsSetup
ToolHandle< IFastCaloSimCaloExtrapolation > m_FastCaloSimCaloExtrapolation
std::unique_ptr< CaloGeometryFromCaloDDM > m_caloGeo
ToolHandleArray< ICaloCellMakerTool > m_caloCellMakerToolsRelease
std::string m_paramsFilename

◆ ~DNNCaloSimSvc()

ISF::DNNCaloSimSvc::~DNNCaloSimSvc ( )
finalvirtualdefault

Destructor.

Member Function Documentation

◆ chronoStart()

const ChronoEntity * ISF::BaseSimulationSvc::chronoStart ( const IChronoSvc::ChronoTag & tag)
inlineinherited

wrapper call to start chrono with given tag

Definition at line 105 of file BaseSimulationSvc.h.

105 {
106 if (m_chrono) return m_chrono->chronoStart( tag);
107 return nullptr;
108 }
ServiceHandle< IChronoStatSvc > m_chrono
The timing service for general usage.

◆ chronoStop()

const ChronoEntity * ISF::BaseSimulationSvc::chronoStop ( const IChronoSvc::ChronoTag & tag)
inlineinherited

wrapper call to stop chrono with given tag

Definition at line 111 of file BaseSimulationSvc.h.

111 {
112 if (m_chrono) return m_chrono->chronoStop( tag);
113 return nullptr;
114 }

◆ detStore() [1/2]

ServiceHandle< StoreGateSvc > & ISF::BaseSimulationSvc::detStore ( )
inlineinherited

Definition at line 126 of file BaseSimulationSvc.h.

126{return m_detStore;};
ServiceHandle< StoreGateSvc > m_detStore
Handle to StoreGate (detector store by default)

◆ detStore() [2/2]

const ServiceHandle< StoreGateSvc > & ISF::BaseSimulationSvc::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 125 of file BaseSimulationSvc.h.

125{return m_detStore;};

◆ evtStore() [1/2]

ServiceHandle< StoreGateSvc > & ISF::BaseSimulationSvc::evtStore ( )
inlineinherited

Definition at line 120 of file BaseSimulationSvc.h.

120{return m_evtStore;};
ServiceHandle< StoreGateSvc > m_evtStore
Handle to StoreGate (event store by default)

◆ evtStore() [2/2]

const ServiceHandle< StoreGateSvc > & ISF::BaseSimulationSvc::evtStore ( ) const
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 119 of file BaseSimulationSvc.h.

119{return m_evtStore;};

◆ fillNetworkInputs()

StatusCode ISF::DNNCaloSimSvc::fillNetworkInputs ( const ISF::ISFParticle & isfp,
NetworkInputs & inputs,
double & trueEnergy )

Definition at line 383 of file DNNCaloSimSvc.cxx.

384{
385 Amg::Vector3D particle_position = isfp.position();
386 Amg::Vector3D particle_direction(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z());
387
388
389 TFCSTruthState truth(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z(),sqrt(isfp.momentum().mag2()+pow(isfp.mass(),2)),isfp.pdgCode());
390 truth.set_vertex(particle_position[Amg::x], particle_position[Amg::y], particle_position[Amg::z]);
391
392 trueEnergy = isfp.ekin();
393
394
395 TFCSExtrapolationState extrapol;
396 //FIXME this is extrapolating to many layers, when we only need middle layer middle surface
397 //FIXME could have dedicated extrapolation to save time
398 m_FastCaloSimCaloExtrapolation->extrapolate(extrapol,&truth);
399 // extrapol.Print();
400
401
402 if (false)
403 {
404 for (int isam=0; isam< CaloCell_ID_FCS::MaxSample ; isam++){
405 //enum SUBPOS { SUBPOS_MID = 0, SUBPOS_ENT = 1, SUBPOS_EXT = 2}; //MID=middle, ENT=entrance, EXT=exit of cal layer
406
407 for (int isubpos=0; isubpos< 3 ; isubpos++){
408
409 ATH_MSG_VERBOSE("EXTRAPO isam=" << isam <<
410 " isubpos=" << isubpos <<
411 " OK=" << extrapol.OK(isam,isubpos) <<
412 " eta=" << extrapol.eta(isam,isubpos) <<
413 " phi=" << extrapol.phi(isam,isubpos) <<
414 " r=" << extrapol.r(isam,isubpos) );
415
416 }
417 }
418 }
419
420 //FIXME deal with endcap as well
421 int isam=CaloCell_ID_FCS::EMB2;
422 int isubpos=SUBPOS_ENT;
423 double etaExtrap=-999.;
424 double phiExtrap=-999.;
425 if (extrapol.eta(isam,isubpos)) {
426 etaExtrap=extrapol.eta(isam,isubpos);
427 phiExtrap=extrapol.phi(isam,isubpos);
428 }
429
430 ATH_MSG_VERBOSE("Will use isam=" << isam <<
431 " isubpos=" << isubpos <<
432 " eta=" << etaExtrap <<
433 " phi=" << phiExtrap );
434
435
436
437 // fill vector of cells, and DDE of middle cell
438 const CaloDetDescrElement * impactCellDDE;
439 if (fillWindowCells(etaExtrap,phiExtrap,impactCellDDE).isFailure()){
440 ATH_MSG_WARNING("Could not build window cells vector ");
441 return StatusCode::FAILURE;
442 }
443
444
445 // start neural network part
446 // fill a map of input nodes
447 // this is for GAN
448 // most likely it should be specialised as a function of m_ParamsInputArchitecture
449
450 double randGaussz = 0.;
451
452
453 int impactEtaIndex = m_emID->eta(impactCellDDE->identify());
454 int impactPhiIndex = m_emID->phi(impactCellDDE->identify());
455 double etaRawImpactCell=impactCellDDE->eta_raw();
456 double phiRawImpactCell=impactCellDDE->phi_raw();
457
458 ATH_MSG_VERBOSE("impact eta_index " << impactEtaIndex
459 << " phi_index " << impactPhiIndex
460 << " sampling " << m_emID->sampling(impactCellDDE->identify()));
461
462 int pconf = impactPhiIndex % 4 ;
463 int econf = (impactEtaIndex + 1) % 2 ; // ofset corresponds to difference in index calculated for neural net preprocessing
464
465 double riImpactEta = (etaExtrap - etaRawImpactCell);
466 // mirror for left half
467 if (etaExtrap < 0){
468 riImpactEta *= -1.;
469
470 }
471 // scale & centre
472 riImpactEta = (riImpactEta - m_riImpactEtaMean)/m_riImpactEtaScale;
473 double riImpactPhi = (CaloPhiRange::diff(phiExtrap, phiRawImpactCell) - m_riImpactPhiMean)/m_riImpactPhiScale;
474
475
476 // fill randomize latent space
477 TFCSSimulationState simulstate(m_randomEngine);
478
479 //FIXME generate in one go
480 for (int i = 0; i< m_GANLatentSize; i ++)
481 {
482 randGaussz = CLHEP::RandGaussZiggurat::shoot(simulstate.randomEngine(), 0., 1.);
483 inputs["Z"].insert ( std::pair<std::string,double>(std::to_string(i), randGaussz) );
484
485 }
486
487 // fill preprocessed true energy
488 inputs["E_true"].insert ( std::pair<std::string,double>("0", (std::log(trueEnergy) - m_logTrueEnergyMean)/m_logTrueEnergyScale) );
489 // fill p,e configurations multi-hot vector
490 for (int i = 0; i< 4; i ++)
491 {
492 if (i == pconf){
493 inputs["pconfig"].insert ( std::pair<std::string,double>(std::to_string(i),1.) );
494 }
495 else{
496 inputs["pconfig"].insert ( std::pair<std::string,double>(std::to_string(i),0.) );
497 }
498 }
499 for (int i = 0; i< 2; i ++){
500 if (i == econf){
501 inputs["econfig"].insert ( std::pair<std::string,double>(std::to_string(i),1.) );
502 }
503 else{
504 inputs["econfig"].insert ( std::pair<std::string,double>(std::to_string(i),0.) );
505 }
506 }
507 // fill position of extrap particle in impact cell
508 inputs["ripos"].insert ( std::pair<std::string,double>("0", riImpactEta) );
509 inputs["ripos"].insert ( std::pair<std::string,double>("1", riImpactPhi ) );
510
511 return StatusCode::SUCCESS;
512}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
constexpr int pow(int base, int exp) noexcept
Identifier identify() const override final
cell identifier
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
StatusCode fillWindowCells(const double etaExtrap, const double phiExtrap, const CaloDetDescrElement *&impactCellDDE)
const LArEM_ID * m_emID
double ekin() const
Kinetic energy.
const Amg::Vector3D & momentum() const
The current momentum vector of the ISFParticle.
const Amg::Vector3D & position() const
The current position of the ISFParticle.
int pdgCode() const
PDG value.
double mass() const
mass of the particle
Eigen::Matrix< double, 3, 1 > Vector3D

◆ fillWindowCells()

StatusCode ISF::DNNCaloSimSvc::fillWindowCells ( const double etaExtrap,
const double phiExtrap,
const CaloDetDescrElement *& impactCellDDE )

Definition at line 515 of file DNNCaloSimSvc.cxx.

515 {
516
517 //now find the cell it corresponds to
518 //FIXME this is barrel should also look in endcap
519 // (note that is really looking up eta, phi, not raw eta phi
520 impactCellDDE=m_caloDetDescrManager->get_element(CaloCell_ID::EMB2,etaExtrap,phiExtrap);
521 if (impactCellDDE==nullptr){
522 ATH_MSG_WARNING("No cell found for this eta " << etaExtrap << " phi " << phiExtrap);
523 return StatusCode::FAILURE;
524 }
525
526
527
528
529 const int caloHashImpactCell=impactCellDDE->calo_hash();
530 const double etaImpactCell=impactCellDDE->eta();
531 const double phiImpactCell=impactCellDDE->phi();
532 const double etaRawImpactCell=impactCellDDE->eta_raw();
533 const double phiRawImpactCell=impactCellDDE->phi_raw();
534
535
536 ATH_MSG_VERBOSE("impact cell calohash=" << caloHashImpactCell <<
537 " eta=" << etaImpactCell <<
538 " phi=" << phiImpactCell <<
539 " eta raw=" << etaRawImpactCell <<
540 " phi raw=" << phiRawImpactCell );
541
542
543 int nSqCuts = 0;
544
545
546 // select the cells DNN will simulate
547 // note that m_theCellContainer has all the calorimeter cells
548 // this will hold the list of cells to simulate
549 //FIXME this can be sped up certainly
550 m_windowCells.clear();
552 float eta_raw;
553 float phi_raw;
554 for(CaloCell* theCell : * m_theContainer) {
555 sampling = theCell->caloDDE()->getSampling();
556 eta_raw = theCell->caloDDE()->eta_raw();
557 phi_raw = theCell->caloDDE()->phi_raw();
558 if (( eta_raw < etaRawImpactCell + m_etaRawBackCut) && (eta_raw > etaRawImpactCell - m_etaRawBackCut)) {
559 if ((CaloPhiRange::diff(phi_raw, phiRawImpactCell) < m_phiRawStripCut ) && (CaloPhiRange::diff(phi_raw, phiRawImpactCell) > - m_phiRawStripCut) ) {
560
561 }
562 else{
563 continue;
564 }
565 }
566 else{
567 continue;
568 }
569
570 if ((sampling == 0) || (sampling == 1) ){
571 if ((eta_raw < etaRawImpactCell + m_etaRawMiddleCut) && (eta_raw > etaRawImpactCell - m_etaRawMiddleCut)) {
572 nSqCuts ++;
573 // add to vector
574 m_windowCells.push_back(theCell);
575
576 }
577 }
578 else if(sampling == 2) {
579 if ((CaloPhiRange::diff(phi_raw , phiRawImpactCell) < m_phiRawMiddleCut) && (CaloPhiRange::diff(phi_raw, phiRawImpactCell) > - m_phiRawMiddleCut)) {
580 if ((eta_raw < etaRawImpactCell + m_etaRawMiddleCut) && (eta_raw > etaRawImpactCell - m_etaRawMiddleCut)) {
581 nSqCuts ++;
582 m_windowCells.push_back(theCell);
583 }
584 }
585 }
586
587 else if(sampling == 3){
588 if ((CaloPhiRange::diff(phi_raw, phiRawImpactCell) < m_phiRawMiddleCut) && (CaloPhiRange::diff(phi_raw , phiRawImpactCell) > - m_phiRawMiddleCut )) {
589 nSqCuts ++;
590 m_windowCells.push_back(theCell);
591 }
592
593 }
594 }
595
596 if (nSqCuts != m_numberOfCellsForDNN){
597 ATH_MSG_WARNING("Total cells passing DNN selection is " << nSqCuts << " but should be " << m_numberOfCellsForDNN );
598 // bail out, but do not stop the job
599 return StatusCode::FAILURE;
600
601 }
602
603 //sort cells within the cluster like they are fed to DNN
604 if (etaRawImpactCell < 0){
606 }
607 else{
609 }
610
611 return StatusCode::SUCCESS;
612
613}
bool compCellsForDNNSortMirror(const CaloCell *a, const CaloCell *b)
bool compCellsForDNNSort(const CaloCell *a, const CaloCell *b)
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
std::vector< CaloCell * > m_windowCells
const double m_phiRawMiddleCut
const int m_numberOfCellsForDNN
const double m_phiRawStripCut
const double m_etaRawBackCut
const double m_etaRawMiddleCut
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ finalize()

StatusCode ISF::DNNCaloSimSvc::finalize ( )
finaloverridevirtual

framework methods

Definition at line 187 of file DNNCaloSimSvc.cxx.

188{
189 ATH_MSG_INFO(m_screenOutputPrefix << "Finalizing ...");
190 return StatusCode::SUCCESS;
191}
#define ATH_MSG_INFO(x)
Gaudi::Property< std::string > m_screenOutputPrefix
Screen output refinement.

◆ initialize()

StatusCode ISF::DNNCaloSimSvc::initialize ( )
finaloverridevirtual

Athena algorithm's interface methods.

framework methods

Definition at line 79 of file DNNCaloSimSvc.cxx.

80{
81
82 ATH_MSG_INFO(m_screenOutputPrefix << "Initializing ...");
83
84 ATH_CHECK(m_rndGenSvc.retrieve());
86 if (!m_randomEngine)
87 {
88 ATH_MSG_ERROR("Could not get random number engine from RandomNumberService. Abort.");
89 return StatusCode::FAILURE;
90 }
91
92 m_caloDetDescrManager = detStore()->tryConstRetrieve<CaloDetDescrManager>(caloMgrStaticKey);
94 std::unique_ptr<CaloDetDescrManager> caloMgrPtr = buildCaloDetDescrNoAlign(serviceLocator()
96 ATH_CHECK(detStore()->record(std::move(caloMgrPtr), caloMgrStaticKey));
99 ATH_MSG_ERROR ("Failed to build CaloDetDescrManager.");
100 return StatusCode::FAILURE;
101 }
102 }
103 const FCALDetectorManager * fcalManager=nullptr;
104 ATH_CHECK(detStore()->retrieve(fcalManager));
105
106 const CaloIdManager* caloId_mgr = m_caloDetDescrManager->getCalo_Mgr();
107 m_emID = caloId_mgr->getEM_ID();
108
109 m_caloGeo = std::make_unique<CaloGeometryFromCaloDDM>();
110 m_caloGeo->LoadGeometryFromCaloDDM(m_caloDetDescrManager);
111 if(!m_caloGeo->LoadFCalChannelMapFromFCalDDM(fcalManager) )ATH_MSG_FATAL("Found inconsistency between FCal_Channel map and GEO file. Please, check if they are configured properly.");
112
113
114 // initialize DNN
115 if (initializeNetwork().isFailure())
116 {
117 ATH_MSG_ERROR("Could not initialize network ");
118 return StatusCode::FAILURE;
119
120 }
121
122
123 // Get FastCaloSimCaloExtrapolation
124 if(m_FastCaloSimCaloExtrapolation.retrieve().isFailure())
125 {
126 ATH_MSG_ERROR("FastCaloSimCaloExtrapolation not found ");
127 return StatusCode::FAILURE;
128 }
129
131
132
133
134 return StatusCode::SUCCESS;
135}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
std::unique_ptr< CaloDetDescrManager > buildCaloDetDescrNoAlign(ISvcLocator *svcLocator, IMessageSvc *msgSvc)
static constexpr const char * caloMgrStaticKey
const LArEM_ID * getEM_ID(void) const
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
StatusCode initializeNetwork()
helper for initialize
IMessageSvc * getMessageSvc(bool quiet=false)
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ initializeNetwork()

StatusCode ISF::DNNCaloSimSvc::initializeNetwork ( )

helper for initialize

Definition at line 138 of file DNNCaloSimSvc.cxx.

139{
140
141
142
143 // get neural net JSON file as an std::istream object
145 if (inputFile.empty()){
146 ATH_MSG_ERROR("Could not find json file " << m_paramsFilename );
147 return StatusCode::FAILURE;
148 }
149
150
151
152 ATH_MSG_INFO("Using json file " << inputFile );
153 std::ifstream input(inputFile);
154 // build the graph
155 m_graph=std::make_unique<lwt::LightweightGraph>(lwt::parse_json_graph(input) );
156 if (m_graph==nullptr){
157 ATH_MSG_ERROR("Could not create LightWeightGraph from " << m_paramsFilename );
158 return StatusCode::FAILURE;
159 }
160
161
162
163 // initialize all necessary constants
164 // FIXME eventually all these could be stored in the .json file
165
166 ATH_MSG_INFO("Using ParamsInputArchitecture: " << m_paramsInputArchitecture );
167 if (m_paramsInputArchitecture=="GANv0") // GAN then VAE etc...
168 {
169 m_GANLatentSize = 300;
170 m_logTrueEnergyMean = 9.70406053;
171 m_logTrueEnergyScale = 1.76099569;
172 m_riImpactEtaMean = 3.47603256e-05;
173 m_riImpactEtaScale = 0.00722316;
174 m_riImpactPhiMean = -5.42153684e-05;
175 m_riImpactPhiScale = 0.00708241;
176 }
177
178 if (m_GANLatentSize==0){
179 ATH_MSG_ERROR("m_GANLatentSize uninitialized!.ParamsInputArchitecture= " << m_paramsInputArchitecture );
180 return StatusCode::FAILURE;
181 }
182
183 return StatusCode::SUCCESS;
184}
std::string PathResolverFindCalibFile(const std::string &logical_file_name)

◆ recordCollection()

template<class T>
StatusCode ISF::BaseSimulationSvc::recordCollection ( T *& coll,
const std::string & collName ) const
inlineinherited

templated record collection method, will create a new one if not existing

Definition at line 151 of file BaseSimulationSvc.h.

151 {
152 // create if necessary
153 coll = coll ? coll : new T;
154 // record
155 if (evtStore()->record( coll, collName).isFailure()){
156 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot record collection " << collName << ". Abort." );
157 return StatusCode::FAILURE;
158 } else
159 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully recorded collection " << collName);
160 return StatusCode::SUCCESS;
161 }
#define ATH_MSG_DEBUG(x)
const ServiceHandle< StoreGateSvc > & evtStore() const
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
unsigned long long T

◆ releaseEvent()

StatusCode ISF::DNNCaloSimSvc::releaseEvent ( )
finaloverridevirtual

Release Event chain - in case of an end-of event action is needed.

Reimplemented from ISF::BaseSimulationSvc.

Definition at line 258 of file DNNCaloSimSvc.cxx.

259{
260 const EventContext& ctx = Gaudi::Hive::currentContext();
261 ATH_MSG_VERBOSE(m_screenOutputPrefix << "release Event");
262
264
265 //run release tools in a loop
266 ToolHandleArray<ICaloCellMakerTool>::iterator itrTool = m_caloCellMakerToolsRelease.begin();
267 ToolHandleArray<ICaloCellMakerTool>::iterator endTool = m_caloCellMakerToolsRelease.end();
268 for (; itrTool != endTool; ++itrTool)
269 {
270 ATH_MSG_VERBOSE( m_screenOutputPrefix << "Calling tool " << itrTool->name() );
271
272 StatusCode sc = (*itrTool)->process(m_theContainer, ctx);
273
274 if (sc.isFailure())
275 {
276 ATH_MSG_ERROR( m_screenOutputPrefix << "Error executing tool " << itrTool->name() );
277 }
278 }
279
280 return StatusCode::SUCCESS;
281
282}
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ retrieveCollection()

template<class T>
StatusCode ISF::BaseSimulationSvc::retrieveCollection ( T *& coll,
const std::string & collName,
bool forceBreak = true ) const
inlineinherited

templated retrieve collection method, boolean steers that force break

Definition at line 165 of file BaseSimulationSvc.h.

165 {
166 // check for existence in the soft case
167 if (!forceBreak && !evtStore()->contains<T>(collName)) {
168 coll = 0;
169 ATH_MSG_DEBUG(m_screenOutputPrefix << "Collection does not exists (not required). Ignore.");
170 return StatusCode::SUCCESS;
171 }
172 if ( evtStore()->retrieve(coll, collName).isFailure()){
173 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retireve collection " << collName << ". Abort." );
174 return StatusCode::FAILURE;
175 } else
176 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved collection " << collName);
177 return StatusCode::SUCCESS;
178 }
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114

◆ retrieveTool()

template<class T>
StatusCode ISF::BaseSimulationSvc::retrieveTool ( ToolHandle< T > & thandle)
inlineinherited

templated Tool retrieval - gives unique handling & look and feel

Definition at line 129 of file BaseSimulationSvc.h.

129 {
130 if (!thandle.empty() && thandle.retrieve().isFailure()){
131 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retrieve " << thandle << ". Abort.");
132 return StatusCode::FAILURE;
133 } else
134 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved " << thandle);
135 return StatusCode::SUCCESS;
136 }

◆ retrieveTools()

template<class T>
StatusCode ISF::BaseSimulationSvc::retrieveTools ( ToolHandleArray< T > & thandleArray)
inlineinherited

templated Tool retrieval - gives unique handling & look and feel

Definition at line 140 of file BaseSimulationSvc.h.

140 {
141 if (!thandleArray.empty() && thandleArray.retrieve().isFailure()){
142 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retrieve " << thandleArray << ". Abort.");
143 return StatusCode::FAILURE;
144 } else
145 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved " << thandleArray);
146 return StatusCode::SUCCESS;
147 }

◆ setParticleBroker()

virtual StatusCode ISF::BaseSimulationSvc::setParticleBroker ( IParticleBroker * broker)
inlineoverridevirtualinherited

Inform the SimulationSvc about the ParticleBroker svc.

Definition at line 78 of file BaseSimulationSvc.h.

78 {
79 m_particleBroker = broker;
80 return StatusCode::SUCCESS;
81 }
IParticleBroker * m_particleBroker
The particle service used to push particles into the simulation.

◆ setupEvent()

StatusCode ISF::DNNCaloSimSvc::setupEvent ( )
finaloverridevirtual

Setup Event chain - in case of a begin-of event action is needed.

Reimplemented from ISF::BaseSimulationSvc.

Definition at line 193 of file DNNCaloSimSvc.cxx.

194{
195 const EventContext& ctx = Gaudi::Hive::currentContext();
196 ATH_MSG_INFO(m_screenOutputPrefix << "setupEvent NEW EVENT! ");
197
198 m_theContainer = new CaloCellContainer(SG::VIEW_ELEMENTS);
199
201 if (sc.isFailure())
202 {
203 ATH_MSG_FATAL( m_screenOutputPrefix << "cannot record CaloCellContainer " << m_caloCellsOutputName );
204 return StatusCode::FAILURE;
205 }
206
207 //FIXME why retrieve every event ?
208 CHECK( m_caloCellMakerToolsSetup.retrieve() );
209 ATH_MSG_DEBUG( "Successfully retrieve CaloCellMakerTools: " << m_caloCellMakerToolsSetup );
210 ToolHandleArray<ICaloCellMakerTool>::iterator itrTool = m_caloCellMakerToolsSetup.begin();
211 ToolHandleArray<ICaloCellMakerTool>::iterator endTool = m_caloCellMakerToolsSetup.end();
212 for (; itrTool != endTool; ++itrTool)
213 {
214 std::string chronoName=this->name()+"_"+ itrTool->name();
215 if (m_chrono) m_chrono->chronoStart(chronoName);
216 StatusCode sc = (*itrTool)->process(m_theContainer, ctx);
217 if (m_chrono) {
218 m_chrono->chronoStop(chronoName);
219 ATH_MSG_DEBUG( m_screenOutputPrefix << "Chrono stop : delta " << m_chrono->chronoDelta (chronoName,IChronoStatSvc::USER) * CLHEP::microsecond / CLHEP::second << " second " );
220 }
221
222 if (sc.isFailure())
223 {
224 ATH_MSG_ERROR( m_screenOutputPrefix << "Error executing tool " << itrTool->name() );
225 return StatusCode::FAILURE;
226 }
227 }
228
229
230 // FIXME just for debugging
231 // exercise window building
232 // should be false by default
233 // careful:if enabled change the random number sequence !
234 if (false){
235 TFCSSimulationState testsimulstate(m_randomEngine);
236 const CaloDetDescrElement * testImpactCellDDE;
237 const int ntrial=100;
238 ATH_MSG_INFO ("Trial window building on " << ntrial << " dummy eta phi " );
239 for (int i=0 ; i< ntrial ; i++){
240 const double eta = CLHEP::RandFlat::shoot(testsimulstate.randomEngine(), 0.2, 0.25);
241 const double phi = CLHEP::RandFlat::shoot(testsimulstate.randomEngine(), -CLHEP::pi , CLHEP::pi);
242
243 //randomise eta, phi
244 if (fillWindowCells(eta,phi,testImpactCellDDE).isFailure()){
245 ATH_MSG_WARNING("Could not build trial window cells vector with eta " << eta << " phi " << phi);
246 }
247 }
248 ATH_MSG_INFO ("End of trial window building on " << ntrial << " dummy eta phi " );
249
250 }
251
252
253
254
255 return StatusCode::SUCCESS;
256}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts

◆ simSvcDescriptor()

const std::string & ISF::BaseSimulationSvc::simSvcDescriptor ( )
inlineoverrideinherited

Return the simulation service descriptor.

Definition at line 67 of file BaseSimulationSvc.h.

67{ return m_simDescr.value(); }
Gaudi::Property< std::string > m_simDescr
The simulator service descriptor.

◆ simulate()

StatusCode ISF::DNNCaloSimSvc::simulate ( ISF::ISFParticle & isfp,
McEventCollection *  )
finaloverridevirtual

Simulation Call.

Reimplemented from ISF::BaseSimulationSvc.

Definition at line 332 of file DNNCaloSimSvc.cxx.

333{
334
335 ATH_MSG_VERBOSE("NEW PARTICLE! DNNCaloSimSvc called with ISFParticle: " << isfp);
336
337
338 //Don't simulate particles with total energy below 10 MeV
339 if(isfp.ekin() < 10) {
340 ATH_MSG_VERBOSE("Skipping particle with Ekin: " << isfp.ekin() <<" MeV. Below the 10 MeV threshold.");
341 return StatusCode::SUCCESS;
342 }
343
344
345 //Compute all inputs to the network
347 double trueEnergy;
348 if (fillNetworkInputs(isfp,inputs,trueEnergy).isFailure()) {
349 ATH_MSG_WARNING("Could not initialize network ");
350 // bail out but do not stop the job
351 return StatusCode::SUCCESS;
352 }
353
354
355 // compute the network output values
356 ATH_MSG_VERBOSE("neural network input = "<<inputs);
357 NetworkOutputs outputs = m_graph->compute(inputs);
358 ATH_MSG_VERBOSE("neural network output = "<<outputs);
359
360
361 // add network output energy in the right place in the calorimeter
362 int itr = 0;
363 for ( auto & windowCell : m_windowCells) {
364 windowCell->addEnergy(trueEnergy * outputs[std::to_string(itr)]);
365 itr++;
366
367 ATH_MSG_VERBOSE(" cell eta_raw " << windowCell->caloDDE()->eta_raw()
368 << " phi_raw " << windowCell->caloDDE()->phi_raw()
369 << " sampling " << windowCell->caloDDE()->getSampling()
370 << " energy " << windowCell->energy());
371 }
372
373
374
375
376
377 return StatusCode::SUCCESS;
378}
StatusCode fillNetworkInputs(const ISF::ISFParticle &isfp, NetworkInputs &inputs, double &trueEnergy)
std::map< std::string, std::map< std::string, double > > NetworkInputs
std::map< std::string, double > NetworkOutputs

◆ simulateVector()

virtual StatusCode ISF::BaseSimulationSvc::simulateVector ( const ISFParticleVector & particles,
McEventCollection * mcEventCollection,
McEventCollection *  )
inlineoverridevirtualinherited

Simulation call for vectors of particles.

Reimplemented in ISF::BaseSimulationG4Svc.

Definition at line 84 of file BaseSimulationSvc.h.

84 {
85 // this implementation is a wrapper in case the simulator does
86 // implement particle-vector input
87 StatusCode sc = StatusCode::SUCCESS;
88 // simulate each particle individually
89 for (ISF::ISFParticle* part : particles) {
90 ATH_MSG_VERBOSE( m_screenOutputPrefix << "Starting simulation of particle: " << part );
91 if ( this->simulate(*part, mcEventCollection).isFailure()) {
92 ATH_MSG_WARNING("Simulation of particle failed!" << endmsg <<
93 " -> simulator: " << this->simSvcDescriptor() <<
94 " -> particle : " << *part );
95 sc = StatusCode::FAILURE;
96 }
97 }
98 return sc;
99 }
#define endmsg
virtual StatusCode simulate(ISFParticle &isp, McEventCollection *mcEventCollection) override
Simulation call for individual particles.
const std::string & simSvcDescriptor() override
Return the simulation service descriptor.

◆ sysInitialize()

virtual StatusCode ISF::BaseSimulationSvc::sysInitialize ( )
inlineoverridevirtualinherited

Gaudi sysInitialize() methods.

Definition at line 52 of file BaseSimulationSvc.h.

53 {
54 if ( AthService::sysInitialize().isFailure() ) {
55 ATH_MSG_FATAL( m_screenOutputPrefix << " Cannot initialize AthService! Abort.");
56 return StatusCode::FAILURE;
57 }
58 if ( m_chrono.retrieve().isFailure()){
59 ATH_MSG_FATAL( m_screenOutputPrefix << " Cannot retrieve ChronoStatSvc! Abort.");
60 return StatusCode::FAILURE;
61 }
62
63 return StatusCode::SUCCESS;
64 }

Member Data Documentation

◆ m_caloCellMakerToolsRelease

ToolHandleArray<ICaloCellMakerTool> ISF::DNNCaloSimSvc::m_caloCellMakerToolsRelease

Definition at line 92 of file DNNCaloSimSvc.h.

◆ m_caloCellMakerToolsSetup

ToolHandleArray<ICaloCellMakerTool> ISF::DNNCaloSimSvc::m_caloCellMakerToolsSetup

Definition at line 91 of file DNNCaloSimSvc.h.

◆ m_caloCellsOutputName

std::string ISF::DNNCaloSimSvc::m_caloCellsOutputName

Definition at line 129 of file DNNCaloSimSvc.h.

◆ m_caloDetDescrManager

const CaloDetDescrManager* ISF::DNNCaloSimSvc::m_caloDetDescrManager

Definition at line 104 of file DNNCaloSimSvc.h.

◆ m_caloGeo

std::unique_ptr<CaloGeometryFromCaloDDM> ISF::DNNCaloSimSvc::m_caloGeo

Definition at line 105 of file DNNCaloSimSvc.h.

◆ m_chrono

ServiceHandle<IChronoStatSvc> ISF::BaseSimulationSvc::m_chrono {this, "ChronoStatService", "ChronoStatSvc"}
protectedinherited

The timing service for general usage.

Definition at line 203 of file BaseSimulationSvc.h.

203{this, "ChronoStatService", "ChronoStatSvc"};

◆ m_detStore

ServiceHandle<StoreGateSvc> ISF::BaseSimulationSvc::m_detStore
privateinherited
Initial value:
{this, "DetStore", "StoreGateSvc/DetectorStore",
"Handle to a StoreGateSvc/DetectorStore instance: it will be used to retrieve data during the course of the job"}

Handle to StoreGate (detector store by default)

Definition at line 189 of file BaseSimulationSvc.h.

189 {this, "DetStore", "StoreGateSvc/DetectorStore",
190 "Handle to a StoreGateSvc/DetectorStore instance: it will be used to retrieve data during the course of the job"};

◆ m_emID

const LArEM_ID* ISF::DNNCaloSimSvc::m_emID = nullptr

Definition at line 106 of file DNNCaloSimSvc.h.

◆ m_etaRawBackCut

const double ISF::DNNCaloSimSvc::m_etaRawBackCut = m_middleCellWidthEta * 4.

Definition at line 124 of file DNNCaloSimSvc.h.

◆ m_etaRawMiddleCut

const double ISF::DNNCaloSimSvc::m_etaRawMiddleCut = m_middleCellWidthEta * 3.5

Definition at line 123 of file DNNCaloSimSvc.h.

◆ m_evtStore

ServiceHandle<StoreGateSvc> ISF::BaseSimulationSvc::m_evtStore
privateinherited
Initial value:
{this, "EvtStore", "StoreGateSvc/StoreGateSvc",
"Handle to a StoreGateSvc instance: it will be used to retrieve data during the course of the job"}

Handle to StoreGate (event store by default)

Definition at line 185 of file BaseSimulationSvc.h.

185 {this, "EvtStore", "StoreGateSvc/StoreGateSvc",
186 "Handle to a StoreGateSvc instance: it will be used to retrieve data during the course of the job"};

◆ m_extrapolator

ToolHandle<Trk::ITimedExtrapolator> ISF::DNNCaloSimSvc::m_extrapolator

Definition at line 95 of file DNNCaloSimSvc.h.

◆ m_FastCaloSimCaloExtrapolation

ToolHandle<IFastCaloSimCaloExtrapolation> ISF::DNNCaloSimSvc::m_FastCaloSimCaloExtrapolation

Definition at line 94 of file DNNCaloSimSvc.h.

◆ m_GANLatentSize

int ISF::DNNCaloSimSvc::m_GANLatentSize = 0

Definition at line 111 of file DNNCaloSimSvc.h.

◆ m_graph

std::unique_ptr<lwt::LightweightGraph> ISF::DNNCaloSimSvc::m_graph

Definition at line 89 of file DNNCaloSimSvc.h.

◆ m_logTrueEnergyMean

double ISF::DNNCaloSimSvc::m_logTrueEnergyMean = 0.

Definition at line 112 of file DNNCaloSimSvc.h.

◆ m_logTrueEnergyScale

double ISF::DNNCaloSimSvc::m_logTrueEnergyScale = 0.

Definition at line 113 of file DNNCaloSimSvc.h.

◆ m_middleCellWidthEta

const double ISF::DNNCaloSimSvc::m_middleCellWidthEta = 0.025

Definition at line 121 of file DNNCaloSimSvc.h.

◆ m_middleCellWidthPhi

const double ISF::DNNCaloSimSvc::m_middleCellWidthPhi = CLHEP::pi / std::pow(2,7)

Definition at line 122 of file DNNCaloSimSvc.h.

◆ m_numberOfCellsForDNN

const int ISF::DNNCaloSimSvc::m_numberOfCellsForDNN = 266

Definition at line 120 of file DNNCaloSimSvc.h.

◆ m_paramsFilename

std::string ISF::DNNCaloSimSvc::m_paramsFilename

Definition at line 86 of file DNNCaloSimSvc.h.

◆ m_paramsInputArchitecture

std::string ISF::DNNCaloSimSvc::m_paramsInputArchitecture

Definition at line 87 of file DNNCaloSimSvc.h.

◆ m_particleBroker

IParticleBroker* ISF::BaseSimulationSvc::m_particleBroker {}
protectedinherited

The particle service used to push particles into the simulation.

Definition at line 206 of file BaseSimulationSvc.h.

206{};

◆ m_phiRawMiddleCut

const double ISF::DNNCaloSimSvc::m_phiRawMiddleCut = m_middleCellWidthPhi * 3.5

Definition at line 125 of file DNNCaloSimSvc.h.

◆ m_phiRawStripCut

const double ISF::DNNCaloSimSvc::m_phiRawStripCut = m_middleCellWidthPhi * 6.0

Definition at line 126 of file DNNCaloSimSvc.h.

◆ m_randomEngine

CLHEP::HepRandomEngine* ISF::DNNCaloSimSvc::m_randomEngine

Definition at line 100 of file DNNCaloSimSvc.h.

◆ m_randomEngineName

std::string ISF::DNNCaloSimSvc::m_randomEngineName

Definition at line 101 of file DNNCaloSimSvc.h.

◆ m_riImpactEtaMean

double ISF::DNNCaloSimSvc::m_riImpactEtaMean = 0.

Definition at line 114 of file DNNCaloSimSvc.h.

◆ m_riImpactEtaScale

double ISF::DNNCaloSimSvc::m_riImpactEtaScale = 0.

Definition at line 115 of file DNNCaloSimSvc.h.

◆ m_riImpactPhiMean

double ISF::DNNCaloSimSvc::m_riImpactPhiMean = 0.

Definition at line 116 of file DNNCaloSimSvc.h.

◆ m_riImpactPhiScale

double ISF::DNNCaloSimSvc::m_riImpactPhiScale = 0.

Definition at line 117 of file DNNCaloSimSvc.h.

◆ m_rndGenSvc

ServiceHandle<IAtRndmGenSvc> ISF::DNNCaloSimSvc::m_rndGenSvc

Definition at line 99 of file DNNCaloSimSvc.h.

◆ m_screenOutputPrefix

Gaudi::Property<std::string> ISF::BaseSimulationSvc::m_screenOutputPrefix
protectedinherited
Initial value:
{this, "ScreenOutputPrefix", "isf >> ",
"Prefix for log output"}

Screen output refinement.

Definition at line 199 of file BaseSimulationSvc.h.

199 {this, "ScreenOutputPrefix", "isf >> ",
200 "Prefix for log output"};

◆ m_simDescr

Gaudi::Property<std::string> ISF::BaseSimulationSvc::m_simDescr
protectedinherited
Initial value:
{this, "Identifier", {},
"A unique string to identify the simulator."}

The simulator service descriptor.

Definition at line 195 of file BaseSimulationSvc.h.

195 {this, "Identifier", {},
196 "A unique string to identify the simulator."};

◆ m_theContainer

CaloCellContainer* ISF::DNNCaloSimSvc::m_theContainer

Definition at line 97 of file DNNCaloSimSvc.h.

◆ m_windowCells

std::vector<CaloCell*> ISF::DNNCaloSimSvc::m_windowCells

Definition at line 107 of file DNNCaloSimSvc.h.


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