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