LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CTreeGeometry_module.cc
Go to the documentation of this file.
1 // Dump TPC / Wire Geometry and mapping
2 // Chao Zhang (chao@bnl.gov) 2/7/2018
3 // adapted by Wenqiang Gu (wgu@bnl.gov) 8/30/2020
4 
5 #ifndef CTreeGeometry_module
6 #define CTreeGeometry_module
7 
8 // LArSoft includes
9 //#include "lardata/Utilities/DetectorProperties.h"
11 // #include "Utilities/LArProperties.h"
22 // #include "nusimdata/SimulationBase/MCParticle.h"
23 // #include "nusimdata/SimulationBase/MCTruth.h"
29 #include "lardataobj/RawData/raw.h"
30 
31 // Framework includes
38 // #include "art/Framework/Services/Optional/TFileService.h"
43 #include "fhiclcpp/ParameterSet.h"
45 
46 // C++ Includes
47 #include <map>
48 #include <vector>
49 // #include <algorithm>
50 #include <fstream>
51 #include <iomanip>
52 #include <iostream>
53 // #include <string>
54 // #include <sstream>
55 // #include <cmath>
56 
57 // #ifdef __MAKECINT__
58 // #pragma link C++ class vector<vector<int> >+;
59 // #pragma link C++ class vector<vector<float> >+;
60 // #endif
61 
62 using namespace std;
63 
64 namespace {
65 
66  class CTreeGeometry : public art::EDAnalyzer {
67  public:
68  explicit CTreeGeometry(fhicl::ParameterSet const& pset);
69  virtual ~CTreeGeometry();
70 
71  void beginJob();
72  void endJob();
73  void analyze(const art::Event& evt);
74 
75  void reconfigure(fhicl::ParameterSet const& pset);
76  void saveChannelWireMap();
77  void printGeometry();
78 
79  private:
80  // the parameters we'll read from the .fcl
81  bool fSaveChannelWireMap;
82 
84 
85  // Geometry Tree Leafs
86  int fNcryostats;
87  int fNTPC;
88  vector<float> fTPC_x; // TPC length in x
89  vector<float> fTPC_y; // TPC length in y
90  vector<float> fTPC_z; // TPC length in z
91  // int fNplanes; // unused
92  vector<int> fPlane_type; // plane type: 0 == induction, 1 == collection
93  vector<int> fPlane_view; // wire orientation: 0 == U, 1 == V, 2 == X
94  vector<double> fPlane_wirepitch; // wire pitch of each plane
95  vector<double> fPlane_wireangle; // wire angle (to vertical) of each plane
96  vector<int> fPlane_wires; // number of wires in each plane
97  int fNchannels;
98  vector<int> channel_starts; // vector os channel starts on each plane
99  vector<int> channel_ends; // vector os channel starts on each plane
100  //int fNOpDets; // unused
101 
102  // Event Tree Leafs
103  //int fEvent; // unused
104  //int fRun; // unused
105  //int fSubRun; // unused
106 
107  }; // class CTreeGeometry
108 
109  //-----------------------------------------------------------------------
110  CTreeGeometry::CTreeGeometry(fhicl::ParameterSet const& parameterSet) : EDAnalyzer(parameterSet)
111  {
112  reconfigure(parameterSet);
113  }
114 
115  //-----------------------------------------------------------------------
116  CTreeGeometry::~CTreeGeometry() {}
117 
118  //-----------------------------------------------------------------------
119  void CTreeGeometry::reconfigure(fhicl::ParameterSet const& p)
120  {
121  fSaveChannelWireMap = p.get<bool>("saveChannelWireMap");
122  }
123 
124  //-----------------------------------------------------------------------
126  {
127 
128  fNcryostats = fGeom->Ncryostats(); // 1
129 
130  fNTPC = fGeom->NTPC();
131  for (auto const& tpc : fGeom->Iterate<geo::TPCGeo>()) {
132  fTPC_x.push_back(tpc.HalfWidth() * 2);
133  fTPC_y.push_back(tpc.HalfHeight() * 2);
134  fTPC_z.push_back(tpc.Length());
135  }
136 
137  // fNplanes = fGeom->Nplanes();
138  // cout << "#planes: " << fNplanes << endl;
139  // for (int i=0; i<fNplanes; i++) {
140  // fPlane_type.push_back(fGeom->SignalType(geo::PlaneID(0, 0, i)));
141  // fPlane_view.push_back(fGeom->Plane(i).View());
142  // // fPlane_wirepitch[i] = fGeom->WirePitch(fPlane_view[i]); // this doesn't seem to return the correct value!
143  // fPlane_wirepitch.push_back(fGeom->WirePitch(fPlane_view[i], 1, 0)); // this doesn't seem to return the correct value);
144  // fPlane_wireangle.push_back(fGeom->WireAngleToVertical(fGeom->Plane(i).View()));
145  // fPlane_wires.push_back(fGeom->Nwires(i));
146  // }
147 
148  fNchannels = fGeom->Nchannels();
149  // cout << "#channel: " << fNchannels << endl;
150 
151  // Save Channel Map to text file.
152  if (fSaveChannelWireMap) { saveChannelWireMap(); }
153 
154  printGeometry();
155  }
156 
157  //-----------------------------------------------------------------------
158  void CTreeGeometry::saveChannelWireMap()
159  {
160  ofstream out;
161  out.open("ChannelWireGeometry.txt");
162  double xyzStart[3];
163  double xyzEnd[3];
164  out << "# " << fGeom->GDMLFile() << "\n";
165  out << "# channel\ttpc\tplane\twire\tsx\tsy\tsz\tex\tey\tez\n";
166  int current_plane = 0;
167  channel_starts.push_back(0);
168  channel_ends.push_back(0);
169  for (int i = 0; i < fNchannels; i++) {
170  std::vector<geo::WireID> wireids = fGeom->ChannelToWire(i);
171  int nWires = wireids.size();
172  for (int j = 0; j < nWires; j++) {
173  geo::WireID wid = wireids.at(j);
174  int cstat = wid.Cryostat;
175  int tpc = wid.TPC;
176  int plane = wid.Plane;
177  int wire = wid.Wire;
178 
179  int plane_id = plane + tpc * 10 + cstat * 100;
180  if (plane_id != current_plane) {
181  current_plane = plane_id;
182  channel_starts.push_back(i);
183  channel_ends.push_back(i);
184  }
185  else {
186  channel_ends[channel_ends.size() - 1] = i;
187  }
188 
189  fGeom->WireEndPoints(wid, xyzStart, xyzEnd);
190 
191  out << i << "\t" << cstat * 2 + tpc << "\t" << plane << "\t" << wire << "\t";
192  for (int i = 0; i < 3; i++) {
193  out << xyzStart[i] << "\t";
194  }
195  for (int i = 0; i < 3; i++) {
196  out << xyzEnd[i] << "\t";
197  }
198  out << "\n";
199  }
200  }
201  out.close();
202  }
203 
204  //-----------------------------------------------------------------------
205  void CTreeGeometry::endJob() {}
206 
207  //-----------------------------------------------------------------------
208  void CTreeGeometry::printGeometry()
209  {
210  cout << "Detector Name: " << fGeom->DetectorName() << endl;
211  cout << "GDML file: " << fGeom->GDMLFile() << endl;
212  // cout << "fNTPC: " << fNTPC << endl;
213  // for (int i=0; i<fNTPC; i++) {
214  // cout << "\tTPC " << i << ": " << fTPC_x[i] << ", " << fTPC_y[i] << ", " << fTPC_z[i] << endl;
215  // }
216  cout << "TPC (Active) Locations: " << endl;
217  for (geo::TPCGeo const& TPC : fGeom->Iterate<geo::TPCGeo>()) {
218  // get center in world coordinates
219  auto const center = TPC.GetCenter();
220  double tpcDim[3] = {TPC.ActiveHalfWidth(), TPC.ActiveHalfHeight(), 0.5 * TPC.ActiveLength()};
221  double xmin = center.X() - tpcDim[0];
222  double xmax = center.X() + tpcDim[0];
223  double ymin = center.Y() - tpcDim[1];
224  double ymax = center.Y() + tpcDim[1];
225  double zmin = center.Z() - tpcDim[2];
226  double zmax = center.Z() + tpcDim[2];
227  cout << "\t[" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << ", " << zmin << ", "
228  << zmax << "]" << endl;
229  } // for all TPC
230 
231  int size = channel_starts.size();
232  cout << size << " planes: first channels: ";
233  for (int i = 0; i < size; i++) {
234  cout << channel_starts[i] << ", ";
235  }
236  cout << endl;
237  size = channel_ends.size();
238  cout << size << " planes: last channels: ";
239  for (int i = 0; i < size; i++) {
240  cout << channel_ends[i] << ", ";
241  }
242  cout << endl;
243  // for (geo::TPCGeo const& TPC: fGeom->IterateTPCs()) {
244  // for (geo::PlaneGeo const& plane: TPC.IteratePlanes()) {
245  // cout << plane.ID() <<
246  // " channels: " fGeom->PlaneWireToChannel(plane.FirstWire().node())<< endl;
247  // }
248 
249  // }
250 
251  // cout << "fNplanes: " << fNplanes << endl;
252  // for (int i=0; i<fNplanes; i++) {
253  // cout
254  // << "\tplane " << i
255  // << "( type: " << fPlane_type[i]
256  // << ", view: " << fPlane_view[i]
257  // << ", wirepitch: " << fPlane_wirepitch[i]
258  // << ", wire angle: " << fPlane_wireangle[i]
259  // << ", wires: " << fPlane_wires[i]
260  // << ")" << endl;
261  // }
262  cout << "fNchannels: " << fGeom->Nchannels() << endl;
263  cout << "fNOpDet: " << fGeom->NOpDets() << endl;
264  cout << "fAuxDetectors: " << fGeom->NAuxDets() << endl;
265  cout << endl;
266  }
267 
268  //-----------------------------------------------------------------------
269  void CTreeGeometry::analyze(const art::Event& event)
270  {
271 
272  // fEvent = event.id().event();
273  // fRun = event.run();
274  // fSubRun = event.subRun();
275 
276  // printEvent();
277  }
278 
279  DEFINE_ART_MODULE(CTreeGeometry)
280 
281 } // namespace
282 
283 #endif // CTreeGeometry_module
Encapsulate the construction of a single cyostat.
Declaration of signal hit object.
Geometry information for a single TPC.
Definition: TPCGeo.h:36
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:211
STL namespace.
Definition of basic raw digits.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginJob()
Definition: Breakpoints.cc:14
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:314
Provides recob::Track data product.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
Declaration of cluster object.
Definition of data types for geometry description.
Encapsulate the geometry of an optical detector.
Encapsulate the construction of a single detector plane.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Declaration of basic channel signal object.
TCEvent evt
Definition: DataStructs.cxx:8
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:399
art framework interface to geometry description
Event finding and building.