BeamlineMagneticField_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 /// \file BeamlineMagneticField.h
3 /// \brief Utility to provide the magnetic field in the beamline for a
4 /// given run number/run conditions.
5 /// NB/ Currently this will use a lookup defined in a fhicl file,
6 /// it should and will be replaced by an interface to a
7 /// database when the field is stored in such a way.
8 /// \author Mike Wallbank (University of Cincinnati) <wallbank@fnal.gov>
9 /// \date August 2019
10 ////////////////////////////////////////////////////////////////////////////
11 
12 #include "BeamlineMagneticField.h"
13 
14 // -----------------------------------------------------------------------
16  fhicl::ParameterSet magnet_currents = pset.get<fhicl::ParameterSet>("MagnetCurrents");
17  std::vector<std::pair<unsigned int, float> > current_table
18  = magnet_currents.get<std::vector<std::pair<unsigned int, float> > >("table");
19  for (std::vector<std::pair<unsigned int, float > >::const_iterator current_table_it = current_table.begin();
20  current_table_it != current_table.end(); ++current_table_it)
21  fMagnetInfo[current_table_it->first] = current_table_it->second;
22  fCurrentToField = pset.get<float>("CurrentToField");
23 }
24 
25 // -----------------------------------------------------------------------
27  : BeamlineMagneticField(pset) {
28 }
29 
30 // -----------------------------------------------------------------------
32 
33  if (run < fMagnetInfo.begin()->first)
34  throw cet::exception("BeamlineMagneticField")
35  << "Requested run " << run << " has no magnet current information available.";
36 
37  unsigned int run_with_current = run;
38  while (!fMagnetInfo.count(run_with_current))
39  run_with_current -= 1;
40 
41  return fMagnetInfo[run_with_current];
42 
43 }
44 
45 // -----------------------------------------------------------------------
47 
48  float magnet_current = this->MagnetCurrent(run);
49  float b_field = this->FieldFromCurrent(magnet_current);
50 
51  return b_field;
52 
53 }
54 
55 // -----------------------------------------------------------------------
57 
58  // eqn from Mark (technote doesn't exist yet - add docdb info here once it does)
59  // eqn gives you the aboslute value of the field - use the sign of the current to determine sign of field
60  float field_magnitude = -0.0294 + abs(magnet_current)/985.3 - pow(abs(magnet_current)/3451.2,2);
61  // returns value of field with sign of current
62  float b_field = copysign(field_magnitude, magnet_current);
63 
64  return b_field;
65 
66 }
67 
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
constexpr T pow(T x)
Definition: pow.h:75
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void abs(TH1 *hist)
Utility to provide the magnetic field in the beamline for a given run number/run conditions. NB/ Currently this will use a lookup defined in a fhicl file, it should and will be replaced by an interface to a database when the field is stored in such a way.
T get(std::string const &key) const
Definition: ParameterSet.h:231
Definition: run.py:1
BeamlineMagneticField(fhicl::ParameterSet const &pset)
std::map< unsigned int, float > fMagnetInfo
float FieldFromCurrent(float magnet_current)
Convert magnet current to magnetic field using field mapping information.
float MagnetCurrent(unsigned int beamline_run)
Return the magnet current for a given beamline data run.
float MagneticField(unsigned int beamline_run)
Return the magnetic field for a given beamline data run.