Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

LCDG4CalSDProj.cc

Go to the documentation of this file.
00001 #include "LCDG4CalSDProj.hh"
00002 #include "LCD_DocumentUtil.hh"
00003 #include "LCD_DocGeoUtil.hh"
00004 
00005 // Geant4
00006 #include "G4String.hh"
00007 
00008 
00009 XERCES_CPP_NAMESPACE_USE;
00010 
00011 /*
00012  * Constructor
00013  *
00014  * This constructor creates a cal-type SD that models projective
00015  * geometries with fixed-solid-angle cells.
00016  * XML parms are loaded from voldb, which points to the <TYPE>_BARREL
00017  * volume.  Parameters necessary for processing projective SD in 
00018  * ProcessHits are stored in phiseg and thetaseg arrays
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  * Destructor
00038  */
00039 LCDG4CalSDProj::~LCDG4CalSDProj() {
00040 }
00041 
00042 //*** Projective cell indices
00043 unsigned int LCDG4CalSDProj::findCell(const G4ThreeVector& pos) {
00044 
00045   // theta,phi are spherical coords from geant hit
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   // convenience aliases
00053   unsigned int& ilayer = index[1];
00054   unsigned int& iphi   = index[2];
00055   unsigned int& itheta = index[3];
00056   // set geometry-dependent indices: index[2] and index[3]
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 //*** Projective geometry calculations to find cell center
00064 G4ThreeVector LCDG4CalSDProj::getCellCenter(unsigned int cellIndex) {
00065   if(cellIndex) ; // make compiler happy
00066   // convenience aliases
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;  // +0.5 for center of cell
00075   double phi = (iphi+0.5)*dphi/radian;        // +0.5 for center of cell
00076 
00077   // rcyl is cyl radius for the center of active material in i-th layer
00078   // rsph is spherical rad for the center of active
00079   double rcyl=0, zc=0;
00080   if(sysno%2==0) {
00081     // ** BARREL **
00082     rcyl = layer0CenterDepth + ilayer*layerThickness;
00083     zc = rcyl/tan(theta);
00084   }
00085   else {
00086     // ** ENDCAP **
00087     zc = layer0CenterDepth + ilayer*layerThickness;
00088     // Check for north/south
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 // Index decoding: index1 is iphi
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 // Index decoding: index2 is itheta
00110 unsigned int LCDG4CalSDProj::getIndex2(unsigned int cellIndex) const {
00111   return cellIndex % _thetaseg;
00112 }
00113 
00114 // Index decoding: index3 is ilayer
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 }

Generated on Thu Oct 7 18:44:46 2004 for LCDG4 by doxygen 1.3.4