}
////////////////////////////////////////////////////////////////////////
-//
-G4int FGeometryInit::GetRegionFromName(const char* volName) const {
+//
+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;
- if (ptrVol->GetName() == volName)
- return ((*i).second);
+ 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;
+ }
}
- return -1;
}
G4cout << "<== Flugg FGeometryInit::PrintMagneticField()" << G4endl;
#endif
}
+
+int FGeometryInit::CurrentVolID(int ir, int& copyNo)
+{
+ G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
+ G4VPhysicalVolume * physicalvol = (*pVolStore)[ir- 1];
+ copyNo = physicalvol->GetCopyNo();
+ 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 level = off;
+ while (level > 0) {
+ if (mother) mother = mother->GetMother();
+ level--;
+ }
+
+ 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]);
+ pGlob *= 10.0; // in millimeters
+ G4ThreeVector pLoc;
+
+ if (iflag == 1) {
+ pLoc =
+ ptrNavig->ComputeLocalPoint(pGlob);
+ } 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) {
+ pGlob = ptrNavig->GetLocalToGlobalTransform().
+ TransformPoint(pLoc);
+ } 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];
+}