/* * EffCollection.cpp * * Created on: 10/ago/2009 * Author: Nicola Mori */ /*! @file EffCollection.cpp The EffCollection class implementation file. */ #include "EffCollection.h" EffCollection::EffCollection(const char *collectionName, TString outFileBase) : VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( outFileBase), _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(); // Add some info about efficiency float eff; if (_sel != 0.) eff = (float)_det / (float)_sel; else eff = 0.; 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 << endl; // Write the output file if (_outFileBase != "") { ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out); outTextFile << _det << " " << _sel << " " << eff << endl; outTextFile.close(); } }