| 9 |
|
|
| 10 |
#include "RigFillAction.h" |
#include "RigFillAction.h" |
| 11 |
|
|
| 12 |
RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
void RigFillAction::_InitHistos(vector<float> &bins) { |
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), |
|
|
_thresholdCoeff(thresholdCoeff) { |
|
| 13 |
|
|
| 14 |
// Reading the bins from file |
_bins = bins; |
|
ifstream rigBinListFile; |
|
|
rigBinListFile.open(rigBinsFile); |
|
|
|
|
|
TString auxString; |
|
|
while (!rigBinListFile.eof()) { |
|
|
rigBinListFile >> auxString; |
|
|
if (auxString != "") { |
|
|
_bins.push_back(auxString.Atof()); |
|
|
} |
|
|
} |
|
|
rigBinListFile.close(); |
|
| 15 |
|
|
| 16 |
// Initializing histograms |
// Initializing histograms |
| 17 |
_rootHisto.SetName("rfHisto"); |
_rootHisto.SetName("rfHisto"); |
| 28 |
_rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray); |
_rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray); |
| 29 |
delete[] auxArray; |
delete[] auxArray; |
| 30 |
|
|
| 31 |
|
_zeroCutoffBins.resize(_bins.size() - 1, 0); |
| 32 |
_textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); |
_textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); |
| 33 |
} |
} |
| 34 |
|
|
| 35 |
|
RigFillAction::RigFillAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) : |
| 36 |
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), |
| 37 |
|
_zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) { |
| 38 |
|
|
| 39 |
|
_InitHistos(bins); |
| 40 |
|
|
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
| 44 |
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), |
| 45 |
|
_zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) { |
| 46 |
|
|
| 47 |
|
// Reading the bins from file |
| 48 |
|
ifstream rigBinListFile; |
| 49 |
|
rigBinListFile.open(rigBinsFile); |
| 50 |
|
|
| 51 |
|
TString auxString; |
| 52 |
|
vector<float> bins(0); |
| 53 |
|
while (!rigBinListFile.eof()) { |
| 54 |
|
rigBinListFile >> auxString; |
| 55 |
|
if (auxString != "") { |
| 56 |
|
bins.push_back(auxString.Atof()); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
rigBinListFile.close(); |
| 60 |
|
|
| 61 |
|
_InitHistos(bins); |
| 62 |
|
|
| 63 |
|
} |
| 64 |
|
|
| 65 |
void RigFillAction::OnGood(PamLevel2 *event) { |
void RigFillAction::OnGood(PamLevel2 *event) { |
| 66 |
|
|
| 67 |
float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
| 72 |
//Bin identification: value must be less than (<) bin maximum |
//Bin identification: value must be less than (<) bin maximum |
| 73 |
|
|
| 74 |
int i = 1; |
int i = 1; |
| 75 |
while (rig >= _bins[i] && i < (int)_textHisto.GetNRows()) { |
while (rig >= _bins[i] && i < (int) _textHisto.GetNRows()) { |
| 76 |
i++; |
i++; |
| 77 |
} |
} |
| 78 |
i--; |
i--; |
| 79 |
|
|
| 80 |
int j = 1; |
//Check the zero bins |
| 81 |
while (rigThreshold >= _bins[j] && j < (int)_textHisto.GetNCols()) { |
if (rigThreshold < _bins[0]) |
| 82 |
j++; |
_zeroCutoffBins[i]++; |
| 83 |
} |
else { |
| 84 |
j--; |
int j = 1; |
| 85 |
|
while (rigThreshold >= _bins[j] && j < (int) _textHisto.GetNCols()) { |
| 86 |
|
j++; |
| 87 |
|
} |
| 88 |
|
j--; |
| 89 |
|
|
| 90 |
if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols()) |
if (i < (int) _textHisto.GetNRows() && j < (int) _textHisto.GetNCols()) |
| 91 |
_textHisto[i][j]++; |
_textHisto[i][j]++; |
| 92 |
|
} |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
void RigFillAction::Finalize() { |
void RigFillAction::Finalize() { |
| 96 |
|
|
| 97 |
// Write the text file |
// Write the text file |
| 98 |
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
if (_outFileBase != "") { |
| 99 |
for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) { |
|
| 100 |
for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) { |
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
| 101 |
outTextFile << setw(7) << _textHisto[i][j] << " "; |
for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) { |
| 102 |
|
for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) { |
| 103 |
|
outTextFile << setw(7) << _textHisto[i][j] << " "; |
| 104 |
|
} |
| 105 |
|
outTextFile << "\n"; |
| 106 |
} |
} |
| 107 |
outTextFile << "\n"; |
outTextFile.close(); |
|
} |
|
|
outTextFile.close(); |
|
| 108 |
|
|
| 109 |
// Write the ROOT file |
// Write the report file, where zero bins are recorded |
| 110 |
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out); |
| 111 |
outRootFile.cd(); |
outTextFile << "Zero bins for cutoff rigidity: \n"; |
| 112 |
_rootHisto.Write(); |
for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++) |
| 113 |
outRootFile.Close(); |
cout << GetCutoffZeroBins()[i] << "\n"; |
| 114 |
|
|
| 115 |
|
// Write the ROOT file |
| 116 |
|
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
| 117 |
|
outRootFile.cd(); |
| 118 |
|
_rootHisto.Write(); |
| 119 |
|
outRootFile.Close(); |
| 120 |
|
|
| 121 |
|
} |
| 122 |
} |
} |