| 1 |
/* |
| 2 |
* EffRigCollection.cpp |
| 3 |
* |
| 4 |
* Created on: 10/ago/2009 |
| 5 |
* Author: Nicola Mori |
| 6 |
*/ |
| 7 |
|
| 8 |
/*! @file EffRigCollection.cpp The EffRigCollection class implementation file. */ |
| 9 |
|
| 10 |
#include "EffRigCollection.h" |
| 11 |
|
| 12 |
extern "C" { |
| 13 |
bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*); |
| 14 |
} |
| 15 |
|
| 16 |
EffRigCollection::EffRigCollection(const char *collectionName, TString outFileBase, TString rigBinsFile, bool absRig) : |
| 17 |
EffCollection(collectionName, outFileBase), _bins(0), _selVector(0), _detVector(0), _outUp(0), _outDown(0) { |
| 18 |
|
| 19 |
ifstream rigBinListFile; |
| 20 |
rigBinListFile.open(rigBinsFile); |
| 21 |
|
| 22 |
TString auxString; |
| 23 |
while (!rigBinListFile.eof()) { |
| 24 |
rigBinListFile >> auxString; |
| 25 |
if (auxString != "") { |
| 26 |
_bins.push_back(auxString.Atof()); |
| 27 |
} |
| 28 |
} |
| 29 |
rigBinListFile.close(); |
| 30 |
|
| 31 |
_selVector.resize(_bins.size() - 1, 0); |
| 32 |
_detVector.resize(_bins.size() - 1, 0); |
| 33 |
} |
| 34 |
|
| 35 |
int EffRigCollection::ApplyCut(PamLevel2 *event) { |
| 36 |
|
| 37 |
_nEv++; |
| 38 |
if (_selCollection.ApplyCut(event) == CUTOK) { |
| 39 |
// Check if the event is inside the rigidity range |
| 40 |
// NOTE: at this point a TrkPhSinCut should be already performed, |
| 41 |
// since we are going to retrieve rigidity. |
| 42 |
float rig; |
| 43 |
if (_absRig) { |
| 44 |
rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
| 45 |
} |
| 46 |
else |
| 47 |
rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection(); |
| 48 |
if (rig >= _bins[0]) { |
| 49 |
int i = 1; |
| 50 |
while (rig >= _bins[i] && i < (int) _bins.size()) { |
| 51 |
i++; |
| 52 |
} |
| 53 |
i--; |
| 54 |
|
| 55 |
if (i < (int) (_selVector.size())) { |
| 56 |
_selVector[i]++; |
| 57 |
_sel++; |
| 58 |
if (_detCollection.ApplyCut(event) == CUTOK) { |
| 59 |
_detVector[i]++; |
| 60 |
_det++; |
| 61 |
_nGood++; |
| 62 |
return CUTOK; |
| 63 |
} |
| 64 |
} |
| 65 |
else |
| 66 |
_outUp++; |
| 67 |
|
| 68 |
} |
| 69 |
else { |
| 70 |
_outDown++; |
| 71 |
return 0; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
void EffRigCollection::Finalize() { |
| 79 |
|
| 80 |
// Print the report |
| 81 |
EffCollection::Finalize(); |
| 82 |
cout << " Events below the minimum rigidity: " << _outDown << "\n"; |
| 83 |
cout << " Events above the maximum rigidity: " << _outUp << "\n"; |
| 84 |
|
| 85 |
// Compute the error |
| 86 |
Int_t sel[_selVector.size()]; |
| 87 |
Int_t det[_detVector.size()]; |
| 88 |
Double_t eff[_selVector.size()]; |
| 89 |
Double_t errLow[_selVector.size()]; |
| 90 |
Double_t errHigh[_selVector.size()]; |
| 91 |
for (unsigned int i = 0; i < _selVector.size(); i++) { |
| 92 |
sel[i] = (Int_t) _selVector[i]; |
| 93 |
det[i] = (Int_t) _detVector[i]; |
| 94 |
efficiency_(&(sel[i]), &(det[i]), &(eff[i]), &(errLow[i]), &(errHigh[i])); |
| 95 |
} |
| 96 |
// Write the output files |
| 97 |
if (_outFileBase != "") { |
| 98 |
ofstream outTextFile((_outFileBase + "-eff-rig.txt").Data(), ios_base::out); |
| 99 |
streamsize newPrec = 4; |
| 100 |
outTextFile.precision(newPrec); |
| 101 |
outTextFile.setf(ios::fixed, ios::floatfield); |
| 102 |
for (unsigned int i = 0; i < _selVector.size(); i++) { |
| 103 |
outTextFile << setw(10) << _detVector[i] << setw(10) << _selVector[i]; |
| 104 |
if (_selVector[i] != 0) |
| 105 |
outTextFile << setw(10) << eff[i] << setw(10) << errLow[i] << setw(10) << errHigh[i] << "\n"; |
| 106 |
else |
| 107 |
outTextFile << setw(10) << 0. << setw(10) << 0. << setw(10) << 0. << endl; |
| 108 |
|
| 109 |
} |
| 110 |
outTextFile.close(); |
| 111 |
} |
| 112 |
|
| 113 |
} |