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

Annotation of /PamCut/Collections/EffRigCollection/EffRigCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Thu Sep 24 18:17:26 2009 UTC (15 years, 2 months ago) by pam-fi
Branch: MAIN
Changes since 1.1: +23 -5 lines
Error computation for efficiency added, output format modified.

1 pam-fi 1.1 /*
2     * EffRigCollection.cpp
3     *
4     * Created on: 10/ago/2009
5     * Author: Nicola Mori
6     */
7    
8     /*! @file EffRigCollection.cpp The EffRigCollection class implementation file. */
9    
10     #include "EffRigCollection.h"
11    
12 pam-fi 1.2 extern "C" {
13     bool efficiency_(Int_t*, Int_t*, Double_t*, Double_t*, Double_t*);
14     }
15    
16 pam-fi 1.1 EffRigCollection::EffRigCollection(const char *collectionName, TString outFileBase, TString rigBinsFile, bool absRig) :
17     EffCollection(collectionName, outFileBase), _bins(0), _selVector(0), _detVector(0), _outUp(0), _outDown(0) {
18    
19     ifstream rigBinListFile;
20     rigBinListFile.open(rigBinsFile);
21    
22     TString auxString;
23     while (!rigBinListFile.eof()) {
24     rigBinListFile >> auxString;
25     if (auxString != "") {
26     _bins.push_back(auxString.Atof());
27     }
28     }
29     rigBinListFile.close();
30    
31     _selVector.resize(_bins.size() - 1, 0);
32     _detVector.resize(_bins.size() - 1, 0);
33     }
34    
35     int EffRigCollection::ApplyCut(PamLevel2 *event) {
36    
37     _nEv++;
38     if (_selCollection.ApplyCut(event) == CUTOK) {
39     // Check if the event is inside the rigidity range
40     // NOTE: at this point a TrkPhSinCut should be already performed,
41     // since we are going to retrieve rigidity.
42     float rig;
43     if (_absRig) {
44     rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();
45     }
46     else
47     rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection();
48     if (rig >= _bins[0]) {
49     int i = 1;
50     while (rig >= _bins[i] && i < (int) _bins.size()) {
51     i++;
52     }
53     i--;
54    
55     if (i < (int) (_selVector.size())) {
56     _selVector[i]++;
57 pam-fi 1.2 _sel++;
58 pam-fi 1.1 if (_detCollection.ApplyCut(event) == CUTOK) {
59     _detVector[i]++;
60 pam-fi 1.2 _det++;
61 pam-fi 1.1 _nGood++;
62     return CUTOK;
63     }
64     }
65     else
66     _outUp++;
67    
68     }
69     else {
70     _outDown++;
71     return 0;
72     }
73     }
74    
75     return 0;
76     }
77    
78     void EffRigCollection::Finalize() {
79    
80     // Print the report
81     EffCollection::Finalize();
82     cout << " Events below the minimum rigidity: " << _outDown << "\n";
83     cout << " Events above the maximum rigidity: " << _outUp << "\n";
84    
85 pam-fi 1.2 // Compute the error
86     Int_t sel[_selVector.size()];
87     Int_t det[_detVector.size()];
88     Double_t eff[_selVector.size()];
89     Double_t errLow[_selVector.size()];
90     Double_t errHigh[_selVector.size()];
91     for (unsigned int i = 0; i < _selVector.size(); i++) {
92     sel[i] = (Int_t) _selVector[i];
93     det[i] = (Int_t) _detVector[i];
94     efficiency_(&(sel[i]), &(det[i]), &(eff[i]), &(errLow[i]), &(errHigh[i]));
95     }
96 pam-fi 1.1 // Write the output files
97     if (_outFileBase != "") {
98     ofstream outTextFile((_outFileBase + "-eff-rig.txt").Data(), ios_base::out);
99 pam-fi 1.2 streamsize newPrec = 4;
100     outTextFile.precision(newPrec);
101     outTextFile.setf(ios::fixed, ios::floatfield);
102 pam-fi 1.1 for (unsigned int i = 0; i < _selVector.size(); i++) {
103 pam-fi 1.2 outTextFile << setw(10) << _detVector[i] << setw(10) << _selVector[i];
104 pam-fi 1.1 if (_selVector[i] != 0)
105 pam-fi 1.2 outTextFile << setw(10) << eff[i] << setw(10) << errLow[i] << setw(10) << errHigh[i] << "\n";
106 pam-fi 1.1 else
107 pam-fi 1.2 outTextFile << setw(10) << 0. << setw(10) << 0. << setw(10) << 0. << endl;
108 pam-fi 1.1
109     }
110     outTextFile.close();
111     }
112    
113     }

  ViewVC Help
Powered by ViewVC 1.1.23