ATLAS Offline Software
TwissFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include <fstream>
10 #include <iomanip>
11 
12 namespace ForwardTracker {
13 
14  std::shared_ptr<std::ifstream> TwissFile(const ConfigData& cData, const Side& side) {
15 
16  if (side != beam1 && side != beam2) throw std::runtime_error("Allowed side values are beam1 or beam2.");
17 
18  std::string fn = (side == beam1) ? cData.twissFile1 : cData.twissFile2;
19 
20  std::shared_ptr<std::ifstream> twissFile(new std::ifstream);
21 
22  ForwardTracker::openFile(fn, twissFile);
23 
24  ForwardTracker::TwissFilePrint(*twissFile, cData.endMarker);
25 
26  return twissFile;
27  }
28 
29  void TwissFilePrint(std::ifstream& pfile, double endMarker) {
30 
31  std::ios::fmtflags cout_flags = std::cout.flags();
32 
33  std::cout << std::left
34  << std::setw(15) << "NAME"
35  << std::setw(15) << "KEYWORD"
36  << std::right
37  << std::setw( 8) << "S"
38  << std::setw( 8) << "L"
39  << std::setw( 8) << "BETX"
40  << std::setw( 8) << "BETY"
41  << std::setw(10) << "HKICK"
42  << std::setw(10) << "VKICK"
43  << std::setw(10) << "K0L"
44  << std::setw(10) << "K1L"
45  << std::setw(10) << "K2L"
46  << std::setw(10) << "K3L"
47  << std::setw(15) << "APERTYPE"
48  << std::setw( 8) << "APER_1"
49  << std::setw( 8) << "APER_2"
50  << std::setw( 8) << "APER_3"
51  << std::setw( 8) << "APER_4"
52  << std::endl;
53 
54  while (pfile.peek() == '@' || pfile.peek() == '*' || pfile.peek() == '$') pfile.ignore(1000, '\n');
55 
56  while (true) {
57 
58  std::string NAME, KEYWORD, PARENT;
59  double ENDPOS, LENGTH;
60  double HKICK, VKICK;
61  double K0L, K1L, K2L, K3L;
62  double X, PX, BETX, ALFX, MUX, DX, DPX;
63  double Y, PY, BETY, ALFY, MUY, DY, DPY;
64  std::string APERTYPE;
65  double APER_1, APER_2, APER_3, APER_4;
66 
67  pfile >> NAME >> KEYWORD >> PARENT >> ENDPOS >> LENGTH
68  >> HKICK >> VKICK
69  >> K0L >> K1L >> K2L >> K3L
70  >> X >> Y >> PX >> PY
71  >> BETX >> BETY >> ALFX >> ALFY >> MUX >> MUY
72  >> DX >> DY >> DPX >> DPY
73  >> APERTYPE
74  >> APER_1 >> APER_2 >> APER_3 >> APER_4;
75 
76  if (ENDPOS > endMarker) break;
77 
78  if (NAME.find("DRIFT") == 1) continue;
79 
80  std::cout.precision(2);
81  std::cout << std::fixed
82  << std::left
83  << std::setw(15) << NAME
84  << std::setw(15) << KEYWORD
85  << std::right
86  << std::setw( 8) << ENDPOS
87  << std::setw( 8) << LENGTH
88  << std::setw( 8) << BETX
89  << std::setw( 8) << BETY;
90  std::cout.precision(6);
91  std::cout << std::setw(10) << HKICK
92  << std::setw(10) << VKICK
93  << std::setw(10) << K0L
94  << std::setw(10) << K1L
95  << std::setw(10) << K2L
96  << std::setw(10) << K3L;
97  std::cout.precision(4);
98  std::cout << std::setw(15) << APERTYPE
99  << std::setw( 8) << APER_1
100  << std::setw( 8) << APER_2
101  << std::setw( 8) << APER_3
102  << std::setw( 8) << APER_4
103  << std::endl;
104  }
105 
106  std::cout.flags(cout_flags);
107 
108  pfile.clear();
109  pfile.seekg(0, std::ios::beg);
110  }
111 
112  double GetBeamEnergy(std::ifstream& pfile) {
113 
114  double beamEnergy = -1;
115  std::string dummy;
116 
117  while (pfile >> dummy) { if (dummy == "ENERGY") { pfile >> dummy; pfile >> beamEnergy; break; } }
118 
119  if (beamEnergy == -1) throw std::runtime_error("Could not read beamEnergy from twiss file");
120 
121  pfile.clear();
122  pfile.seekg(0, std::ios::beg);
123 
124  return beamEnergy;
125  }
126 }
ForwardTracker::beam1
@ beam1
Definition: ForwardTrackerConstants.h:13
ForwardTracker::beam2
@ beam2
Definition: ForwardTrackerConstants.h:13
LArNewCalib_Delay_OFC_Cali.pfile
string pfile
Definition: LArNewCalib_Delay_OFC_Cali.py:181
STLHelpers.h
Monitored::X
@ X
Definition: HistogramFillerUtils.h:24
TRT::Hit::side
@ side
Definition: HitInfo.h:83
ForwardTracker::openFile
void openFile(const std::string &fname, streamptr &strm)
Definition: ForwardTracker/ForwardTracker/STLHelpers.h:17
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:65
ForwardTracker::TwissFile
std::shared_ptr< std::ifstream > TwissFile(const ConfigData &, const Side &)
Definition: TwissFile.cxx:14
Side
Definition: WaferTree.h:36
python.xAODType.dummy
dummy
Definition: xAODType.py:4
Monitored::Y
@ Y
Definition: HistogramFillerUtils.h:24
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
ForwardTracker::TwissFilePrint
void TwissFilePrint(std::ifstream &, double endMarker)
Definition: TwissFile.cxx:29
RunTileTBMonitoring.beamEnergy
beamEnergy
Definition: RunTileTBMonitoring.py:248
TwissFile.h
ForwardTracker::ConfigData::twissFile1
std::string twissFile1
Definition: ForwardTracker/ForwardTracker/ConfigData.h:15
ForwardTrackerConstants.h
ForwardTracker::ConfigData::twissFile2
std::string twissFile2
Definition: ForwardTracker/ForwardTracker/ConfigData.h:16
ForwardTracker::GetBeamEnergy
double GetBeamEnergy(std::ifstream &)
Definition: TwissFile.cxx:112
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