Skip to content
Snippets Groups Projects
Commit 636e7d43 authored by Markus Frank's avatar Markus Frank Committed by MarkusFrankATcernch
Browse files

Have real straws (thin tubes filled with gas) for BoxOfStraws examples

parent febdd597
No related branches found
No related tags found
No related merge requests found
......@@ -39,11 +39,11 @@ namespace dd4hep {
class Geant4RegexSensitivesConstruction : public Geant4DetectorConstruction {
public:
std::string detector_name;
std::string regex_value;
std::vector<std::string> regex_values;
std::size_t collect_volumes(std::set<Volume>& volumes,
PlacedVolume pv,
const std::string& path,
std::regex& match);
const std::vector<std::regex>& matches);
public:
/// Initializing constructor for DDG4
Geant4RegexSensitivesConstruction(Geant4Context* ctxt, const std::string& nam);
......@@ -82,8 +82,8 @@ DECLARE_GEANT4ACTION(Geant4RegexSensitivesConstruction)
Geant4RegexSensitivesConstruction::Geant4RegexSensitivesConstruction(Geant4Context* ctxt, const std::string& nam)
: Geant4DetectorConstruction(ctxt,nam)
{
declareProperty("Detector", detector_name);
declareProperty("Regex", regex_value);
declareProperty("Detector", detector_name);
declareProperty("Match", regex_values);
InstanceCount::increment(this);
}
......@@ -96,24 +96,27 @@ std::size_t
Geant4RegexSensitivesConstruction::collect_volumes(std::set<Volume>& volumes,
PlacedVolume pv,
const std::string& path,
std::regex& match)
const std::vector<std::regex>& matches)
{
std::size_t count = 0;
// Try to minimize a bit the number of regex matches.
if ( volumes.find(pv.volume()) == volumes.end() ) {
if( !path.empty() ) {
std::smatch sm;
bool stat = std::regex_match(path, sm, match);
if( stat ) {
volumes.insert(pv.volume());
for( const auto& m : matches ) {
std::smatch sm;
bool stat = std::regex_match(path, sm, m);
if( stat ) {
volumes.insert(pv.volume());
++count;
break;
}
}
++count;
}
// Now recurse down the daughters
for( int i=0, num = pv->GetNdaughters(); i < num; ++i ) {
PlacedVolume daughter = pv->GetDaughter(i);
std::string daughter_path = path + "/" + daughter.name();
count += this->collect_volumes(volumes, daughter, daughter_path, match);
count += this->collect_volumes(volumes, daughter, daughter_path, matches);
}
}
return count;
......@@ -142,22 +145,24 @@ void Geant4RegexSensitivesConstruction::constructSensitives(Geant4DetectorConstr
std::set<Volume> volumes;
int flags = std::regex_constants::icase | std::regex_constants::ECMAScript;
std::regex expression(regex_value, (std::regex_constants::syntax_option_type)flags);
std::vector<std::regex> expressions;
for( const auto& val : regex_values ) {
std::regex e(val, (std::regex_constants::syntax_option_type)flags);
expressions.emplace_back(e);
}
TTimeStamp start;
print("+++ Detector: %s Starting to scan volume....", det);
std::size_t num_nodes = this->collect_volumes(volumes, de.placement(), de.placementPath(), expression);
std::size_t num_nodes = this->collect_volumes(volumes, de.placement(), de.placementPath(), expressions);
for( const auto& vol : volumes ) {
G4LogicalVolume* g4vol = g4info->g4Volumes[vol];
if( !g4vol ) {
except("+++ Failed to access G4LogicalVolume for SD %s of type %s",
nam.c_str(), typ.c_str());
except("+++ Failed to access G4LogicalVolume for SD %s of type %s", nam.c_str(), typ.c_str());
}
print("+++ Detector: %s Assign sensitive detector [%s] to volume: %s.",
nam.c_str(), typ.c_str(), vol.name());
ctxt->setSensitiveDetector(g4vol, g4sd);
}
TTimeStamp stop;
print("+++ Detector: %s Handled %ld nodes with %ld sensitive volume type. Total of %7.3f seconds.",
print("+++ Detector: %s Handled %ld nodes with %ld sensitive volume type(s). Total of %7.3f seconds.",
det, num_nodes, volumes.size(), stop.AsDouble()-start.AsDouble() );
}
......@@ -13,12 +13,12 @@
-->
<info name="BoxOfStraws"
title="Test with silicon boxes"
title="Test with a box of straws"
author="Markus Frank"
url="http://www.cern.ch/frankm"
url="http://www.cern.ch"
status="development"
version="1.0">
<comment>Alignment test with 2 simple boxes</comment>
<comment>Detector scalability test with a box of straws</comment>
</info>
<includes>
......@@ -37,8 +37,8 @@
<vis name="Invisible" showDaughters="false" visible="false"/>
<vis name="InvisibleWithChildren" showDaughters="true" visible="false"/>
<vis name="VisibleRed" alpha="0.4" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="VisibleBlue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="false" visible="true"/>
<vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" drawingStyle="solid" lineStyle="solid" showDaughters="true" visible="true"/>
<vis name="VisibleBlue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/>
<vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" showDaughters="false" visible="true"/>
</display>
<limits>
......@@ -57,10 +57,13 @@
<detectors>
<detector id="1" name="BoxOfStrawsDet" type="DD4hep_BoxOfStraws" readout="BoxOfStrawsHits" vis="VisibleGreen" region="StrawRegion" limits="BoxOfStrawsLimitSet">
<box x="1*m" y="1*m" z="1000*mm" limits="BoxOfStrawsLimitSet" vis="VisibleRed"/>
<straw rmax="2*mm" y="1*m" thickness="0.5*mm" vis="VisibleBlue">
<straw rmax="0.5*mm" y="1*m" thickness="0.1*mm" vis="VisibleBlue">
<material name="Iron"/>
</straw>
<gas vis="VisibleGreen">
<material name="Argon"/>
<non_sensitive/>
</straw>
</gas>
<position x="0*m" y="0*m" z="0*m"/>
<rotation x="0" y="0" z="0"/>
</detector>
......@@ -74,7 +77,7 @@
<fields>
<field name="GlobalSolenoid" type="solenoid"
inner_field="5.0*tesla"
inner_field="3.0*tesla"
outer_field="-1.5*tesla"
zmax="2*m"
outer_radius="2*m">
......
......@@ -32,7 +32,8 @@ def run():
args = DDG4.CommandLine()
kernel = DDG4.Kernel()
logger = DDG4.Logger('BoxOfStraws')
kernel.loadGeometry(str("file:" + os.environ['DD4hepExamplesINSTALL'] + "/examples/ClientTests/compact/BoxOfStraws.xml"))
install_dir = os.environ['DD4hepExamplesINSTALL']
kernel.loadGeometry(str('file:' + install_dir + '/examples/ClientTests/compact/BoxOfStraws.xml'))
DDG4.importConstants(kernel.detectorDescription(), debug=False)
geant4 = DDG4.Geant4(kernel)
......@@ -49,32 +50,32 @@ def run():
geant4.setupTrackingField(prt=True)
#
# Configure G4 geometry setup
seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
act.DebugVolumes = True
#
# Assign sensitive detectors according to the declarations 'tracker' or 'calorimeter', etc
seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")
seq, act = geant4.addDetectorConstruction('Geant4DetectorSensitivesConstruction/ConstructSD')
#
# Assign sensitive detectors in Geant4 by matching a regular expression in the detector sub-tree
seq, act = geant4.addDetectorConstruction("Geant4RegexSensitivesConstruction/ConstructSDRegEx")
seq, act = geant4.addDetectorConstruction('Geant4RegexSensitivesConstruction/ConstructSDRegEx')
act.Detector = 'BoxOfStrawsDet'
act.OutputLevel = Output.ALWAYS
act.Regex = '/world_volume_(.*)/BoxOfStrawsDet_(.*)/layer_(.*)/straw_(.*)/gas_(.*)'
act.Regex = '/world_volume_(.*)/BoxOfStrawsDet_(.*)/layer_(.*)/straw_(.*)'
act.Match = ['/world_volume_(.*)/BoxOfStrawsDet_(.*)/layer_(.*)/straw_(.*)/gas_(.*)']
act.Match = ['/world_volume_(.*)/BoxOfStrawsDet_(.*)/layer_(.*)/straw_(.*)']
#
# Configure I/O
geant4.setupROOTOutput('RootOutput', 'BoxOfStraws_' + time.strftime('%Y-%m-%d_%H-%M'))
#
# Setup particle gun
gun = geant4.setupGun("Gun", particle='pi+', energy=100 * GeV, multiplicity=1)
gun = geant4.setupGun('Gun', particle='pi+', energy=100 * GeV, multiplicity=1)
gun.enableUI()
#
# And handle the simulation particles.
part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
part = DDG4.GeneratorAction(kernel, 'Geant4ParticleHandler/ParticleHandler')
kernel.generatorAction().adopt(part)
part.SaveProcesses = ['Decay']
part.MinimalKineticEnergy = 100 * MeV
user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
part.MinimalKineticEnergy = 50 * MeV
user = DDG4.Action(kernel, 'Geant4TCUserParticleHandler/UserParticleHandler')
user.TrackingVolume_Zmax = 2.5 * m
user.TrackingVolume_Rmax = 2.5 * m
part.adopt(user)
......
......@@ -29,6 +29,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
xml_dim_t x_rot = x_det.child(_U(rotation));
xml_dim_t x_pos = x_det.child(_U(position));
xml_det_t x_straw = x_det.child(_Unicode(straw));
xml_det_t x_gas = x_det.child(_Unicode(gas));
std::string nam = x_det.nameStr();
const double thick = x_straw.thickness();
const double delta = 2e0*x_straw.rmax();
......@@ -36,18 +37,19 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
const int num_z = int(2e0*x_box.z() / delta);
Tube straw(0., x_straw.rmax()-tol, x_straw.y()-tol);
Volume straw_vol("straw", straw, description.material("Iron"));
Volume straw_vol("straw", straw, description.material(x_straw.materialStr()));
straw_vol.setAttributes(description, x_straw.regionStr(), x_straw.limitsStr(), x_straw.visStr());
Tube straw_gas(0., x_straw.rmax()-tol-thick, x_straw.y()-tol-thick);
Volume straw_gas_vol("gas", straw_gas, description.material(x_straw.materialStr()));
Tube straw_gas(0., straw.rMax()-thick, straw.dZ()-thick);
Volume straw_gas_vol("gas", straw_gas, description.material(x_gas.materialStr()));
straw_gas_vol.setAttributes(description, x_gas.regionStr(), x_gas.limitsStr(), x_gas.visStr());
straw_vol.setAttributes(description, x_straw.regionStr(), x_straw.limitsStr(), x_straw.visStr());
straw_vol.placeVolume(straw_gas_vol);
printout(INFO, "BoxOfStraws", "%s: Straw: rmax: %7.3f y: %7.3f mat: %s vis: %s solid: %s",
nam.c_str(), x_straw.rmax(), x_straw.y(), x_straw.materialStr().c_str(),
x_straw.visStr().c_str(), straw.type());
if ( x_straw.hasChild(_U(sensitive)) ) {
if( x_gas.hasChild(_U(sensitive)) ) {
sens.setType("tracker");
straw_gas_vol.setSensitiveDetector(sens);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment