GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
gtestNaturalIsotopes.cxx File Reference
#include <iomanip>
#include <string>
#include "Framework/Messenger/Messenger.h"
#include "Framework/ParticleData/NaturalIsotopes.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "TParticlePDG.h"
#include "TMath.h"
Include dependency graph for gtestNaturalIsotopes.cxx:

Go to the source code of this file.

Functions

int getA (int pdg)
 
int setA (int pdg, int a)
 
std::string PDGcheck (int pdg)
 
int main (int argc, char **argv)
 

Function Documentation

int getA ( int  pdg)

Definition at line 100 of file gtestNaturalIsotopes.cxx.

Referenced by main().

101 { return (int(pdg/10)%1000); }
int main ( int  argc,
char **  argv 
)

Definition at line 35 of file gtestNaturalIsotopes.cxx.

References genie::NaturalIsotopeElementData::Abundance(), genie::NaturalIsotopes::ElementData(), getA(), genie::NaturalIsotopes::Instance(), genie::PDGLibrary::Instance(), LOG, genie::NaturalIsotopes::NElements(), PDGcheck(), genie::NaturalIsotopeElementData::PdgCode(), pNOTICE, and setA().

36 {
37  bool docheckpdg = false;
38  bool calcavg = false;
39 
40  for (int iarg=1; iarg < argc; ++iarg) {
41  // argv[0] is program name, skip it
42  // std::cout << "[" << iarg << "] = \""
43  // << argv[iarg] << "\"" << std::endl;
44  std::string argvstr = std::string(argv[iarg]);
45  if ( argvstr == "--check-pdg" ) docheckpdg = true;
46  else if ( argvstr == "--avg-a" ) calcavg = true;
47  else {
48  cout << "Usage: " << argv[0] << " [--check-pdg] [--avg-a]" << endl;
49  exit(1);
50  }
51  }
52 
53  LOG("test", pNOTICE)
54  << "Testing the NaturalIsotopes utility";
55 
56  /* PDGLibrary * pdglib = */ PDGLibrary::Instance(); // get msg out
57  NaturalIsotopes * ni = NaturalIsotopes::Instance();
58 
59 
60  if ( docheckpdg ) {
61  LOG("test", pNOTICE)
62  << "Check on PDG in PDGLibrary: [PDG,PDG-proton,PDG-neutron]";
63  }
64 
65  for(int Z = 1; Z < 104; Z++){
66  int nel = ni->NElements(Z);
67  LOG("test", pNOTICE) << "** Z = " << Z
68  << " Number of elements = " << nel;
69 
70  int pdg;
71  double abund, avg_a = 0;
72  std::string extra;
73  for(int n = 0; n < nel; n++){
74  const NaturalIsotopeElementData * el = ni->ElementData(Z,n);
75  pdg = el->PdgCode();
76  abund = el->Abundance();
77  avg_a += double(getA(pdg)) * abund;
78  extra = ( docheckpdg ) ? PDGcheck(pdg) : "";
79  LOG("test", pNOTICE)
80  << " -- Element: " << n
81  << ", PdgCode = " << pdg
82  << extra
83  << ", Abundance = " << abund;
84  } // n
85  if ( calcavg && ( nel > 1 ) ) {
86  avg_a /= 100.; // abundances were in %
87  pdg = setA(pdg,TMath::Nint(avg_a));
88  extra = ( docheckpdg ) ? PDGcheck(pdg) : "";
89  LOG("test", pNOTICE)
90  << " "
91  << " PdgCode = " << pdg
92  << extra
93  << ", average <A> " << avg_a ;
94  }
95  } // Z
96 
97  return 0;
98 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
std::string PDGcheck(int pdg)
int NElements(int Z) const
int setA(int pdg, int a)
Singleton class to load &amp; serve tables of natural occurring isotopes.
int getA(int pdg)
#define pNOTICE
Definition: Messenger.h:61
const NaturalIsotopeElementData * ElementData(int Z, int ielement) const
std::string PDGcheck ( int  pdg)

Definition at line 108 of file gtestNaturalIsotopes.cxx.

References genie::PDGLibrary::Find(), and genie::PDGLibrary::Instance().

Referenced by main().

109 {
110  const int minus_p = 10010; // Z-1, A-1
111  const int minus_n = 10; // A-1
112 
113  PDGLibrary * pdglib = PDGLibrary::Instance();
114  int pdg_minus_p = pdg - minus_p;
115  int pdg_minus_n = pdg - minus_n;
116  const TParticlePDG * part = pdglib->Find(pdg);
117  const TParticlePDG * part_minus_p = pdglib->Find(pdg_minus_p);
118  const TParticlePDG * part_minus_n = pdglib->Find(pdg_minus_n);
119  string codeck = " [";
120  codeck += ( (part) ? "ok" : "NO" );
121  if ( pdg != 1000010010 ) {
122  codeck += ",";
123  codeck += ( (part_minus_p) ? "ok" : "NO" );
124  codeck += ",";
125  codeck += ( (part_minus_n) ? "ok" : "NO" );
126  codeck += "]";
127  } else { // special case for H1
128  codeck += ",--,--]";
129  }
130 
131  return codeck;
132 }
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
int setA ( int  pdg,
int  a 
)

Definition at line 103 of file gtestNaturalIsotopes.cxx.

References a.

Referenced by main().

104 {
105  return int(pdg/10000)*10000 + 10*a;
106 }
const double a