LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ChannelMapAlg.cxx
Go to the documentation of this file.
1 
10 
11 namespace geo{
12 
13 
14  //----------------------------------------------------------------------------
15  unsigned int ChannelMapAlg::NearestWire(const TVector3& worldPos,
16  geo::PlaneID const& planeID) const
17  {
18  return NearestWireID(worldPos, planeID).Wire;
19  }
20 
21  //----------------------------------------------------------------------------
22  unsigned int ChannelMapAlg::NOpChannels(unsigned int NOpDets) const
23  {
24  // By default just return the number of optical detectos
25  return NOpDets;
26  }
27 
28  //----------------------------------------------------------------------------
29  unsigned int ChannelMapAlg::MaxOpChannel(unsigned int NOpDets) const
30  {
31  // By default just return the number of optical detectos
32  return NOpChannels(NOpDets);
33  }
34 
35  //----------------------------------------------------------------------------
36  unsigned int ChannelMapAlg::NOpHardwareChannels(unsigned int /*opDet*/) const
37  {
38  // By defualt, 1 channel per optical detector
39  return 1;
40  }
41 
42 
43 
44  //----------------------------------------------------------------------------
45  unsigned int ChannelMapAlg::OpChannel(unsigned int detNum, unsigned int /* channel */) const
46  {
47  return detNum;
48  }
49 
50  //----------------------------------------------------------------------------
51  unsigned int ChannelMapAlg::OpDetFromOpChannel(unsigned int opChannel) const
52  {
53  return opChannel;
54  }
55 
56  //----------------------------------------------------------------------------
57  unsigned int ChannelMapAlg::HardwareChannelFromOpChannel(unsigned int /* opChannel */) const
58  {
59  return 0;
60  }
61 
62  //----------------------------------------------------------------------------
63  bool ChannelMapAlg::IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const
64  {
65  // Check channel number
66  if ( opChannel >= this->NOpChannels(NOpDets) ) return false;
67 
68  // Check opdet number
69  unsigned int opdet = this->OpDetFromOpChannel(opChannel);
70  if (opdet >= NOpDets) return false;
71 
72  // Check hardware channel number
73  unsigned int hChan = this->HardwareChannelFromOpChannel(opChannel);
74  if (hChan >= this->NOpHardwareChannels(opdet)) return false;
75 
76  return true;
77  }
78 
79  //----------------------------------------------------------------------------
80  size_t ChannelMapAlg::NearestAuxDet(const double* point,
81  std::vector<geo::AuxDetGeo*> const& auxDets) const
82  {
83  double HalfCenterWidth = 0.;
84  double localPoint[3] = {0.};
85 
86  for(size_t a = 0; a < auxDets.size(); ++a) {
87 
88  auxDets[a]->WorldToLocal(point, localPoint);
89 
90  HalfCenterWidth = 0.5 * (auxDets[a]->HalfWidth1() + auxDets[a]->HalfWidth2());
91 
92  if( localPoint[2] >= - auxDets[a]->Length()/2 &&
93  localPoint[2] <= auxDets[a]->Length()/2 &&
94  localPoint[1] >= - auxDets[a]->HalfHeight() &&
95  localPoint[1] <= auxDets[a]->HalfHeight() &&
96  // if AuxDet a is a box, then HalfSmallWidth = HalfWidth
97  localPoint[0] >= - HalfCenterWidth + localPoint[2]*(HalfCenterWidth - auxDets[a]->HalfWidth2())/(0.5 * auxDets[a]->Length()) &&
98  localPoint[0] <= HalfCenterWidth - localPoint[2]*(HalfCenterWidth - auxDets[a]->HalfWidth2())/(0.5 * auxDets[a]->Length())
99  ) return a;
100 
101  }// for loop over AudDet a
102 
103  // throw an exception because we couldn't find the sensitive volume
104  throw cet::exception("ChannelMap") << "Can't find AuxDet for position ("
105  << point[0] << ","
106  << point[1] << ","
107  << point[2] << ")\n";
108 
109  return UINT_MAX;
110 
111  }
112 
113  //----------------------------------------------------------------------------
114  size_t ChannelMapAlg::NearestSensitiveAuxDet(const double* point,
115  std::vector<geo::AuxDetGeo*> const& auxDets) const
116  {
117  double HalfCenterWidth = 0.;
118  double localPoint[3] = {0.};
119 
120  size_t auxDetIdx = this->NearestAuxDet(point, auxDets);
121 
122  geo::AuxDetGeo* adg = auxDets[auxDetIdx];
123 
124  for(size_t a = 0; a < adg->NSensitiveVolume(); ++a) {
125 
126  geo::AuxDetSensitiveGeo const& adsg = adg->SensitiveVolume(a);
127  adsg.WorldToLocal(point, localPoint);
128 
129  HalfCenterWidth = 0.5 * (adsg.HalfWidth1() + adsg.HalfWidth2());
130 
131  if( localPoint[2] >= - adsg.Length()/2 &&
132  localPoint[2] <= adsg.Length()/2 &&
133  localPoint[1] >= - adsg.HalfHeight() &&
134  localPoint[1] <= adsg.HalfHeight() &&
135  // if AuxDet a is a box, then HalfSmallWidth = HalfWidth
136  localPoint[0] >= - HalfCenterWidth + localPoint[2]*(HalfCenterWidth - adsg.HalfWidth2())/(0.5 * adsg.Length()) &&
137  localPoint[0] <= HalfCenterWidth - localPoint[2]*(HalfCenterWidth - adsg.HalfWidth2())/(0.5 * adsg.Length())
138  ) return a;
139  }// for loop over AuxDetSensitive a
140 
141  // throw an exception because we couldn't find the sensitive volume
142  throw cet::exception("Geometry") << "Can't find AuxDetSensitive for position ("
143  << point[0] << ","
144  << point[1] << ","
145  << point[2] << ")\n";
146 
147  return UINT_MAX;
148  }
149 
150  //----------------------------------------------------------------------------
151  size_t ChannelMapAlg::ChannelToAuxDet(std::vector<geo::AuxDetGeo*> const& /* auxDets */,
152  std::string const& detName,
153  uint32_t const& /*channel*/) const
154  {
155  // loop over the map of AuxDet names to Geo object numbers to determine which auxdet
156  // we have. If no name in the map matches the provided string, throw an exception
157  for(auto itr : fADNameToGeo)
158  if( itr.first.compare(detName) == 0 ) return itr.second;
159 
160 
161  throw cet::exception("Geometry") << "No AuxDetGeo matching name: " << detName;
162 
163  return UINT_MAX;
164  }
165 
166  //----------------------------------------------------------------------------
167  // the first member of the pair is the index in the auxDets vector for the AuxDetGeo,
168  // the second member is the index in the vector of AuxDetSensitiveGeos for that AuxDetGeo
169  std::pair<size_t, size_t> ChannelMapAlg::ChannelToSensitiveAuxDet(std::vector<geo::AuxDetGeo*> const& auxDets,
170  std::string const& detName,
171  uint32_t const& channel) const
172  {
173  size_t adGeoIdx = this->ChannelToAuxDet(auxDets, detName, channel);
174 
175  // look for the index of the sensitive volume for the given channel
176  if( fADChannelToSensitiveGeo.count(adGeoIdx) > 0 ){
177 
178  auto itr = fADChannelToSensitiveGeo.find(adGeoIdx);
179 
180  // get the vector of channels to AuxDetSensitiveGeo index
181  if( channel < itr->second.size() )
182  return std::make_pair(adGeoIdx, itr->second[channel]);
183 
184  throw cet::exception("Geometry") << "Given AuxDetSensitive channel, " << channel
185  << ", cannot be found in vector associated to AuxDetGeo index: "
186  << adGeoIdx << ". Vector has size " << itr->second.size();
187  }
188 
189  throw cet::exception("Geometry") << "Given AuxDetGeo with index " << adGeoIdx
190  << " does not correspond to any vector of sensitive volumes";
191 
192  return std::make_pair(adGeoIdx, UINT_MAX);
193  }
194 
196  {
197  return SignalTypeForChannelImpl(channel);
198  }
199 
201  {
202  return SignalTypeForROPIDImpl(ropid);
203  }
204 
206  {
208  }
209 }
virtual std::pair< size_t, size_t > ChannelToSensitiveAuxDet(std::vector< geo::AuxDetGeo * > const &auxDets, std::string const &detName, uint32_t const &channel) const
Returns the index of the sensitive detector containing the channel.
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:159
geo::SigType_t SignalTypeForROPID(readout::ROPID const &ropid) const
Return the signal type on the specified readout plane.
geo::SigType_t SignalTypeForChannel(raw::ChannelID_t const channel) const
Return the signal type of the specified channel.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const =0
Return the signal type of the specified channel.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:313
virtual size_t NearestAuxDet(const double *point, std::vector< geo::AuxDetGeo * > const &auxDets) const
Returns the auxiliary detector closest to the specified point.
virtual unsigned int NOpChannels(unsigned int NOpDets) const
Returns the number of optical channels contained in some detectors.
virtual unsigned int OpDetFromOpChannel(unsigned int opChannel) const
Returns the optical detector the specified optical channel belongs.
unsigned int NearestWire(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the index of the wire nearest to the specified position.
virtual size_t NearestSensitiveAuxDet(const double *point, std::vector< geo::AuxDetGeo * > const &auxDets) const
Returns sensitive auxiliary detector closest to specified point.
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
std::map< std::string, size_t > fADNameToGeo
map the names of the dets to the AuxDetGeo objects
size_t NSensitiveVolume() const
Definition: AuxDetGeo.h:160
Class identifying a set of planes sharing readout channels.
Encapsulate the geometry of an auxiliary detector.
std::map< size_t, std::vector< size_t > > fADChannelToSensitiveGeo
virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const =0
Returns the ID of the first channel in the specified readout plane.
virtual geo::SigType_t SignalTypeForROPIDImpl(readout::ROPID const &ropid) const
Return the signal type on the specified readout plane.
virtual unsigned int HardwareChannelFromOpChannel(unsigned int opChannel) const
Returns the hardware channel number of specified optical channel.
virtual unsigned int MaxOpChannel(unsigned int NOpDets) const
Returns the number of optical channels contained in some detectors.
virtual size_t ChannelToAuxDet(std::vector< geo::AuxDetGeo * > const &auxDets, std::string const &detName, uint32_t const &channel) const
Returns the index of the detector containing the specified channel.
void WorldToLocal(const double *world, double *auxdet) const
Transform point from world frame to local auxiliary detector frame.
virtual unsigned int OpChannel(unsigned int detNum, unsigned int hwchannel=0) const
Returns the channel ID of the specified hardware channel.
virtual unsigned int NOpHardwareChannels(unsigned int opDet) const
Returns the number of channels in the specified optical detectors.
virtual geo::WireID NearestWireID(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the ID of the wire nearest to the specified position.
virtual bool IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const
Returns whether the ID identifies a valid optical detector channel.
Interface to algorithm class for a specific detector channel mapping.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33