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

Enable energy deposit collection in FiberTubeCalorimeter example

parent ea7156ad
No related branches found
No related tags found
No related merge requests found
...@@ -97,7 +97,8 @@ ...@@ -97,7 +97,8 @@
z_length="DRFiberlengthSCE" z_length="DRFiberlengthSCE"
gap="gapSCE" gap="gapSCE"
zmin="-world_side/2.+2*killthick+edgeoffset+DRcrystallength+EcalHcalgap" zmin="-world_side/2.+2*killthick+edgeoffset+DRcrystallength+EcalHcalgap"
z1="killthick"/> z1="killthick"
sensitive="yes"/>
<structure> <structure>
<core1 name="scintillator" rmax="DRFiberFibwidthSCE" rmin="0.0" material="Polystyrene" vis="ScintVis" sensitive="yes"/> <core1 name="scintillator" rmax="DRFiberFibwidthSCE" rmin="0.0" material="Polystyrene" vis="ScintVis" sensitive="yes"/>
<core2 name="quartz" rmax="DRFiberFibwidthSCE" rmin="0.0" material="Quartz" vis="CerenVis" sensitive="yes"/> <core2 name="quartz" rmax="DRFiberFibwidthSCE" rmin="0.0" material="Quartz" vis="CerenVis" sensitive="yes"/>
......
...@@ -15,7 +15,7 @@ import os ...@@ -15,7 +15,7 @@ import os
import time import time
import DDG4 import DDG4
from DDG4 import OutputLevel as Output from DDG4 import OutputLevel as Output
from g4units import GeV, MeV, m from g4units import GeV, MeV, m, cm
# #
# #
""" """
...@@ -67,7 +67,7 @@ def run(): ...@@ -67,7 +67,7 @@ def run():
geant4.setupROOTOutput('RootOutput', 'FiberTubeCalorimeter_' + time.strftime('%Y-%m-%d_%H-%M')) geant4.setupROOTOutput('RootOutput', 'FiberTubeCalorimeter_' + time.strftime('%Y-%m-%d_%H-%M'))
# Setup particle gun # Setup particle gun
gun = geant4.setupGun("Gun", particle='e+', energy=20 * GeV, multiplicity=1, position=(0.0, 0.0, -369.0)) gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1, position=(0.0, 0.0, -364.0*cm))
gun.OutputLevel = generator_output_level gun.OutputLevel = generator_output_level
# And handle the simulation particles. # And handle the simulation particles.
......
...@@ -60,11 +60,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -60,11 +60,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
xml_comp_t x_dim = x_det.dimensions(); xml_comp_t x_dim = x_det.dimensions();
double hthick = x_dim.thickness(); double hthick = x_dim.thickness();
double hzlength = x_dim.z_length()/2.; double hzlength = x_dim.z_length()/2.;
double hzph = x_dim.z1();
int Ncount = x_dim.numsides();
double agap = x_dim.gap();
double azmin = x_dim.zmin();
// these refer to different fields in the xml file for this detector // these refer to different fields in the xml file for this detector
xml_comp_t fX_struct( x_det.child( _Unicode(structure) ) ); xml_comp_t fX_struct( x_det.child( _Unicode(structure) ) );
xml_comp_t fX_absorb( fX_struct.child( _Unicode(absorb) ) ); xml_comp_t fX_absorb( fX_struct.child( _Unicode(absorb) ) );
...@@ -74,18 +70,18 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -74,18 +70,18 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
xml_comp_t fX_phdet1( fX_struct.child( _Unicode(phdet1) ) ); xml_comp_t fX_phdet1( fX_struct.child( _Unicode(phdet1) ) );
xml_comp_t fX_phdet2( fX_struct.child( _Unicode(phdet2) ) ); xml_comp_t fX_phdet2( fX_struct.child( _Unicode(phdet2) ) );
Material mat; Material mat;
Transform3D trafo; Transform3D trafo;
PlacedVolume pv; PlacedVolume pv;
Solid sol; Solid sol;
sens.setType("calorimeter"); sens.setType("calorimeter");
//
// scint fiber // scint fiber
sol = Tube(0.,fX_core1.rmax(), hzlength); sol = Tube(0., fX_core1.rmax(), hzlength);
mat = description.material(fX_core1.materialStr()); mat = description.material(fX_core1.materialStr());
Volume fiber_scint_vol(fX_core1.nameStr(), sol, mat); Volume fiber_scint_vol(fX_core1.nameStr(), sol, mat);
fiber_scint_vol.setAttributes(description,fX_core1.regionStr(),fX_core1.limitsStr(),fX_core1.visStr()); fiber_scint_vol.setAttributes(description, fX_core1.regionStr(), fX_core1.limitsStr(), fX_core1.visStr());
if ( fX_core1.isSensitive() ) { if ( fX_core1.isSensitive() ) {
fiber_scint_vol.setSensitiveDetector(sens); fiber_scint_vol.setSensitiveDetector(sens);
} }
...@@ -94,12 +90,12 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -94,12 +90,12 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
<< " vis: " << setw(15) << left<< fX_core1.visStr() << " vis: " << setw(15) << left<< fX_core1.visStr()
<< " solid: " << setw(20) << left << sol.type() << " solid: " << setw(20) << left << sol.type()
<< " sensitive: " << yes_no(fX_core1.isSensitive()) << endl; << " sensitive: " << yes_no(fX_core1.isSensitive()) << endl;
//
// quartz fiber // quartz fiber
sol = Tube(0.,fX_core2.rmax(), hzlength); sol = Tube(0., fX_core2.rmax(), hzlength);
mat = description.material(fX_core2.materialStr()); mat = description.material(fX_core2.materialStr());
Volume fiber_quartz_vol(fX_core2.nameStr(), sol, mat); Volume fiber_quartz_vol(fX_core2.nameStr(), sol, mat);
fiber_quartz_vol.setAttributes(description,fX_core2.regionStr(),fX_core2.limitsStr(),fX_core2.visStr()); fiber_quartz_vol.setAttributes(description, fX_core2.regionStr(), fX_core2.limitsStr(), fX_core2.visStr());
if ( fX_core2.isSensitive() ) { if ( fX_core2.isSensitive() ) {
fiber_quartz_vol.setSensitiveDetector(sens); fiber_quartz_vol.setSensitiveDetector(sens);
} }
...@@ -108,10 +104,10 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -108,10 +104,10 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
<< " vis: " << setw(15) << left << fX_core2.visStr() << " vis: " << setw(15) << left << fX_core2.visStr()
<< " solid: " << setw(20) << left << sol.type() << " solid: " << setw(20) << left << sol.type()
<< " sensitive: " << yes_no(fX_core2.isSensitive()) << endl; << " sensitive: " << yes_no(fX_core2.isSensitive()) << endl;
//
// absorberhole with a scintillating fiber inside // absorberhole with a scintillating fiber inside
mat = description.material(fX_hole.materialStr()); mat = description.material(fX_hole.materialStr());
sol = Tube(0.,fX_hole.rmax(),hzlength); sol = Tube(0., fX_hole.rmax(), hzlength);
Volume scint_hole_vol( fX_core1.nameStr()+"_hole", sol, mat); Volume scint_hole_vol( fX_core1.nameStr()+"_hole", sol, mat);
scint_hole_vol.setAttributes(description, fX_hole.regionStr(), fX_hole.limitsStr(), fX_hole.visStr()); scint_hole_vol.setAttributes(description, fX_hole.regionStr(), fX_hole.limitsStr(), fX_hole.visStr());
trafo = Transform3D(RotationZYX(0.,0.,0.),Position(0.,0.,0.)); trafo = Transform3D(RotationZYX(0.,0.,0.),Position(0.,0.,0.));
...@@ -125,10 +121,10 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -125,10 +121,10 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
if ( fX_hole.isSensitive() ) { if ( fX_hole.isSensitive() ) {
scint_hole_vol.setSensitiveDetector(sens); scint_hole_vol.setSensitiveDetector(sens);
} }
//
// absorberhole with a quartz inside // absorberhole with a quartz inside
Volume quartz_hole_vol( fX_core2.nameStr()+"_hole", sol, mat); Volume quartz_hole_vol( fX_core2.nameStr()+"_hole", sol, mat);
quartz_hole_vol.setAttributes(description,fX_hole.regionStr(),fX_hole.limitsStr(),fX_hole.visStr()); quartz_hole_vol.setAttributes(description, fX_hole.regionStr(), fX_hole.limitsStr(), fX_hole.visStr());
pv = quartz_hole_vol.placeVolume(fiber_quartz_vol); pv = quartz_hole_vol.placeVolume(fiber_quartz_vol);
pv.addPhysVolID("type",2); pv.addPhysVolID("type",2);
cout << setw(28) << left << quartz_hole_vol.name() cout << setw(28) << left << quartz_hole_vol.name()
...@@ -142,9 +138,9 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -142,9 +138,9 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
// absorber with scintillator inside // absorber with scintillator inside
mat = description.material(fX_absorb.materialStr()); mat = description.material(fX_absorb.materialStr());
sol = Tube(0.,hthick,hzlength); sol = Tube(0., hthick, hzlength);
Volume scint_abs_vol( fX_core1.nameStr()+"_absorber", sol, mat); Volume scint_abs_vol( fX_core1.nameStr()+"_absorber", sol, mat);
scint_abs_vol.setAttributes(description,fX_absorb.regionStr(),fX_absorb.limitsStr(),fX_absorb.visStr()); scint_abs_vol.setAttributes(description, fX_absorb.regionStr(), fX_absorb.limitsStr(), fX_absorb.visStr());
pv = scint_abs_vol.placeVolume(scint_hole_vol); pv = scint_abs_vol.placeVolume(scint_hole_vol);
pv.addPhysVolID("hole",1); pv.addPhysVolID("hole",1);
cout << setw(28) << left << scint_abs_vol.name() cout << setw(28) << left << scint_abs_vol.name()
...@@ -155,11 +151,11 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -155,11 +151,11 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
if ( fX_absorb.isSensitive() ) { if ( fX_absorb.isSensitive() ) {
scint_abs_vol.setSensitiveDetector(sens); scint_abs_vol.setSensitiveDetector(sens);
} }
//
// absorber with quartz inside // absorber with quartz inside
mat = description.material(fX_absorb.materialStr()); mat = description.material(fX_absorb.materialStr());
Volume quartz_abs_vol(fX_core2.nameStr()+"_absorber", sol, mat); Volume quartz_abs_vol(fX_core2.nameStr()+"_absorber", sol, mat);
quartz_abs_vol.setAttributes(description,fX_absorb.regionStr(),fX_absorb.limitsStr(),fX_absorb.visStr()); quartz_abs_vol.setAttributes(description, fX_absorb.regionStr(), fX_absorb.limitsStr(), fX_absorb.visStr());
pv = quartz_abs_vol.placeVolume(quartz_hole_vol, trafo); pv = quartz_abs_vol.placeVolume(quartz_hole_vol, trafo);
pv.addPhysVolID("hole",2); pv.addPhysVolID("hole",2);
cout << setw(28) << left << quartz_abs_vol.name() cout << setw(28) << left << quartz_abs_vol.name()
...@@ -170,11 +166,14 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -170,11 +166,14 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
if ( fX_absorb.isSensitive() ) { if ( fX_absorb.isSensitive() ) {
quartz_abs_vol.setSensitiveDetector(sens); quartz_abs_vol.setSensitiveDetector(sens);
} }
//
// setup the volumes with the shapes and properties in one horixontal layer // Setup the volumes with the shapes and properties in one horixontal layer
double dx = 2*(Ncount + Ncount+1)/2e0 * (hthick+agap) + tol; int Ncount = x_dim.numsides();
double dy = hthick + tol; double hzph = x_dim.z1();
double dz = hzlength+hzph + tol; double agap = x_dim.gap();
double dx = 2*(Ncount + Ncount+1)/2e0 * (hthick+agap) + tol;
double dy = hthick + tol;
double dz = hzlength+hzph + tol;
Box tube_row_box(dx, dy, dz); Box tube_row_box(dx, dy, dz);
Volume tube_row_vol("layer", tube_row_box, air); Volume tube_row_vol("layer", tube_row_box, air);
tube_row_vol.setVisAttributes(description, x_det.visStr()); tube_row_vol.setVisAttributes(description, x_det.visStr());
...@@ -190,7 +189,6 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -190,7 +189,6 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
int towernum = Ncount + ijk + 1; int towernum = Ncount + ijk + 1;
pv = tube_row_vol.placeVolume((towernum%2 == 0) ? quartz_abs_vol : scint_abs_vol, Position(mod_x_off,0.,0.)); pv = tube_row_vol.placeVolume((towernum%2 == 0) ? quartz_abs_vol : scint_abs_vol, Position(mod_x_off,0.,0.));
pv.addPhysVolID("tube", towernum); pv.addPhysVolID("tube", towernum);
//Box bounding_box = pv.volume().solid().GetBoundingBox();
cout << "Placing row " << setw(5) << right << ijk cout << "Placing row " << setw(5) << right << ijk
<< " x-offset: " << setw(7) << right << mod_x_off << " x-offset: " << setw(7) << right << mod_x_off
<< " volume of type " << pv.volume().name() << " volume of type " << pv.volume().name()
...@@ -198,13 +196,16 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -198,13 +196,16 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
} }
dy = 2*(Ncount + Ncount+1)/2e0 * (hthick+agap) + tol; dy = 2*(Ncount + Ncount+1)/2e0 * (hthick+agap) + tol;
DetElement sdet (det_name, det_id); DetElement sdet(det_name, det_id);
Box env_box (dx+tol, dy+tol, dz+tol); Box env_box(dx+tol, dy+tol, dz+tol);
Volume envelopeVol (det_name, env_box, air); Volume envelopeVol(det_name, env_box, air);
envelopeVol.setAttributes(description, x_det.regionStr(), x_det.limitsStr(), x_det.visStr()); envelopeVol.setAttributes(description, x_det.regionStr(), x_det.limitsStr(), x_det.visStr());
if ( x_dim.isSensitive() ) {
envelopeVol.setSensitiveDetector(sens);
}
//
// Now stack multiple horizontal layers to form the final box // Now stack multiple horizontal layers to form the final box
for (int ijk=-Ncount; ijk<Ncount+1; ijk++) { for (int ijk=-Ncount; ijk < Ncount+1; ijk++) {
double mod_y_off = (ijk) * 2 * (tube_row_box.y() + agap); double mod_y_off = (ijk) * 2 * (tube_row_box.y() + agap);
Transform3D tr(RotationZYX(0.,0.,0.), Position(0.,mod_y_off,0.)); Transform3D tr(RotationZYX(0.,0.,0.), Position(0.,mod_y_off,0.));
pv = envelopeVol.placeVolume(tube_row_vol, tr); pv = envelopeVol.placeVolume(tube_row_vol, tr);
...@@ -218,10 +219,11 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s ...@@ -218,10 +219,11 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
<< " volume of type " << pv.volume().name() << " volume of type " << pv.volume().name()
<< endl; << endl;
} }
//
// detector element for entire detector. // detector element for entire detector.
Volume motherVol = description.pickMotherVolume(sdet); dz = x_dim.zmin()+hzlength+hzph+tol;
pv = motherVol.placeVolume(envelopeVol, Position(0.,0.,azmin+hzlength+hzph+tol)); Volume motherVol = description.pickMotherVolume(sdet);
pv = motherVol.placeVolume(envelopeVol, Position(0, 0, dz));
pv.addPhysVolID("system", det_id); pv.addPhysVolID("system", det_id);
sdet.setPlacement(pv); // associate the placed volume to the detector element sdet.setPlacement(pv); // associate the placed volume to the detector element
return sdet; return sdet;
......
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