Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:55

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/GlobalAlignment.h>
0016 #include <DD4hep/MatrixHelpers.h>
0017 #include <DD4hep/Printout.h>
0018 
0019 // ROOT include files
0020 #include <TGeoManager.h>
0021 
0022 namespace  {
0023   struct CheckHandle  {
0024     CheckHandle(const dd4hep::align::GlobalAlignment& a)  {
0025       if ( a.isValid() ) return;
0026       dd4hep::except("dd4hep:GlobalAlignment", "Attempt to access invalid alignment object. [Invalid Handle]");
0027     }
0028     ~CheckHandle() {}
0029   };
0030 }
0031 
0032 /// Initializing constructor to create a new object
0033 dd4hep::align::GlobalAlignment::GlobalAlignment(const std::string& path) {
0034   //cout << "GlobalAlignment: path=" << path << endl;
0035   m_element = new TGeoPhysicalNode(path.c_str());
0036 }
0037 
0038 /// Number of nodes in this branch
0039 int dd4hep::align::GlobalAlignment::numNodes() const  {
0040   CheckHandle verify_handle(*this);
0041   return ptr()->GetLevel();
0042 }
0043 
0044 /// Access the placement of this node
0045 dd4hep::PlacedVolume dd4hep::align::GlobalAlignment::placement()   const   {
0046   CheckHandle verify_handle(*this);
0047   return ptr()->GetNode(0);
0048 }
0049 
0050 /// Access the placement of a node in the chain of placements for this branch
0051 dd4hep::PlacedVolume dd4hep::align::GlobalAlignment::nodePlacement(int level)   const   {
0052   CheckHandle verify_handle(*this);
0053   TGeoNode* n = ptr()->GetNode(level);
0054   if ( n ) return n;
0055   except("dd4hep:GlobalAlignment",
0056          "The object chain of %s is too short. [Invalid index]", placement().name());
0057   return {};
0058 }
0059 
0060 /// Access the placement of the mother of this node
0061 dd4hep::PlacedVolume dd4hep::align::GlobalAlignment::motherPlacement(int level_up)   const    {
0062   CheckHandle verify_handle(*this);
0063   Int_t ind = ptr()->GetLevel()-level_up;
0064   if ( ind >= 0 )  {
0065     return ptr()->GetMother(level_up);
0066   }
0067   except("dd4hep:GlobalAlignment",
0068          "This object %s has not enough mothers. [Invalid index]", placement().name());
0069   return {};
0070 }
0071 
0072 /// Access the currently applied alignment/placement matrix
0073 dd4hep::Transform3D dd4hep::align::GlobalAlignment::toGlobal(int level) const   {
0074   CheckHandle verify_handle(*this);
0075   return detail::matrix::_transform(ptr()->GetMatrix(level));
0076 }
0077 
0078 /// Transform a point from local coordinates of a given level to global coordinates
0079 dd4hep::Position dd4hep::align::GlobalAlignment::toGlobal(const Position& localPoint, int level) const   {
0080   CheckHandle verify_handle(*this);
0081   Position result;
0082   TGeoHMatrix* matrix = ptr()->GetMatrix(level);
0083   matrix->LocalToMaster((Double_t*)&localPoint,(Double_t*)&result);
0084   return result;
0085 }
0086 
0087 /// Transform a point from local coordinates of a given level to global coordinates
0088 dd4hep::Position dd4hep::align::GlobalAlignment::globalToLocal(const Position& globalPoint, int level) const   {
0089   CheckHandle verify_handle(*this);
0090   Position result;
0091   TGeoHMatrix* matrix = ptr()->GetMatrix(level);
0092   matrix->MasterToLocal((Double_t*)&globalPoint,(Double_t*)&result);
0093   return result;
0094 }
0095 
0096 /// Access the currently applied alignment/placement matrix
0097 dd4hep::Transform3D dd4hep::align::GlobalAlignment::toMother(int level) const   {
0098   CheckHandle verify_handle(*this);
0099   return detail::matrix::_transform(ptr()->GetNode(level)->GetMatrix());
0100 }
0101 
0102 /// Access the currently applied alignment/placement matrix
0103 dd4hep::Transform3D dd4hep::align::GlobalAlignment::nominal() const   {
0104   CheckHandle verify_handle(*this);
0105   return detail::matrix::_transform(ptr()->GetOriginalMatrix());
0106 }
0107 
0108 /// Access the currently applied correction matrix (delta)
0109 dd4hep::Transform3D dd4hep::align::GlobalAlignment::delta() const   {
0110   // It may be useful at some point to cache some of these matrices....
0111   CheckHandle verify_handle(*this);
0112   TGeoPhysicalNode* n = ptr();
0113   // T = T_0 * Delta -> Delta = T_0^-1 * T
0114   TGeoHMatrix matrix(n->GetOriginalMatrix()->Inverse());
0115   matrix.Multiply(n->GetNode()->GetMatrix());
0116   return detail::matrix::_transform(&matrix);
0117 }
0118 
0119 /// Access the inverse of the currently applied correction matrix (delta) (mother to daughter)
0120 dd4hep::Transform3D dd4hep::align::GlobalAlignment::invDelta() const   {
0121   // It may be useful at some point to cache some of these matrices....
0122   CheckHandle verify_handle(*this);
0123   TGeoPhysicalNode* n = ptr();
0124   // T = T_0 * Delta -> Delta^-1 = T^-1 * T_0
0125   TGeoHMatrix matrix(n->GetNode()->GetMatrix()->Inverse());
0126   matrix.Multiply(n->GetOriginalMatrix());
0127   return detail::matrix::_transform(&matrix);
0128 }