ATLAS Offline Software
MagnetSet.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
12 
13 #include <fstream>
14 #include <algorithm>
15 
16 namespace ForwardTracker {
17 
19 
20  Magnet::Container_t magnets; // (x, y, z) = (left, up, forward)
21 
22  std::shared_ptr<std::ifstream> twissFile = TwissFile(cData, side);
23 
24  std::ifstream& pfile = *twissFile;
25 
27 
28  std::cout << "beamEnergy[GeV] = " << beamEnergy << std::endl;
29 
30  while (pfile.peek() == '@' || pfile.peek() == '*' || pfile.peek() == '$') pfile.ignore(1000, '\n');
31 
32  std::ios::fmtflags cout_flags = std::cout.flags();
33 
34  std::cout << std::left
35  << std::setw(15) << "magName"
36  << std::setw(15) << "magSort"
37  << std::right
38  << std::setw(10) << "magType"
39  << std::setw(15) << "magEndPos"
40  << std::setw(15) << "magLength"
41  << std::setw(15) << "magStrength"
42  << std::setw(15) << "magAperType"
43  << std::setw(10) << "magAper1"
44  << std::setw(10) << "magAper2"
45  << std::setw(10) << "magAper3"
46  << std::setw(10) << "magAper4"
47  << std::endl;
48 
49  while (true) { // Read the magnet data from twiss_b1.txt for beam 1 (side 1) and twiss_b2.txt for beam 2 (side 0).
50 
51  std::string magName, magSort, magBasic;
52  double magEndPos, magLength;
53  double HKICK, VKICK;
54  double K0L, K1L, K2L, K3L;
55  double X, PX, BETX, ALFX, MUX, DX, DPX;
56  double Y, PY, BETY, ALFY, MUY, DY, DPY;
57  std::string magAperType;
58  double magAper1, magAper2, magAper3, magAper4;
59 
60  pfile >> magName >> magSort >> magBasic >> magEndPos >> magLength
61  >> HKICK >> VKICK
62  >> K0L >> K1L >> K2L >> K3L
63  >> X >> Y >> PX >> PY
64  >> BETX >> BETY >> ALFX >> ALFY >> MUX >> MUY
65  >> DX >> DY >> DPX >> DPY
66  >> magAperType
67  >> magAper1 >> magAper2 >> magAper3 >> magAper4;
68 
69  if (magEndPos < 0) throw std::runtime_error("Magnet End Position cannot be negative.");
70  else if (magEndPos > cData.endMarker) break;
71 
73  double magStrength = 0;
74 
75  if (K0L != 0) { magType = Magnet::hbDipole; magStrength = K0L; }
76  else if (K1L != 0) { magType = (K1L > 0) ? Magnet::hfQuadrupole : Magnet::vfQuadrupole; magStrength = K1L; }
77  else if (HKICK != 0) { magType = Magnet::hbDipole; magStrength = -HKICK; }
78  else if (VKICK != 0) { magType = Magnet::vbDipole; magStrength = +VKICK; }
79 
80  if (magType == Magnet::notAMagnet) continue;
81 
82  std::cout.precision(6);
83  if (magName.find("DRIFT") != 1)
84  std::cout << std::fixed
85  << std::left
86  << std::setw(15) << magName
87  << std::setw(15) << magSort
88  << std::right
89  << std::setw(10) << magType
90  << std::setw(15) << magEndPos
91  << std::setw(15) << magLength
92  << std::setw(15) << magStrength
93  << std::setw(15) << magAperType
94  << std::setw(10) << magAper1
95  << std::setw(10) << magAper2
96  << std::setw(10) << magAper3
97  << std::setw(10) << magAper4
98  << std::endl;
99 
100  if (magLength < 0) throw std::runtime_error("magLength must be positive.");
101  else if (magLength == 0) {
102  if (magType == Magnet::hfQuadrupole) throw std::runtime_error("magLength cannot be zero for hfQuadrupole.");
103  if (magType == Magnet::vfQuadrupole) throw std::runtime_error("magLength cannot be zero for vfQuadrupole.");
104  }
105 
106  double z = (magEndPos - 0.5*magLength)*ForwardTrackerConstants::aside[side];
107 
108  Magnet::ConstPtr_t mptr = MagnetFactory(TransverseShift(z)[0], // account of beam splitting around 155 m
109  TransverseShift(z)[1],
110  z,
111  magStrength,
112  magLength,
113  magAperType,
114  magAper1,
115  magAper2,
116  magAper3,
117  magAper4,
118  beamEnergy,
119  side,
120  magType);
121 
122  magnets.push_back(mptr);
123  }
124 
125  std::sort(magnets.begin(), magnets.end(), absZGreater<Magnet::ConstPtr_t>);
126 
127  std::cout.flags(cout_flags);
128 
129  return magnets;
130  }
131 }
ForwardTracker::Magnet::Type
Type
Definition: ForwardTracker/ForwardTracker/Magnet.h:36
ForwardTracker::TransverseShift
TransversePoint TransverseShift(double z)
Definition: TransverseShift.cxx:13
LArNewCalib_Delay_OFC_Cali.pfile
string pfile
Definition: LArNewCalib_Delay_OFC_Cali.py:173
ForwardTracker::Magnet::vfQuadrupole
@ vfQuadrupole
Definition: ForwardTracker/ForwardTracker/Magnet.h:36
ForwardTracker::ForwardTrackerConstants::aside
static const double aside[2]
Definition: ForwardTrackerConstants.h:20
MagnetFactory.h
STLHelpers.h
Monitored::X
@ X
Definition: HistogramFillerUtils.h:24
ForwardTracker::Magnet::hbDipole
@ hbDipole
Definition: ForwardTracker/ForwardTracker/Magnet.h:36
TransverseShift.h
TRT::Hit::side
@ side
Definition: HitInfo.h:83
ForwardTracker::Magnet::Container_t
std::vector< ConstPtr_t > Container_t
Definition: ForwardTracker/ForwardTracker/Magnet.h:39
ConfigData.h
z
#define z
ForwardTracker::TwissFile
std::shared_ptr< std::ifstream > TwissFile(const ConfigData &, const Side &)
Definition: TwissFile.cxx:14
ForwardTracker::Magnet::notAMagnet
@ notAMagnet
Definition: ForwardTracker/ForwardTracker/Magnet.h:36
MagnetSet.h
Side
Definition: WaferTree.h:36
ForwardTracker::Magnet::hfQuadrupole
@ hfQuadrupole
Definition: ForwardTracker/ForwardTracker/Magnet.h:36
Monitored::Y
@ Y
Definition: HistogramFillerUtils.h:24
RunTileTBMonitoring.beamEnergy
beamEnergy
Definition: RunTileTBMonitoring.py:248
ForwardTracker::Magnet::vbDipole
@ vbDipole
Definition: ForwardTracker/ForwardTracker/Magnet.h:36
TwissFile.h
ForwardTrackerConstants.h
ForwardTracker::GetBeamEnergy
double GetBeamEnergy(std::ifstream &)
Definition: TwissFile.cxx:112
ForwardTracker::MagnetSet
Magnet::Container_t MagnetSet(const ConfigData &, const Side &)
Definition: MagnetSet.cxx:18
ForwardTracker::Magnet::ConstPtr_t
std::shared_ptr< const Magnet > ConstPtr_t
Definition: ForwardTracker/ForwardTracker/Magnet.h:38
ForwardTracker
Definition: ForwardTracker/ForwardTracker/Beamline.h:12
ForwardTracker::ConfigData::endMarker
double endMarker
Definition: ForwardTracker/ForwardTracker/ConfigData.h:21
ForwardTracker::ConfigData
Definition: ForwardTracker/ForwardTracker/ConfigData.h:12
ForwardTracker::MagnetFactory
Magnet::ConstPtr_t MagnetFactory(double x, double y, double z, double strength, double length, const std::string &aperType, double A1, double A2, double A3, double A4, double beamEnergy, Side side, Magnet::Type type)
Definition: MagnetFactory.cxx:39