ATLAS Offline Software
HadronUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <algorithm>
7 #include <string>
8 #include <sstream>
9 
10 std::pair<short,short> HadronClass::type(int pdg) {
11  short typeP = 0; // Flavor
12  short typeH = 2; // 0 : meson ; 1 : baryon ; 2 : other
13  std::ostringstream o; o << abs(pdg);
14  std::string s = o.str();
15  int ns = s.size();
16  if (ns >= 4) {
17  if (s.at(ns-4) != '0') {
18  typeH = 1;
19  typeP = atoi(s.substr(ns-4,1).c_str());
20  } else {
21  typeH = 0;
22  typeP = atoi(s.substr(ns-3,1).c_str());
23  }
24  } else if ( ns == 3 ) {
25  typeH = 0;
26  typeP = atoi(s.substr(0,1).c_str());
27  }
28 
29  return std::make_pair(typeH,typeP);
30 }
31 
32 bool HadronClass::HeavyHadron(int pdg) {
33  short typ = type(pdg).second;
34  short typh = type(pdg).first;
35  return (typh < 2 && (typ == 4 || typ == 5));
36 }
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
HadronClass::type
static std::pair< short, short > type(int)
Definition: HadronUtils.cxx:10
HadronUtils.h
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
HadronClass::HeavyHadron
static bool HeavyHadron(int)
Definition: HadronUtils.cxx:32