Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PhysicsTableHelper class implementation << 26 // $Id: G4PhysicsTableHelper.cc,v 1.8 2010-12-23 06:00:42 kurasige Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ 27 // 28 // 28 // Author: H.Kurashige, 20 August 2004 - First << 29 // 29 // ------------------------------------------- << 30 // ------------------------------------------------------------ >> 31 // GEANT 4 class header file >> 32 // >> 33 // Class Description >> 34 // G4PhysicsTableHelper is a static utility class >> 35 // for helping proceeses to build their physics table >> 36 // >> 37 // ------------------------------------------------------------ >> 38 // First Implementation 20 Aug. 2004 H.Kurashige >> 39 // >> 40 // ------------------------------------------------------------ 30 41 31 #include "G4PhysicsTableHelper.hh" 42 #include "G4PhysicsTableHelper.hh" 32 #include "G4ProductionCutsTable.hh" << 43 #include "G4ProductionCutsTable.hh" 33 #include "G4MCCIndexConversionTable.hh" << 34 #include "G4Threading.hh" << 35 #include "G4ios.hh" << 36 44 37 G4int G4PhysicsTableHelper::verboseLevel = 1; 45 G4int G4PhysicsTableHelper::verboseLevel = 1; 38 46 39 // ------------------------------------------- << 40 G4PhysicsTableHelper::G4PhysicsTableHelper() 47 G4PhysicsTableHelper::G4PhysicsTableHelper() 41 { 48 { 42 } 49 } 43 50 44 // ------------------------------------------- << 45 G4PhysicsTableHelper::~G4PhysicsTableHelper() 51 G4PhysicsTableHelper::~G4PhysicsTableHelper() 46 { 52 { 47 } 53 } 48 54 49 // ------------------------------------------- << 55 G4PhysicsTableHelper::G4PhysicsTableHelper(const G4PhysicsTableHelper&) 50 G4PhysicsTable* << 56 { 51 G4PhysicsTableHelper::PreparePhysicsTable(G4Ph << 57 } 52 { << 58 53 G4ProductionCutsTable* cutTable << 59 G4PhysicsTableHelper& G4PhysicsTableHelper::operator=(const G4PhysicsTableHelper&) 54 = G4ProductionCutsTable::GetProductionCuts << 60 { 55 std::size_t numberOfMCC = cutTable->GetTable << 61 return *this; >> 62 } 56 63 57 if ( physTable != nullptr ) << 64 58 { << 65 G4PhysicsTable* G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable) >> 66 { >> 67 G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable(); >> 68 size_t numberOfMCC = cutTable->GetTableSize(); >> 69 >> 70 if ( physTable !=0) { 59 // compare size of physics table and numbe 71 // compare size of physics table and number of material-cuts-couple 60 if ( physTable->size() < numberOfMCC ) << 72 if ( physTable->size() < numberOfMCC) { 61 { << 73 // enlarge physcis table >> 74 physTable->resize(numberOfMCC, (G4PhysicsVector*)(0)); 62 #ifdef G4VERBOSE 75 #ifdef G4VERBOSE 63 if (verboseLevel>2) << 76 if (verboseLevel>2) { 64 { << 77 G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable "; 65 G4cout << "G4PhysicsTableHelper::Prepa << 78 G4cerr << "Physics Table "<< physTable ; 66 << " the table " << physTable < << 79 G4cerr << " is resized to " << numberOfMCC << G4endl; 67 << physTable->size() << 68 << " will be is resized to " << << 69 } 80 } 70 #endif 81 #endif 71 // enlarge physics table << 82 } else if ( physTable->size() > numberOfMCC){ 72 physTable->resize(numberOfMCC, nullptr); << 73 } << 74 else if ( physTable->size() > numberOfMCC << 75 { << 76 // ERROR: this situation should not occu 83 // ERROR: this situation should not occur 77 // size of physics table is larger than << 84 // size of physics table is shorter than number of material-cuts-couple 78 G4ExceptionDescription ed; << 85 physTable->resize(numberOfMCC); 79 ed << "table " << physTable << " size=" << 86 #ifdef G4VERBOSE 80 << " is longer than number of material-cuts << 87 if (verboseLevel>0) { >> 88 G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable "; >> 89 G4cerr << "Physics Table "<< physTable ; >> 90 G4cerr << " is longer than number of material-cuts-couple " << G4endl; >> 91 } >> 92 #endif 81 G4Exception( "G4PhysicsTableHelper::Prep 93 G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()", 82 "ProcCuts001", FatalExcepti << 94 "ProcCuts001", FatalException, >> 95 "Physics Table is inconsistent with material-cuts-couple"); 83 } 96 } 84 } << 97 } else { 85 else << 86 { << 87 // create PhysicsTable is given poitner is 98 // create PhysicsTable is given poitner is null 88 physTable = new G4PhysicsTable(); << 99 physTable = new G4PhysicsTable(numberOfMCC); 89 physTable->resize(numberOfMCC, nullptr); << 100 if (physTable!=0) { >> 101 physTable->resize(numberOfMCC, (G4PhysicsVector*)(0)); >> 102 } else { >> 103 G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()", >> 104 "ProcCuts002", FatalException, >> 105 "Can't create Physics Table"); >> 106 } 90 } 107 } 91 108 92 #ifdef G4VERBOSE 109 #ifdef G4VERBOSE 93 if (verboseLevel>2) << 110 if (verboseLevel>2) { 94 { << 111 if ( physTable !=0) { 95 G4cout << "G4PhysicsTableHelper::PreparePh << 112 G4cerr << "Physics Table size "<< physTable->size(); 96 << " the table "<< physTable << 113 } else { 97 << " size=" << numberOfMCC << G4endl; << 114 G4cerr << "Physics Table does not exist "; >> 115 } >> 116 G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl; 98 } 117 } 99 #endif 118 #endif 100 119 101 // Reset recal-needed flag for all physics v 120 // Reset recal-needed flag for all physics vectors 102 physTable->ResetFlagArray(); 121 physTable->ResetFlagArray(); 103 122 104 for (std::size_t idx = 0; idx <numberOfMCC; << 123 for (size_t idx = 0; idx <numberOfMCC; idx +=1){ 105 { << 124 const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx); 106 const G4MaterialCutsCouple* mcc = cutTable << 125 //check if re-calculation of the physics vector is needed 107 << 108 // check if re-calculation of the physics << 109 // MCC is not used 126 // MCC is not used 110 if ( !mcc->IsUsed() ) physTable->ClearFlag 127 if ( !mcc->IsUsed() ) physTable->ClearFlag(idx); 111 128 112 // RecalcNeeded flag of MCC is not asserte 129 // RecalcNeeded flag of MCC is not asserted 113 if ( !mcc->IsRecalcNeeded() ) physTable->C 130 if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx); 114 } 131 } 115 132 116 return physTable; 133 return physTable; 117 } 134 } 118 135 119 // ------------------------------------------- << 136 >> 137 120 G4bool G4PhysicsTableHelper::RetrievePhysicsTa 138 G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable, 121 << 139 const G4String& fileName, 122 << 140 G4bool ascii ) 123 { 141 { 124 if (physTable == nullptr ) return false; << 142 if (physTable == 0) return false; 125 143 126 // retrieve physics table from the given fil 144 // retrieve physics table from the given file 127 G4PhysicsTable* tempTable = new G4PhysicsTab 145 G4PhysicsTable* tempTable = new G4PhysicsTable(); 128 if (! tempTable->RetrievePhysicsTable(fileNa << 146 if (! tempTable->RetrievePhysicsTable(fileName,ascii) ){ 129 { << 147 #ifdef G4VERBOSE 130 G4ExceptionDescription ed; << 148 if (verboseLevel>1) { 131 ed << "Cannot retrieve physics table from << 149 G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable "; >> 150 G4cerr << "Fail to retreive from "<< fileName << G4endl; >> 151 } >> 152 #endif 132 G4Exception( "G4ProductionCutsTable::Retri 153 G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()", 133 "ProcCuts105", JustWarning, e << 154 "ProcCuts105", >> 155 JustWarning, "Can not retrieve physics tables from file"); 134 delete tempTable; 156 delete tempTable; 135 return false; 157 return false; 136 } 158 } 137 159 138 G4ProductionCutsTable* cutTable << 160 G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable(); 139 = G4ProductionCutsTable::GetProductionCuts << 161 const G4MCCIndexConversionTable* converter = cutTable->GetMCCIndexConversionTable(); 140 const G4MCCIndexConversionTable* converter << 141 = cutTable->GetMCCIndexConversionTable(); << 142 162 143 // check physics table size 163 // check physics table size 144 if ( tempTable->size() != converter->size()) << 164 if ( tempTable->size() != converter->size()){ 145 { << 165 #ifdef G4VERBOSE 146 G4ExceptionDescription ed; << 166 if (verboseLevel>0) { 147 ed << "Physics table in " << fileName << 167 G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable "; 148 << "\n size=" << tempTable->size() << << 168 G4cerr << "Size of the physics table in "<< fileName; 149 << " is inconsistent with material-cut- << 169 G4cerr << "( size =" << tempTable->size() << ")"; 150 << "size=" << converter->size() << " th << 170 G4cerr << " is inconsistent with material-cut info"; 151 G4Exception("G4ProductionCutsTable::Retrie << 171 G4cerr << "( size =" << converter->size() << ")"; 152 "ProcCuts106", JustWarning, ed << 172 G4cerr << G4endl; >> 173 } >> 174 #endif >> 175 G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()", >> 176 "ProcCuts106", >> 177 JustWarning, "Retrived file is inconsistent with current physics tables "); 153 delete tempTable; 178 delete tempTable; 154 return false; 179 return false; 155 } 180 } 156 181 157 // fill the given physics table with retriev << 182 // fill the given physics table with retrived physics vectors 158 for (std::size_t idx=0; idx<converter->size( << 183 for (size_t idx=0; idx<converter->size(); idx++){ 159 { << 184 if (converter->IsUsed(idx)){ 160 if (converter->IsUsed(idx)) << 185 if (converter->GetIndex(idx)<0) continue; 161 { << 186 size_t i = converter->GetIndex(idx); 162 G4int i = converter->GetIndex(idx); << 163 if(i < 0) << 164 { << 165 tempTable->clearAndDestroy(); << 166 delete tempTable; << 167 return false; << 168 } << 169 G4PhysicsVector* vec = (*physTable)[i]; 187 G4PhysicsVector* vec = (*physTable)[i]; 170 if (vec != nullptr ) delete vec; << 188 if (vec !=0 ) delete vec; 171 (*physTable)[i] = (*tempTable)[idx]; << 189 (*physTable)[i] = (*tempTable)[idx]; 172 physTable->ClearFlag(i); 190 physTable->ClearFlag(i); 173 } 191 } 174 } 192 } 175 tempTable->clear(); 193 tempTable->clear(); 176 delete tempTable; 194 delete tempTable; 177 195 178 return true; 196 return true; 179 } 197 } 180 198 181 // ------------------------------------------- << 199 182 void G4PhysicsTableHelper::SetPhysicsVector(G4 200 void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable, 183 st << 201 size_t idx, 184 G4 << 202 G4PhysicsVector* vec) 185 { 203 { 186 if ( physTable == nullptr) { return; } << 204 if ( physTable ==0) { return; } 187 205 188 if ( physTable->size() <= idx) << 206 if ( physTable->size() <= idx) { 189 { << 207 #ifdef G4VERBOSE 190 G4ExceptionDescription ed; << 208 if (verboseLevel>0) { 191 ed << "Given index (" << idx << ") exceed << 209 G4cerr << "G4PhysicsTableHelper::SetPhysicsVector "; 192 << "the size of the physics table " << 210 G4cerr << "Given index (" << idx << ") exceeds "; 193 << "( size =" << physTable->size() << " << 211 G4cerr << "size of the physics table "; 194 G4Exception("G4ProductionCutsTable::SetPhy << 212 G4cerr << "( size =" << physTable->size()<< ")"; 195 "ProcCuts107", << 213 G4cerr << G4endl; 196 JustWarning, ed); << 214 } >> 215 #endif >> 216 G4Exception( "G4ProductionCutsTable::SetPhysicsVector()", >> 217 "ProcCuts107", >> 218 JustWarning, "Illegal index "); 197 return; 219 return; 198 } 220 } 199 221 200 // set physics vector 222 // set physics vector 201 (*physTable)[idx] = vec; 223 (*physTable)[idx] = vec; 202 // clear flag 224 // clear flag 203 physTable->ClearFlag(idx); 225 physTable->ClearFlag(idx); 204 } << 226 205 227 206 // ------------------------------------------- << 207 void G4PhysicsTableHelper::SetVerboseLevel(G4i << 208 { << 209 if( !G4Threading::IsWorkerThread() ) verbose << 210 } 228 } 211 229 212 // ------------------------------------------- << 230 213 G4int G4PhysicsTableHelper::GetVerboseLevel() << 231 214 { << 232 215 return verboseLevel; << 216 } << 217 233