ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EICPIDParticlev1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EICPIDParticlev1.cc
1 #include "EICPIDParticlev1.h"
2 
3 #include <phool/phool.h>
4 
5 #include <climits>
6 #include <cmath>
7 #include <cstdlib>
8 #include <string>
9 #include <utility>
10 #include "EICPIDDefs.h"
11 
12 using namespace std;
13 
15 {
16  CopyFrom(g4hit);
17 }
18 
20 {
21  m_id = -1;
22  prop_map.clear();
23  m_LogLikelyhoodMap.clear();
24 }
25 
26 void EICPIDParticlev1::identify(ostream& os) const
27 {
28  os << "Class " << this->ClassName();
29  os << " id: " << m_id
30  << ", m_LogLikelyhoodMap.size() = " << m_LogLikelyhoodMap.size()
31  << ", prop_map.size() = " << prop_map.size()
32  << endl;
33  for (const auto& pair : m_LogLikelyhoodMap)
34  {
35  const auto& key = pair.first;
36  const auto& LL = pair.second;
37 
38  os << "\t"
39  << "PID Candidate " << key.first << " from detector ID " << key.second
40  << " " << EICPIDDefs::getPIDDetectorName(key.second);
41  os << " :\t LogLikelyhood = " << LL << endl;
42  }
43  for (prop_map_t::const_iterator i = prop_map.begin(); i != prop_map.end(); ++i)
44  {
45  PROPERTY prop_id = static_cast<PROPERTY>(i->first);
46  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
47  os << "\t" << prop_id << ":\t" << property_info.first << " = \t";
48  switch (property_info.second)
49  {
50  case type_int:
51  os << get_property_int(prop_id);
52  break;
53  case type_uint:
54  os << get_property_uint(prop_id);
55  break;
56  case type_float:
57  os << get_property_float(prop_id);
58  break;
59  default:
60  os << " unknown type ";
61  }
62  os << endl;
63  }
64 }
65 
67 {
68  float LL = 0;
69  for (const auto& pair : m_LogLikelyhoodMap)
70  {
71  if (pair.first.first == pid) LL += pair.second;
72  }
73  return LL;
74 }
75 
77 {
78  if (det == EICPIDDefs::PIDAll) return get_SumLogLikelyhood(pid);
79 
80  const LogLikelyhoodMapKey_t key(pid, det);
81  const auto iter = m_LogLikelyhoodMap.find(key);
82 
83  if (iter == m_LogLikelyhoodMap.end())
84  return m_minLogLikelihood;
85  else
86  return iter->second;
87 }
88 
90 {
91  const LogLikelyhoodMapKey_t key(pid, det);
92 
93  m_LogLikelyhoodMap[key] = LogLikelyhood;
94 }
95 
96 bool EICPIDParticlev1::has_property(const PROPERTY prop_id) const
97 {
98  prop_map_t::const_iterator i = prop_map.find(prop_id);
99  return i != prop_map.end();
100 }
101 
103 {
104  if (!check_property(prop_id, type_float))
105  {
106  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
107  cout << PHWHERE << " Property " << property_info.first << " with id "
108  << prop_id << " is of type " << get_property_type(property_info.second)
109  << " not " << get_property_type(type_float) << endl;
110  exit(1);
111  }
112  prop_map_t::const_iterator i = prop_map.find(prop_id);
113 
114  if (i != prop_map.end()) return u_property(i->second).fdata;
115 
116  return NAN;
117 }
118 
120 {
121  if (!check_property(prop_id, type_int))
122  {
123  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
124  cout << PHWHERE << " Property " << property_info.first << " with id "
125  << prop_id << " is of type " << get_property_type(property_info.second)
126  << " not " << get_property_type(type_int) << endl;
127  exit(1);
128  }
129  prop_map_t::const_iterator i = prop_map.find(prop_id);
130 
131  if (i != prop_map.end()) return u_property(i->second).idata;
132 
133  return INT_MIN;
134 }
135 
136 unsigned int
138 {
139  if (!check_property(prop_id, type_uint))
140  {
141  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
142  cout << PHWHERE << " Property " << property_info.first << " with id "
143  << prop_id << " is of type " << get_property_type(property_info.second)
144  << " not " << get_property_type(type_uint) << endl;
145  exit(1);
146  }
147  prop_map_t::const_iterator i = prop_map.find(prop_id);
148 
149  if (i != prop_map.end()) return u_property(i->second).uidata;
150 
151  return UINT_MAX;
152 }
153 
154 void EICPIDParticlev1::set_property(const PROPERTY prop_id, const float value)
155 {
156  if (!check_property(prop_id, type_float))
157  {
158  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
159  cout << PHWHERE << " Property " << property_info.first << " with id "
160  << prop_id << " is of type " << get_property_type(property_info.second)
161  << " not " << get_property_type(type_float) << endl;
162  exit(1);
163  }
164  prop_map[prop_id] = u_property(value).get_storage();
165 }
166 
167 void EICPIDParticlev1::set_property(const PROPERTY prop_id, const int value)
168 {
169  if (!check_property(prop_id, type_int))
170  {
171  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
172  cout << PHWHERE << " Property " << property_info.first << " with id "
173  << prop_id << " is of type " << get_property_type(property_info.second)
174  << " not " << get_property_type(type_int) << endl;
175  exit(1);
176  }
177  prop_map[prop_id] = u_property(value).get_storage();
178 }
179 
180 void EICPIDParticlev1::set_property(const PROPERTY prop_id, const unsigned int value)
181 {
182  if (!check_property(prop_id, type_uint))
183  {
184  pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
185  cout << PHWHERE << " Property " << property_info.first << " with id "
186  << prop_id << " is of type " << get_property_type(property_info.second)
187  << " not " << get_property_type(type_uint) << endl;
188  exit(1);
189  }
190  prop_map[prop_id] = u_property(value).get_storage();
191 }
192 
193 unsigned int
195 {
196  prop_map_t::const_iterator iter = prop_map.find(prop_id);
197  if (iter != prop_map.end())
198  {
199  return iter->second;
200  }
201  return UINT_MAX;
202 }