/* * EffCollection.cpp * * Created on: 10/ago/2009 * Author: Nicola Mori */ /*! @file EffCollection.cpp The EffCollection class implementation file. */ #include "EffCollection.h" #include "TGraphAsymmErrors.h" extern "C" { bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*); } EffCollection::EffCollection(const char *collectionName, TString outFileBase, int errMethod) : VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( outFileBase), _errMethod(errMethod), _det(0), _sel(0) { } void EffCollection::AddDetectorCut(PamCut &cut) { _detCollection.AddCut(cut); } void EffCollection::AddSelectionCut(PamCut &cut) { _selCollection.AddCut(cut); } void EffCollection::AddDetectorAction(CollectionAction &action) { _detCollection.AddAction(action); } void EffCollection::AddSelectionAction(CollectionAction &action) { _selCollection.AddAction(action); } int EffCollection::ApplyCut(PamLevel2 *event) { _nEv++; if (_selCollection.ApplyCut(event) == CUTOK) { _sel++; if (_detCollection.ApplyCut(event) == CUTOK) { _det++; _nGood++; return CUTOK; } } return 0; } void EffCollection::Finalize() { // Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize for (unsigned int i = 0; i < _selCollection.GetSize(); i++) _cuts.push_back(_selCollection.GetCut(i)); for (unsigned int i = 0; i < _detCollection.GetSize(); i++) _cuts.push_back(_detCollection.GetCut(i)); // Now all the cuts are in place, and VerboseCollection can print its report VerboseCollection::Finalize(); // Compute the error Int_t sel = (Int_t) _sel; Int_t det = (Int_t) _det; Double_t eff, errLow, errHigh; if (_errMethod == EFFRIG_ROOT) { if (sel < 8) { eff = 1.1; errLow = errHigh = 0.; } else { TH1I pass("pass", "pass", 1, 0., 1.); TH1I total("total", "total", 1, 0., 1.); pass.Fill(0.5, det); total.Fill(0.5, sel); TGraphAsymmErrors errGraph; errGraph.BayesDivide(&pass, &total); Double_t dummy; errGraph.GetPoint(0, dummy, eff); errLow = errGraph.GetErrorYlow(0); errHigh = errGraph.GetErrorYhigh(0); } } if (_errMethod == EFFRIG_SERGIO) { efficiency_(&sel, &det, &eff, &errLow, &errHigh); } // Add some info about efficiency to the stdout cout << " ****** Efficiency informations ******\n"; cout << " Detector cuts:\n"; for (unsigned int i = 0; i < _detCollection.GetSize(); i++) cout << " - " << _detCollection.GetCut(i)->GetName() << "\n"; cout << " Total detector efficiency: " << eff << " +" << errHigh << "-" << errLow << endl; // Write the output file if (_outFileBase != "") { ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out); streamsize newPrec = 4; outTextFile.precision(newPrec); outTextFile.setf(ios::fixed, ios::floatfield); outTextFile << setw(10) << det << setw(10) << sel << setw(10) << eff << setw(10) << errLow << setw(10) << errHigh << endl; outTextFile.close(); } }