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

Diff of /PamCut/Collections/EffRigCollection/EffRigCollection.cpp

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

revision 1.3 by pam-fi, Fri Sep 25 15:02:02 2009 UTC revision 1.7 by pam-fi, Thu Mar 18 14:40:51 2010 UTC
# Line 12  Line 12 
12  #include "TGraphAsymmErrors.h"  #include "TGraphAsymmErrors.h"
13    
14  extern "C" {  extern "C" {
15  bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*);  /*! @brief Fortran routine by Sergio Ricciarini which computes errors on the efficiency.
16     *
17     * This routine has been developed to carefully evaluate the error bars on the efficiency,
18     * which must have a value between 0 and 1. See the appendix of Sergio's PhD thesis for more
19     * details.
20     * The important thing is that the computed efficiency will have the unphysical value 1.1
21     * if there are less than 8 events in the efficiency sample (eg., the sample used to compute the
22     * efficiency). This is necessary to have a reliable estimate of the errors.
23     *
24     * @param sel Pointer to an Int_t variable containing the number of events in the efficiency sample.
25     * @param det Pointer to an Int_t variable containing the number of events in the efficiency sample
26     *            which satisfied the set of cuts  for which the efficiency is being measured.
27     * @param eff Pointer to a Double_t variable where the computed efficiency will be returned.
28     * @param errLow Pointer to a Double_t variable where the length of the lower error bar will
29     *               be returned.
30     * @param errHigh Pointer to a Double_t variable where the length of the upper error bar will
31     *               be returned.
32     * @return Not clear at this point... ignore it.
33     */
34    bool efficiency_(Int_t* sel, Int_t* det, Double_t* eff, Double_t* errLow, Double_t* errHigh);
35  }  }
36    
37  EffRigCollection::EffRigCollection(const char *collectionName, TString outFileBase, TString rigBinsFile, int errMethod) :  EffRigCollection::EffRigCollection(const char *collectionName, TString outFileBase, TString rigBinsFile, int errMethod,
38    EffCollection(collectionName, outFileBase, errMethod), _bins(0), _selVector(0), _detVector(0), _outUp(0), _outDown(0) {      bool owns) :
39      EffCollection(collectionName, outFileBase, errMethod, owns), _bins(0), _selVector(0), _detVector(0), _outUp(0),
40          _outDown(0) {
41    
42    ifstream rigBinListFile;    ifstream rigBinListFile;
43    rigBinListFile.open(rigBinsFile);    rigBinListFile.open(rigBinsFile);
# Line 98  void EffRigCollection::Finalize() { Line 119  void EffRigCollection::Finalize() {
119    errGraph.SetMarkerStyle(7);    errGraph.SetMarkerStyle(7);
120    errGraph.GetYaxis()->SetRangeUser(0, 1.2);    errGraph.GetYaxis()->SetRangeUser(0, 1.2);
121    
122    if (_errMethod == EFFRIG_ROOT) {    if (_errMethod == EFFERR_ROOT) {
123      double binning[_bins.size()];      double binning[_bins.size()];
124      for (unsigned int i = 0; i < _bins.size(); i++)      for (unsigned int i = 0; i < _bins.size(); i++)
125        binning[i] = _bins[i];        binning[i] = _bins[i];
# Line 106  void EffRigCollection::Finalize() { Line 127  void EffRigCollection::Finalize() {
127      TH1I pass("pass", "pass", _bins.size() - 1, binning);      TH1I pass("pass", "pass", _bins.size() - 1, binning);
128      TH1I total("total", "total", _bins.size() - 1, binning);      TH1I total("total", "total", _bins.size() - 1, binning);
129      for (unsigned int i = 0; i < _selVector.size(); i++) {      for (unsigned int i = 0; i < _selVector.size(); i++) {
       cout << (binning[i + 1] + binning[i]) / 2. << "  " << det[i] << "  " << sel[i] << endl;  
130        for (int j = 0; j < det[i]; j++)        for (int j = 0; j < det[i]; j++)
131          pass.Fill((binning[i + 1] + binning[i]) / 2.);          pass.Fill((binning[i + 1] + binning[i]) / 2.);
132        for (int j = 0; j < sel[i]; j++)        for (int j = 0; j < sel[i]; j++)
# Line 117  void EffRigCollection::Finalize() { Line 137  void EffRigCollection::Finalize() {
137      Double_t graphX;      Double_t graphX;
138      double currBin;      double currBin;
139      int currPoint = 0;      int currPoint = 0;
140      //cout << errGraph.GetN() << "  " << pass.GetNbinsX() << "  " << total.GetNbinsX() << endl;  
141      for (unsigned int i = 0; i < _selVector.size(); i++) {      for (unsigned int i = 0; i < _selVector.size(); i++) {
142        errGraph.GetPoint(currPoint, graphX, eff[i]);        errGraph.GetPoint(currPoint, graphX, eff[i]);
143        currBin = (binning[i + 1] + binning[i]) / 2.;        currBin = (binning[i + 1] + binning[i]) / 2.;
# Line 134  void EffRigCollection::Finalize() { Line 154  void EffRigCollection::Finalize() {
154      }      }
155    
156    }    }
157    if (_errMethod == EFFRIG_SERGIO) {    if (_errMethod == EFFERR_SERGIO) {
158      for (unsigned int i = 0; i < _selVector.size(); i++) {      for (unsigned int i = 0; i < _selVector.size(); i++) {
159        efficiency_(&(sel[i]), &(det[i]), &(eff[i]), &(errLow[i]), &(errHigh[i]));        efficiency_(&(sel[i]), &(det[i]), &(eff[i]), &(errLow[i]), &(errHigh[i]));
160    
161          float R = (_bins[i] + _bins[i + 1]) / 2.;
162          float halfBin = (_bins[i + 1] - _bins[i]) / 2.;
163          errGraph.SetPoint(i, R, eff[i]);
164          errGraph.SetPointError(i, halfBin, halfBin, errLow[i], errHigh[i]);
165    
166      }      }
167    
168    }    }
169    
170    // Write the output files    // Write the output files
171    if (_outFileBase != "") {    if (_outFileBase != "") {
172      ofstream outTextFile((_outFileBase + "-eff-rig.txt").Data(), ios_base::out);      ofstream outTextFile((_outFileBase + "-" + GetName() + "-rig.txt").Data(), ios_base::out);
173      streamsize newPrec = 4;      streamsize newPrec = 4;
174      outTextFile.precision(newPrec);      outTextFile.precision(newPrec);
175      outTextFile.setf(ios::fixed, ios::floatfield);      outTextFile.setf(ios::fixed, ios::floatfield);
176      for (unsigned int i = 0; i < _selVector.size(); i++) {      for (unsigned int i = 0; i < _selVector.size(); i++) {
177        outTextFile << setw(10) << _detVector[i] << setw(10) << _selVector[i];        outTextFile << setw(10) << _bins[i] << " " << setw(10) << _bins[i + 1] << " " << setw(10) << _detVector[i] << " "
178              << setw(10) << _selVector[i] << " ";
179        if (_selVector[i] != 0)        if (_selVector[i] != 0)
180          outTextFile << setw(10) << eff[i] << setw(10) << errLow[i] << setw(10) << errHigh[i] << "\n";          outTextFile << setw(10) << eff[i] << " " << setw(10) << errLow[i] << " " << setw(10) << errHigh[i];
181        else        else
182          outTextFile << setw(10) << 0. << setw(10) << 0. << setw(10) << 0. << endl;          outTextFile << setw(10) << 0. << " " << setw(10) << 0. << " " << setw(10) << 0.;
183          if (i < _selVector.size() - 1) //Avoids to print an empty line at the end of the file
184            outTextFile << endl;
185    
186      }      }
187    
188      outTextFile.close();      outTextFile.close();
189      if (_errMethod == EFFRIG_ROOT) {  
190        TFile outRootFile((_outFileBase + "-eff-rig.root"), "RECREATE");      TFile outRootFile((_outFileBase + "-" + GetName() + "-rig.root"), "RECREATE");
191        outRootFile.cd();      outRootFile.cd();
192        errGraph.Write();      errGraph.Write();
193        outRootFile.Close();      outRootFile.Close();
194      }  
195    }    }
196    
197  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23