GeometryBase.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file GeometryBase.h
3 /// \brief Encapsulate the geometry of one entire detector (near, far,
4 /// ndos)
5 ///
6 /// \version $Id: GeometryBase.h,v 1.6 2012-12-05 02:24:17 bckhouse Exp $
7 /// \author messier@indiana.edu
8 ////////////////////////////////////////////////////////////////////////
9 #ifndef GEO_GEOMETRYBASE_H
10 #define GEO_GEOMETRYBASE_H
11 
16 #include "NovaDAQConventions/DAQConventions.h"
17 
18 #include "fhiclcpp/types/Atom.h"
19 #include "fhiclcpp/types/Table.h"
20 
21 #include <map>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include "TVector3.h"
27 
28 class TGeoNode;
29 class TGeoMaterial;
30 class TGeoManager;
31 
32 namespace CLHEP{class HepRandomEngine;}
33 
34 namespace geo {
35  class PlaneGeo;
36  class CellGeo;
37  /// Return codes which flag errors and the like
40  };
41 
42  typedef struct{
43  OfflineChan chan; ///< Channel passed through by line
44  TVector3 entry; ///< Entry point into cell
45  TVector3 exit; ///< Exit point from cell
46  } CellOnLine;
47 
48  /// The geometry of one entire detector (near, far, ipnd)
49  class GeometryBase {
50  public:
51  template<class T> using Atom = fhicl::Atom<T>;
52  template<class T> using Table = fhicl::Table<T>;
54  using Name = fhicl::Name;
55 
57  {
58  Atom<bool> BigBoxUsed{Name("BigBoxUsed")};
59  Atom<double> BigBoxRange{Name("BigBoxRange"), Comment("in cm")};
60  Atom<double> FiducialVolumeXHi{Name("FiducialVolumeXHi")};
61  Atom<double> FiducialVolumeXLo{Name("FiducialVolumeXLo")};
62  Atom<double> FiducialVolumeYHi{Name("FiducialVolumeYHi")};
63  Atom<double> FiducialVolumeYLo{Name("FiducialVolumeYLo")};
64  Atom<double> FiducialVolumeZHi{Name("FiducialVolumeZHi")};
65  Atom<double> FiducialVolumeZLo{Name("FiducialVolumeZLo")};
66  };
67 
68  struct Params
69  {
70  Atom<std::string> GDMLFile{Name("GDML")};
71  Atom<bool> ForceUseFCLOnly{Name("ForceUseFCLOnly"), Comment("Force geometry to only use the value set by the fcl file"), false};
72  Atom<std::string> StoreTempGeo{Name("StoreTempGeo"), Comment("Folder to store temporary geometry files in")};
73 
74  Table<DetectorParams> ndos{Name("ndos")};
78  };
79 
80  GeometryBase(const Params& params);
81  virtual ~GeometryBase();
82 
83  // Information about planes and cells
84  const PlaneGeo* Plane(unsigned int i) const;
85  const std::set<unsigned int>& GetPlanesByView(View_t v=kXorY) const;
86  const unsigned int NextPlaneInView(unsigned int p,
87  int d=+1) const;
88  const unsigned int NextPlaneOtherView(unsigned int p,
89  int d=+1) const;
90  const unsigned int FirstPlaneInMuonCatcher() const;
91  double CellTpos(unsigned int ip, unsigned int ic, double w=0.0) const;
92  void CellInfo(unsigned int ip, unsigned int ic,
93  View_t* view=0, double* pos=0, double* dpos=0) const;
94 
95  const CellGeo* IdToCell(const CellUniqueId& id,
96  int* iplane, int* icell) const;
97 
98  const PlaneGeo* IdToPlane(const CellUniqueId& id,
99  int* iplane) const;
100 
101  /// Same as IdToCell and IdToPlane, but doesn't calculate CellGeo (PlaneGeo),
102  /// just the global plane number or cell number
103  int getPlaneID(const CellUniqueId& id) const;
104  int getCellID (const CellUniqueId& id) const;
105  bool getPlaneAndCellID(const CellUniqueId& id, int& plane, int& cell) const;
106  int getPlaneID(const double& x, const double& y, const double& z) const {return getPlaneID(CellId(x,y,z));}
107  int getCellID (const double& x, const double& y, const double& z) const {return getCellID(CellId(x,y,z));}
108  bool getPlaneAndCellID(const double& x, const double& y, const double& z, int& plane, int& cell) const{return getPlaneAndCellID(CellId(x,y,z), plane, cell);}
109 
110 
111  void CountCellsOnLine(double X1, double Y1, double Z1,
112  double X2, double Y2, double Z2,
113  std::vector<OfflineChan>& Xhitsonline,
114  std::vector<OfflineChan>& Yhitsonline);
115 
116  void CountCellsOnLine(TVector3 r1, TVector3 r2,
117  std::vector<OfflineChan>& Xhitsonline,
118  std::vector<OfflineChan>& Yhitsonline);
119 
120  /// \brief Make list of cells in each view traversed by a line segment and the entry and exit points into each cell
121  void CountCellsOnLine(double X1, double Y1, double Z1,
122  double X2, double Y2, double Z2,
123  std::vector<CellOnLine>& Xhitsonline,
124  std::vector<CellOnLine>& Yhitsonline);
125 
126  void CountCellsOnLine(TVector3 r1, TVector3 r2,
127  std::vector<CellOnLine>& Xhitsonline,
128  std::vector<CellOnLine>& Yhitsonline);
129 
130 
131  /// \brief Make list of cells in each view traversed by a line segment
132  ///
133  /// Unlike \ref CountCellsOnLine, which uses the full geometry, here we
134  /// make some assumptions about cuboidal cells and the effects of
135  /// alignment. For this loss in accuracy we gain a lot of speed.
136  void CountCellsOnLineFast(double x1, double y1, double z1,
137  double x2, double y2, double z2,
138  std::vector<OfflineChan>& Xhitsonline,
139  std::vector<OfflineChan>& Yhitsonline);
140 
141  void CountCellsOnLineFast(TVector3 r1, TVector3 r2,
142  std::vector<OfflineChan>& Xhitsonline,
143  std::vector<OfflineChan>& Yhitsonline);
144 
145  /// 2D version
146  void CountCellsOnLineFast(geo::View_t view,
147  double v1, double z1,
148  double v2, double z2,
149  std::vector<OfflineChan>& hitsonline);
150 
151  // Size of detector, information about "world" frames
152  unsigned int NPlanes() const;
153  double DetHalfWidth() const;
154  double DetHalfHeight() const;
155  double DetLength() const;
156  double SurfaceY() const;
157 
158  /// \brief Direction of neutrinos from the NuMI beam (unit vector)
159  ///
160  /// Because of the varying location of pion decays in the decay pipe, this
161  /// can only be an average value in the ND and NDOS.
162  TVector3 NuMIBeamDirection() const;
163 
164  /// Direction of neutrinos from the Booster beam (unit vector)
165  TVector3 BoosterBeamDirection() const;
166 
167  ///get distance from local z position in cell to apd in cm, including pigtail
168  double DistToElectronics(double localz, const CellGeo& cell) const;
169 
170  /// Return length of fiber in cm from end of cell to apd
171  double GetPigtail(const CellUniqueId& id) const;
172 
173  // Boxes
174  void WorldBox(double* xlo_cm, double* xhi_cm,
175  double* ylo_cm, double* yhi_cm,
176  double* zlo_cm, double* zhi_cm) const;
177 
178  void DetectorEnclosureBox(double* xlo_cm, double* xhi_cm,
179  double* ylo_cm, double* yhi_cm,
180  double* zlo_cm, double* zhi_cm) const;
181 
182  void DetectorBigBox(double* xlo_cm, double* xhi_cm,
183  double* ylo_cm, double* yhi_cm,
184  double* zlo_cm, double* zhi_cm) const;
185 
186  bool IntersectsDetector(double* xyz_cm, double* dxyz) const;
187  bool IntersectsBigBox(double* xyz_cm, double* dxyz) const;
188  // DetectorBigBox stuff
189  /// Do we use the Detector Big Box
190  bool isDetectorBigBoxUsed() const {return fIsDetectorBigBoxUsed;}
191  /// Is the particle inside the detector Big Box?
192  bool isInsideDetectorBigBox(const double x_cm, const double y_cm, const double z_cm) const;
193 
194  /// Is the particle inside the detector Fiducial Volume?
195  bool isInsideFiducialVolume(const double x_cm, const double y_cm, const double z_cm) const;
196  bool isInsideFiducialVolume(const double* xyz_dimensionless) const;
197 
198  void FiducialBox(TVector3& r0, TVector3& r1) const;
199 
200  // Useful for tracking and swimming through a TGeometry
201  int CurrentCell(int* ip, int* ic) const;
202  const CellUniqueId CurrentCellId() const;
203  const CellUniqueId CellId(const double& x, const double& y, const double& z,
204  double dxds=0., double dyds=0.,
205  double dzds=1.,double step=0.01) const;
206  TGeoMaterial* Material(double x, double y, double z) const;
207  bool IsActive(const TGeoMaterial* m) const;
208  double TotalMass(const char *volume="vDetEnclosure") const;
209  double MassBetweenPoints(double *p1, double *p2) const;
210 
211  void MaterialsBetweenPoints(const double *p1,
212  const double *p2,
213  std::vector<double>& ds,
214  std::vector<const TGeoMaterial*>& mat) const;
215 
216  void MaterialsBetweenPoints(TVector3 v1,
217  TVector3 v2,
218  std::vector<double>& ds,
219  std::vector<const TGeoMaterial*>& mat) const;
220 
221  bool calculateMassesLong(const unsigned int number_of_points,
222  CLHEP::HepRandomEngine& engine) const;
223  double DEdge(const double* x0, const double* dx,
224  double *exitp=0) const;
225  double ClosestApproach(unsigned int ip,
226  unsigned int ic,
227  const TVector3& vtx,
228  const TVector3& dir,
229  double dx=0.0,
230  double dy=0.0,
231  double* w=0,
232  double* s=0,
233  TVector3* point_in_cell=0,
234  TVector3* point_on_track=0) const;
235  std::string GDMLFile() const { return fGDMLFile; }
236  std::string ROOTFile() const { return fROOTFile; }
237  std::string GDMLFromFCL() const { return fGDMLFromFCL; }
238  std::string FileBaseName() const;
239  int Run() const { return fRunNumber; }
240  TGeoManager* ROOTGeoManager() const;
241 
242  /// Prefer \ref ds::DetectorService::DetId() instead
243  novadaq::cnv::DetId DetId() const { return fDetId; }
244 
245  CoordinateTransformation* getCoordinateTransformation() const { return (CoordinateTransformation*)&fCoordinateTransformation;}
246  /// Extract contents from \ref fGDMLFile and return as a string
247  std::string ExtractGDML() const;
248  /// \brief Extract contents from \a fname and return as a string
249  ///
250  /// \param fullpath If false, search for the file in FW_SEARCH_PATH
251  static std::string ExtractGDML(std::string fname, bool fullpath);
252 
253  protected:
254 
255  typedef std::unordered_map<CellUniqueId, OfflineChan> UIDMap;
256  geo::OfflineChan getPlaneCellMap(const CellUniqueId& id) const;
257 
258  /// Method to set DetectorID
259  virtual void setDetectorID(novadaq::cnv::DetId);
260 
261  void setDetectorBigBox(double detector_bigbox_range);
262 
263  void FindPlanes(std::vector<const TGeoNode*>& n, unsigned int depth, bool inMuonCatcher = false);
264  void MakePlane (std::vector<const TGeoNode*>& n, unsigned int depth, bool inMuonCatcher);
265  void SetDrawOptions();
266  void BuildMaps();
267  void SetDetectorSize();
268 
269  /// In case of unknown ID, guesses from the filename
270  bool LoadGeometryFile(std::string gdmlfile, novadaq::cnv::DetId det_id = novadaq::cnv::kUNKNOWN_DET);
271 
272  int MakeTmpFile(std::string gdmlInfo);
273  void RemoveTmpFile(std::string fileName);
274 
275  /// Search for Geometry/gdml/fname in FW_SEARCH_PATH, return full path
276  static std::string FindGDMLFile(std::string fname);
277 
278  protected:
280 
281  std::string fGDMLFile; ///< gdml file holding the geometry
282  std::string fROOTFile; ///< root file holding the geometry
283  std::string fGDMLFromFCL; ///< keep track of original fcl parameter
284 
285  novadaq::cnv::DetId fDetId; ///< id for the detector being used
286 
287 
288  /// Coordinate Transformation class
290 
291  std::vector<PlaneGeo*> fPlanes; ///< The detector planes
292  std::vector<PlaneGeo*> fPlanesInMuonCatcher; ///< Same pointers as fPlanes
293  UIDMap fIdMap; ///< Unique ID -> Plane,Cell
294 
295  std::set<unsigned int> fAllPlanes; ///< List of all planes
296  std::set<unsigned int> fXplanes; ///< List of X measuring planes
297  std::set<unsigned int> fYplanes; ///< List of Y measuring planes
298 
299  double fDetLength; ///< Detector length (cm)
300  double fDetHalfHeight; ///< Detector 1/2 height (cm)
301  double fDetHalfWidth; ///< Detector 1/2 width (cm)
302 
303  // Detector Big Box is the box surrounding the detector enclosure
304  // It is usually defined by adding 15m to each if the enclosure dimension,
305  // but could be redefined in the detectorbigbox.xml
306  // This is used in Geant - if the particle leaves it, stop tracking it.
307  // As well as in the Cosmic generator - if the cosmic ray particle doesn't intersect it,
308  // don't put it in the stack.
309  // DetectorBigBox dimensions in cm
310  bool fIsDetectorBigBoxUsed; ///< Do we need to use the BigBox cut?
311  double fBigBoxRange; ///< Range of big box
312 
313  /// Dimensions of the DetectorBigBox in cm
320 
321  fhicl::ParameterSet fConfigNDOS, fConfigND, fConfigFD, fConfigTB;
322 
329 
330  std::string fStoreTempGeo; ///< folder to store temp geo file
331 
332  unsigned int fRunNumber; ///< Run number of configuration
333  };
334 }
335 #endif // GEO_GEOMETRYBASE_H
336 ////////////////////////////////////////////////////////////////////////
novadaq::cnv::DetId fDetId
id for the detector being used
Definition: GeometryBase.h:285
double fFiducialVolumeZLo
Definition: GeometryBase.h:328
bool getPlaneAndCellID(const double &x, const double &y, const double &z, int &plane, int &cell) const
Definition: GeometryBase.h:108
bool isDetectorBigBoxUsed() const
Do we use the Detector Big Box.
Definition: GeometryBase.h:190
fileName
Definition: plotROC.py:78
double fDetectorBigBoxXHi
Dimensions of the DetectorBigBox in cm.
Definition: GeometryBase.h:314
double fDetLength
Detector length (cm)
Definition: GeometryBase.h:299
Float_t y1[n_points_granero]
Definition: compare.C:5
std::string fROOTFile
root file holding the geometry
Definition: GeometryBase.h:282
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Float_t x1[n_points_granero]
Definition: compare.C:5
Definition: geo.h:1
const char * p
Definition: xmltok.h:285
std::string fGDMLFile
gdml file holding the geometry
Definition: GeometryBase.h:281
bool fIsDetectorBigBoxUsed
Do we need to use the BigBox cut?
Definition: GeometryBase.h:310
std::set< unsigned int > fAllPlanes
List of all planes.
Definition: GeometryBase.h:295
std::string GDMLFromFCL() const
Definition: GeometryBase.h:237
double fFiducialVolumeXLo
Definition: GeometryBase.h:324
int Run() const
Definition: GeometryBase.h:239
TString ip
Definition: loadincs.C:5
double fDetHalfHeight
Detector 1/2 height (cm)
Definition: GeometryBase.h:300
std::vector< PlaneGeo * > fPlanes
The detector planes.
Definition: GeometryBase.h:291
double fDetHalfWidth
Detector 1/2 width (cm)
Definition: GeometryBase.h:301
TVector3 exit
Exit point from cell.
Definition: GeometryBase.h:45
CoordinateTransformation * getCoordinateTransformation() const
Definition: GeometryBase.h:245
double fFiducialVolumeXHi
Definition: GeometryBase.h:323
Double_t X2
Definition: plot.C:264
Give every cell in the geometry a unique ID number based on the TGeo path to the node.
const XML_Char * s
Definition: expat.h:262
double dy[NP][NC]
double dx[NP][NC]
unsigned int fRunNumber
Run number of configuration.
Definition: GeometryBase.h:332
int getCellID(const double &x, const double &y, const double &z) const
Definition: GeometryBase.h:107
Double_t X1
Definition: plot.C:264
Double_t Y1
Definition: plot.C:264
TVector3 entry
Entry point into cell.
Definition: GeometryBase.h:44
std::set< unsigned int > fYplanes
List of Y measuring planes.
Definition: GeometryBase.h:297
UIDMap fIdMap
Unique ID -> Plane,Cell.
Definition: GeometryBase.h:293
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Geometry information for a single readout plane.
Definition: PlaneGeo.h:36
_return_codes
Return codes which flag errors and the like.
Definition: GeometryBase.h:38
double fDetectorBigBoxZHi
Definition: GeometryBase.h:318
void FindPlanes(TGeoNode *n, TGeoVolume *v)
Definition: geom.C:146
Material
Definition: BetheBloch.h:16
Float_t d
Definition: plot.C:236
void SetDrawOptions()
Definition: geom.C:4
Definition: structs.h:1
CoordinateTransformation fCoordinateTransformation
Coordinate Transformation class.
Definition: GeometryBase.h:289
double fDetectorBigBoxXLo
Definition: GeometryBase.h:315
double fDetectorBigBoxYLo
Definition: GeometryBase.h:317
double fFiducialVolumeZHi
Definition: GeometryBase.h:327
double fBigBoxRange
Range of big box.
Definition: GeometryBase.h:311
z
Definition: test.py:28
A very simple service to remember what detector we&#39;re working in.
std::string GDMLFile() const
Definition: GeometryBase.h:235
static constexpr double m
Double_t Z2
Definition: plot.C:264
std::vector< PlaneGeo * > fPlanesInMuonCatcher
Same pointers as fPlanes.
Definition: GeometryBase.h:292
Double_t Z1
Definition: plot.C:264
int getPlaneID(const double &x, const double &y, const double &z) const
Definition: GeometryBase.h:106
unsigned long long int CellUniqueId
Definition: CellUniqueId.h:15
std::set< unsigned int > fXplanes
List of X measuring planes.
Definition: GeometryBase.h:296
double fDetectorBigBoxZLo
Definition: GeometryBase.h:319
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
OfflineChan chan
Channel passed through by line.
Definition: GeometryBase.h:43
double ClosestApproach(const double point[], const double intercept[], const double slopes[], double closest[])
Find the distance of closest approach between point and line.
Definition: Geo.cxx:222
TDirectory * dir
Definition: macro.C:5
A (plane, cell) pair.
Definition: OfflineChan.h:17
fhicl::ParameterSet fConfigTB
Definition: GeometryBase.h:321
std::unordered_map< CellUniqueId, OfflineChan > UIDMap
Definition: GeometryBase.h:255
TVector3 NuMIBeamDirection(caf::Det_t det)
Average direction of NuMI neutrinos in a given detector This function is a copy of geo::GeometryBase:...
Definition: Utilities.cxx:333
double fDetectorBigBoxYHi
Definition: GeometryBase.h:316
std::string ROOTFile() const
Definition: GeometryBase.h:236
The geometry of one entire detector (near, far, ipnd)
Definition: GeometryBase.h:49
double fFiducialVolumeYHi
Definition: GeometryBase.h:325
std::string fGDMLFromFCL
keep track of original fcl parameter
Definition: GeometryBase.h:283
Encapsulate the cell geometry.
Definition: CellGeo.h:25
Helper for AttenCurve.
Definition: Path.h:10
double fFiducialVolumeYLo
Definition: GeometryBase.h:326
Float_t w
Definition: plot.C:20
Simple object representing a (plane, cell) pair.
Eigen::MatrixXd mat
Double_t Y2
Definition: plot.C:264
std::string fStoreTempGeo
folder to store temp geo file
Definition: GeometryBase.h:330