StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FwdGeomUtils.h
1 #ifndef FWD_GEOM_UTILS_H
2 #define FWD_GEOM_UTILS_H
3 
4 #include "TGeoVolume.h"
5 #include "TGeoNode.h"
6 #include "TGeoMatrix.h"
7 #include "TGeoNavigator.h"
8 
9 class FwdGeomUtils {
10  public:
11 
12  FwdGeomUtils( TGeoManager * gMan ) {
13  if ( gMan != nullptr )
14  _navigator = gMan->AddNavigator();
15  }
16 
17  ~FwdGeomUtils(){
18 
19  }
20 
21  bool cd( const char* path ){
22  // Change to the specified path
23  bool ret = _navigator -> cd(path);
24  // If successful, set the node, the volume, and the GLOBAL transformation
25  // for the requested node. Otherwise, invalidate these
26  if ( ret ) {
27  _matrix = _navigator->GetCurrentMatrix();
28  _node = _navigator->GetCurrentNode();
29  _volume = _node->GetVolume();
30  } else {
31  _matrix = 0; _node = 0; _volume = 0;
32  }
33  return ret;
34  }
35 
36  vector<double> fttZ( vector<double> defaultZ ) {
37  double z0 = fttZ(0);
38  if ( z0 > 1.0 ) { // returns 0 on faiure
39  vector<double> z = {z0, fttZ(1), fttZ(2), fttZ(3)};
40  return z;
41  }
42  return defaultZ;
43  }
44  double fttZ( int index ) {
45 
46  // This ftt_z_delta is needed to match the z location of hits (midpint of active volume?) to the z location of the mother volume.
47  // NOTE: It may be possible to improve this when the higher precision FTT geometry model is added
48  const double ftt_z_delta = -0.5825245;
49  stringstream spath;
50  spath << "/HALL_1/CAVE_1/STGM_1/STFM_" << (index + 1) * 4 << "/";
51  bool can = cd( spath.str().c_str() );
52  if ( can && _matrix != nullptr ){
53  return _matrix->GetTranslation()[2] + ftt_z_delta;
54  }
55  return 0.0;
56  }
57 
58  vector<double> fstZ( vector<double> defaultZ ) {
59  double z0 = fstZ(0);
60  if ( z0 > 1.0 ) { // returns 0 on faiure
61  vector<double> z = {z0, fstZ(1), fstZ(2)};
62  return z;
63  }
64  return defaultZ;
65  }
66 
67  double fstZ( int index ) {
68  // starting in FtsmGeom v1.16? or 1.17
69  // the index are now 4,5,6
70  // hence +4 below
71  // also fixed typo, previously was incorrectly FTSD_
72 
73  stringstream spath;
74  spath << "/HALL_1/CAVE_1/FSTM_1/FSTD_" << (index + 4) << "/";
75  bool can = cd( spath.str().c_str() );
76  if ( can && _matrix != nullptr ){
77  return _matrix->GetTranslation()[2];
78  }
79  return 0.0;
80  }
81 
82  protected:
83  TGeoVolume *_volume = nullptr;
84  TGeoNode *_node = nullptr;
85  TGeoHMatrix *_matrix = nullptr;
86  TGeoIterator *_iter = nullptr;
87  TGeoNavigator *_navigator = nullptr;
88 };
89 
90 #endif