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