Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4CentralityReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4CentralityReco.cc
1 #include "PHG4CentralityReco.h"
2 
3 #include <centrality/CentralityInfo.h> // for CentralityInfo, CentralityI...
4 #include <centrality/CentralityInfov1.h> // for CentralityInfov1
5 
7 #include <fun4all/SubsysReco.h>
8 
10 #include <phool/PHIODataNode.h>
11 #include <phool/PHNode.h>
12 #include <phool/PHNodeIterator.h>
13 #include <phool/PHObject.h> // for PHObject
14 #include <phool/getClass.h>
15 #include <phool/phool.h> // for PHWHERE
16 
18 #include <g4main/PHG4Hit.h>
20 #include <epd/EPDDefs.h>
21 
22 #include <iostream> // for operator<<, basic_ostream
23 #include <map> // for _Rb_tree_const_iterator
24 #include <sstream>
25 #include <stdexcept> // for runtime_error
26 #include <utility> // for pair
27 
29  : SubsysReco(name)
30  , _centrality_calibration_params(name)
31 {
32 }
33 
35 {
36  if (Verbosity() >= 1)
37  std::cout << "PHG4CentralityReco::InitRun : enter " << std::endl;
38 
39  try
40  {
41  CreateNode(topNode);
42  }
43  catch (std::exception &e)
44  {
45  std::cout << PHWHERE << ": " << e.what() << std::endl;
46  throw;
47  }
48 
49  auto bhits = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_BBC");
50  if (!bhits)
51  std::cout << "PHG4CentralityReco::InitRun : cannot find G4HIT_BBC, will not use MBD centrality" << std::endl;
52 
53  auto ehits = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_EPD");
54  if (!ehits)
55  std::cout << "PHG4CentralityReco::InitRun : cannot find G4HIT_EPD, will not use sEPD centrality" << std::endl;
56 
58  {
59  if (Verbosity() >= 1)
60  {
61  std::cout << "PHG4CentralityReco::InitRun : Centrality calibration description : " << std::endl
62  << " ";
63  std::cout << _centrality_calibration_params.get_string_param("description") << std::endl;
64  }
65  // search for possible centile definitions
66  for (int n = 0; n < 101; n++)
67  {
68  std::ostringstream s1;
69  s1 << "epd_centile_" << n;
71  {
73  if (Verbosity() >= 2)
74  std::cout << "PHG4CentralityReco::InitRun : sEPD centrality calibration, centile " << n << "% is " << _centrality_calibration_params.get_double_param(s1.str().c_str()) << std::endl;
75  }
76  }
77  for (int n = 0; n < 101; n++)
78  {
79  std::ostringstream s2;
80  s2 << "mbd_centile_" << n;
82  {
84  if (Verbosity() >= 2)
85  std::cout << "PHG4CentralityReco::InitRun : MBD centrality calibration, centile " << n << "% is " << _centrality_calibration_params.get_double_param(s2.str().c_str()) << std::endl;
86  }
87  }
88  for (int n = 0; n < 101; n++)
89  {
90  std::ostringstream s3;
91  s3 << "bimp_centile_" << n;
93  {
95  if (Verbosity() >= 2)
96  std::cout << "PHG4CentralityReco::InitRun : b (impact parameter) centrality calibration, centile " << n << "% is " << _centrality_calibration_params.get_double_param(s3.str().c_str()) << std::endl;
97  }
98  }
99  }
100  else
101  {
102  std::cout << "PHG4CentralityReco::InitRun : no centrality calibration found!" << std::endl;
103  }
104 
106 }
107 
109 {
110  _bimp = 101;
111  auto event_header = findNode::getClass<EventHeaderv1>(topNode, "EventHeader");
112  if (event_header)
113  {
114  _bimp = event_header->get_floatval("bimp");
115 
116  if (Verbosity() >= 5)
117  std::cout << "PHG4CentralityReco::process_event : Hijing impact parameter b = " << _bimp << std::endl;
118  }
119  else
120  {
121  if (Verbosity() >= 5)
122  std::cout << "PHG4CentralityReco::process_event : No Hijing impact parameter info, setting b = 101" << std::endl;
123  }
124 
125  _mbd_N = 0;
126  _mbd_S = 0;
127  _mbd_NS = 0;
128 
129  auto bhits = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_BBC");
130 
131  if (bhits)
132  {
133  auto brange = bhits->getHits();
134  for (auto it = brange.first; it != brange.second; ++it)
135  {
136  if ((it->second->get_t(0) > -50) && (it->second->get_t(1) < 50))
137  {
138  _mbd_NS += it->second->get_edep();
139  int id = it->second->get_layer();
140  if ((id & 0x40) == 0)
141  _mbd_N += it->second->get_edep();
142  else
143  _mbd_S += it->second->get_edep();
144  }
145  }
146 
147  if (Verbosity() >= 5)
148  std::cout << "PHG4CentralityReco::process_event : MBD Sum Charge N / S / N+S = " << _mbd_N << " / " << _mbd_S << " / " << _mbd_NS << std::endl;
149  }
150  else
151  {
152  if (Verbosity() >= 5)
153  std::cout << "PHG4CentralityReco::process_event : No MBD info, setting all Sum Charges = 0" << std::endl;
154  }
155 
156  _epd_N = 0;
157  _epd_S = 0;
158  _epd_NS = 0;
159 
160  auto ehits = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_EPD");
161 
162  if (ehits)
163  {
164  auto erange = ehits->getHits();
165  for (auto it = erange.first; it != erange.second; ++it)
166  if ((it->second->get_t(0) > -50) && (it->second->get_t(1) < 50))
167  {
168  _epd_NS += it->second->get_edep();
169 
170  int sim_tileid = (it->second->get_hit_id() >> PHG4HitDefs::hit_idbits);
171  int this_arm = EPDDefs::get_arm(sim_tileid);
172 
173  if (this_arm == 1)
174  _epd_N += it->second->get_edep();
175  else
176  _epd_S += it->second->get_edep();
177  }
178 
179  if (Verbosity() >= 5)
180  std::cout << "PHG4CentralityReco::process_event : sEPD Sum Energy N / S / N+S = " << _epd_N << " / " << _epd_S << " / " << _epd_NS << std::endl;
181  }
182  else
183  {
184  if (Verbosity() >= 5)
185  std::cout << "PHG4CentralityReco::process_event : No sEPD info, setting all Sum Energies = 0" << std::endl;
186  }
187 
188  if (Verbosity() >= 1)
189  std::cout << "PHG4CentralityReco::process_event : summary MBD (N, S, N+S) = (" << _mbd_N << ", " << _mbd_S << ", " << _mbd_NS << "), sEPD (N, S, N+S) = (" << _epd_N << ", " << _epd_S << ", " << _epd_NS << ")" << std::endl;
190 
192  {
193  // sEPD centrality
194  float low_epd_val = -10000;
195  float high_epd_val = 10000;
196  int low_epd_centile = -1;
197  int high_epd_centile = -1;
198 
199  for (std::map<float, int>::iterator it = _cent_cal_epd.begin(); it != _cent_cal_epd.end(); ++it)
200  {
201  float signal = it->first;
202  int cent = it->second;
203 
204  if (signal < _epd_NS && signal > low_epd_val)
205  {
206  low_epd_val = signal;
207  low_epd_centile = cent;
208  }
209  if (signal > _epd_NS && signal < high_epd_val)
210  {
211  high_epd_val = signal;
212  high_epd_centile = cent;
213  }
214 
215  } // close iterate through sEPD cuts
216 
217  if (low_epd_centile >= 0 && high_epd_centile >= 0)
218  {
219  _epd_cent = (low_epd_centile + high_epd_centile) / 2.0;
220  if (Verbosity() >= 10)
221  std::cout << "PHG4CentralityReco::process_event : lower EPD value is " << low_epd_val << " (" << low_epd_centile << "%), higher is " << high_epd_val << " (" << high_epd_centile << "%), assigning " << _epd_cent << "%" << std::endl;
222  }
223  else
224  {
225  _epd_cent = 101;
226  if (Verbosity() >= 5)
227  std::cout << "PHG4CentralityReco::process_event : not able to map EPD value to a centrality. debug info = " << low_epd_val << "/" << low_epd_centile << "/" << high_epd_val << "/" << high_epd_centile << std::endl;
228  }
229 
230  // MBD centrality
231  float low_mbd_val = -10000;
232  float high_mbd_val = 10000;
233  int low_mbd_centile = -1;
234  int high_mbd_centile = -1;
235 
236  for (std::map<float, int>::iterator it = _cent_cal_mbd.begin(); it != _cent_cal_mbd.end(); ++it)
237  {
238  float signal = it->first;
239  int cent = it->second;
240 
241  if (signal < _mbd_NS && signal > low_mbd_val)
242  {
243  low_mbd_val = signal;
244  low_mbd_centile = cent;
245  }
246  if (signal > _mbd_NS && signal < high_mbd_val)
247  {
248  high_mbd_val = signal;
249  high_mbd_centile = cent;
250  }
251 
252  } // close iterate through MBD cuts
253 
254  if (low_mbd_centile >= 0 && high_mbd_centile >= 0)
255  {
256  _mbd_cent = (low_mbd_centile + high_mbd_centile) / 2.0;
257  if (Verbosity() >= 10)
258  std::cout << "PHG4CentralityReco::process_event : lower MBD value is " << low_mbd_val << " (" << low_mbd_centile << "%), higher is " << high_mbd_val << " (" << high_mbd_centile << "%), assigning " << _mbd_cent << "%" << std::endl;
259  }
260  else
261  {
262  _mbd_cent = 101;
263  if (Verbosity() >= 5)
264  std::cout << "PHG4CentralityReco::process_event : not able to map MBD value to a centrality. debug info = " << low_mbd_val << "/" << low_mbd_centile << "/" << high_mbd_val << "/" << high_mbd_centile << std::endl;
265  }
266 
267  // b (impact parameter) centrality
268  float low_bimp_val = -1;
269  float high_bimp_val = 10000;
270  int low_bimp_centile = -1;
271  int high_bimp_centile = -1;
272 
273  for (std::map<float, int>::iterator it = _cent_cal_bimp.begin(); it != _cent_cal_bimp.end(); ++it)
274  {
275  float signal = it->first;
276  int cent = it->second;
277 
278  if (signal < _bimp && signal > low_bimp_val)
279  {
280  low_bimp_val = signal;
281  low_bimp_centile = cent;
282  }
283  if (signal > _bimp && signal < high_bimp_val)
284  {
285  high_bimp_val = signal;
286  high_bimp_centile = cent;
287  }
288 
289  } // close iterate through bimp cuts
290 
291  if (low_bimp_centile >= 0 && high_bimp_centile >= 0)
292  {
293  _bimp_cent = (low_bimp_centile + high_bimp_centile) / 2.0;
294  if (Verbosity() >= 10)
295  std::cout << "PHG4CentralityReco::process_event : lower b value is " << low_bimp_val << " (" << low_bimp_centile << "%), higher is " << high_bimp_val << " (" << high_bimp_centile << "%), assigning " << _bimp_cent << "%" << std::endl;
296  }
297  else
298  {
299  _bimp_cent = 101;
300  if (Verbosity() >= 5)
301  std::cout << "PHG4CentralityReco::process_event : not able to map b value to a centrality. debug info = " << low_bimp_val << "/" << low_bimp_centile << "/" << high_bimp_val << "/" << high_bimp_centile << std::endl;
302  }
303 
304  } // close centrality calibration
305 
306  FillNode(topNode);
307 
309 }
310 
312 {
314 }
315 
317 {
318  CentralityInfo *cent = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
319  if (!cent)
320  {
321  std::cout << " ERROR -- can't find CentralityInfo node after it should have been created" << std::endl;
322  return;
323  }
324  else
325  {
326  cent->set_quantity(CentralityInfo::PROP::mbd_N, _mbd_N);
327  cent->set_quantity(CentralityInfo::PROP::mbd_S, _mbd_S);
328  cent->set_quantity(CentralityInfo::PROP::mbd_NS, _mbd_NS);
329  cent->set_quantity(CentralityInfo::PROP::epd_N, _epd_N);
330  cent->set_quantity(CentralityInfo::PROP::epd_S, _epd_S);
331  cent->set_quantity(CentralityInfo::PROP::epd_NS, _epd_NS);
332  cent->set_quantity(CentralityInfo::PROP::bimp, _bimp);
333 
334  cent->set_centile(CentralityInfo::PROP::epd_NS, _epd_cent);
335  cent->set_centile(CentralityInfo::PROP::mbd_NS, _mbd_cent);
336  cent->set_centile(CentralityInfo::PROP::bimp, _bimp_cent);
337  }
338 }
339 
341 {
342  PHNodeIterator iter(topNode);
343 
344  PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
345  if (!dstNode)
346  {
347  std::cerr << PHWHERE << "DST Node missing, doing nothing." << std::endl;
348  throw std::runtime_error("Failed to find DST node in PHG4CentralityReco::CreateNode");
349  }
350 
351  PHNodeIterator dstiter(dstNode);
352  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", "GLOBAL"));
353  if (!DetNode)
354  {
355  DetNode = new PHCompositeNode("GLOBAL");
356  dstNode->addNode(DetNode);
357  }
358 
359  CentralityInfo *cent = new CentralityInfov1();
360 
361  PHIODataNode<PHObject> *centNode = new PHIODataNode<PHObject>(cent, "CentralityInfo", "PHObject");
362  DetNode->addNode(centNode);
363 }