13 #include "TObjArray.h"
16 #include "TLeafObject.h"
25 const Char_t *name,
const Char_t *formula, TTree *tree) :
26 TTreeFormula(name, formula, tree) {
33 static Char_t lname[64];
37 for (i = 0; i < GetNcodes(); i++) {
43 if (fMultiplicity != 1)
44 fMultiplicity = pCutG->
GetFormulaX()->GetMultiplicity();
45 if (fMultiplicity != 1)
46 fMultiplicity = pCutG->
GetFormulaY()->GetMultiplicity();
53 name = leaf->GetBranch()->GetName();
54 strcpy(lname, name.Data());
57 Int_t len = strlen(lname);
58 for(Int_t j = len; j--;) {
59 if (lname[j] ==
'.') {
76 if ((i < 0) || (i > fNcodes))
return 0;
79 return (
HCutG*)fMethods.At(i);
86 Char_t branchname[128];
88 TObjArray *lleaves = fTree->GetListOfLeaves();
89 Int_t nleaves = lleaves->GetEntriesFast();
91 if ((fCodes[indcode] < 0) || (fCodes[indcode] >= nleaves))
return -1;
94 for (i=fCodes[indcode]; i--;) {
95 TLeaf *leaf = (TLeaf*)lleaves->UncheckedAt(i);
96 if (!strcmp(lname,leaf->GetBranch()->GetName() ) ) {
103 for (i=fCodes[indcode]; i--;) {
104 TLeaf *leaf = (TLeaf*)lleaves->UncheckedAt(i);
105 sprintf(branchname,
"%s.%s",leaf->GetBranch()->GetName(),leaf->GetName());
106 if (!strcmp(lname,branchname)) {
112 for (i=fCodes[indcode]; i--;) {
113 TLeaf *leaf = (TLeaf*)lleaves->UncheckedAt(i);
114 if (!strcmp(lname,leaf->GetBranch()->GetName())) {
129 Int_t i,pos,pos2,int1,int2;
136 for(i = 0; i < fNcodes; i++)
145 TLeaf *leaf = GetLeaf(0);
150 return leaf->GetValue(0);
152 leaf->GetBranch()->GetEntry(fTree->GetReadEntry());
153 if (!(leaf->IsA() == TLeafObject::Class()))
return leaf->GetValue(fIndex[0]);
154 return GetValueLeafObject(fIndex[0],(TLeafObject *)leaf);
158 for(i=0;i<fNval;i++) {
163 TLeaf *leaf = GetLeaf(i);
168 param[i] = leaf->GetValue(0);
170 leaf->GetBranch()->GetEntry(fTree->GetReadEntry());
171 if (!(leaf->IsA() == TLeafObject::Class())) param[i] = leaf->GetValue(fIndex[i]);
172 else param[i] = GetValueLeafObject(fIndex[i],(TLeafObject *)leaf);
179 for (i=0; i<fNoper; i++) {
180 Int_t action = fOper[i];
182 if (action >= 105000) {
187 TLeafC *leafc = (TLeafC*)GetLeaf(action-105000);
188 leafc->GetBranch()->GetEntry(fTree->GetReadEntry());
189 pos2++; tab2[pos2-1] = leafc->GetValueString();
194 if (action >= 100000) {
195 pos++; tab[pos-1] = param[action-100000];
199 if (action == 80000) {
200 pos2++; tab2[pos2-1] = (Char_t*)fExpr[i].Data();
204 if (action >= 50000) {
205 pos++; tab[pos-1] = fConst[action-50000];
210 sscanf((
const Char_t*)fExpr[i],
"%g",&aresult);
211 tab[pos-1] = aresult;
213 }
else if (action < 100) {
215 case 1 : pos--; tab[pos-1] += tab[pos];
break;
216 case 2 : pos--; tab[pos-1] -= tab[pos];
break;
217 case 3 : pos--; tab[pos-1] *= tab[pos];
break;
218 case 4 :
if (tab[pos-1] == 0) {tab[pos-1] = 0;}
219 else { pos--; tab[pos-1] /= tab[pos]; }
221 case 5 : {pos--; int1=Int_t(tab[pos-1]); int2=Int_t(tab[pos]); tab[pos-1] = Double_t(int1%int2);
break;}
222 case 10 : tab[pos-1] = TMath::Cos(tab[pos-1]);
break;
223 case 11 : tab[pos-1] = TMath::Sin(tab[pos-1]);
break;
224 case 12 :
if (TMath::Cos(tab[pos-1]) == 0) {tab[pos-1] = 0;}
225 else tab[pos-1] = TMath::Tan(tab[pos-1]);
227 case 13 :
if (TMath::Abs(tab[pos-1]) > 1) {tab[pos-1] = 0;}
228 else tab[pos-1] = TMath::ACos(tab[pos-1]);
230 case 14 :
if (TMath::Abs(tab[pos-1]) > 1) {tab[pos-1] = 0;}
231 else tab[pos-1] = TMath::ASin(tab[pos-1]);
233 case 15 : tab[pos-1] = TMath::ATan(tab[pos-1]);
break;
234 case 70 : tab[pos-1] = TMath::CosH(tab[pos-1]);
break;
235 case 71 : tab[pos-1] = TMath::SinH(tab[pos-1]);
break;
236 case 72 :
if (TMath::CosH(tab[pos-1]) == 0) {tab[pos-1] = 0;}
237 else tab[pos-1] = TMath::TanH(tab[pos-1]);
239 case 73 :
if (tab[pos-1] < 1) {tab[pos-1] = 0;}
240 else tab[pos-1] = TMath::ACosH(tab[pos-1]);
242 case 74 : tab[pos-1] = TMath::ASinH(tab[pos-1]);
break;
243 case 75 :
if (TMath::Abs(tab[pos-1]) > 1) {tab[pos-1] = 0;}
244 else tab[pos-1] = TMath::ATanH(tab[pos-1]);
break;
245 case 16 : pos--; tab[pos-1] = TMath::ATan2(tab[pos-1],tab[pos]);
break;
246 case 20 : pos--; tab[pos-1] = TMath::Power(tab[pos-1],tab[pos]);
break;
247 case 21 : tab[pos-1] = tab[pos-1]*tab[pos-1];
break;
248 case 22 : tab[pos-1] = TMath::Sqrt(TMath::Abs(tab[pos-1]));
break;
249 case 23 : pos2 -= 2; pos++;
if (strstr(tab2[pos2],tab2[pos2+1])) tab[pos-1]=1;
250 else tab[pos-1]=0;
break;
251 case 30 :
if (tab[pos-1] > 0) tab[pos-1] = TMath::Log(tab[pos-1]);
252 else {tab[pos-1] = 0;}
254 case 31 : dexp = tab[pos-1];
255 if (dexp < -70) {tab[pos-1] = 0;
break;}
256 if (dexp > 70) {tab[pos-1] = TMath::Exp(70);
break;}
257 tab[pos-1] = TMath::Exp(dexp);
break;
258 case 32 :
if (tab[pos-1] > 0) tab[pos-1] = TMath::Log10(tab[pos-1]);
259 else {tab[pos-1] = 0;}
261 case 40 : pos++; tab[pos-1] = TMath::ACos(-1);
break;
262 case 41 : tab[pos-1] = TMath::Abs(tab[pos-1]);
break;
263 case 42 :
if (tab[pos-1] < 0) tab[pos-1] = -1;
else tab[pos-1] = 1;
break;
265 case 50 : tab[pos-1] = 0.5;
break;
266 case 60 : pos--;
if (tab[pos-1]!=0 && tab[pos]!=0) tab[pos-1]=1;
267 else tab[pos-1]=0;
break;
268 case 61 : pos--;
if (tab[pos-1]!=0 || tab[pos]!=0) tab[pos-1]=1;
269 else tab[pos-1]=0;
break;
270 case 62 : pos--;
if (tab[pos-1] == tab[pos]) tab[pos-1]=1;
271 else tab[pos-1]=0;
break;
272 case 63 : pos--;
if (tab[pos-1] != tab[pos]) tab[pos-1]=1;
273 else tab[pos-1]=0;
break;
274 case 64 : pos--;
if (tab[pos-1] < tab[pos]) tab[pos-1]=1;
275 else tab[pos-1]=0;
break;
276 case 65 : pos--;
if (tab[pos-1] > tab[pos]) tab[pos-1]=1;
277 else tab[pos-1]=0;
break;
278 case 66 : pos--;
if (tab[pos-1]<=tab[pos]) tab[pos-1]=1;
279 else tab[pos-1]=0;
break;
280 case 67 : pos--;
if (tab[pos-1]>=tab[pos]) tab[pos-1]=1;
281 else tab[pos-1]=0;
break;
282 case 68 :
if (tab[pos-1]!=0) tab[pos-1] = 0;
else tab[pos-1] = 1;
break;
283 case 76 : pos2 -= 2; pos++;
if (!strcmp(tab2[pos2+1],tab2[pos2])) tab[pos-1]=1;
284 else tab[pos-1]=0;
break;
285 case 77 : pos2 -= 2; pos++;
if (strcmp(tab2[pos2+1],tab2[pos2])) tab[pos-1]=1;
286 else tab[pos-1]=0;
break;
287 case 78 : pos--; tab[pos-1]= ((Int_t) tab[pos-1]) & ((Int_t) tab[pos]);
break;
288 case 79 : pos--; tab[pos-1]= ((Int_t) tab[pos-1]) | ((Int_t) tab[pos]);
break;
292 Double_t result = tab[0];
virtual void GroupLeaves()
TTreeFormula * GetFormulaX()
Short_t getIndexByCode(Short_t code)
TTreeFormula * GetFormulaY()
virtual Double_t EvalInstance(HCombinedIndex *pInstancesIndex)