| 1 |
pam-fi |
1.1 |
/* |
| 2 |
|
|
* EffCollection.cpp |
| 3 |
|
|
* |
| 4 |
|
|
* Created on: 10/ago/2009 |
| 5 |
|
|
* Author: Nicola Mori |
| 6 |
|
|
*/ |
| 7 |
|
|
|
| 8 |
|
|
/*! @file EffCollection.cpp The EffCollection class implementation file. */ |
| 9 |
|
|
|
| 10 |
|
|
#include "EffCollection.h" |
| 11 |
|
|
|
| 12 |
|
|
EffCollection::EffCollection(const char *collectionName, TString rigBinsFile, TString &outFileBase, bool absRig) : |
| 13 |
|
|
VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( |
| 14 |
|
|
outFileBase), _absRig(absRig), _bins(0), _sel(0), _det(0), _outUp(0), _outDown(0) { |
| 15 |
|
|
|
| 16 |
|
|
ifstream rigBinListFile; |
| 17 |
|
|
rigBinListFile.open(rigBinsFile); |
| 18 |
|
|
|
| 19 |
|
|
TString auxString; |
| 20 |
|
|
while (!rigBinListFile.eof()) { |
| 21 |
|
|
rigBinListFile >> auxString; |
| 22 |
|
|
if (auxString != "") { |
| 23 |
|
|
_bins.push_back(auxString.Atof()); |
| 24 |
|
|
} |
| 25 |
|
|
} |
| 26 |
|
|
rigBinListFile.close(); |
| 27 |
|
|
|
| 28 |
|
|
_sel.resize(_bins.size() - 1, 0); |
| 29 |
|
|
_det.resize(_bins.size() - 1, 0); |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
void EffCollection::AddDetectorCut(PamCut &cut) { |
| 33 |
|
|
_detCollection.AddCut(cut); |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
void EffCollection::AddSelectionCut(PamCut &cut) { |
| 37 |
|
|
_selCollection.AddCut(cut); |
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
void EffCollection::AddDetectorAction(CollectionAction &action) { |
| 41 |
|
|
_detCollection.AddAction(action); |
| 42 |
|
|
} |
| 43 |
|
|
|
| 44 |
|
|
void EffCollection::AddSelectionAction(CollectionAction &action) { |
| 45 |
|
|
_selCollection.AddAction(action); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
int EffCollection::ApplyCut(PamLevel2 *event) { |
| 49 |
|
|
|
| 50 |
|
|
// See if the rigidity of the event is between the limits |
| 51 |
|
|
float rig; |
| 52 |
|
|
if (_absRig) |
| 53 |
|
|
rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
| 54 |
|
|
else |
| 55 |
|
|
rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection(); |
| 56 |
|
|
if (rig >= _bins[0]) { |
| 57 |
|
|
int i = 1; |
| 58 |
|
|
while (rig >= _bins[i] && i < (int) _bins.size()) { |
| 59 |
|
|
i++; |
| 60 |
|
|
} |
| 61 |
|
|
i--; |
| 62 |
|
|
if (i < (int) (_sel.size())) { |
| 63 |
|
|
_nEv++; |
| 64 |
|
|
// Rigidity is OK, let's apply the cuts |
| 65 |
|
|
if (_selCollection.ApplyCut(event) == CUTOK) { |
| 66 |
|
|
_sel[i]++; |
| 67 |
|
|
if (_detCollection.ApplyCut(event) == CUTOK) { |
| 68 |
|
|
_det[i]++; |
| 69 |
|
|
_nGood++; |
| 70 |
|
|
return CUTOK; |
| 71 |
|
|
} |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
else |
| 75 |
|
|
_outUp++; |
| 76 |
|
|
} |
| 77 |
|
|
else |
| 78 |
|
|
_outDown++; |
| 79 |
|
|
|
| 80 |
|
|
return 0; |
| 81 |
|
|
} |
| 82 |
|
|
|
| 83 |
|
|
void EffCollection::Finalize() { |
| 84 |
|
|
// Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize |
| 85 |
|
|
for (unsigned int i = 0; i < _selCollection.GetSize(); i++) |
| 86 |
|
|
_cuts.push_back(_selCollection.GetCut(i)); |
| 87 |
|
|
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
| 88 |
|
|
_cuts.push_back(_detCollection.GetCut(i)); |
| 89 |
|
|
// Now all the cuts are in place, and VerboseCollection can print its report |
| 90 |
|
|
VerboseCollection::Finalize(); |
| 91 |
|
|
// Add some info about efficiency |
| 92 |
pam-fi |
1.2 |
cout << " ****** Efficiency informations ******\n"; |
| 93 |
|
|
cout << " Detector cuts:\n"; |
| 94 |
|
|
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
| 95 |
|
|
cout << " - " << _detCollection.GetCut(i)->GetName() << "\n"; |
| 96 |
pam-fi |
1.1 |
cout << " Events below the minimum rigidity: " << _outDown << "\n"; |
| 97 |
|
|
cout << " Events above the maximum rigidity: " << _outUp << "\n"; |
| 98 |
pam-fi |
1.2 |
cout << " Total detector efficiency: " |
| 99 |
pam-fi |
1.1 |
<< (float) _detCollection.GetNGood() / |
| 100 |
|
|
(float) (_selCollection.GetCut(_selCollection.GetSize() - 1)->GetNGood()) |
| 101 |
|
|
<< "\n" << endl; |
| 102 |
|
|
|
| 103 |
|
|
// Write the output files |
| 104 |
|
|
if (_outFileBase != "") { |
| 105 |
|
|
ofstream outTextFile((_outFileBase + "-sel.txt").Data(), ios_base::out); |
| 106 |
|
|
for (unsigned int i = 0; i < _sel.size(); i++) { |
| 107 |
|
|
outTextFile << _sel[i] << "\n"; |
| 108 |
|
|
} |
| 109 |
|
|
outTextFile.close(); |
| 110 |
|
|
|
| 111 |
|
|
outTextFile.open((_outFileBase + "-det.txt").Data(), ios_base::out); |
| 112 |
|
|
for (unsigned int i = 0; i < _det.size(); i++) { |
| 113 |
|
|
outTextFile << _det[i] << "\n"; |
| 114 |
|
|
} |
| 115 |
|
|
outTextFile.close(); |
| 116 |
|
|
|
| 117 |
|
|
outTextFile.open((_outFileBase + "-eff.txt").Data(), ios_base::out); |
| 118 |
|
|
for (unsigned int i = 0; i < _det.size(); i++) { |
| 119 |
|
|
if (_sel[i] != 0) |
| 120 |
|
|
outTextFile << (float) _det[i] / (float) _sel[i] << "\n"; |
| 121 |
|
|
else |
| 122 |
|
|
outTextFile << "0.\n"; |
| 123 |
|
|
} |
| 124 |
|
|
outTextFile.close(); |
| 125 |
|
|
|
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
|
|
} |