EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHFieldUtility.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHFieldUtility.cc
1 #include "PHFieldUtility.h"
2 
3 #include "PHField.h"
4 #include "PHField2D.h"
5 #include "PHField3DCartesian.h"
6 #include "PHField3DCylindrical.h"
7 #include "PHFieldBeast.h"
8 #include "PHFieldCleo.h"
9 #include "PHFieldConfig.h"
10 #include "PHFieldConfigv1.h"
11 #include "PHFieldUniform.h"
12 
13 #include <fun4all/Fun4AllServer.h>
14 
15 #include <phool/PHCompositeNode.h>
16 #include <phool/PHDataNode.h>
17 #include <phool/PHIODataNode.h>
18 #include <phool/PHNodeIterator.h>
19 #include <phool/PHObject.h>
20 #include <phool/getClass.h>
21 #include <phool/phool.h> // for PHWHERE
22 
23 #include <TSystem.h>
24 
25 #include <cassert>
26 #include <cstdlib> // for getenv
27 #include <iostream>
28 
29 using namespace std;
30 
31 PHField *
32 PHFieldUtility::BuildFieldMap(const PHFieldConfig *field_config, const int verbosity)
33 {
34  assert(field_config);
35 
36  if (verbosity)
37  {
38  cout << "PHFieldUtility::BuildFieldMap - construction field with configuration: ";
39  field_config->identify();
40  }
41 
42  PHField *field(nullptr);
43 
44  switch (field_config->get_field_config())
45  {
47  // return "Constant field";
48 
49  field = new PHFieldUniform(
50  field_config->get_field_mag_x(),
51  field_config->get_field_mag_y(),
52  field_config->get_field_mag_z());
53 
54  break;
56  // return "2D field map expressed in cylindrical coordinates";
57  field = new PHField2D(
58  field_config->get_filename(),
59  verbosity,
60  field_config->get_magfield_rescale());
61  break;
62 
64  // return "3D field map expressed in cylindrical coordinates";
65  field = new PHField3DCylindrical(
66  field_config->get_filename(),
67  verbosity,
68  field_config->get_magfield_rescale());
69  break;
70 
72  // return "3D field map expressed in Cartesian coordinates";
73  field = new PHField3DCartesian(
74  field_config->get_filename(),
75  field_config->get_magfield_rescale());
76  break;
77 
79  // return "2D Beast field map expressed in Cartesian coordinates";
80  cout << "calling PHFieldBeast scale " << field_config->get_magfield_rescale() << endl;
81  field = new PHFieldBeast(
82  field_config->get_filename(),
83  verbosity,
84  field_config->get_magfield_rescale());
85  break;
86 
88  // return "2D Beast field map expressed in Cartesian coordinates";
89  cout << "calling PHFieldCleo scale " << field_config->get_magfield_rescale() << endl;
90  field = new PHFieldCleo(
91  field_config->get_filename(),
92  verbosity,
93  field_config->get_magfield_rescale());
94  break;
95 
96  default:
97  cout << "PHFieldUtility::BuildFieldMap - Invalid Field Configuration" << endl;
98  // return nullptr;
99  // return "Invalid Field";
100  }
101  assert(field); // Check for Invalid Field
102  return field;
103 }
104 
110 {
112  (string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root")),
113  -1.4 / 1.5);
114 }
115 
117 PHField *
118 PHFieldUtility::GetFieldMapNode(const PHFieldConfig *default_config, PHCompositeNode *topNode, const int verbosity)
119 {
120  if (topNode == nullptr)
121  {
122  topNode = Fun4AllServer::instance()->topNode();
123  }
124  assert(topNode);
125  PHNodeIterator iter(topNode);
126 
127  // Looking for the RUN node
128  PHCompositeNode *parNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "PAR"));
129  if (!parNode)
130  {
131  cout << PHWHERE << ": PAR Node missing, request aborting.";
132  gSystem->Exit(1);
133  }
134 
135  PHField *field = findNode::getClass<PHField>(parNode, GetDSTFieldMapNodeName());
136  if (!field)
137  {
138  PHFieldConfig *field_config = GetFieldConfigNode(default_config, topNode, verbosity);
139  assert(field_config);
140 
141  field = BuildFieldMap(field_config, verbosity > 0 ? verbosity - 1 : verbosity);
142  assert(field);
143 
144  parNode->addNode(new PHDataNode<PHField>(field, GetDSTFieldMapNodeName()));
145  }
146 
147  return field;
148 }
149 
152 PHFieldUtility::GetFieldConfigNode(const PHFieldConfig *default_config, PHCompositeNode *topNode, const int verbosity)
153 {
154  if (topNode == nullptr)
155  {
156  topNode = Fun4AllServer::instance()->topNode();
157  }
158  assert(topNode);
159 
160  PHNodeIterator iter(topNode);
161 
162  // Looking for the RUN node
163  PHCompositeNode *runNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
164  if (!runNode)
165  {
166  cout << PHWHERE << ": RUN Node missing, aborting.";
167  gSystem->Exit(1);
168  }
169 
170  PHFieldConfig *field = findNode::getClass<PHFieldConfig>(runNode, GetDSTConfigNodeName());
171  if (!field)
172  {
173  if (!default_config)
174  {
175  field = DefaultFieldConfig();
176  if (verbosity)
177  {
178  cout << "PHFieldUtility::GetFieldConfigNode - field map with configuration from build-in default: ";
179  field->identify();
180  }
181  }
182  else
183  {
184  field = static_cast<PHFieldConfig *>(default_config->CloneMe());
185  if (verbosity)
186  {
187  cout << "PHFieldUtility::GetFieldConfigNode - field map with configuration from input default: ";
188  field->identify();
189  }
190  }
191 
192  assert(field);
193  runNode->addNode(new PHIODataNode<PHObject>(field, GetDSTConfigNodeName(), "PHObject"));
194  }
195  else
196  {
197  if (verbosity)
198  {
199  cout << "PHFieldUtility::GetFieldConfigNode - field map with configuration from DST/RUN: ";
200  field->identify();
201  }
202  }
203 
204  return field;
205 }