]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutSet.cxx
b3aaf90c3c39a1dac54f075654da5bb492688487
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutSet.cxx
1 #include "AliLog.h"
2
3 #include "AliRsnCut.h"
4 #include "AliRsnExpression.h"
5
6 #include "AliRsnCutSet.h"
7
8 ClassImp ( AliRsnCutSet )
9
10 AliRsnCutSet::AliRsnCutSet()
11     : TNamed(),fCuts(0),fNumOfCuts ( 0 ),
12     fCutScheme ( "" ),
13     fCutSchemeIndexed ( "" ),
14     fBoolValues ( 0 ),fIsScheme ( kFALSE ),fExpression(0)
15 {
16   fBoolValues = new Bool_t[1];
17 //   fExpression = new AliRsnExpression ( fCutSchemeIndexed );
18   AliRsnExpression::sCutSet = this;
19 }
20
21 AliRsnCutSet::AliRsnCutSet ( TString name )
22     : TNamed ( name,name ),fCuts(0),fNumOfCuts ( 0 ),
23     fCutScheme ( "" ),
24     fCutSchemeIndexed ( "" ),
25     fBoolValues ( 0 ),fIsScheme ( kFALSE ),fExpression(0)
26 {
27   fBoolValues = new Bool_t[1];
28   fExpression = 0;
29   AliRsnExpression::sCutSet = this;
30 }
31
32 AliRsnCutSet::AliRsnCutSet ( const AliRsnCutSet & copy )
33     :    TNamed ( ( TNamed ) copy ),fCuts ( copy.fCuts ),fNumOfCuts ( copy.fNumOfCuts ),
34     fCutScheme ( copy.fCutScheme ),
35     fCutSchemeIndexed ( copy.fCutSchemeIndexed ),
36     fBoolValues(0),
37     fIsScheme ( copy.fIsScheme ),
38     fExpression ( copy.fExpression )
39 {
40   AliRsnExpression::sCutSet = this;
41 }
42
43 AliRsnCutSet::~AliRsnCutSet()
44 {
45   delete fExpression;
46   delete [] fBoolValues;
47 }
48
49 void AliRsnCutSet::AddCut ( AliRsnCut * cut )
50 {
51   AliDebug ( AliLog::kDebug,"<-" );
52   fCuts.Add ( cut );
53   fNumOfCuts++;
54   if ( fBoolValues )
55     delete fBoolValues;
56   fBoolValues = new Bool_t[fNumOfCuts];
57   for ( Int_t i=0;i<fNumOfCuts ; i++ )
58   {
59     fBoolValues[i] = kTRUE;
60   }
61
62   AliDebug ( AliLog::kDebug,Form ( "%d",fCuts.GetEntriesFast() ) );
63   AliDebug ( AliLog::kDebug,"->" );
64 }
65
66 void AliRsnCutSet::ShowCuts ( )
67 {
68 //   AliRsnCut *cut;
69 //   for ( Int_t i=0; i<fCuts.GetEntriesFast() ;i++ )
70 //   {
71 //     cut = ( AliRsnCut* ) fCuts.At ( i );
72 //     AliInfo ( Form ( "%s (\"%s\") [%.2f - %.2f]",cut->GetName(),cut->GetTitle(),cut->GetMin(),cut->GetMax() ) );
73 //   }
74 }
75
76 Bool_t AliRsnCutSet::IsSelected ( AliRsnCut::ECutSetType type, AliRsnDaughter *daughter )
77 {
78   if ( !fNumOfCuts )
79     return kTRUE;
80
81   Bool_t boolReturn = kTRUE;
82   AliRsnCut *cut;
83   for ( Int_t i=0; i<fNumOfCuts ;i++ )
84   {
85     cut = ( AliRsnCut* ) fCuts.At ( i );
86     fBoolValues[i] = cut->IsSelected ( type,daughter );
87 //     AliInfo(Form("%s %d",cut->GetName(),fBoolValues[i]));
88   }
89
90   if ( fIsScheme )
91     boolReturn = Passed();
92
93   return boolReturn;
94 }
95
96 Bool_t AliRsnCutSet::IsSelected ( AliRsnCut::ECutSetType type, AliRsnPairParticle * pair )
97 {
98   if ( !fNumOfCuts )
99     return kTRUE;
100
101   Bool_t boolReturn = kTRUE;
102   AliRsnCut *cut;
103   for ( Int_t i=0; i<fNumOfCuts ;i++ )
104   {
105     cut = ( AliRsnCut* ) fCuts.At ( i );
106     fBoolValues[i] = cut->IsSelected (type,pair );
107 //     AliInfo(Form("%s %d",cut->GetName(),fBoolValues[i]));
108   }
109
110   if ( fIsScheme )
111     boolReturn = Passed();
112
113   return boolReturn;
114 }
115
116
117 void AliRsnCutSet::SetCutScheme ( const TString & theValue )
118 {
119   AliDebug ( AliLog::kDebug,"<-" );
120   fCutScheme = theValue;
121   SetCutSchemeIndexed ( theValue );
122   fIsScheme = kTRUE;
123   AliDebug ( AliLog::kDebug,"->" );
124 }
125
126
127 void AliRsnCutSet::SetCutSchemeIndexed ( TString theValue )
128 {
129   AliDebug ( AliLog::kDebug,"<-" );
130   theValue.Append(" ");
131 //   fCutSchemeIndexed = theValue;
132   fCutSchemeIndexed = GetCutSchemeIndexed();
133   AliDebug ( AliLog::kDebug,"->" );
134 }
135
136 Int_t AliRsnCutSet::GetIndexByCutName ( TString s )
137 {
138   AliRsnCut *cut;
139   for ( Int_t i=0 ;i< fCuts.GetEntriesFast() ;i++ )
140   {
141     cut = ( AliRsnCut* ) fCuts.At ( i );
142 //     if ( !cut->GetName().CompareTo ( s ) )
143     if ( !s.CompareTo ( cut->GetName() ) )
144     {
145       return i;
146     }
147   }
148
149   return -1;
150 }
151
152 Bool_t AliRsnCutSet::Passed()
153 {
154   AliRsnExpression::sCutSet = this;
155   if ( !fExpression )
156   {
157     fExpression = new AliRsnExpression ( fCutSchemeIndexed );
158     AliDebug ( AliLog::kDebug,"fExpression was created." );
159   }
160   return fExpression->Value ( *GetCuts() );
161 }
162
163 Bool_t AliRsnCutSet::IsValidScheme()
164 {
165   return ( ! ( ShowCutScheme().Contains ( "Error" ) ) );
166 }
167
168 TString AliRsnCutSet::ShowCutScheme()
169 {
170   return fExpression->Unparse();
171 }
172
173 Int_t AliRsnCutSet::TestExpression ( TString opt )
174 {
175 //   AliRsnCut *cut1 = new AliRsnCut ( "aaa","aaa" );
176 //   cut1->SetCutValues ( AliRsnCut::kEsdPt,0.0,1.0 );
177 //   AliRsnCut *cut2 = new AliRsnCut ( "bbb","bbb" );
178 //   cut2->SetCutValues ( AliRsnCut::kEsdPt,1.,2.0 );
179 //   AliRsnCut *cut3 = new AliRsnCut ( "ccc","ccc" );
180 //   cut3->SetCutValues ( AliRsnCut::kEsdPt,2.0,3.0 );
181 //
182 //   AliRsnCutSet* set  = new AliRsnCutSet ( "setOne" );
183 //   set->AddCut ( cut1 );
184 //   set->AddCut ( cut2 );
185 //   set->AddCut ( cut3 );
186 //
187 //   set->SetCutScheme ( "(aaa&!(ccc))&(bbb&!(ccc))" );
188 //
189 //   set->ShowCuts ();
190     AliDebug(1, opt.Data());
191
192   return 0;
193 }
194
195 void AliRsnCutSet::PrintSetInfo()
196 {
197
198
199   AliInfo ( "========== Rsn Cut Set info ==============" );
200   AliInfo ( Form ( "Sheme : %s",fCutScheme.Data() ) );
201   AliInfo ( Form ( "Sheme : %s",fCutSchemeIndexed.Data() ) );
202   AliInfo ( Form ( "Num of Cuts: %d", fCuts.GetEntriesFast() ) );
203   AliInfo ( "====== Cuts ======" );
204   AliRsnCut *cut;
205   for ( Int_t i=0 ;i< fCuts.GetEntriesFast() ;i++ )
206   {
207     cut = ( AliRsnCut* ) fCuts.At ( i );
208     if ( cut )
209       AliInfo ( Form ( "%d %d",i,fBoolValues[i] ) );
210
211   }
212   AliInfo ( "========== END Rsn Cut Mgr info ==============" );
213
214 }
215
216 TString AliRsnCutSet::GetCutSchemeIndexed()
217 {
218   AliDebug ( AliLog::kDebug,"<-" );
219   TString str ( fCutScheme );
220   AliDebug ( AliLog::kDebug,Form ( "Num of cuts %d",fCuts.GetEntriesFast() ) );
221   AliRsnCut *cut;
222   for ( Int_t i=0; i<fCuts.GetEntriesFast();i++ )
223   {
224     cut = ( AliRsnCut* ) fCuts.At ( i );
225     str.ReplaceAll ( cut->GetName(),Form ( "%d",i ) );
226   }
227   AliDebug ( AliLog::kDebug,"->" );
228   return str;
229 }
230