All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CRT/CRTChannelMapAlg.cxx
Go to the documentation of this file.
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"
17 #include "TVector3.h"
18 #include <iostream>
19 #include <ostream>
20 
21 namespace geo {
22 
23  //---------------------------------------------------------------------------
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  //----------------------------------------------------------------------------
86 
87  //----------------------------------------------------------------------------
89  double const worldLoc[3],
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  // Get the origin of the sensitive volume in the world coordinate system
102  double svOrigin[3] = {0, 0, 0};
103  double localOrigin[3] = {0, 0, 0};
104 
105  auxDets[ad].SensitiveVolume(sv).LocalToWorld(localOrigin, svOrigin);
106 
107  // Check to see which AuxDet this position corresponds to
108  auto gnItr = fADGeoToName.find(ad);
109  if (gnItr != fADGeoToName.end()){
110  // Get the vector of channel and sensitive volume pairs
111  auto csvItr = fADGeoToChannelAndSV.find(ad);
112 
113  if (csvItr == fADGeoToChannelAndSV.end()) {
114  throw cet::exception("CRTChannelMapAlg")
115  << "No entry in channel and sensitive volume map for AuxDet index "
116  << ad;
117  }
118 
119  // N.B. This is the ID on the nth channel, and the strip has n and n+1
120  channel = 2 * sv + 0;
121  }
122 
123  if (channel == UINT_MAX) {
124  mf::LogDebug("CRTChannelMapAlg") << "Can't find AuxDet for position ("
125  << worldLoc[0] << ","
126  << worldLoc[1] << ","
127  << worldLoc[2]
128  << ")\n";
129  }
130 
131  return channel;
132  }
133 
134  //----------------------------------------------------------------------------
136  uint32_t const& channel,
137  std::string const& auxDetName,
138  std::vector<geo::AuxDetGeo> const& auxDets) const {
139  double x = 0;
140  double y = 0;
141  double z = 0;
142 
143  std::cout << "CRTChannelMapAlg::AuxDetChannelToPosition" << std::endl;
144 
145  // Figure out which detector we are in
146  size_t ad = UINT_MAX;
147  if (fNameToADGeo.count(auxDetName) > 0) {
148  ad = fNameToADGeo.find(auxDetName)->second;
149  }
150  else {
151  throw cet::exception("CRTChannelMapAlg")
152  << "No AuxDetGeo with name " << auxDetName;
153  }
154 
155  // Get the vector of channel and sensitive volume pairs
156  auto csvItr = fADGeoToChannelAndSV.find(ad);
157 
158  if (csvItr == fADGeoToChannelAndSV.end()) {
159  throw cet::exception("CRTChannelMapAlg")
160  << "No entry in channel and sensitive volume"
161  << " map for AuxDet index " << ad << " bail";
162  }
163 
164  // Loop over the vector of channel and sensitive volumes to determine the
165  // sensitive volume for this channel. Then get the origin of the sensitive
166  // volume in the world coordinate system.
167  double svOrigin[3] = {0, 0, 0};
168  double localOrigin[3] = {0, 0, 0};
169  for (auto csv : csvItr->second) {
170  if (csv.first == channel) {
171  // Get the center of the sensitive volume for this channel
172  auxDets[ad].SensitiveVolume(csv.second).LocalToWorld(localOrigin,
173  svOrigin);
174 
175  x = svOrigin[0];
176  y = svOrigin[1];
177  z = svOrigin[2];
178 
179  break;
180  }
181  }
182 
183  return TVector3(x, y, z);
184  }
185 
186 } // namespace geo
std::map< std::string, size_t > fNameToADGeo
map the names to the AuxDetGeo index
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
Encapsulate the geometry of the sensitive portion of an auxiliary detector.
void Initialize(AuxDetGeometryData_t &geodata) override
std::map< size_t, std::vector< chanAndSV > > fADGeoToChannelAndSV
pdgs p
Definition: selectors.fcl:22
Access the description of auxiliary detector geometry.
process_name gaushit a
uint32_t PositionToAuxDetChannel(double const worldLoc[3], std::vector< geo::AuxDetGeo > const &auxDets, size_t &ad, size_t &sv) const override
process_name opflash particleana ie ie y
Encapsulate the geometry of an auxiliary detector.
const TVector3 AuxDetChannelToPosition(uint32_t const &channel, std::string const &auxDetName, std::vector< geo::AuxDetGeo > const &auxDets) const override
std::map< size_t, std::string > fADGeoToName
map the AuxDetGeo index to the name
virtual size_t NearestSensitiveAuxDet(const double *point, std::vector< geo::AuxDetGeo > const &auxDets, size_t &ad, double tolerance=0) const
BEGIN_PROLOG could also be cout