00001 #ifndef STI_DETECTOR_BUILDER_H
00002 #define STI_DETECTOR_BUILDER_H
00003
00004 #include <map>
00005 #include <vector>
00006 #include <string>
00007 #include <stdexcept>
00008 #include <math.h>
00009 #include "StDetectorDbMaker/StiTrackingParameters.h"
00010 #include "Sti/StiMapUtilities.h"
00011 #include "Sti/Base/Named.h"
00012 #include "StThreeVector.hh"
00013 #include "StiVMCToolKit.h"
00014 #include "TMath.h"
00015 class StiDetector;
00016 class StiMaterial;
00017 class StiShape;
00018 class StMaker;
00019 class TDataSet;
00020 class StiPlanarShape;
00021 class StiCylindricalShape;
00022 template<class Factorized>class Factory;
00023
00024
00025
00026 typedef map<NameMapKey, StiMaterial*> materialMap;
00027 typedef materialMap::value_type materialMapValType;
00028 typedef map<NameMapKey, StiShape*> shapeMap;
00029 typedef shapeMap::value_type shapeMapValType;
00030 typedef map<NameMapKey, StiDetector*> detectorMap;
00031 typedef detectorMap::const_iterator detectorIterator;
00032 typedef detectorMap::value_type detectorMapValType;
00033
00041 class StiDetectorBuilder : public Named
00042 {
00043 public:
00044
00045 StiDetectorBuilder(const string & name,bool active, const string & inputFile);
00046 virtual ~StiDetectorBuilder();
00047 detectorMap getDetectors(){ return mDetectorMap; }
00048 virtual StiMaterial * add(StiMaterial *material);
00049 virtual StiShape * add(StiShape *shape);
00050 virtual StiDetector * add(StiDetector *detector);
00051 virtual StiDetector * add(unsigned int row, unsigned int sector, StiDetector *detector);
00052 virtual StiMaterial * findMaterial(const string& szName) const;
00053 virtual StiShape * findShape(const string& szName) const;
00054 virtual StiDetector * findDetector(const string& szName) const;
00055 virtual StiDetector * getDetector(unsigned int layer, unsigned int sector) const;
00056 virtual void setDetector(unsigned int layer, unsigned int sector, StiDetector * detector);
00059 virtual void setNRows(unsigned int nRows) {if (_detectors.size() < nRows) _detectors.resize(nRows);}
00060 virtual unsigned int getNRows() const {return _detectors.size();}
00061 virtual unsigned int getNSectors(unsigned int row=0) const;
00062 virtual void setNSectors(unsigned int row, unsigned int nSectors) {
00063 setNRows(row+1);if (_detectors[row].size() < nSectors) _detectors[row].resize(nSectors);
00064 }
00065 virtual bool hasMore() const;
00066 virtual StiDetector* next();
00067 virtual void build(StMaker&source);
00068 virtual void buildDetectors(StMaker&source);
00069
00070 double nice(double angle) const;
00071 void setGroupId(int id) { _groupId = id;}
00072 int getGroupId() const {return _groupId;}
00073 void setTrackingParameters(const StiTrackingParameters & pars);
00074 StiTrackingParameters *getTrackingParameters() { return _trackingParameters;}
00075 Factory<StiDetector>* getDetectorFactory() {return _detectorFactory;}
00076 void SetCurrentDetectorBuilder(StiDetectorBuilder *m) {fCurrentDetectorBuilder = m;}
00077 static StiDetectorBuilder *GetCurrentDetectorBuilder() {return fCurrentDetectorBuilder;}
00078 static void MakeAverageVolume(TGeoPhysicalNode *nodeP) {
00079 if (fCurrentDetectorBuilder) fCurrentDetectorBuilder->AverageVolume(nodeP);
00080 }
00081 virtual void AverageVolume(TGeoPhysicalNode *nodeP);
00082 virtual void useVMCGeometry() {}
00083 void setGasMat(StiMaterial *m) {_gasMat = m;}
00084 StiMaterial *getGasMat() {return _gasMat;}
00085 static void setDebug(int m = 0) {_debug = m;}
00086 static int debug() {return _debug;}
00087 protected:
00088
00089 int _groupId;
00090 bool _active;
00091 materialMap mMaterialMap;
00092 shapeMap mShapeMap;
00093 detectorMap mDetectorMap;
00094 detectorIterator mDetectorIterator;
00095 vector< vector<StiDetector*> > _detectors;
00096 Factory<StiDetector>*_detectorFactory;
00097 StiTrackingParameters *_trackingParameters;
00098 string _inputFile;
00099 static StiDetectorBuilder* fCurrentDetectorBuilder;
00100 StiMaterial * _gasMat;
00101 static int _debug;
00102 };
00103
00104 inline double StiDetectorBuilder::nice(double angle) const
00105 {
00106 while(angle >= M_PI){ angle -= 2.*M_PI; }
00107 while(angle < -M_PI){ angle += 2.*M_PI; }
00108 return angle;
00109 }
00110
00111
00112 #endif // ifndef STI_DETECTOR_BUILDER_H