G4PhysicsTableHelper.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 // $Id$
00027 //
00028 // 
00029 // ------------------------------------------------------------
00030 //      GEANT 4 class header file 
00031 //
00032 // Class Description
00033 //  G4PhysicsTableHelper is a static utility class 
00034 //  for helping proceeses to build their physics table
00035 //
00036 // ------------------------------------------------------------
00037 //   First Implementation          20 Aug. 2004   H.Kurashige
00038 //
00039 // ------------------------------------------------------------
00040 
00041 #include "G4PhysicsTableHelper.hh" 
00042 #include  "G4ProductionCutsTable.hh"
00043 
00044 G4int G4PhysicsTableHelper::verboseLevel = 1; 
00045 
00046 G4PhysicsTableHelper::G4PhysicsTableHelper()
00047 {
00048 }
00049 
00050 G4PhysicsTableHelper::~G4PhysicsTableHelper()
00051 {
00052 }
00053 
00054 G4PhysicsTableHelper::G4PhysicsTableHelper(const G4PhysicsTableHelper&)
00055 {
00056 }
00057 
00058 G4PhysicsTableHelper& G4PhysicsTableHelper::operator=(const G4PhysicsTableHelper&)
00059 {
00060   return *this;
00061 }
00062 
00063 
00064 G4PhysicsTable* G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable)
00065 {
00066   G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable();  
00067   size_t numberOfMCC = cutTable->GetTableSize(); 
00068 
00069   if ( physTable !=0) {
00070     // compare size of physics table and number of material-cuts-couple
00071     if ( physTable->size() < numberOfMCC) {
00072       // enlarge physcis table
00073       physTable->resize(numberOfMCC, (G4PhysicsVector*)(0));
00074 #ifdef G4VERBOSE  
00075       if (verboseLevel>2) {
00076         G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable  ";
00077         G4cerr << "Physics Table "<< physTable ;
00078         G4cerr << " is resized to " << numberOfMCC << G4endl;
00079       }
00080 #endif 
00081     } else if ( physTable->size() > numberOfMCC){
00082       // ERROR: this situation should not occur  
00083       //  size of physics table is shorter than  number of material-cuts-couple
00084       physTable->resize(numberOfMCC);
00085 #ifdef G4VERBOSE  
00086       if (verboseLevel>0) {
00087         G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable  ";
00088         G4cerr << "Physics Table "<< physTable ;
00089         G4cerr << " is longer than number of material-cuts-couple " << G4endl;
00090       }
00091 #endif 
00092       G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
00093                    "ProcCuts001", FatalException, 
00094                    "Physics Table is inconsistent with  material-cuts-couple");
00095     } 
00096   } else {
00097     // create PhysicsTable is given poitner is null
00098     physTable = new G4PhysicsTable(numberOfMCC);
00099     if (physTable!=0) {
00100       physTable->resize(numberOfMCC, (G4PhysicsVector*)(0));
00101     } else {
00102       G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
00103                    "ProcCuts002", FatalException, 
00104                    "Can't create Physics Table");
00105     }
00106   }
00107 
00108 #ifdef G4VERBOSE  
00109   if (verboseLevel>2) {
00110     if ( physTable !=0) { 
00111       G4cerr << "Physics Table size "<< physTable->size();
00112     } else {
00113       G4cerr << "Physics Table does not exist   ";
00114     }
00115     G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl;
00116   }
00117 #endif 
00118 
00119   // Reset recal-needed flag for all physics vectors
00120   physTable->ResetFlagArray();
00121 
00122   for (size_t idx = 0; idx <numberOfMCC; idx +=1){
00123     const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
00124     //check if re-calculation of the physics vector is needed 
00125     // MCC is not used
00126     if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
00127 
00128     // RecalcNeeded flag of MCC is not asserted 
00129     if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx);
00130   }
00131   
00132   return physTable;
00133 }
00134 
00135 
00136 
00137 G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable,
00138                                                   const G4String& fileName,
00139                                                   G4bool ascii              )
00140 {
00141   if (physTable == 0) return false;
00142   
00143   // retrieve physics table from the given file
00144   G4PhysicsTable* tempTable = new G4PhysicsTable();
00145   if (! tempTable->RetrievePhysicsTable(fileName,ascii) ){
00146 #ifdef G4VERBOSE  
00147     if (verboseLevel>1) {
00148       G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable  ";
00149       G4cerr << "Fail to retreive from "<< fileName << G4endl;
00150     }
00151 #endif 
00152     G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()",
00153                  "ProcCuts105",
00154                  JustWarning, "Can not retrieve physics tables from file");
00155     delete tempTable;
00156     return false;
00157   } 
00158 
00159   G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable();  
00160   const G4MCCIndexConversionTable* converter = cutTable->GetMCCIndexConversionTable();
00161 
00162   // check physics table size
00163   if ( tempTable->size() != converter->size()){
00164 #ifdef G4VERBOSE  
00165     if (verboseLevel>0) {
00166       G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable  ";
00167       G4cerr << "Size of the physics table in "<< fileName;
00168       G4cerr << "( size =" << tempTable->size() << ")";
00169       G4cerr << " is inconsistent with material-cut info";
00170       G4cerr << "( size =" << converter->size() << ")";
00171       G4cerr << G4endl;
00172     }
00173 #endif
00174     G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()",
00175                  "ProcCuts106",
00176                  JustWarning, "Retrived file is inconsistent with current physics tables ");
00177     delete tempTable;
00178     return false;
00179   }
00180   
00181   // fill the given physics table with retrived physics vectors 
00182   for (size_t idx=0; idx<converter->size(); idx++){
00183     if (converter->IsUsed(idx)){
00184       if (converter->GetIndex(idx)<0) continue;
00185       size_t i = converter->GetIndex(idx);
00186       G4PhysicsVector* vec = (*physTable)[i];
00187        if (vec !=0 ) delete vec;
00188       (*physTable)[i] =  (*tempTable)[idx];
00189       physTable->ClearFlag(i);
00190     }
00191   }
00192   tempTable->clear();
00193   delete tempTable;
00194 
00195   return true;
00196 }
00197 
00198 
00199 void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
00200                                             size_t idx,
00201                                             G4PhysicsVector* vec)
00202 {
00203   if ( physTable ==0) {  return;  }
00204 
00205   if ( physTable->size() <= idx) {
00206 #ifdef G4VERBOSE  
00207     if (verboseLevel>0) {
00208       G4cerr << "G4PhysicsTableHelper::SetPhysicsVector   ";
00209       G4cerr << "Given index (" << idx << ")  exceeds ";
00210       G4cerr << "size of the physics table ";
00211       G4cerr << "( size =" << physTable->size()<< ")";
00212       G4cerr << G4endl;
00213     }
00214 #endif
00215     G4Exception( "G4ProductionCutsTable::SetPhysicsVector()",
00216                  "ProcCuts107",
00217                  JustWarning, "Illegal index ");
00218     return;
00219   } 
00220 
00221   // set physics vector 
00222   (*physTable)[idx] = vec;
00223   // clear flag
00224   physTable->ClearFlag(idx);
00225  
00226 
00227 }
00228 
00229 
00230 
00231 

Generated on Mon May 27 17:49:19 2013 for Geant4 by  doxygen 1.4.7