BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
PlotEfficiency.cc File Reference
#include <fstream>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TF1.h"
#include "TString.h"
#include "TCanvas.h"
#include "TRandom.h"
#include "TMath.h"
#include "TFitter.h"
#include "TLegend.h"
#include "TApplication.h"
#include "Widget/HadronWidget/HadronInterface.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file PlotEfficiency.cc.

35 {
36
37 std::cout << std::endl << "*** Running the calibration ***" << std::endl << std::endl;
38
39 std::string configfile("");
40 TString inputfile("");
41 int part = -1;
42 std::string parfile("parameters.txt");
43 int ask = 1;
44 TString saveas("");
45
46 // ***************************
47 // Parse command line options
48 // ***************************
49
50 for (int i = 1; i < argc; i++){
51
52 std::string arg(argv[i]);
53
54 if (arg == "-c"){
55 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
56 else configfile = argv[++i]; }
57 if (arg == "-f"){
58 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
59 else inputfile = argv[++i]; }
60 if (arg == "-p"){
61 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
62 else parfile = argv[++i]; }
63 if (arg == "-t"){
64 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
65 else part = atoi(argv[++i]); }
66 if (arg == "-i"){
67 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
68 else ask = atoi(argv[++i]); }
69 if (arg == "-s"){
70 if ((i+1 == argc) || (argv[i+1][0] == '-')) arg = "-h";
71 else saveas = argv[++i]; }
72 if (arg == "-h"){
73 std::cout << std::endl << " Usage for: " << argv[0] << std::endl << std::endl;
74 std::cout << "\t -c <file>\t Configuration file" << std::endl;
75 std::cout << "\t -s <file>\t Save output as" << std::endl;
76 std::cout << "\t -f <file>\t Input file" << std::endl;
77 std::cout << "\t -p <file>\t Curve parameter file" << std::endl;
78 std::cout << "\t -t <int>\t Particle type (-1 = all)" << std::endl;
79 std::cout << "\t -i <int>\t Ask before each step? (0 = no, 1 = yes)" << std::endl;
80 exit(1);
81 }
82 }
83
84 if( configfile == "" && inputfile == "" ){
85 std::cout << "ERROR: No input file was given..." << std::endl;
86 return 1;
87 }
88
89 // Hesitate after each if ask flag is true
90 std::string ready("y");
91
92 // Create a calibration interface
93 HadronInterface widget;
94
95 std::vector< TString > types;
96 types.push_back("pion");
97 types.push_back("kaon");
98 types.push_back("proton");
99 types.push_back("muon");
100 types.push_back("electron");
101
102 // ---------------------------------------------------------------------------
103 // 0. Set the parameters either from a config file or use the defaults
104
105 if( configfile != "" ){
106 widget.SetupFromConfigFile(configfile);
107 widget.PrintParameters();
108 }
109 else{
110 std::cout << "No configuration file provided, ";
111 std::cout << "are you sure you want to use the default values (y/n)? ";
112 std::cin >> ready; std::cout << std::endl;
113 if( ready != "y" ) return 1;
114
115 int bgbins[5];
116 double bgmax[5];
117 double bgmin[5];
118
119 // BESIII XYZ 2014 DATA
120 bgbins[0] = 30;
121 bgmax[0] = 2.12/Widget::mpion;
122 bgmin[0] = 0.12/Widget::mpion;
123 bgbins[1] = 10;
124 bgmax[1] = 1.8/Widget::mkaon;
125 bgmin[1] = 0.35/Widget::mkaon;
126 bgbins[2] = 10;
127 bgmax[2] = 1.7/Widget::mproton;
128 bgmin[2] = 0.5/Widget::mproton;
129 bgbins[3] = 15;
130 bgmax[3] = 1.92/Widget::mmuon;
131 bgmin[3] = 1.76/Widget::mmuon;
132 bgbins[4] = 30;
133 bgmax[4] = 2.3/Widget::melectron;
134 bgmin[4] = 0.3/Widget::melectron;
135
136 int cosbins[5];
137 double cosmax[5];
138 double cosmin[5];
139 for( int i = 0; i < 4; ++i ){
140 cosbins[i] = 18;
141 cosmax[i] = 0.93;
142 cosmin[i] = 0.0;
143 }
144 cosbins[4] = 18;
145 cosmax[4] = 0.93;
146 cosmin[4] = 0.5;
147
148 // add particles
149 for( int i = 0; i < 5; ++i ){
150 if( inputfile != "" )
151 widget.AddParticle(types[i],inputfile+types[i]+".root",0.0,
152 bgbins[i],bgmax[i],bgmin[i],
153 cosbins[i],cosmax[i],cosmin[i]);
154 else
155 widget.AddParticle(types[i],"widget."+types[i]+".root",0.0,
156 bgbins[i],bgmax[i],bgmin[i],
157 cosbins[i],cosmax[i],cosmin[i]);
158 }
159 }
160
161 // set the file that holds the calibration constants
162 widget.SetParamFile(parfile);
163 // ---------------------------------------------------------------------------
164
165 // redirect output to log file, but save a pointer to the old
166 // buffer associated with std::cout and restore it for some output
167 std::streambuf *coutbuf = std::cout.rdbuf();
168 std::ofstream out("widget.log");
169
170 // ---------------------------------------------------------------------------
171 // 1. Plot the efficiency for dE/dx
172
173 std::cout.rdbuf( out.rdbuf() );
174 widget.PlotEfficiency(saveas);
175 std::cout.rdbuf( coutbuf );
176 // ---------------------------------------------------------------------------
177}
void SetParamFile(std::string paramfile)
void PlotEfficiency(TString saveas)
void SetupFromConfigFile(std::string configfile)
void AddParticle(TString particle, TString filename, int nevents, int bgbins, double upperbg, double lowerbg, int cosbins, double uppercos, double lowercos)