]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
applied corrections of first implementation; separated materials from section (added...
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 5 Sep 2000 09:33:09 +0000 (09:33 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 5 Sep 2000 09:33:09 +0000 (09:33 +0000)
TGeant4/TG4XMLGeometryGenerator.cxx

index 1d85a98b804ab97824073df3ffd7e0637b74c99c..e7f68cbfb41f7e7b48093302a7f0ef091d95ae1d 100644 (file)
@@ -94,6 +94,22 @@ void TG4XMLGeometryGenerator::ProcessMaterials(G4LogicalVolume* lv)
     }
 }  
 
+void TG4XMLGeometryGenerator::ProcessRotations(G4LogicalVolume* lv) 
+{
+// Writes all rotation matrices of given logical volume.
+// ---
+
+  G4int nofDaughters = lv->GetNoDaughters();
+  if (nofDaughters>0) 
+    for (G4int i=0; i<nofDaughters; i++) {
+      G4VPhysicalVolume* pvd = lv->GetDaughter(i);
+      const G4RotationMatrix* kRotation = pvd->GetRotation();
+      if (kRotation) fConvertor->WriteRotation(kRotation);
+      G4LogicalVolume* lvd = pvd->GetLogicalVolume();
+      ProcessRotations(lvd);
+    }
+}  
+
 void TG4XMLGeometryGenerator::ProcessLogicalVolume(G4LogicalVolume* lv) 
 {
 // Writes logical volume tree.
@@ -102,6 +118,81 @@ void TG4XMLGeometryGenerator::ProcessLogicalVolume(G4LogicalVolume* lv)
   G4int nofDaughters = lv->GetNoDaughters();
   if (nofDaughters == 0) return;
   
+  // open composition
+  G4String name = lv->GetName();
+  name.append("_comp");
+  fConvertor->OpenComposition(name);
+      
+  // write positions  
+  for (G4int i=0; i<nofDaughters; i++) {
+    G4VPhysicalVolume* vpvd = lv->GetDaughter(i);
+    G4LogicalVolume* lvd = vpvd->GetLogicalVolume();
+      
+    // only placements are processed
+    G4PVPlacement* pvd = dynamic_cast<G4PVPlacement*>(vpvd);
+    if (pvd) {
+      G4String solidName = lvd->GetSolid()->GetName();
+      G4String compName = lvd->GetName();
+      compName.append("_comp");      
+      G4int nd = lvd->GetNoDaughters(); 
+      G4ThreeVector  position = vpvd->GetFrameTranslation();
+      const G4RotationMatrix* kMatrix = vpvd->GetFrameRotation();      
+
+      if (!kMatrix) {
+       fConvertor->WritePosition(solidName, position);
+        // if volume is not leaf node place its logical volume
+        if (nd>0) 
+         fConvertor->WritePosition(compName, position);
+      }          
+      else {  
+       fConvertor->WritePositionWithRotation(solidName, position, kMatrix);
+        if (nd>0) 
+          fConvertor->WritePositionWithRotation(compName, position, kMatrix);
+      }   
+          
+    }
+    else {
+      G4String text = "TG4XMLGeometryGenerator::ProcessLogicalVolume: \n";
+      text = text + "    Limitation: \n";
+      text = text + "    Other physical volumes than PVPlacement";
+      text = text + " are not implemented.";
+      TG4Globals::Warning(text);
+    }
+  }  
+
+  // close composition
+  fConvertor->CloseComposition();      
+  fConvertor->WriteEmptyLine();
+
+  // make a vector of contained logical volumes
+  // with daughters
+  // -> change to a global map of names of written compositions 
+  //    and test against this map 
+  G4std::vector<G4LogicalVolume*> vect;
+  for (G4int i=0; i<nofDaughters; i++) {
+    G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume();
+    G4bool store = true;
+    for (G4int j=0; j<vect.size(); j++) 
+      if (vect[j] == lvd || lvd->GetNoDaughters()==0) store = false;
+    if (store) vect.push_back(lvd);
+  }   
+
+  // process contained logical volumes with daughters  
+  fConvertor->IncreaseIndention();
+  for (G4int j=0; j<vect.size(); j++) 
+    ProcessLogicalVolume(vect[j]);
+  fConvertor->DecreaseIndention();
+}  
+
+/*
+void TG4XMLGeometryGenerator::ProcessLogicalVolumeOld(G4LogicalVolume* lv) 
+{
+// Writes logical volume tree.
+// ---
+  
+  G4int nofDaughters = lv->GetNoDaughters();
+  if (nofDaughters == 0) return;
+  
   // make a vector of contained logical volumes
   G4std::vector<G4LogicalVolume*> vect;
   for (G4int i=0; i<nofDaughters; i++) {
@@ -158,37 +249,56 @@ void TG4XMLGeometryGenerator::ProcessLogicalVolume(G4LogicalVolume* lv)
     }
   }
 }  
+*/
 
 // public methods
 
+void TG4XMLGeometryGenerator::GenerateMaterials( 
+                        const G4String& version, const G4String& date,
+                       const G4String& author,  const G4String dtdVersion,
+                       G4LogicalVolume* lv)
+{
+// Generates the XML material element containing
+// all materials present in given logical volume.
+// ---
+
+  // create section
+  fConvertor->OpenMaterials(version, date, author, dtdVersion);  
+  fConvertor->WriteEmptyLine();
+  
+  // process materials
+  ProcessMaterials(lv);
+  fConvertor->WriteEmptyLine();
+
+  // close section
+  fConvertor->CloseMaterials();
+  fConvertor->WriteEmptyLine();
+}   
+
 void TG4XMLGeometryGenerator::GenerateSection(const G4String& name, 
                         const G4String& version, const G4String& date,
                        const G4String& author, const G4String& topVolume,
                         G4LogicalVolume* lv)
 {
-// Generates the XML section containing
+// Generates the XML section element containing
 // all geometry objects defined in given logical volume:
-// materials, solids, rotation matrices and
-// volumes hierarchy.
+// rotation matrices, solids and volumes hierarchy.
 // ---
 
   // create section
   fConvertor->OpenSection(name, version, date, author, topVolume);  
   fConvertor->WriteEmptyLine();
   
-  // process materials
-  ProcessMaterials(lv);
+  // process rotations
+  ProcessRotations(lv);
   fConvertor->WriteEmptyLine();
-
+    
   // process solids
   ProcessSolids(lv);
   fConvertor->WriteEmptyLine();
     
   // process geometry tree
-  G4String moduleName = name; moduleName.append("_module");
-  fConvertor->OpenComposition(moduleName);  
   ProcessLogicalVolume(lv);
-  fConvertor->CloseComposition();
   fConvertor->WriteEmptyLine();
   
   // close section