ATLAS Offline Software
Loading...
Searching...
No Matches
GeoDetectorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Base class
7#include "GeoDetectorTool.h"
8#include "Geo2G4Builder.h"
9#include "VolumeBuilder.h"
10
11#include "G4NistManager.hh"
12#include "G4LogicalVolume.hh"
13#include "G4PVPlacement.hh"
14#include "G4GDMLParser.hh"
15
16// Geant4 includes used in functions
17
18GeoDetectorTool::GeoDetectorTool(const std::string& type, const std::string& name, const IInterface* parent)
20{
21 m_topTransform.setIdentity();
22 ATH_MSG_DEBUG( "GeoDetectorTool constructor for " << name );
23 declareProperty("GeoDetectorName",m_geoDetectorName, "Name of the detector in GeoModel, if different from G4.");
24 declareProperty("GDMLFileOut",m_dumpGDMLFile,"File name where the GDML description for the detector will be dumped.");
25
26}
27
29{
30 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::initialize(): Starting" );
31 if(m_detectorName.empty())
32 {
33 m_detectorName = this->name();
34 // re-initialize m_detectorName in order to take the real detector name rather than the path to it
35 size_t ipos=m_detectorName.value().find_last_of('.');
36 size_t length=m_detectorName.value().size();
37 if (ipos<length)
38 {
39 ATH_MSG_VERBOSE( "m_detectorName: " << m_detectorName.value() << " needs to be reset.");
40 m_detectorName = m_detectorName.value().substr(ipos+1,length-ipos-1);
41 ATH_MSG_VERBOSE( "m_detectorName default value reset to " << m_detectorName.value());
42 }
43 }
44 ATH_MSG_DEBUG( name() << "GeoDetectorTool::initialize() : Detector name = " << m_detectorName.value() );
45 if(m_geoDetectorName.empty())
46 {
48 }
49 ATH_MSG_DEBUG( name() << "GeoDetectorTool::initialize() : Geo Detector name = " << m_geoDetectorName );
50
51 ATH_CHECK(m_geo2G4Svc.retrieve());
52 m_builderName = m_geo2G4Svc->GetDefaultBuilder()->GetKey();
53 m_blGetTopTransform = m_geo2G4Svc->UseTopTransforms();
54 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::initialize(): Finished" );
55 return StatusCode::SUCCESS;
56}
57
58
60{
61 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::BuildGeometry(): Starting" );
62 G4LogicalVolume* temp = this->Convert();
63 m_envelope.theEnvelope=temp;
64
65 if (this->IsTopTransform())
66 {
68 }
69 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::BuildGeometry(): Finished" );
70}
71
73{
74 ATH_MSG_DEBUG( name() << " GeoDetectorTool::PositionInParent(): Starting" );
75
77 if (!m_dumpGDMLFile.empty()) {
78 G4GDMLParser parser;
79 parser.Write(m_dumpGDMLFile,m_envelope.thePositionedVolume);
80 }
81}
82
83G4LogicalVolume* GeoDetectorTool::Convert()
84{
85 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::Convert(): Starting" );
86 ATH_MSG_DEBUG( name() << " GeoDetectorTool::Convert(): GeoDetectorName:builderName = "<<m_geoDetectorName<<":"<<m_builderName);
89 b->SetParam(m_blParamOn);
90 G4LogicalVolume *temp=Builder.BuildTree();
91 if(this->IsTopTransform())
92 {
94 }
95
96 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::Convert(): Finished" );
97 return temp;
98}
99
104
106{
107 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::SetInitialTransformation(): Starting" );
108 if (!m_envelope.theRotation)
109 {
110 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::SetInitialTransformation(): Creating new G4RotationMatrix" );
111 m_envelope.theRotation=new G4RotationMatrix;
112 }
113 *(m_envelope.theRotation)=m_topTransform.getRotation().inverse();
114 m_envelope.thePosition=m_topTransform.getTranslation();
115 ATH_MSG_VERBOSE( name() << " GeoDetectorTool::SetInitialTransformation(): Finished" );
116}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
double length(const pvec &v)
DetectorGeometryBase(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< std::string > m_detectorName
virtual void PositionInParent() override
Main builder to create/position all volumes described in a GeoModel Tree.
VolumeBuilder * GetVolumeBuilder(std::string)
G4LogicalVolume * BuildTree()
HepGeom::Transform3D GetDetectorTransform()
G4Transform3D m_topTransform
G4LogicalVolume * Convert()
GeoDetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
std::string m_builderName
ServiceHandle< IGeo2G4Svc > m_geo2G4Svc
virtual void BuildGeometry() override final
virtual methods being implemented here
virtual StatusCode initialize() override final
Athena method.
virtual void PositionInParent() override final
std::string m_geoDetectorName
std::string m_dumpGDMLFile