source: trunk/source/particles/test/checkParticles/checkParticles.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

File size: 6.6 KB
Line 
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//
27// $Id: checkParticles.cc,v 1.13 2010/10/01 02:41:44 kurasige Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30//
31// ---------------------------------------------------------------
32#include "G4ios.hh"
33#include "globals.hh"
34#include "tstParticleConstructor.hh"
35#include "G4ParticleTable.hh"
36#include "G4StateManager.hh"
37#include <iostream>
38#include <fstream>
39#include <iomanip>
40#include <sstream>
41
42void CheckMass(const char*);
43void CheckWidth(const char*);
44
45const double ALLOWANCE = 1.0e-5;
46
47int main(int argc,char** argv) {
48  // PDG computer-readble file for particle properties
49  //  see http://www-pdg.lbl.gov/computer_read.html
50  std::ifstream pdgFile;
51  G4String pdgFileName = "mass_width_2010.mcd";
52  if (argc > 1) pdgFileName =  argv[1];
53 
54  // open the pdg file
55  pdgFile.open((const char*)pdgFileName);
56  if( pdgFile.fail() ) {
57    G4cerr << "pdg data file <" << pdgFileName << "> could not open." << G4endl;
58        exit(1);
59  }
60  // set the initial application state
61  G4StateManager::GetStateManager()->SetNewState(G4State_PreInit);
62
63
64  // set Readiness
65  G4ParticleTable::GetParticleTable()->SetReadiness();
66
67  // create all particles
68  tstParticleConstructor pConstructor;
69  pConstructor.ConstructParticle();
70
71  // read mass and width from pdg file and check with Geant4
72  char aLine[256];
73  const int LineLength = 255;
74
75  while(1){
76        // read one line
77    pdgFile.getline( aLine, LineLength );
78    if (pdgFile.eof() ) {
79                break;
80    } else if( pdgFile.bad() ) {
81        G4cout << "Cannot read " << pdgFileName << "." << G4endl;
82        break;
83    } 
84
85    aLine[LineLength] = '\0';
86    if ( aLine[0] == 'M' ){
87      CheckMass( &aLine[1] );
88        } else if ( aLine[0] == 'W' ){
89      CheckWidth( &aLine[1] );
90        }
91  }
92  return EXIT_SUCCESS;
93}
94
95#include "G4ParticleTable.hh"
96
97void CheckMass(const char* inputString)
98{
99  const char* t = inputString;
100  std::istringstream is((char*)t);
101 
102  G4int     encoding;
103  G4double  mass;
104  char      massRange[20];
105  char      name[20];
106
107  is >> encoding;
108
109  t = &inputString[33];
110  std::istringstream is2((char*)t);
111  is2 >> mass >> massRange >> name;
112
113  // get a pointer to G4ParticleDefinition with encoding
114  G4ParticleDefinition* particle = 
115    G4ParticleTable::GetParticleTable()->FindParticle(encoding);
116  if (particle == 0) {
117    G4cout << "Can not find the particle with " << encoding;
118    G4cout << " for " << name << G4endl;
119    return;
120  } 
121 
122  if ( std::abs(particle->GetPDGMass()/GeV-mass)/mass > ALLOWANCE ) {
123        G4cout << "Mass is inconsistent for " << particle->GetParticleName();
124    G4cout << " mass = " << particle->GetPDGMass()/GeV << G4endl;
125    G4cout <<  encoding << " " << mass <<  " ";
126        G4cout << massRange <<  " " << name << G4endl;
127  }
128
129  // anti_particle
130  G4int anti_encoding = particle->GetAntiPDGEncoding();
131  if ( (anti_encoding !=0) && (encoding != anti_encoding) ) {
132        particle =
133      G4ParticleTable::GetParticleTable()->FindParticle(anti_encoding);
134    if (particle == 0) {
135      G4cout << "Can not find the anti_particle with " << anti_encoding;
136      G4cout << " for " << name << G4endl;
137      return;
138    } 
139    if ( std::abs(particle->GetPDGMass()/GeV-mass)/mass > ALLOWANCE ) {
140          G4cout << "Mass is inconsistent for " << particle->GetParticleName();
141      G4cout << " mass = " << particle->GetPDGMass()/GeV << G4endl;
142      G4cout <<  encoding << " " << mass <<  " ";
143          G4cout << massRange <<  " " << name << G4endl;
144    }
145  }
146} 
147
148void CheckWidth(const char* inputString)
149{
150  const char* t = inputString;
151  std::istringstream is((char*)t);
152 
153  G4int     encoding;
154  G4double  width;
155  char      widthRange[20];
156  char      name[20];
157
158  is >> encoding;
159
160   t = &inputString[33];
161   std::istringstream is2((char*)t);
162   is2 >> width >> widthRange >> name;
163
164  // get a pointer to G4ParticleDefinition with encoding
165  G4ParticleDefinition* particle = 
166    G4ParticleTable::GetParticleTable()->FindParticle(encoding);
167  if (particle == 0) {
168    G4cout << "Can not find the particle with " << encoding;
169    G4cout << " for " << name << G4endl;
170    return;
171  } 
172 
173  if ( std::abs(particle->GetPDGWidth()/GeV-width)/width > ALLOWANCE ) {
174        G4cout << "Width is inconsistent for " << particle->GetParticleName();
175    G4cout << " width = " << particle->GetPDGWidth()/GeV << G4endl;
176    G4cout <<  encoding << " " << width <<  " ";
177        G4cout << widthRange <<  " " << name << G4endl;
178  }
179
180  // anti_particle
181  G4int anti_encoding = particle->GetAntiPDGEncoding();
182  if ((anti_encoding !=0) && (encoding != anti_encoding)) {
183        particle =
184      G4ParticleTable::GetParticleTable()->FindParticle(anti_encoding);
185    if (particle == 0) {
186      G4cout << "Can not find the anti_particle with " << anti_encoding;
187      G4cout << " for " << name << G4endl;
188      return;
189    } 
190   if ( std::abs(particle->GetPDGWidth()/GeV-width)/width > ALLOWANCE ) {
191        G4cout << "Width is inconsistent for " << particle->GetParticleName();
192        G4cout << " width = " << particle->GetPDGWidth()/GeV << G4endl;
193        G4cout <<  encoding << " " << width <<  " ";
194        G4cout << widthRange <<  " " << name << G4endl;
195  }
196 }
197
198} 
199
Note: See TracBrowser for help on using the repository browser.