G3toG4MANY.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // By I. Hrivnacova, 22.10.01 
00030 
00031 //#define G3G4DEBUG 1
00032 
00033 #include "globals.hh"
00034 #include "G3toG4MANY.hh"
00035 #include "G3Pos.hh"
00036 #include "G3RotTable.hh"
00037 #include "G4SubtractionSolid.hh"
00038 
00039 void G3toG4MANY(G3VolTableEntry* curVTE)
00040 {
00041   if (curVTE->GetNoOverlaps() > 0) {
00042   
00043     // check consistency 
00044     if (!curVTE->HasMANY()) { 
00045       G4String text = "G3toG4MANY: volume ";
00046       text = text + curVTE->GetName() + " has specified overlaps \n";
00047       text = text + " but is not defined as MANY.";
00048       G4Exception("G3toG4MANY()", "G3toG40009",
00049                   FatalException, text);
00050       return;
00051     }  
00052 
00053     // only MANY volumes with one position are supported
00054     if (curVTE->NPCopies() != 1) {
00055       G4String text = "G3toG4MANY: volume ";
00056       text = text + curVTE->GetName() + " which has MANY has not just one position.";
00057       G4Exception("G3toG4MANY()", "G3toG40010",
00058                   FatalException, text);
00059       return;
00060     }  
00061 
00062     #ifdef G3G4DEBUG
00063     G4cout << "G3toG4MANY  " << curVTE->GetName() << " boolean" << G4endl;
00064     #endif
00065 
00066     G4Transform3D transform = GetTransform3D(curVTE->GetG3PosCopy(0)); 
00067     
00068     MakeBooleanSolids(curVTE, curVTE->GetOverlaps(), transform.inverse());
00069   }
00070 
00071   // process daughters
00072   for (G4int i=0; i<curVTE->GetNoDaughters(); i++)
00073     G3toG4MANY(curVTE->GetDaughter(i));
00074 }
00075 
00076 void MakeBooleanSolids(G3VolTableEntry* curVTE, G3VolTableEntryVector* overlaps,
00077                        const G4Transform3D& transform)
00078 {                            
00079   // loop over overlap VTEs
00080   for (size_t i=0; i<overlaps->size(); i++){
00081    
00082     G3VolTableEntry* overlapVTE = (*overlaps)[i]; 
00083 
00084      // loop over clone VTEs
00085     for (G4int ij=0; ij<overlapVTE->GetMasterClone()->GetNoClones(); ij++){
00086     
00087       G3VolTableEntry* cloneVTE = overlapVTE->GetMasterClone()->GetClone(ij);   
00088    
00089       // loop over clone positions
00090       for (G4int j=0; j<cloneVTE->NPCopies(); j++){
00091 
00092         #ifdef G3G4DEBUG
00093         G4cout << "From '" << curVTE->GetName() << "' "
00094                << "cut '" << cloneVTE->GetName() << "' :"
00095                << i  << "th overlap (from " << overlaps->size() << ") "
00096                << ij << "th clone (from " << overlapVTE->GetMasterClone()->GetNoClones() << ") "
00097                << j  << "th copy (from " << cloneVTE->NPCopies() << ")  "
00098                << G4endl;
00099         #endif
00100 
00101         SubstractSolids(curVTE, cloneVTE, j, transform); 
00102       }
00103     }    
00104   }                               
00105 }                       
00106 
00107 void SubstractSolids(G3VolTableEntry* vte1, G3VolTableEntry* vte2,
00108                      G4int copy, const G4Transform3D& transform)
00109 {                            
00110   // vte2 transformation
00111   G4Transform3D transform2 = GetTransform3D(vte2->GetG3PosCopy(copy));
00112    
00113   // compose new name 
00114   G4String newName = vte1->GetSolid()->GetName();
00115   newName = newName + "-" + vte2->GetSolid()->GetName();   
00116 
00117   #ifdef G3G4DEBUG
00118   G4cout << "   " << newName << G4endl; 
00119   #endif
00120 
00121   G4VSolid* newSolid 
00122     = new G4SubtractionSolid(newName, vte1->GetSolid(), vte2->GetSolid(),
00123                              transform*transform2);
00124                                  
00125   // update vte1
00126   vte1->SetSolid(newSolid);
00127 
00128   // process daughters
00129   for (G4int k=0; k<vte1->GetNoDaughters(); k++){
00130                 
00131     G3VolTableEntry* dVTE = vte1->GetDaughter(k);                               
00132          
00133     if (dVTE->NPCopies() != 1) {
00134       G4String text = "G3toG4MANY: volume ";
00135       text = text + dVTE->GetName() + " which has MANY has not just one position.";
00136       G4Exception("G3toG4MANY()", "G3toG40011",
00137                   FatalException, text);
00138       return;
00139     }
00140           
00141     G4Transform3D dt = GetTransform3D(dVTE->GetG3PosCopy(0)); 
00142     SubstractSolids(dVTE, vte2, copy, dt.inverse()*transform);
00143   }     
00144 }                       
00145 
00146 G4Transform3D GetTransform3D(G3Pos* g3pos)
00147 {
00148   G4int irot = g3pos->GetIrot();
00149   G4RotationMatrix* theMatrix = 0;
00150   if (irot>0) theMatrix = G3Rot.Get(irot);
00151   
00152   G4Rotate3D rotation;
00153   if (theMatrix) {            
00154      rotation = G4Rotate3D(*theMatrix);
00155   }
00156 
00157   G4Translate3D translation(*(g3pos->GetPos()));
00158   G4Transform3D transform3D = translation * (rotation.inverse());
00159   
00160   return transform3D;
00161 }
00162 
00163 

Generated on Mon May 27 17:47:36 2013 for Geant4 by  doxygen 1.4.7