00001 #include "LCDG4CalSDProj.hh"
00002 #include "LCD_DocumentUtil.hh"
00003 #include "LCD_DocGeoUtil.hh"
00004
00005
00006 #include "G4String.hh"
00007
00008
00009 XERCES_CPP_NAMESPACE_USE;
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 LCDG4CalSDProj::LCDG4CalSDProj(G4String name, const DOM_Element& voldb)
00021 : LCDG4CalSD(name)
00022 {
00023 G4cout <<" Creating projective LCDG4CalSD..."<< G4endl;
00024 double thseg, phiseg;
00025 bool ok = LCD_DocGeoUtil::getSegmentation( voldb, &thseg, &phiseg);
00026 if (!ok) {
00027 G4cerr <<"***** LCDG4CalSDProj Error: can not get segmentation!!!"
00028 << G4endl;
00029 exit(1);
00030 }
00031
00032 _thetaseg = (G4int)thseg;
00033 _phiseg = (G4int)phiseg;
00034 }
00035
00036
00037
00038
00039 LCDG4CalSDProj::~LCDG4CalSDProj() {
00040 }
00041
00042
00043 unsigned int LCDG4CalSDProj::findCell(const G4ThreeVector& pos) {
00044
00045
00046 G4double hittheta = pos.theta();
00047 G4double hitphi = pos.phi();
00048 if(hitphi < 0.0) hitphi += 360.0*degree;
00049
00050 G4double dphi = 360.0*degree/_phiseg;
00051 G4double dtheta = 180.0*degree/_thetaseg;
00052
00053 unsigned int& ilayer = index[1];
00054 unsigned int& iphi = index[2];
00055 unsigned int& itheta = index[3];
00056
00057 iphi = int(hitphi/dphi);
00058 itheta = int(hittheta/dtheta);
00059 unsigned int cellIndex = itheta + _thetaseg* (iphi + _phiseg*ilayer);
00060 return cellIndex;
00061 }
00062
00063
00064 G4ThreeVector LCDG4CalSDProj::getCellCenter(unsigned int cellIndex) {
00065 if(cellIndex) ;
00066
00067 unsigned int& sysno = index[0];
00068 unsigned int& ilayer = index[1];
00069 unsigned int& iphi = index[2];
00070 unsigned int& itheta = index[3];
00071
00072 double dtheta = 180.*degree / _thetaseg;
00073 double dphi = 360.*degree / _phiseg;
00074 double theta = (itheta+0.5)*dtheta/radian;
00075 double phi = (iphi+0.5)*dphi/radian;
00076
00077
00078
00079 double rcyl=0, zc=0;
00080 if(sysno%2==0) {
00081
00082 rcyl = layer0CenterDepth + ilayer*layerThickness;
00083 zc = rcyl/tan(theta);
00084 }
00085 else {
00086
00087 zc = layer0CenterDepth + ilayer*layerThickness;
00088
00089 if(north) zc = -zc;
00090 rcyl = zc*tan(theta);
00091 assert(rcyl >= 0.0);
00092 }
00093
00094
00095 double xc = rcyl*cos(phi);
00096 double yc = rcyl*sin(phi);
00097 G4ThreeVector cellcenter(xc,yc,zc);
00098 return cellcenter;
00099 }
00100
00101
00102 unsigned int LCDG4CalSDProj::getIndex1(unsigned int cellIndex) const {
00103 unsigned int iaux = cellIndex - (cellIndex%_thetaseg);
00104 assert( iaux%_thetaseg == 0 );
00105 unsigned int iphi = (iaux/_thetaseg) % _phiseg;
00106 return iphi;
00107 }
00108
00109
00110 unsigned int LCDG4CalSDProj::getIndex2(unsigned int cellIndex) const {
00111 return cellIndex % _thetaseg;
00112 }
00113
00114
00115 unsigned int LCDG4CalSDProj::getIndex3(unsigned int cellIndex) const {
00116 unsigned int imult = _phiseg*_thetaseg;
00117 unsigned int iaux = cellIndex - (cellIndex % imult);
00118 unsigned int ilayer = iaux / imult;
00119 return ilayer;
00120 }