BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
HadronInterface Class Reference

#include <HadronInterface.h>

Public Member Functions

 HadronInterface ()
 
virtual ~HadronInterface ()
 
void SetupFromConfigFile (std::string configfile)
 
void SetParamFile (std::string paramfile)
 
void PrintParameters ()
 
void AddParticle (TString particle, TString filename, int nevents, int bgbins, double upperbg, double lowerbg, int cosbins, double uppercos, double lowercos)
 
void QualityCheck (TString outfilename)
 
void GenerateSample (TString particle)
 
void SimulateSample (TString infilename, TString particle)
 
void SimulateReconstruction (TString infilename, TString outfilename)
 
void PrepareSample (TString outfilename, bool correct, int particle)
 
void PrepareResults (TString outfilename, bool correct)
 
void SaturationCorrection (TString prepfilename, std::string parfile)
 
void BetaGammaFits (std::vector< TString > particles, TString filename)
 
void PlotBGCurve (std::vector< TString > particles, TString filename)
 
void SigmaFits (TString filename)
 
void PlotEfficiency (TString saveas)
 

Detailed Description

Definition at line 44 of file HadronInterface.h.

Constructor & Destructor Documentation

◆ HadronInterface()

HadronInterface::HadronInterface ( )

Definition at line 3 of file HadronInterface.cc.

3 {
4 // set up a vector of particle names
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");
10
11 // if no files are specified, assume sample is BESIII MC
12 m_mcFlag = 1;
13 m_type = 0;
14
15 // set up the values in the map of particle names
16 for( int i = 0; i < 5; ++i ){
17 m_index[m_types[i]] = i;
18 }
19
20 // and masses
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;
26
27 // initialize various parameters
28 for( int i = 0; i < 5; ++i ){
29 m_filenames[i] = "";
30 m_nevents[i] = 0;
31 m_bgbins[i] = 15;
32 m_upperbg[i] = 5.0;
33 m_lowerbg[i] = 0.1;
34 m_cosbins[i] = 18;
35 m_uppercos[i] = 0.93;
36 m_lowercos[i] = 0.0;
37 }
38
39 m_paramfile = "parameters.txt";
40}

◆ ~HadronInterface()

virtual HadronInterface::~HadronInterface ( )
inlinevirtual

Definition at line 49 of file HadronInterface.h.

49{}

Member Function Documentation

◆ AddParticle()

void HadronInterface::AddParticle ( TString  particle,
TString  filename,
int  nevents,
int  bgbins,
double  upperbg,
double  lowerbg,
int  cosbins,
double  uppercos,
double  lowercos 
)

Definition at line 144 of file HadronInterface.cc.

144 {
145 int index = m_index[particle];
146
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;
155}

Referenced by main().

◆ BetaGammaFits()

void HadronInterface::BetaGammaFits ( std::vector< TString >  particles,
TString  filename 
)

Definition at line 308 of file HadronInterface.cc.

308 {
309
310 cout << "HadronInterface: performing the beta-gamma curve fits..." << endl;
311
312 // make sure the file exists
313 TFile* testfile = new TFile(filename);
314 if( testfile->GetListOfKeys()->IsEmpty() ){
315 cout << "\t CAUTION: Fitted file does not exist... " << endl;
316 exit(1);
317 }
318 testfile->Close();
319
320 // create the HadronCalibration object and fit the prepared samples
321 HadronCalibration hadcal;
322 hadcal.fitBGCurve(particles,filename,m_paramfile);
323 SetParamFile("parameters.bgcurve.fit");
324}
void fitBGCurve(std::vector< TString > particles, TString filename, std::string paramfile)
void SetParamFile(std::string paramfile)

Referenced by main().

◆ GenerateSample()

void HadronInterface::GenerateSample ( TString  particle = "pion")

Definition at line 173 of file HadronInterface.cc.

173 {
174
175 cout << "HadronInterface: generating sample events..." << endl;
176
177 int index = m_index[particle];
178
179 // generate a sample of events
180 WidgetGenerator generator(m_nevents[index], m_upperbg[index], m_lowerbg[index]);
181 generator.generateEvents(m_filenames[index],m_mass[particle]);
182
183 cout << "\t generated " << m_nevents[index] << "..." << endl;
184}

◆ PlotBGCurve()

void HadronInterface::PlotBGCurve ( std::vector< TString >  particles,
TString  filename 
)

Definition at line 327 of file HadronInterface.cc.

327 {
328
329 cout << "HadronInterface: performing the beta-gamma curve fits..." << endl;
330
331 // make sure the file exists
332 TFile* testfile = new TFile(filename);
333 if( testfile->GetListOfKeys()->IsEmpty() ){
334 cout << "\t CAUTION: Fitted file does not exist... " << endl;
335 exit(1);
336 }
337 testfile->Close();
338
339 // create the HadronCalibration object and fit the prepared samples
340 HadronCalibration hadcal;
341 hadcal.plotBGCurve(particles,filename,m_paramfile);
342}
void plotBGCurve(std::vector< TString > particles, TString filename, std::string paramfile)

Referenced by main().

◆ PlotEfficiency()

void HadronInterface::PlotEfficiency ( TString  saveas)

Definition at line 368 of file HadronInterface.cc.

368 {
369
370 cout << "HadronInterface: plotting the efficiency..." << endl;
371
372 // create the HadronCalibration object and fill histograms
373 HadronCalibration hadcal;
374 SetParamFile("parameters.bgcurve.fit");
375
376 TString flavor("pion");
377 hadcal.plotEfficiency(m_filenames,saveas,m_paramfile,m_mcFlag,m_type);
378}
void plotEfficiency(TString filenames[5], TString saveas, std::string paramfile, int mcFlag, int type)

Referenced by main().

◆ PrepareResults()

void HadronInterface::PrepareResults ( TString  outfilename,
bool  correct 
)

Definition at line 260 of file HadronInterface.cc.

260 {
261
262 cout << "HadronInterface: getting the universal beta-gamma fits..." << endl;
263
264 TFile* outfile = new TFile(outfilename,"RECREATE");
265 // make sure the samples exist
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;
270 continue;
271 }
272 testfile->Close();
273
274 // prepare the sample by fitting in bins of beta-gamma and cos(theta)
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);
277 }
278 outfile->Close();
279}

Referenced by main().

◆ PrepareSample()

void HadronInterface::PrepareSample ( TString  outfilename,
bool  correct,
int  particle 
)

Definition at line 219 of file HadronInterface.cc.

219 {
220
221 cout << "HadronInterface: fitting in bins of beta-gamma and cos(theta)..." << endl;
222
223 TFile* outfile = new TFile(outfilename,"RECREATE");
224 if( particle == -1 ){
225 // make sure the samples exist
226 for( int i = 0; i < 5; ++i ){ // <---- adding electrons...
227 TFile* testfile = new TFile(m_filenames[i]);
228 if( testfile->GetListOfKeys()->IsEmpty() ){
229 cout << "\t No hadron sample for " << m_types[i] << "... " << endl;
230 continue;
231 }
232 testfile->Close();
233
234 // prepare the sample by fitting in bins of beta-gamma and cos(theta)
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]);
236 prep.bgCosThetaFits(m_types[i],outfile,correct,m_paramfile);
237 }
238 }
239 else{
240 // make sure the samples exist
241 TFile* testfile = new TFile(m_filenames[particle]);
242 if( testfile->GetListOfKeys()->IsEmpty() ){
243 cout << "\t No hadron sample for " << m_types[particle] << "... " << endl;
244 }
245 testfile->Close();
246
247 // prepare the sample by fitting in bins of beta-gamma and cos(theta)
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);
250 }
251
252 outfile->Close();
253}

Referenced by main().

◆ PrintParameters()

void HadronInterface::PrintParameters ( )

Definition at line 124 of file HadronInterface.cc.

124 {
125
126 cout << endl << endl << "Printing parameters" << endl << endl;
127
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;
135 }
136}

Referenced by main().

◆ QualityCheck()

void HadronInterface::QualityCheck ( TString  outfilename)

Definition at line 158 of file HadronInterface.cc.

158 {
159
160 cout << "HadronInterface: making quality plots..." << endl;
161
162 std::vector<TString> filenames;
163 for( int i = 0; i < 5; ++i ){
164 filenames.push_back(m_filenames[i]);
165 }
166
167 WidgetQuality gq(m_type,m_upperbg,m_lowerbg);
168 gq.makeHistograms(filenames, outfilename);
169 gq.plotHistograms(outfilename);
170}

Referenced by main().

◆ SaturationCorrection()

void HadronInterface::SaturationCorrection ( TString  prepfilename,
std::string  parfile 
)

Definition at line 282 of file HadronInterface.cc.

282 {
283
284 // do not do the correction on mc samples...
285 if( m_mcFlag ) return;
286
287 cout << "HadronInterface: performing the hadron saturation correction..." << endl;
288
289 // make sure the file exists
290 TFile* testfile = new TFile(prepfilename);
291 if( testfile->GetListOfKeys()->IsEmpty() ){
292 cout << "\t CAUTION: Fitted file does not exist... " << endl;
293 exit(1);
294 }
295 testfile->Close();
296
297 // create the HadronSaturation object and fill the prepared samples
298 HadronSaturation hadsat;
299 hadsat.setParameters(parfile);
300 hadsat.fillSample(prepfilename);
301 hadsat.printEvents(0,10);
302
303 // perform the hadron saturation correction
304 hadsat.fitSaturation();
305}
void printEvents(int firstevent, int nevents)
void fillSample(TString infilename)
void setParameters(double par[])

Referenced by main().

◆ SetParamFile()

void HadronInterface::SetParamFile ( std::string  paramfile)

Definition at line 139 of file HadronInterface.cc.

139 {
140 m_paramfile = paramfile;
141}

Referenced by BetaGammaFits(), main(), PlotEfficiency(), and SigmaFits().

◆ SetupFromConfigFile()

void HadronInterface::SetupFromConfigFile ( std::string  configfile)

Definition at line 43 of file HadronInterface.cc.

43 {
44
45 cout << "HadronInterface: setting up from " << configfile << endl;
46
47 std::ifstream input(configfile.c_str());
48
49 int type;
50 std::string varname, vartype, line;
51 while( std::getline(input, line) ){
52
53 // skip comment lines
54 line.erase( std::find( line.begin(), line.end(), '#' ), line.end() );
55 if( line.empty() ) continue;
56
57 // parse the lines in the configuration file
58 type = -1;
59 std::istringstream iss(line);
60 iss >> vartype;
61
62 // check for a mcFlag
63 if( vartype == "mcFlag" ){
64 iss >> m_mcFlag;
65 continue;
66 }
67 else if( vartype == "type" ){
68 iss >> m_type;
69 continue;
70 }
71 else if( vartype == "pion") // the first word in the line should be the particle type
72 type = 0;
73 else if( vartype == "kaon")
74 type = 1;
75 else if( vartype == "proton")
76 type = 2;
77 else if( vartype == "muon")
78 type = 3;
79 else if( vartype == "electron")
80 type = 4;
81 else{
82 cout << "HadronInterface: ERROR: unknown particle type " << vartype << " - this line will not be read" << endl;
83 continue;
84 }
85
86 // the next word should be the variable type
87 iss >> varname;
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]];
101 }
102 else if( varname == "lowerp"){
103 iss >> m_lowerbg[type];
104 m_lowerbg[type] = m_lowerbg[type]/m_mass[m_types[type]];
105 }
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];
112 else{
113 cout << "HadronInterface: ERROR: unknown variable type " << vartype << " - this line will not be read" << endl;
114 continue;
115 }
116 }
117
118 cout << "HadronInterface: Done parsing configuration file..." << endl;
119
120 m_paramfile = "parameters.txt";
121}

Referenced by main().

◆ SigmaFits()

void HadronInterface::SigmaFits ( TString  filename)

Definition at line 345 of file HadronInterface.cc.

345 {
346
347 cout << "HadronInterface: performing the sigma curve fits..." << endl;
348
349 // make sure the file exists
350 TFile* testfile = new TFile(filename);
351 if( testfile->GetListOfKeys()->IsEmpty() ){
352 cout << "\t CAUTION: Fitted file does not exist... " << endl;
353 exit(1);
354 }
355 testfile->Close();
356
357 // create the HadronCalibration object and fit the prepared samples
358 // only the pion samples are used for the sigma fits
359 HadronCalibration hadcal;
360 hadcal.fitSigmaVsNHit(m_filenames[0],m_paramfile,m_mcFlag,m_type);
361 SetParamFile("parameters.sigmanhit.fit");
362 hadcal.fitSigmaVsSin(m_filenames[0],m_paramfile,m_mcFlag,m_type);
363 SetParamFile("parameters.sigmasin.fit");
364}
void fitSigmaVsSin(TString filename, std::string paramfile, int mcFlag, int type)
void fitSigmaVsNHit(TString filename, std::string paramfile, int mcFlag, int type)

Referenced by main().

◆ SimulateReconstruction()

void HadronInterface::SimulateReconstruction ( TString  infilename,
TString  outfilename 
)

Definition at line 201 of file HadronInterface.cc.

201 {
202
203 cout << "HadronInterface: simulating the dE/dx reconstruction..." << endl;
204
205 // simulate the dE/dx response for a sample of events
206 WidgetGenerator generator;
207 generator.simulateReconstruction(infilename,outfilename);
208
209 cout << "\t simulated reconstruction finished..." << endl;
210}
void simulateReconstruction(TString infilename, TString outfilename)

◆ SimulateSample()

void HadronInterface::SimulateSample ( TString  infilename,
TString  particle 
)

Definition at line 187 of file HadronInterface.cc.

187 {
188
189 cout << "HadronInterface: simulating the dE/dx response for sample events..." << endl;
190
191 int index = m_index[particle];
192
193 // simulate the dE/dx response for a sample of events
194 WidgetGenerator generator(m_nevents[index], m_upperbg[index], m_lowerbg[index]);
195 generator.simulateDedx(infilename,m_filenames[index],m_mass[particle]);
196
197 cout << "\t simulated " << m_nevents[index] << "..." << endl;
198}

The documentation for this class was generated from the following files: