LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MagneticField_service.cc
Go to the documentation of this file.
1 
22 // Framework includes
24 
25 // nutools includes
27 
28 #include "TGeoManager.h"
29 
30 #include <vector>
31 #include <string>
32 
33 namespace mag {
34 
36  {
37  this->reconfigure(pset);
38  }
39 
40  //------------------------------------------------------------
42  {
43  auto fieldDescriptions = pset.get<std::vector<fhicl::ParameterSet> >("FieldDescriptions");
44 
45  MagneticFieldDescription fieldDescription;
46  for(auto itr : fieldDescriptions){
47  fieldDescription.fMode = (mag::MagFieldMode_t)(itr.get<int>("UseField"));
48 
49  // if the mode is turned to off, no point looking for a volume or
50  // trying to put a description into the fFieldDescriptions data member.
51  // if all input field descriptions are set to fMode = kNoBFieldMode, then the
52  // methods to return the fields will not go into the loop over fFieldDescriptions
53  // and will just return a 0 field.
54  if(fieldDescription.fMode == mag::kNoBFieldMode) continue;
55 
56  fieldDescription.fVolume = itr.get<std::string>("MagnetizedVolume");
57  fieldDescription.fGeoVol = gGeoManager->FindVolumeFast(fieldDescription.fVolume.c_str());
58 
59  // check that we have a good volume
60  if( fieldDescription.fGeoVol == nullptr )
61  throw cet::exception("MagneticField")
62  << "cannot locat volume "
63  << fieldDescription.fVolume
64  << " in gGeoManager, bail";
65 
66  // These need to be read as types that FHICL know about, but they
67  // are used by Geant, so I store them in Geant4 types.
68  std::vector<double> field = itr.get<std::vector<double> >("ConstantField");
69 
70  // Force the dimension of the field definition
71  field.resize(3);
72  for(size_t i = 0; i < 3; ++i) fieldDescription.fField[i] = field[i];
73 
74  fFieldDescriptions.push_back(fieldDescription);
75  }
76 
77  return;
78  }
79 
80  //------------------------------------------------------------
81  G4ThreeVector const MagneticField::FieldAtPoint(G4ThreeVector const& p) const
82  {
83  // check that the input point is in the magnetized volume
84  // Use the gGeoManager to determine what node the point
85  // is in
86  double point[3] = { p.x(), p.y(), p.z() };
87 
88  // loop over the field descriptions to see if the point is in any of them
89  for(auto fd : fFieldDescriptions){
90  // we found a node, see if its name is the same as
91  // the volume with the field
92  if(fd.fGeoVol->Contains(point)) return fd.fField;
93  }
94 
95  // if we get here, we can't find a field
96  return G4ThreeVector(0);
97  }
98 
99  //------------------------------------------------------------
100  G4ThreeVector const MagneticField::UniformFieldInVolume(std::string const& volName) const
101  {
102  // if the input volume name is the same as the magnetized volume
103  // return the uniform field
104 
105  for(auto fd : fFieldDescriptions){
106  if (fd.fVolume.compare(volName) == 0) return fd.fField;
107  }
108 
109  // if we get here, we can't find a field
110  return G4ThreeVector(0);
111  }
112 
113 }// namespace
114 
115 namespace mag {
116 
118 
119 } // namespace mag
G4ThreeVector const FieldAtPoint(G4ThreeVector const &p=G4ThreeVector(0)) const
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
std::vector< MagneticFieldDescription > fFieldDescriptions
Descriptions of the fields.
Definition: MagneticField.h:70
Describe the magnetic field structure of a detector.
T get(std::string const &key) const
Definition: ParameterSet.h:231
MagneticField(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
enum mag::MagneticFieldMode MagFieldMode_t
G4ThreeVector const UniformFieldInVolume(std::string const &volName) const
void reconfigure(fhicl::ParameterSet const &pset)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33