MINT2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Attributes | List of all members
ParticlePropertiesList Class Reference

#include <ParticlePropertiesList.h>

Public Member Functions

const ParticlePropertiesget (const std::string &name) const
 
const ParticlePropertiesget (int pdg_id) const
 
void print (std::ostream &out=std::cout) const
 

Static Public Member Functions

static const ParticlePropertiesListgetMe ()
 
static double mass (const std::string &name)
 
static double mass (int PDG)
 
static double width (const std::string &name)
 
static double width (int PDG)
 

Protected Member Functions

FILE * findFiles ()
 
bool readFiles ()
 

Static Protected Member Functions

static const std::vector< std::string > & dirList ()
 
static void fillDirList ()
 
static void printCannotFindWarning (const std::string &where, const std::string &what)
 
static void printCannotFindWarning (const std::string &where, int what)
 
static FILE * findThisFile (const std::string &fname)
 

Protected Attributes

std::string _fname
 
std::list< ParticlePropertiestheList
 
std::map< std::string, std::list< ParticleProperties >::iterator > byName
 
std::map< int, std::list< ParticleProperties >::iterator > byID
 

Static Protected Attributes

static std::vector< std::string > _dirList
 

Private Member Functions

 ParticlePropertiesList (std::string fname_in="mass_width.cvs")
 

Static Private Attributes

static ParticlePropertiesListptr =0
 
static std::string _MintDalitzSpecialParticles ="MintDalitzSpecialParticles.cvs"
 

Detailed Description

Definition at line 14 of file ParticlePropertiesList.h.

Constructor & Destructor Documentation

◆ ParticlePropertiesList()

ParticlePropertiesList::ParticlePropertiesList ( std::string  fname_in = "mass_width.cvs")
private

Definition at line 168 of file ParticlePropertiesList.cpp.

168  {
169  _fname=fname_in;
170 
171  if(! readFiles()){
172  std::cout << "ERROR! in ParticleProperties constructor:"
173  << " Problem reading file "
174  << _fname << std::endl;
175  }
176 
177 }

Member Function Documentation

◆ dirList()

const std::vector< std::string > & ParticlePropertiesList::dirList ( )
staticprotected

Definition at line 84 of file ParticlePropertiesList.cpp.

84  {
85  if(_dirList.empty()) fillDirList();
86  return _dirList;
87 }
static std::vector< std::string > _dirList

◆ fillDirList()

void ParticlePropertiesList::fillDirList ( )
staticprotected

Definition at line 89 of file ParticlePropertiesList.cpp.

89  {
90  _dirList.clear();
91  NamedParameter<std::string> userDir("ParticlePropertiesList::ParticlePropertiesDir",
92  (char*)0, NamedParameterBase::QUIET);
93  for(int i=0; i < userDir.size(); i++){
94  if("" != userDir.getVal(i)){
95  _dirList.push_back(userDir.getVal(i) + "/");
96  // cout << "just pushed back " << userDir.getVal() << endl;
97  }
98  }
99 
100 // Get directory to MINTROOT
101 
102 
103  std::string MintRoot(".");
104  char * Mintevn(0);
105  Mintevn = getenv ("MINT2");
106  if (NULL != Mintevn){
107  MintRoot = Mintevn;
108  }
109 
110  std::string DecFilesRoot("UNKNOWN");
111  char * DecFiles;
112  DecFiles = getenv ("DECFILESROOT");
113  if (NULL != DecFiles){
114  DecFilesRoot = DecFiles;
115  }
116 
117  _dirList.push_back("");
118  _dirList.push_back("./");
119  _dirList.push_back(MintRoot+"/share/");
120  _dirList.push_back(DecFilesRoot+"/MintData/");
121 }
static std::vector< std::string > _dirList

◆ findFiles()

FILE * ParticlePropertiesList::findFiles ( )
protected

Definition at line 124 of file ParticlePropertiesList.cpp.

124  {
125  static int i=0;
126  // cout << " i = " << i << endl;
127  FILE* f(0);
128  if(0 == i){
129  f = findThisFile(_fname);
130  if(0 == f) findThisFile("mass_width.csv"); // making it backward compatible with old typo
131  if(0 == f)i++;
132  }
133  if(1 == i){
135  if(0 == f) i++;
136  }
137 
138  i = (i+1)%3;
139 
140  return f;
141 }
static FILE * findThisFile(const std::string &fname)
static std::string _MintDalitzSpecialParticles

◆ findThisFile()

FILE * ParticlePropertiesList::findThisFile ( const std::string &  fname)
staticprotected

Definition at line 142 of file ParticlePropertiesList.cpp.

142  {
143  bool verbose=true;
144  for(std::vector<std::string>::const_iterator it = dirList().begin();
145  it != dirList().end();
146  it++){
147 
148  std::string tryThisDir = (*it);
149  std::string fullFname = tryThisDir + fname;
150  if(verbose)cout << "INFO in ParticlePropertiesList: trying: " << fullFname << endl;
151  FILE* f=fopen(fullFname.c_str(), "r");
152  if(0 != f){
153  cout << "INFO in ParticlePropertiesList: Using this file: "
154  << fullFname << endl;
155  return f;
156  }
157 
158  }
159  cout << "ERROR in ParticlePropertiesList::findFile()"
160  << "\n > having trouble finding file"
161  << "\n > with name " << fname
162  << "\n > in any directory I could guess."
163  << "\n > This is hardcoded in ParticleProperties.C."
164  << endl;
165  return (FILE*) 0;
166 }
static const std::vector< std::string > & dirList()

◆ get() [1/2]

const ParticleProperties * ParticlePropertiesList::get ( const std::string &  name) const

Definition at line 237 of file ParticlePropertiesList.cpp.

237  {
238  std::map<std::string, std::list<ParticleProperties>::iterator >::const_iterator it
239  = byName.find(name);
240  if(it == byName.end()) return 0;
241 
242  return &(*(it->second));
243 }
std::map< std::string, std::list< ParticleProperties >::iterator > byName

◆ get() [2/2]

const ParticleProperties * ParticlePropertiesList::get ( int  pdg_id) const

Definition at line 244 of file ParticlePropertiesList.cpp.

244  {
245  std::map<int, std::list<ParticleProperties>::iterator >::const_iterator it
246  = byID.find(id);
247  if(it == byID.end()) return 0;
248 
249  return &(*(it->second));
250 }
std::map< int, std::list< ParticleProperties >::iterator > byID

◆ getMe()

const ParticlePropertiesList * ParticlePropertiesList::getMe ( )
static

Definition at line 21 of file ParticlePropertiesList.cpp.

21  {
22  if(! ptr){
24  }
25  if(0 == ptr){
26  cout << "ERROR in ParticlceProperties::getMe"
27  << " Couldn't get ParticlePropertiesList (i.e. myself)"
28  << "\n\t This is a serious problem. Will crash."
29  << endl;
30  throw "No ParticlePropertiesList";
31  }
32  return ptr;
33 }
ParticlePropertiesList(std::string fname_in="mass_width.cvs")
static ParticlePropertiesList * ptr

◆ mass() [1/2]

double ParticlePropertiesList::mass ( const std::string &  name)
static

Definition at line 50 of file ParticlePropertiesList.cpp.

50  {
51  const ParticleProperties* props = getMe()->get(name);
52  if(0 == props){
53  printCannotFindWarning("mass", name);
54  return -9999;
55  }
56  return props->mass();
57 }
const ParticleProperties * get(const std::string &name) const
static void printCannotFindWarning(const std::string &where, const std::string &what)
static const ParticlePropertiesList * getMe()

◆ mass() [2/2]

double ParticlePropertiesList::mass ( int  PDG)
static

Definition at line 58 of file ParticlePropertiesList.cpp.

58  {
59  const ParticleProperties* props = getMe()->get(pid);
60  if(0 == props){
61  printCannotFindWarning("mass", pid);
62  return -9999;
63  }
64  return props->mass();
65 }
const ParticleProperties * get(const std::string &name) const
static void printCannotFindWarning(const std::string &where, const std::string &what)
static const ParticlePropertiesList * getMe()

◆ print()

void ParticlePropertiesList::print ( std::ostream &  out = std::cout) const

Definition at line 229 of file ParticlePropertiesList.cpp.

229  {
230  for(std::list<ParticleProperties>::const_iterator it= theList.begin();
231  it != theList.end(); it++){
232  it->print(out);
233  out << "\n";
234  }
235 }
std::list< ParticleProperties > theList

◆ printCannotFindWarning() [1/2]

void ParticlePropertiesList::printCannotFindWarning ( const std::string &  where,
const std::string &  what 
)
staticprotected

Definition at line 35 of file ParticlePropertiesList.cpp.

36  {
37  cout << "WARNING in ParticlceProperties::" << where
38  << " Got ParticlePropertiesList, but couldn't find "
39  << what
40  << endl;
41 }

◆ printCannotFindWarning() [2/2]

void ParticlePropertiesList::printCannotFindWarning ( const std::string &  where,
int  what 
)
staticprotected

Definition at line 42 of file ParticlePropertiesList.cpp.

43  {
44  cout << "WARNING in ParticlceProperties::" << where
45  << " Got ParticlePropertiesList, but couldn't find "
46  << what
47  << endl;
48 }

◆ readFiles()

bool ParticlePropertiesList::readFiles ( )
protected

Definition at line 179 of file ParticlePropertiesList.cpp.

179  {
180  bool shoutIfTwice=true;
181  int counter=0;
182  while(FILE* f = findFiles()){
183  cout << "reading " << counter << "th file" << endl;
184  if(0==f) return false;
185 
186  static const int lineLength=800;
187  char line[lineLength]={'\0'};
188 
189  while(fgets(line, lineLength, f)){
190  ParticleProperties P(line);
191  if(! P.isValid()) continue;
192 
193  theList.push_back(P);
194  if(P.hasDistinctAnti()){
195  P.antiThis();
196  theList.push_back(P);
197  }
198  }
199  fclose(f);
200  }
201 
202  // make maps for fast particle finding:
203  for(std::list<ParticleProperties>::iterator it= theList.begin();
204  it != theList.end(); it++){
205  byName[it->name()] = it;
206  if(shoutIfTwice && it->pdg_id() != 0){
207  map<int, list<ParticleProperties>::iterator >::iterator found = byID.find(it->pdg_id());
208  if(found != byID.end()){
209  cout << "WARNING in ParticlePropertiesList::readFiles "
210  << "pdg_id " << it->pdg_id() << " used twice, here: "
211  << (found->second)->name()
212  << ", and here:\n " << it->name()
213  << endl;
214  cout << " Important: Note that this is probably not be a MintDalitz error - "
215  << "\n some particles (the 'non-established' ones) have the same PDG code."
216  << "\n To use those realiably, you'll need to put your own copy of the"
217  << "\n mass_width.cvs file, put it into your run-directory, and edit the file"
218  << "\n so that your particle has a unique PID code."
219  << "\n -----------------------"
220  << endl;
221  }
222  }
223  byID[it->pdg_id()] = it;
224  }
225 
226  return true;
227 }
std::map< int, std::list< ParticleProperties >::iterator > byID
std::list< ParticleProperties > theList
std::map< std::string, std::list< ParticleProperties >::iterator > byName

◆ width() [1/2]

double ParticlePropertiesList::width ( const std::string &  name)
static

Definition at line 66 of file ParticlePropertiesList.cpp.

66  {
67  const ParticleProperties* props = getMe()->get(name);
68  if(0 == props){
69  printCannotFindWarning("width", name);
70  return -9999;
71  }
72  return props->width();
73 }
const ParticleProperties * get(const std::string &name) const
static void printCannotFindWarning(const std::string &where, const std::string &what)
static const ParticlePropertiesList * getMe()
double width() const

◆ width() [2/2]

double ParticlePropertiesList::width ( int  PDG)
static

Definition at line 74 of file ParticlePropertiesList.cpp.

74  {
75  const ParticleProperties* props = getMe()->get(pid);
76  if(0 == props){
77  printCannotFindWarning("width", pid);
78  return -9999;
79  }
80  return props->width();
81 }
const ParticleProperties * get(const std::string &name) const
static void printCannotFindWarning(const std::string &where, const std::string &what)
static const ParticlePropertiesList * getMe()
double width() const

Member Data Documentation

◆ _dirList

std::vector< std::string > ParticlePropertiesList::_dirList
staticprotected

Definition at line 31 of file ParticlePropertiesList.h.

◆ _fname

std::string ParticlePropertiesList::_fname
protected

Definition at line 40 of file ParticlePropertiesList.h.

◆ _MintDalitzSpecialParticles

std::string ParticlePropertiesList::_MintDalitzSpecialParticles ="MintDalitzSpecialParticles.cvs"
staticprivate

Definition at line 29 of file ParticlePropertiesList.h.

◆ byID

std::map<int, std::list<ParticleProperties>::iterator > ParticlePropertiesList::byID
protected

Definition at line 46 of file ParticlePropertiesList.h.

◆ byName

std::map<std::string, std::list<ParticleProperties>::iterator > ParticlePropertiesList::byName
protected

Definition at line 45 of file ParticlePropertiesList.h.

◆ ptr

ParticlePropertiesList * ParticlePropertiesList::ptr =0
staticprivate

Definition at line 25 of file ParticlePropertiesList.h.

◆ theList

std::list<ParticleProperties> ParticlePropertiesList::theList
protected

Definition at line 44 of file ParticlePropertiesList.h.


The documentation for this class was generated from the following files: