ROOT
6.08/07
Reference Guide
tutorials
mc
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>1
E
-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
}
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition:
TNamed.h:51
TParticlePDG.h
Float_t
float Float_t
Definition:
RtypesCore.h:53
c
return c
Definition:
entrylist_figure1.C:47
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition:
TString.h:635
TString
Basic string class.
Definition:
TString.h:137
Int_t
int Int_t
Definition:
RtypesCore.h:41
TMath::Abs
Short_t Abs(Short_t d)
Definition:
TMathBase.h:110
TSystem::UnixPathName
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition:
TSystem.cxx:1037
TDatabasePDG::Instance
static TDatabasePDG * Instance()
static function
Definition:
TDatabasePDG.cxx:103
gSystem
R__EXTERN TSystem * gSystem
Definition:
TSystem.h:549
TParticlePDG
Description of the static properties of a particle.
Definition:
TParticlePDG.h:23
TMath::E
Double_t E()
Definition:
TMath.h:54
Printf
#define Printf
Definition:
TGeoToOCC.h:18
Double_t
double Double_t
Definition:
RtypesCore.h:55
TDatabasePDG::GetParticle
TParticlePDG * GetParticle(Int_t pdgCode) const
Get a pointer to the particle object according to the MC code number.
Definition:
TDatabasePDG.cxx:229
file
Definition:
file.py:1
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition:
TMathBase.h:202
TParticlePDG::Mass
Double_t Mass() const
Definition:
TParticlePDG.h:71
TDatabasePDG.h
TString::Data
const char * Data() const
Definition:
TString.h:349