Class Reference for E1039 Core & Analysis Software
PHFieldUtility.cc
Go to the documentation of this file.
1 #include "PHFieldUtility.h"
2 
3 #include "PHFieldConfig_v1.h"
4 
5 #include "PHField2D.h"
6 #include "PHField3DCartesian.h"
7 #include "PHField3DCylindrical.h"
8 #include "PHFieldUniform.h"
9 #include "PHFieldRegionalConst.h"
10 #include "PHFieldSeaQuest.h"
11 
12 // PHENIX includes
13 #include <fun4all/Fun4AllServer.h>
15 #include <phool/PHCompositeNode.h>
16 #include <phool/PHIODataNode.h>
17 #include <phool/PHNodeIterator.h>
19 #include <phool/getClass.h>
20 #include <phool/recoConsts.h>
21 
22 #include <cassert>
23 #include <cstdio>
24 #include <fstream>
25 #include <iostream>
26 #include <sstream>
27 #include <stdexcept>
28 
29 #include <sys/types.h>
30 #include <unistd.h> // for generate unique local file
31 using namespace std;
32 
34 {
35 }
36 
38 {
39 }
40 
41 PHField *
42 PHFieldUtility::BuildFieldMap(const PHFieldConfig *field_config, const int verbosity)
43 {
44  assert(field_config);
45 
46  if (verbosity)
47  {
48  cout << "PHFieldUtility::BuildFieldMap - construction field with configuration: ";
49  field_config->identify();
50  }
51 
52  PHField *field(nullptr);
53 
54  switch (field_config->get_field_config())
55  {
57  // return "Constant field";
58 
59  field = new PHFieldUniform(
60  field_config->get_field_mag_x(),
61  field_config->get_field_mag_y(),
62  field_config->get_field_mag_z());
63 
64  break;
66  // return "2D field map expressed in cylindrical coordinates";
67  field = new PHField2D(
68  field_config->get_filename(),
69  verbosity,
70  field_config->get_magfield_rescale());
71 
72  break;
74  // return "3D field map expressed in cylindrical coordinates";
75  field = new PHField3DCylindrical(
76  field_config->get_filename(),
77  verbosity,
78  field_config->get_magfield_rescale());
79 
80  break;
82  // return "3D field map expressed in Cartesian coordinates";
83  field = new PHField3DCartesian(
84  field_config->get_filename(),
85  field_config->get_magfield_rescale());
86  break;
88  // return "3D field map expressed in Cartesian coordinates";
89  field = new PHFieldRegionalConst(
90  5.0,
91  1.0);
92  break;
94  field = new PHFieldSeaQuest(
95  field_config->get_filename1(),
96  field_config->get_filename2(),
97  field_config->get_magfield_rescale1(),
98  field_config->get_magfield_rescale2(),
99  field_config->get_taregetmag_y()
100  );
101  break;
102  default:
103  cout << "PHFieldUtility::BuildFieldMap - Invalid Field Configuration" << endl;
104  // return nullptr;
105  // return "Invalid Field";
106  }
107  assert(field); // Check for Invalid Field
108  return field;
109 }
110 
118 {
120  "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root",
121  1.4 / 1.5);
122 }
123 
125 PHField *
126 PHFieldUtility::GetFieldMapNode(const PHFieldConfig *default_config, PHCompositeNode *topNode, const int verbosity)
127 {
128  if (topNode == nullptr) topNode = Fun4AllServer::instance()->topNode();
129  assert(topNode);
130  PHNodeIterator iter(topNode);
131 
132  // Looking for the RUN node
133  PHCompositeNode *parNode = static_cast<PHCompositeNode *>(iter.findFirst(
134  "PHCompositeNode", "PAR"));
135  if (!parNode)
136  {
137  stringstream serr;
138  serr << __PRETTY_FUNCTION__ << ": PAR Node missing, request aborting.";
139  cout << serr.str() << endl;
140 
141  throw runtime_error(serr.str());
142 
143  return NULL;
144  }
145 
146  PHField *field = findNode::getClass<PHField>(parNode, GetDSTFieldMapNodeName());
147  if (!field)
148  {
149  PHFieldConfig *field_config =
150  GetFieldConfigNode(default_config, topNode, verbosity);
151  assert(field_config);
152 
153  field = BuildFieldMap(field_config, verbosity>0?verbosity-1:verbosity);
154  assert(field);
155 
156  parNode->addNode(new PHDataNode<PHObject>(field, GetDSTFieldMapNodeName(), "PHObject"));
157  }
158 
159  return field;
160 }
161 
164 PHFieldUtility::GetFieldConfigNode(const PHFieldConfig *default_config, PHCompositeNode *topNode, const int verbosity)
165 {
166  if (topNode == nullptr) topNode = Fun4AllServer::instance()->topNode();
167  assert(topNode);
168 
169  PHNodeIterator iter(topNode);
170 
171  // Looking for the RUN node
172  PHCompositeNode *runNode = static_cast<PHCompositeNode *>(iter.findFirst(
173  "PHCompositeNode", "RUN"));
174  if (!runNode)
175  {
176  stringstream serr;
177  serr << __PRETTY_FUNCTION__ << ": RUN Node missing, request aborting.";
178  cout << serr.str() << endl;
179 
180  throw runtime_error(serr.str());
181 
182  return NULL;
183  }
184 
185  PHFieldConfig *field = findNode::getClass<PHFieldConfig>(runNode,
186  GetDSTConfigNodeName());
187  if (!field)
188  {
189  if (!default_config)
190  {
191  field = DefaultFieldConfig();
192  if (verbosity)
193  {
194  cout <<"PHFieldUtility::GetFieldConfigNode - field map with configuration from build-in default: ";
195  field->identify();
196  }
197  }
198  else
199  {
200  field = static_cast<PHFieldConfig *>(default_config->Clone());
201  if (verbosity)
202  {
203  cout <<"PHFieldUtility::GetFieldConfigNode - field map with configuration from input default: ";
204  field->identify();
205  }
206  }
207 
208  assert(field);
209  runNode->addNode(new PHIODataNode<PHObject>(field,
210  GetDSTConfigNodeName(), "PHObject"));
211  }
212  else
213  {
214  if (verbosity)
215  {
216  cout <<"PHFieldUtility::GetFieldConfigNode - field map with configuration from DST/RUN: ";
217  field->identify();
218  }}
219 
220  return field;
221 }
#define NULL
Definition: Pdb.h:9
static Fun4AllServer * instance()
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
PHBoolean addNode(PHNode *)
untested code - I don't know if this is being used, drop me a line (with the field) and I test this -...
PHFieldConfig_v1 implements field configuration information for input a field map file.
PHFieldConfig store field configuration information.
Definition: PHFieldConfig.h:20
virtual double get_taregetmag_y() const
field value in Tesla for target field model ONLY for PHFieldConfig_v3
@ kFieldUniform
Constant field.
Definition: PHFieldConfig.h:41
@ kField2D
2D field map expressed in cylindrical coordinates
Definition: PHFieldConfig.h:43
@ kField3DCartesian
3D field map expressed in Cartesian coordinates
Definition: PHFieldConfig.h:47
@ kField3DCylindrical
3D field map expressed in cylindrical coordinates
Definition: PHFieldConfig.h:45
virtual void identify(std::ostream &os=std::cout) const
virtual double get_magfield_rescale1() const
field value in Tesla for uniform field model ONLY for PHFieldConfig_v3
virtual double get_field_mag_x() const
field value in Tesla for uniform field model ONLY for PHFieldConfig_v2
virtual double get_field_mag_z() const
field value in Tesla for uniform field model ONLY for PHFieldConfig_v2
virtual FieldConfigTypes get_field_config() const
virtual double get_magfield_rescale() const
virtual const std::string & get_filename2() const
Definition: PHFieldConfig.h:94
virtual const std::string & get_filename() const
virtual const std::string & get_filename1() const
field value in Tesla for target field model ONLY for PHFieldConfig_v3
Definition: PHFieldConfig.h:93
virtual double get_magfield_rescale2() const
field value in Tesla for uniform field model ONLY for PHFieldConfig_v3
virtual double get_field_mag_y() const
field value in Tesla for uniform field model ONLY for PHFieldConfig_v2
untested code - I don't know if this is being used, drop me a line (with the field) and I test this -...
static PHField * GetFieldMapNode(const PHFieldConfig *default_config=nullptr, PHCompositeNode *topNode=nullptr, const int verbosity=0)
Get transient PHField from DST nodes. If not found, make a new one based on default_config.
static PHFieldConfig * DefaultFieldConfig()
static PHFieldConfig * GetFieldConfigNode(const PHFieldConfig *default_config=nullptr, PHCompositeNode *topNode=nullptr, const int verbosity=0)
Get persistent PHGeomIOTGeo from DST nodes. If not found, make a new one.
virtual ~PHFieldUtility()
static PHField * BuildFieldMap(const PHFieldConfig *field_config, const int verbosity=0)
Build or build field map with a configuration object.
transient DST object for field storage and access
Definition: PHField.h:14
PHNode * findFirst(const std::string &, const std::string &)