Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-07-03 07:05:28

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 {
0035     kAerogel,
0036     kGas,
0037     nRadiators
0038   };
0039 
0040   // return radiator name associated with index
0041   static std::string RadiatorName(int num, std::shared_ptr<spdlog::logger> m_log = nullptr) {
0042     if(num==kAerogel)  return "Aerogel";
0043     else if(num==kGas) return "Gas";
0044     else {
0045       if (m_log) m_log->error("unknown radiator number {}", num);
0046       else std::cerr << "ERROR: unknown radiator number " << num << std::endl;
0047       return "UNKNOWN_RADIATOR";
0048     }
0049   }
0050 
0051   // return radiator index associated with name
0052   static int RadiatorNum(std::string name, std::shared_ptr<spdlog::logger> m_log = nullptr) {
0053     if(name=="Aerogel")  return kAerogel;
0054     else if(name=="Gas") return kGas;
0055     else {
0056       if (m_log) m_log->error("unknown radiator name {}", name);
0057       else std::cerr << "ERROR: unknown radiator name " << name << std::endl;
0058       return -1;
0059     }
0060   }
0061 
0062   static int RadiatorNum(const char * name, std::shared_ptr<spdlog::logger> m_log = nullptr) {
0063     return RadiatorNum(std::string(name), m_log);
0064   }
0065 
0066   // search string `input` for a radiator name; return corresponding index
0067   static int ParseRadiatorName(std::string input, std::shared_ptr<spdlog::logger> m_log = nullptr) {
0068     if      (input.find("aerogel")!=std::string::npos) return kAerogel;
0069     else if (input.find("Aerogel")!=std::string::npos) return kAerogel;
0070     else if (input.find("gas")!=std::string::npos)     return kGas;
0071     else if (input.find("Gas")!=std::string::npos)     return kGas;
0072     else {
0073       if (m_log) m_log->error("failed to parse '{}' for radiator name", input);
0074       else std::cerr << "ERROR: failed to parse '" << input << "' for radiator name" << std::endl;
0075       return -1;
0076     }
0077   }
0078 
0079 }