| 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.6 2009/08/01 07:57:13 kurasige Exp $
|
|---|
| 27 | // GEANT4 tag $Name: geant4-09-03-cand-01 $
|
|---|
| 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 |
|
|---|
| 45 | G4int G4PhysicsTableHelper::verboseLevel = 1;
|
|---|
| 46 |
|
|---|
| 47 | G4PhysicsTableHelper::G4PhysicsTableHelper()
|
|---|
| 48 | {
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | G4PhysicsTableHelper::~G4PhysicsTableHelper()
|
|---|
| 52 | {
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | G4PhysicsTableHelper::G4PhysicsTableHelper(const G4PhysicsTableHelper&)
|
|---|
| 56 | {
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | G4PhysicsTableHelper& G4PhysicsTableHelper::operator=(const G4PhysicsTableHelper&)
|
|---|
| 60 | {
|
|---|
| 61 | return *this;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | G4PhysicsTable* 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 | #ifdef G4VERBOSE
|
|---|
| 76 | if (verboseLevel>2) {
|
|---|
| 77 | G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
|
|---|
| 78 | G4cerr << "Physics Table "<< physTable ;
|
|---|
| 79 | G4cerr << " is resized to " << numberOfMCC << G4endl;
|
|---|
| 80 | }
|
|---|
| 81 | #endif
|
|---|
| 82 | } else if ( physTable->size() > numberOfMCC){
|
|---|
| 83 | // ERROR: this situation should not occur
|
|---|
| 84 | // size of physics table is shorter than number of material-cuts-couple
|
|---|
| 85 | physTable->resize(numberOfMCC);
|
|---|
| 86 | #ifdef G4VERBOSE
|
|---|
| 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
|
|---|
| 93 | }
|
|---|
| 94 | } else {
|
|---|
| 95 | // create PhysicsTable is given poitner is null
|
|---|
| 96 | physTable = new G4PhysicsTable(numberOfMCC);
|
|---|
| 97 | physTable->resize(numberOfMCC, (G4PhysicsVector*)(0));
|
|---|
| 98 |
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | #ifdef G4VERBOSE
|
|---|
| 102 | if (verboseLevel>2) {
|
|---|
| 103 | if ( physTable !=0) {
|
|---|
| 104 | G4cerr << "Physics Table size "<< physTable->size();
|
|---|
| 105 | } else {
|
|---|
| 106 | G4cerr << "Physics Table does not exist ";
|
|---|
| 107 | }
|
|---|
| 108 | G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl;
|
|---|
| 109 | }
|
|---|
| 110 | #endif
|
|---|
| 111 |
|
|---|
| 112 | // Reset recal-needed flag for all physics vectors
|
|---|
| 113 | physTable->ResetFlagArray();
|
|---|
| 114 |
|
|---|
| 115 | for (size_t idx = 0; idx <numberOfMCC; idx +=1){
|
|---|
| 116 | const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
|
|---|
| 117 | //check if re-calculation of the physics vector is needed
|
|---|
| 118 | // MCC is not used
|
|---|
| 119 | if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
|
|---|
| 120 |
|
|---|
| 121 | // RecalcNeeded flag of MCC is not asserted
|
|---|
| 122 | if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | return physTable;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable,
|
|---|
| 131 | const G4String& fileName,
|
|---|
| 132 | G4bool ascii )
|
|---|
| 133 | {
|
|---|
| 134 | if (physTable == 0) return false;
|
|---|
| 135 |
|
|---|
| 136 | // retrieve physics table from the given file
|
|---|
| 137 | G4PhysicsTable* tempTable = new G4PhysicsTable();
|
|---|
| 138 | if (! tempTable->RetrievePhysicsTable(fileName,ascii) ){
|
|---|
| 139 | #ifdef G4VERBOSE
|
|---|
| 140 | if (verboseLevel>1) {
|
|---|
| 141 | G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable ";
|
|---|
| 142 | G4cerr << "Fail to retreive from "<< fileName << G4endl;
|
|---|
| 143 | }
|
|---|
| 144 | #endif
|
|---|
| 145 | return false;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable();
|
|---|
| 149 | const G4MCCIndexConversionTable* converter = cutTable->GetMCCIndexConversionTable();
|
|---|
| 150 |
|
|---|
| 151 | // check physics table size
|
|---|
| 152 | if ( tempTable->size() != converter->size()){
|
|---|
| 153 | #ifdef G4VERBOSE
|
|---|
| 154 | if (verboseLevel>0) {
|
|---|
| 155 | G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable ";
|
|---|
| 156 | G4cerr << "Size of the physics table in "<< fileName;
|
|---|
| 157 | G4cerr << "( size =" << tempTable->size() << ")";
|
|---|
| 158 | G4cerr << " is inconsistent with material-cut info";
|
|---|
| 159 | G4cerr << "( size =" << converter->size() << ")";
|
|---|
| 160 | G4cerr << G4endl;
|
|---|
| 161 | }
|
|---|
| 162 | #endif
|
|---|
| 163 | return false;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // fill the given physics table with retrived physics vectors
|
|---|
| 167 | for (size_t idx=0; idx<converter->size(); idx++){
|
|---|
| 168 | if (converter->IsUsed(idx)){
|
|---|
| 169 | size_t i = converter->GetIndex(idx);
|
|---|
| 170 | G4PhysicsVector* vec = (*physTable)[i];
|
|---|
| 171 | if (vec !=0 ) delete vec;
|
|---|
| 172 | (*physTable)[i] = (*tempTable)[idx];
|
|---|
| 173 | physTable->ClearFlag(i);
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 | tempTable->clear();
|
|---|
| 177 | delete tempTable;
|
|---|
| 178 |
|
|---|
| 179 | return true;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 | void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
|
|---|
| 184 | size_t idx,
|
|---|
| 185 | G4PhysicsVector* vec)
|
|---|
| 186 | {
|
|---|
| 187 | if ( physTable ==0) { return; }
|
|---|
| 188 |
|
|---|
| 189 | if ( physTable->size() <= idx) {
|
|---|
| 190 | #ifdef G4VERBOSE
|
|---|
| 191 | if (verboseLevel>0) {
|
|---|
| 192 | G4cerr << "G4PhysicsTableHelper::SetPhysicsVector ";
|
|---|
| 193 | G4cerr << "Given index (" << idx << ") exceeds ";
|
|---|
| 194 | G4cerr << "size of the physics table ";
|
|---|
| 195 | G4cerr << "( size =" << physTable->size()<< ")";
|
|---|
| 196 | G4cerr << G4endl;
|
|---|
| 197 | }
|
|---|
| 198 | #endif
|
|---|
| 199 | return;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | // set physics vector
|
|---|
| 203 | (*physTable)[idx] = vec;
|
|---|
| 204 | // clear flag
|
|---|
| 205 | physTable->ClearFlag(idx);
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|