00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // the GEANT4 collaboration. 00027 // 00028 // By copying, distributing or modifying the Program (or any work 00029 // based on the Program) you indicate your acceptance of this statement, 00030 // and all its terms. 00031 // 00032 // $Id$ 00033 // 00034 // 00035 // --------------------------------------------------------------- 00036 #include "G4TextPPRetriever.hh" 00037 #include "G4ios.hh" 00038 #include "globals.hh" 00039 #include "G4SystemOfUnits.hh" 00040 #include "G4ParticleTable.hh" 00041 #include "G4ParticleDefinition.hh" 00042 #include "G4DecayTable.hh" 00043 #include "G4VDecayChannel.hh" 00044 #include "G4Tokenizer.hh" 00045 #include <iomanip> 00046 #include <fstream> 00047 00049 G4TextPPRetriever::G4TextPPRetriever():G4VParticlePropertyRetriever() 00050 { 00051 } 00052 00054 G4TextPPRetriever::~G4TextPPRetriever() 00055 { 00056 } 00057 00059 void G4TextPPRetriever::Retrieve(const G4String& option) 00060 { 00061 SparseOption( option ); 00062 00063 // pointer to the particle table 00064 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable(); 00065 G4ParticleTable::G4PTblDicIterator* theParticleIterator; 00066 theParticleIterator = theParticleTable->GetIterator(); 00067 00068 // loop over all particles in G4ParticleTable 00069 theParticleIterator->reset(); 00070 while( (*theParticleIterator)() ){ 00071 G4ParticleDefinition* particle = theParticleIterator->value(); 00072 ModifyPropertyTable(particle); 00073 } 00074 } 00075 00076 00077 void G4TextPPRetriever::SparseOption(const G4String& option) 00078 { 00079 G4Tokenizer savedToken( option ); 00080 00081 // 1st option : base directory 00082 baseDir = savedToken(); 00083 if (!baseDir.isNull()) { 00084 if(baseDir(baseDir.length()-1)!='/') { 00085 baseDir += "/"; 00086 } 00087 } 00088 } 00089 00090 00091 00092 G4bool G4TextPPRetriever::ModifyPropertyTable(const G4ParticleDefinition* particle) 00093 { 00094 G4String name = particle->GetParticleName(); 00095 00096 //--- open file ----- 00097 G4String fileName = baseDir + name + ".txt"; 00098 // exception 00099 if (name == "J/psi") fileName = baseDir +"jpsi.txt"; 00100 00101 std::ifstream inFile(fileName, std::ios::in ); 00102 if (!inFile) return false; 00103 00104 // GetParticleProperty 00105 G4ParticlePropertyData* pData = pPropertyTable->GetParticleProperty(name); 00106 00107 // particle name encoding 00108 G4String name_t; 00109 G4int encoding; 00110 inFile >> name_t >> encoding; 00111 if ( (name != name_t) || (encoding != pData->GetPDGEncoding()) ){ 00112 G4cout << "G4TextPPRetriever::ModifyPropertyTable: "; 00113 G4cout << "particle name or encoding mismatch for " << name ; 00114 G4cout << G4endl; 00115 return false; 00116 } 00117 00118 // IJPC 00119 G4int iIsoSpin, iSpin, iParity, iConj; 00120 inFile >> iIsoSpin >> iSpin >> iParity >> iConj; 00121 if ( ( iIsoSpin != pData->GetPDGiIsospin()) || 00122 ( iSpin != pData->GetPDGiSpin()) || 00123 ( iParity != pData->GetPDGiParity()) || 00124 ( iConj != pData->GetPDGiConjugation()) ){ 00125 G4cout << "G4TextPPRetriever::ModifyPropertyTable: "; 00126 G4cout << "IJPC mismatch for " << name ; 00127 G4cout << G4endl; 00128 return false; 00129 } 00130 00131 // mass, width, charge 00132 G4double mass, width, charge; 00133 inFile >> mass >> width >> charge; 00134 mass *= GeV; 00135 width *= GeV; 00136 charge *= eplus; 00137 if (mass != pData->GetPDGMass()){ pData->SetPDGMass(mass);} 00138 if (width != pData->GetPDGWidth()){ pData->SetPDGWidth(width);} 00139 if (charge != pData->GetPDGCharge()){ pData->SetPDGCharge(charge);} 00140 00141 // life time 00142 G4double tlife; 00143 inFile >> tlife; 00144 tlife *= second; 00145 if (tlife != pData->GetPDGLifeTime()){ pData->SetPDGLifeTime(tlife);} 00146 00147 pPropertyTable->SetParticleProperty(*pData); 00148 00149 // Decay Table 00150 G4DecayTable* dcyTable = particle->GetDecayTable(); 00151 if (dcyTable == 0) return true; 00152 00153 G4int idx =0; 00154 while (!inFile.eof() ) { 00155 G4double br; 00156 G4int n_daughters; 00157 inFile >> br >> n_daughters; 00158 00159 G4VDecayChannel * channel = dcyTable->GetDecayChannel(idx); 00160 00161 if ( n_daughters == channel->GetNumberOfDaughters()) { 00162 channel->SetBR(br); 00163 } 00164 00165 idx += 1; 00166 if (idx>= dcyTable->entries()) break; 00167 } 00168 return true; 00169 } 00170 00171 00172 00173 00174