10 #include "cetlib_except/exception.h" 16 constexpr
auto invalid_index = std::numeric_limits<std::size_t>::max();
37 std::vector<AuxDetGeo>
const& auxDets,
39 bool throwIfAbsent)
const 41 for (std::size_t a = 0; a < auxDets.size(); ++a) {
42 auto const localPoint = auxDets[a].toLocalCoords(point);
43 double const HalfCenterWidth = 0.5 * (auxDets[a].HalfWidth1() + auxDets[a].HalfWidth2());
45 if (localPoint.Z() >= (-auxDets[a].Length() / 2 - tolerance) &&
46 localPoint.Z() <= (auxDets[a].Length() / 2 + tolerance) &&
47 localPoint.Y() >= (-auxDets[a].HalfHeight() - tolerance) &&
48 localPoint.Y() <= (auxDets[a].HalfHeight() + tolerance) &&
50 localPoint.X() >= (-HalfCenterWidth +
51 localPoint.Z() * (HalfCenterWidth - auxDets[a].HalfWidth2()) /
52 (0.5 * auxDets[a].
Length()) -
54 localPoint.X() <= (HalfCenterWidth -
55 localPoint.Z() * (HalfCenterWidth - auxDets[a].HalfWidth2()) /
56 (0.5 * auxDets[a].
Length()) +
61 std::ostringstream msg;
62 msg <<
"Can't find AuxDet for position " << point;
64 if (throwIfAbsent) {
throw cet::exception(
"AuxDetReadoutGeom") << msg.str(); }
72 std::vector<AuxDetGeo>
const& auxDets,
74 bool throwIfAbsent)
const 76 std::size_t
const auxDetIdx =
NearestAuxDet(point, auxDets, tolerance, throwIfAbsent);
77 if (auxDetIdx == invalid_index) {
return invalid_index; }
79 AuxDetGeo const& adg = auxDets[auxDetIdx];
86 if (localPoint.Z() >= -(adsg.
Length() / 2 + tolerance) &&
87 localPoint.Z() <= (adsg.
Length() / 2 + tolerance) &&
88 localPoint.Y() >= -adsg.
HalfHeight() - tolerance &&
89 localPoint.Y() <= adsg.
HalfHeight() + tolerance &&
93 localPoint.Z() * (HalfCenterWidth - adsg.
HalfWidth2()) / (0.5 * adsg.
Length()) -
97 localPoint.Z() * (HalfCenterWidth - adsg.
HalfWidth2()) / (0.5 * adsg.
Length()) +
102 std::ostringstream msg;
103 msg <<
"Can't find AuxDetSensitive for position " << point;
105 if (throwIfAbsent) {
throw cet::exception(
"AuxDetReadoutGeom") << msg.str(); }
108 return invalid_index;
115 std::string
const& detName,
116 std::uint32_t channel)
const 124 <<
"Given AuxDetSensitive channel, " << channel
125 <<
", cannot be found in vector associated to AuxDetGeo index: " << adGeoIdx
126 <<
". Vector has size " << it->second.size();
130 if (channel < it->
second.size())
return {adGeoIdx, it->second[channel].second};
132 throw cet::exception(
"Geometry") <<
"Given AuxDetGeo with index " << adGeoIdx
133 <<
" does not correspond to any vector of sensitive volumes";
138 std::uint32_t
const channel,
139 std::string
const& auxDetName,
140 std::vector<geo::AuxDetGeo>
const& auxDets)
const 145 throw cet::exception(
"CRTWireReadoutGeom") <<
"No AuxDetGeo with name " << auxDetName;
147 std::size_t
const ad = ad_it->second;
152 throw cet::exception(
"CRTWireReadoutGeom") <<
"No entry in channel and sensitive volume" 153 <<
" map for AuxDet index " << ad <<
" bail";
159 for (
auto const& [ch, svindex] : it->second) {
160 if (ch == channel) {
return auxDets[ad].SensitiveVolume(svindex).GetCenter(); }
174 return pr.second == detName;
177 throw cet::exception(
"Geometry") <<
"No AuxDetGeo matching name: " << detName;
float Length(const PFPStruct &pfp)
double HalfWidth2() const
Encapsulate the geometry of the sensitive portion of an auxiliary detector .
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
std::size_t NearestAuxDet(Point_t const &point, std::vector< AuxDetGeo > const &auxDets, double tolerance=0, bool throwIfAbsent=true) const
std::map< std::size_t, std::string > ADGeoToName
map the AuxDetGeo index to the name
std::map< std::size_t, std::vector< chanAndSV > > fADGeoToChannelAndSV
std::size_t DetNameToAuxDet(std::string const &detName) const
double HalfWidth1() const
std::pair< std::size_t, std::size_t > ChannelToSensitiveAuxDet(std::string const &detName, std::uint32_t channel) const
double HalfHeight() const
LocalPoint_t toLocalCoords(Point_t const &world) const
Transform point from world frame to local auxiliary detector frame.
virtual ~AuxDetInitializer()
size_t NSensitiveVolume() const
virtual AuxDetReadoutInitializers initialize(std::vector< AuxDetGeo > const &ads) const =0
Encapsulate the geometry of an auxiliary detector.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::map< std::string, std::size_t > fNameToADGeo
map the names to the AuxDetGeo index
AuxDetReadoutInitializers init(std::vector< AuxDetGeo > const &ads) const
Point_t AuxDetChannelToPosition(std::uint32_t channel, std::string const &auxDetName, std::vector< AuxDetGeo > const &auxDets) const
second_as<> second
Type of time stored in seconds, in double precision.
std::size_t NearestSensitiveAuxDet(Point_t const &point, std::vector< AuxDetGeo > const &auxDets, double tolerance=0, bool throwIfAbsent=true) const
std::map< std::size_t, std::string > fADGeoToName
map the AuxDetGeo index to the name
Interface to auxiliary-detector geometry for wire readouts. .
AuxDetReadoutGeom(AuxDetReadoutInitializers initializers)
cet::coded_exception< error, detail::translate > exception