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