BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
xe/ElectronCorrection.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// ElectronCorrection is a program that applies electron dE/dx corrections.
8//
9// For additional details, see the Widget document.
10//
11//********************************************************************************
12
13#include <fstream>
14#include <iostream>
15#include <streambuf>
16#include <string>
17
19
20int main( int argc, char* argv[] ) {
21
22 std::cout << std::endl << "*** Running the electron calibration ***" << std::endl << std::endl;
23
24 std::string configfile("electron.template.txt");
25 int ask = 0;
26
27 // ***************************
28 // Parse command line options
29 // ***************************
30
31 for (int i = 1; i < argc; i++){
32
33 std::string arg(argv[i]);
34
35 if (arg == "-c"){
36 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
37 else configfile = argv[++i]; }
38 if (arg == "-i"){
39 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
40 else ask = atoi(argv[++i]); }
41 if (arg == "-h"){
42 std::cout << std::endl << " Usage for: " << argv[0] << std::endl << std::endl;
43 std::cout << "\t -c <file>\t Configuration file" << std::endl;
44 std::cout << "\t -i <int>\t Ask before each step? (0 = no, 1 = yes)" << std::endl;
45 exit(1);
46 }
47 }
48
49 if( configfile == "" ){
50 std::cout << "ERROR: No configuration file was given..." << std::endl;
51 return 1;
52 }
53
54 // Hesitate after each if ask flag is true
55 std::string ready("y");
56
57 // Create a calibration interface
58 ElectronInterface widget;
59
60
61 // ---------------------------------------------------------------------------
62 // 0. Set the parameters either from a config file
63
64 if( configfile != "" )
65 widget.SetupFromConfigFile(configfile);
66 else{
67 std::cout << "ElectronCorrection ERROR: No configuration file provided";
68 return 1;
69 }
70 // ---------------------------------------------------------------------------
71 std::cout << "Done configuring settings..." << std::endl;
72
73 // redirect output to log file, but save a pointer to the old
74 // buffer associated with std::cout and restore it for some output
75 std::streambuf *coutbuf = std::cout.rdbuf();
76 std::ofstream out("widget.electron.log");
77
78
79 // ---------------------------------------------------------------------------
80 // 1. Apply corrections
81
82 if( ask == 1 ){
83 std::cout << "Do you want to apply corrections (y/n)? ";
84 std::cin >> ready; std::cout << std::endl;
85 }
86 if( ask == 0 || ready == "y" ){
87 std::cout << "Applying corrections..." << std::endl;
88
89 std::cout.rdbuf( out.rdbuf() );
90 widget.ApplyCorrections("electron.corrected.root");
91 std::cout.rdbuf( coutbuf );
92 }
93 // ---------------------------------------------------------------------------
94
95 std::cout << std::endl << std::endl << "DONE ELECTRON CORRECTION" << std::endl;
96
97 out.close();
98}
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
void SetupFromConfigFile(std::string configfile)
void ApplyCorrections(TString outfile)
int main()
Definition: test_IFile.cxx:11