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 | // the GEANT4 collaboration. |
---|
27 | // |
---|
28 | // By copying, distributing or modifying the Program (or any work |
---|
29 | // based on the Program) you indicate your acceptance of this statement, |
---|
30 | // and all its terms. |
---|
31 | // |
---|
32 | // $Id: G4TextPPRetriever.cc,v 1.2 2006/06/29 19:28:04 gunter Exp $ |
---|
33 | // GEANT4 tag $Name: HEAD $ |
---|
34 | // |
---|
35 | // |
---|
36 | // --------------------------------------------------------------- |
---|
37 | #include "G4TextPPRetriever.hh" |
---|
38 | #include "G4ios.hh" |
---|
39 | #include "globals.hh" |
---|
40 | #include "G4DecayTable.hh" |
---|
41 | #include "G4Tokenizer.hh" |
---|
42 | #include <iomanip> |
---|
43 | #include <fstream> |
---|
44 | |
---|
45 | ////////////////////////////// |
---|
46 | G4TextPPRetriever::G4TextPPRetriever():G4VParticlePropertyRetriever() |
---|
47 | { |
---|
48 | } |
---|
49 | |
---|
50 | //////////////////////////// |
---|
51 | G4TextPPRetriever::~G4TextPPRetriever() |
---|
52 | { |
---|
53 | } |
---|
54 | |
---|
55 | ///////////////////// |
---|
56 | void G4TextPPRetriever::Retrieve(const G4String& option) |
---|
57 | { |
---|
58 | SparseOption( option ); |
---|
59 | |
---|
60 | // pointer to the particle table |
---|
61 | G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable(); |
---|
62 | G4ParticleTable::G4PTblDicIterator* theParticleIterator; |
---|
63 | theParticleIterator = theParticleTable->GetIterator(); |
---|
64 | |
---|
65 | // loop over all particles in G4ParticleTable |
---|
66 | theParticleIterator->reset(); |
---|
67 | while( (*theParticleIterator)() ){ |
---|
68 | G4ParticleDefinition* particle = theParticleIterator->value(); |
---|
69 | ModifyPropertyTable(particle); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | void G4TextPPRetriever::SparseOption(const G4String& option) |
---|
75 | { |
---|
76 | G4Tokenizer savedToken( option ); |
---|
77 | |
---|
78 | // 1st option : base directory |
---|
79 | baseDir = savedToken(); |
---|
80 | if (!baseDir.isNull()) { |
---|
81 | if(baseDir(baseDir.length()-1)!='/') { |
---|
82 | baseDir += "/"; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | G4bool G4TextPPRetriever::ModifyPropertyTable(G4ParticleDefinition* particle) |
---|
90 | { |
---|
91 | G4String name = particle->GetParticleName(); |
---|
92 | |
---|
93 | //--- open file ----- |
---|
94 | G4String fileName = baseDir + name + ".txt"; |
---|
95 | // exception |
---|
96 | if (name == "J/psi") fileName = baseDir +"jpsi.txt"; |
---|
97 | |
---|
98 | std::ifstream inFile(fileName, std::ios::in ); |
---|
99 | if (!inFile) return false; |
---|
100 | |
---|
101 | // GetParticleProperty |
---|
102 | G4ParticlePropertyData* pData = pPropertyTable->GetParticleProperty(name); |
---|
103 | |
---|
104 | // particle name encoding |
---|
105 | G4String name_t; |
---|
106 | G4int encoding; |
---|
107 | inFile >> name_t >> encoding; |
---|
108 | if ( (name != name_t) || (encoding != pData->GetPDGEncoding()) ){ |
---|
109 | G4cout << "G4TextPPRetriever::ModifyPropertyTable: "; |
---|
110 | G4cout << "particle name or encoding mismatch for " << name ; |
---|
111 | G4cout << G4endl; |
---|
112 | return false; |
---|
113 | } |
---|
114 | |
---|
115 | // IJPC |
---|
116 | G4int iIsoSpin, iSpin, iParity, iConj; |
---|
117 | inFile >> iIsoSpin >> iSpin >> iParity >> iConj; |
---|
118 | if ( ( iIsoSpin != pData->GetPDGiIsospin()) || |
---|
119 | ( iSpin != pData->GetPDGiSpin()) || |
---|
120 | ( iParity != pData->GetPDGiParity()) || |
---|
121 | ( iConj != pData->GetPDGiConjugation()) ){ |
---|
122 | G4cout << "G4TextPPRetriever::ModifyPropertyTable: "; |
---|
123 | G4cout << "IJPC mismatch for " << name ; |
---|
124 | G4cout << G4endl; |
---|
125 | return false; |
---|
126 | } |
---|
127 | |
---|
128 | // mass, width, charge |
---|
129 | G4double mass, width, charge; |
---|
130 | inFile >> mass >> width >> charge; |
---|
131 | mass *= GeV; |
---|
132 | width *= GeV; |
---|
133 | charge *= eplus; |
---|
134 | if (mass != pData->GetPDGMass()){ pData->SetPDGMass(mass);} |
---|
135 | if (width != pData->GetPDGWidth()){ pData->SetPDGWidth(width);} |
---|
136 | if (charge != pData->GetPDGCharge()){ pData->SetPDGCharge(charge);} |
---|
137 | |
---|
138 | // life time |
---|
139 | G4double tlife; |
---|
140 | inFile >> tlife; |
---|
141 | tlife *= second; |
---|
142 | if (tlife != pData->GetPDGLifeTime()){ pData->SetPDGLifeTime(tlife);} |
---|
143 | |
---|
144 | pPropertyTable->SetParticleProperty(*pData); |
---|
145 | |
---|
146 | // Decay Table |
---|
147 | G4DecayTable* dcyTable = particle->GetDecayTable(); |
---|
148 | if (dcyTable == 0) return true; |
---|
149 | |
---|
150 | G4int idx =0; |
---|
151 | while (!inFile.eof() ) { |
---|
152 | G4double br; |
---|
153 | G4int n_daughters; |
---|
154 | inFile >> br >> n_daughters; |
---|
155 | |
---|
156 | G4VDecayChannel * channel = dcyTable->GetDecayChannel(idx); |
---|
157 | |
---|
158 | if ( n_daughters == channel->GetNumberOfDaughters()) { |
---|
159 | channel->SetBR(br); |
---|
160 | } |
---|
161 | |
---|
162 | idx += 1; |
---|
163 | if (idx>= dcyTable->entries()) break; |
---|
164 | } |
---|
165 | return true; |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | |
---|