Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /*
0002  * Export phi and theta range, in absolute coordinates, for each TPOT Tile.
0003  * this can be used to hard-code the TPOT acceptance, for instance when extrapolating
0004  * to the full TPC acceptance
0005  */
0006 
0007 #include <g4detectors/PHG4CylinderGeomContainer.h>
0008 
0009 #include <micromegas/CylinderGeomMicromegas.h>
0010 #include <micromegas/MicromegasDefs.h>
0011 
0012 #include <trackreco/MakeActsGeometry.h>
0013 
0014 #include <ffamodules/CDBInterface.h>
0015 
0016 #include <fun4all/Fun4AllRunNodeInputManager.h>
0017 #include <fun4all/Fun4AllServer.h>
0018 
0019 #include <phool/getClass.h>
0020 #include <phool/recoConsts.h>
0021 
0022 
0023 #include <Rtypes.h> // for R__LOAD_LIBRARY macro
0024 
0025 R__LOAD_LIBRARY(libffamodules.so)
0026 R__LOAD_LIBRARY(libfun4all.so)
0027 R__LOAD_LIBRARY(libtrack_reco.so)
0028 
0029 namespace
0030 {
0031 
0032   // range adaptor to be able to use range-based for loop
0033   template<class T> class range_adaptor
0034   {
0035     public:
0036     explicit range_adaptor( const T& range ):m_range(range){}
0037     const typename T::first_type& begin() {return m_range.first;}
0038     const typename T::second_type& end() {return m_range.second;}
0039     private:
0040     T m_range;
0041   };
0042 
0043   // generic pair printout
0044   template<class T, class U>
0045   std::ostream& operator << (std::ostream& out, const std::pair<T, U> pair)
0046   {
0047     out << "{" << pair.first << "," << pair.second << "}";
0048     return out;
0049   }
0050 
0051   // generic container printout
0052   template<template<typename,typename> class Container, class T, class A>
0053     std::ostream& operator << (std::ostream& out, const Container<T,A>& container)
0054   {
0055     out << "{";
0056     bool first = true;
0057     for( const auto& value:container )
0058     {
0059       if( !first ) { out << ", "; };
0060       first = false;
0061       out << value;
0062     }
0063     out << "}";
0064     return out;
0065   }
0066 
0067 }
0068 
0069 void ExportTpotAcceptanceRange()
0070 {
0071 
0072   // initialization
0073   auto *rc = recoConsts::instance();
0074   auto *se = Fun4AllServer::instance();
0075   auto *topNode = se->topNode();
0076 
0077   // set run number to get proper CDB entries
0078   const int runnumber = 52077;
0079 
0080   rc->set_IntFlag("RUNNUMBER", runnumber);
0081   rc->set_IntFlag("RUNSEGMENT", 0);
0082   rc->set_StringFlag("CDB_GLOBALTAG", "newcdbtag");
0083   rc->set_uint64Flag("TIMESTAMP", runnumber);
0084 
0085   // load geometry file
0086   std::string geofile = CDBInterface::instance()->getUrl("Tracking_Geometry");
0087   // the std::string::c_str() is needed, a string barfs with the above generic printout
0088   std::cout << "Geometry - geofile: " << geofile.c_str() << std::endl;
0089   auto *ingeo = new Fun4AllRunNodeInputManager("GeoIn");
0090   ingeo->AddFile(geofile);
0091   ingeo->run(0);
0092 
0093   // acts geometry initialization
0094   auto *geom = new MakeActsGeometry;
0095   geom->set_mvtx_applymisalign(true);
0096   geom->InitRun( topNode );
0097 
0098   // get relevant nodes
0099   // micromegas geometry
0100   auto *m_micromegas_geomcontainer = findNode::getClass<PHG4CylinderGeomContainer>(topNode, "CYLINDERGEOM_MICROMEGAS_FULL");
0101 
0102   // ACTS geometry
0103   auto *m_tGeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
0104 
0105   using range_list_t = std::vector<CylinderGeomMicromegas::range_t>;
0106   range_list_t theta_range_list;
0107   range_list_t phi_range_list;
0108 
0109   // loop over layers
0110   for( const auto& [layer, layergeom] : range_adaptor( m_micromegas_geomcontainer->get_begin_end() ) )
0111   {
0112     // sanity
0113     assert(layer == layergeom->get_layer());
0114 
0115     auto *micromegas_layergeom = static_cast<CylinderGeomMicromegas*>(layergeom);
0116 
0117     // tiles
0118     const unsigned int tile_count = micromegas_layergeom->get_tiles_count();
0119 
0120     // segmentation
0121     const auto segmentation = micromegas_layergeom->get_segmentation_type();
0122 
0123     for( unsigned int itile = 0; itile < tile_count; ++itile )
0124     {
0125       switch(segmentation)
0126       {
0127         case MicromegasDefs::SegmentationType::SEGMENTATION_PHI:
0128         phi_range_list.emplace_back(micromegas_layergeom->get_phi_range(itile, m_tGeometry));
0129         break;
0130 
0131         case MicromegasDefs::SegmentationType::SEGMENTATION_Z:
0132         theta_range_list.emplace_back(micromegas_layergeom->get_theta_range(itile, m_tGeometry));
0133         break;
0134       }
0135     }
0136   }
0137 
0138   // calculate inner phi range for each sector
0139   auto get_phi_range = [phi_range_list]( const std::vector<int>& indexes )
0140   {
0141     CylinderGeomMicromegas::range_t out{0,0};
0142     for(const auto& i:indexes)
0143     {
0144       const auto& window = phi_range_list[i];
0145       if( out.first == 0 || window.first > out.first ) out.first = window.first;
0146       if( out.second == 0 || window.second < out.second ) out.second = window.second;
0147     }
0148     return out;
0149   };
0150 
0151   const auto phi_range_central = get_phi_range( {0,1,2,3} );
0152   const auto phi_range_east = get_phi_range( {4,5} );
0153   const auto phi_range_west = get_phi_range( {6,7} );
0154 
0155   std::cout << "phi_range_central=" << phi_range_central << std::endl;
0156   std::cout << "phi_range_east=" << phi_range_east << std::endl;
0157   std::cout << "phi_range_west=" << phi_range_west << std::endl;
0158   std::cout << std::endl;
0159 
0160   std::cout << "theta_range_central=" << range_list_t{theta_range_list[0], theta_range_list[1], theta_range_list[2], theta_range_list[3]} << std::endl;
0161   std::cout << "theta_range_east=" << range_list_t{theta_range_list[4], theta_range_list[5]} << std::endl;
0162   std::cout << "theta_range_west=" << range_list_t{theta_range_list[6], theta_range_list[7]} << std::endl;
0163 
0164   return;
0165 }