]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutSet.cxx
Made a general review to fix as possible most coding conventions violations.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutSet.cxx
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 "AliRsnCut.h"
13 #include "AliRsnExpression.h"
14
15 #include "AliRsnCutSet.h"
16
17 ClassImp(AliRsnCutSet)
18
19 //_____________________________________________________________________________
20 AliRsnCutSet::AliRsnCutSet() :
21     TNamed(),
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 //_____________________________________________________________________________
39 AliRsnCutSet::AliRsnCutSet(TString name) :
40     TNamed(name, name),
41     fCuts(0),
42     fNumOfCuts(0),
43     fCutScheme(""),
44     fCutSchemeIndexed(""),
45     fBoolValues(0),
46     fIsScheme(kFALSE),
47     fExpression(0)
48 {
49 //
50 // Constructor with argument name (recommended)
51 //
52
53   fBoolValues = new Bool_t[1];
54   fExpression = 0;
55   AliRsnExpression::fgCutSet = this;
56 }
57
58 //_____________________________________________________________________________
59 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
60     TNamed((TNamed) copy),
61     fCuts(copy.fCuts),
62     fNumOfCuts(copy.fNumOfCuts),
63     fCutScheme(copy.fCutScheme),
64     fCutSchemeIndexed(copy.fCutSchemeIndexed),
65     fBoolValues(0),
66     fIsScheme(copy.fIsScheme),
67     fExpression(copy.fExpression)
68 {
69 //
70 // Copy constructor
71 //
72
73   AliRsnExpression::fgCutSet = this;
74 }
75
76 //_____________________________________________________________________________
77 AliRsnCutSet::~AliRsnCutSet()
78 {
79 //
80 // Destructor
81 //
82
83   delete fExpression;
84   delete [] fBoolValues;
85 }
86
87 //_____________________________________________________________________________
88 void AliRsnCutSet::AddCut(AliRsnCut *cut)
89 {
90 //
91 // Add a new cut.
92 // This must be done for all components of the final expression
93 //
94
95   Int_t i;
96
97   AliDebug(AliLog::kDebug,"<-");
98   fCuts.Add(cut);
99   fNumOfCuts++;
100
101   if (fBoolValues) delete fBoolValues;
102
103   fBoolValues = new Bool_t[fNumOfCuts];
104   for (i = 0; i < fNumOfCuts; i++) {
105     fBoolValues[i] = kTRUE;
106   }
107
108   AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
109   AliDebug(AliLog::kDebug,"->");
110 }
111
112 //_____________________________________________________________________________
113 void AliRsnCutSet::ShowCuts() const
114 {
115 //
116 // Prints all cuts
117 //
118 //   AliRsnCut *cut;
119 //   for (Int_t i=0; i<fCuts.GetEntriesFast() ;i++)
120 //   {
121 //     cut = (AliRsnCut*) fCuts.At (i);
122 //     AliInfo (Form ("%s (\"%s\") [%.2f - %.2f]",cut->GetName(),cut->GetTitle(),cut->GetMin(),cut->GetMax()));
123 //   }
124 }
125
126 //_____________________________________________________________________________
127 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnDaughter *daughter)
128 {
129 //
130 // Checks an object according to the cut expression defined here.
131 //
132
133   Int_t i;
134
135   if (!fNumOfCuts) return kTRUE;
136
137   Bool_t boolReturn = kTRUE;
138   AliRsnCut *cut;
139   for (i = 0; i < fNumOfCuts; i++) {
140     cut = (AliRsnCut*)fCuts.At(i);
141     fBoolValues[i] = cut->IsSelected(type,daughter);
142   }
143
144   if (fIsScheme) boolReturn = Passed();
145   return boolReturn;
146 }
147
148 //_____________________________________________________________________________
149 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnPairParticle * pair)
150 {
151 //
152 // Checks an object according to the cut expression defined here.
153 //
154
155   Int_t i;
156
157   if (!fNumOfCuts) return kTRUE;
158
159   Bool_t boolReturn = kTRUE;
160   AliRsnCut *cut;
161   for (i = 0; i < fNumOfCuts; i++) {
162     cut = (AliRsnCut*) fCuts.At(i);
163     fBoolValues[i] = cut->IsSelected(type,pair);
164   }
165
166   if (fIsScheme) boolReturn = Passed();
167   return boolReturn;
168 }
169
170 //_____________________________________________________________________________
171 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * event)
172 {
173 //
174 // Checks an object according to the cut expression defined here.
175 //
176
177   Int_t i;
178   if (!fNumOfCuts) return kTRUE;
179
180   Bool_t boolReturn = kTRUE;
181   AliRsnCut *cut;
182   for (i = 0; i < fNumOfCuts; i++) {
183     cut = (AliRsnCut*) fCuts.At(i);
184     fBoolValues[i] = cut->IsSelected(type,event);
185   }
186
187   if (fIsScheme) boolReturn = Passed();
188   return boolReturn;
189 }
190
191 //_____________________________________________________________________________
192 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * ev1, AliRsnEvent *ev2)
193 {
194 //
195 // Checks an object according to the cut expression defined here.
196 //
197
198   Int_t i;
199   if (!fNumOfCuts) return kTRUE;
200
201   Bool_t boolReturn = kTRUE;
202   AliRsnCut *cut;
203   for (i = 0; i < fNumOfCuts; i++) {
204     cut = (AliRsnCut*) fCuts.At(i);
205     fBoolValues[i] = cut->IsSelected(type,ev1,ev2);
206   }
207
208   if (fIsScheme) boolReturn = Passed();
209   return boolReturn;
210 }
211
212 //_____________________________________________________________________________
213 void AliRsnCutSet::SetCutScheme(const TString & theValue)
214 {
215 //
216 // Define the combination of cuts with logical operators
217 // and using the names given to all defined cuts.
218 //
219
220   AliDebug(AliLog::kDebug,"<-");
221   fCutScheme = theValue;
222   SetCutSchemeIndexed(theValue);
223   fIsScheme = kTRUE;
224   AliDebug(AliLog::kDebug,"->");
225 }
226
227 //_____________________________________________________________________________
228 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
229 {
230 //
231 // Internal method which indexes all cuts to organize their combo
232 //
233
234   AliDebug(AliLog::kDebug,"<-");
235   theValue.Append(" ");
236   // fCutSchemeIndexed = theValue;
237   fCutSchemeIndexed = GetCutSchemeIndexed();
238   AliDebug(AliLog::kDebug,"->");
239 }
240
241 //_____________________________________________________________________________
242 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
243 {
244 //
245 // Retrieve the cut index from its name
246 //
247
248   Int_t i;
249   AliRsnCut *cut;
250
251   for (i = 0; i < fCuts.GetEntriesFast(); i++) {
252     cut = (AliRsnCut*) fCuts.At(i);
253     if (!s.CompareTo(cut->GetName())) return i;
254   }
255
256   return -1;
257 }
258
259 //_____________________________________________________________________________
260 Bool_t AliRsnCutSet::Passed()
261 {
262 //
263 // Combines the cuts according to expression
264 // and gives a global response to the cut check
265 //
266
267   AliRsnExpression::fgCutSet = this;
268   if (!fExpression) {
269     fExpression = new AliRsnExpression(fCutSchemeIndexed);
270     AliDebug(AliLog::kDebug,"fExpression was created.");
271   }
272
273   return fExpression->Value(*GetCuts());
274 }
275
276 //_____________________________________________________________________________
277 Bool_t AliRsnCutSet::IsValidScheme()
278 {
279 //
280 // Validity check on cut expression specified by user
281 //
282
283   return (!(ShowCutScheme().Contains("Error")));
284 }
285
286 //_____________________________________________________________________________
287 TString AliRsnCutSet::ShowCutScheme()
288 {
289 //
290 // Utility method to check validity of expression
291 //
292   return fExpression->Unparse();
293 }
294
295 //_____________________________________________________________________________
296 Int_t AliRsnCutSet::TestExpression(TString opt)
297 {
298
299 //   AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
300 //   cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
301 //   AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
302 //   cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
303 //   AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
304 //   cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
305 //
306 //   AliRsnCutSet* set  = new AliRsnCutSet ("setOne");
307 //   set->AddCut (cut1);
308 //   set->AddCut (cut2);
309 //   set->AddCut (cut3);
310 //
311 //   set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
312 //
313 //   set->ShowCuts ();
314
315   AliDebug(1, opt.Data());
316   return 0;
317 }
318
319 //_____________________________________________________________________________
320 void AliRsnCutSet::PrintSetInfo()
321 {
322 //
323 // Show data about the cut set
324 //
325
326   Int_t i;
327
328   AliInfo("========== Rsn Cut Set info ==============");
329   AliInfo(Form("Sheme : %s",fCutScheme.Data()));
330   AliInfo(Form("Sheme : %s",fCutSchemeIndexed.Data()));
331   AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
332   AliInfo("====== Cuts ======");
333   AliRsnCut *cut;
334   for (i = 0; i < fCuts.GetEntriesFast(); i++) {
335     cut = (AliRsnCut*) fCuts.At(i);
336     if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
337   }
338   AliInfo("========== END Rsn Cut Mgr info ==============");
339 }
340
341 //_____________________________________________________________________________
342 TString AliRsnCutSet::GetCutSchemeIndexed()
343 {
344 //
345 // Internal method to retrieve the list of cuts with their indexes
346 // for evaluation of cut expression
347 //
348
349   AliDebug(AliLog::kDebug,"<-");
350   Int_t i;
351   TString str(fCutScheme);
352   AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
353   AliRsnCut *cut;
354   for (i = 0; i < fCuts.GetEntriesFast(); i++) {
355     cut = (AliRsnCut*) fCuts.At(i);
356     str.ReplaceAll(cut->GetName(),Form("%d",i));
357   }
358   AliDebug(AliLog::kDebug,"->");
359   return str;
360 }