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

Annotation of /PamCut/Collections/EffCollection/EffCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Tue Oct 27 10:24:01 2009 UTC (15 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.7: +26 -7 lines
New ownership feature added.

1 pam-fi 1.1 /*
2     * EffCollection.cpp
3     *
4     * Created on: 10/ago/2009
5     * Author: Nicola Mori
6     */
7    
8     /*! @file EffCollection.cpp The EffCollection class implementation file. */
9    
10     #include "EffCollection.h"
11 pam-fi 1.6 #include "TGraphAsymmErrors.h"
12 pam-fi 1.1
13 pam-fi 1.5 extern "C" {
14 pam-fi 1.8 /*! @brief Fortran routine by Sergio Ricciarini which computes errors on the efficiency.
15     *
16     * This routine has been developed to carefully evaluate the error bars on the efficiency,
17     * which must have a value between 0 and 1. See the appendix of Sergio's PhD thesis for more
18     * details.
19     * The important thing is that the computed efficiency will have the unphysical value 1.1
20     * if there are less than 8 events in the efficiency sample (eg., the sample used to compute the
21     * efficiency). This is necessary to have a reliable estimate of the errors.
22     *
23     * @param sel Pointer to an Int_t variable containing the number of events in the efficiency sample.
24     * @param det Pointer to an Int_t variable containing the number of events in the efficiency sample
25     * which satisfied the set of cuts for which the efficiency is being measured.
26     * @param eff Pointer to a Double_t variable where the computed efficiency will be returned.
27     * @param errLow Pointer to a Double_t variable where the length of the lower error bar will
28     * be returned.
29     * @param errHigh Pointer to a Double_t variable where the length of the upper error bar will
30     * be returned.
31     * @return Not clear at this point... ignore it.
32     */
33     bool efficiency_(Int_t* sel, Int_t* det, Double_t* eff, Double_t* errLow, Double_t* errHigh);
34 pam-fi 1.5 }
35    
36 pam-fi 1.8 EffCollection::EffCollection(const char *collectionName, TString outFileBase, int errMethod, bool owns) :
37     VerboseCollection(collectionName, owns), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(
38 pam-fi 1.6 outFileBase), _errMethod(errMethod), _det(0), _sel(0) {
39 pam-fi 1.1
40     }
41    
42 pam-fi 1.8 void EffCollection::AddDetectorCut(PamCut *cut) {
43 pam-fi 1.1 _detCollection.AddCut(cut);
44     }
45    
46 pam-fi 1.8 void EffCollection::AddSelectionCut(PamCut *cut) {
47 pam-fi 1.1 _selCollection.AddCut(cut);
48     }
49    
50 pam-fi 1.8 void EffCollection::AddDetectorAction(CollectionAction *action) {
51 pam-fi 1.1 _detCollection.AddAction(action);
52     }
53    
54 pam-fi 1.8 void EffCollection::AddSelectionAction(CollectionAction *action) {
55 pam-fi 1.1 _selCollection.AddAction(action);
56     }
57    
58     int EffCollection::ApplyCut(PamLevel2 *event) {
59    
60 pam-fi 1.3 _nEv++;
61     if (_selCollection.ApplyCut(event) == CUTOK) {
62     _sel++;
63     if (_detCollection.ApplyCut(event) == CUTOK) {
64     _det++;
65     _nGood++;
66     return CUTOK;
67 pam-fi 1.1 }
68     }
69    
70     return 0;
71     }
72    
73     void EffCollection::Finalize() {
74     // Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize
75     for (unsigned int i = 0; i < _selCollection.GetSize(); i++)
76     _cuts.push_back(_selCollection.GetCut(i));
77     for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
78     _cuts.push_back(_detCollection.GetCut(i));
79     // Now all the cuts are in place, and VerboseCollection can print its report
80     VerboseCollection::Finalize();
81 pam-fi 1.3
82 pam-fi 1.5 // Compute the error
83     Int_t sel = (Int_t) _sel;
84     Int_t det = (Int_t) _det;
85     Double_t eff, errLow, errHigh;
86 pam-fi 1.7 if (_errMethod == EFFERR_ROOT) {
87 pam-fi 1.6 if (sel < 8) {
88     eff = 1.1;
89     errLow = errHigh = 0.;
90     }
91     else {
92     TH1I pass("pass", "pass", 1, 0., 1.);
93     TH1I total("total", "total", 1, 0., 1.);
94     pass.Fill(0.5, det);
95     total.Fill(0.5, sel);
96     TGraphAsymmErrors errGraph;
97     errGraph.BayesDivide(&pass, &total);
98     Double_t dummy;
99     errGraph.GetPoint(0, dummy, eff);
100     errLow = errGraph.GetErrorYlow(0);
101     errHigh = errGraph.GetErrorYhigh(0);
102     }
103     }
104 pam-fi 1.7 if (_errMethod == EFFERR_SERGIO) {
105 pam-fi 1.6 efficiency_(&sel, &det, &eff, &errLow, &errHigh);
106     }
107 pam-fi 1.5
108     // Add some info about efficiency to the stdout
109 pam-fi 1.2 cout << " ****** Efficiency informations ******\n";
110     cout << " Detector cuts:\n";
111     for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
112     cout << " - " << _detCollection.GetCut(i)->GetName() << "\n";
113 pam-fi 1.5 cout << " Total detector efficiency: " << eff << " +" << errHigh << "-" << errLow << endl;
114 pam-fi 1.1
115 pam-fi 1.3 // Write the output file
116 pam-fi 1.1 if (_outFileBase != "") {
117 pam-fi 1.5
118 pam-fi 1.7 ofstream outTextFile((_outFileBase + "-" + GetName() + ".txt").Data(), ios_base::out);
119 pam-fi 1.5 streamsize newPrec = 4;
120     outTextFile.precision(newPrec);
121     outTextFile.setf(ios::fixed, ios::floatfield);
122     outTextFile << setw(10) << det << setw(10) << sel << setw(10) << eff << setw(10) << errLow << setw(10) << errHigh
123     << endl;
124 pam-fi 1.1 outTextFile.close();
125     }
126    
127     }

  ViewVC Help
Powered by ViewVC 1.1.23