Logo ROOT   6.08/07
Reference Guide
CompareMasses.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_mc
3 /// Macro to compare masses in ROOT data base to the values from pdg
4 /// [pdg](http://pdg.lbl.gov/2009/mcdata/mass_width_2008.mc).
5 ///
6 /// The ROOT values are read in by TDatabasePDG from `$ROOTSYS/etc/pdg_table.txt`
7 ///
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \author Christian.Klein-Boesing
12 
13 #include "TDatabasePDG.h"
14 #include "TParticlePDG.h"
15 
16 
17 void CompareMasses()
18 {
19  TString massWidthFile = gSystem->UnixPathName(__FILE__);
20  massWidthFile.ReplaceAll("CompareMasses.C","mass_width_2008.mc.txt");
21 
22  FILE* file = fopen(massWidthFile.Data(),"r");
23 
24  if (!file){
25  Printf("Could not open PDG particle file %s", massWidthFile.Data());
26  return;
27  }
28 
29  char c[200];
30  char cempty;
31  Int_t pdg[4];
32  Float_t mass, err1, err2, err;
33  Int_t ndiff = 0;
34 
35  while (fgets(c, 200, file)) {
36  if (c[0] != '*' && c[0] !='W') {
37  //printf("%s",c);
38  sscanf(&c[1], "%8d", &pdg[0]);
39 
40  // check emptiness
41  pdg[1] = 0;
42  for(int i = 0;i<8;i++){
43  sscanf(&c[9+i],"%c",&cempty);
44  if(cempty != ' ')sscanf(&c[9],"%8d",&pdg[1]);
45  }
46 
47  pdg[2] = 0;
48  for(int i = 0;i<8;i++){
49  sscanf(&c[17+i],"%c",&cempty);
50  if(cempty != ' ')sscanf(&c[17],"%8d",&pdg[2]);
51  }
52 
53  pdg[3] = 0;
54  for(int i = 0;i<8;i++){
55  sscanf(&c[25+i],"%c",&cempty);
56  if(cempty != ' ')sscanf(&c[25],"%8d",&pdg[3]);
57  }
58 
59  sscanf(&c[35],"%14f",&mass);
60  sscanf(&c[50],"%8f",&err1);
61  sscanf(&c[50],"%8f",&err2);
62  err = TMath::Max((Double_t)err1,(Double_t)-1.*err2);
63  for(int ipdg = 0;ipdg < 4;ipdg++){
64  if(pdg[ipdg]==0)continue;
65  TParticlePDG *partRoot = TDatabasePDG::Instance()->GetParticle(pdg[ipdg]);
66  if(partRoot){
67  Float_t massRoot = partRoot->Mass();
68  Float_t deltaM = TMath::Abs(massRoot - mass);
69  // if(deltaM > err){
70  if (mass != 0.0 && deltaM/mass>1E-05){
71  ndiff++;
72  Printf("%10s %8d pdg mass %E pdg err %E root Mass %E >> deltaM %E = %3.3f%%",partRoot->GetName(),pdg[ipdg],mass,err,massRoot,deltaM,100.*deltaM/mass);
73  }
74  }
75  }
76  }
77  }// while
78  fclose(file);
79  if (ndiff == 0) Printf("Crongratulations !! All particles in ROOT and PDG have identical masses");
80 
81 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
float Float_t
Definition: RtypesCore.h:53
return c
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1037
static TDatabasePDG * Instance()
static function
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Description of the static properties of a particle.
Definition: TParticlePDG.h:23
Double_t E()
Definition: TMath.h:54
#define Printf
Definition: TGeoToOCC.h:18
double Double_t
Definition: RtypesCore.h:55
TParticlePDG * GetParticle(Int_t pdgCode) const
Get a pointer to the particle object according to the MC code number.
Definition: file.py:1
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Double_t Mass() const
Definition: TParticlePDG.h:71
const char * Data() const
Definition: TString.h:349