diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h index 85b6673ff9e19b93be514c9a69ebb6c26a5dd1b9..a7d4b02cce81579a9131d29b5c41d6d253ce7a68 100644 --- a/DDCore/include/DD4hep/Detector.h +++ b/DDCore/include/DD4hep/Detector.h @@ -51,15 +51,15 @@ namespace DD4hep { int combineHits; double ecut; std::string hitsCollection; - Readout readout; - Region region; - LimitSet limits; - Extensions extensions; - /// Default constructor - Object() : magic(magic_word()), verbose(0), combineHits(0), ecut(0.0), - hitsCollection(), readout(), region(), limits(), extensions() {} - /// Internal object destructor: release extension object(s) - ~Object(); + Readout readout; + Region region; + LimitSet limits; + Extensions extensions; + /// Default constructor + Object() : magic(magic_word()), verbose(0), combineHits(0), ecut(0.0), + hitsCollection(), readout(), region(), limits(), extensions() {} + /// Internal object destructor: release extension object(s) + ~Object(); }; protected: @@ -160,127 +160,127 @@ namespace DD4hep { typedef Ref_t Parent; typedef std::map<std::string,DetElement> Children; typedef std::map<const std::type_info*,void*> Extensions; - + enum { - COPY_NONE = 0, - COPY_PLACEMENT = 1<<0, - COPY_PARENT = 1<<1, - COPY_ALIGNMENT = 1<<2, - LAST + COPY_NONE = 0, + COPY_PLACEMENT = 1<<0, + COPY_PARENT = 1<<1, + COPY_ALIGNMENT = 1<<2, + LAST } CopyParameters; struct Object { unsigned int magic; int id; - /// Full path to this detector element. May be invalid - std::string path; + /// Full path to this detector element. May be invalid + std::string path; int combineHits; Volume volume; Readout readout; Alignment alignment; Conditions conditions; - PlacedVolume placement; - Parent parent; - Parent reference; + PlacedVolume placement; + Parent parent; + Parent reference; Children children; - Extensions extensions; - /// Intermediate buffer to store the transformation to the world coordination system - TGeoMatrix* worldTrafo; - /// Intermediate buffer to store the transformation to the parent detector element - TGeoMatrix* parentTrafo; - /// Intermediate buffer for the transformation to an arbitrary DetElement - TGeoMatrix* referenceTrafo; - /// The path to the placement of the detector element (if placed) - std::string placementPath; - - /// Default constructor + Extensions extensions; + /// Intermediate buffer to store the transformation to the world coordination system + TGeoMatrix* worldTrafo; + /// Intermediate buffer to store the transformation to the parent detector element + TGeoMatrix* parentTrafo; + /// Intermediate buffer for the transformation to an arbitrary DetElement + TGeoMatrix* referenceTrafo; + /// The path to the placement of the detector element (if placed) + std::string placementPath; + + /// Default constructor Object(); - /// Internal object destructor: release extension object(s) - virtual ~Object(); - /// Deep object copy to replicate DetElement trees e.g. for reflection - virtual Value<TNamed,Object>* clone(int new_id, int flag) const; - /// Conversion to reference object - operator Ref_t(); - /// Conversion to reference object - Ref_t asRef(); - /// Create cached matrix to transform to world coordinates - TGeoMatrix* worldTransformation(); - /// Create cached matrix to transform to parent coordinates - TGeoMatrix* parentTransformation(); - /// Create cached matrix to transform to reference coordinates - TGeoMatrix* referenceTransformation(); + /// Internal object destructor: release extension object(s) + virtual ~Object(); + /// Deep object copy to replicate DetElement trees e.g. for reflection + virtual Value<TNamed,Object>* clone(int new_id, int flag) const; + /// Conversion to reference object + operator Ref_t(); + /// Conversion to reference object + Ref_t asRef(); + /// Create cached matrix to transform to world coordinates + TGeoMatrix* worldTransformation(); + /// Create cached matrix to transform to parent coordinates + TGeoMatrix* parentTransformation(); + /// Create cached matrix to transform to reference coordinates + TGeoMatrix* referenceTransformation(); }; - + /// Additional data accessor Object& _data() const { return *data<Object>(); } /// Internal assert function to check conditions void check(bool condition, const std::string& msg) const; - - protected: - + + protected: + /// Templated destructor function template <typename T> static void _delete(void* ptr) { delete (T*)(ptr); } /// Templated copy constructor - template <typename T> static void* _copy(const void* ptr, DetElement elt) + template <typename T> static void* _copy(const void* ptr, DetElement elt) { return new T(*(dynamic_cast<const T*>((T*)ptr)),elt); } - + /// Add an extension object to the detector element void* i_addExtension(void* ptr, const std::type_info& info, void* (*copy)(const void*, DetElement), void (*destruct)(void*)); /// Access an existing extension object from the detector element void* i_extension(const std::type_info& info) const; - - public: - + + public: + /// Default constructor DetElement() : Ref_t() {} - + /// Default constructor template<typename Q> DetElement(Q* data, const std::string& name, const std::string& type) : Ref_t(data) { this->assign(data, name, type); } - + /// Templated constructor for handle conversions template<typename Q> DetElement(const Handle<Q>& e) : Ref_t(e) {} - + /// Constructor to copy handle DetElement(const DetElement& e) : Ref_t(e) {} - + /// Constructor for a new subdetector element DetElement(const std::string& name, const std::string& type, int id); - + /// Constructor for a new subdetector element DetElement(const std::string& name, int id); - + /// Constructor for a new subdetector element DetElement(DetElement parent, const std::string& name, int id); - + /// Clone (Deep copy) the DetElement structure with a new name DetElement clone(const std::string& new_name) const; - + /// Clone (Deep copy) the DetElement structure with a new name and new identifier DetElement clone(const std::string& new_name, int new_id) const; /// Extend the detector element with an arbitrary structure accessible by the type - template<typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) + template<typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) { return (IFACE*)i_addExtension(dynamic_cast<IFACE*>(c),typeid(IFACE),_copy<CONCRETE>,_delete<IFACE>); } - + /// Access extension element by the type template <class T> T* extension() const { return (T*)i_extension(typeid(T)); } - + /// Set the detector identifier int id() const; /// Setter: Combine hits attribite DetElement& setCombineHits(bool value, SensitiveDetector& sens); /// Getter: Combine hits attribite bool combineHits() const; - - /// Access detector type (structure, tracker, calorimeter, etc.). + + /// Access detector type (structure, tracker, calorimeter, etc.). /** Required for determination of G4 sensitive detector. */ std::string type() const; - /// Set detector type (structure, tracker, calorimeter, etc.). + /// Set detector type (structure, tracker, calorimeter, etc.). DetElement& setType(const std::string& typ); - + /// Path of the detector element (not necessarily identical to placement path!) std::string path() const; /// Access to the full path to the placed object @@ -288,8 +288,8 @@ namespace DD4hep { /// Set all attributes in one go DetElement& setAttributes(const LCDD& lcdd, const Volume& volume, - const std::string& region, - const std::string& limits, + const std::string& region, + const std::string& limits, const std::string& vis); /// Set Visualization attributes to the detector element @@ -299,19 +299,19 @@ namespace DD4hep { /// Set the limits to the detector element DetElement& setLimitSet(const LCDD& lcdd, const std::string& name, const Volume& volume); - /// Access the readout structure + /// Access the readout structure Readout readout() const; /// Assign readout definition DetElement& setReadout(const Readout& readout); - + /// Access to the logical volume of the daughter placement Volume volume() const; - + /// Access to the physical volume of this detector element PlacedVolume placement() const; /// Set the physical volumes of the detector element DetElement& setPlacement(const PlacedVolume& volume); - + /// Add new child to the detector structure DetElement& add(DetElement sub_element); /// Access to the list of children @@ -320,24 +320,24 @@ namespace DD4hep { DetElement child(const std::string& name) const; /// Access to the detector elements's parent DetElement parent() const; - + /// Set detector element for reference transformations. Will delete existing reference trafo. DetElement& setReference(DetElement reference); - + /// Transformation from local coordinates of the placed volume to the world system bool localToWorld(const Position& local, Position& global) const; /// Transformation from local coordinates of the placed volume to the parent system bool localToParent(const Position& local, Position& parent) const; /// Transformation from local coordinates of the placed volume to arbitrary parent system set as reference bool localToReference(const Position& local, Position& reference) const; - + /// Transformation from world coordinates of the local placed volume coordinates bool worldToLocal(const Position& global, Position& local) const; /// Transformation from world coordinates of the local placed volume coordinates bool parentToLocal(const Position& parent, Position& local) const; /// Transformation from world coordinates of the local placed volume coordinates bool referenceToLocal(const Position& reference, Position& local) const; - + }; } /* End namespace Geometry */ diff --git a/DDCore/python/lcdd.py b/DDCore/python/lcdd.py index b9147d656c03519b4091c21fc49e7f33e915951c..9d9e379f4e33998048612222fc66395b7f1a2130 100644 --- a/DDCore/python/lcdd.py +++ b/DDCore/python/lcdd.py @@ -127,10 +127,10 @@ def process_xmlfile(lcdd, file): current_xmlfile = last_xmlfile #-------------------------------------------------------------------------------- -def fromCompact(xmlfile): +def fromXML(xmlfile): print 'Converting Compact file: ', xmlfile lcdd = LCDD.getInstance() - lcdd.create() + #lcdd.create() process_xmlfile(lcdd, xmlfile) return lcdd @@ -160,7 +160,7 @@ def process_info(lcdd, elem): def process_define(lcdd, elem): for c in elem.findall('constant'): #print 'Adding constant ...', c.get('name') - lcdd.addConstant(Constant(lcdd, c.get('name'),c.get('value'))) + lcdd.addConstant(Constant(c.get('name'),c.get('value'))) _toDictionary(c.get('name'),c.get('value')) #-- Make it known to the evaluator constants[c.get('name')] = c.getF('value') @@ -235,7 +235,7 @@ def process_material(lcdd, m): def process_display(lcdd, elem): for v in elem.findall('vis'): #print 'Adding vis ...', v.name - visattr = VisAttr(lcdd, v.name) + visattr = VisAttr(v.name) r,g,b = 1.,1.,1. if 'r' in v.keys() : r = v.getF('r') if 'g' in v.keys() : g = v.getF('g') diff --git a/DDExamples/ILDExDet/drivers/ILDExSIT.py b/DDExamples/ILDExDet/drivers/ILDExSIT.py index 4267fd11c3a4b6c91e5d33ab8748a57051530ef3..be56c7fb0841b4dfbb3596bd81297d2268866730 100644 --- a/DDExamples/ILDExDet/drivers/ILDExSIT.py +++ b/DDExamples/ILDExDet/drivers/ILDExSIT.py @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------------- def detector_ILDExSIT(lcdd, det): - sit = DetElement(lcdd, det.name, det.type, det.id) + sit = DetElement(det.name, det.type, det.id) mother = lcdd.worldVolume() for layer in det.findall('layer'): support = layer.find('support') @@ -15,17 +15,17 @@ def detector_ILDExSIT(lcdd, det): support_radius = sens_radius + sens_thick/2. + supp_thick/2. width = 2.*tan(dphi/2.)*(sens_radius-sens_thick/2.) - ladderbox = Box(lcdd, layername+'_ladder_box', (sens_thick+supp_thick)/2.,width/2.,zhalf) - laddervol = Volume(lcdd, layername+'_ladder', ladderbox, lcdd.material('Air')) + ladderbox = Box(layername+'_ladder_box', (sens_thick+supp_thick)/2.,width/2.,zhalf) + laddervol = Volume(layername+'_ladder', ladderbox, lcdd.material('Air')) laddervol.setVisAttributes(lcdd.visAttributes(layer.vis)) - sensbox = Box(lcdd, layername+'_sens_box', sens_thick/2.,width/2.,zhalf) - sensvol = Volume(lcdd, layername+'_sens_volume', sensbox, lcdd.material(ladder.material)) + sensbox = Box(layername+'_sens_box', sens_thick/2.,width/2.,zhalf) + sensvol = Volume(layername+'_sens_volume', sensbox, lcdd.material(ladder.material)) sensvol.setVisAttributes(lcdd.visAttributes(layer.vis)) laddervol.placeVolume(sensvol, Position(-(sens_thick+supp_thick)/2.+sens_thick/2.,0,0)) - suppbox = Box(lcdd, layername+'_supp_box', supp_thick/2.,width/2.,zhalf) - suppvol = Volume(lcdd,layername+'_supp', suppbox,lcdd.material(support.material)) + suppbox = Box(layername+'_supp_box', supp_thick/2.,width/2.,zhalf) + suppvol = Volume(layername+'_supp', suppbox,lcdd.material(support.material)) suppvol.setVisAttributes(lcdd.visAttributes(support.vis)) laddervol.placeVolume(suppvol, Position(-(sens_thick+supp_thick)/2.+sens_thick/2.+supp_thick/2.,0,0)) diff --git a/DDExamples/ILDExDet/drivers/ILDExTPC.py b/DDExamples/ILDExDet/drivers/ILDExTPC.py index d27e0f42f3c05d334b02b76467353a0649b01c1c..c579ecbddd77c839b441bcaa8150c257cd9e6c8f 100644 --- a/DDExamples/ILDExDet/drivers/ILDExTPC.py +++ b/DDExamples/ILDExDet/drivers/ILDExTPC.py @@ -4,23 +4,23 @@ from ROOT import DD4hep def detector_ILDExTPC(lcdd, det): tube = det.find('tubs') material = det.find('material') - tpc_de = DD4hep.ILDExTPC(lcdd, det.name, det.type, det.id) - tpc_tube = Tube(lcdd, det.name+'_tube', tube.rmin, tube.rmax, tube.zhalf) - tpc_vol = Volume(lcdd, det.name+'_envelope', tpc_tube, lcdd.material(material.name)) + tpc_de = DD4hep.ILDExTPC(det.name, det.type, det.id) + tpc_tube = Tube(det.name+'_tube', tube.rmin, tube.rmax, tube.zhalf) + tpc_vol = Volume(det.name+'_envelope', tpc_tube, lcdd.material(material.name)) for px in det.findall('detector'): px_tube = px.find('tubs') px_pos = px.find('position') px_rot = px.find('rotation') px_mat = px.find('material') - part_det = DetElement(lcdd, px.name, px.type, px.id) - part_tube = Tube(lcdd,px.name+'_tube',px_tube.rmin, px_tube.rmax, px_tube.zhalf) - part_vol = Volume(lcdd, px.name, part_tube, lcdd.material(px_mat.name)) + part_det = DetElement(px.name, px.type, px.id) + part_tube = Tube(px.name+'_tube',px_tube.rmin, px_tube.rmax, px_tube.zhalf) + part_vol = Volume(px.name, part_tube, lcdd.material(px_mat.name)) part_vol.setVisAttributes(lcdd.visAttributes(px.vis)) - part_det.addPlacement(tpc_vol.placeVolume(part_vol, getPosition(px_pos), getRotation(px_rot))) + part_det.setPlacement(tpc_vol.placeVolume(part_vol, getPosition(px_pos), getRotation(px_rot))) if px.id == 0 : tpc_de.setInnerWall(part_det) elif px.id == 1 : tpc_de.setOuterWall(part_det) - elif px.id == 2 : tpc_de.setEndPlate(part_det) + elif px.id == 2 : tpc_de.setEndPlate(part_det,1) elif px.id == 5 : tpc_de.setGasVolume(part_det) tpc_de.add(part_det) tpc_vol.setVisAttributes(lcdd.visAttributes(det.vis)) diff --git a/DDExamples/ILDExDet/drivers/ILDExVXD.py b/DDExamples/ILDExDet/drivers/ILDExVXD.py index e585c5c5d80a9796d92417dc217906d102b8aef8..725fb27b85b721977d80813c63fb6e84cadd78ed 100644 --- a/DDExamples/ILDExDet/drivers/ILDExVXD.py +++ b/DDExamples/ILDExDet/drivers/ILDExVXD.py @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------------- def detector_ILDExVXD(lcdd, det): - vdx = DetElement(lcdd, det.name, det.type, det.id) + vdx = DetElement(det.name, det.type, det.id) mother = lcdd.worldVolume() for layer in det.findall('layer'): support = layer.find('support') @@ -13,16 +13,16 @@ def detector_ILDExVXD(lcdd, det): supp_radius = ladder.radius + sens_thick/2. + supp_thick/2. width = 2.*tan(dphi/2.)*(ladder.radius-sens_thick/2.) - ladderbox = Box(lcdd, layername+'_ladder_box', (sens_thick+supp_thick)/2., width/2., ladder.zhalf) - laddervol = Volume(lcdd, layername+'_ladder', ladderbox, lcdd.material('Air')) + ladderbox = Box(layername+'_ladder_box', (sens_thick+supp_thick)/2., width/2., ladder.zhalf) + laddervol = Volume(layername+'_ladder', ladderbox, lcdd.material('Air')) - sensbox = Box(lcdd, layername+'_sens_box', sens_thick/2., width/2., ladder.zhalf) - sensvol = Volume(lcdd, layername+'_sens', sensbox, lcdd.material(ladder.material)) + sensbox = Box(layername+'_sens_box', sens_thick/2., width/2., ladder.zhalf) + sensvol = Volume(layername+'_sens', sensbox, lcdd.material(ladder.material)) sensvol.setVisAttributes(lcdd.visAttributes(layer.vis)) laddervol.placeVolume(sensvol, Position(-(sens_thick+supp_thick)/2.+sens_thick/2.,0,0)) - suppbox = Box(lcdd, layername+'_supp_box', supp_thick/2.,width/2.,ladder.zhalf) - suppvol = Volume(lcdd,layername+'_supp', suppbox, lcdd.material(support.material)) + suppbox = Box(layername+'_supp_box', supp_thick/2.,width/2.,ladder.zhalf) + suppvol = Volume(layername+'_supp', suppbox, lcdd.material(support.material)) suppvol.setVisAttributes(lcdd.visAttributes(support.vis)) laddervol.placeVolume(suppvol, Position(-(sens_thick+supp_thick)/2.+sens_thick/2.+supp_thick/2.,0,0))