diff --git a/DDCore/include/DD4hep/DetFactoryHelper.h b/DDCore/include/DD4hep/DetFactoryHelper.h index 49a04b363feb64fdbc9d5b1ee84509134131a8a8..363e23b7ecdf6bfbb0ed44299143d92bb0552f24 100644 --- a/DDCore/include/DD4hep/DetFactoryHelper.h +++ b/DDCore/include/DD4hep/DetFactoryHelper.h @@ -12,6 +12,7 @@ #include "XML/XMLDetector.h" #include "DD4hep/LCDD.h" #include "DD4hep/Factories.h" +#include "DD4hep/TGeoUnits.h" // Shortcuts to elements of the XML namespace typedef DD4hep::XML::Tag_t xml_tag_t; diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index 8fa9d24f029857b182e723569277ae403e9abeb0..bb1e4154bf2e98b5a6c6e0f205929a0a2e1bf72f 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -30,7 +30,7 @@ class TGeoManager; #define RAD_2_DEGREE 57.295779513082320876798154814105 #endif #ifndef DEGREE_2_RAD -#define DEGREE_2_RAD 0.017453292519943295769236907684886 +#define DEGREE_2_RAD 0.0174532925199432957692369076848 #endif #ifndef CM_2_MM #define CM_2_MM 10.0 diff --git a/DDCore/include/DD4hep/InstanceCount.h b/DDCore/include/DD4hep/InstanceCount.h index 9ad1756d0e56c4c88fbd499ca8385f8e562efc15..cbbb686f4cace0158dabc0e063e323741c7043a1 100644 --- a/DDCore/include/DD4hep/InstanceCount.h +++ b/DDCore/include/DD4hep/InstanceCount.h @@ -45,14 +45,16 @@ namespace DD4hep { counter_t m_count; /// Increment counter value counter_t m_tot; + /// Maximum number of simultaneous instances + counter_t m_max; public: /// Default constructor Counter() - : m_count(0), m_tot(0) { + : m_count(0), m_tot(0), m_max(0) { } /// Copy constructor Counter(const Counter& c) - : m_count(c.m_count), m_tot(c.m_tot) { + : m_count(c.m_count), m_tot(c.m_tot), m_max(c.m_max) { } /// Destructor ~Counter() { @@ -61,6 +63,7 @@ namespace DD4hep { void increment() { ++m_count; ++m_tot; + m_max = std::max(m_max,m_count); } /// Decrement counter void decrement() { @@ -74,6 +77,10 @@ namespace DD4hep { counter_t total() const { return m_tot; } + /// Access maximum counter value + counter_t maximum() const { + return m_max; + } }; public: /// Standard Constructor - No need to call explicitly diff --git a/DDCore/include/DD4hep/Plugins.h b/DDCore/include/DD4hep/Plugins.h index 087a2d1bc58fe099fe169a9a47d8f010ec5f364c..c6e460058b8c1dff8ab3b59ed4b68589e7002250 100644 --- a/DDCore/include/DD4hep/Plugins.h +++ b/DDCore/include/DD4hep/Plugins.h @@ -10,7 +10,9 @@ #define DD4HEP_PLUGINS_H // ROOT include files +#ifndef __CINT__ #include "Reflex/PluginService.h" +#endif /* * DD4hep namespace declaration diff --git a/DDCore/include/DD4hep/Primitives.h b/DDCore/include/DD4hep/Primitives.h index d119cfdb8b5a843c085867be7f86acaf1a3736db..0b4ccce097867c90eb79ebdd7d7be64c863070e3 100644 --- a/DDCore/include/DD4hep/Primitives.h +++ b/DDCore/include/DD4hep/Primitives.h @@ -99,7 +99,6 @@ namespace DD4hep { template <typename M> ReleaseObjects<M> releaseObjects(M& m) { return ReleaseObjects<M>(m); } - /* * Geometry namespace declaration */ diff --git a/DDCore/include/DD4hep/Printout.h b/DDCore/include/DD4hep/Printout.h index c17d7bc18821901107e2d4d2aebb4e42270055d9..bcfcf0ca2255aaa863b20d124eaf6cc87963ee9c 100644 --- a/DDCore/include/DD4hep/Printout.h +++ b/DDCore/include/DD4hep/Printout.h @@ -188,11 +188,11 @@ namespace DD4hep { void operator()() const; }; -/// Helper function to print booleans in format YES/NO + /// Helper function to print booleans in format YES/NO inline const char* yes_no(bool value) { return value ? "YES" : "NO "; } -/// Helper function to print booleans in format true/false + /// Helper function to print booleans in format true/false inline const char* true_false(bool value) { return value ? "true " : "false"; } diff --git a/DDCore/include/DD4hep/Segmentations.h b/DDCore/include/DD4hep/Segmentations.h index 51d512fd09ca4a58df802c92f19e47622c70b9bf..8e7ccb26fc660266a1ffe3c1c3aed25efbe96245 100644 --- a/DDCore/include/DD4hep/Segmentations.h +++ b/DDCore/include/DD4hep/Segmentations.h @@ -121,6 +121,7 @@ namespace DD4hep { /// Default constructor Data(BitField64* decoder = 0) : Object(), BaseSegmentation(decoder), nphi(0), ntheta(0), nz(0) { + segmentation = this; } /// Default destructor virtual ~Data(); @@ -165,6 +166,7 @@ namespace DD4hep { Data(BitField64* decoder = 0) : Object(), BaseSegmentation(decoder) { grid_size_phi = grid_size_theta = grid_size_z = 0; + segmentation = this; } /// Default destructor virtual ~Data(); @@ -205,6 +207,7 @@ namespace DD4hep { Data(BitField64* decoder = 0) : Object(), BaseSegmentation(decoder) { nphi = ntheta = nz = 0; + segmentation = this; } /// Default destructor virtual ~Data(); @@ -241,6 +244,7 @@ namespace DD4hep { /// Default constructor Data(BitField64* decoder = 0) : Object(), DDSegmentation::CartesianGridXY(decoder) { + segmentation = this; } /// Default destructor virtual ~Data(); @@ -271,6 +275,7 @@ namespace DD4hep { /// Default constructor Data(BitField64* decoder = 0) : Object(), DDSegmentation::CartesianGridXYZ(decoder) { + segmentation = this; } /// Default destructor virtual ~Data(); diff --git a/DDCore/include/DD4hep/Shapes.h b/DDCore/include/DD4hep/Shapes.h index 9e7f7b26832e6612ae782a49d61ada16317fd89e..4650cbfc276f94e2864fbc8647d34bfac1d341ea 100644 --- a/DDCore/include/DD4hep/Shapes.h +++ b/DDCore/include/DD4hep/Shapes.h @@ -190,11 +190,11 @@ namespace DD4hep { /// Constructor to create a new ConeSegment object ConeSegment(double dz, double rmin1, double rmax1, double rmin2, double rmax2, double phi1 = 0.0, - double phi2 = 2.0 * M_PI); + double phi2 = 2.0 * M_PI*RAD_2_DEGREE); /// Set the cone segment dimensions ConeSegment& setDimensions(double dz, double rmin1, double rmax1, double rmin2, double rmax2, double phi1 = 0.0, - double phi2 = 2.0 * M_PI); + double phi2 = 2.0 * M_PI*RAD_2_DEGREE); }; /**@class Tube Shapes.h @@ -227,7 +227,12 @@ namespace DD4hep { } /// Constructor to create a new anonymous tube object with attribute initialization - Tube(double rmin, double rmax, double z, double deltaPhi = 2 * M_PI) { + Tube(double rmin, double rmax, double z) { + make("", rmin, rmax, z, 0, 2*M_PI*RAD_2_DEGREE); + } + + /// Constructor to create a new anonymous tube object with attribute initialization + Tube(double rmin, double rmax, double z, double deltaPhi) { make("", rmin, rmax, z, 0, deltaPhi); } @@ -237,7 +242,12 @@ namespace DD4hep { } /// Legacy: Constructor to create a new identifiable tube object with attribute initialization - Tube(const std::string& name, double rmin, double rmax, double z, double deltaPhi = 2 * M_PI) { + Tube(const std::string& name, double rmin, double rmax, double z) { + make(name, rmin, rmax, z, 0, 2*M_PI*RAD_2_DEGREE); + } + + /// Legacy: Constructor to create a new identifiable tube object with attribute initialization + Tube(const std::string& name, double rmin, double rmax, double z, double deltaPhi) { make(name, rmin, rmax, z, 0, deltaPhi); } @@ -331,7 +341,7 @@ namespace DD4hep { : Solid_type<TGeoTorus>(e) { } /// Constructor to create a new anonymous object with attribute initialization - Torus(double r, double rmin, double rmax, double phi = M_PI, double delta_phi = 2. * M_PI); + Torus(double r, double rmin, double rmax, double phi = M_PI*RAD_2_DEGREE, double delta_phi = 2. * M_PI*RAD_2_DEGREE); /// Set the Torus dimensions Torus& setDimensions(double r, double rmin, double rmax, double phi, double delta_phi); }; @@ -347,8 +357,8 @@ namespace DD4hep { : Solid_type<TGeoSphere>(e) { } /// Constructor to create a new anonymous object with attribute initialization - Sphere(double rmin, double rmax, double theta = 0., double delta_theta = M_PI, double phi = 0.0, - double delta_phi = 2. * M_PI); + Sphere(double rmin, double rmax, double theta = 0., double delta_theta = M_PI*RAD_2_DEGREE, double phi = 0.0, + double delta_phi = 2. * M_PI*RAD_2_DEGREE); /// Set the Sphere dimensions Sphere& setDimensions(double rmin, double rmax, double theta, double delta_theta, double phi, double delta_phi); }; diff --git a/DDCore/src/Evaluator/setSystemOfUnits.cpp b/DDCore/src/Evaluator/setSystemOfUnits.cpp index ef9732d2302f6f5be57f2dd261adc8f5b9b24271..a8d15dd490cbd0a6f46c8a80a2319983e628fea7 100644 --- a/DDCore/src/Evaluator/setSystemOfUnits.cpp +++ b/DDCore/src/Evaluator/setSystemOfUnits.cpp @@ -81,14 +81,15 @@ void Evaluator::setSystemOfUnits(double meter, // // ====================================================================== + const double pi = 3.14159265358979323846; // Plane angle - const double rad = 1.; + //const double rad = 1.; // Geant4 (rad units) + const double rad = 180.0/pi; // Degree units setVariable("radian", rad); setVariable("rad", rad); setVariable("milliradian", milli_ * rad); setVariable("mrad", milli_ * rad); - const double pi = 3.14159265358979323846; const double deg = rad*pi/180.; setVariable("degree", deg); setVariable("deg", deg); diff --git a/DDCore/src/ExpressionEvaluator.cpp b/DDCore/src/ExpressionEvaluator.cpp index 17d409ff660a74000c96de5622e86ee15524977e..2d060576fae7165b7da476499d963d0a9b8e785f 100644 --- a/DDCore/src/ExpressionEvaluator.cpp +++ b/DDCore/src/ExpressionEvaluator.cpp @@ -13,8 +13,21 @@ namespace { // Initialize numerical expressions parser with the standard math functions // and the system of units used by Gaudi (Geant4) DD4hep::evaluator().setStdMath(); - DD4hep::evaluator().setSystemOfUnits(1.e+3, 1. / 1.60217733e-25, 1.e+9, 1. / 1.60217733e-10, 1.0, 1.0, 1.0); + // ====================================================================================== + // Geant4 units + // Geant4: kilogram = joule*s*s/(m*m) 1/e_SI * 1e-6 * 1e9 1e9 / 1e3 / 1e3 = 1. / 1.60217733e-25 + //DD4hep::evaluator().setSystemOfUnits(1.e+3, 1. / 1.60217733e-25, 1.e+9, 1. / 1.60217733e-10, 1.0, 1.0, 1.0); + // ====================================================================================== + // CGS units + //DD4hep::evaluator().setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0); + // ====================================================================================== + // DDG4 units (TGeo) 1 sec = 10^9 [nsec] + // 1 Coulomb = 1/e As + // Ampere = C/s = 1/e * As / s = 1. / 1.60217733e-19 + // kilogram = joule*s*s/(m*m) 1/e_SI * 1 *1 / 1e2 / 1e2 + DD4hep::evaluator().setSystemOfUnits(1.e+2, 1./1.60217733e-6, 1.0, 1./1.60217733e-19, 1.0, 1.0, 1.0); } + }; _Init s_init; } diff --git a/DDCore/src/InstanceCount.cpp b/DDCore/src/InstanceCount.cpp index 4651006a0301776652b83d9b96f58a4e81b7c691..e1bb6278c67d9e01e5353720cd31b83f350ef36c 100644 --- a/DDCore/src/InstanceCount.cpp +++ b/DDCore/src/InstanceCount.cpp @@ -81,30 +81,33 @@ void InstanceCount::dump(int typ) { if ((typ & STRING) && s_strCounts.get()) { if (s_strCounts->begin() != s_strCounts->end()) { StringCounter::const_iterator i; - std::cout << "+----------------------------------------------------------------+" << std::endl; - std::cout << "| I n s t a n c e c o u n t e r s b y N A M E |" << std::endl; - std::cout << "+----------+---------+-------------------------------------------+" << std::endl; - std::cout << "| Total | Leaking | Type identifier |" << std::endl; - std::cout << "+----------+---------+-------------------------------------------+" << std::endl; + std::cout << "+-----------------------------------------------------------------------+" << std::endl; + std::cout << "| I n s t a n c e c o u n t e r s b y N A M E |" << std::endl; + std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; + std::cout << "| Total | Max | Leaking | Type identifier |" << std::endl; + std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; for (i = s_strCounts->begin(); i != s_strCounts->end(); ++i) { - std::cout << "|" << std::setw(10) << (*i).second->total() << "|" << std::setw(9) << (*i).second->value() << "|" - << (*i).first << std::endl; + std::cout << "|" << std::setw(10) << (*i).second->total() + << "|" << std::setw(6) << (*i).second->maximum() + << "|" << std::setw(9) << (*i).second->value() + << "|" << (*i).first << std::endl; } need_footer = true; } } - if ((typ & TYPEINFO) && s_typCounts.get()) { if (s_typCounts->begin() != s_typCounts->end()) { TypeCounter::const_iterator i; - std::cout << "+----------------------------------------------------------------+" << std::endl; - std::cout << "| I n s t a n c e c o u n t e r s b y T Y P E I N F O |" << std::endl; - std::cout << "+----------+---------+-------------------------------------------+" << std::endl; - std::cout << "| Total | Leaking | Type identifier |" << std::endl; - std::cout << "+----------+---------+-------------------------------------------+" << std::endl; + std::cout << "+-----------------------------------------------------------------------+" << std::endl; + std::cout << "| I n s t a n c e c o u n t e r s b y T Y P E I N F O |" << std::endl; + std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; + std::cout << "| Total | Max | Leaking | Type identifier |" << std::endl; + std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; for (i = s_typCounts->begin(); i != s_typCounts->end(); ++i) { - std::cout << "|" << std::setw(10) << (*i).second->total() << "|" << std::setw(9) << (*i).second->value() << "|" - << typeName(*((*i).first)) << std::endl; + std::cout << "|" << std::setw(10) << (*i).second->total() + << "|" << std::setw(6) << (*i).second->maximum() + << "|" << std::setw(9) << (*i).second->value() + << "|" << typeName(*((*i).first)) << std::endl; } need_footer = true; } diff --git a/DDCore/src/MatrixHelpers.cpp b/DDCore/src/MatrixHelpers.cpp index 9a69f5450c80ebd5089e6ef9d8b0d96e84c438fe..4e82874375b190eff43768901e2ac1ed1f45ecab 100644 --- a/DDCore/src/MatrixHelpers.cpp +++ b/DDCore/src/MatrixHelpers.cpp @@ -18,7 +18,7 @@ TGeoIdentity* DD4hep::Geometry::identityTransform() { } TGeoTranslation* DD4hep::Geometry::_translation(const Position& pos) { - return new TGeoTranslation("", pos.X() * MM_2_CM, pos.Y() * MM_2_CM, pos.Z() * MM_2_CM); + return new TGeoTranslation("", pos.X(), pos.Y(), pos.Z()); } TGeoRotation* DD4hep::Geometry::_rotationZYX(const RotationZYX& rot) { @@ -36,9 +36,6 @@ TGeoHMatrix* DD4hep::Geometry::_transform(const Transform3D& trans) { Double_t* t = tr->GetTranslation(); Double_t* r = tr->GetRotationMatrix(); trans.GetComponents(r[0],r[1],r[2],t[0],r[3],r[4],r[5],t[1],r[6],r[7],r[8],t[2]); - t[0] *= MM_2_CM; - t[1] *= MM_2_CM; - t[2] *= MM_2_CM; #endif double t[3]; RotationZYX rot; @@ -49,8 +46,8 @@ TGeoHMatrix* DD4hep::Geometry::_transform(const Transform3D& trans) { tr->RotateY(rot.Theta() * RAD_2_DEGREE); tr->RotateX(rot.Psi() * RAD_2_DEGREE); pos.GetCoordinates(t); - tr->SetDx(t[0] * MM_2_CM); - tr->SetDy(t[1] * MM_2_CM); - tr->SetDz(t[2] * MM_2_CM); + tr->SetDx(t[0]); + tr->SetDy(t[1]); + tr->SetDz(t[2]); return tr; } diff --git a/DDCore/src/Readout.cpp b/DDCore/src/Readout.cpp index 4111bac3b58bbc82741feac4d03a4a2e54bcbd11..32a634ef2aa729ba9da47adcf0a1741b60b4c10a 100644 --- a/DDCore/src/Readout.cpp +++ b/DDCore/src/Readout.cpp @@ -41,7 +41,7 @@ void Readout::setIDDescriptor(const Ref_t& new_descriptor) const { Segmentation seg = data<Object>()->segmentation; IDDescriptor id = new_descriptor; if (seg.isValid()) { - //seg.segmentation()->setDecoder(id.decoder()); + seg.segmentation()->setDecoder(id.decoder()); } return; } diff --git a/DDCore/src/Segementations.cpp b/DDCore/src/Segementations.cpp index 92100e39b38bee78b5e2171c4a001b4761beab32..6adc202fd9e60b0774b9ae42369eded259b45f50 100644 --- a/DDCore/src/Segementations.cpp +++ b/DDCore/src/Segementations.cpp @@ -20,11 +20,18 @@ namespace { void not_implemented_call(const char* tag) { throw runtime_error(tag); } + template <typename T> T& _obj(const DDSegmentation::Segmentation* ptr) { + // ---> This would be so much more efficient, but sissies refused.... + // T* p = (T*)(((const char*)ptr) - sizeof(Segmentation::Object)); + // return *p; + const T* p = dynamic_cast<const T*>(ptr); + return *(T*)p; + } } /// Standard constructor Segmentation::Object::Object() - : magic(magic_word()), useForHitPosition(0) { + : magic(magic_word()), useForHitPosition(0), segmentation(0) { InstanceCount::increment(this); } @@ -39,22 +46,26 @@ std::string Segmentation::type() const { } bool Segmentation::useForHitPosition() const { - return object<Object>().useForHitPosition != 0; + return _obj<Object>(ptr()).useForHitPosition != 0; } /// Segmentation type string SegmentationParams::type() const { - return object<Object>().segmentation->type(); + return _obj<Object>(ptr()).segmentation->type(); } /// Access to the parameters SegmentationParams::Parameters SegmentationParams::parameters() const { - return object<Object>().segmentation->parameters(); + Object& o = _obj<Object>(ptr()); + if (o.segmentation != 0) { + return o.segmentation->parameters(); + } + throw runtime_error("DD4hep: The segmentation object " + string(type()) + " is invalid!"); } /// Access segmentation object DD4hep::DDSegmentation::Segmentation* Segmentation::segmentation() const { - Object& o = object<Object>(); + Object& o = _obj<Object>(ptr()); if (o.segmentation != 0) return o.segmentation; throw runtime_error( @@ -91,32 +102,32 @@ ProjectiveCylinder::ProjectiveCylinder(LCDD&) /// Accessors: get number of bins in theta int ProjectiveCylinder::thetaBins() const { - return object<Data>().ntheta; + return _obj<Data>(ptr()).ntheta; } /// Accessors: get number of bins in phi int ProjectiveCylinder::phiBins() const { - return object<Data>().nphi; + return _obj<Data>(ptr()).nphi; } /// Accessors: get number of bins in z int ProjectiveCylinder::zBins() const { - return object<Data>().nz; + return _obj<Data>(ptr()).nz; } /// Accessors: set number of bins in theta void ProjectiveCylinder::setThetaBins(int value) { - object<Data>().ntheta = value; + _obj<Data>(ptr()).ntheta = value; } /// Accessors: set grid size in Y void ProjectiveCylinder::setPhiBins(int value) { - object<Data>().nphi = value; + _obj<Data>(ptr()).nphi = value; } /// Accessors: set number of bins in Z void ProjectiveCylinder::setZBins(int value) { - object<Data>().nz = value; + _obj<Data>(ptr()).nz = value; } /// Default destructor @@ -148,22 +159,22 @@ NonProjectiveCylinder::NonProjectiveCylinder(LCDD&) /// Accessors: get size of bins in Z double NonProjectiveCylinder::gridSizeZ() const { - return object<Data>().grid_size_z; + return _obj<Data>(ptr()).grid_size_z; } /// Accessors: get size of bins in phi double NonProjectiveCylinder::gridSizePhi() const { - return object<Data>().grid_size_phi; + return _obj<Data>(ptr()).grid_size_phi; } /// Accessors: set number of bins in theta void NonProjectiveCylinder::setThetaBinSize(double value) { - object<Data>().grid_size_phi = value; + _obj<Data>(ptr()).grid_size_phi = value; } /// Accessors: set grid size in Y void NonProjectiveCylinder::setPhiBinSize(double value) { - object<Data>().grid_size_z = value; + _obj<Data>(ptr()).grid_size_z = value; } /// Default destructor @@ -195,22 +206,22 @@ ProjectiveZPlane::ProjectiveZPlane(LCDD&) /// Accessors: get number of bins in phi int ProjectiveZPlane::phiBins() const { - return object<Data>().nphi; + return _obj<Data>(ptr()).nphi; } /// Accessors: get number of bins in theta int ProjectiveZPlane::thetaBins() const { - return object<Data>().ntheta; + return _obj<Data>(ptr()).ntheta; } /// Accessors: set number of bins in theta void ProjectiveZPlane::setThetaBins(int value) { - object<Data>().ntheta = value; + _obj<Data>(ptr()).ntheta = value; } /// Accessors: set grid size in Y void ProjectiveZPlane::setPhiBins(int value) { - object<Data>().nphi = value; + _obj<Data>(ptr()).nphi = value; } /// Default destructor @@ -224,22 +235,22 @@ GridXY::GridXY(LCDD&, const std::string& typ) /// Accessors: get grid size in X double GridXY::getGridSizeX() const { - return object<Data>().getGridSizeX(); + return _obj<Data>(ptr()).getGridSizeX(); } /// Accessors: get grid size in Y double GridXY::getGridSizeY() const { - return object<Data>().getGridSizeY(); + return _obj<Data>(ptr()).getGridSizeY(); } /// Accessors: set grid size in X void GridXY::setGridSizeX(double value) { - object<Data>().setGridSizeX(value); + _obj<Data>(ptr()).setGridSizeX(value); } /// Accessors: set grid size in Y void GridXY::setGridSizeY(double value) { - object<Data>().setGridSizeY(value); + _obj<Data>(ptr()).setGridSizeY(value); } /// Default destructor @@ -254,30 +265,30 @@ GridXYZ::GridXYZ(LCDD&, const std::string& typ) /// Accessors: get grid size in X double GridXYZ::getGridSizeX() const { - return object<Data>().getGridSizeX(); + return _obj<Data>(ptr()).getGridSizeX(); } /// Accessors: get grid size in Y double GridXYZ::getGridSizeY() const { - return object<Data>().getGridSizeY(); + return _obj<Data>(ptr()).getGridSizeY(); } /// Accessors: get grid size in Z double GridXYZ::getGridSizeZ() const { - return object<Data>().getGridSizeZ(); + return _obj<Data>(ptr()).getGridSizeZ(); } /// Accessors: set grid size in X void GridXYZ::setGridSizeX(double value) { - object<Data>().setGridSizeX(value); + _obj<Data>(ptr()).setGridSizeX(value); } /// Accessors: set grid size in Y void GridXYZ::setGridSizeY(double value) { - object<Data>().setGridSizeY(value); + _obj<Data>(ptr()).setGridSizeY(value); } /// Accessors: set grid size in Z void GridXYZ::setGridSizeZ(double value) { - object<Data>().setGridSizeZ(value); + _obj<Data>(ptr()).setGridSizeZ(value); } diff --git a/DDCore/src/Shapes.cpp b/DDCore/src/Shapes.cpp index b5a37cf0dca16e6845185da36c27a536b720a53a..e0d309a961f23ac34cfd3a10855ab3239ebeba14 100644 --- a/DDCore/src/Shapes.cpp +++ b/DDCore/src/Shapes.cpp @@ -50,34 +50,34 @@ template <typename T> const char* Solid_type<T>::name() const { } void Box::make(const string& name, double x, double y, double z) { - _assign(new TGeoBBox(x * MM_2_CM, y * MM_2_CM, z * MM_2_CM), name, "box", true); + _assign(new TGeoBBox(x, y, z), name, "box", true); } /// Set the box dimensionsy Box& Box::setDimensions(double x, double y, double z) { - double params[] = { x * MM_2_CM, y * MM_2_CM, z * MM_2_CM }; + double params[] = { x, y, z}; _setDimensions(params); return *this; } /// Access half "length" of the box double Box::x() const { - return this->ptr()->GetDX() * CM_2_MM; + return this->ptr()->GetDX(); } /// Access half "width" of the box double Box::y() const { - return this->ptr()->GetDY() * CM_2_MM; + return this->ptr()->GetDY(); } /// Access half "depth" of the box double Box::z() const { - return this->ptr()->GetDZ() * CM_2_MM; + return this->ptr()->GetDZ(); } /// Constructor to be used when creating a new object Polycone::Polycone(double start, double delta) { - _assign(new TGeoPcon(RAD_2_DEGREE * start, RAD_2_DEGREE * delta, 0), "", "polycone", false); + _assign(new TGeoPcon(start, delta, 0), "", "polycone", false); } /// Constructor to be used when creating a new polycone object. Add at the same time all Z planes @@ -87,13 +87,13 @@ Polycone::Polycone(double start, double delta, const vector<double>& rmin, const if (rmin.size() < 2) { throw runtime_error("DD4hep: PolyCone::addZPlanes> Not enough Z planes. minimum is 2!"); } - params.push_back(RAD_2_DEGREE * start); - params.push_back(RAD_2_DEGREE * delta); + params.push_back(start); + params.push_back(delta); params.push_back(rmin.size()); for (size_t i = 0; i < rmin.size(); ++i) { - params.push_back(z[i] * MM_2_CM); - params.push_back(rmin[i] * MM_2_CM); - params.push_back(rmax[i] * MM_2_CM); + params.push_back(z[i] ); + params.push_back(rmin[i] ); + params.push_back(rmax[i] ); } _assign(new TGeoPcon(¶ms[0]), "", "polycone", true); } @@ -115,9 +115,9 @@ void Polycone::addZPlanes(const vector<double>& rmin, const vector<double>& rmax params.push_back(s->GetRmax(i)); } for (size_t i = 0; i < rmin.size(); ++i) { - params.push_back(z[i] * MM_2_CM); - params.push_back(rmin[i] * MM_2_CM); - params.push_back(rmax[i] * MM_2_CM); + params.push_back(z[i] ); + params.push_back(rmin[i] ); + params.push_back(rmax[i] ); } _setDimensions(¶ms[0]); } @@ -125,66 +125,65 @@ void Polycone::addZPlanes(const vector<double>& rmin, const vector<double>& rmax /// Constructor to be used when creating a new cone segment object ConeSegment::ConeSegment(double dz, double rmin1, double rmax1, double rmin2, double rmax2, double phi1, double phi2) { _assign( - new TGeoConeSeg(dz * MM_2_CM, rmin1 * MM_2_CM, rmax1 * MM_2_CM, rmin2 * MM_2_CM, rmax2 * MM_2_CM, RAD_2_DEGREE * phi1, - RAD_2_DEGREE * phi2), "", "cone_segment", true); + new TGeoConeSeg(dz, rmin1, rmax1, rmin2, rmax2, phi1,phi2), "", "cone_segment", true); } /// Set the cone segment dimensions ConeSegment& ConeSegment::setDimensions(double dz, double rmin1, double rmax1, double rmin2, double rmax2, double phi1, double phi2) { - double params[] = { dz * MM_2_CM, rmin1 * MM_2_CM, rmax1 * MM_2_CM, rmin2 * MM_2_CM, rmax2 * MM_2_CM, RAD_2_DEGREE * phi1, - RAD_2_DEGREE * phi2 }; + double params[] = { dz, rmin1, rmax1, rmin2, rmax2, phi1, + phi2 }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization void Tube::make(const string& name, double rmin, double rmax, double z, double startPhi, double deltaPhi) { - //_assign(new TGeoTubeSeg(rmin*MM_2_CM,rmax*MM_2_CM,z*MM_2_CM,RAD_2_DEGREE*startPhi,RAD_2_DEGREE*deltaPhi),name,"tube",true); + //_assign(new TGeoTubeSeg(rmin,rmax,z,RAD_2_DEGREE*startPhi,RAD_2_DEGREE*deltaPhi),name,"tube",true); _assign(new MyConeSeg(), name, "tube", true); setDimensions(rmin, rmax, z, startPhi, deltaPhi); } /// Set the tube dimensions Tube& Tube::setDimensions(double rmin, double rmax, double z, double startPhi, double deltaPhi) { - //double params[] = {rmin*MM_2_CM,rmax*MM_2_CM,z*MM_2_CM,RAD_2_DEGREE*startPhi,RAD_2_DEGREE*deltaPhi}; - double params[] = { z * MM_2_CM, rmin * MM_2_CM, rmax * MM_2_CM, rmin * MM_2_CM, rmax * MM_2_CM, RAD_2_DEGREE * startPhi, - RAD_2_DEGREE * deltaPhi }; + //double params[] = {rmin,rmax,z,RAD_2_DEGREE*startPhi,RAD_2_DEGREE*deltaPhi}; + double params[] = { z, rmin, rmax, rmin, rmax, startPhi, + deltaPhi }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization void Cone::make(const string& name, double z, double rmin1, double rmax1, double rmin2, double rmax2) { - _assign(new TGeoCone(z * MM_2_CM, rmin1 * MM_2_CM, rmax1 * MM_2_CM, rmin2 * MM_2_CM, rmax2 * MM_2_CM), name, "cone", true); + _assign(new TGeoCone(z, rmin1, rmax1, rmin2, rmax2 ), name, "cone", true); } Cone& Cone::setDimensions(double z, double rmin1, double rmax1, double rmin2, double rmax2) { - double params[] = { z * MM_2_CM, rmin1 * MM_2_CM, rmax1 * MM_2_CM, rmin2 * MM_2_CM, rmax2 * MM_2_CM }; + double params[] = { z, rmin1, rmax1, rmin2, rmax2 }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization Trapezoid::Trapezoid(double x1, double x2, double y1, double y2, double z) { - _assign(new TGeoTrd2(x1 * MM_2_CM, x2 * MM_2_CM, y1 * MM_2_CM, y2 * MM_2_CM, z * MM_2_CM), "", "trd2", true); + _assign(new TGeoTrd2(x1, x2, y1, y2, z ), "", "trd2", true); } /// Set the Trapezoid dimensions Trapezoid& Trapezoid::setDimensions(double x1, double x2, double y1, double y2, double z) { - double params[] = { x1 * MM_2_CM, x2 * MM_2_CM, y1 * MM_2_CM, y2 * MM_2_CM, z * MM_2_CM }; + double params[] = { x1, x2, y1, y2, z }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization Paraboloid::Paraboloid(double r_low, double r_high, double delta_z) { - _assign(new TGeoParaboloid(r_low * MM_2_CM, r_high * MM_2_CM, delta_z * MM_2_CM), "", "paraboloid", true); + _assign(new TGeoParaboloid(r_low, r_high, delta_z ), "", "paraboloid", true); } /// Set the Paraboloid dimensions Paraboloid& Paraboloid::setDimensions(double r_low, double r_high, double delta_z) { - double params[] = { r_low * MM_2_CM, r_high * MM_2_CM, delta_z * MM_2_CM }; + double params[] = { r_low, r_high, delta_z }; _setDimensions(params); return *this; } @@ -192,27 +191,26 @@ Paraboloid& Paraboloid::setDimensions(double r_low, double r_high, double delta_ /// Constructor to be used when creating a new object with attribute initialization Sphere::Sphere(double rmin, double rmax, double theta, double delta_theta, double phi, double delta_phi) { _assign( - new TGeoSphere(rmin * MM_2_CM, rmax * MM_2_CM, RAD_2_DEGREE * theta, RAD_2_DEGREE * delta_theta, RAD_2_DEGREE * phi, - RAD_2_DEGREE * delta_phi), "", "sphere", true); + new TGeoSphere(rmin, rmax, theta, delta_theta, phi, delta_phi), "", "sphere", true); } /// Set the Sphere dimensions Sphere& Sphere::setDimensions(double rmin, double rmax, double theta, double delta_theta, double phi, double delta_phi) { - double params[] = { rmin * MM_2_CM, rmax * MM_2_CM, RAD_2_DEGREE * theta, RAD_2_DEGREE * delta_theta, RAD_2_DEGREE * phi, - RAD_2_DEGREE * delta_phi }; + double params[] = { rmin, rmax, theta, delta_theta, phi, + delta_phi }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization Torus::Torus(double r, double rmin, double rmax, double phi, double delta_phi) { - _assign(new TGeoTorus(r * MM_2_CM, rmin * MM_2_CM, rmax * MM_2_CM, RAD_2_DEGREE * phi, RAD_2_DEGREE * delta_phi), "", "torus", + _assign(new TGeoTorus(r, rmin, rmax, phi, delta_phi), "", "torus", true); } /// Set the Torus dimensions Torus& Torus::setDimensions(double r, double rmin, double rmax, double phi, double delta_phi) { - double params[] = { r * MM_2_CM, rmin * MM_2_CM, rmax * MM_2_CM, RAD_2_DEGREE * phi, RAD_2_DEGREE * delta_phi }; + double params[] = { r, rmin, rmax, phi, delta_phi }; _setDimensions(params); return *this; } @@ -221,8 +219,7 @@ Torus& Torus::setDimensions(double r, double rmin, double rmax, double phi, doub Trap::Trap(double z, double theta, double phi, double y1, double x1, double x2, double alpha1, double y2, double x3, double x4, double alpha2) { _assign( - new TGeoTrap(z, RAD_2_DEGREE * theta, RAD_2_DEGREE * phi, y1 * MM_2_CM, x1 * MM_2_CM, x2 * MM_2_CM, alpha1, y2 * MM_2_CM, - x3 * MM_2_CM, x4 * MM_2_CM, alpha2), "", "trap", true); + new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2), "", "trap", true); } /// Constructor to be used when creating a new anonymous object with attribute initialization @@ -235,15 +232,13 @@ Trap::Trap(double pz, double py, double px, double pLTX) { double x2 = pLTX / 2e0; double alpha1 = (pLTX - px) / py; _assign( - new TGeoTrap(z, RAD_2_DEGREE * theta, RAD_2_DEGREE * phi, y1 * MM_2_CM, x1 * MM_2_CM, x2 * MM_2_CM, alpha1, y1 * MM_2_CM, - x1 * MM_2_CM, x2 * MM_2_CM, alpha1), "", "trap", true); + new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1, y1, x1, x2, alpha1), "", "trap", true); } /// Set the trap dimensions Trap& Trap::setDimensions(double z, double theta, double phi, double y1, double x1, double x2, double alpha1, double y2, double x3, double x4, double alpha2) { - double params[] = { z, RAD_2_DEGREE * theta, RAD_2_DEGREE * phi, y1 * MM_2_CM, x1 * MM_2_CM, x2 * MM_2_CM, alpha1, y2 - * MM_2_CM, x3 * MM_2_CM, x4 * MM_2_CM, alpha2 }; + double params[] = { z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2 }; _setDimensions(params); return *this; } @@ -256,8 +251,7 @@ void PolyhedraRegular::_create(const string& name, int nsides, double rmin, doub else if (rmax < 0e0) throw runtime_error("DD4hep: PolyhedraRegular: Illegal argument rmax:<" + _toString(rmax) + "> is invalid!"); _assign(new TGeoPgon(), name, "polyhedra", false); - double params[] = { RAD_2_DEGREE * start, RAD_2_DEGREE * delta, double(nsides), 2e0, zpos * MM_2_CM, rmin * MM_2_CM, rmax - * MM_2_CM, zneg * MM_2_CM, rmin * MM_2_CM, rmax * MM_2_CM }; + double params[] = { start, delta, double(nsides), 2e0, zpos, rmin, rmax, zneg, rmin, rmax }; _setDimensions(¶ms[0]); } diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 870390517b2cb1e0983dc6109e35aff0998b1363..34461ab9e89ca652f176cbdd7227cfd350c03685 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -301,11 +301,31 @@ template <> void Converter<Material>::operator()(xml_h e) const { xml_h density = m.child(_U(D), false); double radlen_val = radlen.ptr() ? radlen.attr<double>(_U(value)) : 0.0; double intlen_val = intlen.ptr() ? intlen.attr<double>(_U(value)) : 0.0; - double dens_val = density.ptr() ? density.attr<double>(_U(value)) : 0.0; - if (0 == mat && !density.ptr()) { + double dens_val = density.ptr() ? density.attr<double>(_U(value)) : 0.0; + double dens_unit = 1.0; + if ( 0 == mat && !density.ptr() ) { has_density = false; } - + if ( density.ptr() && density.hasAttr(_U(unit)) ) { + dens_unit = density.attr<double>(_U(unit))/XML::_toDouble("gram/cm3"); + } + if ( dens_unit != 1.0 ) { + cout << matname << " Density unit:" << dens_unit; + if ( dens_unit != 1.0 ) cout << " " << density.attr<string>(_U(unit)); + cout << " Density Value raw:" << dens_val << " normalized:" << (dens_val*dens_unit) << endl; + dens_val *= dens_unit; + } +#if 0 + cout << "Gev " << XML::_toDouble("GeV") << endl; + cout << "sec " << XML::_toDouble("second") << endl; + cout << "nsec " << XML::_toDouble("nanosecond") << endl; + cout << "kilo " << XML::_toDouble("kilogram") << endl; + cout << "kilo " << XML::_toDouble("joule*s*s/(m*m)") << endl; + cout << "meter " << XML::_toDouble("meter") << endl; + cout << "ampere " << XML::_toDouble("ampere") << endl; + cout << "degree " << XML::_toDouble("degree") << endl; +#endif + //throw 1; printout(DEBUG, "Compact", "++ Creating material %s", matname); mat = mix = new TGeoMixture(matname, composites.size(), dens_val); mat->SetRadLen(radlen_val, intlen_val);