/[PAMELA software]/PamCut/PamCutBase/PamCutBase.cpp
ViewVC logotype

Annotation of /PamCut/PamCutBase/PamCutBase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Wed Dec 2 13:28:53 2009 UTC (15 years ago) by pam-fi
Branch: MAIN
Changes since 1.4: +7 -8 lines
Minor fix in Process to let Setup be  always executed.

1 pam-fi 1.1 /*
2     * PamCutBase.cpp
3     *
4     * Created on: 12-feb-2009
5     * Author: Nicola Mori
6     */
7    
8     /*! @file PamCutBase.cpp Implementation for classes defined in PamCut.h */
9    
10     #include "PamCutBase.h"
11    
12     /* ************** *
13     * PAMCUT
14     * ************** */
15     int PamCut::ApplyCut(PamLevel2 *event) {
16    
17     _nEv++;
18     int result = Check(event);
19     if (result == CUTOK) {
20     _nGood++;
21     OnGood(event);
22     }
23     else {
24     OnBad(event, result);
25     }
26     return result;
27    
28     }
29    
30     void PamCut::Process(PamLevel2 *events, ULong_t firstEvent, ULong_t lastEvent) {
31    
32 pam-fi 1.5 // Prepare the collection for the new analysis
33     Setup(events);
34    
35 pam-fi 1.1 // Check the range of events to analyze
36     if (firstEvent > lastEvent) {
37     return;
38     }
39     if (firstEvent < 0 || lastEvent > events->GetEntries() - 1) {
40     return;
41     }
42    
43     // Apply the cuts
44     for (ULong_t iev = firstEvent; iev < lastEvent + 1; iev++) {
45     events->GetEntry(iev);
46     ApplyCut(events);
47     }
48    
49     // Closes the analysis
50     Finalize();
51    
52     }
53 pam-fi 1.2 void PamCut::Setup(PamLevel2 *events) {
54 pam-fi 1.1 _nEv = _nGood = 0;
55     }
56    
57     const char* PamCut::GetName() const {
58     return _cutName;
59     }
60    
61     void PamCut::SetName(const char *newName) {
62     _cutName = newName;
63     }
64    
65 pam-fi 1.2 PamCut& PamCut::operator=(const PamCut &rightValue) {
66     _cutName = rightValue._cutName;
67     return *this;
68     }
69 pam-fi 1.1
70     /* ************************ *
71     * PAMCUTCOLLECTION
72     * ************************ */
73 pam-fi 1.5 PamCutCollection::~PamCutCollection() {
74 pam-fi 1.1
75 pam-fi 1.5 if (_owns) {
76 pam-fi 1.4 for (unsigned int i = 0; i < _cuts.size(); i++)
77 pam-fi 1.5 if (_cuts[i] != NULL) {
78 pam-fi 1.4 delete _cuts[i];
79     _cuts[i] = NULL;
80     }
81     }
82     }
83    
84     void PamCutCollection::AddCut(PamCut *cut) {
85     _cuts.push_back(cut);
86 pam-fi 1.1 }
87    
88     int PamCutCollection::Check(PamLevel2 *event) {
89    
90     // Apply the cuts
91     if (_cuts.size() == 0) {
92     return CUTOK;
93     }
94    
95     for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
96     if (_cuts[icut]->Check(event) != CUTOK) {
97     return icut;
98     }
99     }
100    
101     return CUTOK;
102     }
103    
104     int PamCutCollection::ApplyCut(PamLevel2 *event) {
105    
106     _nEv++;
107     // Apply the cuts
108     if (_cuts.size() == 0) {
109     _nGood++;
110     OnGood(event);
111     return CUTOK;
112     }
113    
114     for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
115     if (_cuts[icut]->ApplyCut(event) != CUTOK) {
116     OnBad(event, icut);
117     return icut;
118     }
119     }
120    
121     _nGood++;
122     OnGood(event);
123     return CUTOK;
124     }
125    
126     PamCut *PamCutCollection::GetCut(unsigned int iCut) {
127     if (_cuts.size() == 0)
128     return NULL;
129     if (iCut < 0 || iCut > _cuts.size() - 1)
130     return NULL;
131     else
132     return _cuts[iCut];
133     }
134    
135 pam-fi 1.3 PamCut *PamCutCollection::GetCut(const char *cutName) {
136     if (_cuts.size() == 0)
137     return NULL;
138 pam-fi 1.5 for (unsigned int i = 0; i < _cuts.size(); i++) {
139 pam-fi 1.3 if (strcmp(_cuts[i]->GetName(), cutName) == 0)
140     return _cuts[i];
141     }
142    
143     return NULL;
144     }
145    
146 pam-fi 1.1 unsigned int PamCutCollection::GetSize() {
147     return (unsigned int) _cuts.size();
148    
149     }
150    
151     PamCutCollection& PamCutCollection::operator=(const PamCutCollection &rightValue) {
152    
153     PamCut::operator=(rightValue);
154     _cuts = rightValue._cuts;
155     return *this;
156     }
157    
158 pam-fi 1.2 void PamCutCollection::Setup(PamLevel2 *events) {
159 pam-fi 1.1
160     PamCut::Setup(events);
161    
162 pam-fi 1.2 for (unsigned int i = 0; i < GetSize(); i++) {
163 pam-fi 1.1 _cuts[i]->Setup(events);
164     }
165     }
166    
167 pam-fi 1.2 void PamCutCollection::Finalize() {
168 pam-fi 1.1
169 pam-fi 1.2 // PamCut::Finalize() is currently void, but in future it could contain something, so it's good to place a call here.
170 pam-fi 1.1 PamCut::Finalize();
171    
172 pam-fi 1.2 for (unsigned int i = 0; i < GetSize(); i++) {
173 pam-fi 1.1 _cuts[i]->Finalize();
174     }
175     }

  ViewVC Help
Powered by ViewVC 1.1.23