Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CentralityReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CentralityReco.cc
1 #include "CentralityReco.h"
2 
3 #include "CentralityInfov2.h"
4 
5 #include <mbd/MbdOut.h>
6 
8 
9 #include <cdbobjects/CDBTTree.h>
10 
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h>
15 #include <phool/PHNode.h>
16 #include <phool/PHNodeIterator.h>
17 #include <phool/PHObject.h>
18 #include <phool/getClass.h>
19 #include <phool/phool.h>
20 
21 #include <filesystem>
22 #include <iostream>
23 #include <string>
24 
26  : SubsysReco(name)
27 {
28 
29 }
30 
32 {
34 
35  std::string centdiv_url = _cdb->getUrl("Centrality");
36 
37  if (Download_centralityDivisions(centdiv_url))
38  {
40  }
41 
42  std::string centscale_url = _cdb->getUrl("CentralityScale");
43 
44  if (Download_centralityScale(centscale_url))
45  {
47  }
48 
49  CreateNodes(topNode);
51 }
52 
54 {
55  _centrality_scale = 1.00;
56 
57  std::filesystem::path dbase_file = dbfile;
58  if (dbase_file.extension() == ".root")
59  {
60  CDBTTree *cdbttree = new CDBTTree(dbase_file);
61  cdbttree->LoadCalibrations();
62  _centrality_scale = cdbttree->GetDoubleValue(0, "centralityscale");
63  if (Verbosity())
64  {
65  std::cout << "centscale = " << _centrality_scale << std::endl;
66  }
67  delete cdbttree;
68  }
69  else
70  {
71  std::cout << PHWHERE << ", ERROR, unknown file type, " << dbfile << std::endl;
73  }
74 
76 }
77 
79 {
80  _centrality_map.fill(0);
81 
82  std::filesystem::path dbase_file = dbfile;
83 
84  if (dbase_file.extension() == ".root")
85  {
86  CDBTTree *cdbttree = new CDBTTree(dbase_file);
87  cdbttree->LoadCalibrations();
88  if (Verbosity())
89  {
90  cdbttree->Print();
91  }
92  for (int idiv = 0; idiv < NDIVS; idiv++)
93  {
94  _centrality_map[idiv] = cdbttree->GetFloatValue(idiv, "centralitydiv");
95  if (Verbosity())
96  {
97  std::cout << "centdiv " << idiv << " : " << _centrality_map[idiv] << std::endl;
98  }
99  }
100  delete cdbttree;
101  }
102  else
103  {
104  std::cout << PHWHERE << ", ERROR, unknown file type, " << dbfile << std::endl;
106  }
107 
109 }
110 
112 {
113  if (Verbosity() > 1)
114  {
115  std::cout << __FILE__ << " :: " << __FUNCTION__ << std::endl;
116  }
117  _mbd_charge_sum = 0.;
118  _mbd_charge_sum_n = 0.;
119  _mbd_charge_sum_s = 0.;
120 
122 }
123 
125 {
126  if (Verbosity() > 1)
127  {
128  std::cout << __FILE__ << " :: " << __FUNCTION__ << std::endl;
129  }
130 
132 
134 
136 
137  if (Verbosity())
138  {
139  std::cout << " MBD sum = " << _mbd_charge_sum << std::endl;
140  std::cout << " North: " << _mbd_charge_sum_n << std::endl;
141  std::cout << " South: " << _mbd_charge_sum_s << std::endl;
142  }
143 
145 }
146 
148 {
149  // Fill is minbias
150 
151  if (Verbosity() > 1)
152  {
153  std::cout << __FILE__ << " :: " << __FUNCTION__ << std::endl;
154  }
155  int binvalue = std::numeric_limits<int>::quiet_NaN();
156  float value = std::numeric_limits<float>::quiet_NaN();
157  for (int i = 0; i < NDIVS; i++)
158  {
160  {
161  binvalue = i + 1;
162  value = static_cast<float>(i + 1)/static_cast<float>(NDIVS);
163 
164  break;
165  }
166  }
167  if (Verbosity())
168  {
169  std::cout << " Centile : " << (value >= 0 ? value : -999) << std::endl;
170  }
171  _central->set_centile(CentralityInfo::PROP::mbd_NS, value);
172  _central->set_centrality_bin(CentralityInfo::PROP::mbd_NS, binvalue);
173 
175 }
176 
178 {
179  if (Verbosity())
180  {
181  std::cout << "------------CentralityReco-------------" << std::endl;
182  }
183 
184  // Get Nodes from the Tree
185  if (GetNodes(topNode))
186  {
188  }
189 
190  // Fill Arrays
191  if (FillVars())
192  {
194  }
195 
196  if (FillCentralityInfo())
197  {
199  }
200  if (Verbosity())
201  {
202  _central->identify();
203  }
204 
206 }
207 
209 {
210  if (Verbosity() > 1)
211  {
212  std::cout << __FILE__ << " :: " << __FUNCTION__ << " :: " << __LINE__ << std::endl;
213  }
214 
215  _central = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
216 
217  if (!_central)
218  {
219  std::cout << "no centrality node " << std::endl;
221  }
222 
223  _mbd_out = findNode::getClass<MbdOut>(topNode, "MbdOut");
224 
225  if (!_mbd_out)
226  {
227  std::cout << "no MBD out node " << std::endl;
229  }
231 }
232 
234 {
235  if (Verbosity())
236  {
237  std::cout << __FILE__ << " :: " << __FUNCTION__ << " :: " << __LINE__ << std::endl;
238  }
239 
240  PHNodeIterator iter(topNode);
241  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
242  if (!dstNode)
243  {
244  std::cout << PHWHERE << "DST Node missing doing nothing" << std::endl;
245  }
246 
247  PHNodeIterator dstIter(dstNode);
248 
249  PHCompositeNode *detNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", "GLOBAL"));
250  if (!detNode)
251  {
252  std::cout << PHWHERE << "Detector Node missing, making one" << std::endl;
253  detNode = new PHCompositeNode("GLOBAL");
254  dstNode->addNode(detNode);
255  }
256 
257  CentralityInfo *central = new CentralityInfov2();
258 
259  PHIODataNode<PHObject> *centralityNode = new PHIODataNode<PHObject>(central, "CentralityInfo", "PHObject");
260  detNode->addNode(centralityNode);
261 
262  return;
263 }