]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutSet.cxx
New classes required for revision of package
[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::sCutSet = 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::sCutSet = 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::sCutSet = 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   {
106     fBoolValues[i] = kTRUE;
107   }
108
109   AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
110   AliDebug(AliLog::kDebug,"->");
111 }
112
113 //_____________________________________________________________________________
114 void AliRsnCutSet::ShowCuts()
115 {
116 //
117 // Prints all cuts
118 //
119 //   AliRsnCut *cut;
120 //   for (Int_t i=0; i<fCuts.GetEntriesFast() ;i++)
121 //   {
122 //     cut = (AliRsnCut*) fCuts.At (i);
123 //     AliInfo (Form ("%s (\"%s\") [%.2f - %.2f]",cut->GetName(),cut->GetTitle(),cut->GetMin(),cut->GetMax()));
124 //   }
125 }
126
127 //_____________________________________________________________________________
128 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnDaughter *daughter)
129 {
130 //
131 // Checks an object according to the cut expression defined here.
132 //
133
134   Int_t i;
135
136   if (!fNumOfCuts) return kTRUE;
137
138   Bool_t boolReturn = kTRUE;
139   AliRsnCut *cut;
140   for (i = 0; i < fNumOfCuts; i++)
141   {
142     cut = (AliRsnCut*)fCuts.At(i);
143     fBoolValues[i] = cut->IsSelected(type,daughter);
144   }
145
146   if (fIsScheme) boolReturn = Passed();
147   return boolReturn;
148 }
149
150 //_____________________________________________________________________________
151 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnPairParticle * pair)
152 {
153 //
154 // Checks an object according to the cut expression defined here.
155 //
156
157   Int_t i;
158
159   if (!fNumOfCuts) return kTRUE;
160
161   Bool_t boolReturn = kTRUE;
162   AliRsnCut *cut;
163   for (i = 0; i < fNumOfCuts; i++)
164   {
165     cut = (AliRsnCut*) fCuts.At(i);
166     fBoolValues[i] = cut->IsSelected(type,pair);
167   }
168
169   if (fIsScheme) boolReturn = Passed();
170   return boolReturn;
171 }
172
173 //_____________________________________________________________________________
174 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * event)
175 {
176 //
177 // Checks an object according to the cut expression defined here.
178 //
179
180   Int_t i;
181   if (!fNumOfCuts) return kTRUE;
182
183   Bool_t boolReturn = kTRUE;
184   AliRsnCut *cut;
185   for (i = 0; i < fNumOfCuts; i++)
186   {
187     cut = (AliRsnCut*) fCuts.At(i);
188     fBoolValues[i] = cut->IsSelected(type,event);
189   }
190
191   if (fIsScheme) boolReturn = Passed();
192   return boolReturn;
193 }
194
195 //_____________________________________________________________________________
196 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * ev1, AliRsnEvent *ev2)
197 {
198 //
199 // Checks an object according to the cut expression defined here.
200 //
201
202   Int_t i;
203   if (!fNumOfCuts) return kTRUE;
204
205   Bool_t boolReturn = kTRUE;
206   AliRsnCut *cut;
207   for (i = 0; i < fNumOfCuts; i++)
208   {
209     cut = (AliRsnCut*) fCuts.At(i);
210     fBoolValues[i] = cut->IsSelected(type,ev1,ev2);
211   }
212
213   if (fIsScheme) boolReturn = Passed();
214   return boolReturn;
215 }
216
217 //_____________________________________________________________________________
218 void AliRsnCutSet::SetCutScheme(const TString & theValue)
219 {
220 //
221 // Define the combination of cuts with logical operators
222 // and using the names given to all defined cuts.
223 //
224
225   AliDebug(AliLog::kDebug,"<-");
226   fCutScheme = theValue;
227   SetCutSchemeIndexed(theValue);
228   fIsScheme = kTRUE;
229   AliDebug(AliLog::kDebug,"->");
230 }
231
232 //_____________________________________________________________________________
233 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
234 {
235 //
236 // Internal method which indexes all cuts to organize their combo
237 //
238
239   AliDebug(AliLog::kDebug,"<-");
240   theValue.Append(" ");
241   // fCutSchemeIndexed = theValue;
242   fCutSchemeIndexed = GetCutSchemeIndexed();
243   AliDebug(AliLog::kDebug,"->");
244 }
245
246 //_____________________________________________________________________________
247 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
248 {
249 //
250 // Retrieve the cut index from its name
251 //
252
253   Int_t i;
254   AliRsnCut *cut;
255
256   for (i = 0; i < fCuts.GetEntriesFast(); i++)
257   {
258     cut = (AliRsnCut*) fCuts.At(i);
259     if (!s.CompareTo(cut->GetName())) return i;
260   }
261
262   return -1;
263 }
264
265 //_____________________________________________________________________________
266 Bool_t AliRsnCutSet::Passed()
267 {
268 //
269 // Combines the cuts according to expression
270 // and gives a global response to the cut check
271 //
272
273   AliRsnExpression::sCutSet = this;
274   if (!fExpression)
275   {
276     fExpression = new AliRsnExpression(fCutSchemeIndexed);
277     AliDebug(AliLog::kDebug,"fExpression was created.");
278   }
279
280   return fExpression->Value(*GetCuts());
281 }
282
283 //_____________________________________________________________________________
284 Bool_t AliRsnCutSet::IsValidScheme()
285 {
286 //
287 // Validity check on cut expression specified by user
288 //
289
290   return (!(ShowCutScheme().Contains("Error")));
291 }
292
293 //_____________________________________________________________________________
294 TString AliRsnCutSet::ShowCutScheme()
295 {
296 //
297 // Utility method to check validity of expression
298 //
299   return fExpression->Unparse();
300 }
301
302 //_____________________________________________________________________________
303 Int_t AliRsnCutSet::TestExpression(TString opt)
304 {
305
306 //   AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
307 //   cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
308 //   AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
309 //   cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
310 //   AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
311 //   cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
312 //
313 //   AliRsnCutSet* set  = new AliRsnCutSet ("setOne");
314 //   set->AddCut (cut1);
315 //   set->AddCut (cut2);
316 //   set->AddCut (cut3);
317 //
318 //   set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
319 //
320 //   set->ShowCuts ();
321
322   AliDebug(1, opt.Data());
323   return 0;
324 }
325
326 //_____________________________________________________________________________
327 void AliRsnCutSet::PrintSetInfo()
328 {
329 //
330 // Show data about the cut set
331 //
332
333   Int_t i;
334
335   AliInfo("========== Rsn Cut Set info ==============");
336   AliInfo(Form("Sheme : %s",fCutScheme.Data()));
337   AliInfo(Form("Sheme : %s",fCutSchemeIndexed.Data()));
338   AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
339   AliInfo("====== Cuts ======");
340   AliRsnCut *cut;
341   for (i = 0; i < fCuts.GetEntriesFast(); i++)
342   {
343     cut = (AliRsnCut*) fCuts.At(i);
344     if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
345   }
346   AliInfo("========== END Rsn Cut Mgr info ==============");
347 }
348
349 //_____________________________________________________________________________
350 TString AliRsnCutSet::GetCutSchemeIndexed()
351 {
352 //
353 // Internal method to retrieve the list of cuts with their indexes
354 // for evaluation of cut expression
355 //
356
357   AliDebug(AliLog::kDebug,"<-");
358   Int_t i;
359   TString str(fCutScheme);
360   AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
361   AliRsnCut *cut;
362   for (i = 0; i < fCuts.GetEntriesFast(); i++)
363   {
364     cut = (AliRsnCut*) fCuts.At(i);
365     str.ReplaceAll(cut->GetName(),Form("%d",i));
366   }
367   AliDebug(AliLog::kDebug,"->");
368   return str;
369 }