42 #include <boost/assign/list_inserter.hpp>
44 #include "libConfigUtils.hpp"
45 #include "reportingUtils.hpp"
47 #include "libconfig.h++"
52 using namespace libconfig;
53 using namespace boost::bimaps;
58 typedef bimap<string, unsigned int> nameGeantIdBimap;
59 nameGeantIdBimap initNameGeantIdTranslator()
61 nameGeantIdBimap translator;
62 boost::assign::insert(translator)
63 (nameGeantIdBimap::value_type(
"gamma", 1))
64 (nameGeantIdBimap::value_type(
"e+", 2))
65 (nameGeantIdBimap::value_type(
"e-", 3))
66 (nameGeantIdBimap::value_type(
"mu+", 5))
67 (nameGeantIdBimap::value_type(
"mu-", 6))
68 (nameGeantIdBimap::value_type(
"pi0", 7))
69 (nameGeantIdBimap::value_type(
"pi+", 8))
70 (nameGeantIdBimap::value_type(
"pi-", 9))
71 (nameGeantIdBimap::value_type(
"K_L", 10))
72 (nameGeantIdBimap::value_type(
"K+", 11))
73 (nameGeantIdBimap::value_type(
"K-", 12))
74 (nameGeantIdBimap::value_type(
"n", 13))
75 (nameGeantIdBimap::value_type(
"p+", 14))
76 (nameGeantIdBimap::value_type(
"pbar-", 15))
77 (nameGeantIdBimap::value_type(
"K_S", 16))
78 (nameGeantIdBimap::value_type(
"eta", 17))
79 (nameGeantIdBimap::value_type(
"Lambda", 18))
80 (nameGeantIdBimap::value_type(
"nbar", 25))
81 (nameGeantIdBimap::value_type(
"Lambdabar", 26))
82 (nameGeantIdBimap::value_type(
"rho(770)0", 57))
83 (nameGeantIdBimap::value_type(
"rho(770)+", 58))
84 (nameGeantIdBimap::value_type(
"rho(770)-", 59))
85 (nameGeantIdBimap::value_type(
"omega(782)", 60))
86 (nameGeantIdBimap::value_type(
"eta'(982)", 61))
87 (nameGeantIdBimap::value_type(
"phi(1020)", 62));
95 map<string, particleProperties> particleDataTable::_dataTable;
96 bool particleDataTable::_debug =
false;
97 nameGeantIdBimap particleDataTable::_nameGeantIdMap = initNameGeantIdTranslator();
100 string particleDataTable::particleNameFromGeantId(
const int id) {
101 nameGeantIdBimap::right_const_iterator it = _nameGeantIdMap.right.find(
id);
102 if (it == _nameGeantIdMap.right.end()) {
103 printErr <<
id <<
" is unknown GEANT particle ID. returning particle name 'unknown'." << endl;
108 const string bareName = particleProperties::chargeFromName(it->second, charge);
109 return particleProperties::nameWithCharge(bareName, charge);
113 void particleDataTable::geantIdAndChargeFromParticleName(
const string& name,
118 const string bareName = particleProperties::chargeFromName(name, charge);
119 nameGeantIdBimap::left_const_iterator it = _nameGeantIdMap.left.find(name);
120 if(it == _nameGeantIdMap.left.end()) {
122 it = _nameGeantIdMap.left.find(bareName);
124 if(it == _nameGeantIdMap.left.end()) {
125 printErr <<
"particle '" << name <<
"' is unknown. returning GEANT particle ID 0." << endl;
132 unsigned int particleDataTable::geantIdFromParticleName(
const std::string& name) {
135 geantIdAndChargeFromParticleName(name, retval, tmp);
141 particleDataTable::isInTable(
const string& partName)
143 if (_dataTable.find(partName) == _dataTable.end()) {
151 particleDataTable::entry(
const string& partName,
152 const bool warnIfNotExistent)
155 if (i == _dataTable.end()) {
156 if (warnIfNotExistent)
157 printWarn <<
"could not find entry for particle '" << partName <<
"'" << endl;
164 vector<const particleProperties*>
167 const double minMass,
168 const double minMassWidthFactor,
169 const vector<string>& whiteList,
170 const vector<string>& blackList,
172 const bool& forceDecayCheck)
174 const pair<particleProperties, string> selector(prototype, sel);
175 vector<const particleProperties*> matchingEntries;
176 for (
iterator i = _dataTable.begin();
i != _dataTable.end(); ++
i) {
177 if (
i->second != selector)
181 if ((minMass > 0) and (partProp.
mass() + minMassWidthFactor * partProp.
width() < minMass))
183 if(_debug)printDebug << partProp.
name() <<
" not in mass window " << flush;
187 bool whiteListMatch = (whiteList.size() == 0) ?
true :
false;
188 for (
size_t j = 0; j < whiteList.size(); ++j)
189 if ((partProp.
name() == whiteList[j]) or (partProp.
bareName() == whiteList[j])) {
190 whiteListMatch =
true;
193 if (not whiteListMatch){
194 if(_debug)printDebug << partProp.
name() <<
" not in whitelist " << endl;
198 bool blackListMatch =
false;
199 for (
size_t j = 0; j < blackList.size(); ++j)
200 if ((partProp.
name() == blackList[j]) or (partProp.
bareName() == blackList[j])) {
201 blackListMatch =
true;
204 if (blackListMatch) {
205 if(_debug)printDebug << partProp.
name() <<
" on blacklist " << endl;
209 bool decayMatch =
true;
213 }
else if (forceDecayCheck)
215 if (not decayMatch) {
217 printDebug << partProp.
name() <<
" does not have a decay into " << decay << endl;
222 printDebug <<
"found entry " << partProp.
name() <<
" matching " << prototype
223 <<
" and '" << sel <<
"'" << flush;
225 cout <<
" with mass > " << minMass - minMassWidthFactor * partProp.
width() <<
" GeV";
226 if (whiteList.size() > 0)
227 cout <<
" ; in white list";
228 if (blackList.size() > 0)
229 cout <<
" ; not in black list";
231 cout <<
" ; with allowed decay into " << decay << endl;
233 matchingEntries.push_back(&partProp);
235 return matchingEntries;
242 const string name = partProp.
name();
244 if (i != _dataTable.end()) {
245 printWarn <<
"trying to add entry for particle '" << name <<
"' "
246 <<
"which already exists in table" << endl
247 <<
" existing entry: " << i->second << endl
248 <<
" conflicts with: " << partProp << endl
249 <<
" entry was not added to table." << endl;
252 _dataTable[name] = partProp;
254 printDebug <<
"added entry for '" << name <<
"' into particle data table" << endl;
263 unsigned int countEntries = 0;
266 out <<
"entry " << setw(3) << countEntries <<
": " <<
i->second << endl;
284 particleDataTable::readFile(
const string& fileName)
286 printInfo <<
"reading particle data from file '" << fileName <<
"'" << endl;
287 ifstream file(fileName.c_str());
288 if (not file or not file.good()) {
289 printWarn <<
"cannot open file '" << fileName <<
"'" << endl;
297 particleDataTable::read(istream& in)
299 if (not in or not in.good()) {
300 printWarn <<
"cannot read from input stream" << endl;
304 printDebug <<
"data table has " << nmbEntries() <<
" entries (before reading)" << endl;
305 unsigned int countEntries = 0;
308 if (in >> partProp) {
309 if (addEntry(partProp))
315 printSucc <<
"read " << countEntries <<
" new entries into particle data table" << endl;
317 cout <<
" data table has " << nmbEntries() <<
" entries (after reading)" << endl;
323 particleDataTable::readDecayModeFile(
const string& fileName)
325 printInfo <<
"reading particle decay modes from file '" << fileName <<
"'" << endl;
328 if (not parseLibConfigFile(fileName, file, _debug)) {
329 printWarn <<
"problems reading file with decay modes '" << fileName <<
"'. "
330 <<
"cannot set decay modes." << endl;
333 const Setting&
root = file.getRoot();
335 const Setting* partDecayList = findLibConfigList(root,
"particleDecayList");
336 if (not partDecayList) {
337 printWarn <<
"cannot find 'particleDecayList' list. cannot set decay modes." << endl;
340 const unsigned int nmbEntries = partDecayList->getLength();
342 printDebug <<
"found particle decay list with " << nmbEntries <<
" entries in file "
343 <<
"'" << fileName <<
"'" << endl;
345 unsigned int countEntries = 0;
346 for (
unsigned int entryIndex = 0; entryIndex < nmbEntries; ++entryIndex) {
347 const Setting& partDecayEntry = (*partDecayList)[entryIndex];
349 if (not partDecayEntry.lookupValue(
"name", partName)) {
350 printWarn <<
"particle decay list entry [" << entryIndex <<
"] does not hava a 'name' field. "
351 <<
"ignoring entry." << endl;
355 printDebug <<
"setting decays for '" << partName <<
"':" << endl;
357 const Setting* partDecays = findLibConfigList(partDecayEntry,
"decays");
358 if (not partDecays) {
359 printWarn <<
"cannot find 'decays' list for " << partName
360 <<
" particle decay (list entry [" << entryIndex <<
"]). "
361 <<
"ignoring entry." << endl;
365 map<string, particleProperties>::iterator dataTableEntry = _dataTable.find(partName);
366 if (dataTableEntry == _dataTable.end()) {
367 printWarn <<
"could not find particle " << partName <<
" in data table. "
368 <<
"ignoring entry." << endl;
373 const unsigned int nmbDecays = partDecays->getLength();
374 for (
unsigned int decayIndex = 0; decayIndex < nmbDecays; ++decayIndex) {
376 const Setting* decayDaughters = findLibConfigArray((*partDecays)[decayIndex],
"products");
377 if (not decayDaughters) {
378 printWarn <<
"cannot find 'products' array for " << partName
379 <<
" particle decay list entry [" << decayIndex <<
"]. "
380 <<
"ignoring entry." << endl;
386 const unsigned int nmbDaughters = decayDaughters->getLength();
387 multiset<string> daughters;
388 for (
unsigned int daughterIndex = 0; daughterIndex < nmbDaughters; ++daughterIndex) {
389 const string daughterName = (*decayDaughters)[daughterIndex];
390 daughters.insert(daughterName);
392 cout << daughterName << ((daughterIndex < nmbDaughters - 1) ?
" " :
"");
397 (*partDecays)[decayIndex].lookupValue(
"L", decay.
_L);
398 (*partDecays)[decayIndex].lookupValue(
"S", decay.
_S);
404 printSucc <<
"read " << countEntries <<
" particle decays into particle data table" << endl;