StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofGeometry.h
1 /*******************************************************************
2  *
3  * $Id: StBTofGeometry.h,v 1.26 2021/04/13 22:35:50 geurts Exp $
4  *
5  * Authors: Shuwei Ye, Xin Dong
6  *******************************************************************
7  *
8  * Description: Collection of geometry classes for the TOF-MRPC
9  * initializes from GEANT geometry
10  *
11  *
12  *******************************************************************/
13 #ifndef STBTOFGEOMETRY_H
14 #define STBTOFGEOMETRY_H
15 
17 // //
18 // group of classes for BTof Geometry: //
19 // //
20 // StBTofGeometry, StBTofNode, //
21 // StBTofGeomTray, StBTofGeomSensor //
22 // //
23 // Usage: //
24 // StBTofGeometry* geo = new StBTofGeometry("tof","tof geometry"); //
25 // geo->Init(TVolume *starHall, const Int_t BTofConf); //
26 // //
28 #include "TObject.h"
29 #include "TList.h"
30 #include "TNode.h"
31 #include "TBRIK.h"
32 #include "TGeometry.h"
33 #include "StThreeVectorD.hh"
34 #include "StHelixD.hh"
35 #include "TVolume.h"
36 #include "TVolumeView.h"
37 #include "TVolumeViewIter.h"
38 #include "StMaker.h"
39 
40 #include <vector>
41 #include <string>
42 typedef std::vector<Int_t> IntVec;
43 typedef std::vector<Double_t> DoubleVec;
44 typedef std::vector<StThreeVector<double> > PointVec;
45 class StBTofNode;
46 class StBTofGeomNode;
47 class StBTofGeomTray;
48 class StBTofGeomSensor;
49 class StBTofGeometry;
50 
51 class TGeoPhysicalNode;
52 class TGeoManager;
53 
58 class StBTofNode : public TObject {
59  protected:
60  TVolumeView *fView;
61  TVolumePosition *pView;
62  TVolumeView *mMasterNode;
63 
64  Double_t mTransMRS[3]; //Translate vector in MRS
65  Double_t mRotMRS[9]; //RotateMatrix from MRS to this
66  Bool_t mTransFlag; //Flag, kTRUE=if translation/matrix updated
67 // Double_t mCenterRxy; //center position R(xy) in MRS
68 // Double_t mCenterEta; //center position Eta in MRS
69 // Double_t mCenterPhi; //center position Phi in MRS
70  Double_t mEtaMin; //minimum covered Eta in MRS
71  Double_t mEtaMax; //maximum covered Eta in MRS
72  Double_t mPhiMin; //minimum covered Phi in MRS
73  Double_t mPhiMax; //maximum covered Phi in MRS
74  // Bool_t mMatrixUpdated; //is TNode::fRotMatrix updated
75  Double_t mAlign[3];
76 
77  static Bool_t mDebug;
78 
79  protected:
80 // StBTofNode(TVolumeView *element, TVolumeView *top);
81  StBTofNode(TVolumeView *element, TVolumeView *top, const StThreeVectorD& align, TVolumePosition *pos=0);
82 
83  StBTofNode(const TGeoPhysicalNode& gpNode, const StThreeVectorD& align);
84 
85 
86  void UpdateMatrix();
87  void BuildMembers();
88 
89  public:
90  StBTofNode() {}
91  ~StBTofNode() {
92  if ( TestBit(kIsOwner) ) {
93  if (pView != fView->GetPosition()) delete pView;
94  delete fView;
95  delete mMasterNode;
96  delete mTVolume;
97  delete mTShape;
98  }
99  }
100 
101  TVolumeView* GetfView() const { return fView; }
102  TVolumePosition* GetpView() const { return pView; }
103  TVolumeView* GetTopNode() const { return mMasterNode; }
104  static void DebugOn() { mDebug = kTRUE; }
105  static void DebugOff() { mDebug = kFALSE; }
106  static Bool_t IsDebugOn() { return mDebug; }
107 
108  static void CalcMatrix(StBTofNode* son, Double_t* align, Double_t* trans, Double_t* rot,
109  StBTofNode* mother=0);
110  static void ConvertPos(StBTofNode* from, const Double_t* pos_from,
111  StBTofNode* to, Double_t* pos_to);
112  void Local2Master(const Double_t* local, Double_t* master);
113  void Master2Local(const Double_t* master, Double_t* local);
114  TShape *GetShape() const { return fView->GetPosition()->GetNode()->GetShape();}
115 
116  StThreeVectorD YZPlaneNormal();
117  StThreeVectorD GetCenterPosition() const;
118 // Double_t GetCenterRxy() const { return mCenterRxy; }
119 // Double_t GetCenterEta() const { return mCenterEta; }
120 // Double_t GetCenterPhi() const { return mCenterPhi; }
121  Double_t GetEtaMin() const { return mEtaMin; }
122  Double_t GetEtaMax() const { return mEtaMax; }
123  Double_t GetPhiMin() const { return mPhiMin; }
124  Double_t GetPhiMax() const { return mPhiMax; }
125  Bool_t IsLocalPointIn(const Double_t x, const Double_t y,
126  const Double_t z);
127  Bool_t IsGlobalPointIn(const StThreeVectorD &global);
128  Bool_t HelixCross(const StHelixD &helix, Double_t &pathLen, StThreeVectorD &cross);
129  Bool_t HelixCross(const StHelixD &helix, Double_t &pathLen, StThreeVectorD &cross, Double_t &theta);
130  StThreeVectorD* Align() const {return new StThreeVectorD(mAlign[0], mAlign[1], mAlign[2]); }
131  virtual void Print(const Option_t *opt="") const;
132 
133  private:
134 
135  enum EBTofNodeBits {
138  kIsOwner = BIT(23)
139  };
140 
144  TVolume *mTVolume;
145  TShape *mTShape;
146 
148  ClassDef(StBTofNode,2) //Virutal TNode for TOF geometry
149 };
150 
151 
153 //
154 // StBTofGeomTray
155 // ==============
156 //
158 
159 class StBTofGeomTray : public StBTofNode {
160  friend class StBTofGeometry;
161 
162  private:
163  Int_t mTrayIndex; //Tray Index number
164  Int_t mBTOHIndex; // BTOH Index number
165  Int_t mSectorsInBTOH; //number of sectors in one half TOF
166 
167  protected:
168  static Bool_t mDebug;
169 
170  public:
171 // StBTofGeomTray(const Int_t ibtoh, TVolumeView *sector, TVolumeView *top);
172 
173  StBTofGeomTray(const Int_t ibtoh, TVolumeView *sector, TVolumeView *top, const StThreeVectorD& align, TVolumePosition *pos=0);
174 
175  StBTofGeomTray(const int trayId, const TGeoPhysicalNode& gpNode, const StThreeVectorD& align);
176 
177  StBTofGeomTray() {}
178  ~StBTofGeomTray() {};
179 
180  static void DebugOn() { mDebug = kTRUE; }
181  static void DebugOff() { mDebug = kFALSE; }
182  static Bool_t IsDebugOn() { return mDebug; }
183 
184  Int_t BTOHIndex() const { return mBTOHIndex; }
185  Int_t Index() const { return mTrayIndex; }
186  virtual void Print(const Option_t *opt="") const;
187 
188  ClassDef(StBTofGeomTray,1) //Tray node in TOF geometry
189 };
190 
191 
193 //
194 // StBTofGeomSensor
195 // ================
196 //
198 
199 class StBTofGeomSensor : public StBTofNode {
200  friend class StBTofGeomTray;
201 
202  private:
203  Int_t mModuleIndex; //Module Index number
204  static Int_t const mCells = 6;
205  Double_t mCellY[mCells+1]; //Y Range of cells
206  static Double_t const mSensorDy;// = 10.35; // Actual module length;
207 
208  protected:
209  static Bool_t mDebug;
210 
211  protected:
212  void CreateGeomCells();
213 
214  public:
215 // StBTofGeomSensor(TVolumeView *element, TVolumeView *top);
216  StBTofGeomSensor(TVolumeView *element, TVolumeView *top, const StThreeVectorD& align, TVolumePosition *pos=0);
217 
218  StBTofGeomSensor(const int moduleId, const TGeoPhysicalNode& gpNode, const StThreeVectorD& align);
219 
220  StBTofGeomSensor() {}
221  ~StBTofGeomSensor() {}
222 
223  static void DebugOn() { mDebug = kTRUE; }
224  static void DebugOff() { mDebug = kFALSE; }
225  static Bool_t IsDebugOn() { return mDebug; }
226 
227  static Int_t GetCells() { return mCells; }
228  void SetIndex(Int_t imod);
229  Int_t Index() const { return mModuleIndex; }
230  Double_t GetCellYMin(const Int_t icell) const;
231  Double_t GetCellYMax(const Int_t icell) const;
232  Int_t FindCellIndex(const Double_t* local);
233  Int_t PrevCellIndex(const Int_t icell) const;
234  Int_t NextCellIndex(const Int_t icell) const;
235  StThreeVectorD GetCellPosition(const Int_t icell);
236  virtual void Print(Option_t *opt="") const ;
237 
238  ClassDef(StBTofGeomSensor,1) //Module node in TOF geometry
239 };
240 //____________________________________________________________________________
241 inline void StBTofGeomSensor::SetIndex(Int_t imod){ mModuleIndex = imod;}
242 
243 //_____________________________________________________________________________
244 inline Int_t StBTofGeomSensor::PrevCellIndex(const Int_t icell)
245 const
246 {
247  Int_t ret = -1;
248  if (icell>mCells) ret=mCells;
249  else if (icell>0) ret=icell-1;
250  return ret;
251 }
252 
253 //_____________________________________________________________________________
254 inline Int_t StBTofGeomSensor::NextCellIndex(const Int_t icell)
255 const
256 {
257  Int_t ret = -1;
258  if (icell<0) ret=0;
259  else if (icell<mCells) ret=icell+1;
260  return ret;
261 }
262 
264 //
265 // StBTofGeometry
266 // ==============
267 //
269 
270 class StBTofGeometry : public TNamed {
271 
272  friend class StBTofGeomTray;
273 
274  private:
275  TNamed* mGeoNamed;
276  static Int_t const mNTrays = 120;
277  static Int_t const mNModules = 32;
278 
279  std::string FormTGeoPath(TGeoManager &geoManager, int trayId, bool hasGmt = false, int moduleId = -1);
280 
281  static bool mGemTofGeom;
282  static bool TrayHasGmtModules(int trayId);
283 
284  void InitFrom(TVolume &starHall);
285 
287  void InitFrom(TGeoManager &geoManager);
288 
289  protected:
290  TVolumeView* mTopNode; //top TNode as MRS
291  const char* mRootFile;
292  Int_t mSectorsInBTOH; //number of sectors in one half TOF
293  Int_t mNValidTrays; //amount of TOF trays
294  Int_t mModulesInTray; //number of modules in a tray
295  Int_t mCellsInModule; //number of cell in a module
296  Bool_t mInitFlag; //flag of initialization, kTRUE if done
297  Int_t mBTofConf; //configuration for tray/full (0/1) tof
298 
299  StBTofGeomTray* mBTofTray[mNTrays];
300  StBTofGeomSensor* mBTofSensor[mNTrays][mNModules];
301 
302  Bool_t mIsMC;
303  static Bool_t mDebug;
304 
305  string mAlignFile;
306 
307  static const char* sectorPref ;//= "BSEC";
308  static const char* trayPref ;//= "BTRA";
309  static const char* senPref ;//= "BRMD";
310 
312  Double_t mTrayX0[mNTrays];
313  Double_t mTrayY0[mNTrays];
314  Double_t mTrayZ0[mNTrays];
315 
316  public:
317  StBTofGeometry(const char* name="btofGeo",
318  const char* title="Simplified BTof Geometry");
319  ~StBTofGeometry();
320 
321  Bool_t IsBSEC(const TVolume* element) const
322  { return !(strcmp(element->GetName(), sectorPref)); }
323  Bool_t IsBTRA(const TVolume* element) const
324  { return !(strcmp(element->GetName(), trayPref)); }
325  Bool_t IsBRMD(const TVolume* element) const
326  { return !(strcmp(element->GetName(), senPref)); }
327 
328  Bool_t ContainOthers(TVolume *element);
329 
330  static Bool_t LackThis(const char* fromWhere);
331 
332  static void DebugOn() { mDebug = kTRUE; }
333  static void DebugOff() { mDebug = kFALSE; }
334  static Bool_t IsDebugOn() { return mDebug; }
335  void SetMCOn() { mIsMC = kTRUE; }
336  void SetMCOff() { mIsMC = kFALSE; }
337 
338  void SetAlignFile(const Char_t *infile="") { mAlignFile = infile; }
339 
340  void Init(StMaker *maker, TVolume *starHall, TGeoManager* geoManager = nullptr);
341 
342  Bool_t IsInitDone() const { return mInitFlag; }
343  Bool_t IsCellValid(const Int_t icell) const;
344  Bool_t IsSensorValid(const Int_t imodule) const;
345  Bool_t IsTrayValid(const Int_t itray) const;
346 
347  Int_t CalcCellId(const Int_t volumeId, const Double_t* local) const;
348  Int_t CalcCellId(const Int_t volumeId, const Float_t* local) const;
349  Int_t CalcSensorId(const Int_t imodule, const Int_t itray=0) const;
350  Int_t PrevCellId(const Int_t cellId) const;
351  Int_t NextCellId(const Int_t cellId) const;
352  Int_t CalcCellId(const Int_t icell, const Int_t imodule,
353  const Int_t itray=0) const;
354  void DecodeVolumeId(const Int_t volumeId,
355  Int_t &imodule, Int_t &itray) const;
356  Bool_t DecodeSensorId(const Int_t sensorId, Int_t &imodule,
357  Int_t &itray) const;
358  Bool_t DecodeCellId(const Int_t cellId, Int_t &icell,
359  Int_t &imodule, Int_t &itray) const;
360  Int_t GetCellIndex(const Int_t cellId) const;
361 
362  Int_t CellsInModule(const Int_t imodule=0, const Int_t itray=0) const
363  { return StBTofGeomSensor::GetCells(); }
364  Int_t ModulesInTray(const Int_t itray=0) const
365  { return mModulesInTray; }
366  Int_t Trays() const { return mNValidTrays; }
367 
368  const char* GeoRootFile() { return mRootFile; }
369  virtual void Print(Option_t *opt="") const ;
370 
371  TVolumeView* GetTopNode() const { return mTopNode; }
372  StBTofGeomSensor* GetGeomCell(const Int_t cellId) const;
373  StBTofGeomSensor* GetGeomSensor(const Int_t imodule,
374  const Int_t itray=0) const;
375  StBTofGeomTray* GetGeomTray(const Int_t itray=0) const;
376  StBTofGeomTray* GetGeomTrayAt(const Int_t idx=0) const;
377  Int_t GetTrayIndexAt(const Int_t idx=0) const;
378  Int_t GetAtOfTray(const Int_t itray=0) const;
379 
380  Int_t CellIdPointIn(const StThreeVectorD& point) const;
381 #ifndef __CINT__
382  Bool_t HelixCrossCellIds(const StHelixD &helix, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec) const;
383  Bool_t HelixCrossCellIds(const StHelixD &helix, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec, DoubleVec &thetaVec) const;
384  Bool_t HelixCrossCellIds(const StHelixD &helix, IntVec validModuleVec, IntVec projTrayVec, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec) const;
385  Bool_t HelixCross(const StHelixD &helix) const;
386  Bool_t HelixCross(const StHelixD &helix, IntVec validModuleVec, IntVec projTrayVec) const;
387  Bool_t projTrayVector(const StHelixD &helix, IntVec &trayVec) const;
388 #endif
389  ClassDef(StBTofGeometry,2) //Simplified TOF Geometry
390 };
391 
392 R__EXTERN StBTofGeometry* gBTofGeometry;
393 
394 #endif //end of STBTOFGEOMETRY_H
395 
396 /*******************************************************************
397  * $Log: StBTofGeometry.h,v $
398  * Revision 1.26 2021/04/13 22:35:50 geurts
399  * Fixed geomtry serious bug in accounting of valid trays and in the handling of GEM-trays pre-Run13 (introduced with v1.14.2.13)
400  * h/t to Leszek Kosarzewski.
401  *
402  * Revision 1.25 2018/03/09 21:36:17 smirnovd
403  * Remove declared but undefined function
404  *
405  * Revision 1.24 2018/02/26 23:29:00 smirnovd
406  * StBTofGeometry: Introduced alternative initialization using TGeo geometry
407  *
408  * Revision 1.23 2018/02/26 23:28:53 smirnovd
409  * StBTofGeometry: Added private InitFrom(TGeoManager)
410  *
411  * Revision 1.22 2018/02/26 23:28:45 smirnovd
412  * StBTofGeometry: InitFrom(TVolume*) to InitFrom(TVolume&)
413  *
414  * Revision 1.21 2018/02/26 23:28:38 smirnovd
415  * StBTofGeometry: s/InitFromStar/InitFrom/ and make it private
416  *
417  * Revision 1.20 2018/02/26 23:28:30 smirnovd
418  * StBTofGeometry: Added static method to identify trays with GMT modules
419  *
420  * Revision 1.19 2018/02/26 23:28:22 smirnovd
421  * StBTofGeometry: New method to form TGeo paths for trays and modules
422  *
423  * Revision 1.18 2018/02/26 23:28:14 smirnovd
424  * StBTofGeomSensor: New constructor accepting TGeo
425  *
426  * Revision 1.17 2018/02/26 23:28:07 smirnovd
427  * StBTofGeoTray: New constructor accepting TGeo
428  *
429  * Revision 1.16 2018/02/26 23:28:00 smirnovd
430  * StBTofNode: New constructor accepting TGeo volume
431  *
432  * The new TGeo constructor creates transient TVolume objects to provide
433  * functionality compatible with the existing TVolume-base geometry
434  * transformations. Unlike previously, the TVolume objects are owned by this class
435  * and so have to be deleted.
436  *
437  * Revision 1.15 2018/02/26 23:27:53 smirnovd
438  * Accept reference instead of pointer to xyz alignment
439  *
440  * Revision 1.14 2018/02/26 23:27:45 smirnovd
441  * StBTofGeometry: Senseless assignments in destructors
442  *
443  * Revision 1.13 2018/02/26 23:27:15 smirnovd
444  * StBTofGeometry: Removed unused member pointer to non-TGeo ROOT geometry
445  *
446  * Revision 1.12 2018/02/26 23:27:01 smirnovd
447  * Remove unnecessary guards around ClassDef macro
448  *
449  * Revision 1.11 2018/02/26 23:13:19 smirnovd
450  * Move embedded CVS log messages to the end of file
451  *
452  * Revision 1.10 2017/10/20 17:50:33 smirnovd
453  * Squashed commit of the following:
454  *
455  * StBTof: Remove outdated ClassImp macro
456  *
457  * Prefer explicit namespace for std:: names in header files
458  *
459  * Removed unnecessary specification of default std::allocator
460  *
461  * Frank signed-off
462  *
463  * Revision 1.9 2014/02/06 21:21:13 geurts
464  * Fix Index() of modules in GEMTOF trays, only applies to Run 13+ geometries [Joey Butterworth]
465  *
466  * Revision 1.8 2011/07/27 16:15:12 geurts
467  * Alignment calibration modifications [Patrick Huck]:
468  * - added mAlignFile and SetAlignFile for use in StBTofMatchMaker
469  * - phi0, x0, z0 made mNTrays dependent
470  *
471  * Revision 1.7 2010/08/09 18:45:36 geurts
472  * Include methods in StBTofNode and StBTofGeometry that calculate local theta [Masa]
473  *
474  * Revision 1.6 2010/07/14 20:35:28 geurts
475  * introduce switch to enable ideal MC geometry, without alignment updates. Default: disabled
476  *
477  * Revision 1.5 2009/08/25 15:41:29 fine
478  * fix the compilation issues under SL5_64_bits gcc 4.3.2
479  *
480  * Revision 1.4 2009/03/18 14:18:18 dongx
481  * - Optimized the geometry initialization function, reduced the CPU time use
482  * - Optimized the HelixCrossCellIds() function, now doing the tray fast projection to reduce the loop
483  *
484  * Revision 1.3 2009/02/13 00:00:56 dongx
485  * Tray geometry alignment implemented.
486  *
487  * Revision 1.2 2009/02/12 01:45:57 dongx
488  * Clean up
489  *
490  * Revision 1.1 2009/02/02 21:56:54 dongx
491  * first release - Barrel geometry
492  */
static const char * sectorPref
filename for alignment input
Bool_t HelixCrossCellIds(const StHelixD &helix, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec) const
Double_t mTrayX0[mNTrays]
Alignment parameters.
void CreateGeomCells()
Control message printing of this class.
static Bool_t mDebug
Alignment parameters.
string mAlignFile
Control message printing of this class.
static Bool_t mDebug
Control MC input (ignore alignment corrections)
Int_t mSectorsInBTOH
the root file of geometry