ATLAS Offline Software
Loading...
Searching...
No Matches
RegionCreator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Base class
7
8// Geant4 includes used in functions
9
10#include "G4LogicalVolume.hh"
11#include "G4LogicalVolumeStore.hh"
12#include "G4Region.hh"
13#include "G4ProductionCuts.hh"
14
15RegionCreator::RegionCreator(const std::string& type, const std::string& name, const IInterface* parent)
16 : base_class(type,name,parent)
17{
18}
19
20// Athena method, called at initialization time
22{
23 ATH_MSG_VERBOSE(" initializing RegionCreator "<<name() );
24 if (m_regionName.empty()) {
25 m_regionName = this->name();
26 // re-initialize m_regionName in order to take the real tool name rather than the path to it
27 size_t ipos=m_regionName.value().find_last_of('.');
28 size_t length=m_regionName.value().size();
29 if (ipos<length) {
30 ATH_MSG_VERBOSE( "m_regionName: " << m_regionName.value() << " needs to be reset.");
31 m_regionName=m_regionName.value().substr(ipos+1,length-ipos-1);
32 }
33 ATH_MSG_VERBOSE( "m_regionName default value reset to "<<m_regionName.value());
34 }
35 return StatusCode::SUCCESS;
36}
37
39{
40 //create a new G4Region
41 G4Region* theRegion=new G4Region(m_regionName.value());
42
43 // loop over volumes and fish for those in the list
44 size_t nVolumes{0};
45 G4LogicalVolumeStore* logStore=G4LogicalVolumeStore::GetInstance();
46 for (const auto& vol: m_logicalVolumes) {
47 size_t nVolumesCurrent{0};
48 for (auto* it: *logStore)
49 {
50
51 if (vol == static_cast<const std::string&>(it->GetName()))
52 {
53 nVolumesCurrent++;
54 it->SetRegion(theRegion);
55 theRegion->AddRootLogicalVolume(it);
56 }
57 }
58 if (nVolumesCurrent==0) {
59 ATH_MSG_WARNING("No volumes matching \"" << vol << "\" found in G4 LogicalVolumeStore. " << m_regionName.value() << " G4PhysicsRegion may not behave as intended.");
60 }
61 nVolumes += nVolumesCurrent;
62 }
63
64 if (m_dumpRegion) { ATH_MSG_INFO("A total of "<<nVolumes<<" volumes was assigned to region "<<m_regionName.value() ); }
65
66 // create a G4ProductionCuts object and set appropriate values
67 G4ProductionCuts* cuts=new G4ProductionCuts();
68 cuts->SetProductionCut(m_gammaCut,"gamma");
69 cuts->SetProductionCut(m_electronCut,"e-");
70 cuts->SetProductionCut(m_positronCut,"e+");
71 cuts->SetProductionCut(m_protonCut,"proton");
72
73 // assign cuts to the region and return succesfully
74 theRegion->SetProductionCuts(cuts);
75
76 if (m_dumpRegion) { Dump(); }
77}
78
80{
81 ATH_MSG_INFO("+----------------------------------------------------+");
82 ATH_MSG_INFO(" ");
83 ATH_MSG_INFO(" Dump of region "<<m_regionName.value());
84 ATH_MSG_INFO(" Volumes being assigned to this region:");
85 for (const auto& vol: m_logicalVolumes)
86 {
87 ATH_MSG_INFO(" "<<vol);
88 }
89 ATH_MSG_INFO(" ");
90 ATH_MSG_INFO(" Cuts selected for this region:");
91 ATH_MSG_INFO(" Gamma ="<<m_gammaCut);
92 ATH_MSG_INFO(" Electron ="<<m_electronCut);
93 ATH_MSG_INFO(" Positron ="<<m_positronCut);
94 ATH_MSG_INFO(" Proton ="<<m_protonCut);
95 ATH_MSG_INFO(" ");
96 ATH_MSG_INFO("+----------------------------------------------------+");
97}
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
double length(const pvec &v)
void Construct() override
Gaudi::Property< std::string > m_regionName
Gaudi::Property< double > m_electronCut
virtual StatusCode initialize() override
Gaudi::Property< std::vector< std::string > > m_logicalVolumes
Gaudi::Property< double > m_protonCut
void Dump() override
Gaudi::Property< double > m_gammaCut
BooleanProperty m_dumpRegion
RegionCreator(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< double > m_positronCut