Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:23:58

0001 /*
0002  * Convert TPOT alignment translation offset, given in centimeter unit,
0003  * and mesured in local coordinates into global coordinates, and millimeter
0004  * units, suitable for modifying the alignment parameters
0005  * text file passed to ACTS in fun4all
0006  * local coordinates translation offsets are hard-coded
0007  */
0008 
0009 #include <g4detectors/PHG4CylinderGeomContainer.h>
0010 
0011 #include <micromegas/CylinderGeomMicromegas.h>
0012 
0013 #include <trackreco/MakeActsGeometry.h>
0014 
0015 #include <ffamodules/CDBInterface.h>
0016 
0017 #include <fun4all/Fun4AllRunNodeInputManager.h>
0018 #include <fun4all/Fun4AllServer.h>
0019 
0020 #include <micromegas/MicromegasDefs.h>
0021 
0022 #include <phool/getClass.h>
0023 #include <phool/recoConsts.h>
0024 
0025 #include <Rtypes.h> // for R__LOAD_LIBRARY macro
0026 #include <TVector3.h>
0027 
0028 R__LOAD_LIBRARY(libffamodules.so)
0029 R__LOAD_LIBRARY(libfun4all.so)
0030 R__LOAD_LIBRARY(libtrack_reco.so)
0031 
0032 namespace
0033 {
0034   //! small class to restore std::cout precision at end-of-scope
0035   class std_precision_restore_t // NOLINT(hicpp-special-member-functions)
0036   {
0037     public:
0038 
0039     //! constructor
0040     explicit std_precision_restore_t( std::ostream& out = std::cout ):
0041       m_out( out ),
0042       m_precision( out.precision() )
0043     {}
0044 
0045     //! destructor
0046     ~std_precision_restore_t()
0047     { m_out << std::setprecision( m_precision ); }
0048 
0049     private:
0050     std::ostream& m_out;
0051     int m_precision = 0;
0052   };
0053 
0054   //! handles TPOT local and global alignment parameters
0055   class translation_parameters_t
0056   {
0057     public:
0058 
0059     translation_parameters_t( TrkrDefs::hitsetkey key, double local_x, double local_y ):
0060       m_hitsetkey( key ),
0061       m_local_x( local_x ),
0062       m_local_y( local_y )
0063     {}
0064 
0065 //NOLINTBEGIN(misc-non-private-member-variables-in-classes)
0066     TrkrDefs::hitsetkey m_hitsetkey = 0;
0067     double m_local_x = 0;
0068     double m_local_y = 0;
0069     double m_global_x = 0;
0070     double m_global_y = 0;
0071     double m_global_z = 0;
0072 //NOLINTEND(misc-non-private-member-variables-in-classes)
0073 
0074     friend std::ostream& operator << (std::ostream& out, const translation_parameters_t& p )
0075     {
0076       std_precision_restore_t precision_restore(out);
0077       out << p.m_hitsetkey << " 0 0 0 "
0078         << std::setprecision(3)
0079         << p.m_global_x*Acts::UnitConstants::cm << " "
0080         << p.m_global_y*Acts::UnitConstants::cm << " "
0081         << p.m_global_z*Acts::UnitConstants::cm;
0082       return out;
0083     }
0084 
0085     using list = std::vector<translation_parameters_t>;
0086 
0087   };
0088 
0089   /*
0090    * TPOT local alignment parameters
0091    * local translation parameters along local x (approximatle rphi) and local y (approximately z)
0092    * first parameter is hitsetkey, used to identify individual Micromegas detectors
0093    */
0094   translation_parameters_t::list translation_parameters =
0095   {
0096     { 53936384, 1.86, -0.56 },
0097     { 53936385, 1.74, -0.61 },
0098     { 53936386, 1.49, -1.23 },
0099     { 53936387, 1.58, -1.02 },
0100     { 53936388, 0.34, -0.96 },
0101     { 53936389, 0.45, 0.66 },
0102     { 53936390, 2.02, -0.52 },
0103     { 53936391, 2.14, -1.13 },
0104     { 54001664, 1.86, -0.56 },
0105     { 54001665, 1.74, -0.61 },
0106     { 54001666, 1.49, -1.23 },
0107     { 54001667, 1.58, -1.02 },
0108     { 54001668, 0.34, -0.96 },
0109     { 54001669, 0.45, 0.66 },
0110     { 54001670, 2.02, -0.52 },
0111     { 54001671, 2.14, -1.13 }
0112   };
0113 
0114 }
0115 
0116 //_________________________________________________________________
0117 void ConvertTpotAlignment()
0118 {
0119 
0120   // initialization
0121   auto *rc = recoConsts::instance();
0122   auto *se = Fun4AllServer::instance();
0123   auto *topNode = se->topNode();
0124 
0125   // set run number to get proper CDB entries
0126   const int runnumber = 52077;
0127 
0128   rc->set_IntFlag("RUNNUMBER", runnumber);
0129   rc->set_IntFlag("RUNSEGMENT", 0);
0130   rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0131   rc->set_uint64Flag("TIMESTAMP", runnumber);
0132 
0133   // load geometry file
0134   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0135   std::cout << "Geometry - geofile: " << geofile << std::endl;
0136   auto *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0137   ingeo->AddFile(geofile);
0138   ingeo->run(0);
0139 
0140   // acts geometry initialization
0141   auto *geom = new MakeActsGeometry;
0142   geom->set_mvtx_applymisalign(true);
0143   geom->InitRun( topNode );
0144 
0145   // get relevant nodes
0146   // micromegas geometry
0147   auto *m_micromegas_geomcontainer = findNode::getClass<PHG4CylinderGeomContainer>(topNode, "CYLINDERGEOM_MICROMEGAS_FULL");
0148 
0149   // ACTS geometry
0150   auto *m_tGeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
0151 
0152   // write down the center of all tiles
0153   const auto [begin,end] = m_micromegas_geomcontainer->get_begin_end();
0154   for( auto iter = begin; iter != end; ++iter )
0155   {
0156 
0157     auto *layergeom = dynamic_cast<CylinderGeomMicromegas*>(iter->second);
0158 
0159     // get layer
0160     const unsigned int layer = layergeom->get_layer();
0161 
0162     // get tiles
0163     const unsigned int tile_count = layergeom->get_tiles_count();
0164 
0165     // loop over tiles
0166     for( unsigned int tileid = 0; tileid < tile_count; ++tileid )
0167     {
0168       // get tile center and print
0169       const auto center = layergeom->get_world_from_local_coords( tileid, m_tGeometry, {0,0} );
0170       std::cout << "ConvertTpotAlignment - layer: " << layer << " tile: " << tileid << " center: {" << center.x() << "," << center.y() << "," << center.z() << "}" << std::endl;
0171     }
0172   }
0173 
0174 
0175   // loop over TPOT alignment parameters
0176   for( auto&& p:translation_parameters )
0177   {
0178     // get layer and tile from hitsetkey
0179     const auto layer = TrkrDefs::getLayer(p.m_hitsetkey);
0180     const auto tileid = MicromegasDefs::getTileId(p.m_hitsetkey);
0181 
0182     // get relevant geometry
0183     const auto *const layergeom =  static_cast<const CylinderGeomMicromegas*>(m_micromegas_geomcontainer->GetLayerGeom(layer));
0184 
0185     // get global translation
0186     const auto translation_global = layergeom->get_world_from_local_vect(tileid, m_tGeometry, {p.m_local_x, p.m_local_y, 0} );
0187     p.m_global_x = translation_global.x();
0188     p.m_global_y = translation_global.y();
0189     p.m_global_z = translation_global.z();
0190 
0191   }
0192 
0193   // printout
0194   for( const auto& p:translation_parameters )
0195   { std::cout << p << std::endl; }
0196 
0197   std::cout << "All done" << std::endl;
0198 
0199 }