File indexing completed on 2024-09-28 07:03:04
0001
0002
0003
0004 #include "IrtGeo.h"
0005
0006 #include <DD4hep/Volumes.h>
0007 #include <Evaluator/DD4hepUnits.h>
0008 #include <IRT/CherenkovRadiator.h>
0009 #include <Math/GenVector/DisplacementVector3D.h>
0010 #include <TGDMLMatrix.h>
0011 #include <TString.h>
0012 #include <TVector3.h>
0013 #include <fmt/core.h>
0014 #include <stdint.h>
0015 #include <cmath>
0016 #include <functional>
0017 #include <map>
0018 #include <utility>
0019 #include <vector>
0020
0021 #include "services/geometry/richgeo/RichGeo.h"
0022
0023
0024 richgeo::IrtGeo::IrtGeo(std::string detName_, gsl::not_null<const dd4hep::Detector*> det_, gsl::not_null<const dd4hep::rec::CellIDPositionConverter*> conv_, std::shared_ptr<spdlog::logger> log_) :
0025 m_detName(detName_), m_det(det_), m_converter(conv_), m_log(log_)
0026 {
0027 Bind();
0028 }
0029
0030
0031
0032 void richgeo::IrtGeo::Bind() {
0033
0034 m_detRich = m_det->detector(m_detName);
0035 m_posRich = m_detRich.placement().position();
0036
0037
0038 m_irtDetectorCollection = new CherenkovDetectorCollection();
0039 m_irtDetector = m_irtDetectorCollection->AddNewDetector(m_detName.c_str());
0040 }
0041
0042
0043
0044 void richgeo::IrtGeo::SetReadoutIDToPositionLambda() {
0045
0046 m_irtDetector->m_ReadoutIDToPosition = [
0047 &m_log = this->m_log,
0048
0049 cell_mask = this->m_irtDetector->GetReadoutCellMask(),
0050 converter = this->m_converter,
0051 sensor_info = this->m_sensor_info
0052 ] (auto cell_id) {
0053
0054 auto sensor_id = cell_id & cell_mask;
0055 auto pixel_volume_centroid = (1/dd4hep::mm) * converter->position(cell_id);
0056
0057 auto sensor_info_it = sensor_info.find(sensor_id);
0058 if(sensor_info_it == sensor_info.end()) {
0059 m_log->warn("cannot find sensor ID {} in IrtGeo; using pixel volume centroid instead",sensor_id);
0060 return TVector3( pixel_volume_centroid.x(), pixel_volume_centroid.y(), pixel_volume_centroid.z());
0061 }
0062 auto sensor_obj = sensor_info_it->second;
0063
0064 auto pixel_surface_centroid = pixel_volume_centroid + sensor_obj.surface_offset;
0065
0066 auto dist = sqrt((pixel_surface_centroid - sensor_obj.surface_centroid).Mag2());
0067 if( dist > sensor_obj.size / sqrt(2) )
0068 m_log->warn("dist(pixel,sensor) is too large: {} mm",dist);
0069 return TVector3( pixel_surface_centroid.x(), pixel_surface_centroid.y(), pixel_surface_centroid.z());
0070 };
0071
0072 }
0073
0074
0075
0076 void richgeo::IrtGeo::SetRefractiveIndexTable() {
0077 m_log->debug("{:-^60}"," Refractive Index Tables ");
0078 for(auto rad_obj : m_irtDetector->Radiators()) {
0079 m_log->debug("{}:", rad_obj.first.Data());
0080 auto *const rad = rad_obj.second;
0081 const auto *rindex_matrix = m_det->material(rad->GetAlternativeMaterialName()).property("RINDEX");
0082 for(unsigned row=0; row<rindex_matrix->GetRows(); row++) {
0083 auto energy = rindex_matrix->Get(row,0) / dd4hep::eV;
0084 auto rindex = rindex_matrix->Get(row,1);
0085 m_log->debug(" {:>5} eV {:<}", energy, rindex);
0086 rad->m_ri_lookup_table.emplace_back(energy,rindex);
0087 }
0088 }
0089 }
0090
0091
0092 richgeo::IrtGeo::~IrtGeo() {
0093 delete m_irtDetector;
0094 delete m_irtDetectorCollection;
0095 }