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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/cuts/src/G4PhysicsTableHelper.cc (Version 11.3.0) and /processes/cuts/src/G4PhysicsTableHelper.cc (Version 10.7.p1)


  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 // G4PhysicsTableHelper class implementation 
 27 //                                                 27 //
 28 // Author: H.Kurashige, 20 August 2004 - First     28 // Author: H.Kurashige, 20 August 2004 - First implementation
 29 // -------------------------------------------     29 // --------------------------------------------------------------------
 30                                                    30 
 31 #include "G4PhysicsTableHelper.hh"                 31 #include "G4PhysicsTableHelper.hh" 
 32 #include "G4ProductionCutsTable.hh"            <<  32 #include  "G4ProductionCutsTable.hh"
 33 #include "G4MCCIndexConversionTable.hh"        << 
 34 #include "G4Threading.hh"                      << 
 35 #include "G4ios.hh"                            << 
 36                                                    33 
 37 G4int G4PhysicsTableHelper::verboseLevel = 1;  <<  34 G4ThreadLocal G4int G4PhysicsTableHelper::verboseLevel = 1; 
 38                                                    35 
 39 // -------------------------------------------     36 // --------------------------------------------------------------------
 40 G4PhysicsTableHelper::G4PhysicsTableHelper()       37 G4PhysicsTableHelper::G4PhysicsTableHelper()
 41 {                                                  38 {
 42 }                                                  39 }
 43                                                    40 
 44 // -------------------------------------------     41 // --------------------------------------------------------------------
 45 G4PhysicsTableHelper::~G4PhysicsTableHelper()      42 G4PhysicsTableHelper::~G4PhysicsTableHelper()
 46 {                                                  43 {
 47 }                                                  44 }
 48                                                    45 
 49 // -------------------------------------------     46 // --------------------------------------------------------------------
 50 G4PhysicsTable*                                    47 G4PhysicsTable*
 51 G4PhysicsTableHelper::PreparePhysicsTable(G4Ph     48 G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable)
 52 {                                                  49 {
 53   G4ProductionCutsTable* cutTable                  50   G4ProductionCutsTable* cutTable
 54     = G4ProductionCutsTable::GetProductionCuts     51     = G4ProductionCutsTable::GetProductionCutsTable();
 55   std::size_t numberOfMCC = cutTable->GetTable     52   std::size_t numberOfMCC = cutTable->GetTableSize(); 
 56                                                    53 
 57   if ( physTable != nullptr )                  <<  54   if ( physTable != nullptr)
 58   {                                                55   {
 59     // compare size of physics table and numbe     56     // compare size of physics table and number of material-cuts-couple
 60     if ( physTable->size() < numberOfMCC )     <<  57     if ( physTable->size() < numberOfMCC)
 61     {                                              58     {
                                                   >>  59       // enlarge physics table
                                                   >>  60       physTable->resize(numberOfMCC, nullptr);
 62 #ifdef G4VERBOSE                                   61 #ifdef G4VERBOSE  
 63       if (verboseLevel>2)                          62       if (verboseLevel>2)
 64       {                                            63       {
 65         G4cout << "G4PhysicsTableHelper::Prepa <<  64         G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable  ";
 66                << " the table " << physTable < <<  65         G4cerr << "Physics Table "<< physTable ;
 67          << physTable->size()                  <<  66         G4cerr << " is resized to " << numberOfMCC << G4endl;
 68                << " will be is resized to " << << 
 69       }                                            67       }
 70 #endif                                             68 #endif 
 71       // enlarge physics table                 << 
 72       physTable->resize(numberOfMCC, nullptr); << 
 73     }                                              69     }
 74     else if ( physTable->size() > numberOfMCC  <<  70     else if ( physTable->size() > numberOfMCC)
 75     {                                              71     {
 76       // ERROR: this situation should not occu     72       // ERROR: this situation should not occur  
 77       // size of physics table is larger than  <<  73       // size of physics table is shorter than number of material-cuts-couple
 78       G4ExceptionDescription ed;               <<  74       physTable->resize(numberOfMCC);
 79       ed << "table " << physTable << " size="  <<  75 #ifdef G4VERBOSE  
 80    << " is longer than number of material-cuts <<  76       if (verboseLevel>0)
                                                   >>  77       {
                                                   >>  78         G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable  ";
                                                   >>  79         G4cerr << "Physics Table "<< physTable ;
                                                   >>  80         G4cerr << " is longer than number of material-cuts-couple " << G4endl;
                                                   >>  81       }
                                                   >>  82 #endif 
 81       G4Exception( "G4PhysicsTableHelper::Prep     83       G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
 82                    "ProcCuts001", FatalExcepti <<  84                    "ProcCuts001", FatalException, 
                                                   >>  85                    "Physics Table is inconsistent with  material-cuts-couple");
 83     }                                              86     } 
 84   }                                                87   }
 85   else                                             88   else
 86   {                                                89   {
 87     // create PhysicsTable is given poitner is     90     // create PhysicsTable is given poitner is null
 88     physTable = new G4PhysicsTable();          <<  91     physTable = new G4PhysicsTable(numberOfMCC);
 89     physTable->resize(numberOfMCC, nullptr);   <<  92     if (physTable != nullptr)
                                                   >>  93     {
                                                   >>  94       physTable->resize(numberOfMCC, nullptr);
                                                   >>  95     }
                                                   >>  96     else
                                                   >>  97     {
                                                   >>  98       G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
                                                   >>  99                    "ProcCuts002", FatalException, 
                                                   >> 100                    "Can't create Physics Table");
                                                   >> 101     }
 90   }                                               102   }
 91                                                   103 
 92 #ifdef G4VERBOSE                                  104 #ifdef G4VERBOSE  
 93   if (verboseLevel>2)                             105   if (verboseLevel>2)
 94   {                                               106   {
 95     G4cout << "G4PhysicsTableHelper::PreparePh << 107     if ( physTable != nullptr)
 96      << " the table "<< physTable              << 108     { 
 97      << " size=" << numberOfMCC << G4endl;     << 109       G4cerr << "Physics Table size "<< physTable->size();
                                                   >> 110     }
                                                   >> 111     else
                                                   >> 112     {
                                                   >> 113       G4cerr << "Physics Table does not exist   ";
                                                   >> 114     }
                                                   >> 115     G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl;
 98   }                                               116   }
 99 #endif                                            117 #endif 
100                                                   118 
101   // Reset recal-needed flag for all physics v    119   // Reset recal-needed flag for all physics vectors
102   physTable->ResetFlagArray();                    120   physTable->ResetFlagArray();
103                                                   121 
104   for (std::size_t idx = 0; idx <numberOfMCC;     122   for (std::size_t idx = 0; idx <numberOfMCC; ++idx)
105   {                                               123   {
106     const G4MaterialCutsCouple* mcc = cutTable << 124     const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
107                                                   125 
108     // check if re-calculation of the physics     126     // check if re-calculation of the physics vector is needed 
109     // MCC is not used                            127     // MCC is not used
110     if ( !mcc->IsUsed() ) physTable->ClearFlag    128     if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
111                                                   129 
112     // RecalcNeeded flag of MCC is not asserte    130     // RecalcNeeded flag of MCC is not asserted 
113     if ( !mcc->IsRecalcNeeded() ) physTable->C    131     if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx);
114   }                                               132   }
115                                                   133   
116   return physTable;                               134   return physTable;
117 }                                                 135 }
118                                                   136 
119 // -------------------------------------------    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 == nullptr ) 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   {
130     G4ExceptionDescription ed;                 << 148 #ifdef G4VERBOSE  
131     ed << "Cannot retrieve physics table from  << 149     if (verboseLevel>1)
                                                   >> 150     {
                                                   >> 151       G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable  ";
                                                   >> 152       G4cerr << "Fail to retrieve from "<< fileName << G4endl;
                                                   >> 153     }
                                                   >> 154 #endif 
132     G4Exception( "G4ProductionCutsTable::Retri    155     G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()",
133                  "ProcCuts105", JustWarning, e << 156                  "ProcCuts105",
                                                   >> 157                  JustWarning, "Can not retrieve physics tables from file");
134     delete tempTable;                             158     delete tempTable;
135     return false;                                 159     return false;
136   }                                               160   } 
137                                                   161 
138   G4ProductionCutsTable* cutTable                 162   G4ProductionCutsTable* cutTable
139     = G4ProductionCutsTable::GetProductionCuts    163     = G4ProductionCutsTable::GetProductionCutsTable();  
140   const G4MCCIndexConversionTable* converter      164   const G4MCCIndexConversionTable* converter
141     = cutTable->GetMCCIndexConversionTable();     165     = cutTable->GetMCCIndexConversionTable();
142                                                   166 
143   // check physics table size                     167   // check physics table size
144   if ( tempTable->size() != converter->size())    168   if ( tempTable->size() != converter->size())
145   {                                               169   {
146     G4ExceptionDescription ed;                 << 170 #ifdef G4VERBOSE  
147     ed << "Physics table in " << fileName      << 171     if (verboseLevel>0)
148        << "\n   size=" << tempTable->size() << << 172     {
149        << " is inconsistent with material-cut- << 173       G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable  ";
150        << "size=" << converter->size() << " th << 174       G4cerr << "Size of the physics table in "<< fileName;
                                                   >> 175       G4cerr << "( size =" << tempTable->size() << ")";
                                                   >> 176       G4cerr << " is inconsistent with material-cut info";
                                                   >> 177       G4cerr << "( size =" << converter->size() << ")";
                                                   >> 178       G4cerr << G4endl;
                                                   >> 179     }
                                                   >> 180 #endif
151     G4Exception("G4ProductionCutsTable::Retrie    181     G4Exception("G4ProductionCutsTable::RetrievePhysicsTable()",
152                 "ProcCuts106", JustWarning, ed << 182                 "ProcCuts106", JustWarning,
                                                   >> 183                 "Retrieved file is inconsistent with current physics tables!");
153     delete tempTable;                             184     delete tempTable;
154     return false;                                 185     return false;
155   }                                               186   }
156                                                   187   
157   // fill the given physics table with retriev    188   // fill the given physics table with retrieved physics vectors 
158   for (std::size_t idx=0; idx<converter->size(    189   for (std::size_t idx=0; idx<converter->size(); ++idx)
159   {                                               190   {
160     if (converter->IsUsed(idx))                   191     if (converter->IsUsed(idx))
161     {                                             192     {
162       G4int i = converter->GetIndex(idx);      << 193       if (converter->GetIndex(idx)<0) continue;
163       if(i < 0)                                << 194       std::size_t i = converter->GetIndex(idx);
164       {                                        << 
165         tempTable->clearAndDestroy();          << 
166   delete tempTable;                            << 
167   return false;                                << 
168       }                                        << 
169       G4PhysicsVector* vec = (*physTable)[i];     195       G4PhysicsVector* vec = (*physTable)[i];
170       if (vec != nullptr ) delete vec;            196       if (vec != nullptr ) delete vec;
171       (*physTable)[i] = (*tempTable)[idx];        197       (*physTable)[i] = (*tempTable)[idx];
172       physTable->ClearFlag(i);                    198       physTable->ClearFlag(i);
173     }                                             199     }
174   }                                               200   }
175   tempTable->clear();                             201   tempTable->clear();
176   delete tempTable;                               202   delete tempTable;
177                                                   203 
178   return true;                                    204   return true;
179 }                                                 205 }
180                                                   206 
181 // -------------------------------------------    207 // --------------------------------------------------------------------
182 void G4PhysicsTableHelper::SetPhysicsVector(G4    208 void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
183                                             st    209                                             std::size_t idx,
184                                             G4    210                                             G4PhysicsVector* vec)
185 {                                                 211 {
186   if ( physTable == nullptr) {  return;  }        212   if ( physTable == nullptr) {  return;  }
187                                                   213 
188   if ( physTable->size() <= idx)                  214   if ( physTable->size() <= idx)
189   {                                               215   {
190     G4ExceptionDescription ed;                 << 216 #ifdef G4VERBOSE  
191     ed << "Given index (" << idx << ")  exceed << 217     if (verboseLevel>0)
192        << "the size of the physics table "     << 218     {
193        << "( size =" << physTable->size() << " << 219       G4cerr << "G4PhysicsTableHelper::SetPhysicsVector   ";
                                                   >> 220       G4cerr << "Given index (" << idx << ")  exceeds ";
                                                   >> 221       G4cerr << "size of the physics table ";
                                                   >> 222       G4cerr << "( size =" << physTable->size()<< ")";
                                                   >> 223       G4cerr << G4endl;
                                                   >> 224     }
                                                   >> 225 #endif
194     G4Exception("G4ProductionCutsTable::SetPhy    226     G4Exception("G4ProductionCutsTable::SetPhysicsVector()",
195                 "ProcCuts107",                    227                 "ProcCuts107",
196                 JustWarning, ed);              << 228                 JustWarning, "Illegal index!");
197     return;                                       229     return;
198   }                                               230   } 
199                                                   231 
200   // set physics vector                           232   // set physics vector 
201   (*physTable)[idx] = vec;                        233   (*physTable)[idx] = vec;
202   // clear flag                                   234   // clear flag
203   physTable->ClearFlag(idx);                      235   physTable->ClearFlag(idx);
204 }                                                 236 }
205                                                   237 
206 // -------------------------------------------    238 // --------------------------------------------------------------------
207 void G4PhysicsTableHelper::SetVerboseLevel(G4i << 239 void  G4PhysicsTableHelper::SetVerboseLevel(G4int value)
208 {                                                 240 {
209   if( !G4Threading::IsWorkerThread() ) verbose << 241   verboseLevel = value;
210 }                                                 242 }
211                                                   243 
212 // -------------------------------------------    244 // --------------------------------------------------------------------
213 G4int G4PhysicsTableHelper::GetVerboseLevel()     245 G4int G4PhysicsTableHelper::GetVerboseLevel()
214 {                                                 246 {
215   return verboseLevel;                            247   return verboseLevel;
216 }                                                 248 }
217                                                   249