Skip to content
Snippets Groups Projects
Commit 3037838c authored by Whitney Armstrong's avatar Whitney Armstrong
Browse files

Adding geometry service

	new file:   JugBase/JugBase/IGeoSvc.h
	new file:   JugBase/src/components/GeoSvc.cpp
	new file:   JugBase/src/components/GeoSvc.h
	new file:   demo/compact/elements.xml
	new file:   demo/compact/gem_tracker_disc.xml
	new file:   demo/compact/materials.xml
	new file:   demo/test/options/demo_geosvc.py
parent 9609f20c
No related branches found
No related tags found
No related merge requests found
//
// IGeoSvc.h
//
//
// Created by Julia Hrdinka on 30/03/15.
//
//
#ifndef IGEOSVC_H
#define IGEOSVC_H
#include "GaudiKernel/IService.h"
namespace dd4hep {
class Detector;
class DetElement;
}
class G4VUserDetectorConstruction;
class GAUDI_API IGeoSvc : virtual public IService {
public:
/// InterfaceID
DeclareInterfaceID(IGeoSvc, 1, 0);
// receive DD4hep Geometry
virtual dd4hep::DetElement getDD4HepGeo() = 0;
virtual dd4hep::Detector* lcdd() = 0;
virtual dd4hep::Detector* detector() = 0;
// receive Geant4 Geometry
//virtual G4VUserDetectorConstruction* getGeant4Geo() = 0;
virtual ~IGeoSvc() {}
};
#endif // IGEOSVC_H
//
// GeoSvc.cxx
//
//
// Created by Julia Hrdinka on 30/03/15.
//
//
#include "GeoSvc.h"
#include "GaudiKernel/Service.h"
//#include "GeoConstruction.h"
#include "TGeoManager.h"
#include "DD4hep/Printout.h"
using namespace Gaudi;
DECLARE_COMPONENT(GeoSvc)
GeoSvc::GeoSvc(const std::string& name, ISvcLocator* svc)
: base_class(name, svc)
, m_incidentSvc("IncidentSvc", "GeoSvc")
, m_dd4hepgeo(0)
//, m_geant4geo(0)
, m_log(msgSvc(), name)
, m_failureFlag(false) {}
GeoSvc::~GeoSvc() {
if (m_dd4hepgeo){
try {
m_dd4hepgeo->destroyInstance();
m_dd4hepgeo = 0;
} catch(...) {}
}
}
StatusCode GeoSvc::initialize() {
StatusCode sc = Service::initialize();
if (!sc.isSuccess()) return sc;
// Turn off TGeo printouts if appropriate for the msg level
if (msgLevel() >= MSG::INFO) {
TGeoManager::SetVerboseLevel(0);
}
uint printoutLevel = msgLevel();
dd4hep::setPrintLevel(dd4hep::PrintLevel(printoutLevel));
m_incidentSvc->addListener(this, "GeometryFailure");
if (buildDD4HepGeo().isFailure())
m_log << MSG::ERROR << "Could not build DD4Hep geometry" << endmsg;
else
m_log << MSG::INFO << "DD4Hep geometry SUCCESSFULLY built" << endmsg;
//if (buildGeant4Geo().isFailure())
// m_log << MSG::ERROR << "Could not build Geant4 geometry" << endmsg;
//else
// m_log << MSG::INFO << "Geant4 geometry SUCCESSFULLY built" << endmsg;
if (m_failureFlag) {
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
StatusCode GeoSvc::finalize() { return StatusCode::SUCCESS; }
StatusCode GeoSvc::buildDD4HepGeo() {
// we retrieve the the static instance of the DD4HEP::Geometry
m_dd4hepgeo = &(dd4hep::Detector::getInstance());
m_dd4hepgeo->addExtension<IGeoSvc>(this);
// load geometry
for (auto& filename : m_xmlFileNames) {
m_log << MSG::INFO << "loading geometry from file: '" << filename << "'" << endmsg;
m_dd4hepgeo->fromCompact(filename);
}
m_dd4hepgeo->volumeManager();
m_dd4hepgeo->apply("DD4hepVolumeManager", 0, 0);
return StatusCode::SUCCESS;
}
dd4hep::Detector* GeoSvc::lcdd() { return (m_dd4hepgeo); }
dd4hep::DetElement GeoSvc::getDD4HepGeo() { return (lcdd()->world()); }
//StatusCode GeoSvc::buildGeant4Geo() {
// std::shared_ptr<G4VUserDetectorConstruction> detector(new det::GeoConstruction(*lcdd()));
// m_geant4geo = detector;
// if (m_geant4geo) {
// return StatusCode::SUCCESS;
// } else
// return StatusCode::FAILURE;
//}
//G4VUserDetectorConstruction* GeoSvc::getGeant4Geo() { return (m_geant4geo.get()); }
void GeoSvc::handle(const Incident& inc) {
error() << "Handling incident '" << inc.type() << "'" << endmsg;
if (!inc.type().compare("GeometryFailure")) {
m_failureFlag = true;
}
}
//
// GeoSvc.h
//
//
// Created by Julia Hrdinka on 30/03/15.
//
//
#ifndef GEOSVC_H
#define GEOSVC_H
// Interface
#include "JugBase/IGeoSvc.h"
// Gaudi
#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/Incident.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/Service.h"
#include "GaudiKernel/ServiceHandle.h"
// DD4Hep
#include "DD4hep/Detector.h"
//// Geant4
//#include "G4RunManager.hh"
//#include "G4VUserDetectorConstruction.hh"
class GeoSvc : public extends2<Service, IGeoSvc, IIncidentListener> {
public:
/// Default constructor
GeoSvc(const std::string& name, ISvcLocator* svc);
/// Destructor
virtual ~GeoSvc();
/// Initialize function
virtual StatusCode initialize() final;
/// Finalize function
virtual StatusCode finalize() final;
/// This function generates the DD4hep geometry
StatusCode buildDD4HepGeo();
/// This function generates the Geant4 geometry
//StatusCode buildGeant4Geo();
// receive DD4hep Geometry
virtual dd4hep::DetElement getDD4HepGeo() override;
virtual dd4hep::Detector* lcdd() override;
virtual dd4hep::Detector* detector() override { return lcdd();}
// receive Geant4 Geometry
//virtual G4VUserDetectorConstruction* getGeant4Geo() override;
/// Inform that a new incident has occurred
virtual void handle(const Incident& inc) final;
private:
/// Pointer to the incident service
ServiceHandle<IIncidentSvc> m_incidentSvc;
/// Pointer to the interface to the DD4hep geometry
dd4hep::Detector* m_dd4hepgeo;
/// Pointer to the detector construction of DDG4
//std::shared_ptr<G4VUserDetectorConstruction> m_geant4geo;
/// XML-files with the detector description
Gaudi::Property<std::vector<std::string>> m_xmlFileNames{this, "detectors", {}, "Detector descriptions XML-files"};
// output
MsgStream m_log;
// Flag set to true if any incident is fired from geometry constructors
bool m_failureFlag;
};
#endif // GEOSVC_H
This diff is collapsed.
<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">
<info name="beam_pipe" title="Beam pipe test"
author="Whitney Armstrong"
url="https://eicweb.phy.anl.gov/EIC/NPDet"
status="development"
version="">
<comment>EIC Beam Pipe</comment>
</info>
<includes>
<gdmlFile ref="elements.xml"/>
<gdmlFile ref="materials.xml"/>
</includes>
<define>
<constant name="world_side" value="10*m"/>
<constant name="world_x" value="world_side"/>
<constant name="world_y" value="world_side"/>
<constant name="world_z" value="10*world_side"/>
<constant name="tracker_region_rmax" value="2.0*m" />
<constant name="tracker_region_zmax" value="4.0*m" />
<constant name="CrossingAngle" value="0.020*rad"/>
<constant name="CentralBeamPipe_length" value="50.0*cm"/>
<constant name="CentralBeamPipe_thickness" value="0.1*mm"/>
<constant name="CentralBeamPipe_radius" value="3.5*cm"/>
<constant name="CentralBeamPipe_z" value="0.0*cm"/>
<constant name="UpStreamBeamPipe_length" value="150.0*cm"/>
<constant name="UpStreamBeamPipe_thickness" value="0.1*mm"/>
<constant name="UpStreamBeamPipe_radius" value="5*cm"/>
<constant name="UpStreamBeamPipe_z" value="-1.0*(CentralBeamPipe_length+UpStreamBeamPipe_length)/2.0"/>
<constant name="DownStreamBeamPipe_length" value="250.0*cm"/>
<constant name="DownStreamBeamPipe_thickness" value="0.1*mm"/>
<constant name="DownStreamBeamPipe_radius" value="5*cm"/>
<constant name="DownStreamBeamPipe_z" value="1.0*(CentralBeamPipe_length+DownStreamBeamPipe_length)/2.0"/>
<constant name="Place_Center" value="0*cm"/>
<constant name="ForwardTrackerPlane_z0" value="400*cm"/>
</define>
<limits>
<limitset name="cal_limits">
<limit name="step_length_max" particles="*" value="5.0" unit="mm" />
</limitset>
<limitset name="GemTrackerDiscRegionLimitSet">
<limit name="step_length_max" particles="*" value="5.0" unit="mm" />
<limit name="track_length_max" particles="*" value="5.0" unit="mm" />
<limit name="time_max" particles="*" value="5.0" unit="ns" />
<limit name="ekin_min" particles="*" value="0.01" unit="MeV" />
<limit name="range_min" particles="*" value="5.0" unit="mm" />
</limitset>
</limits>
<regions>
<region name="GemTrackerDiscRegion" eunit="MeV" lunit="mm" cut="0.001" threshold="0.001">
<limitsetref name="GemTrackerDiscRegionLimitSet"/>
</region>
</regions>
<limits>
<limitset name="Tracker_limits">
<limit name="step_length_max" particles="*" value="5.0" unit="mm" />
</limitset>
</limits>
<comment>Common Generic visualization attributes</comment>
<display>
<vis name="InvisibleNoDaughters" showDaughters="false" visible="false"/>
<vis name="InvisibleWithDaughters" showDaughters="true" visible="false"/>
<vis name="GreenVis" alpha="0.5" r= "0.0" g="1.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="RedVis" alpha="0.5" r= "1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="BlueVis" alpha="0.5" r= "0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/>
<vis name="OrangeVis" alpha="0.5" r= "1.0" g="0.45" b="0.0" showDaughters="true" visible="true"/>
<vis name="RedGreenVis" alpha="0.5" r= "1.0" g="1.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="BlueGreenVis" alpha="0.5" r= "0.0" g="1.0" b="1.0" showDaughters="true" visible="true"/>
<vis name="PurpleVis" alpha="0.5" r= "1.0" g="0.0" b="1.0" showDaughters="true" visible="true"/>
<vis name="DoubleRedG" alpha="0.5" r= "2.0" g=".10" b="0.0" showDaughters="true" visible="true"/>
<vis name="RBG015" alpha="0.5" r= "0.0" g=".2" b="1.0" showDaughters="true" visible="true"/>
<vis name="RBG510" alpha="0.5" r= "1.0" g=".2" b="0.0" showDaughters="true" visible="true"/>
<vis name="RBG" alpha="0.5" r= "1.0" g="1.0" b="1.0" showDaughters="true" visible="true"/>
<vis name="GrayVis" alpha="1.0" r= "0.75" g="0.75" b="0.75" showDaughters="true" visible="true"/>
</display>
<detectors>
<!--
<detector id="1" name="GEMTracker_PVDIS" vis="RedVis" type="GEMTrackerDiscSOLID" readout="GEMTrackerHits" >
<layer id="1" z="157.5*cm" inner_r="48.0*cm" outer_r="122.0*cm" phi0_offset=" 0.5*deg" />
<layer id="2" z="185.5*cm" inner_r="59.0*cm" outer_r="143.0*cm" phi0_offset=" 0.0*deg" />
<layer id="3" z="190 *cm" inner_r="65.0*cm" outer_r="143.0*cm" phi0_offset=" 0.0*deg" />
<layer id="4" z="306 *cm" inner_r="105.0*cm" outer_r="230.0*cm" phi0_offset="-0.5*deg" />
<layer id="5" z="315 *cm" inner_r="109.0*cm" outer_r="237.0*cm" phi0_offset="-0.5*deg" />
</detector>
-->
<detector id="2" name="GEMTracker_SIDIS" vis="RedVis" type="GEMTrackerDisc" readout="GEMTrackerHits" >
<layer id="1" z="-175 *cm" inner_r="36*cm" outer_r="87.0*cm" phi0_offset="0.0*deg" />
<layer id="2" z="-150 *cm" inner_r="21*cm" outer_r="98.0*cm" phi0_offset="0.0*deg" />
<layer id="3" z="-119 *cm" inner_r="25*cm" outer_r="112.0*cm" phi0_offset="0.0*deg" />
<layer id="4" z="-68 *cm" inner_r="32*cm" outer_r="135.0*cm" phi0_offset="0.0*deg" />
<layer id="5" z="-5 *cm" inner_r="42*cm" outer_r="100.0*cm" phi0_offset="0.0*deg" />
<layer id="6" z="5 *cm" inner_r="42*cm" outer_r="100.0*cm" phi0_offset="0.0*deg" />
<layer id="7" z="30 *cm" inner_r="42*cm" outer_r="123.0*cm" phi0_offset="0.0*deg" />
<layer id="8" z="60 *cm" inner_r="42*cm" outer_r="123.0*cm" phi0_offset="0.0*deg" />
<layer id="9" z="92 *cm" inner_r="55*cm" outer_r="123.0*cm" phi0_offset="0.0*deg" />
</detector>
<detector id="102" name="GEMTracker_assembly" type="DD4hep_SubdetectorAssembly" vis="BlueVis">
<composite name="GEMTracker_SIDIS"/>
</detector>
</detectors>
<readouts>
<readout name="TPCollection">
<segmentation type="CartesianGridXY" grid_size_x="10.0*cm" grid_size_y="10.0*cm" />
<id>system:5,layer:9,module:8,x:32:-16,y:-16</id>
</readout>
<!--
<readout name="SiVertexBarrelHits">
<id>system:8,barrel:3,layer:4,module:14,sensor:2,side:32:-2,strip:24</id>
</readout>
-->
<readout name="GEMTrackerHits">
<segmentation type="PolarGridRPhi" grid_size_phi="1.0*degree" grid_size_r="1.0*cm"/>
<id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
</readout>
<!--
<readout name="SiTrackerEndcapHits">
<id>system:8,barrel:3,layer:4,module:14,sensor:2,side:32:-2,strip:24</id>
</readout>
<readout name="SiVertexEndcapHits">
<id>system:8,barrel:3,layer:4,wedge:6,module:6,sensor:1,side:32:-2,strip:26</id>
</readout>
-->
</readouts>
<plugins>
<plugin name="DD4hep_GenericSurfaceInstallerPlugin">
<argument value="GEMTracker_SIDIS"/>
<argument value="dimension=2"/>
<argument value="u_x=-1."/>
<argument value="v_y=-1."/>
<argument value="n_z=1."/>
</plugin>
<plugin name="InstallSurfaceManager"/>
</plugins>
<fields>
<field name="GlobalSolenoid" type="solenoid"
inner_field="3.0*tesla"
outer_field="-0.5*tesla"
zmax="4.0*m"
outer_radius="2.0*m">
</field>
</fields>
</lccdd>
<?xml version="1.0" encoding="UTF-8"?>
<materials>
<!--
Air by weight from
http://www.engineeringtoolbox.com/air-composition-24_212.html
-->
<material name="Air">
<D type="density" unit="g/cm3" value="0.0012"/>
<fraction n="0.754" ref="N"/>
<fraction n="0.234" ref="O"/>
<fraction n="0.012" ref="Ar"/>
</material>
<material name="air">
<D type="density" unit="g/cm3" value="0.0012"/>
<fraction n="0.754" ref="N"/>
<fraction n="0.234" ref="O"/>
<fraction n="0.012" ref="Ar"/>
</material>
<!-- We model vakuum just as very thin air -->
<material name="Vacuum">
<D type="density" unit="g/cm3" value="0.0000000001" />
<fraction n="0.754" ref="N"/>
<fraction n="0.234" ref="O"/>
<fraction n="0.012" ref="Ar"/>
</material>
<material name="Epoxy">
<D type="density" value="1.3" unit="g/cm3"/>
<composite n="44" ref="H"/>
<composite n="15" ref="C"/>
<composite n="7" ref="O"/>
</material>
<material name="Quartz">
<D type="density" value="2.2" unit="g/cm3"/>
<composite n="1" ref="Si"/>
<composite n="2" ref="O"/>
</material>
<material name="G10">
<D type="density" value="1.7" unit="g/cm3"/>
<fraction n="0.08" ref="Cl"/>
<fraction n="0.773" ref="Quartz"/>
<fraction n="0.147" ref="Epoxy"/>
</material>
<material name="Polystyrene">
<D value="1.032" unit="g/cm3"/>
<composite n="19" ref="C"/>
<composite n="21" ref="H"/>
</material>
<material name="Steel235">
<D value="7.85" unit="g/cm3"/>
<fraction n="0.998" ref="Fe"/>
<fraction n=".002" ref="C"/>
</material>
<material name="SiliconOxide">
<D type="density" value="2.65" unit="g/cm3"/>
<composite n="1" ref="Si"/>
<composite n="2" ref="O"/>
</material>
<material name="BoronOxide">
<D type="density" value="2.46" unit="g/cm3"/>
<composite n="2" ref="B"/>
<composite n="3" ref="O"/>
</material>
<material name="SodiumOxide">
<D type="density" value="2.65" unit="g/cm3"/>
<composite n="2" ref="Na"/>
<composite n="1" ref="O"/>
</material>
<material name="AluminumOxide">
<D type="density" value="3.89" unit="g/cm3"/>
<composite n="2" ref="Al"/>
<composite n="3" ref="O"/>
</material>
<material name="PyrexGlass">
<D type="density" value="2.23" unit="g/cm3"/>
<fraction n="0.806" ref="SiliconOxide"/>
<fraction n="0.130" ref="BoronOxide"/>
<fraction n="0.040" ref="SodiumOxide"/>
<fraction n="0.023" ref="AluminumOxide"/>
</material>
<material name="CarbonFiber">
<D type="density" value="1.5" unit="g/cm3"/>
<fraction n="0.65" ref="C"/>
<fraction n="0.35" ref="Epoxy"/>
</material>
<material name="CarbonFiber_50D">
<D type="density" value="0.75" unit="g/cm3"/>
<fraction n="0.65" ref="C"/>
<fraction n="0.35" ref="Epoxy"/>
</material>
<material name="Rohacell31">
<D type="density" value="0.032" unit="g/cm3"/>
<composite n="9" ref="C"/>
<composite n="13" ref="H"/>
<composite n="2" ref="O"/>
<composite n="1" ref="N"/>
</material>
<material name="Rohacell31_50D">
<D type="density" value="0.016" unit="g/cm3"/>
<composite n="9" ref="C"/>
<composite n="13" ref="H"/>
<composite n="2" ref="O"/>
<composite n="1" ref="N"/>
</material>
<material name="RPCGasDefault" state="gas">
<D type="density" value="0.0037" unit="g/cm3"/>
<composite n="209" ref="C"/>
<composite n="239" ref="H"/>
<composite n="381" ref="F"/>
</material>
<material name="PolystyreneFoam">
<D type="density" value="0.0056" unit="g/cm3"/>
<fraction n="1.0" ref="Polystyrene"/>
</material>
<material name="Kapton">
<D value="1.43" unit="g/cm3" />
<composite n="22" ref="C"/>
<composite n="10" ref="H" />
<composite n="2" ref="N" />
<composite n="5" ref="O" />
</material>
<material name="PEEK">
<D value="1.37" unit="g/cm3" />
<composite n="19" ref="C"/>
<composite n="12" ref="H" />
<composite n="3" ref="O" />
</material>
</materials>
from Gaudi.Configuration import *
from Configurables import ApplicationMgr
from Configurables import HelloWorld
alg = HelloWorld()
from Configurables import GeoSvc
geoservice = GeoSvc("GeoSvc", detectors=[ 'gem_tracker_disc.xml'], OutputLevel = DEBUG)
#from Configurables import TestCellCounting
#cells = TestCellCounting("cells", readoutName="ECalHits",
# fieldNames=["system"],
# fieldValues=[0],
# volumeMatchName="BoxECal",
# OutputLevel = DEBUG)
# ApplicationMgr
ApplicationMgr(EvtSel='NONE',
EvtMax=1,
TopAlg=[alg],
ExtSvc=[geoservice],
OutputLevel=DEBUG)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment