G4cout << "<== Flugg FGeometryInit::FGeometryInit()" << G4endl;
}
-
+void FGeometryInit::Init() {
+// Build and initialize G4 geometry
+ setDetector();
+ setMotherVolume();
+ closeGeometry();
+ InitHistories();
+ InitJrLtGeantArray();
+ InitHistArray();
+ createFlukaMatFile();
+}
+
+
void FGeometryInit::closeGeometry() {
#ifdef G4GEOMETRY_DEBUG
G4cout << "==> Flugg FGeometryInit::closeGeometry()" << G4endl;
}
//*****************************************************************************
+int FGeometryInit::GetLastMaterialIndex() const
+{
+// Get last material index as known by FLUKA
+ const FlukaMaterialsTable *matTable = FlukaMaterial::GetMaterialTable();
+ int matsize = matTable->size();
+ return matsize+2;
+}
void FGeometryInit::createFlukaMatFile() {
// last modification Sara Vanini 1/III/99
//Regions map
BuildRegionsMap();
- G4std::ofstream vos("Volumes_index.inp");
+ std::ofstream vos("Volumes_index.inp");
PrintRegionsMap(vos);
vos.close();
//Materials and compounds
BuildMaterialTables();
- G4std::ofstream fos("flukaMat.inp");
+ std::ofstream fos("flukaMat.inp");
PrintMaterialTables(fos);
PrintAssignmat(fos);
PrintMagneticField(fos);
#endif
}
-void FGeometryInit::PrintRegionsMap(G4std::ostream& os) {
+void FGeometryInit::PrintRegionsMap(std::ostream& os) {
#ifdef G4GEOMETRY_DEBUG
G4cout << "==> Flugg FGeometryInit::PrintRegionsMap()" << G4endl;
#endif
int index = (*i).second;
//Print index and region name in some fixed format
- os.setf(G4std::ios::left, G4std::ios::adjustfield);
+ os.setf(std::ios::left, std::ios::adjustfield);
os << setw10 << index;
- os << G4std::setw(20) << ptrVol->GetName() << G4std::setw(20) << "";
+ os << std::setw(20) << ptrVol->GetName() << std::setw(20) << "";
//If volume is a replica... print some more stuff
if(ptrVol->IsReplicated()) {
G4double offset = -1;
G4bool consum = false;
ptrVol->GetReplicationData(axis, nRep, width, offset, consum);
- os.setf(G4std::ios::left, G4std::ios::adjustfield);
- os << setw10 << "Repetion Nb: " << G4std::setw(3) << nRep;
+ os.setf(std::ios::left, std::ios::adjustfield);
+ os << setw10 << "Repetion Nb: " << std::setw(3) << nRep;
}
os << G4endl;
#endif
}
+////////////////////////////////////////////////////////////////////////
+//
+void FGeometryInit::BuildMediaMap()
+{
+ fRegionMediumMap = new int[fNRegions+1];
+ for (RegionIterator i = fRegionVolumeMap.begin();
+ i != fRegionVolumeMap.end();
+ i++) {
+ //Get info in the map
+ G4VPhysicalVolume* ptrVol = (*i).first;
+ int region = (*i).second;
+ G4int imed = fMediumVolumeMap[ptrVol];
+ fRegionMediumMap[region] = imed;
+ printf("BuildMediaMap %s %d %d\n",(ptrVol->GetName()).data(), region, imed);
+
+ }
+}
+
+G4int FGeometryInit::GetMedium(int region) const
+{
+ return fRegionMediumMap[region];
+}
+
+
+void FGeometryInit::SetMediumFromName(const char* volName, int medium, int volid)
+ {
+ char name4[5];
+ char tmp[5];
+ strncpy(tmp, volName, 4);
+ tmp[4]='\0';
+ fNRegions = 0;
+
+ for (RegionIterator i = fRegionVolumeMap.begin();
+ i != fRegionVolumeMap.end();
+ i++) {
+ fNRegions++;
+ //Get info in the map
+ G4VPhysicalVolume* ptrVol = (*i).first;
+ strncpy(name4, (ptrVol->GetName()).data(), 4);
+ name4[4]='\0';
+ for (int j = 0; j < 4; j++) {
+ if (name4[j] == '\0') {
+ for (int k = j; k < 4; k++) {
+ name4[k] = ' ';
+ }
+ break;
+ }
+ }
+ if (! strncmp(name4, tmp, 4)) {
+ fMediumVolumeMap[ptrVol] = medium;
+ fVolIdVolumeMap[ptrVol] = volid;
+ }
+ }
+}
+
+
+
////////////////////////////////////////////////////////////////////////
//
void FGeometryInit::BuildMaterialTables() {
#endif
}
-void FGeometryInit::PrintMaterialTables(G4std::ostream& os) {
+void FGeometryInit::PrintMaterialTables(std::ostream& os) {
#ifdef G4GEOMETRY_DEBUG
G4cout << "==> Flugg FGeometryInit::PrintMaterialTables()" << G4endl;
#endif
size_t nElements = G4Element::GetNumberOfElements();
size_t nMaterials = G4Material::GetNumberOfMaterials();
- os << "* In Geant4 there are " << nMaterials << " materials" << endl;
- os << "* In Geant4 there are " << nElements << " elements" << endl;
- os << "* In Geant4 there are " << nIsotopes << " isotopes" << endl;
+ os << "* In Geant4 there are " << nMaterials << " materials" << G4endl;
+ os << "* In Geant4 there are " << nElements << " elements" << G4endl;
+ os << "* In Geant4 there are " << nIsotopes << " isotopes" << G4endl;
//Materials
G4cout << "\t* Printing FLUKA materials..." << G4endl;
////////////////////////////////////////////////////////////////////////
//
-void FGeometryInit::PrintAssignmat(G4std::ostream& os) {
+void FGeometryInit::PrintAssignmat(std::ostream& os) {
#ifdef G4GEOMETRY_DEBUG
G4cout << "==> Flugg FGeometryInit::PrintAssignmat()" << G4endl;
#endif
//Print card
os << setw10 << "ASSIGNMAT ";
- os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
+ os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
os << setw10 << setfixed << G4double(matIndex);
os << setw10 << setfixed << G4double(iFlukaRegion);
os << setw10 << "0.0";
}
-void FGeometryInit::PrintMagneticField(G4std::ostream& os) {
+void FGeometryInit::PrintMagneticField(std::ostream& os) {
#ifdef G4GEOMETRY_DEBUG
G4cout << "==> Flugg FGeometryInit::PrintMagneticField()" << G4endl;
#endif
os << setw10 << "";
os << setw10 << "";
os << setw10 << "";
- os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
+ os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
os << setw10 << setfixed
- << G4std::setprecision(4) << B[0]
+ << std::setprecision(4) << B[0]
<< setw10 << B[1]
<< setw10 << B[2]
<< G4endl;
G4cout << "<== Flugg FGeometryInit::PrintMagneticField()" << G4endl;
#endif
}
+
+int FGeometryInit::CurrentVolID(int ir, int& copyNo)
+{
+ if (ir == 0)
+ {
+ copyNo = -1;
+ return -1;
+ }
+
+ G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
+ G4VPhysicalVolume * physicalvol = (*pVolStore)[ir- 1];
+
+ if (physicalvol) {
+ copyNo = physicalvol->GetCopyNo();
+ } else {
+ copyNo = -1;
+ return -1;
+ }
+
+
+ int id = fVolIdVolumeMap[physicalvol];
+ return id;
+}
+
+int FGeometryInit::CurrentVolOffID(int ir, int off, int& copyNo)
+{
+ if (off == 0) return CurrentVolID(ir, copyNo);
+
+ G4PhysicalVolumeStore* pVolStore = G4PhysicalVolumeStore::GetInstance();
+ G4VPhysicalVolume* physicalvol = (*pVolStore)[ir- 1];
+ G4VPhysicalVolume* mother = physicalvol;
+
+ int index;
+//============================================================================
+ if (mother) {
+ // Check touchable depth
+ //
+ if (ptrTouchHist->GetHistoryDepth() < off) {
+ mother = 0;
+ } else {
+ // Get the off-th mother
+ index = ptrTouchHist->GetHistoryDepth() - off;
+ // in the touchable history volumes are ordered
+ // from top volume up to mother volume;
+ // the touchable volume is not in the history
+ mother = ptrTouchHist->GetHistory()->GetVolume(index);
+ }
+ }
+//============================================================================
+
+ int id;
+
+ if (!mother) {
+ G4cout << "Flugg FGeometryInit::CurrentVolOffID mother not found" << G4endl;
+ id = -1;
+ copyNo = -1;
+ } else {
+ copyNo = mother ->GetCopyNo();
+ id = fVolIdVolumeMap[mother];
+ }
+ return id;
+}
+
+void FGeometryInit::Gmtod(double* xm, double* xd, int iflag)
+{
+// Transforms a position from the world reference frame
+// to the current volume reference frame.
+//
+// Geant3 desription:
+// ==================
+// Computes coordinates XD (in DRS)
+// from known coordinates XM in MRS
+// The local reference system can be initialized by
+// - the tracking routines and GMTOD used in GUSTEP
+// - a call to GMEDIA(XM,NUMED)
+// - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
+// (inverse routine is GDTOM)
+//
+// If IFLAG=1 convert coordinates
+// IFLAG=2 convert direction cosinus
+//
+// ---
+ FluggNavigator * ptrNavig = getNavigatorForTracking();
+ //setting variables (and dimension: Fluka uses cm.!)
+ G4ThreeVector pGlob(xm[0],xm[1],xm[2]);
+ G4ThreeVector pLoc;
+
+ if (iflag == 1) {
+ pGlob *= 10.0; // in mm
+// change because of geant 4 6.0
+// pLoc = ptrNavig->ComputeLocalPoint(pGlob);
+ pLoc = ptrNavig->GetGlobalToLocalTransform().TransformPoint(pGlob);
+
+ pLoc /= 10.0; // in cm
+ } else if (iflag == 2) {
+ pLoc =
+ ptrNavig->ComputeLocalAxis(pGlob);
+ } else {
+ G4cout << "Flugg FGeometryInit::Gmtod called with undefined flag" << G4endl;
+ }
+ xd[0] = pLoc[0]; xd[1] = pLoc[1]; xd[2] = pLoc[2];
+}
+
+void FGeometryInit::Gdtom(double* xd, double* xm, int iflag)
+{
+// Transforms a position from the current volume reference frame
+// to the world reference frame.
+//
+// Geant3 desription:
+// ==================
+// Computes coordinates XM (Master Reference System
+// knowing the coordinates XD (Detector Ref System)
+// The local reference system can be initialized by
+// - the tracking routines and GDTOM used in GUSTEP
+// - a call to GSCMED(NLEVEL,NAMES,NUMBER)
+// (inverse routine is GMTOD)
+//
+// If IFLAG=1 convert coordinates
+// IFLAG=2 convert direction cosinus
+//
+// ---
+
+ FluggNavigator * ptrNavig = getNavigatorForTracking();
+ G4ThreeVector pLoc(xd[0],xd[1],xd[2]);
+
+ G4ThreeVector pGlob;
+ if (iflag == 1) {
+ pLoc *= 10.0; // in mm
+ pGlob = ptrNavig->GetLocalToGlobalTransform().
+ TransformPoint(pLoc);
+ pGlob /= 10.0; // in cm
+ } else if (iflag == 2) {
+ pGlob = ptrNavig->GetLocalToGlobalTransform().
+ TransformAxis(pLoc);
+ } else {
+ G4cout << "Flugg FGeometryInit::Gdtom called with undefined flag" << G4endl;
+ }
+
+ xm[0] = pGlob[0]; xm[1] = pGlob[1]; xm[2] = pGlob[2];
+}