|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | +/// \file CRTChannelMapAlg.cxx |
| 3 | +/// \brief Algorithm class for SBND auxiliary detector channel mapping |
| 4 | +/// |
| 5 | +/// Ported from AuxDetChannelMapLArIATAlg.cxx (Author: brebel@fnal.gov) |
| 6 | +/// |
| 7 | +/// \version $Id: $ |
| 8 | +/// \author mastbaum@uchicago.edu |
| 9 | +/////////////////////////////////////////////////////////////////////////////// |
| 10 | + |
| 11 | +#include "art/Framework/Services/Registry/ServiceHandle.h" |
| 12 | +#include "messagefacility/MessageLogger/MessageLogger.h" |
| 13 | +#include "larcorealg/Geometry/AuxDetGeo.h" |
| 14 | +#include "larcorealg/Geometry/AuxDetSensitiveGeo.h" |
| 15 | +#include "larcorealg/Geometry/AuxDetGeometryCore.h" |
| 16 | +#include "sbndcode/CRT/CRTChannelMapAlg.h" |
| 17 | +#include "TVector3.h" |
| 18 | +#include <iostream> |
| 19 | +#include <ostream> |
| 20 | + |
| 21 | +namespace geo { |
| 22 | + |
| 23 | + //--------------------------------------------------------------------------- |
| 24 | + CRTChannelMapAlg::CRTChannelMapAlg( |
| 25 | + fhicl::ParameterSet const& p) |
| 26 | + : fSorter(geo::CRTGeoObjectSorter(p)) {} |
| 27 | + |
| 28 | + //--------------------------------------------------------------------------- |
| 29 | + void CRTChannelMapAlg::Initialize(AuxDetGeometryData_t& geodata) { |
| 30 | + Uninitialize(); |
| 31 | + |
| 32 | + std::vector<geo::AuxDetGeo>& adgeo = geodata.auxDets; |
| 33 | + |
| 34 | + // Sort the AuxDetGeo objects and map them to names of the detectors |
| 35 | + //fSorter.SortAuxDets(adgeo); |
| 36 | + |
| 37 | + // Map the AuxDetGeo names to their position in the sorted vector |
| 38 | + // |
| 39 | + // Each tagger is composed of scintillator modules, composed of 16 strips. |
| 40 | + // In the geometry, CRTStripArrays are AuxDets and CRTStrips are the |
| 41 | + // AuxDetSensitives. Each strip has two SiPM channels, one per optical |
| 42 | + // fiber (not in the geometry). |
| 43 | + // |
| 44 | + // 2x TaggerTop: (5x2 +5x2)x16 = 320 strips, 640 channels |
| 45 | + // 2x TaggerSide: (4x2 +5x2)x16 = 288 strips, 576 channels |
| 46 | + // 1x TaggerFace: (4x2 +4x2)x16 = 256 strips, 512 channels |
| 47 | + // 1x TaggerFace: (4x2-1+4x2)x16 = 240 strips, 480 channels |
| 48 | + // 1x TaggerBot: 34x16 = 544 strips, 1088 channels |
| 49 | + |
| 50 | + fADGeoToName.clear(); |
| 51 | + fADGeoToChannelAndSV.clear(); |
| 52 | + |
| 53 | + for (size_t a=0; a<adgeo.size(); a++){ |
| 54 | + std::string volName(adgeo[a].TotalVolume()->GetName()); |
| 55 | + |
| 56 | + long unsigned int number_scintillating_strips = 0; |
| 57 | + |
| 58 | + if (strncmp(((adgeo[a].TotalVolume())->GetShape())->GetName(), "CRTstripMINOSArray", 18) == 0) { |
| 59 | + number_scintillating_strips = 20; //To account for the MINOS modules. |
| 60 | + } |
| 61 | + else {number_scintillating_strips = 16;} |
| 62 | + |
| 63 | + size_t nsv = adgeo[a].NSensitiveVolume(); |
| 64 | + if (nsv != number_scintillating_strips) { |
| 65 | + throw cet::exception("CRTChannelMap") |
| 66 | + << "Wrong number of sensitive volumes for CRT volume " |
| 67 | + << volName << " (got " << nsv << ", expected 16)" << std::endl; |
| 68 | + } |
| 69 | + |
| 70 | + fADGeoToName[a] = volName; |
| 71 | + fNameToADGeo[volName] = a; |
| 72 | + |
| 73 | + if (volName.find("CRTStripArray") != std::string::npos) { |
| 74 | + for (size_t svID=0; svID<number_scintillating_strips; svID++) { |
| 75 | + for (size_t ich=0; ich<2; ich++) { |
| 76 | + size_t chID = 2 * svID + ich; |
| 77 | + fADGeoToChannelAndSV[a].push_back(std::make_pair(chID, svID)); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + //---------------------------------------------------------------------------- |
| 85 | + void CRTChannelMapAlg::Uninitialize() {} |
| 86 | + |
| 87 | + //---------------------------------------------------------------------------- |
| 88 | + uint32_t CRTChannelMapAlg::PositionToAuxDetChannel( |
| 89 | + Point_t const& worldLoc, |
| 90 | + std::vector<geo::AuxDetGeo> const& auxDets, |
| 91 | + size_t& ad, |
| 92 | + size_t& sv) const { |
| 93 | + |
| 94 | + // Set the default to be that we don't find the position in any AuxDet |
| 95 | + uint32_t channel = UINT_MAX; |
| 96 | + |
| 97 | + // Figure out which detector we are in |
| 98 | + ad = 0; |
| 99 | + sv = this->NearestSensitiveAuxDet(worldLoc, auxDets, ad, 0.0001); |
| 100 | + |
| 101 | + // Check to see which AuxDet this position corresponds to |
| 102 | + auto gnItr = fADGeoToName.find(ad); |
| 103 | + if (gnItr != fADGeoToName.end()){ |
| 104 | + // Get the vector of channel and sensitive volume pairs |
| 105 | + auto csvItr = fADGeoToChannelAndSV.find(ad); |
| 106 | + |
| 107 | + if (csvItr == fADGeoToChannelAndSV.end()) { |
| 108 | + throw cet::exception("CRTChannelMapAlg") |
| 109 | + << "No entry in channel and sensitive volume map for AuxDet index " |
| 110 | + << ad; |
| 111 | + } |
| 112 | + |
| 113 | + // N.B. This is the ID on the nth channel, and the strip has n and n+1 |
| 114 | + channel = 2 * sv + 0; |
| 115 | + } |
| 116 | + |
| 117 | + if (channel == UINT_MAX) { |
| 118 | + mf::LogDebug("CRTChannelMapAlg") << "Can't find AuxDet for position (" |
| 119 | + << worldLoc.X() << "," |
| 120 | + << worldLoc.Y() << "," |
| 121 | + << worldLoc.Z() |
| 122 | + << ")\n"; |
| 123 | + } |
| 124 | + |
| 125 | + return channel; |
| 126 | + } |
| 127 | + |
| 128 | + //---------------------------------------------------------------------------- |
| 129 | + Point_t CRTChannelMapAlg::AuxDetChannelToPosition( |
| 130 | + uint32_t const channel, |
| 131 | + std::string const& auxDetName, |
| 132 | + std::vector<geo::AuxDetGeo> const& auxDets) const { |
| 133 | + |
| 134 | + std::cout << "CRTChannelMapAlg::AuxDetChannelToPosition" << std::endl; |
| 135 | + |
| 136 | + // Figure out which detector we are in |
| 137 | + size_t ad = UINT_MAX; |
| 138 | + if (fNameToADGeo.count(auxDetName) > 0) { |
| 139 | + ad = fNameToADGeo.find(auxDetName)->second; |
| 140 | + } |
| 141 | + else { |
| 142 | + throw cet::exception("CRTChannelMapAlg") |
| 143 | + << "No AuxDetGeo with name " << auxDetName; |
| 144 | + } |
| 145 | + |
| 146 | + // Get the vector of channel and sensitive volume pairs |
| 147 | + auto csvItr = fADGeoToChannelAndSV.find(ad); |
| 148 | + |
| 149 | + if (csvItr == fADGeoToChannelAndSV.end()) { |
| 150 | + throw cet::exception("CRTChannelMapAlg") |
| 151 | + << "No entry in channel and sensitive volume" |
| 152 | + << " map for AuxDet index " << ad << " bail"; |
| 153 | + } |
| 154 | + |
| 155 | + // Loop over the vector of channel and sensitive volumes to determine the |
| 156 | + // sensitive volume for this channel. Then get the origin of the sensitive |
| 157 | + // volume in the world coordinate system. |
| 158 | + for (auto csv : csvItr->second) { |
| 159 | + if (csv.first == channel) { |
| 160 | + // Get the center of the sensitive volume for this channel |
| 161 | + return auxDets[ad].SensitiveVolume(csv.second).GetCenter(); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + return {}; |
| 166 | + } |
| 167 | + |
| 168 | +} // namespace geo |
0 commit comments