]> git.uio.no Git - u/mrichter/AliRoot.git/blame - 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
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,"<-");
169 fCutScheme = theValue;
170 SetCutSchemeIndexed(theValue);
171 fIsScheme = kTRUE;
172 AliDebug(AliLog::kDebug,"->");
e2bafbbc 173}
06351446 174
e2bafbbc 175//_____________________________________________________________________________
aec0ec32 176void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
06351446 177{
e2bafbbc 178//
179// Internal method which indexes all cuts to organize their combo
180//
181
aec0ec32 182 AliDebug(AliLog::kDebug,"<-");
183 theValue.Append(" ");
184 // fCutSchemeIndexed = theValue;
185 fCutSchemeIndexed = GetCutSchemeIndexed();
186 AliDebug(AliLog::kDebug,"->");
06351446 187}
188
e2bafbbc 189//_____________________________________________________________________________
aec0ec32 190Int_t AliRsnCutSet::GetIndexByCutName(TString s)
06351446 191{
e2bafbbc 192//
193// Retrieve the cut index from its name
194//
06351446 195
aec0ec32 196 Int_t i;
197 AliRsnCut *cut;
198
4fbb2459 199 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
aec0ec32 200 cut = (AliRsnCut*) fCuts.At(i);
201 if (!s.CompareTo(cut->GetName())) return i;
202 }
203
204 return -1;
06351446 205}
206
e2bafbbc 207//_____________________________________________________________________________
06351446 208Bool_t AliRsnCutSet::Passed()
209{
e2bafbbc 210//
211// Combines the cuts according to expression
212// and gives a global response to the cut check
213//
214
4fbb2459 215 AliRsnExpression::fgCutSet = this;
216 if (!fExpression) {
aec0ec32 217 fExpression = new AliRsnExpression(fCutSchemeIndexed);
218 AliDebug(AliLog::kDebug,"fExpression was created.");
219 }
220
221 return fExpression->Value(*GetCuts());
06351446 222}
223
e2bafbbc 224//_____________________________________________________________________________
06351446 225Bool_t AliRsnCutSet::IsValidScheme()
226{
e2bafbbc 227//
228// Validity check on cut expression specified by user
229//
230
aec0ec32 231 return (!(ShowCutScheme().Contains("Error")));
06351446 232}
233
e2bafbbc 234//_____________________________________________________________________________
06351446 235TString AliRsnCutSet::ShowCutScheme()
236{
e2bafbbc 237//
238// Utility method to check validity of expression
239//
aec0ec32 240 return fExpression->Unparse();
06351446 241}
242
e2bafbbc 243//_____________________________________________________________________________
aec0ec32 244Int_t AliRsnCutSet::TestExpression(TString opt)
06351446 245{
e2bafbbc 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);
06351446 253//
e2bafbbc 254// AliRsnCutSet* set = new AliRsnCutSet ("setOne");
255// set->AddCut (cut1);
256// set->AddCut (cut2);
257// set->AddCut (cut3);
06351446 258//
e2bafbbc 259// set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
06351446 260//
261// set->ShowCuts ();
262
aec0ec32 263 AliDebug(1, opt.Data());
264 return 0;
06351446 265}
266
e2bafbbc 267//_____________________________________________________________________________
06351446 268void AliRsnCutSet::PrintSetInfo()
269{
e2bafbbc 270//
271// Show data about the cut set
272//
06351446 273
aec0ec32 274 Int_t i;
275
276 AliInfo("========== Rsn Cut Set info ==============");
413bbf44 277 AliInfo(Form("Scheme : %s",fCutScheme.Data()));
278 AliInfo(Form("Scheme : %s",fCutSchemeIndexed.Data()));
aec0ec32 279 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
280 AliInfo("====== Cuts ======");
281 AliRsnCut *cut;
4fbb2459 282 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
aec0ec32 283 cut = (AliRsnCut*) fCuts.At(i);
284 if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
285 }
286 AliInfo("========== END Rsn Cut Mgr info ==============");
06351446 287}
288
e2bafbbc 289//_____________________________________________________________________________
06351446 290TString AliRsnCutSet::GetCutSchemeIndexed()
291{
e2bafbbc 292//
293// Internal method to retrieve the list of cuts with their indexes
294// for evaluation of cut expression
295//
06351446 296
aec0ec32 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;
4fbb2459 302 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
aec0ec32 303 cut = (AliRsnCut*) fCuts.At(i);
304 str.ReplaceAll(cut->GetName(),Form("%d",i));
305 }
306 AliDebug(AliLog::kDebug,"->");
307 return str;
e2bafbbc 308}
413bbf44 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}