/[PAMELA software]/PamCut/Collections/EffCollection/EffCollection.cpp
ViewVC logotype

Diff of /PamCut/Collections/EffCollection/EffCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by pam-fi, Tue Aug 11 13:30:16 2009 UTC revision 1.3 by pam-fi, Wed Aug 12 14:18:13 2009 UTC
# Line 9  Line 9 
9    
10  #include "EffCollection.h"  #include "EffCollection.h"
11    
12  EffCollection::EffCollection(const char *collectionName, TString rigBinsFile, TString &outFileBase, bool absRig) :  EffCollection::EffCollection(const char *collectionName, TString outFileBase) :
13    VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(    VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(
14        outFileBase), _absRig(absRig), _bins(0), _sel(0), _det(0), _outUp(0), _outDown(0) {        outFileBase), _det(0), _sel(0) {
15    
   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);  
16  }  }
17    
18  void EffCollection::AddDetectorCut(PamCut &cut) {  void EffCollection::AddDetectorCut(PamCut &cut) {
# Line 47  void EffCollection::AddSelectionAction(C Line 33  void EffCollection::AddSelectionAction(C
33    
34  int EffCollection::ApplyCut(PamLevel2 *event) {  int EffCollection::ApplyCut(PamLevel2 *event) {
35    
36    // See if the rigidity of the event is between the limits    _nEv++;
37    float rig;    if (_selCollection.ApplyCut(event) == CUTOK) {
38    if (_absRig)      _sel++;
39      rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();      if (_detCollection.ApplyCut(event) == CUTOK) {
40    else        _det++;
41      rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection();        _nGood++;
42    if (rig >= _bins[0]) {        return CUTOK;
     int i = 1;  
     while (rig >= _bins[i] && i < (int) _bins.size()) {  
       i++;  
43      }      }
     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++;  
44    }    }
   else  
     _outDown++;  
45    
46    return 0;    return 0;
47  }  }
# Line 88  void EffCollection::Finalize() { Line 54  void EffCollection::Finalize() {
54      _cuts.push_back(_detCollection.GetCut(i));      _cuts.push_back(_detCollection.GetCut(i));
55    // Now all the cuts are in place, and VerboseCollection can print its report    // Now all the cuts are in place, and VerboseCollection can print its report
56    VerboseCollection::Finalize();    VerboseCollection::Finalize();
57    
58    // Add some info about efficiency    // Add some info about efficiency
59      float eff;
60      if (_sel != 0.)
61        eff = _det / _sel;
62      else
63        eff = 0.;
64    cout << "    ****** Efficiency informations ******\n";    cout << "    ****** Efficiency informations ******\n";
65    cout << "    Detector cuts:\n";    cout << "    Detector cuts:\n";
66    for (unsigned int i = 0; i < _detCollection.GetSize(); i++)    for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
67      cout << "      - " << _detCollection.GetCut(i)->GetName() << "\n";      cout << "      - " << _detCollection.GetCut(i)->GetName() << "\n";
68    cout << "    Events below the minimum rigidity: " << _outDown << "\n";    cout << "    Total detector efficiency: " << eff << endl;
   cout << "    Events above the maximum rigidity: " << _outUp << "\n";  
   cout << "    Total detector efficiency: "  
        << (float) _detCollection.GetNGood() /  
           (float) (_selCollection.GetCut(_selCollection.GetSize() - 1)->GetNGood())  
        << "\n" << endl;  
69    
70    // Write the output files    // Write the output file
71    if (_outFileBase != "") {    if (_outFileBase != "") {
72      ofstream outTextFile((_outFileBase + "-sel.txt").Data(), ios_base::out);      ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out);
73      for (unsigned int i = 0; i < _sel.size(); i++) {      outTextFile << _det << "    " << _sel << "    " << eff << endl;
       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";  
     }  
74      outTextFile.close();      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();  
   
75    }    }
76    
77  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.23