| 1 |
/* |
| 2 |
* RigFillAction.cpp |
| 3 |
* |
| 4 |
* Created on: 14/lug/2009 |
| 5 |
* Author: Nicola Mori |
| 6 |
*/ |
| 7 |
|
| 8 |
/*! @file RigFillAction.cpp The RigFillAction class implementation file. */ |
| 9 |
|
| 10 |
#include "RigFillAction.h" |
| 11 |
|
| 12 |
RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
| 13 |
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), |
| 14 |
_thresholdCoeff(thresholdCoeff) { |
| 15 |
|
| 16 |
// Reading the bins from file |
| 17 |
ifstream rigBinListFile; |
| 18 |
rigBinListFile.open(rigBinsFile); |
| 19 |
|
| 20 |
TString auxString; |
| 21 |
while (!rigBinListFile.eof()) { |
| 22 |
rigBinListFile >> auxString; |
| 23 |
if (auxString != "") { |
| 24 |
_bins.push_back(auxString.Atof()); |
| 25 |
} |
| 26 |
} |
| 27 |
rigBinListFile.close(); |
| 28 |
|
| 29 |
// Initializing histograms |
| 30 |
_rootHisto.SetName("rfHisto"); |
| 31 |
_rootHisto.SetTitle(Form("Rc Vs R (thr.: %.2f)", _thresholdCoeff)); |
| 32 |
_rootHisto.GetXaxis()->SetTitle("R (GV)"); |
| 33 |
_rootHisto.GetYaxis()->SetTitle("Rc (GV)"); |
| 34 |
|
| 35 |
Double_t *auxArray = new Double_t[_bins.size()]; |
| 36 |
|
| 37 |
for (unsigned int i = 1; i < _bins.size(); i++) { |
| 38 |
auxArray[i] = _bins[i]; |
| 39 |
} |
| 40 |
|
| 41 |
_rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray); |
| 42 |
delete[] auxArray; |
| 43 |
|
| 44 |
_textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); |
| 45 |
} |
| 46 |
|
| 47 |
void RigFillAction::OnGood(PamLevel2 *event) { |
| 48 |
|
| 49 |
float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
| 50 |
float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
| 51 |
|
| 52 |
_rootHisto.Fill(rigThreshold, rig); |
| 53 |
|
| 54 |
//Bin identification: value must be less than (<) bin maximum |
| 55 |
|
| 56 |
int i = 1; |
| 57 |
while (rig >= _bins[i] && i < (int)_textHisto.GetNRows()) { |
| 58 |
i++; |
| 59 |
} |
| 60 |
i--; |
| 61 |
|
| 62 |
int j = 1; |
| 63 |
while (rigThreshold >= _bins[j] && j < (int)_textHisto.GetNCols()) { |
| 64 |
j++; |
| 65 |
} |
| 66 |
j--; |
| 67 |
|
| 68 |
if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols()) |
| 69 |
_textHisto[i][j]++; |
| 70 |
} |
| 71 |
|
| 72 |
void RigFillAction::Finalize() { |
| 73 |
|
| 74 |
// Write the text file |
| 75 |
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
| 76 |
for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) { |
| 77 |
for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) { |
| 78 |
outTextFile << setw(7) << _textHisto[i][j] << " "; |
| 79 |
} |
| 80 |
outTextFile << "\n"; |
| 81 |
} |
| 82 |
outTextFile.close(); |
| 83 |
|
| 84 |
// Write the ROOT file |
| 85 |
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
| 86 |
outRootFile.cd(); |
| 87 |
_rootHisto.Write(); |
| 88 |
outRootFile.Close(); |
| 89 |
|
| 90 |
} |