]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PWG2/RESONANCES/AliRsnCutSet.cxx
A macro to test the output size in memory based on the output file.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutSet.cxx
... / ...
CommitLineData
1//
2// Class AliRsnCutSet
3//
4// This is the front-end for cut management and checking.
5// It must be prepared by adding all required single cuts,
6// and then with a logical expression which combines all cuts
7// with the "AND", "OR" and "NOT" operators.
8//
9
10#include "AliLog.h"
11
12#include "AliRsnExpression.h"
13
14#include "AliRsnCutSet.h"
15
16ClassImp(AliRsnCutSet)
17
18//_____________________________________________________________________________
19AliRsnCutSet::AliRsnCutSet(AliRsnCut::ETarget target) :
20 TNamed(),
21 fTarget(target),
22 fCuts(0),
23 fNumOfCuts(0),
24 fCutScheme(""),
25 fCutSchemeIndexed(""),
26 fBoolValues(0),
27 fIsScheme(kFALSE),
28 fExpression(0)
29{
30//
31// Constructor without name (not recommended)
32//
33
34 fBoolValues = new Bool_t[1];
35 AliRsnExpression::fgCutSet = this;
36}
37
38//_____________________________________________________________________________
39AliRsnCutSet::AliRsnCutSet(TString name, AliRsnCut::ETarget target) :
40 TNamed(name, name),
41 fTarget(target),
42 fCuts(0),
43 fNumOfCuts(0),
44 fCutScheme(""),
45 fCutSchemeIndexed(""),
46 fBoolValues(0),
47 fIsScheme(kFALSE),
48 fExpression(0)
49{
50//
51// Constructor with argument name (recommended)
52//
53
54 fBoolValues = new Bool_t[1];
55 fExpression = 0;
56 AliRsnExpression::fgCutSet = this;
57}
58
59//_____________________________________________________________________________
60AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
61 TNamed((TNamed) copy),
62 fTarget(copy.fTarget),
63 fCuts(copy.fCuts),
64 fNumOfCuts(copy.fNumOfCuts),
65 fCutScheme(copy.fCutScheme),
66 fCutSchemeIndexed(copy.fCutSchemeIndexed),
67 fBoolValues(0),
68 fIsScheme(copy.fIsScheme),
69 fExpression(copy.fExpression)
70{
71//
72// Copy constructor
73//
74
75 AliRsnExpression::fgCutSet = this;
76}
77
78//_____________________________________________________________________________
79AliRsnCutSet::~AliRsnCutSet()
80{
81//
82// Destructor
83//
84
85 delete fExpression;
86 delete [] fBoolValues;
87}
88
89//_____________________________________________________________________________
90void AliRsnCutSet::AddCut(AliRsnCut *cut)
91{
92//
93// Add a new cut.
94// This must be done for all components of the final expression.
95// If the target of the cut does not match the target of this,
96// the cut is not added.
97//
98
99 if (!cut->IsTarget(fTarget))
100 {
101 AliError("Cut target does not match the cut-set target. Not added.");
102 return;
103 }
104
105 Int_t i;
106
107 AliDebug(AliLog::kDebug,"<-");
108 fCuts.Add(cut);
109 fNumOfCuts++;
110
111 if (fBoolValues) delete [] fBoolValues;
112
113 fBoolValues = new Bool_t[fNumOfCuts];
114 for (i = 0; i < fNumOfCuts; i++)
115 {
116 fBoolValues[i] = kTRUE;
117 }
118
119 AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
120 AliDebug(AliLog::kDebug,"->");
121}
122
123//_____________________________________________________________________________
124void AliRsnCutSet::ShowCuts() const
125{
126//
127// Prints all cuts
128//
129 AliRsnCut *cut;
130
131 for (Int_t i = 0; i < fCuts.GetEntriesFast() ;i++)
132 {
133 cut = (AliRsnCut*)fCuts.At (i);
134 cut->Print();
135 }
136}
137
138//_____________________________________________________________________________
139Bool_t AliRsnCutSet::IsSelected(TObject *obj1, TObject *obj2)
140{
141//
142// Checks an object according to the cut expression defined here.
143//
144
145 Int_t i;
146
147 if (!fNumOfCuts) return kTRUE;
148
149 Bool_t boolReturn = kTRUE;
150 AliRsnCut *cut;
151 for (i = 0; i < fNumOfCuts; i++) {
152 cut = (AliRsnCut*)fCuts.At(i);
153 fBoolValues[i] = cut->IsSelected(obj1, obj2);
154 }
155
156 if (fIsScheme) boolReturn = Passed();
157 return boolReturn;
158}
159
160//_____________________________________________________________________________
161void AliRsnCutSet::SetCutScheme(const TString & theValue)
162{
163//
164// Define the combination of cuts with logical operators
165// and using the names given to all defined cuts.
166//
167
168 AliDebug(AliLog::kDebug,"<-");
169 fCutScheme = theValue;
170 SetCutSchemeIndexed(theValue);
171 fIsScheme = kTRUE;
172 AliDebug(AliLog::kDebug,"->");
173}
174
175//_____________________________________________________________________________
176void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
177{
178//
179// Internal method which indexes all cuts to organize their combo
180//
181
182 AliDebug(AliLog::kDebug,"<-");
183 theValue.Append(" ");
184 // fCutSchemeIndexed = theValue;
185 fCutSchemeIndexed = GetCutSchemeIndexed();
186 AliDebug(AliLog::kDebug,"->");
187}
188
189//_____________________________________________________________________________
190Int_t AliRsnCutSet::GetIndexByCutName(TString s)
191{
192//
193// Retrieve the cut index from its name
194//
195
196 Int_t i;
197 AliRsnCut *cut;
198
199 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
200 cut = (AliRsnCut*) fCuts.At(i);
201 if (!s.CompareTo(cut->GetName())) return i;
202 }
203
204 return -1;
205}
206
207//_____________________________________________________________________________
208Bool_t AliRsnCutSet::Passed()
209{
210//
211// Combines the cuts according to expression
212// and gives a global response to the cut check
213//
214
215 AliRsnExpression::fgCutSet = this;
216 if (!fExpression) {
217 fExpression = new AliRsnExpression(fCutSchemeIndexed);
218 AliDebug(AliLog::kDebug,"fExpression was created.");
219 }
220
221 return fExpression->Value(*GetCuts());
222}
223
224//_____________________________________________________________________________
225Bool_t AliRsnCutSet::IsValidScheme()
226{
227//
228// Validity check on cut expression specified by user
229//
230
231 return (!(ShowCutScheme().Contains("Error")));
232}
233
234//_____________________________________________________________________________
235TString AliRsnCutSet::ShowCutScheme()
236{
237//
238// Utility method to check validity of expression
239//
240 return fExpression->Unparse();
241}
242
243//_____________________________________________________________________________
244Int_t AliRsnCutSet::TestExpression(TString opt)
245{
246
247// AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
248// cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
249// AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
250// cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
251// AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
252// cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
253//
254// AliRsnCutSet* set = new AliRsnCutSet ("setOne");
255// set->AddCut (cut1);
256// set->AddCut (cut2);
257// set->AddCut (cut3);
258//
259// set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
260//
261// set->ShowCuts ();
262
263 AliDebug(1, opt.Data());
264 return 0;
265}
266
267//_____________________________________________________________________________
268void AliRsnCutSet::PrintSetInfo()
269{
270//
271// Show data about the cut set
272//
273
274 Int_t i;
275
276 AliInfo("========== Rsn Cut Set info ==============");
277 AliInfo(Form("Scheme : %s",fCutScheme.Data()));
278 AliInfo(Form("Scheme : %s",fCutSchemeIndexed.Data()));
279 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
280 AliInfo("====== Cuts ======");
281 AliRsnCut *cut;
282 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
283 cut = (AliRsnCut*) fCuts.At(i);
284 if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
285 }
286 AliInfo("========== END Rsn Cut Mgr info ==============");
287}
288
289//_____________________________________________________________________________
290TString AliRsnCutSet::GetCutSchemeIndexed()
291{
292//
293// Internal method to retrieve the list of cuts with their indexes
294// for evaluation of cut expression
295//
296
297 AliDebug(AliLog::kDebug,"<-");
298 Int_t i;
299 TString str(fCutScheme);
300 AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
301 AliRsnCut *cut;
302 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
303 cut = (AliRsnCut*) fCuts.At(i);
304 str.ReplaceAll(cut->GetName(),Form("%d",i));
305 }
306 AliDebug(AliLog::kDebug,"->");
307 return str;
308}
309
310//_____________________________________________________________________________
311void AliRsnCutSet::SetEvent(AliRsnEvent *event)
312{
313//
314// Set the reference event to all contained cuts
315//
316
317 Int_t i;
318 AliRsnCut *cut;
319 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
320 cut = (AliRsnCut*) fCuts.At(i);
321 if (cut) cut->SetEvent(event);
322 }
323}