--- PamCut/Collections/EffRigCollection/EffRigCollection.cpp 2009/08/12 14:18:37 1.1 +++ PamCut/Collections/EffRigCollection/EffRigCollection.cpp 2009/09/24 18:17:26 1.2 @@ -9,6 +9,10 @@ #include "EffRigCollection.h" +extern "C" { +bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*); +} + EffRigCollection::EffRigCollection(const char *collectionName, TString outFileBase, TString rigBinsFile, bool absRig) : EffCollection(collectionName, outFileBase), _bins(0), _selVector(0), _detVector(0), _outUp(0), _outDown(0) { @@ -50,8 +54,10 @@ if (i < (int) (_selVector.size())) { _selVector[i]++; + _sel++; if (_detCollection.ApplyCut(event) == CUTOK) { _detVector[i]++; + _det++; _nGood++; return CUTOK; } @@ -71,22 +77,34 @@ void EffRigCollection::Finalize() { - // Correct the number of selected events by subtracting events outside the rigidity interval - _sel -= _outUp + _outDown; // Print the report EffCollection::Finalize(); cout << " Events below the minimum rigidity: " << _outDown << "\n"; cout << " Events above the maximum rigidity: " << _outUp << "\n"; + // Compute the error + Int_t sel[_selVector.size()]; + Int_t det[_detVector.size()]; + Double_t eff[_selVector.size()]; + Double_t errLow[_selVector.size()]; + Double_t errHigh[_selVector.size()]; + for (unsigned int i = 0; i < _selVector.size(); i++) { + sel[i] = (Int_t) _selVector[i]; + det[i] = (Int_t) _detVector[i]; + efficiency_(&(sel[i]), &(det[i]), &(eff[i]), &(errLow[i]), &(errHigh[i])); + } // Write the output files if (_outFileBase != "") { ofstream outTextFile((_outFileBase + "-eff-rig.txt").Data(), ios_base::out); + streamsize newPrec = 4; + outTextFile.precision(newPrec); + outTextFile.setf(ios::fixed, ios::floatfield); for (unsigned int i = 0; i < _selVector.size(); i++) { - outTextFile << _detVector[i] << " " << _selVector[i] << " "; + outTextFile << setw(10) << _detVector[i] << setw(10) << _selVector[i]; if (_selVector[i] != 0) - outTextFile << (float) _detVector[i] / (float) _selVector[i] << "\n"; + outTextFile << setw(10) << eff[i] << setw(10) << errLow[i] << setw(10) << errHigh[i] << "\n"; else - outTextFile << "0.\n"; + outTextFile << setw(10) << 0. << setw(10) << 0. << setw(10) << 0. << endl; } outTextFile.close();