Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 07:55:50

0001 // Copyright (C) 2022, 2023, Christopher Dilks
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 
0004 #pragma once
0005 
0006 #include <string>
0007 #include <iostream>
0008 #include <fmt/format.h>
0009 #include <spdlog/spdlog.h>
0010 #include <edm4hep/SimTrackerHitData.h>
0011 
0012 namespace richgeo {
0013 
0014 using CellIDType = decltype(edm4hep::SimTrackerHitData::cellID);
0015 
0016 // sensors
0017 // -----------------------------------------------------------------------
0018 /* keep track of information for a sensor
0019    */
0020 class Sensor {
0021 public:
0022   Sensor(){};
0023   ~Sensor(){};
0024   double size;
0025   dd4hep::Position surface_centroid;
0026   dd4hep::Direction surface_offset; // surface centroid = volume centroid + `surface_offset`
0027 };
0028 
0029 // radiators
0030 // -----------------------------------------------------------------------
0031 /* in many places in the reconstruction, we need to track which radiator
0032    * we are referring to; these are common methods to enumerate them
0033    */
0034 enum radiator_enum { kAerogel, kGas, nRadiators };
0035 
0036 // return radiator name associated with index
0037 [[maybe_unused]] static std::string RadiatorName(int num,
0038                                                  std::shared_ptr<spdlog::logger> m_log = nullptr) {
0039   if (num == kAerogel)
0040     return "Aerogel";
0041   else if (num == kGas)
0042     return "Gas";
0043   else {
0044     if (m_log)
0045       m_log->error("unknown radiator number {}", num);
0046     else
0047       std::cerr << "ERROR: unknown radiator number " << num << std::endl;
0048     return "UNKNOWN_RADIATOR";
0049   }
0050 }
0051 
0052 // return radiator index associated with name
0053 [[maybe_unused]] static int RadiatorNum(std::string name,
0054                                         std::shared_ptr<spdlog::logger> m_log = nullptr) {
0055   if (name == "Aerogel")
0056     return kAerogel;
0057   else if (name == "Gas")
0058     return kGas;
0059   else {
0060     if (m_log)
0061       m_log->error("unknown radiator name {}", name);
0062     else
0063       std::cerr << "ERROR: unknown radiator name " << name << std::endl;
0064     return -1;
0065   }
0066 }
0067 
0068 [[maybe_unused]] static int RadiatorNum(const char* name,
0069                                         std::shared_ptr<spdlog::logger> m_log = nullptr) {
0070   return RadiatorNum(std::string(name), m_log);
0071 }
0072 
0073 // search string `input` for a radiator name; return corresponding index
0074 [[maybe_unused]] static int ParseRadiatorName(std::string input,
0075                                               std::shared_ptr<spdlog::logger> m_log = nullptr) {
0076   if (input.find("aerogel") != std::string::npos)
0077     return kAerogel;
0078   else if (input.find("Aerogel") != std::string::npos)
0079     return kAerogel;
0080   else if (input.find("gas") != std::string::npos)
0081     return kGas;
0082   else if (input.find("Gas") != std::string::npos)
0083     return kGas;
0084   else {
0085     if (m_log)
0086       m_log->error("failed to parse '{}' for radiator name", input);
0087     else
0088       std::cerr << "ERROR: failed to parse '" << input << "' for radiator name" << std::endl;
0089     return -1;
0090   }
0091 }
0092 
0093 } // namespace richgeo