LArSoft  v10_04_05
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 // LArSoft includes
11 
12 // Framework includes
17 #include "fhiclcpp/ParameterSet.h"
18 
19 // C++ Includes
20 #include <fstream>
21 #include <iomanip>
22 #include <iostream>
23 #include <vector>
24 
25 using namespace std;
26 
27 namespace {
28 
29  class CTreeGeometry : public art::EDAnalyzer {
30  public:
31  explicit CTreeGeometry(fhicl::ParameterSet const& pset);
32 
33  private:
34  void beginJob() override;
35  void analyze(const art::Event& evt) override;
36 
37  void saveChannelWireMap();
38  void printGeometry();
39 
40  // the parameters we'll read from the .fcl
41  bool fSaveChannelWireMap;
42 
44  geo::WireReadoutGeom const* fWireReadoutGeom{
46  geo::AuxDetGeometryCore const* fAuxDetGeom{
47  art::ServiceHandle<geo::AuxDetGeometry>()->GetProviderPtr()};
48 
49  // Geometry Tree Leafs
50  int fNchannels;
51  vector<int> channel_starts; // vector os channel starts on each plane
52  vector<int> channel_ends; // vector os channel starts on each plane
53 
54  }; // class CTreeGeometry
55 
56  //-----------------------------------------------------------------------
57  CTreeGeometry::CTreeGeometry(fhicl::ParameterSet const& pset)
58  : EDAnalyzer(pset), fSaveChannelWireMap{pset.get<bool>("saveChannelWireMap")}
59  {}
60 
61  //-----------------------------------------------------------------------
63  {
64  fNchannels = fWireReadoutGeom->Nchannels();
65 
66  // Save Channel Map to text file.
67  if (fSaveChannelWireMap) { saveChannelWireMap(); }
68 
69  printGeometry();
70  }
71 
72  //-----------------------------------------------------------------------
73  void CTreeGeometry::saveChannelWireMap()
74  {
75  ofstream out;
76  out.open("ChannelWireGeometry.txt");
77  double xyzStart[3];
78  double xyzEnd[3];
79  out << "# " << fGeom->GDMLFile() << "\n";
80  out << "# channel\ttpc\tplane\twire\tsx\tsy\tsz\tex\tey\tez\n";
81  int current_plane = 0;
82  channel_starts.push_back(0);
83  channel_ends.push_back(0);
84  for (int i = 0; i < fNchannels; i++) {
85  std::vector<geo::WireID> wireids = fWireReadoutGeom->ChannelToWire(i);
86  int nWires = wireids.size();
87  for (int j = 0; j < nWires; j++) {
88  geo::WireID wid = wireids.at(j);
89  int cstat = wid.Cryostat;
90  int tpc = wid.TPC;
91  int plane = wid.Plane;
92  int wire = wid.Wire;
93 
94  int plane_id = plane + tpc * 10 + cstat * 100;
95  if (plane_id != current_plane) {
96  current_plane = plane_id;
97  channel_starts.push_back(i);
98  channel_ends.push_back(i);
99  }
100  else {
101  channel_ends[channel_ends.size() - 1] = i;
102  }
103 
104  fWireReadoutGeom->WireEndPoints(wid, xyzStart, xyzEnd);
105 
106  out << i << "\t" << cstat * 2 + tpc << "\t" << plane << "\t" << wire << "\t";
107  for (int i = 0; i < 3; i++) {
108  out << xyzStart[i] << "\t";
109  }
110  for (int i = 0; i < 3; i++) {
111  out << xyzEnd[i] << "\t";
112  }
113  out << "\n";
114  }
115  }
116  out.close();
117  }
118 
119  //-----------------------------------------------------------------------
120  void CTreeGeometry::printGeometry()
121  {
122  cout << "Detector Name: " << fGeom->DetectorName() << endl;
123  cout << "GDML file: " << fGeom->GDMLFile() << endl;
124  cout << "TPC (Active) Locations: " << endl;
125  for (geo::TPCGeo const& TPC : fGeom->Iterate<geo::TPCGeo>()) {
126  // get center in world coordinates
127  auto const center = TPC.GetCenter();
128  double tpcDim[3] = {TPC.ActiveHalfWidth(), TPC.ActiveHalfHeight(), 0.5 * TPC.ActiveLength()};
129  double xmin = center.X() - tpcDim[0];
130  double xmax = center.X() + tpcDim[0];
131  double ymin = center.Y() - tpcDim[1];
132  double ymax = center.Y() + tpcDim[1];
133  double zmin = center.Z() - tpcDim[2];
134  double zmax = center.Z() + tpcDim[2];
135  cout << "\t[" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << ", " << zmin << ", "
136  << zmax << "]" << endl;
137  } // for all TPC
138 
139  int size = channel_starts.size();
140  cout << size << " planes: first channels: ";
141  for (int i = 0; i < size; i++) {
142  cout << channel_starts[i] << ", ";
143  }
144  cout << endl;
145  size = channel_ends.size();
146  cout << size << " planes: last channels: ";
147  for (int i = 0; i < size; i++) {
148  cout << channel_ends[i] << ", ";
149  }
150  cout << endl;
151 
152  cout << "fNchannels: " << fNchannels << endl;
153  cout << "fNOpDet: " << fGeom->NOpDets() << endl;
154  cout << "fAuxDetectors: " << fAuxDetGeom->NAuxDets() << endl;
155  cout << endl;
156  }
157 
158  //-----------------------------------------------------------------------
159  void CTreeGeometry::analyze(const art::Event&) {}
160 
161  DEFINE_ART_MODULE(CTreeGeometry)
162 
163 } // namespace
Geometry information for a single TPC.
Definition: TPCGeo.h:33
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:195
STL namespace.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:430
Description of physical geometry of one set of auxiliary detectors.
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
Interface for a class providing readout channel mapping to geometry.
T get(std::string const &key) const
Definition: ParameterSet.h:314
art framework interface to geometry description for auxiliary detectors
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:373
Definition of data types for geometry description.
TCEvent evt
Definition: DataStructs.cxx:8
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:315
art framework interface to geometry description
Encapsulate the construction of a single detector plane .