00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00071 if ( physTable->size() < numberOfMCC) {
00072
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
00083
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
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
00120 physTable->ResetFlagArray();
00121
00122 for (size_t idx = 0; idx <numberOfMCC; idx +=1){
00123 const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
00124
00125
00126 if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
00127
00128
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
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
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
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
00222 (*physTable)[idx] = vec;
00223
00224 physTable->ClearFlag(idx);
00225
00226
00227 }
00228
00229
00230
00231