/[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.5 by pam-fi, Thu Sep 24 18:17:28 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) :  extern "C" {
13    VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(  bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*);
14        outFileBase), _absRig(absRig), _bins(0), _sel(0), _det(0), _outUp(0), _outDown(0) {  }
   
   ifstream rigBinListFile;  
   rigBinListFile.open(rigBinsFile);  
15    
16    TString auxString;  EffCollection::EffCollection(const char *collectionName, TString outFileBase) :
17    while (!rigBinListFile.eof()) {    VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(
18      rigBinListFile >> auxString;        outFileBase), _det(0), _sel(0) {
     if (auxString != "") {  
       _bins.push_back(auxString.Atof());  
     }  
   }  
   rigBinListFile.close();  
19    
   _sel.resize(_bins.size() - 1, 0);  
   _det.resize(_bins.size() - 1, 0);  
20  }  }
21    
22  void EffCollection::AddDetectorCut(PamCut &cut) {  void EffCollection::AddDetectorCut(PamCut &cut) {
# Line 47  void EffCollection::AddSelectionAction(C Line 37  void EffCollection::AddSelectionAction(C
37    
38  int EffCollection::ApplyCut(PamLevel2 *event) {  int EffCollection::ApplyCut(PamLevel2 *event) {
39    
40    // See if the rigidity of the event is between the limits    _nEv++;
41    float rig;    if (_selCollection.ApplyCut(event) == CUTOK) {
42    if (_absRig)      _sel++;
43      rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();      if (_detCollection.ApplyCut(event) == CUTOK) {
44    else        _det++;
45      rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection();        _nGood++;
46    if (rig >= _bins[0]) {        return CUTOK;
     int i = 1;  
     while (rig >= _bins[i] && i < (int) _bins.size()) {  
       i++;  
47      }      }
     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++;  
48    }    }
   else  
     _outDown++;  
49    
50    return 0;    return 0;
51  }  }
# Line 88  void EffCollection::Finalize() { Line 58  void EffCollection::Finalize() {
58      _cuts.push_back(_detCollection.GetCut(i));      _cuts.push_back(_detCollection.GetCut(i));
59    // 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
60    VerboseCollection::Finalize();    VerboseCollection::Finalize();
61    // Add some info about efficiency  
62      // Compute the error
63      Int_t sel = (Int_t) _sel;
64      Int_t det = (Int_t) _det;
65      Double_t eff, errLow, errHigh;
66      efficiency_(&sel, &det, &eff, &errLow, &errHigh);
67    
68      // Add some info about efficiency to the stdout
69    cout << "    ****** Efficiency informations ******\n";    cout << "    ****** Efficiency informations ******\n";
70    cout << "    Detector cuts:\n";    cout << "    Detector cuts:\n";
71    for (unsigned int i = 0; i < _detCollection.GetSize(); i++)    for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
72      cout << "      - " << _detCollection.GetCut(i)->GetName() << "\n";      cout << "      - " << _detCollection.GetCut(i)->GetName() << "\n";
73    cout << "    Events below the minimum rigidity: " << _outDown << "\n";    cout << "    Total detector efficiency: " << eff << " +" << errHigh << "-" << errLow << 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;  
74    
75    // Write the output files    // Write the output file
76    if (_outFileBase != "") {    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();  
77    
78      outTextFile.open((_outFileBase + "-eff.txt").Data(), ios_base::out);      ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out);
79      for (unsigned int i = 0; i < _det.size(); i++) {      streamsize newPrec = 4;
80        if (_sel[i] != 0)      outTextFile.precision(newPrec);
81          outTextFile << (float) _det[i] / (float) _sel[i] << "\n";      outTextFile.setf(ios::fixed, ios::floatfield);
82        else      outTextFile << setw(10) << det << setw(10) << sel << setw(10) << eff << setw(10) << errLow << setw(10) << errHigh
83          outTextFile << "0.\n";          << endl;
     }  
84      outTextFile.close();      outTextFile.close();
   
85    }    }
86    
87  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23