G3toG4BuildTree.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 // modified by I. Hrivnacova, 2.8.99 
00030 
00031 #include "globals.hh"
00032 #include "G3toG4BuildTree.hh"
00033 #include "G3RotTable.hh"
00034 #include "G3MedTable.hh"
00035 #include "G3VolTable.hh"
00036 #include "G3SensVolVector.hh"
00037 #include "G3Pos.hh"
00038 #include "G4LogicalVolume.hh"
00039 #include "G4PVPlacement.hh"
00040 #include "G4ReflectionFactory.hh"
00041 #include "G4Transform3D.hh"
00042 
00043 void G3toG4BuildTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE)
00044 {
00045   G3toG4BuildLVTree(curVTE, motherVTE);
00046   G3toG4BuildPVTree(curVTE);
00047 }  
00048 
00049 void G3toG4BuildLVTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE)
00050 {
00051   // check existence of the solid
00052   if (curVTE->GetSolid()) {
00053     G4LogicalVolume* curLog = curVTE->GetLV();
00054     if (!curLog) {
00055       // skip creating logical volume
00056       // in case it already exists
00057     
00058       // material
00059       G4Material* material = 0;
00060       G3MedTableEntry* mte = G3Med.get(curVTE->GetNmed());
00061       if (mte) material = mte->GetMaterial();
00062       if (!material) {
00063         G4String err_message = "VTE " + curVTE->GetName()
00064                              + " has not defined material!!";
00065         G4Exception("G3toG4BuildLVTree()", "G3toG40001",
00066                     FatalException, err_message);
00067         return;
00068       } 
00069 
00070       // logical volume
00071       curLog = 
00072         new G4LogicalVolume(curVTE->GetSolid(), material, curVTE->GetName());
00073       curVTE->SetLV(curLog);
00074       
00075       // insert logical volume to G3SensVol vector
00076       // in case it is sensitive
00077       if (mte->GetISVOL()) G3SensVol.push_back(curLog);
00078     }  
00079   }
00080   else {
00081     if ( !(curVTE->GetDivision() && motherVTE->GetMasterClone() == motherVTE &&
00082            motherVTE->GetNoClones()>1)) {
00083       // ignore dummy vte's 
00084       // (this should be the only case when the vte is dummy but
00085       // is present in mother <-> daughters tree
00086       G4String err_message = "VTE " + curVTE->GetName()
00087                            + " has not defined solid!!";
00088       G4Exception("G3toG4BuildLVTree()", "G3toG40002",
00089                   FatalException, err_message);
00090       return;
00091     }
00092   }  
00093   
00094   // process daughters
00095   G4int Ndau = curVTE->GetNoDaughters();
00096   for (int Idau=0; Idau<Ndau; Idau++){
00097     G3toG4BuildLVTree(curVTE->GetDaughter(Idau), curVTE);
00098   }
00099 }
00100 
00101 void G3toG4BuildPVTree(G3VolTableEntry* curVTE)
00102 {
00103   // check existence of the solid
00104   if (curVTE->GetSolid()) {
00105     G4LogicalVolume* curLog = curVTE->GetLV();
00106   
00107     // positions in motherVTE
00108     for (G4int i=0; i<curVTE->NPCopies(); i++){
00109 
00110       G3Pos* theG3Pos = curVTE->GetG3PosCopy(i);
00111       if (theG3Pos) {
00112 
00113         // loop over all mothers 
00114         for (G4int im=0; im<curVTE->GetNoMothers(); im++) {
00115 
00116           G3VolTableEntry* motherVTE = curVTE->GetMother(im);
00117           if (theG3Pos->GetMotherName() == motherVTE->GetMasterClone()->GetName()) {
00118      
00119             // get mother logical volume
00120             G4LogicalVolume* mothLV=0;
00121             G4String motherName = motherVTE->GetName();    
00122             if (!curVTE->FindMother(motherName)) continue;
00123             if (curVTE->FindMother(motherName)->GetName() != motherName) {
00124               // check consistency - tbr
00125               G4String err_message =
00126                        "G3toG4BuildTree: Inconsistent mother <-> daughter !!";
00127               G4Exception("G3toG4BuildPVTree()", "G3toG40003",
00128                           FatalException, err_message);
00129               return;
00130             }
00131             mothLV = motherVTE->GetLV();
00132     
00133             // copy number
00134             // (in G3 numbering starts from 1 but in G4 from 0)
00135             G4int copyNo = theG3Pos->GetCopy() - 1;
00136       
00137             // position it if not top-level volume
00138 
00139             if (mothLV != 0) {
00140 
00141               // transformation
00142               G4int irot = theG3Pos->GetIrot();
00143               G4RotationMatrix* theMatrix = 0;
00144               if (irot>0) theMatrix = G3Rot.Get(irot);
00145               G4Rotate3D rotation;
00146               if (theMatrix) {            
00147                 rotation = G4Rotate3D(*theMatrix);
00148               }
00149 
00150               #ifndef G3G4_NO_REFLECTION
00151               G4Translate3D translation(*(theG3Pos->GetPos()));
00152               G4Transform3D transform3D = translation * (rotation.inverse());
00153 
00154               G4ReflectionFactory::Instance()
00155                 ->Place(transform3D,       // transformation
00156                         curVTE->GetName(), // PV name
00157                         curLog,            // its logical volume 
00158                         mothLV,            // mother logical volume
00159                         false,             // only
00160                         copyNo);           // copy
00161               #else
00162               new G4PVPlacement(theMatrix,            // rotation matrix
00163                               *(theG3Pos->GetPos()),  // its position
00164                               curLog,                 // its LogicalVolume 
00165                               curVTE->GetName(),      // PV name
00166                               mothLV,                 // Mother LV
00167                               0,                      // only
00168                               copyNo);                // copy
00169               #endif
00170 
00171               // verbose
00172               #ifdef G3G4DEBUG
00173                 G4cout << "PV: " << i << "th copy of " << curVTE->GetName()
00174                        << "  in " << motherVTE->GetName() << "  copyNo: " 
00175                        << copyNo << "  irot: " << irot << "  pos: " 
00176                        << *(theG3Pos->GetPos()) << G4endl;
00177               #endif
00178             }       
00179           }
00180         }
00181         // clear this position
00182         curVTE->ClearG3PosCopy(i);
00183         i--;
00184       }
00185     }
00186 
00187     // divisions     
00188     if (curVTE->GetDivision()) {
00189       curVTE->GetDivision()->CreatePVReplica();
00190       // verbose
00191       #ifdef G3G4DEBUG
00192         G4cout << "CreatePVReplica: " << curVTE->GetName() 
00193                << " in "  <<  curVTE->GetMother()->GetName() << G4endl;
00194       #endif
00195 
00196       // clear this divison
00197       curVTE->ClearDivision(); 
00198     }
00199   }
00200   
00201   // process daughters
00202   G4int Ndau = curVTE->GetNoDaughters();
00203   for (int Idau=0; Idau<Ndau; Idau++){
00204     G3toG4BuildPVTree(curVTE->GetDaughter(Idau));
00205   }
00206 }
00207 

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