Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:45

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 //  ROOT interpreted macro to test world to local and local to world
0013 //  transformations using 2 simple boxes.
0014 //
0015 //  usage: $> root.exe <path>/BoxTrafos.C
0016 //
0017 //
0018 //====================================================================
0019 
0020 namespace {
0021   struct Loader {  Loader() { gSystem->Load("libDDCore"); }  } _load;
0022 }
0023 
0024 using namespace dd4hep::detail;
0025 
0026 void printPos(const char* com, const Position& p)  {
0027   printf("%-24s:  %7.3f %7.3f %7.3f\n",com,p.x(),p.y(),p.z());
0028 }
0029 
0030 void printCoord(const Position& global, const Position& local)  {
0031   printPos("Global",global);
0032   printPos("Local",local);
0033 }
0034 
0035 void local_to_world(const char* com,const DetElement de, const Position& pos,const Position& loc)  {
0036   Position glob;
0037   printf("Local to World: Transformation '%s'(%7.3f, %7.3f, %7.3f)->world (Should be: (%7.3f, %7.3f, %7.3f) :\n",
0038      com, loc.x(),loc.y(),loc.z(),
0039      loc.x()+pos.x(),loc.y()+pos.y(),loc.z()+pos.z() );
0040   de.localToWorld(loc,glob);
0041   printCoord(glob,loc);
0042 }
0043 
0044 void world_to_local(const char* com,const DetElement de, const Position& pos,const Position& glob)  {
0045   Position loc;
0046   printf("World to Local: Transformation '%s'(%7.3f, %7.3f, %7.3f)->world (Should be: (%7.3f, %7.3f, %7.3f) :\n",
0047      com, glob.x(),glob.y(),glob.z(),
0048      glob.x()-pos.x(),glob.y()-pos.y(),glob.z()-pos.z() );
0049   de.worldToLocal(glob,loc);
0050   printCoord(glob,loc);
0051 }
0052 
0053 int BoxTrafos()  {
0054   string xml = "file:";
0055   xml += gSystem->Getenv("DD4hepINSTALL");
0056   xml += "/examples/ClientTests/compact/BoxTrafos.xml";
0057   const char* argv[] = {xml.c_str(), "BUILD_DEFAULT", 0};
0058 
0059   gSystem->Load("libDDCore");
0060   Detector& description = Detector::getInstance();
0061   description.apply("DD4hep_CompactLoader",2,(char**)argv);
0062   description.apply("DD4hep_GeometryDisplay",0,0);
0063 
0064 
0065   DetElement de = description.detector("B3");
0066   PlacedVolume pv = de.placement();
0067   Volume vol = pv.volume();
0068   Solid solid = vol.solid();
0069   TGeoBBox* box = (TGeoBBox*)(solid.ptr());
0070   Position glob,loc, pos(-10,30,10);
0071 
0072   printf("\n++++  local->world:\n\n");
0073 
0074   loc = Position(-pos.x(),-pos.y(),-pos.z());
0075   local_to_world("origine",de,pos,loc);
0076 
0077   loc = Position();
0078   local_to_world("center",de,pos,loc);
0079 
0080   loc = Position(box->GetDX(),box->GetDY(),box->GetDZ());
0081   local_to_world("top edge",de,pos,loc);
0082 
0083   loc = Position(box->GetDX(),box->GetDY(),-box->GetDZ());
0084   local_to_world("top edge",de,pos,loc);
0085 
0086   loc = Position(-box->GetDX(),box->GetDY(),box->GetDZ());
0087   local_to_world("top edge",de,pos,loc);
0088 
0089   loc = Position(-box->GetDX(),box->GetDY(),-box->GetDZ());
0090   local_to_world("top edge",de,pos,loc);
0091 
0092   loc = Position(box->GetDX(),-box->GetDY(),box->GetDZ());
0093   local_to_world("bottom edge",de,pos,loc);
0094 
0095   loc = Position(box->GetDX(),-box->GetDY(),-box->GetDZ());
0096   local_to_world("bottom edge",de,pos,loc);
0097 
0098   loc = Position(-box->GetDX(),-box->GetDY(),box->GetDZ());
0099   local_to_world("bottom edge",de,pos,loc);
0100 
0101   loc = Position(-box->GetDX(),-box->GetDY(),-box->GetDZ());
0102   local_to_world("bottom edge",de,pos,loc);
0103 
0104   printf("\n++++  world->local:\n\n");
0105 
0106   glob = Position(0,0,0);
0107   world_to_local("world center",de,pos,glob);
0108 
0109   glob = Position(pos.x(),pos.y(),pos.z());
0110   world_to_local("position",de,pos,glob);
0111 
0112   glob = Position( box->GetDX()+pos.x(),  box->GetDY()+pos.y(),  box->GetDZ()+pos.z());
0113   world_to_local("top edge",de,pos,glob);
0114 
0115   glob = Position( box->GetDX()+pos.x(),  box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
0116   world_to_local("top edge",de,pos,glob);
0117 
0118   glob = Position(-box->GetDX()+pos.x(),  box->GetDY()+pos.y(),  box->GetDZ()+pos.z());
0119   world_to_local("top edge",de,pos,glob);
0120 
0121   glob = Position(-box->GetDX()+pos.x(),  box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
0122   world_to_local("top edge",de,pos,glob);
0123 
0124   glob = Position( box->GetDX()+pos.x(), -box->GetDY()+pos.y(),  box->GetDZ()+pos.z());
0125   world_to_local("bottom edge",de,pos,glob);
0126 
0127   glob = Position( box->GetDX()+pos.x(), -box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
0128   world_to_local("bottom edge",de,pos,glob);
0129 
0130   glob = Position(-box->GetDX()+pos.x(), -box->GetDY()+pos.y(),  box->GetDZ()+pos.z());
0131   world_to_local("bottom edge",de,pos,glob);
0132 
0133   glob = Position(-box->GetDX()+pos.x(), -box->GetDY()+pos.y(), -box->GetDZ()+pos.z());
0134   world_to_local("bottom edge",de,pos,glob);
0135 
0136   return 1;
0137 }