5 m_types.push_back(
"pion");
6 m_types.push_back(
"kaon");
7 m_types.push_back(
"proton");
8 m_types.push_back(
"muon");
9 m_types.push_back(
"electron");
16 for(
int i = 0; i < 5; ++i ){
17 m_index[m_types[i]] = i;
21 m_mass[
"pion"] = Widget::mpion;
22 m_mass[
"kaon"] = Widget::mkaon;
23 m_mass[
"proton"] = Widget::mproton;
24 m_mass[
"muon"] = Widget::mmuon;
25 m_mass[
"electron"] = Widget::melectron;
28 for(
int i = 0; i < 5; ++i ){
39 m_paramfile =
"parameters.txt";
45 cout <<
"HadronInterface: setting up from " << configfile << endl;
47 std::ifstream input(configfile.c_str());
50 std::string varname, vartype, line;
51 while( std::getline(input, line) ){
54 line.erase( std::find( line.begin(), line.end(),
'#' ), line.end() );
55 if( line.empty() )
continue;
59 std::istringstream iss(line);
63 if( vartype ==
"mcFlag" ){
67 else if( vartype ==
"type" ){
71 else if( vartype ==
"pion")
73 else if( vartype ==
"kaon")
75 else if( vartype ==
"proton")
77 else if( vartype ==
"muon")
79 else if( vartype ==
"electron")
82 cout <<
"HadronInterface: ERROR: unknown particle type " << vartype <<
" - this line will not be read" << endl;
88 if( varname ==
"filename")
89 iss >> m_filenames[type];
90 else if( varname ==
"nevents")
91 iss >> m_nevents[type];
92 else if( varname ==
"bgbins")
93 iss >> m_bgbins[type];
94 else if( varname ==
"upperbg")
95 iss >> m_upperbg[type];
96 else if( varname ==
"lowerbg")
97 iss >> m_lowerbg[type];
98 else if( varname ==
"upperp"){
99 iss >> m_upperbg[type];
100 m_upperbg[type] = m_upperbg[type]/m_mass[m_types[type]];
102 else if( varname ==
"lowerp"){
103 iss >> m_lowerbg[type];
104 m_lowerbg[type] = m_lowerbg[type]/m_mass[m_types[type]];
106 else if( varname ==
"cosbins")
107 iss >> m_cosbins[type];
108 else if( varname ==
"uppercos")
109 iss >> m_uppercos[type];
110 else if( varname ==
"lowercos")
111 iss >> m_lowercos[type];
113 cout <<
"HadronInterface: ERROR: unknown variable type " << vartype <<
" - this line will not be read" << endl;
118 cout <<
"HadronInterface: Done parsing configuration file..." << endl;
120 m_paramfile =
"parameters.txt";
126 cout << endl << endl <<
"Printing parameters" << endl << endl;
128 for(
int i = 0; i < 5; ++i ){
129 cout << m_types[i] << endl;
130 cout <<
"\tFilename: " << m_filenames[i] << endl;
131 cout <<
"\tBeta-gamma range: " <<
132 m_bgbins[i] <<
" bins, from " << m_upperbg[i] <<
" to " << m_lowerbg[i] << endl;
133 cout <<
"\tCos(theta) range: " <<
134 m_cosbins[i] <<
" bins, from " << m_uppercos[i] <<
" to " << m_lowercos[i] << endl;
140 m_paramfile = paramfile;
144HadronInterface::AddParticle( TString particle, TString filename,
int nevents,
int bgbins,
double upperbg,
double lowerbg,
int cosbins,
double uppercos,
double lowercos ){
145 int index = m_index[particle];
147 m_filenames[index] = filename;
148 m_nevents[index] = nevents;
149 m_bgbins[index] = bgbins;
150 m_upperbg[index] = upperbg;
151 m_lowerbg[index] = lowerbg;
152 m_cosbins[index] = cosbins;
153 m_uppercos[index] = uppercos;
154 m_lowercos[index] = lowercos;
160 cout <<
"HadronInterface: making quality plots..." << endl;
162 std::vector<TString> filenames;
163 for(
int i = 0; i < 5; ++i ){
164 filenames.push_back(m_filenames[i]);
175 cout <<
"HadronInterface: generating sample events..." << endl;
177 int index = m_index[particle];
180 WidgetGenerator generator(m_nevents[index], m_upperbg[index], m_lowerbg[index]);
183 cout <<
"\t generated " << m_nevents[index] <<
"..." << endl;
189 cout <<
"HadronInterface: simulating the dE/dx response for sample events..." << endl;
191 int index = m_index[particle];
194 WidgetGenerator generator(m_nevents[index], m_upperbg[index], m_lowerbg[index]);
195 generator.
simulateDedx(infilename,m_filenames[index],m_mass[particle]);
197 cout <<
"\t simulated " << m_nevents[index] <<
"..." << endl;
203 cout <<
"HadronInterface: simulating the dE/dx reconstruction..." << endl;
209 cout <<
"\t simulated reconstruction finished..." << endl;
221 cout <<
"HadronInterface: fitting in bins of beta-gamma and cos(theta)..." << endl;
223 TFile* outfile =
new TFile(outfilename,
"RECREATE");
224 if( particle == -1 ){
226 for(
int i = 0; i < 5; ++i ){
227 TFile* testfile =
new TFile(m_filenames[i]);
228 if( testfile->GetListOfKeys()->IsEmpty() ){
229 cout <<
"\t No hadron sample for " << m_types[i] <<
"... " << endl;
235 HadronPrep prep(m_filenames[i], m_mcFlag, m_type, m_bgbins[i], m_upperbg[i], m_lowerbg[i], m_cosbins[i], m_uppercos[i], m_lowercos[i]);
241 TFile* testfile =
new TFile(m_filenames[particle]);
242 if( testfile->GetListOfKeys()->IsEmpty() ){
243 cout <<
"\t No hadron sample for " << m_types[particle] <<
"... " << endl;
248 HadronPrep prep(m_filenames[particle], m_mcFlag, m_type, m_bgbins[particle], m_upperbg[particle], m_lowerbg[particle], m_cosbins[particle], m_uppercos[particle], m_lowercos[particle]);
249 prep.
bgCosThetaFits(m_types[particle],outfile,correct,m_paramfile);
262 cout <<
"HadronInterface: getting the universal beta-gamma fits..." << endl;
264 TFile* outfile =
new TFile(outfilename,
"RECREATE");
266 for(
int i = 0; i < 5; ++i ){
267 TFile* testfile =
new TFile(m_filenames[i]);
268 if( testfile->GetListOfKeys()->IsEmpty() ){
269 cout <<
"\t No hadron sample for " << m_types[i] <<
"... " << endl;
275 HadronPrep prep(m_filenames[i], m_mcFlag, m_type, m_bgbins[i], m_upperbg[i], m_lowerbg[i], m_cosbins[i], m_uppercos[i], m_lowercos[i]);
276 prep.
bgFits(m_types[i],outfile,correct,m_paramfile);
285 if( m_mcFlag )
return;
287 cout <<
"HadronInterface: performing the hadron saturation correction..." << endl;
290 TFile* testfile =
new TFile(prepfilename);
291 if( testfile->GetListOfKeys()->IsEmpty() ){
292 cout <<
"\t CAUTION: Fitted file does not exist... " << endl;
310 cout <<
"HadronInterface: performing the beta-gamma curve fits..." << endl;
313 TFile* testfile =
new TFile(filename);
314 if( testfile->GetListOfKeys()->IsEmpty() ){
315 cout <<
"\t CAUTION: Fitted file does not exist... " << endl;
322 hadcal.
fitBGCurve(particles,filename,m_paramfile);
329 cout <<
"HadronInterface: performing the beta-gamma curve fits..." << endl;
332 TFile* testfile =
new TFile(filename);
333 if( testfile->GetListOfKeys()->IsEmpty() ){
334 cout <<
"\t CAUTION: Fitted file does not exist... " << endl;
341 hadcal.
plotBGCurve(particles,filename,m_paramfile);
347 cout <<
"HadronInterface: performing the sigma curve fits..." << endl;
350 TFile* testfile =
new TFile(filename);
351 if( testfile->GetListOfKeys()->IsEmpty() ){
352 cout <<
"\t CAUTION: Fitted file does not exist... " << endl;
360 hadcal.
fitSigmaVsNHit(m_filenames[0],m_paramfile,m_mcFlag,m_type);
362 hadcal.
fitSigmaVsSin(m_filenames[0],m_paramfile,m_mcFlag,m_type);
370 cout <<
"HadronInterface: plotting the efficiency..." << endl;
376 TString flavor(
"pion");
377 hadcal.
plotEfficiency(m_filenames,saveas,m_paramfile,m_mcFlag,m_type);
void fitSigmaVsSin(TString filename, std::string paramfile, int mcFlag, int type)
void plotEfficiency(TString filenames[5], TString saveas, std::string paramfile, int mcFlag, int type)
void plotBGCurve(std::vector< TString > particles, TString filename, std::string paramfile)
void fitBGCurve(std::vector< TString > particles, TString filename, std::string paramfile)
void fitSigmaVsNHit(TString filename, std::string paramfile, int mcFlag, int type)
void BetaGammaFits(std::vector< TString > particles, TString filename)
void SetParamFile(std::string paramfile)
void SimulateSample(TString infilename, TString particle)
void QualityCheck(TString outfilename)
void PrepareResults(TString outfilename, bool correct)
void PlotEfficiency(TString saveas)
void PrepareSample(TString outfilename, bool correct, int particle)
void SaturationCorrection(TString prepfilename, std::string parfile)
void PlotBGCurve(std::vector< TString > particles, TString filename)
void SetupFromConfigFile(std::string configfile)
void GenerateSample(TString particle)
void AddParticle(TString particle, TString filename, int nevents, int bgbins, double upperbg, double lowerbg, int cosbins, double uppercos, double lowercos)
void SigmaFits(TString filename)
void SimulateReconstruction(TString infilename, TString outfilename)
void bgCosThetaFits(TString particle, TFile *outfile, bool correct, std::string paramfile)
void bgFits(TString particle, TFile *outfile, bool correct, std::string paramfile)
void printEvents(int firstevent, int nevents)
void fillSample(TString infilename)
void setParameters(double par[])