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