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

Contents of /PamCut/Collections/EffCollection/EffCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Thu Oct 1 10:34:34 2009 UTC (15 years, 3 months ago) by pam-fi
Branch: MAIN
Changes since 1.6: +3 -3 lines
Slight change in output file name.

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 #include "TGraphAsymmErrors.h"
12
13 extern "C" {
14 bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*);
15 }
16
17 EffCollection::EffCollection(const char *collectionName, TString outFileBase, int errMethod) :
18 VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase(
19 outFileBase), _errMethod(errMethod), _det(0), _sel(0) {
20
21 }
22
23 void EffCollection::AddDetectorCut(PamCut &cut) {
24 _detCollection.AddCut(cut);
25 }
26
27 void EffCollection::AddSelectionCut(PamCut &cut) {
28 _selCollection.AddCut(cut);
29 }
30
31 void EffCollection::AddDetectorAction(CollectionAction &action) {
32 _detCollection.AddAction(action);
33 }
34
35 void EffCollection::AddSelectionAction(CollectionAction &action) {
36 _selCollection.AddAction(action);
37 }
38
39 int EffCollection::ApplyCut(PamLevel2 *event) {
40
41 _nEv++;
42 if (_selCollection.ApplyCut(event) == CUTOK) {
43 _sel++;
44 if (_detCollection.ApplyCut(event) == CUTOK) {
45 _det++;
46 _nGood++;
47 return CUTOK;
48 }
49 }
50
51 return 0;
52 }
53
54 void EffCollection::Finalize() {
55 // Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize
56 for (unsigned int i = 0; i < _selCollection.GetSize(); i++)
57 _cuts.push_back(_selCollection.GetCut(i));
58 for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
59 _cuts.push_back(_detCollection.GetCut(i));
60 // Now all the cuts are in place, and VerboseCollection can print its report
61 VerboseCollection::Finalize();
62
63 // Compute the error
64 Int_t sel = (Int_t) _sel;
65 Int_t det = (Int_t) _det;
66 Double_t eff, errLow, errHigh;
67 if (_errMethod == EFFERR_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 }
85 if (_errMethod == EFFERR_SERGIO) {
86 efficiency_(&sel, &det, &eff, &errLow, &errHigh);
87 }
88
89 // Add some info about efficiency to the stdout
90 cout << " ****** Efficiency informations ******\n";
91 cout << " Detector cuts:\n";
92 for (unsigned int i = 0; i < _detCollection.GetSize(); i++)
93 cout << " - " << _detCollection.GetCut(i)->GetName() << "\n";
94 cout << " Total detector efficiency: " << eff << " +" << errHigh << "-" << errLow << endl;
95
96 // Write the output file
97 if (_outFileBase != "") {
98
99 ofstream outTextFile((_outFileBase + "-" + GetName() + ".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 }

  ViewVC Help
Powered by ViewVC 1.1.23