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