source: trunk/source/processes/cuts/src/G4PhysicsTableHelper.cc @ 961

Last change on this file since 961 was 961, checked in by garnier, 15 years ago

update processes

File size: 6.6 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26// $Id: G4PhysicsTableHelper.cc,v 1.5 2006/06/29 19:30:12 gunter Exp $
27// GEANT4 tag $Name: geant4-09-02-ref-02 $
28//
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// ------------------------------------------------------------
41
42#include "G4PhysicsTableHelper.hh"
43#include  "G4ProductionCutsTable.hh"
44
45G4int G4PhysicsTableHelper::verboseLevel = 1; 
46
47G4PhysicsTableHelper::G4PhysicsTableHelper()
48{
49}
50
51G4PhysicsTableHelper::~G4PhysicsTableHelper()
52{
53}
54
55G4PhysicsTableHelper::G4PhysicsTableHelper(const G4PhysicsTableHelper&)
56{
57}
58
59G4PhysicsTableHelper& G4PhysicsTableHelper::operator=(const G4PhysicsTableHelper&)
60{
61  return *this;
62}
63
64
65G4PhysicsTable* G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable)
66{
67  G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable(); 
68  size_t numberOfMCC = cutTable->GetTableSize(); 
69
70  if ( physTable !=0) {
71    // compare size of physics table and number of material-cuts-couple
72    if ( physTable->size() < numberOfMCC) {
73      // enlarge physcis table
74      physTable->resize(numberOfMCC, (G4PhysicsVector*)(0));
75    } else if ( physTable->size() > numberOfMCC){
76      // ERROR: this situation should not occur 
77      //  size of physics table is shorter than  number of material-cuts-couple
78      physTable->resize(numberOfMCC);
79#ifdef G4VERBOSE 
80      if (verboseLevel>0) {
81        G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable  ";
82        G4cerr << "Physics Table "<< physTable ;
83        G4cerr << " is longer than number of material-cuts-couple " << G4endl;
84      }
85#endif
86    } 
87  } else {
88    // create PhysicsTable is given poitner is null
89    physTable = new G4PhysicsTable(numberOfMCC);
90    physTable->resize(numberOfMCC, (G4PhysicsVector*)(0));
91
92  }
93
94#ifdef G4VERBOSE 
95  if (verboseLevel>2) {
96    if ( physTable !=0) { 
97      G4cerr << "Physics Table size "<< physTable->size();
98    } else {
99      G4cerr << "Physics Table does not exist   ";
100    }
101    G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl;
102  }
103#endif
104
105  // Reset recal-needed flag for all physics vectors
106  physTable->ResetFlagArray();
107
108  for (size_t idx = 0; idx <numberOfMCC; idx +=1){
109    const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
110    //check if re-calculation of the physics vector is needed
111    // MCC is not used
112    if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
113
114    // RecalcNeeded flag of MCC is not asserted
115    if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx);
116  }
117 
118  return physTable;
119}
120
121
122
123G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable,
124                                                  const G4String& fileName,
125                                                  G4bool ascii              )
126{
127  if (physTable == 0) return false;
128 
129  // retrieve physics table from the given file
130  G4PhysicsTable* tempTable = new G4PhysicsTable();
131  if (! tempTable->RetrievePhysicsTable(fileName,ascii) ){
132#ifdef G4VERBOSE 
133    if (verboseLevel>1) {
134      G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable  ";
135      G4cerr << "Fail to retreive from "<< fileName << G4endl;
136    }
137#endif
138    return false;
139  } 
140
141  G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable(); 
142  const G4MCCIndexConversionTable* converter = cutTable->GetMCCIndexConversionTable();
143
144  // check physics table size
145  if ( tempTable->size() != converter->size()){
146#ifdef G4VERBOSE 
147    if (verboseLevel>0) {
148      G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable  ";
149      G4cerr << "Size of the physics table in "<< fileName;
150      G4cerr << "( size =" << tempTable->size() << ")";
151      G4cerr << " is inconsistent with material-cut info";
152      G4cerr << "( size =" << converter->size() << ")";
153      G4cerr << G4endl;
154    }
155#endif
156    return false;
157  }
158 
159  // fill the given physics table with retrived physics vectors
160  for (size_t idx=0; idx<converter->size(); idx++){
161    if (converter->IsUsed(idx)){
162      size_t i = converter->GetIndex(idx);
163      G4PhysicsVector* vec = (*physTable)[i];
164      if (vec !=0 ) delete vec;
165      (*physTable)[i] =  (*tempTable)[idx];
166      physTable->ClearFlag(i);
167    }
168  }
169  tempTable->clear();
170  delete tempTable;
171
172  return true;
173}
174
175
176void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
177                                            size_t idx,
178                                            G4PhysicsVector* vec)
179{
180  if ( physTable ==0) {  return;  }
181
182  if ( physTable->size() <= idx) {
183#ifdef G4VERBOSE 
184    if (verboseLevel>0) {
185      G4cerr << "G4PhysicsTableHelper::SetPhysicsVector   ";
186      G4cerr << "Given index (" << idx << ")  exceeds ";
187      G4cerr << "size of the physics table ";
188      G4cerr << "( size =" << physTable->size()<< ")";
189      G4cerr << G4endl;
190    }
191#endif
192    return;
193  } 
194
195  // set physics vector
196  (*physTable)[idx] = vec;
197  // clear flag
198  physTable->ClearFlag(idx);
199 
200
201}
202
203
204
205
Note: See TracBrowser for help on using the repository browser.