// $Id$ // // File: DRootGeom.h // Created: Fri Feb 13 08:43:39 EST 2009 // Creator: zihlmann // #include "DRootGeom.h" #include "hddsroot.h" using namespace std; //--------------------------------- // DRootGeom (Constructor) //--------------------------------- DRootGeom::DRootGeom(JApplication *japp) { pthread_mutexattr_init(&mutex_attr); pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&mutex, &mutex_attr); table_initialized = false; DRGeom = NULL; int runnumber = 1; jcalib = japp->GetJCalibration(runnumber); if(!jcalib){ _DBG_<<"Unable to get JCalibration object!"<GetJParameterManager(); if(!jparms){ _DBG_<<"Unable to get JParameterManager object!"< > Mmap; jcalib->Get(namepath, Mmap); cout< to make a // histogram of the entries by using the key to hold the extent // so that the number of entries will be equal to the number of // different values. map rvals; map zvals; double rmin, zmin, rmax, zmax; rmin = zmin = 1.0E6; rmax = zmax = -1.0E6; for(unsigned int i=0; i &a = Mmap[i]; float &r = a[0]; float &z = a[1]; rvals[r] = 1; zvals[z] = 1; if(rrmax)rmax=r; if(z>zmax)zmax=z; } Nr = rvals.size(); Nz = zvals.size(); r0 = rmin; z0 = zmin; dr = (rmax-rmin)/(double)(Nr-1); dz = (zmax-zmin)/(double)(Nz-1); cout<<" Nr="< &a = Mmap[i]; float &r = a[0]; float &z = a[1]; int ir = floor((r - r0)/dr); int iz = floor((z - z0)/dz); if(ir<0 || ir>=Nr){_DBG_<<"ir out of range: ir="<FindNode(x[0],x[1],x[2]); pthread_mutex_unlock(&mutex); return cnode; } //--------------------------------- // FindVolume //--------------------------------- TGeoVolume* DRootGeom::FindVolume(double *x) { pthread_mutex_lock(&mutex); if(!DRGeom)InitDRGeom(); TGeoNode *cnode = DRGeom->FindNode(x[0],x[1],x[2]); TGeoVolume *cvol = cnode->GetVolume(); pthread_mutex_unlock(&mutex); return cvol; } //--------------------------------- // FindMat //--------------------------------- jerror_t DRootGeom::FindMat(DVector3 pos, double &density, double &A, double &Z, double &RadLen) const { return FindMatLL(pos, density, A, Z, RadLen); } //--------------------------------- // FindMat //--------------------------------- jerror_t DRootGeom::FindMat(DVector3 pos, double &rhoZ_overA, double &rhoZ_overA_logI, double &RadLen) const { return FindMatTable(pos, rhoZ_overA, rhoZ_overA_logI, RadLen); } //--------------------------------- // FindMatTable //--------------------------------- jerror_t DRootGeom::FindMatTable(DVector3 pos,double &density, double &A, double &Z, double &RadLen) const { if(!table_initialized)((DRootGeom*)this)->InitTable(); // For now, this just finds the bin in the material map the given position is in // (i.e. no interpolation ) double r = pos.Perp(); double z = pos.Z(); int ir = floor((r-r0)/dr); int iz = floor((z-z0)/dz); if(ir<0 || ir>=Nr || iz<0 || iz>=Nz){ A = Z = density = RadLen = 0.0; return RESOURCE_UNAVAILABLE; } const VolMat &mat = MatTable[ir][iz]; A = mat.A; Z = mat.Z; density = mat.Density; RadLen = mat.RadLen; return NOERROR; } //--------------------------------- // FindMatTable //--------------------------------- jerror_t DRootGeom::FindMatTable(DVector3 pos, double &rhoZ_overA, double &rhoZ_overA_logI, double &RadLen) const { if(!table_initialized)((DRootGeom*)this)->InitTable(); // For now, this just finds the bin in the material map the given position is in // (i.e. no interpolation ) double r = pos.Perp(); double z = pos.Z(); int ir = floor((r-r0)/dr); int iz = floor((z-z0)/dz); if(ir<0 || ir>=Nr || iz<0 || iz>=Nz){ rhoZ_overA = rhoZ_overA_logI = RadLen = 0.0; return RESOURCE_UNAVAILABLE; } const VolMat &mat = MatTable[ir][iz]; rhoZ_overA = mat.rhoZ_overA; rhoZ_overA_logI = mat.rhoZ_overA_logI; RadLen = mat.RadLen; return NOERROR; } //--------------------------------- // FindMatLL //--------------------------------- jerror_t DRootGeom::FindMatLL(DVector3 pos, double &rhoZ_overA, double &rhoZ_overA_logI, double &RadLen) const { /// This is a wrapper for the other FindMatLL method that returns density, A, and Z. /// It is here to make easy comparisons between the LL and table methods. double density, A, Z; FindMatLL(pos, density, A, Z, RadLen); double I = (Z*12.0 + 7.0)*1.0E-9; // From Leo 2nd ed. pg 25. rhoZ_overA = density*Z/A; rhoZ_overA_logI = rhoZ_overA*log(I); return NOERROR; } //--------------------------------- // FindMatLL //--------------------------------- jerror_t DRootGeom::FindMatLL(DVector3 pos,double &density, double &A, double &Z, double &RadLen) const{ density=RadLen=A=Z=0.; pthread_mutex_lock(const_cast(&mutex)); if(!DRGeom)((DRootGeom*)this)->InitDRGeom(); // cast away constness to ensure DRGeom is set TGeoNode *cnode = DRGeom->FindNode(pos.X(),pos.Y(),pos.Z()); if (cnode==NULL){ _DBG_<<"Missing cnode at position (" <GetVolume(); if (cvol==NULL){ _DBG_<<"Missing cvol" <GetMedium()->GetMaterial(); density=cmat->GetDensity(); RadLen=cmat->GetRadLen(); A=cmat->GetA(); Z=cmat->GetZ(); if (A<1.){ // try to prevent division by zero problems A=1.; } pthread_mutex_unlock(const_cast(&mutex)); return NOERROR; } //--------------------------------- // FindMat //--------------------------------- struct VolMat DRootGeom::FindMat(double *x) { pthread_mutex_lock(&mutex); if(!DRGeom)InitDRGeom(); TGeoNode *cnode = DRGeom->FindNode(x[0],x[1],x[2]); TGeoVolume *cvol = cnode->GetVolume(); TGeoMaterial *cmat = cvol->GetMedium()->GetMaterial(); Current_Node = cnode; Current_Volume = cvol; Current_Material = cmat; Mat_Index = cmat->GetIndex(); Mat.A = cmat->GetA(); Mat.Z = cmat->GetZ(); Mat.Density = cmat->GetDensity(); Mat.RadLen = cmat->GetRadLen(); pthread_mutex_unlock(&mutex); //cout<FindNode(x[0],x[1],x[2])->GetVolume()->GetName()<