BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
xe/ElectronCalibration.cc
Go to the documentation of this file.
1//********************************************************************************
2// This file is part of the Widget, a package for performing dE/dx calibration.
3//
4// Author: Jake Bennett
5// Date: July 8, 2015
6//
7// ElectronCalibration is a program that performs the generation, simulation,
8// fitting, and correction tasks necessary for dE/dx "electron calibration".
9//
10// For additional details, see the Widget document.
11//
12//********************************************************************************
13
14#include <fstream>
15#include <iostream>
16#include <streambuf>
17#include <string>
18
20
21int main( int argc, char* argv[] ) {
22
23 std::cout << std::endl << "*** Running the electron calibration ***" << std::endl << std::endl;
24
25 std::string configfile("electron.template.txt");
26 std::string ask("y");
27
28 // ***************************
29 // Parse command line options
30 // ***************************
31
32 for (int i = 1; i < argc; i++){
33
34 std::string arg(argv[i]);
35
36 if (arg == "-c"){
37 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
38 else configfile = argv[++i]; }
39 if (arg == "-i"){
40 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
41 else ask = argv[++i]; }
42 if (arg == "-h"){
43 std::cout << std::endl << " Usage for: " << argv[0] << std::endl << std::endl;
44 std::cout << "\t -c <file>\t Configuration file" << std::endl;
45 std::cout << "\t -i <int>\t Ask before each step (y/n)" << std::endl;
46 exit(1);
47 }
48 }
49
50 if( configfile == "" ){
51 std::cout << "ERROR: No configuration file was given..." << std::endl;
52 return 1;
53 }
54
55 // Hesitate after each if ask flag is true
56 std::string ready("y");
57
58 // Create a calibration interface
59 ElectronInterface widget;
60
61
62 // ---------------------------------------------------------------------------
63 // 0. Set the parameters either from a config file
64
65 if( configfile != "" )
66 widget.SetupFromConfigFile(configfile);
67 else{
68 std::cout << "ElectronCalibration ERROR: No configuration file provided";
69 return 1;
70 }
71 // ---------------------------------------------------------------------------
72 std::cout << "Done configuring settings. Output redirected to log file." << std::endl;
73
74 // redirect output to log file, but save a pointer to the old
75 // buffer associated with std::cout and restore it for some output
76 std::streambuf *coutbuf = std::cout.rdbuf();
77 std::ofstream out("widget.electron.log");
78
79
80 // ---------------------------------------------------------------------------
81 // 0b. Generate samples
82
83 if( ask == "y" ){
84 std::cout << "Do you want to generate the sample (y/n)? ";
85 std::cin >> ready; std::cout << std::endl;
86 }
87 if( ready == "y" ){
88 std::cout << "Generating the sample..." << std::endl;
89
90 std::cout.rdbuf( out.rdbuf() );
91 widget.GenerateSample("electrons.root");
92 std::cout.rdbuf( coutbuf );
93 }
94 // ---------------------------------------------------------------------------
95
96 // Get the name of the original input file (or the generated one)
97 TString originfile = widget.GetFileName();
98
99
100
101 // ---------------------------------------------------------------------------
102 // Apply old constants
103
104 if( ask == "y" ){
105 std::cout << "Do you want to apply the old constants (y/n)? ";
106 std::cin >> ready; std::cout << std::endl;
107 }
108 if( ready == "y" ){
109 std::cout << "Applying old constants..." << std::endl;
110
111 std::cout.rdbuf( out.rdbuf() );
112 widget.ApplyCorrections("electrons.precalib.root");
113 widget.SetFileName("electrons.precalib.root");
114 std::cout.rdbuf( coutbuf );
115 }
116 // ---------------------------------------------------------------------------
117
118
119
120 // ---------------------------------------------------------------------------
121 // 1. Run gains
122
123 if( ask == "y" ){
124 std::cout << "Do you want to determine the run gains (y/n)? ";
125 std::cin >> ready; std::cout << std::endl;
126 }
127 if( ready == "y" ){
128 std::cout << "Getting run gains..." << std::endl;
129
130 std::cout.rdbuf( out.rdbuf() );
131 widget.RunGains("rungains.root");
132
133 // reapply constants with new run gains
134 widget.SetFileName(originfile);
135 widget.ApplyCorrections("electrons.rungains.root");
136 widget.SetFileName("electrons.rungains.root");
137
138 std::cout.rdbuf( coutbuf );
139 }
140 // ---------------------------------------------------------------------------
141
142
143
144 // ---------------------------------------------------------------------------
145 // 2. Do fits of doca vs. entrance angle
146
147 if( ask == "y" ){
148 std::cout << "Do you want to do the 2d correction (y/n)? ";
149 std::cin >> ready; std::cout << std::endl;
150 }
151 if( ready == "y" ){
152 std::cout << "Doing 2d correction..." << std::endl;
153
154 std::cout.rdbuf( out.rdbuf() );
155 widget.TwoDCorrection("twodcorrection.root");
156
157 // reapply constants with new 2D correction
158 widget.SetFileName(originfile);
159 widget.ApplyCorrections("electrons.twod.root");
160 widget.SetFileName("electrons.twod.root");
161
162 std::cout.rdbuf( coutbuf );
163 }
164 // ---------------------------------------------------------------------------
165
166
167 // ---------------------------------------------------------------------------
168 // 3. Do fits of dE/dx vs. cos(theta): saturation correction
169
170 if( ask == "y" ){
171 std::cout << "Do you want to do the saturation correction (y/n)? ";
172 std::cin >> ready; std::cout << std::endl;
173 }
174 if( ready == "y" ){
175 std::cout << "Doing saturation correction..." << std::endl;
176
177 std::cout.rdbuf( out.rdbuf() );
178 widget.SaturationCorrection("saturation.root");
179
180 // reapply constants with new saturation correction
181 widget.SetFileName(originfile);
182 widget.ApplyCorrections("electrons.saturation.root");
183 widget.SetFileName("electrons.saturation.root");
184
185 std::cout.rdbuf( coutbuf );
186 }
187 // ---------------------------------------------------------------------------
188
189 std::cout << std::endl << std::endl << "DONE ELECTRON CALIBRATION" << std::endl;
190
191 out.close();
192}
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
void SetupFromConfigFile(std::string configfile)
void RunGains(TString outfilename)
void ApplyCorrections(TString outfile)
void SaturationCorrection(TString outfilename)
void SetFileName(TString newfilename)
void TwoDCorrection(TString outfilename)
void GenerateSample(TString outfile)
int main()
Definition: test_IFile.cxx:11