/* * 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 rigBinsFile, TString &outFileBase, bool absRig) : VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( outFileBase), _absRig(absRig), _bins(0), _sel(0), _det(0), _outUp(0), _outDown(0) { ifstream rigBinListFile; rigBinListFile.open(rigBinsFile); TString auxString; while (!rigBinListFile.eof()) { rigBinListFile >> auxString; if (auxString != "") { _bins.push_back(auxString.Atof()); } } rigBinListFile.close(); _sel.resize(_bins.size() - 1, 0); _det.resize(_bins.size() - 1, 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) { // See if the rigidity of the event is between the limits float rig; if (_absRig) rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); else rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection(); if (rig >= _bins[0]) { int i = 1; while (rig >= _bins[i] && i < (int) _bins.size()) { i++; } i--; if (i < (int) (_sel.size())) { _nEv++; // Rigidity is OK, let's apply the cuts if (_selCollection.ApplyCut(event) == CUTOK) { _sel[i]++; if (_detCollection.ApplyCut(event) == CUTOK) { _det[i]++; _nGood++; return CUTOK; } } } else _outUp++; } else _outDown++; 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 cout << " ****** Efficiency informations ******\n"; cout << " Detector cuts:\n"; for (unsigned int i = 0; i < _detCollection.GetSize(); i++) cout << " - " << _detCollection.GetCut(i)->GetName() << "\n"; cout << " Events below the minimum rigidity: " << _outDown << "\n"; cout << " Events above the maximum rigidity: " << _outUp << "\n"; cout << " Total detector efficiency: " << (float) _detCollection.GetNGood() / (float) (_selCollection.GetCut(_selCollection.GetSize() - 1)->GetNGood()) << "\n" << endl; // Write the output files if (_outFileBase != "") { ofstream outTextFile((_outFileBase + "-sel.txt").Data(), ios_base::out); for (unsigned int i = 0; i < _sel.size(); i++) { outTextFile << _sel[i] << "\n"; } outTextFile.close(); outTextFile.open((_outFileBase + "-det.txt").Data(), ios_base::out); for (unsigned int i = 0; i < _det.size(); i++) { outTextFile << _det[i] << "\n"; } outTextFile.close(); outTextFile.open((_outFileBase + "-eff.txt").Data(), ios_base::out); for (unsigned int i = 0; i < _det.size(); i++) { if (_sel[i] != 0) outTextFile << (float) _det[i] / (float) _sel[i] << "\n"; else outTextFile << "0.\n"; } outTextFile.close(); } }