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: G4HtmlPPReporter.cc,v 1.5 2007/03/11 07:17:35 kurasige Exp $ |
---|
33 | // GEANT4 tag $Name: $ |
---|
34 | // |
---|
35 | // |
---|
36 | // --------------------------------------------------------------- |
---|
37 | #include "G4HtmlPPReporter.hh" |
---|
38 | #include "G4ios.hh" |
---|
39 | #include "globals.hh" |
---|
40 | #include "G4DecayTable.hh" |
---|
41 | #include "G4Tokenizer.hh" |
---|
42 | #include <iomanip> |
---|
43 | |
---|
44 | G4HtmlPPReporter::G4HtmlPPReporter():G4VParticlePropertyReporter() |
---|
45 | { |
---|
46 | |
---|
47 | } |
---|
48 | |
---|
49 | G4HtmlPPReporter::~G4HtmlPPReporter() |
---|
50 | { |
---|
51 | } |
---|
52 | |
---|
53 | void G4HtmlPPReporter::Print(const G4String& option) |
---|
54 | { |
---|
55 | SparseOption( option ); |
---|
56 | |
---|
57 | GenerateIndex(); |
---|
58 | |
---|
59 | for (size_t i=0; i< pList.size(); i++){ |
---|
60 | G4ParticleDefinition* particle = G4ParticleTable::GetParticleTable()->FindParticle( pList[i]->GetParticleName() ); |
---|
61 | GeneratePropertyTable(particle); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | void G4HtmlPPReporter::SparseOption(const G4String& option) |
---|
67 | { |
---|
68 | G4Tokenizer savedToken( option ); |
---|
69 | |
---|
70 | // 1st option : base directory |
---|
71 | baseDir = savedToken(); |
---|
72 | if (!baseDir.isNull()) { |
---|
73 | if(baseDir(baseDir.length()-1)!='/') { |
---|
74 | baseDir += "/"; |
---|
75 | } |
---|
76 | } |
---|
77 | comment = savedToken(); |
---|
78 | } |
---|
79 | |
---|
80 | void G4HtmlPPReporter::GenerateIndex() |
---|
81 | { |
---|
82 | //--- open index file ----- |
---|
83 | G4String fileName = baseDir + "index.html"; |
---|
84 | std::ofstream outFile(fileName, std::ios::out ); |
---|
85 | outFile.setf( std::ios:: scientific, std::ios::floatfield ); |
---|
86 | |
---|
87 | // header |
---|
88 | PrintHeader(outFile); |
---|
89 | |
---|
90 | // comment |
---|
91 | outFile << "<! -- " << comment << " --!> " << G4endl; |
---|
92 | outFile << G4endl; |
---|
93 | |
---|
94 | |
---|
95 | outFile << sTABLE << '"' << "80%" << '"' << " > " << G4endl; |
---|
96 | |
---|
97 | // Raw #1 |
---|
98 | outFile << sTR; |
---|
99 | outFile << sTD << sLFONT << "Code" << eLFONT<< eTD; |
---|
100 | outFile << sTD << sLFONT << "Name" << eLFONT<< eTD; |
---|
101 | outFile << sTD << sLFONT << "Anti-Particle" << eLFONT<< eTD; |
---|
102 | outFile << eTR << G4endl;; |
---|
103 | |
---|
104 | for (size_t i=0; i< pList.size(); i++){ |
---|
105 | if (pList[i]->GetPDGEncoding()<0) continue; |
---|
106 | |
---|
107 | outFile << sTR << G4endl;; |
---|
108 | // column 1 : endcoding |
---|
109 | outFile << sTD << pList[i]->GetPDGEncoding() << eTD << G4endl;; |
---|
110 | // column 2 : name |
---|
111 | G4String name = pList[i]->GetParticleName(); |
---|
112 | |
---|
113 | G4String fname = name +".html"; |
---|
114 | // exception |
---|
115 | if (name == "J/psi") fname = "jpsi.html"; |
---|
116 | |
---|
117 | outFile << sTD; |
---|
118 | outFile << "<A HREF=" << '"' << fname << '"' << ">"; |
---|
119 | outFile << name << "</A>" << eTD << G4endl; |
---|
120 | |
---|
121 | // column 3 AntiParticle |
---|
122 | if ( (pList[i]->GetAntiPDGEncoding()!= 0) && |
---|
123 | (pList[i]->GetAntiPDGEncoding() != pList[i]->GetPDGEncoding() ) ) { |
---|
124 | G4ParticleDefinition* anti_particle = G4ParticleTable::GetParticleTable()->FindParticle( pList[i]->GetAntiPDGEncoding() ); |
---|
125 | |
---|
126 | outFile << sTD << anti_particle->GetParticleName() << eTD << G4endl;; |
---|
127 | } |
---|
128 | outFile << eTR << G4endl;; |
---|
129 | } |
---|
130 | |
---|
131 | outFile << eTABLE << G4endl; |
---|
132 | |
---|
133 | // footer |
---|
134 | PrintFooter(outFile); |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | void G4HtmlPPReporter::GeneratePropertyTable(G4ParticleDefinition* particle) |
---|
139 | { |
---|
140 | if (particle->GetPDGEncoding()<0) return; |
---|
141 | |
---|
142 | G4String name = particle->GetParticleName(); |
---|
143 | //--- open index file ----- |
---|
144 | G4String fileName = baseDir + name + ".html"; |
---|
145 | // exception |
---|
146 | if (name == "J/psi") fileName = baseDir +"jpsi.html"; |
---|
147 | std::ofstream outFile(fileName, std::ios::out ); |
---|
148 | outFile.setf( std::ios:: scientific, std::ios::floatfield ); |
---|
149 | outFile << std::setprecision(7) << G4endl; |
---|
150 | |
---|
151 | PrintHeader(outFile); |
---|
152 | |
---|
153 | // particle name |
---|
154 | outFile << "<H2>" << name << "</H2>" << G4endl; |
---|
155 | outFile << "<HR>" << G4endl; |
---|
156 | |
---|
157 | // encoding, type |
---|
158 | outFile << sTABLE << '"' << "40%" << '"' << " > " << G4endl; |
---|
159 | outFile << sTR << sTD << sB << "PDG encoding" << eB << eTD; |
---|
160 | outFile << sTD << particle->GetPDGEncoding() << eTD << eTR << G4endl; |
---|
161 | outFile << sTR << sTD << sB << "Type" << eB << eTD; |
---|
162 | outFile << sTD << particle->GetParticleType() << eTD << eTR << G4endl; |
---|
163 | outFile << eTABLE << G4endl; |
---|
164 | outFile << "<HR>" << G4endl; |
---|
165 | |
---|
166 | // Properties |
---|
167 | outFile << sTABLE << '"' << "60%" << '"' << " > " << G4endl; |
---|
168 | // mass |
---|
169 | outFile << sTR << sTD << sB << "Mass" << eB << eTD; |
---|
170 | outFile << sTD << particle->GetPDGMass()/GeV; |
---|
171 | outFile << " [GeV/c" << sSUP << "2" << eSUP << "]" << eTD << eTR << G4endl; |
---|
172 | // width |
---|
173 | outFile << sTR << sTD << sB << "Width" << eB << eTD; |
---|
174 | outFile << sTD << particle->GetPDGWidth()/GeV; |
---|
175 | outFile << " [GeV/c" << sSUP << "2" << eSUP << "]" << eTD << eTR << G4endl; |
---|
176 | // IJPC |
---|
177 | outFile << sTR << sTD << sB << "I J" << sSUP << "PC"<< eSUP << eB << eTD; |
---|
178 | if ( particle->GetPDGiIsospin() <0 ) { |
---|
179 | outFile << sTD << " "; |
---|
180 | } else if ( particle->GetPDGiIsospin() == 1) { |
---|
181 | outFile << sTD << "1/2 "; |
---|
182 | } else if ( particle->GetPDGiIsospin() == 3) { |
---|
183 | outFile << sTD << "3/2 "; |
---|
184 | } else { |
---|
185 | outFile << sTD << particle->GetPDGiIsospin()/2 << " "; |
---|
186 | } |
---|
187 | if ( particle->GetPDGiSpin() == 1) { |
---|
188 | outFile << "1/2"; |
---|
189 | } else if ( particle->GetPDGiSpin() == 3) { |
---|
190 | outFile << "3/2"; |
---|
191 | } else if ( particle->GetPDGiSpin() == 5) { |
---|
192 | outFile << "5/2"; |
---|
193 | } else if ( particle->GetPDGiSpin() == 7) { |
---|
194 | outFile << "7/2"; |
---|
195 | } else if ( particle->GetPDGiSpin() == 9) { |
---|
196 | outFile << "9/2"; |
---|
197 | } else if ( particle->GetPDGiSpin() == 11) { |
---|
198 | outFile << "11/2"; |
---|
199 | } else if ( particle->GetPDGiSpin() == 13) { |
---|
200 | outFile << "13/2"; |
---|
201 | } else { |
---|
202 | outFile << particle->GetPDGiSpin()/2; |
---|
203 | } |
---|
204 | outFile << sSUP << sSYMBOL; |
---|
205 | if (particle->GetPDGiParity() == +1 ){ |
---|
206 | outFile << "+"; |
---|
207 | } else if (particle->GetPDGiParity() == -1 ){ |
---|
208 | outFile << "-"; |
---|
209 | } else { |
---|
210 | outFile << " "; |
---|
211 | } |
---|
212 | if (particle->GetPDGiConjugation() == +1 ){ |
---|
213 | outFile << "+"; |
---|
214 | } else if (particle->GetPDGiConjugation() == -1 ){ |
---|
215 | outFile << "-"; |
---|
216 | } else { |
---|
217 | outFile << " "; |
---|
218 | } |
---|
219 | outFile << eSYMBOL << eSUP; |
---|
220 | outFile << eTD << eTR << G4endl; |
---|
221 | // charge |
---|
222 | outFile << sTR << sTD << sB << "Charge" << eB << eTD; |
---|
223 | outFile << sTD << particle->GetPDGCharge()/eplus; |
---|
224 | outFile << eTD << eTR << G4endl; |
---|
225 | // Magnetic Moment |
---|
226 | outFile << sTR << sTD << sB << "Magnetic Moment" << eB << eTD; |
---|
227 | if (particle->GetPDGMagneticMoment() != 0.0){ |
---|
228 | outFile << sTD << particle->GetPDGMagneticMoment()/MeV*tesla; |
---|
229 | outFile << "[MeV/T]" << eTD << eTR << G4endl; |
---|
230 | } else { |
---|
231 | outFile << sTD << " not defined "; |
---|
232 | outFile << eTD << eTR << G4endl; |
---|
233 | } |
---|
234 | // life time |
---|
235 | outFile << sTR << sTD << sB << "Life Time" << eB << eTD; |
---|
236 | if ( particle->GetPDGLifeTime() >0.0 ) { |
---|
237 | outFile << sTD << particle->GetPDGLifeTime()/second; |
---|
238 | outFile << "[sec]" << eTD << G4endl; |
---|
239 | } else { |
---|
240 | if (particle->GetPDGStable()) { |
---|
241 | outFile << sTD << "stable" << eTD; |
---|
242 | } else if (particle->IsShortLived()) { |
---|
243 | outFile << sTD << "short-lived" << eTD; |
---|
244 | } else { |
---|
245 | outFile << sTD << "not Defined" << eTD; |
---|
246 | } |
---|
247 | } |
---|
248 | outFile << eTR << G4endl; |
---|
249 | |
---|
250 | outFile << eTABLE << G4endl; |
---|
251 | outFile << "<HR>" << G4endl; |
---|
252 | |
---|
253 | // Qurak content |
---|
254 | outFile << "<H2>" << " Quark Content " << "</H2>" << G4endl; |
---|
255 | |
---|
256 | outFile << sTABLE << '"' << "60%" << '"' << " > " << G4endl; |
---|
257 | |
---|
258 | outFile << sTR; |
---|
259 | outFile << sTD << sB << "flavour " << eB << eTD ; |
---|
260 | outFile << sTD << sB << " quark " << eB << eTD; |
---|
261 | outFile << sTD << sB << " anti-quark " << eB << eTD; |
---|
262 | outFile << eTR; |
---|
263 | |
---|
264 | static const char* quarkName[6] = { "d", "u", "s", "c", "b", "t" }; |
---|
265 | for (G4int flv = 0; flv <6 ; flv++ ){ |
---|
266 | outFile << sTR; |
---|
267 | outFile << sTD << sB << quarkName[flv] << eB << eTD ; |
---|
268 | outFile << sTD << sB << particle->GetQuarkContent(flv+1) << eB << eTD ; |
---|
269 | outFile << sTD << sB << particle->GetAntiQuarkContent(flv+1) << eB << eTD ; |
---|
270 | outFile << eTR; |
---|
271 | } |
---|
272 | outFile << eTABLE << G4endl; |
---|
273 | outFile << "<HR>" << G4endl; |
---|
274 | |
---|
275 | // Decay Table |
---|
276 | G4DecayTable* dcyTable = particle->GetDecayTable(); |
---|
277 | if (dcyTable != 0) { |
---|
278 | outFile << "<H2>" << " Decay Table " << "</H2>" << G4endl; |
---|
279 | |
---|
280 | outFile << sTABLE << '"' << "80%" << '"' << " > " << G4endl; |
---|
281 | |
---|
282 | outFile << sTR; |
---|
283 | outFile << sTD << sB << "BR" << eB << eTD ; |
---|
284 | outFile << sTD << sB << "kinematics" << eB << eTD; |
---|
285 | outFile << eTR; |
---|
286 | |
---|
287 | for (G4int i=0; i< dcyTable->entries(); i++){ |
---|
288 | G4VDecayChannel * channel = dcyTable->GetDecayChannel(i); |
---|
289 | outFile << sTR << G4endl;; |
---|
290 | // column 1 : BR |
---|
291 | outFile << sTD << channel->GetBR() << eTD; |
---|
292 | // column 2 : Kinematics |
---|
293 | outFile << sTD << channel->GetKinematicsName() << eTD; |
---|
294 | // column 3.. : daughters |
---|
295 | for (G4int j=0; j< channel->GetNumberOfDaughters(); j++){ |
---|
296 | outFile << sTD << channel->GetDaughter(j)->GetParticleName() << eTD; |
---|
297 | } |
---|
298 | outFile << eTR << G4endl; |
---|
299 | } |
---|
300 | outFile << eTABLE << G4endl; |
---|
301 | outFile << "<HR>" << G4endl; |
---|
302 | } |
---|
303 | |
---|
304 | outFile << sB; |
---|
305 | outFile << "<A HREF=" << '"' << "index.html" << '"' << ">back to index</A>"; |
---|
306 | outFile << eB << G4endl; |
---|
307 | |
---|
308 | PrintFooter(outFile); |
---|
309 | } |
---|
310 | |
---|
311 | void G4HtmlPPReporter::PrintHeader(std::ofstream& outFile) |
---|
312 | { |
---|
313 | outFile << "<HTML>" << G4endl; |
---|
314 | outFile << "<HEAD>" << G4endl; |
---|
315 | outFile << " <META HTTP-EQUIV=" << "\"" << " Content-Type" << "\""; |
---|
316 | outFile << " CONTENT=" << "\"" << "text/html; charset=iso-8859-1" << "\"" << ">" << G4endl; |
---|
317 | outFile << " <TITLE>Geant4 Particle List </TITLE>" << G4endl; |
---|
318 | outFile << "</HEAD>" << G4endl; |
---|
319 | outFile << "<!-- Generated automatically by Geant4, "; |
---|
320 | outFile << " -- >" << G4endl; |
---|
321 | outFile << "<BODY>" << G4endl; |
---|
322 | } |
---|
323 | |
---|
324 | void G4HtmlPPReporter::PrintFooter(std::ofstream& outFile) |
---|
325 | { |
---|
326 | outFile << "<HR>" << G4endl; |
---|
327 | outFile << "</BODY>" << G4endl; |
---|
328 | outFile << "</HTML>" << G4endl; |
---|
329 | } |
---|
330 | |
---|
331 | const char* G4HtmlPPReporter::sTABLE = "<TABLE WIDTH="; |
---|
332 | const char* G4HtmlPPReporter::eTABLE = "</TABLE>"; |
---|
333 | const char* G4HtmlPPReporter::sTR = "<TR>"; |
---|
334 | const char* G4HtmlPPReporter::eTR = "</TR>"; |
---|
335 | const char* G4HtmlPPReporter::sTD = "<TD>"; |
---|
336 | const char* G4HtmlPPReporter::eTD = "</TD>"; |
---|
337 | const char* G4HtmlPPReporter::sB = "<B>"; |
---|
338 | const char* G4HtmlPPReporter::eB = "</B>"; |
---|
339 | const char* G4HtmlPPReporter::sLFONT = "<FONT SIZE = +1>"; |
---|
340 | const char* G4HtmlPPReporter::eLFONT = "</FONT>"; |
---|
341 | const char* G4HtmlPPReporter::sSYMBOL = "<FONT FACE = \"symbol\" >"; |
---|
342 | const char* G4HtmlPPReporter::eSYMBOL = "</FONT>"; |
---|
343 | const char* G4HtmlPPReporter::sSUP = "<SUP>"; |
---|
344 | const char* G4HtmlPPReporter::eSUP = "</SUP>"; |
---|
345 | const char* G4HtmlPPReporter::sSUB = "<SUB>"; |
---|
346 | const char* G4HtmlPPReporter::eSUB = "</SUB>"; |
---|
347 | |
---|
348 | |
---|