StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiDetectorBuilder.h
1 #ifndef STI_DETECTOR_BUILDER_H
2 #define STI_DETECTOR_BUILDER_H
3 
4 #include <map>
5 #include <vector>
6 #include <string>
7 #include <stdexcept>
8 #include <math.h>
9 #include "StDetectorDbMaker/StiTrackingParameters.h"
10 #include "Sti/StiMapUtilities.h"
11 #include "Sti/Base/Named.h"
12 #include "StThreeVector.hh"
13 #include "StiVMCToolKit.h"
14 #include "TMath.h"
15 using namespace std;
16 class StiDetector;
17 class StiMaterial;
18 class StiShape;
19 class StMaker;
20 class TDataSet;
21 class StiPlanarShape;
23 template<class Factorized>class Factory;
24 
25 // Set up stl maps for by-name lookup of shapes and materials.
26 // Not used for placements because they are unique to each detector.
27 typedef map<NameMapKey, StiMaterial*> materialMap;
28 typedef materialMap::value_type materialMapValType;
29 typedef map<NameMapKey, StiShape*> shapeMap;
30 typedef shapeMap::value_type shapeMapValType;
31 typedef map<NameMapKey, StiDetector*> detectorMap;
32 typedef detectorMap::const_iterator detectorIterator;
33 typedef detectorMap::value_type detectorMapValType;
34 typedef std::pair<NameMapKey, StiDetector*> DetectorMapPair;
42 class StiDetectorBuilder : public Named
43 {
44 public:
45 
46  StiDetectorBuilder(const string & name,bool active);
47  virtual ~StiDetectorBuilder();
48  detectorMap getDetectors(){ return mDetectorMap; }
49  virtual StiMaterial * add(StiMaterial *material);
50  virtual StiShape * add(StiShape *shape);
51  virtual StiDetector * add(StiDetector *detector);
52  virtual StiDetector * add(UInt_t row, UInt_t sector, StiDetector *detector);
53  virtual void del(UInt_t row, UInt_t sector);
54  virtual StiMaterial * findMaterial(const string& szName) const;
55  virtual StiShape * findShape(const string& szName) const;
56  virtual StiDetector * findDetector(const string& szName) const;
57  virtual StiDetector * getDetector(UInt_t layer, UInt_t sector) const;
58  virtual void setDetector(UInt_t layer, UInt_t sector, StiDetector * detector);
61  virtual void setNRows(UInt_t nRows) {if (_detectors.size() < nRows) _detectors.resize(nRows);}
62  virtual UInt_t getNRows() const {return _detectors.size();}
63  virtual UInt_t getNSectors(UInt_t row=0) const;
64  virtual void setNSectors(UInt_t row, UInt_t nSectors) {
65  setNRows(row+1);if (_detectors[row].size() < nSectors) _detectors[row].resize(nSectors);
66  }
67  virtual bool hasMore() const;
68  virtual StiDetector* next();
69  virtual void build(StMaker&source);
70  virtual void buildDetectors(StMaker&source);
71 
72  double nice(double angle) const;
73  void setGroupId(int id) { _groupId = id;}
74  int getGroupId() const {return _groupId;}
75  StiTrackingParameters *getTrackingParameters() { return _trackingParameters;}
76  Factory<StiDetector>* getDetectorFactory() {return _detectorFactory;}
77  void SetCurrentDetectorBuilder(StiDetectorBuilder *m) {fCurrentDetectorBuilder = m;}
78  virtual void AverageVolume(TGeoPhysicalNode *nodeP);
79  virtual void useVMCGeometry() {}
80  void setGasMat(StiMaterial *m) {_gasMat = m;}
81  StiMaterial *getGasMat() {return _gasMat;}
82  void setSplit(double relThick=0.5, int maxSplit=20) {mThkSplit=relThick;mMaxSplit=maxSplit;}
83 // Static methodes
84  static void setDebug(int m = 0) {_debug = m;}
85  static int debug() {return _debug;}
86  static StiDetectorBuilder *GetCurrentDetectorBuilder(){return fCurrentDetectorBuilder;}
87  static void MakeAverageVolume(TGeoPhysicalNode *nodeP)
88  {if (fCurrentDetectorBuilder) fCurrentDetectorBuilder->AverageVolume(nodeP);}
89  void Print() const;
90 
91  friend ostream& operator<<(ostream &os, const DetectorMapPair &detMapEntry);
92 
93  protected:
94  float mThkSplit; //wide/thickness/mThkSplit = nSplits
95  int mMaxSplit; //max number of splittings allowed
96  int _groupId;
97  bool _active;
98  materialMap mMaterialMap;
99  shapeMap mShapeMap;
100  detectorMap mDetectorMap;
101  detectorIterator mDetectorIterator;
102  vector< vector<StiDetector*> > _detectors;
103  Factory<StiDetector>*_detectorFactory;
104  StiTrackingParameters *_trackingParameters;
105  static StiDetectorBuilder* fCurrentDetectorBuilder;
106  StiMaterial * _gasMat; // Mother Volume material
107  static int _debug;
108 };
109 
110 inline double StiDetectorBuilder::nice(double angle) const
111 {
112  while(angle >= M_PI){ angle -= 2.*M_PI; }
113  while(angle < -M_PI){ angle += 2.*M_PI; }
114  return angle;
115 }
116 
117 
118 #endif // ifndef STI_DETECTOR_BUILDER_H
Definition: Named.h:16
virtual void setNRows(UInt_t nRows)