LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MagneticFieldStandard.cxx
Go to the documentation of this file.
1 // \file MagneticFieldStandard.cxx
3 //
4 // \brief implementation of class for storing/accessing magnetic fields
5 //
6 // \author ebrianne@fnal.gov
7 //
9 
10 //nug4 includes
12 
13 //ROOT includes
14 #include "TGeoManager.h"
15 
16 // Framework includes
17 #include "fhiclcpp/ParameterSet.h"
18 
19 //std includes
20 #include <vector>
21 #include <string>
22 
23 namespace mag {
24 
25  //-----------------------------------------------
27  {
28  this->reconfigure(pset);
29  }
30 
31  //------------------------------------------------
33  {
34  auto fieldDescriptions = pset.get<std::vector<fhicl::ParameterSet> >("FieldDescriptions");
35 
36  MagneticFieldDescription fieldDescription;
37  for(auto itr : fieldDescriptions){
38  fieldDescription.fMode = (mag::MagFieldMode_t)(itr.get<int>("UseField"));
39  // if the mode is turned to off, no point looking for a volume or
40  // trying to put a description into the fFieldDescriptions data member.
41  // if all input field descriptions are set to fMode = kNoBFieldMode, then the
42  // methods to return the fields will not go into the loop over fFieldDescriptions
43  // and will just return a 0 field.
44  if(fieldDescription.fMode == mag::kNoBFieldMode) continue;
45  fieldDescription.fVolume = itr.get<std::string>("MagnetizedVolume");
46  fieldDescription.fGeoVol = gGeoManager->FindVolumeFast(fieldDescription.fVolume.c_str());
47  // check that we have a good volume
48  if( fieldDescription.fGeoVol == nullptr )
49  throw cet::exception("MagneticField")
50  << "cannot locat volume "
51  << fieldDescription.fVolume
52  << " in gGeoManager, bail";
53  // These need to be read as types that FHICL know about, but they
54  // are used by Geant, so I store them in Geant4 types.
55  std::vector<double> field = itr.get<std::vector<double> >("ConstantField");
56 
57  // Force the dimension of the field definition
58  field.resize(3);
59  for(size_t i = 0; i < 3; ++i) fieldDescription.fField[i] = field[i];
60 
61  fFieldDescriptions.push_back(fieldDescription);
62  }
63 
64  return;
65  }
66 
67  //------------------------------------------------------------
68  G4ThreeVector const MagneticFieldStandard::FieldAtPoint(G4ThreeVector const& p) const
69  {
70  // check that the input point is in the magnetized volume
71  // Use the gGeoManager to determine what node the point
72  // is in
73  double point[3] = { p.x(), p.y(), p.z() };
74  // loop over the field descriptions to see if the point is in any of them
75  for(auto fd : fFieldDescriptions){
76  // we found a node, see if its name is the same as
77  // the volume with the field
78  if(fd.fGeoVol->Contains(point)) return fd.fField;
79  }
80  // if we get here, we can't find a field
81  return G4ThreeVector(0);
82  }
83 
84  //------------------------------------------------------------
85  G4ThreeVector const MagneticFieldStandard::UniformFieldInVolume(std::string const& volName) const
86  {
87  // if the input volume name is the same as the magnetized volume
88  // return the uniform field
89 
90  for(auto fd : fFieldDescriptions){
91  if (fd.fVolume.compare(volName) == 0) return fd.fField;
92  }
93 
94  // if we get here, we can't find a field
95  return G4ThreeVector(0);
96  }
97 }//namespace mag
MagneticFieldStandard(fhicl::ParameterSet const &pset)
void reconfigure(fhicl::ParameterSet const &pset)
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::vector< MagneticFieldDescription > fFieldDescriptions
Descriptions of the fields.
G4ThreeVector const FieldAtPoint(G4ThreeVector const &p=G4ThreeVector(0)) const override
enum mag::MagneticFieldMode MagFieldMode_t
G4ThreeVector const UniformFieldInVolume(std::string const &volName) const override
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33