Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:57:59

0001 // Copyright 2022, David Lawrence
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 //
0005 
0006 #include "ACTSGeo_service.h"
0007 
0008 #include <Acts/Visualization/ViewConfig.hpp>
0009 #include <JANA/JApplication.h>
0010 #include <JANA/JException.h>
0011 #include <JANA/Services/JServiceLocator.h>
0012 #include <array>
0013 #include <exception>
0014 #include <gsl/pointers>
0015 #include <stdexcept>
0016 #include <string>
0017 
0018 #include "ActsGeometryProvider.h"
0019 #include "services/geometry/dd4hep/DD4hep_service.h"
0020 #include "services/log/Log_service.h"
0021 
0022 // Virtual destructor implementation to pin vtable and typeinfo to this
0023 // translation unit
0024 ACTSGeo_service::~ACTSGeo_service() = default;
0025 
0026 //----------------------------------------------------------------
0027 // detector
0028 //
0029 /// Return pointer to the dd4hep::Detector object.
0030 /// Call Initialize if needed.
0031 //----------------------------------------------------------------
0032 std::shared_ptr<const ActsGeometryProvider> ACTSGeo_service::actsGeoProvider() {
0033 
0034   try {
0035     std::call_once(m_init_flag, [this]() {
0036       // Assemble everything on the first call
0037 
0038       if (m_dd4hepGeo == nullptr) {
0039         throw JException("ACTSGeo_service m_dd4hepGeo==null which should never be!");
0040       }
0041 
0042       // Get material map from user parameter
0043       std::string material_map_file;
0044       try {
0045         material_map_file = m_dd4hepGeo->constant<std::string>("material-map");
0046       } catch (const std::runtime_error& e) {
0047         material_map_file = "calibrations/materials-map.cbor";
0048       }
0049       m_app->SetDefaultParameter("acts:MaterialMap", material_map_file,
0050                                  "JSON/CBOR material map file path");
0051 
0052       // Reading the geometry may take a long time and if the JANA ticker is enabled, it will keep printing
0053       // while no other output is coming which makes it look like something is wrong. Disable the ticker
0054       // while parsing and loading the geometry
0055       auto tickerEnabled = m_app->IsTickerEnabled();
0056       m_app->SetTicker(false);
0057 
0058       // Create default m_acts_provider
0059       m_acts_provider = std::make_shared<ActsGeometryProvider>();
0060 
0061       // Set ActsGeometryProvider parameters
0062       bool objWriteIt = m_acts_provider->getObjWriteIt();
0063       bool plyWriteIt = m_acts_provider->getPlyWriteIt();
0064       m_app->SetDefaultParameter("acts:WriteObj", objWriteIt,
0065                                  "Write tracking geometry as obj files");
0066       m_app->SetDefaultParameter("acts:WritePly", plyWriteIt,
0067                                  "Write tracking geometry as ply files");
0068       m_acts_provider->setObjWriteIt(objWriteIt);
0069       m_acts_provider->setPlyWriteIt(plyWriteIt);
0070 
0071       std::string outputTag = m_acts_provider->getOutputTag();
0072       std::string outputDir = m_acts_provider->getOutputDir();
0073       m_app->SetDefaultParameter("acts:OutputTag", outputTag, "Obj and ply output file tag");
0074       m_app->SetDefaultParameter("acts:OutputDir", outputDir, "Obj and ply output file dir");
0075       m_acts_provider->setOutputTag(outputTag);
0076       m_acts_provider->setOutputDir(outputDir);
0077 
0078 #if Acts_VERSION_MAJOR >= 37
0079       std::array<int, 3> containerView = m_acts_provider->getContainerView().color.rgb;
0080       std::array<int, 3> volumeView    = m_acts_provider->getVolumeView().color.rgb;
0081       std::array<int, 3> sensitiveView = m_acts_provider->getSensitiveView().color.rgb;
0082       std::array<int, 3> passiveView   = m_acts_provider->getPassiveView().color.rgb;
0083       std::array<int, 3> gridView      = m_acts_provider->getGridView().color.rgb;
0084 #else
0085             std::array<int,3> containerView = m_acts_provider->getContainerView().color;
0086             std::array<int,3> volumeView = m_acts_provider->getVolumeView().color;
0087             std::array<int,3> sensitiveView = m_acts_provider->getSensitiveView().color;
0088             std::array<int,3> passiveView = m_acts_provider->getPassiveView().color;
0089             std::array<int,3> gridView = m_acts_provider->getGridView().color;
0090 #endif
0091       m_app->SetDefaultParameter("acts:ContainerView", containerView, "RGB for container views");
0092       m_app->SetDefaultParameter("acts:VolumeView", volumeView, "RGB for volume views");
0093       m_app->SetDefaultParameter("acts:SensitiveView", sensitiveView, "RGB for sensitive views");
0094       m_app->SetDefaultParameter("acts:PassiveView", passiveView, "RGB for passive views");
0095       m_app->SetDefaultParameter("acts:GridView", gridView, "RGB for grid views");
0096       m_acts_provider->setContainerView(containerView);
0097       m_acts_provider->setVolumeView(volumeView);
0098       m_acts_provider->setSensitiveView(sensitiveView);
0099       m_acts_provider->setPassiveView(passiveView);
0100       m_acts_provider->setGridView(gridView);
0101 
0102       // Initialize m_acts_provider
0103       m_acts_provider->initialize(m_dd4hepGeo, material_map_file, m_log, m_log);
0104 
0105       // Enable ticker back
0106       m_app->SetTicker(tickerEnabled);
0107     });
0108   } catch (std::exception& ex) {
0109     throw JException(ex.what());
0110   }
0111 
0112   return m_acts_provider;
0113 }
0114 
0115 void ACTSGeo_service::acquire_services(JServiceLocator* srv_locator) {
0116 
0117   auto log_service = srv_locator->get<Log_service>();
0118   m_log            = log_service->logger("acts");
0119 
0120   // DD4Hep geometry
0121   auto dd4hep_service = srv_locator->get<DD4hep_service>();
0122   m_dd4hepGeo         = dd4hep_service->detector();
0123 }