Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:26:17

0001 //==========================================================================
0002 //  AIDA Detector description implementation
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/AlignmentData.h>
0016 #include <DD4hep/MatrixHelpers.h>
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DD4hep/DetElement.h>
0019 #include <DD4hep/OpaqueData.h>
0020 #include <DD4hep/Primitives.h>
0021 
0022 // ROOT include files
0023 #include <TGeoMatrix.h>
0024 
0025 // C/C++ include files
0026 #include <sstream>
0027 
0028 using namespace dd4hep;
0029 
0030 /// Copy constructor
0031 Delta::Delta(const Delta& c)
0032   : translation(c.translation), pivot(c.pivot), rotation(c.rotation), flags(c.flags)
0033 {
0034 }
0035 
0036 /// Default destructor
0037 Delta::~Delta()   {
0038 }
0039 
0040 /// Assignment operator
0041 Delta& Delta::operator=(const Delta& c)   {
0042   if ( &c != this )  {
0043     pivot       = c.pivot;
0044     translation = c.translation;
0045     rotation    = c.rotation;
0046     flags       = c.flags;
0047   }
0048   return *this;
0049 }
0050 
0051 /// Reset information to identity
0052 void Delta::clear()   {
0053   flags       = 0;
0054   pivot       = Pivot();
0055   translation = Position();
0056   rotation    = RotationZYX();
0057 }
0058 
0059 /// Compute the alignment delta for one detector element and its alignment condition
0060 void Delta::computeMatrix(TGeoHMatrix& tr_delta)  const   {
0061   const Delta&       delta = *this;
0062   const Position&      pos = delta.translation;
0063   const Translation3D& piv = delta.pivot;
0064   const RotationZYX&   rot = delta.rotation;
0065 
0066   switch(delta.flags)   {
0067   case Delta::HAVE_TRANSLATION+Delta::HAVE_ROTATION+Delta::HAVE_PIVOT:
0068     detail::matrix::_transform(tr_delta, Transform3D(Translation3D(pos)*piv*rot*(piv.Inverse())));
0069     break;
0070   case Delta::HAVE_TRANSLATION+Delta::HAVE_ROTATION:
0071     detail::matrix::_transform(tr_delta, Transform3D(rot,pos));
0072     break;
0073   case Delta::HAVE_ROTATION+Delta::HAVE_PIVOT:
0074     detail::matrix::_transform(tr_delta, Transform3D(piv*rot*(piv.Inverse())));
0075     break;
0076   case Delta::HAVE_ROTATION:
0077     detail::matrix::_transform(tr_delta, rot);
0078     break;
0079   case Delta::HAVE_TRANSLATION:
0080     detail::matrix::_transform(tr_delta, pos);
0081     break;
0082   default:
0083     break;
0084   }
0085 }
0086 
0087 /// print alignment delta object
0088 std::ostream& operator << (std::ostream& ostr, const Delta& data)   {
0089   std::string res;
0090   std::stringstream str;
0091   str << "[" << data.translation << "," << data.rotation << "," << data.pivot << "]";
0092   res = str.str();
0093   for(std::size_t i=0; i<res.length(); ++i)
0094     if ( res[i]=='\n' ) res[i] = ' ';
0095   return ostr << res;
0096 }
0097 
0098 /// Standard constructor
0099 AlignmentData::AlignmentData()
0100   : flag(0), magic(magic_word())
0101 {
0102   InstanceCount::increment(this);
0103 }
0104 
0105 /// Copy constructor
0106 AlignmentData::AlignmentData(const AlignmentData& copy)
0107   : delta(copy.delta), worldTrafo(copy.worldTrafo),
0108     detectorTrafo(copy.detectorTrafo),
0109     nodes(copy.nodes), trToWorld(copy.trToWorld), detector(copy.detector),
0110     placement(copy.placement), flag(copy.flag), magic(magic_word())
0111 {
0112   InstanceCount::increment(this);
0113 }
0114 
0115 /// Default destructor
0116 AlignmentData::~AlignmentData()  {
0117   InstanceCount::decrement(this);
0118 }
0119 
0120 /// Assignment operator necessary due to copy constructor
0121 AlignmentData& AlignmentData::operator=(const AlignmentData& copy)  {
0122   if ( this != &copy )  {
0123     delta         = copy.delta;
0124     detectorTrafo = copy.detectorTrafo;
0125     nodes         = copy.nodes;
0126     trToWorld     = copy.trToWorld;
0127     detector      = copy.detector;
0128     placement     = copy.placement;
0129     flag          = copy.flag;
0130   }
0131   return *this;
0132 }
0133 
0134 /// print Conditions object
0135 std::ostream& operator << (std::ostream& ostr, const AlignmentData& data)   {
0136   std::stringstream str;
0137   str << data.delta;
0138   return ostr << str.str();
0139 }
0140 
0141 /// Transform a point from local coordinates of a given level to global coordinates
0142 Position AlignmentData::localToWorld(const Position& local) const   {
0143   Position global;
0144   Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0145   worldTrafo.LocalToMaster(local_point, master_point);
0146   global.SetCoordinates(master_point);
0147   return global;
0148 }
0149 
0150 /// Transformation from local coordinates of the placed volume to the world system
0151 void AlignmentData::localToWorld(const Position& local, Position& global) const   {
0152   Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0153   worldTrafo.LocalToMaster(local_point, master_point);
0154   global.SetCoordinates(master_point);
0155 }
0156 
0157 /// Transformation from local coordinates of the placed volume to the world system
0158 void AlignmentData::localToWorld(const Double_t local[3], Double_t global[3]) const  {
0159   worldTrafo.LocalToMaster(local, global);
0160 }
0161 
0162 /// Transform a point from local coordinates of a given level to global coordinates
0163 Position AlignmentData::worldToLocal(const Position& global) const   {
0164   Position local;
0165   // If the path is unknown an exception will be thrown inside worldTransformation() !
0166   Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0167   worldTrafo.MasterToLocal(master_point, local_point);
0168   local.SetCoordinates(local_point);
0169   return local;
0170 }
0171 
0172 /// Transformation from world coordinates of the local placed volume coordinates
0173 void AlignmentData::worldToLocal(const Position& global, Position& local) const  {
0174   Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0175   worldTrafo.MasterToLocal(master_point, local_point);
0176   local.SetCoordinates(local_point);
0177 }
0178 
0179 /// Transformation from world coordinates of the local placed volume coordinates
0180 void AlignmentData::worldToLocal(const Double_t global[3], Double_t local[3]) const   {
0181   worldTrafo.MasterToLocal(global, local);
0182 }
0183 
0184 /// Transform a point from local coordinates to the coordinates of the DetElement
0185 Position AlignmentData::localToDetector(const Position& local) const   {
0186   Position global;
0187   Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0188   detectorTrafo.LocalToMaster(local_point, master_point);
0189   global.SetCoordinates(master_point);
0190   return global;
0191 }
0192 
0193 /// Transformation from local coordinates of the placed volume to the detector system
0194 void AlignmentData::localToDetector(const Position& local, Position& global) const   {
0195   Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() };
0196   detectorTrafo.LocalToMaster(local_point, master_point);
0197   global.SetCoordinates(master_point);
0198 }
0199 
0200 /// Transformation from local coordinates of the placed volume to the detector system
0201 void AlignmentData::localToDetector(const Double_t local[3], Double_t global[3]) const   {
0202   detectorTrafo.LocalToMaster(local, global);
0203 }
0204 
0205 /// Transform a point from local coordinates of the DetElement to global coordinates
0206 Position AlignmentData::detectorToLocal(const Position& global) const   {
0207   Position local;
0208   // If the path is unknown an exception will be thrown inside worldTransformation() !
0209   Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0210   detectorTrafo.MasterToLocal(master_point, local_point);
0211   local.SetCoordinates(local_point);
0212   return local;
0213 }
0214 
0215 /// Transformation from detector element coordinates to the local placed volume coordinates
0216 void AlignmentData::detectorToLocal(const Position& global, Position& local) const   {
0217   // If the path is unknown an exception will be thrown inside worldTransformation() !
0218   Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 };
0219   detectorTrafo.MasterToLocal(master_point, local_point);
0220   local.SetCoordinates(local_point);
0221 }
0222 
0223 /// Transformation from detector element coordinates to the local placed volume coordinates
0224 void AlignmentData::detectorToLocal(const Double_t global[3], Double_t local[3]) const   {
0225   detectorTrafo.MasterToLocal(global, local);
0226 }
0227 
0228 /// Access the ideal/nominal alignment/placement matrix
0229 Alignment AlignmentData::nominal() const   {
0230   return detector.nominal();
0231 }
0232 
0233 #include <DD4hep/GrammarUnparsed.h>
0234 static auto s_registry = GrammarRegistry::pre_note<Delta>(1)
0235               .pre_note<AlignmentData>(1)
0236               .pre_note<std::map<DetElement, Delta> >(1);