diff --git a/DDExamples/CLICSiD/compact/compact.xml b/DDExamples/CLICSiD/compact/compact.xml index 13ea107198780e10b9e4d6cda3e9eaf88b7a4555..0edd3c78360b03e881d801e13b2dd113ffceb571 100644 --- a/DDExamples/CLICSiD/compact/compact.xml +++ b/DDExamples/CLICSiD/compact/compact.xml @@ -1524,13 +1524,13 @@ <readouts> <readout name="SiTrackerEndcapHits"> - <id>system:8,barrel:3,layer:4,module:16,sensor:1,side:32:-2,strip:20</id> + <id>system:8,barrel:3,layer:4,module:14,sensor:2,side:32:-2,strip:20</id> </readout> <readout name="SiTrackerBarrelHits"> - <id>system:8,barrel:3,layer:4,module:12,sensor:1,side:v32:-2,strip:20</id> + <id>system:8,barrel:3,layer:4,module:14,sensor:2,side:32:-2,strip:20</id> </readout> <readout name="SiVertexBarrelHits"> - <id>system:8,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:24</id> + <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> @@ -1545,7 +1545,7 @@ </readout> <readout name="HcalBarrelHits"> <segmentation type="RegularNgonCartesianGridXY" gridSizeX="3.0*cm" gridSizeY="3.0*cm" /> - <id>system:8,barrel:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id> + <id>system:8,barrel:3,module:6,layer:8,slice:5,x:32:-16,y:-16</id> </readout> <readout name="HcalEndcapHits"> <segmentation type="GlobalGridXY" gridSizeX="3.0*cm" gridSizeY="3.0*cm" /> diff --git a/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp b/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp index e8bfeaeecc1358f9ad87b2b943a29caec85f5f6a..ebcf3bddc669bbe19bb415ecc77be2022db77d74 100644 --- a/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp +++ b/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp @@ -25,8 +25,8 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { double rmin = dim.inner_r(); double rmax = dim.outer_r(); double totWidth = Layering(x_det).totalThickness(); - double z = zmin; - int n = 0; + double z = zmin; + int layer_num = 1; for(xml_coll_t c(x_det,_U(layer)); c; ++c) { xml_comp_t x_layer = c; @@ -35,7 +35,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { layerWidth += xml_comp_t(l).thickness(); for(int i=0, m=0, repeat=x_layer.repeat(); i<repeat; ++i, m=0) { double zlayer = z; - string layer_name = det_name + _toString(n,"_layer%d"); + string layer_name = det_name + _toString(layer_num,"_layer%d"); Volume layer_vol(layer_name,Tube(rmin,rmax,layerWidth),air); for(xml_coll_t l(x_layer,_U(slice)); l; ++l, ++m) { @@ -58,8 +58,8 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Position layer_pos(0,0,zlayer-zmin-totWidth/2+layerWidth/2); PlacedVolume layer_phys = envelopeVol.placeVolume(layer_vol,layer_pos); - layer_phys.addPhysVolID("layer",n); - ++n; + layer_phys.addPhysVolID("layer",layer_num); + ++layer_num; } } envelope.setDimensions(rmin,rmax,totWidth,0,2*M_PI); diff --git a/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp b/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp index 919153c58f49e7e622516c47390e2d63a506db8f..c0dc915824275002f16aa02fbff4271995f8a416 100644 --- a/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp +++ b/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp @@ -30,8 +30,8 @@ static void placeStaves(DetElement& parent, double posX = -sectCenterRadius * std::sin(rotY); double posY = sectCenterRadius * std::cos(rotY); - for (int module = 0; module < numsides; ++module) { - DetElement det = module>0 ? stave.clone(_toString(module,"stave%d")) : stave; + for (int module = 1; module <= numsides; ++module) { + DetElement det = module>1 ? stave.clone(_toString(module,"stave%d")) : stave; PlacedVolume pv = envelopeVolume.placeVolume(sectVolume,Transform3D(Rotation(0,rotY,rotX), Translation3D(-posX,-posY,0))); // Not a valid volID: pv.addPhysVolID("stave", 0); @@ -60,7 +60,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { double detZ = dim.z(); double rmin = dim.rmin(); DetElement sdet(det_name,x_det.id()); - DetElement stave("stave0",x_det.id()); + DetElement stave("stave1",x_det.id()); Volume motherVol = lcdd.pickMotherVolume(sdet); for(xml_coll_t c(x_det,_U(layer)); c; ++c) { diff --git a/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp b/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe3742ebcbf987f4304aa79bd633571568f04583 --- /dev/null +++ b/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp @@ -0,0 +1,89 @@ +// $Id: TubeSegment_geo.cpp 633 2013-06-21 13:50:50Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== + +// Framework include files +#include "DD4hep/LCDD.h" +#include "DD4hep/Printout.h" +#include "DD4hep/Factories.h" +#include "DD4hep/IDDescriptor.h" +#include "DD4hep/VolumeManager.h" + +// C/C++ include files +#include <stdexcept> + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Geometry; + +static long test(LCDD& lcdd,int argc,char** argv) { + cout << "Processing plugin...." << endl; + typedef vector<PlacedVolume::VolID> VolIDs; + VolumeManager mgr = lcdd.volumeManager(); + DetElement sdet = lcdd.detector("HcalBarrel"); + SensitiveDetector sd = lcdd.sensitiveDetector("HcalBarrel"); + IDDescriptor iddesc = sd.readout().idSpec(); + + size_t ii, jj, kk; + VolIDs sysIds; + sysIds.push_back(PlacedVolume::VolID("system",sdet.id())); + sysIds.push_back(PlacedVolume::VolID("barrel",0)); + DetElement::Children::const_iterator i, j, k; + const DetElement::Children& staves = sdet.children(); + for (i=staves.begin(), ii=1; i!=staves.end(); ++i, ++ii) { + VolIDs staveIds(sysIds); + DetElement stave = (*i).second; + const DetElement::Children& layers = stave.children(); + PlacedVolume stave_pv = stave.placement(); + staveIds.insert(staveIds.end(),stave_pv.volIDs().begin(),stave_pv.volIDs().end()); + for (j=layers.begin(), jj=1; j!=layers.end(); ++j, ++jj) { + VolIDs layerIds(staveIds); + DetElement layer = (*j).second; + PlacedVolume layer_pv = layer.placement(); + const DetElement::Children& slices = layer.children(); + layerIds.insert(layerIds.end(),layer_pv.volIDs().begin(),layer_pv.volIDs().end()); + for (k=slices.begin(), kk=1; k!=slices.end(); ++k, ++kk) { + VolIDs sliceIds(layerIds); + DetElement slice = (*k).second; + PlacedVolume pv = slice.placement(); + sliceIds.insert(sliceIds.end(),pv.volIDs().begin(),pv.volIDs().end()); + if ( pv.volume().isSensitive() ) { + stringstream err, log; + VolumeManager::VolumeID vid = iddesc.encode(sliceIds); + DetElement det = mgr.lookupDetector(vid); + DetElement det_elem = mgr.lookupDetElement(vid); + PlacedVolume det_place = mgr.lookupPlacement(vid); + if ( pv.ptr() != det_place.ptr() ) { + err << "Wrong placement "; + } + else if ( det_elem.ptr() != slice.ptr() ) { + err << "Wrong associated detector element vid=" << (void*)vid + << " got " << det_elem.path() << " (" << (void*)det_elem.ptr() << ") " + << " instead of " << slice.path() << " (" << (void*)slice.ptr() << ")"; + } + else if ( det.ptr() != sdet.ptr() ) { + err << "Wrong associated detector "; + } + + const IDDescriptor::FieldMap& m = iddesc.fields(); + log << "IDS(" << pv.name() << "): "; + for(IDDescriptor::FieldMap::const_iterator l=m.begin(); l != m.end(); ++l) { + log << (*l).first << "=" << (*l).second->value(vid) << " "; + } + if ( !err.str().empty() ) { + printout(ERROR,"CLICSid_PolyhedraBarrel_VolMgrTest",(err.str()+" "+log.str()).c_str()); + throw runtime_error(err.str()); + } + printout(INFO,"CLICSid_PolyhedraBarrel_VolMgrTest",("Found Volume: "+log.str()).c_str()); + } + } + } + } + return 1; +} +DECLARE_APPLY(CLICSid_PolyhedraBarrel_VolMgrTest,test); diff --git a/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp b/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp index 58c4ad92d377d79b0df6cb399dab05e0146a9773..5cbde6b82acfc98108c86b31f85b78ada648687b 100644 --- a/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp +++ b/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp @@ -28,7 +28,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { double totalThickness = layering.totalThickness(); Volume envelopeVol(det_name+"_envelope",PolyhedraRegular(numsides,rmin,rmax,totalThickness),air); - int l_num = 0; + int l_num = 1; int layerType = 0; double layerZ = -totalThickness/2; @@ -36,12 +36,12 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { for(xml_coll_t c(x_det,_U(layer)); c; ++c) { xml_comp_t x_layer = c; - double l_thick = layering.layer(l_num)->thickness(); + double l_thick = layering.layer(l_num-1)->thickness(); string l_name = det_name + _toString(layerType,"_layer%d"); int l_repeat = x_layer.repeat(); Volume l_vol(l_name,PolyhedraRegular(numsides,rmin,rmax,l_thick),air); - int s_num = 0; + int s_num = 1; double sliceZ = -l_thick/2; for(xml_coll_t s(x_layer,_U(slice)); s; ++s) { xml_comp_t x_slice = s; diff --git a/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp b/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp index 33355eb07fcce7225fefc165462672a55b988d1d..fe27a57341155697d513d27703653e6223032199 100644 --- a/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp +++ b/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp @@ -29,7 +29,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { xml_comp_t m_env = x_mod.child(_U(module_envelope)); string m_nam = x_mod.nameStr(); Volume m_vol(det_name+"_"+m_nam,Box(m_env.width()/2,m_env.length()/2,m_env.thickness()/2),air); - int ncomponents = 0, sensor_number = 0; + int ncomponents = 0, sensor_number = 1; if ( volumes.find(m_nam) != volumes.end() ) { printout(ERROR,"SiTrackerBarrel","Logics error in building modules."); @@ -76,7 +76,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { int lay_id = x_layer.id(); string m_nam = x_layer.moduleStr(); Volume m_env = volumes[m_nam]; - string lay_nam = det_name+"_"+m_nam+_toString(lay_id,"_layer%d"); + string lay_nam = det_name+"_"+m_nam; Tube lay_tub (x_barrel.inner_r(),x_barrel.outer_r(),x_barrel.z_length()); Volume lay_vol (lay_nam,lay_tub,air); // Create the layer envelope volume. double phi0 = x_layout.phi0(); // Starting phi of first module. @@ -96,7 +96,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { double z_incr = (2.0 * z0) / (nz - 1); // Starting z for module placement along Z axis. double module_z = -z0; - int module = 0; + int module = 1; // Loop over the number of modules in phi. for (int ii = 0; ii < nphi; ii++) { diff --git a/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp b/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp index 983ca8f2d3946ae904106c16cbc60bdbe38d9175..c24cd89c999d28bbe1ee8f00471e621a4f74e67a 100644 --- a/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp +++ b/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp @@ -47,7 +47,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Volume m_volume(det_name+"_"+m_nam, Trapezoid(x1, x2, y1, y2, z), vacuum); m_volume.setVisAttributes(lcdd.visAttributes(x_mod.visStr())); - for(ci.reset(), n_sensor=0, c_id=0, posY=-y1; ci; ++ci, ++c_id) { + for(ci.reset(), n_sensor=1, c_id=0, posY=-y1; ci; ++ci, ++c_id) { xml_comp_t c = ci; double c_thick = c.thickness(); Material c_mat = lcdd.material(c.materialStr()); @@ -56,9 +56,9 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { c_vol.setVisAttributes(lcdd.visAttributes(c.visStr())); pv = m_volume.placeVolume(c_vol,Position(0,posY+c_thick/2,0)); - pv.addPhysVolID(_U(component),c_id); + //pv.addPhysVolID("component",c_id); if ( c.isSensitive() ) { - sdet.check(n_sensor > 1,"SiTrackerEndcap2::fromCompact: "+c_name+" Max of 2 modules allowed!"); + sdet.check(n_sensor > 2,"SiTrackerEndcap2::fromCompact: "+c_name+" Max of 2 modules allowed!"); pv.addPhysVolID("sensor",n_sensor); c_vol.setSensitiveDetector(sens); ++n_sensor; @@ -71,7 +71,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { for(xml_coll_t li(x_det,_U(layer)); li; ++li) { xml_comp_t x_layer(li); int l_id = x_layer.id(); - int mod_num = 0; + int mod_num = 1; for(xml_coll_t ri(x_layer,_U(ring)); ri; ++ri) { xml_comp_t x_ring = ri; double r = x_ring.r(); @@ -90,13 +90,11 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { double y = -r*std::sin(phi); DetElement module(sdet,m_base+"_pos",det_id); pv = assembly.placeVolume(m_vol,Transform3D(Rotation(0,-M_PI/2-phi,-M_PI/2),Position(x,y,zstart+dz))); - pv.addPhysVolID("barrel",1); - pv.addPhysVolID("layer", l_id).addPhysVolID("module",mod_num); + pv.addPhysVolID("barrel",1).addPhysVolID("layer", l_id).addPhysVolID("module",mod_num); module.setPlacement(pv); if ( reflect ) { pv = assembly.placeVolume(m_vol,Transform3D(Rotation(M_PI,-M_PI/2-phi,-M_PI/2),Position(x,y,-zstart-dz))); - pv.addPhysVolID("barrel",2); - pv.addPhysVolID("layer", l_id).addPhysVolID("module",mod_num); + pv.addPhysVolID("barrel",2).addPhysVolID("layer",l_id).addPhysVolID("module",mod_num); DetElement r_module(sdet,m_base+"_neg",det_id); r_module.setPlacement(pv); }