/[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.1 by pam-fi, Tue Aug 11 08:37:18 2009 UTC revision 1.6 by pam-fi, Fri Sep 25 15:02:03 2009 UTC
# Line 8  Line 8 
8  /*! @file EffCollection.cpp The EffCollection class implementation file. */  /*! @file EffCollection.cpp The EffCollection class implementation file. */
9    
10  #include "EffCollection.h"  #include "EffCollection.h"
11    #include "TGraphAsymmErrors.h"
12    
13  EffCollection::EffCollection(const char *collectionName, TString rigBinsFile, TString &outFileBase, bool absRig) :  extern "C" {
14    VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(  bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*);
15        outFileBase), _absRig(absRig), _bins(0), _sel(0), _det(0), _outUp(0), _outDown(0) {  }
   
   ifstream rigBinListFile;  
   rigBinListFile.open(rigBinsFile);  
16    
17    TString auxString;  EffCollection::EffCollection(const char *collectionName, TString outFileBase, int errMethod) :
18    while (!rigBinListFile.eof()) {    VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(
19      rigBinListFile >> auxString;        outFileBase), _errMethod(errMethod), _det(0), _sel(0) {
     if (auxString != "") {  
       _bins.push_back(auxString.Atof());  
     }  
   }  
   rigBinListFile.close();  
20    
   _sel.resize(_bins.size() - 1, 0);  
   _det.resize(_bins.size() - 1, 0);  
21  }  }
22    
23  void EffCollection::AddDetectorCut(PamCut &cut) {  void EffCollection::AddDetectorCut(PamCut &cut) {
# Line 47  void EffCollection::AddSelectionAction(C Line 38  void EffCollection::AddSelectionAction(C
38    
39  int EffCollection::ApplyCut(PamLevel2 *event) {  int EffCollection::ApplyCut(PamLevel2 *event) {
40    
41    // See if the rigidity of the event is between the limits    _nEv++;
42    float rig;    if (_selCollection.ApplyCut(event) == CUTOK) {
43    if (_absRig)      _sel++;
44      rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();      if (_detCollection.ApplyCut(event) == CUTOK) {
45    else        _det++;
46      rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection();        _nGood++;
47    if (rig >= _bins[0]) {        return CUTOK;
     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;  
         }  
       }  
48      }      }
     else  
       _outUp++;  
49    }    }
   else  
     _outDown++;  
50    
51    return 0;    return 0;
52  }  }
# Line 88  void EffCollection::Finalize() { Line 59  void EffCollection::Finalize() {
59      _cuts.push_back(_detCollection.GetCut(i));      _cuts.push_back(_detCollection.GetCut(i));
60    // 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
61    VerboseCollection::Finalize();    VerboseCollection::Finalize();
   // Add some info about efficiency  
   cout << "    Events below the minimum rigidity: " << _outDown << "\n";  
   cout << "    Events above the maximum rigidity: " << _outUp << "\n";  
   cout << "    Integrated efficiency: "  
        << (float) _detCollection.GetNGood() /  
           (float) (_selCollection.GetCut(_selCollection.GetSize() - 1)->GetNGood())  
        << "\n" << endl;  
62    
63    // Write the output files    // Compute the error
64    if (_outFileBase != "") {    Int_t sel = (Int_t) _sel;
65      ofstream outTextFile((_outFileBase + "-sel.txt").Data(), ios_base::out);    Int_t det = (Int_t) _det;
66      for (unsigned int i = 0; i < _sel.size(); i++) {    Double_t eff, errLow, errHigh;
67        outTextFile << _sel[i] << "\n";    if (_errMethod == EFFRIG_ROOT) {
68        if (sel < 8) {
69          eff = 1.1;
70          errLow = errHigh = 0.;
71        }
72        else {
73          TH1I pass("pass", "pass", 1, 0., 1.);
74          TH1I total("total", "total", 1, 0., 1.);
75          pass.Fill(0.5, det);
76          total.Fill(0.5, sel);
77          TGraphAsymmErrors errGraph;
78          errGraph.BayesDivide(&pass, &total);
79          Double_t dummy;
80          errGraph.GetPoint(0, dummy, eff);
81          errLow = errGraph.GetErrorYlow(0);
82          errHigh = errGraph.GetErrorYhigh(0);
83      }      }
84      outTextFile.close();    }
85      if (_errMethod == EFFRIG_SERGIO) {
86        efficiency_(&sel, &det, &eff, &errLow, &errHigh);
87      }
88    
89      outTextFile.open((_outFileBase + "-det.txt").Data(), ios_base::out);    // Add some info about efficiency to the stdout
90      for (unsigned int i = 0; i < _det.size(); i++) {    cout << "    ****** Efficiency informations ******\n";
91        outTextFile << _det[i] << "\n";    cout << "    Detector cuts:\n";
92      }    for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
93      outTextFile.close();      cout << "      - " << _detCollection.GetCut(i)->GetName() << "\n";
94      cout << "    Total detector efficiency: " << eff << " +" << errHigh << "-" << errLow << endl;
95    
96      outTextFile.open((_outFileBase + "-eff.txt").Data(), ios_base::out);    // Write the output file
97      for (unsigned int i = 0; i < _det.size(); i++) {    if (_outFileBase != "") {
       if (_sel[i] != 0)  
         outTextFile << (float) _det[i] / (float) _sel[i] << "\n";  
       else  
         outTextFile << "0.\n";  
     }  
     outTextFile.close();  
98    
99        ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out);
100        streamsize newPrec = 4;
101        outTextFile.precision(newPrec);
102        outTextFile.setf(ios::fixed, ios::floatfield);
103        outTextFile << setw(10) << det << setw(10) << sel << setw(10) << eff << setw(10) << errLow << setw(10) << errHigh
104            << endl;
105        outTextFile.close();
106    }    }
107    
108  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.23