]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - Flugg/FGeometryInit.cxx
Updates needed for move to geant4.6
[u/mrichter/AliRoot.git] / Flugg / FGeometryInit.cxx
index 45b04944aa714eac19abc21cb4e8a3d14198930a..65010044506193d060010d78e426ae30a45a109f 100644 (file)
@@ -77,7 +77,18 @@ FGeometryInit::~FGeometryInit() {
   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;
@@ -296,13 +307,13 @@ void FGeometryInit::createFlukaMatFile() {
 
   //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);
@@ -342,7 +353,7 @@ void FGeometryInit::BuildRegionsMap() {
 #endif
 }
 
-void FGeometryInit::PrintRegionsMap(G4std::ostream& os) {
+void FGeometryInit::PrintRegionsMap(std::ostream& os) {
 #ifdef G4GEOMETRY_DEBUG
   G4cout << "==> Flugg FGeometryInit::PrintRegionsMap()" << G4endl;
 #endif
@@ -360,9 +371,9 @@ void FGeometryInit::PrintRegionsMap(G4std::ostream& os) {
     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()) {
@@ -372,8 +383,8 @@ void FGeometryInit::PrintRegionsMap(G4std::ostream& os) {
       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;
     
@@ -384,6 +395,63 @@ void FGeometryInit::PrintRegionsMap(G4std::ostream& os) {
 #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() {
@@ -595,7 +663,7 @@ FGeometryInit::BuildFlukaCompoundFromElement(const G4Element* element,
 #endif
 }
 
-void FGeometryInit::PrintMaterialTables(G4std::ostream& os) {
+void FGeometryInit::PrintMaterialTables(std::ostream& os) {
 #ifdef G4GEOMETRY_DEBUG
   G4cout << "==> Flugg FGeometryInit::PrintMaterialTables()" << G4endl;
 #endif
@@ -607,9 +675,9 @@ void FGeometryInit::PrintMaterialTables(G4std::ostream& os) {
   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;
@@ -627,7 +695,7 @@ void FGeometryInit::PrintMaterialTables(G4std::ostream& os) {
 
 ////////////////////////////////////////////////////////////////////////
 // 
-void FGeometryInit::PrintAssignmat(G4std::ostream& os) {
+void FGeometryInit::PrintAssignmat(std::ostream& os) {
 #ifdef G4GEOMETRY_DEBUG
   G4cout << "==> Flugg FGeometryInit::PrintAssignmat()" << G4endl;
 #endif
@@ -669,7 +737,7 @@ void FGeometryInit::PrintAssignmat(G4std::ostream& os) {
     
     //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";
@@ -685,7 +753,7 @@ void FGeometryInit::PrintAssignmat(G4std::ostream& os) {
 }
 
 
-void FGeometryInit::PrintMagneticField(G4std::ostream& os) {
+void FGeometryInit::PrintMagneticField(std::ostream& os) {
 #ifdef G4GEOMETRY_DEBUG
   G4cout << "==> Flugg FGeometryInit::PrintMagneticField()" << G4endl;
 #endif
@@ -714,9 +782,9 @@ void FGeometryInit::PrintMagneticField(G4std::ostream& os) {
        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;
@@ -736,3 +804,129 @@ void FGeometryInit::PrintMagneticField(G4std::ostream& os) {
   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 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];
+}