StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMtdGeometry.h
1 /********************************************************************
2  * $Id: StMtdGeometry.h,v 1.13 2017/03/08 20:40:38 marr Exp $
3  ********************************************************************
4  *
5  * $Log: StMtdGeometry.h,v $
6  * Revision 1.13 2017/03/08 20:40:38 marr
7  * Add back the old implementation of GetCellLocalYCenter() function to make
8  * the class backward compatible.
9  *
10  * Revision 1.12 2017/02/13 02:56:11 marr
11  * From 2017, do not move BL 8&24 along y direction by hand since this is already
12  * done in the geometry file. Calibration, production and analysis should use
13  * the new version consistently.
14  *
15  * Revision 1.11 2016/08/05 16:12:34 marr
16  * Add MTD hit IdTruth to avoid applying dy shift for BL 8 and 24 for MC hits
17  *
18  * Revision 1.10 2015/07/29 01:11:25 smirnovd
19  * Initialize static constants outside of class definition
20  *
21  * C++ forbids initialization of non-integral static const members within the class
22  * definition. The syntax is allowed only for integral type variables.
23  *
24  * Revision 1.9 2015/07/24 15:56:05 marr
25  * 1. Remove calling a macro in Init() to create geometry. It should be done within
26  * the maker that uses this utility class.
27  * 2. Add the TGeoManager parameter to the default constructor to force the existance
28  * of the gometry when using this utility class.
29  * 3. Simplify the code for getting the pointer to the magnetic field
30  *
31  * Revision 1.8 2015/05/01 01:55:34 marr
32  * Fix the geometry of shifted backleg 8 and 24
33  *
34  * Revision 1.7 2015/04/07 16:23:33 marr
35  * 1. Make use the constants defined in StMtdConstants.h
36  * 2. Cleaning up
37  *
38  * Revision 1.6 2014/08/06 11:43:28 jeromel
39  * Suffix on literals need to be space (later gcc compiler makes it an error) - first wave of fixes
40  *
41  * Revision 1.5 2014/07/16 15:31:01 huangbc
42  * Add an option to lock bfield to FF.
43  *
44  * Revision 1.4 2014/07/10 20:45:13 huangbc
45  * New geometry class for MTD, load geometry from geant geometry. Need gGeoManager.
46  *
47  * Revision 1.3 2013/08/07 18:27:01 geurts
48  * - updated strip gap dimension from old to current MRPC design [Bingchu]
49  * - include CVS Id and Log tags
50  *
51  *
52  *******************************************************************/
53 #ifndef StMtdGeometry_HH
54 #define StMtdGeometry_HH
55 
56 #include "TMath.h"
57 #include "TNamed.h"
58 #include "TObject.h"
59 #include "TF1.h"
60 #include "TGeoManager.h"
61 #include "TGeoNode.h"
62 #include "TGeoMatrix.h"
63 #include "TGeoShape.h"
64 #include "StThreeVectorD.hh"
65 #include "StMaker.h"
66 #include "StPhysicalHelixD.hh"
67 #include "StarMagField.h"
68 #include "StMtdConstants.h"
69 
70 #include <vector>
71 #include <string>
72 #ifndef ST_NO_NAMESPACES
73 using std::vector;
74 using std::sort;
75 using std::string;
76 #endif
77 #ifndef __CINT__
78 #if !defined(ST_NO_TEMPLATE_DEF_ARGS)
79 typedef vector<Int_t> IntVec;
80 typedef vector<Double_t> DoubleVec;
81 typedef vector<StThreeVectorD > PointVec;
82 #else
83 typedef vector<Int_t, allocator<Int_t> > IntVec;
84 typedef vector<Double_t, allocator<Double_t> > DoubleVec;
85 typedef vector<StThreeVectorD, allocator<StThreeVectorD>> PointVec;
86 #endif
87 #endif
88 
89 class TGeoVolume;
90 class StMaker;
91 class StMtdGeometry;
92 
93 const double muonMass= 0.105658389;
94 
95 
96 //----------------------------------------------------//
97 // //
98 // StMtdGeoNode //
99 // //
100 //----------------------------------------------------//
101 class StMtdGeoNode : public TObject {
102 
103 public:
104  StMtdGeoNode(TGeoVolume *vol, TGeoHMatrix *mat, StThreeVectorD point, Int_t nExtraCells);
105  StMtdGeoNode():fTransFlag(0),fNExtraCells(0){}
106  virtual ~StMtdGeoNode();
107 
108  void LocalToMaster(const Double_t* local, Double_t* master);
109  void MasterToLocal(const Double_t* master, Double_t* local);
110  void UpdateMatrix();
111  StThreeVectorD YZPlaneNormal();
112  void PrintNormal();
113  void SetNExtraCells(Int_t val) { fNExtraCells = val>0?val:0; }
114 
115  Bool_t HelixCross(const StPhysicalHelixD helix, const Double_t pathToMagOutR, const Double_t tofToMagOutR, Double_t &pathL, Double_t &tof, StThreeVectorD &cross);
116  Bool_t IsGlobalPointIn(StThreeVectorD &global);
117  Bool_t IsLocalPointIn(const Double_t x, const Double_t y, const Double_t z);
118  StThreeVectorD GetNodePoint();
119 
120  protected:
121  TGeoVolume *fVolume;
122  TGeoHMatrix *fMatrix;
123  StThreeVectorD fPoint;
124  StThreeVectorD fNormal;
125 
126  const Double_t *fTransMRS; //Translate vector in MRS
127  const Double_t *fRotMRS; //RotateMatrix from MRS to this
128  Bool_t fTransFlag; //Flag, kTRUE=if translation/matrix updated
129  Int_t fNExtraCells; //Number of extra cells considered in matching
130 };
131 
132 //_____________________________________________________________________________
133 inline void StMtdGeoNode::PrintNormal()
134 {
135  LOG_INFO<<"normal x,y,z = "
136  <<fNormal[0]<<", "
137  <<fNormal[1]<<", "
138  <<fNormal[2]<<endm;
139 }
140 
141 
142 //----------------------------------------------------//
143 // //
144 // StMtdGeoBackleg //
145 // //
146 //----------------------------------------------------//
147 
149  //friend class StMtdGeometry;
150  public:
151  StMtdGeoBackleg (Int_t iMTTG, Int_t iBL, TGeoVolume *vol, TGeoHMatrix *mat, StThreeVectorD point, Int_t nExtraCells);
152 
153  StMtdGeoBackleg() {}
154  ~StMtdGeoBackleg();
155 
156  private:
157  Int_t mMTTGIndex;
158  Int_t mBacklegIndex;
159 
160 };
161 
162 //----------------------------------------------------//
163 // //
164 // StMtdGeoModule //
165 // //
166 //----------------------------------------------------//
167 
168 class StMtdGeoModule : public StMtdGeoNode {
169  //friend class StMtdGeoBackleg;
170  public:
171  StMtdGeoModule (Int_t iMTRA, Int_t iMod, TGeoVolume *vol, TGeoHMatrix *mat, StThreeVectorD point, Int_t nExtraCells);
172  StMtdGeoModule() {}
173  ~StMtdGeoModule();
174  Int_t FindCellId(const Double_t *local);
175  Float_t GetCellPhiCenter(Int_t iCell);
176  Float_t GetCellZCenter(Int_t iCell);
177  Float_t GetCellLocalYCenter(Int_t iCell, Int_t iBL, Int_t idTruth);
178  Float_t GetCellLocalYCenter(Int_t iCell);
179 
180  private:
181  Int_t mMTRAIndex;
182  Int_t mModuleIndex;
183 };
184 
185 //----------------------------------------------------//
186 // //
187 // StMtdGeometry //
188 // //
189 //----------------------------------------------------//
190 
191 class StMtdGeometry : public TNamed{
192  private:
193  static const Double_t mMtdMinR;
194  static const Double_t mMtdMaxR;
195  static const Double_t mMagInR;
196  static const Double_t mMagOutR;
197  static const Double_t mEmcInR;
198  static const Double_t mEmcOutR;
199 
200  public:
201  StMtdGeometry(const char* name="mtdGeo",
202  const char* title="Simplified Mtd Geometry",
203  TGeoManager *manager = 0);
204  ~StMtdGeometry();
205 
206  void Init(StMaker *maker);
207 
208  void DebugOn() { mDebug = kTRUE; }
209  void DebugOff() { mDebug = kFALSE; }
210  Bool_t IsDebugOn() { return mDebug; }
211 
212  void SetNExtraCells(Int_t val) { mNExtraCells = val>0?val:0; }
213  Bool_t ProjToMagOutR(const StPhysicalHelixD helix, const StThreeVectorD vertex, StPhysicalHelixD &outHelix, Double_t &pathL, Double_t &tof, StThreeVectorD &pos);
214  void ProjToVertex(const StPhysicalHelixD helix, const StThreeVectorD vertex, Double_t &pathL, Double_t &tof, StThreeVectorD &dcaPos);
215 #ifndef __CINT__
216  Bool_t ProjToBLModVect(const StPhysicalHelixD helix, IntVec &blVect, IntVec &modVect);
217  Bool_t HelixCrossCellIds(const StPhysicalHelixD helix, const StThreeVectorD vertex, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec, DoubleVec &tofVec );
218  Bool_t HelixCrossCellIds(const StPhysicalHelixD helix, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec, DoubleVec &tofVec );
219 #endif
220 
221  Int_t CalcCellId(Int_t iBL, Int_t iMod, Int_t iCel);
222  Bool_t IsIdValid(Int_t id);
223  Int_t FindBLId(Double_t phi);
224  Int_t FindModId(Double_t z);
225  void SetBFactor(Float_t val){mBFactor=val;}
226  void SetELossFlag(Bool_t val){mELossFlag=val;}
227  void SetCosmicFlag(Bool_t val){mCosmicFlag=val;}
228  void SetLockBField(Bool_t val);
229  void DecodeCellId(Int_t id, Int_t &iBL, Int_t &iMod, Int_t &iCell);
230  StThreeVectorD GetField(StThreeVectorD pos) const;
231  StThreeVectorD GetField(Double_t x, Double_t y, Double_t z) const;
232  Double_t GetFieldZ(StThreeVectorD pos) const;
233  Double_t GetFieldZ(Double_t x, Double_t y, Double_t z) const;
234  StMtdGeoModule *GetGeoModule(Int_t iBL, Int_t iMod) const;
235 
236  protected:
237  Bool_t mDebug;
238  Bool_t mCosmicFlag;
239  Bool_t mELossFlag;
240  Bool_t mLockBField;
241  Int_t mNExtraCells;
242  Int_t mNValidBLs;
243  Int_t mMTTG2BL[gMtdNBacklegs];
244  Int_t mMTRA2Mod[gMtdNBacklegs][gMtdNModules]; //BL, Module index all start from 1
245  Float_t mBFactor;
246 
247  StMtdGeoBackleg *mMtdGeoBackleg[gMtdNBacklegs];
248  StMtdGeoModule *mMtdGeoModule[gMtdNBacklegs][gMtdNModules];
249  StarMagField *mStarBField;
250  TF1 *fMagEloss;
251 
252  static const char* backlegPref[4];//= "MTMT,MTMF,MTTG,MTT1";
253  static const char* modulePref ;//= "MTRA";
254  TGeoManager *mGeoManager;
255 
256  Bool_t IsMTTG(const TGeoVolume * vol) const;
257  Bool_t IsMTRA(const TGeoVolume * vol) const { return !(strcmp(vol->GetName(), modulePref));}
258 
259 #ifndef __CINT__
260  void RemoveDuplicate(IntVec &vec);
261 #endif
262 
263  const char *GetCVS() const
264  {static const char cvs[]="Tag $Name: $ $Id: StMtdGeometry.h,v 1.13 2017/03/08 20:40:38 marr Exp $ built " __DATE__ " " __TIME__ ; return cvs;}
265  ClassDef(StMtdGeometry,1);
266 };
267 
268 R__EXTERN StMtdGeometry* gMtdGeometry;
269 
270 #endif
Bool_t mCosmicFlag
Control message printing of this class.
Int_t mNExtraCells
Control mag field to FF.
Bool_t mELossFlag
Cosmic event flag.
Definition: tof.h:15
Bool_t IsIdValid(Int_t id)
return BL*1000+Module*100+(Cell+50). BL: 1-30, Module: 1-5, Cell: 0-11.
Int_t mNValidBLs
Control matching range in the module.
StMtdGeometry(const char *name="mtdGeo", const char *title="Simplified Mtd Geometry", TGeoManager *manager=0)
EMC system outer radius.
static const char * backlegPref[4]
EMC system outer radius.
Bool_t mLockBField
Control energy loss flag.