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

LCDG4CalSDNonProj.cc

Go to the documentation of this file.
00001 #include "LCDG4CalSDNonProj.hh"
00002 #include "LCDG4CalHit.hh"
00003 #include "LCD_DocumentUtil.hh"
00004 #include "NonProjCalGeometry.hh"
00005 #include "NonProjCalGeomParams.hh"
00006 #include "Util_String.hh"
00007 #include "NPCellID.hh"
00008 
00009 // Geant4
00010 #include "G4String.hh"
00011 
00012 using std::ofstream;
00013 using std::ios;
00014 
00015 XERCES_CPP_NAMESPACE_USE;
00016 
00017 /*
00018  * Constructor
00019  *
00020  * This constructor creates a cal-type SD that models non-projective
00021  * geometries with fixed-size rectangular cells.
00022  * XML parms are loaded from voldb, which points to the <TYPE>_BARREL
00023  * volume.  Parameters necessary for processing non-projective SD in 
00024  * ProcessHits are stored in NonProj geometry classes
00025  */
00026 LCDG4CalSDNonProj::LCDG4CalSDNonProj(G4String name, const DOM_Element& voldb)
00027   : LCDG4CalSD(name)
00028 {
00029   G4cout <<"  Creating non-projective LCDG4CalSD..."<< G4endl;
00030 
00031   // Encapsulate the NonProj parameters
00032   hcalpar = new NonProjCalGeomParams(voldb);
00033 
00034   // Create the geometry object
00035   hcal = new NonProjCalGeometry(*hcalpar);
00036 
00037   //------------------------------
00038   // Write out geometry parameters in output txt file.  Temporary?
00039   const char* geomfile = getenv("TXTGEOMFILE");
00040 
00041   if (geomfile == "") {
00042     G4cerr << "geomfilepath is NULL";
00043   }
00044   else {
00045     /* print all cell_info, layering, slice and volume information */
00046     if(debugLevel) {
00047       G4cout << "For NonProj geometry parameters, please check:\n";
00048     }
00049     G4cout << "NP geom file: " << geomfile << G4endl;
00050   }
00051 
00052   ofstream* outf_hcal = new ofstream(geomfile,ios::app);
00053   if( outf_hcal ) {
00054     *outf_hcal <<"Segmentation:\n\n";
00055     *outf_hcal<<"CalorimeterCell=hep.lcd.geometry.np.NPHADCalorimeterCell\n\n";
00056     *outf_hcal << "innerR= "<< hcalpar->GlobalRmin()/cm << G4endl;
00057     *outf_hcal << "outerR= "<< hcalpar->GlobalRmax()/cm << G4endl;
00058     *outf_hcal << "outerZ= "<< hcalpar->GlobalZmax()/cm << G4endl;
00059     *outf_hcal << "cellLenZ= "<< hcalpar->CellDimZ()/cm << G4endl;
00060     *outf_hcal << "cellLenPhi= "<< hcalpar->CellDimPhi()/cm<<G4endl;
00061     *outf_hcal << "num_layers= "<< hcalpar->NumberOfLayers() << G4endl;
00062     *outf_hcal << "preabs_thick= "<< hcalpar->PreAbsThickness()/cm<< G4endl;
00063     *outf_hcal << "sens_thick= "<< hcalpar->SensorThickness()/cm<< G4endl;
00064     *outf_hcal << "postabs_thick= "<< hcalpar->PostAbsThickness()/cm<< G4endl;
00065     *outf_hcal << "\nend;\n";
00066     outf_hcal->close();
00067     delete outf_hcal;
00068   }
00069 }
00070 
00071 /*
00072  * Destructor
00073  */
00074 LCDG4CalSDNonProj::~LCDG4CalSDNonProj() {
00075 }
00076 
00077 // NonProjective cell indices
00078 unsigned int LCDG4CalSDNonProj::findCell(const G4ThreeVector& pos) {
00079   NPCellID npid = hcal->getClosestCell(pos);
00080   unsigned int cellIndex = npid.packIn32Bits();
00081   return cellIndex;
00082 }
00083 
00084 // Nonprojective geometry calculations to find cell center
00085 G4ThreeVector LCDG4CalSDNonProj::getCellCenter(unsigned int cellIndex) {
00086 
00087   // Important: set geometry-dependent indices: index[2] and index[3]
00088   // convenience aliases
00089   unsigned int& iphi = index[2];
00090   unsigned int& iz   = index[3];
00091   iphi = getIndex1(cellIndex);
00092   iz   = getIndex2(cellIndex);
00093   NPCellID npid(cellIndex);
00094   G4ThreeVector cellcenter(hcal->getCellCenter(npid));
00095   return cellcenter;
00096 }
00097 
00098 //*** Cell indices
00099 // Non Projective cell indices
00100 //    6 bits for layer number
00101 //   12 bits for theta index
00102 //   14 bits for phi index
00103 //     = 32 bits total
00104 
00105 // index1 is iphi
00106 unsigned int LCDG4CalSDNonProj::getIndex1(unsigned int cellIndex) const {
00107   return (cellIndex & 0x3fff);
00108 }
00109 
00110 // index2 is iz
00111 unsigned int LCDG4CalSDNonProj::getIndex2(unsigned int cellIndex) const {
00112 //   int izAux = (cellIndex>>14)&0xfff;
00113 //   if(izAux&0x800) izAux |= ~0xfff;        // account for sign bit
00114 //   unsigned int iz = izAux;
00115   return (cellIndex >> 14) & 0xfff;
00116 }
00117 
00118 // index3 is ilayer
00119 unsigned int LCDG4CalSDNonProj::getIndex3(unsigned int cellIndex) const {
00120   return (cellIndex >> 26) & 0x3f;
00121 }
00122 
00123 //   //*** Temporary: check we can recover incoming indices ***
00124 //   int laynoAux = (cellIndex>>26);
00125 //   int izAux = (cellIndex>>14)&0xfff;
00126 //   if(izAux&0x800) izAux |= ~0xfff;        // account for sign bit
00127 //   int iphiAux = cellIndex & 0x3fff;
00128 //   assert( laynoAux == npid.ir );
00129 //   assert( izAux == npid.iz );
00130 //   assert( iphiAux == npid.iphi );
00131 //   //*** end of temporary code

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