| 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 |
extern "C" { |
| 13 |
bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*); |
| 14 |
} |
| 15 |
|
| 16 |
EffCollection::EffCollection(const char *collectionName, TString outFileBase) : |
| 17 |
VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( |
| 18 |
outFileBase), _det(0), _sel(0) { |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
void EffCollection::AddDetectorCut(PamCut &cut) { |
| 23 |
_detCollection.AddCut(cut); |
| 24 |
} |
| 25 |
|
| 26 |
void EffCollection::AddSelectionCut(PamCut &cut) { |
| 27 |
_selCollection.AddCut(cut); |
| 28 |
} |
| 29 |
|
| 30 |
void EffCollection::AddDetectorAction(CollectionAction &action) { |
| 31 |
_detCollection.AddAction(action); |
| 32 |
} |
| 33 |
|
| 34 |
void EffCollection::AddSelectionAction(CollectionAction &action) { |
| 35 |
_selCollection.AddAction(action); |
| 36 |
} |
| 37 |
|
| 38 |
int EffCollection::ApplyCut(PamLevel2 *event) { |
| 39 |
|
| 40 |
_nEv++; |
| 41 |
if (_selCollection.ApplyCut(event) == CUTOK) { |
| 42 |
_sel++; |
| 43 |
if (_detCollection.ApplyCut(event) == CUTOK) { |
| 44 |
_det++; |
| 45 |
_nGood++; |
| 46 |
return CUTOK; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
void EffCollection::Finalize() { |
| 54 |
// Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize |
| 55 |
for (unsigned int i = 0; i < _selCollection.GetSize(); i++) |
| 56 |
_cuts.push_back(_selCollection.GetCut(i)); |
| 57 |
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
| 58 |
_cuts.push_back(_detCollection.GetCut(i)); |
| 59 |
// Now all the cuts are in place, and VerboseCollection can print its report |
| 60 |
VerboseCollection::Finalize(); |
| 61 |
|
| 62 |
// Compute the error |
| 63 |
Int_t sel = (Int_t) _sel; |
| 64 |
Int_t det = (Int_t) _det; |
| 65 |
Double_t eff, errLow, errHigh; |
| 66 |
efficiency_(&sel, &det, &eff, &errLow, &errHigh); |
| 67 |
|
| 68 |
// Add some info about efficiency to the stdout |
| 69 |
cout << " ****** Efficiency informations ******\n"; |
| 70 |
cout << " Detector cuts:\n"; |
| 71 |
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
| 72 |
cout << " - " << _detCollection.GetCut(i)->GetName() << "\n"; |
| 73 |
cout << " Total detector efficiency: " << eff << " +" << errHigh << "-" << errLow << endl; |
| 74 |
|
| 75 |
// Write the output file |
| 76 |
if (_outFileBase != "") { |
| 77 |
|
| 78 |
ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out); |
| 79 |
streamsize newPrec = 4; |
| 80 |
outTextFile.precision(newPrec); |
| 81 |
outTextFile.setf(ios::fixed, ios::floatfield); |
| 82 |
outTextFile << setw(10) << det << setw(10) << sel << setw(10) << eff << setw(10) << errLow << setw(10) << errHigh |
| 83 |
<< endl; |
| 84 |
outTextFile.close(); |
| 85 |
} |
| 86 |
|
| 87 |
} |