PandaRoot
PndMdtIGeometry.h
Go to the documentation of this file.
1 #ifndef PNDMDTIGEOMETRY_H
2 #define PNDMDTIGEOMETRY_H 1
3 
4 #include "TVector3.h"
5 #include "TGeoVolume.h"
6 #include <vector>
7 #include "TF1.h"
8 #include <map>
9 #include <set>
10 #include "PndMdtID.h"
11 #include "TGeoMatrix.h"
12 #include <iostream>
13 
14 using std::ostream;
15 ostream &operator<<(ostream &os, const TVector3 &v3);
16 
17 class PndMdtIGeometry : public TNamed {
18 
19  public:
20  static PndMdtIGeometry *Instance();
25 
26  void SetVerbose(Int_t _v) { fVerbose = _v; }
27  void AddSensor(TString _v) { fSensorSet.insert(_v); }
28  // version and Init() should be invoked first before using access functions
29  // now only support ROOT geometry version 0, 1, 2
30  Bool_t Init();
31  //================================================================
32  // Access to Tube Geometery for given parameters
33  Bool_t GetTubeCenter(Int_t iDetId, TVector3 &pos) const
34  {
35  std::map<Int_t, InfoType>::const_iterator it = fGeoMap.find(iDetId);
36  if (it == fGeoMap.end())
37  return kFALSE;
38  pos = it->second.Position;
39  return kTRUE;
40  }
41  //
42  Bool_t GetTubeLength(Int_t iDetId, Double_t &len) const
43  {
44  std::map<Int_t, InfoType>::const_iterator it = fGeoMap.find(iDetId);
45  if (it == fGeoMap.end())
46  return kFALSE;
47  len = it->second.Length;
48  return kTRUE;
49  }
50  //
51  Bool_t GetStripLength(Int_t iDetId, Double_t &len) const
52  {
53  std::map<Int_t, InfoType>::const_iterator it = fGeoMap.find(iDetId);
54  if (it == fGeoMap.end())
55  return kFALSE;
56  len = it->second.Length;
57  return kTRUE;
58  }
59  Bool_t GetStripCenter(Int_t iDetId, TVector3 &pos) const
60  {
61  std::map<Int_t, InfoType>::const_iterator it = fGeoMap.find(iDetId);
62  if (it == fGeoMap.end())
63  return kFALSE;
64  pos = it->second.Position;
65  return kTRUE;
66  }
67  Bool_t GetLayerBoundary(Int_t iLayer, TVector3 &LBPos, TVector3 &RTPos) const
68  {
69  std::map<Int_t, LayerBoundary>::const_iterator it = fLayerInfoMap.find(iLayer);
70  if (it == fLayerInfoMap.end())
71  return kFALSE;
72  LBPos = TVector3(it->second.minX, it->second.minY, it->second.minZ);
73  RTPos = TVector3(it->second.maxX, it->second.maxY, it->second.maxZ);
74  return kTRUE;
75  }
76  Bool_t MasterToLocal(Int_t iDetId, TVector3 &master, TVector3 &local)
77  {
78  std::map<Int_t, InfoType>::const_iterator it = fGeoMap.find(iDetId);
79  if (it == fGeoMap.end())
80  return kFALSE;
81  TVector3 center = it->second.Position;
82  TGeoMatrix *fMtrx = it->second.Matrix;
83  if (!fMtrx)
84  return kFALSE;
85  // fMtrx->Print();
86  // fMtrx->MasterToLocal(&center[0], &local[0]);
87  // std::cout<<"local 1 "<<local<<std::endl;
88  fMtrx->MasterToLocal(&master[0], &local[0]);
89  // std::cout<<"local 2 "<<local<<std::endl;
90  return kTRUE;
91  }
92  Bool_t MapWireToStrip(Int_t iDetId, const TVector3 &fEntryPos, Int_t &fStripDetID)
93  {
94  static const Double_t cSTRIPWIDTH = 1.; // cent meter;
95  static const Double_t cGAPOFSTRIPS = 0.0; // cent meter;
96  Short_t iMod = PndMdtID::Module(iDetId);
97  Short_t iSec = PndMdtID::Sector(iDetId);
98  Short_t iLayer = PndMdtID::Layer(iDetId);
99  Int_t layerID = PndMdtID::LayerID(iMod, iSec, iLayer);
100  LayerInfoMapIter it = fLayerInfoMap.find(layerID);
101  if (it == fLayerInfoMap.end())
102  return kFALSE;
103  Int_t fStripNo;
104  if (iMod == 1)
105  fStripNo = (fEntryPos.Z() - it->second.minZ) / (cSTRIPWIDTH + cGAPOFSTRIPS);
106  else if (iMod == 2) // endcap
107  {
108  if (iLayer < 2)
109  fStripNo = (fEntryPos.Y() - it->second.minY) / (cSTRIPWIDTH + cGAPOFSTRIPS);
110  else
111  fStripNo = (fEntryPos.X() - it->second.minX) / (cSTRIPWIDTH + cGAPOFSTRIPS);
112  } else
113  fStripNo = (fEntryPos.X() - it->second.minX) / (cSTRIPWIDTH + cGAPOFSTRIPS);
114  fStripDetID = PndMdtID::Identifier(iMod, iSec, iLayer, fStripNo);
115  return kTRUE;
116  }
117  void Print() const;
118 
119  private:
120  std::set<TString> fSensorSet;
121  Bool_t FindSensorinPath(TString path)
122  {
123  Bool_t ret = kFALSE;
124  std::set<TString>::iterator it = fSensorSet.begin();
125  std::set<TString>::iterator end = fSensorSet.end();
126  while (it != end) {
127  if (path.Contains(*it)) {
128  ret = kTRUE;
129  break;
130  }
131  ++it;
132  }
133  return ret;
134  }
135 
136  private:
137  Int_t fVerbose;
138  Bool_t fGoodGeometry;
139  TString fStateTip;
140 
141  public:
142  struct InfoType {
143  TVector3 Position;
144  Double_t Length;
145  TGeoMatrix *Matrix;
146  };
147 
148  private:
149  std::map<Int_t, InfoType> fGeoMap;
150  std::map<Int_t, TGeoMatrix *> fMatrixMap;
151 
152  public:
153  struct LayerBoundary {
154  Double_t minX;
155  Double_t minY;
156  Double_t minZ;
157  Double_t maxX;
158  Double_t maxY;
159  Double_t maxZ;
160  };
161 
162  private:
163  std::map<Int_t, LayerBoundary> fLayerInfoMap;
164  typedef std::map<Int_t, LayerBoundary>::iterator LayerInfoMapIter;
165  typedef std::pair<Int_t, LayerBoundary> LayerInfoMapValue;
166 
167  Int_t fBarrelVersion;
168  Int_t fEndcapVersion;
169  Int_t fForwardVersion;
170  Int_t fMuonFilterVersion;
171  Int_t fNumofMdt;
172  Int_t fNumofStrip;
173  Bool_t fInitialized;
174 
175  void LoadGeometry(TGeoNode *node);
176  Bool_t GetStripInfo();
177  Bool_t GetGeometryInfoV2(const TString &fFullPath, const TString &Name);
178  void InsertLayerInfo(Int_t layerID, const TVector3 &pos, const TVector3 &lwh);
179 
180  Bool_t AddTubeInfo(Int_t detID, const TVector3 &center, Double_t wirelen, TGeoMatrix *matrix);
181  Bool_t AddStripInfo(Int_t detID, TVector3 stripPos, Double_t stripLen, TGeoMatrix *matrix = 0);
182  Bool_t AddMatrix(Int_t layerID, TGeoMatrix *matrix);
183 
184  static PndMdtIGeometry *fInstance;
185 
186  ClassDef(PndMdtIGeometry, 1);
187 };
188 
189 #endif
ostream & operator<<(ostream &os, const TVector3 &v3)
static Short_t Module(Int_t detID)
Definition: PndMdtID.h:16
Bool_t MasterToLocal(Int_t iDetId, TVector3 &master, TVector3 &local)
static Short_t Layer(Int_t detID)
Definition: PndMdtID.h:18
Bool_t GetTubeLength(Int_t iDetId, Double_t &len) const
Bool_t GetLayerBoundary(Int_t iLayer, TVector3 &LBPos, TVector3 &RTPos) const
static Int_t LayerID(Int_t iMod, Int_t iOct, Int_t iLayer)
Definition: PndMdtID.h:13
static Int_t Identifier(Int_t iMod, Int_t iOct, Int_t iLayer, Int_t iBox, Int_t iWire)
Definition: PndMdtID.h:9
Bool_t MapWireToStrip(Int_t iDetId, const TVector3 &fEntryPos, Int_t &fStripDetID)
Bool_t GetStripCenter(Int_t iDetId, TVector3 &pos) const
static Short_t Sector(Int_t detID)
Definition: PndMdtID.h:17
Bool_t GetTubeCenter(Int_t iDetId, TVector3 &pos) const
void AddSensor(TString _v)
void SetVerbose(Int_t _v)
Bool_t GetStripLength(Int_t iDetId, Double_t &len) const
void Print() const
static PndMdtIGeometry * Instance()
basic_ostream< char, char_traits< char > > ostream