4 |
ClassImp(CaloLong); |
ClassImp(CaloLong); |
5 |
ClassImp(Calo2D); |
ClassImp(Calo2D); |
6 |
|
|
7 |
|
|
8 |
|
int isempty(struct stack *s){ |
9 |
|
return (s->top == EMPTY) ? 1 : 0; |
10 |
|
} |
11 |
|
|
12 |
|
void emptystack(struct stack* s){ |
13 |
|
s->top=EMPTY; |
14 |
|
strcpy(s->data," "); |
15 |
|
} |
16 |
|
|
17 |
|
void push(struct stack* s,int item){ |
18 |
|
if(s->top == (MAX-1)){ |
19 |
|
printf("\n ERROR! STACK FULL (too many digits in SetLower/UpperLimit)\n"); |
20 |
|
} else { |
21 |
|
s->data[++s->top]=(char)item; |
22 |
|
}; |
23 |
|
} |
24 |
|
|
25 |
|
char pop(struct stack* s){ |
26 |
|
char ret=(char)EMPTY; |
27 |
|
if(!isempty(s)){ |
28 |
|
ret= s->data[s->top--]; |
29 |
|
}; |
30 |
|
return ret; |
31 |
|
} |
32 |
|
|
33 |
|
|
34 |
|
int ipop(struct stack* s){ |
35 |
|
int ret=EMPTY; |
36 |
|
if(s->top == EMPTY) |
37 |
|
printf("\n ERROR! STACK EMPTY (too few digits in SetLower/UpperLimit)\n"); |
38 |
|
else { |
39 |
|
ret= s->data[s->top--]; |
40 |
|
}; |
41 |
|
return ret; |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
|
void display(struct stack s){ |
46 |
|
int ss = s.top; |
47 |
|
while(s.top != EMPTY){ |
48 |
|
printf("\n%d",s.data[s.top--]); |
49 |
|
}; |
50 |
|
printf(" s.top %i \n",ss); |
51 |
|
} |
52 |
|
|
53 |
|
int isoperator(char e){ |
54 |
|
if(e == '+' || e == '-' || e == '*' || e == '/' || e == '%') |
55 |
|
return 1; |
56 |
|
else |
57 |
|
return 0; |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
int priority(char e){ |
62 |
|
int pri = 0; |
63 |
|
if(e == '*' || e == '/' || e =='%') |
64 |
|
pri = 2; |
65 |
|
else { |
66 |
|
if(e == '+' || e == '-') pri = 1; |
67 |
|
}; |
68 |
|
return pri; |
69 |
|
} |
70 |
|
|
71 |
|
void infix2postfix(char* infix, char * postfix, int insertspace){ |
72 |
|
char *i,*p; |
73 |
|
struct stack X; |
74 |
|
char n1; |
75 |
|
emptystack(&X); |
76 |
|
i = &infix[0]; |
77 |
|
p = &postfix[0]; |
78 |
|
while(*i){ |
79 |
|
while(*i == ' ' || *i == '\t' ){ |
80 |
|
i++; |
81 |
|
}; |
82 |
|
TString c=i; |
83 |
|
if( isdigit(*i) || isalpha(*i) || c.BeginsWith(".") ){ |
84 |
|
while( isdigit(*i) || isalpha(*i) || c.BeginsWith(".") ){ |
85 |
|
*p = *i; |
86 |
|
p++; |
87 |
|
i++; |
88 |
|
c=i; |
89 |
|
}; |
90 |
|
/*SPACE CODE*/ |
91 |
|
if(insertspace){ |
92 |
|
*p = ' '; |
93 |
|
p++; |
94 |
|
}; |
95 |
|
/*END SPACE CODE*/ |
96 |
|
}; |
97 |
|
if( *i == '(' ){ |
98 |
|
push(&X,*i); |
99 |
|
i++; |
100 |
|
}; |
101 |
|
if( *i == ')'){ |
102 |
|
n1 = pop(&X); |
103 |
|
while( n1 != '(' ){ |
104 |
|
*p = n1; |
105 |
|
p++; |
106 |
|
/*SPACE CODE*/ |
107 |
|
if(insertspace){ |
108 |
|
*p = ' '; |
109 |
|
p++; |
110 |
|
}; |
111 |
|
/*END SPACE CODE*/ |
112 |
|
n1 = pop(&X); |
113 |
|
}; |
114 |
|
i++; |
115 |
|
}; |
116 |
|
if( isoperator(*i) ){ |
117 |
|
if(isempty(&X)){ |
118 |
|
push(&X,*i); |
119 |
|
} else { |
120 |
|
n1 = pop(&X); |
121 |
|
while( priority(n1) >= priority(*i) ){ |
122 |
|
*p = n1; |
123 |
|
p++; |
124 |
|
/*SPACE CODE*/ |
125 |
|
if(insertspace){ |
126 |
|
*p = ' '; |
127 |
|
p++; |
128 |
|
}; |
129 |
|
/*END SPACE CODE*/ |
130 |
|
n1 = pop(&X); |
131 |
|
}; |
132 |
|
push(&X,n1); |
133 |
|
push(&X,*i); |
134 |
|
}; |
135 |
|
i++; |
136 |
|
}; |
137 |
|
}; |
138 |
|
while(!isempty(&X)){ |
139 |
|
n1 = pop(&X); |
140 |
|
*p = n1; |
141 |
|
p++; |
142 |
|
/*SPACE CODE*/ |
143 |
|
if(insertspace){ |
144 |
|
*p = ' '; |
145 |
|
p++; |
146 |
|
}; |
147 |
|
/*END SPACE CODE*/ |
148 |
|
}; |
149 |
|
*p = '\0'; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
Float_t evaluate(char *postfix){ |
154 |
|
// |
155 |
|
Float_t op1 = 0.; |
156 |
|
Float_t op2 = 0.; |
157 |
|
Float_t result = 0.; |
158 |
|
// |
159 |
|
TString e = postfix; |
160 |
|
Float_t st[50]; |
161 |
|
memset(st,0,50*sizeof(Float_t)); |
162 |
|
TObjArray *ae = e.Tokenize(" "); |
163 |
|
Int_t o = 0; |
164 |
|
Int_t a = 0; |
165 |
|
Int_t ap = 0; |
166 |
|
// |
167 |
|
while ( o < ae->GetEntries() ){ |
168 |
|
if ( ((TString)(((TObjString*)ae->At(o))->GetString())).IsFloat() ){ |
169 |
|
st[a] = (Float_t)((TString)(((TObjString*)ae->At(o))->GetString())).Atof();; |
170 |
|
a++; |
171 |
|
} else { |
172 |
|
ap = a-1; |
173 |
|
op1 = st[ap--]; |
174 |
|
op2 = st[ap]; |
175 |
|
const char *p=((TString)(((TObjString*)ae->At(o))->GetString())).Data(); |
176 |
|
switch(*p){ |
177 |
|
case '+': |
178 |
|
result = op2 + op1; |
179 |
|
break; |
180 |
|
case '-': |
181 |
|
result = op2 - op1; |
182 |
|
break; |
183 |
|
case '/': |
184 |
|
result = op2 / op1; |
185 |
|
break; |
186 |
|
case '*': |
187 |
|
result = op2 * op1; |
188 |
|
break; |
189 |
|
case '%': |
190 |
|
result = (Int_t)round(op2) % (Int_t)round(op1); |
191 |
|
break; |
192 |
|
default: |
193 |
|
printf("\nInvalid Operator: %s \n",((TString)(((TObjString*)ae->At(o))->GetString())).Data()); |
194 |
|
return 0; |
195 |
|
}; |
196 |
|
st[ap] = result; |
197 |
|
a = ap+1; |
198 |
|
// |
199 |
|
}; |
200 |
|
o++; |
201 |
|
}; |
202 |
|
return result; |
203 |
|
// |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
209 |
/** |
/** |
210 |
* 1-dimension function describing lateral distribution of the |
* 1-dimension function describing lateral distribution of the |
667 |
maskYE = false; |
maskYE = false; |
668 |
maskYO = false; |
maskYO = false; |
669 |
// |
// |
670 |
|
lmax = 0.; |
671 |
|
umax = 100.; |
672 |
|
slmax = ""; |
673 |
|
sumax = ""; |
674 |
|
// |
675 |
}; |
}; |
676 |
|
|
677 |
void CaloLong::MaskSection(TString sec){ |
void CaloLong::MaskSection(TString sec){ |
701 |
chi2 = 0.; |
chi2 = 0.; |
702 |
ndf = 0.; |
ndf = 0.; |
703 |
E0 = 0.; |
E0 = 0.; |
704 |
|
defE0 = 0.; |
705 |
a = 0.; |
a = 0.; |
706 |
b = 0.; |
b = 0.; |
707 |
errE0 = 0.; |
errE0 = 0.; |
727 |
printf(" nchi2 :.. %f\n",chi2/ndf); |
printf(" nchi2 :.. %f\n",chi2/ndf); |
728 |
printf(" E0 :.. %f\n",E0); |
printf(" E0 :.. %f\n",E0); |
729 |
printf(" E0/260. :.. %f\n",E0/260.); |
printf(" E0/260. :.. %f\n",E0/260.); |
730 |
|
printf(" defE0 :.. %f\n",defE0); |
731 |
|
printf(" lower :.. %f\n",lmax); |
732 |
|
printf(" upper :.. %f\n",umax); |
733 |
|
printf(" s lower :.. %s\n",slmax.Data()); |
734 |
|
printf(" s upper :.. %s\n",sumax.Data()); |
735 |
printf(" a :.. %f\n",a); |
printf(" a :.. %f\n",a); |
736 |
printf(" b :.. %f\n",b); |
printf(" b :.. %f\n",b); |
737 |
printf(" errE0 :.. %f\n",errE0); |
printf(" errE0 :.. %f\n",errE0); |
994 |
this->Fit(false); |
this->Fit(false); |
995 |
}; |
}; |
996 |
|
|
997 |
|
Float_t CaloLong::Evaluate(TString s, Float_t tmax){ |
998 |
|
/* SAMPLE OUTPUT: |
999 |
|
Enter Infix Expression : A + B + C / (E - F) |
1000 |
|
Postfix Expression is : A B + C E F - / + |
1001 |
|
*/ |
1002 |
|
if ( !s.Contains("t") ){ |
1003 |
|
printf(" ERROR, the input formula must contain \"t\"\n"); |
1004 |
|
return 0.; |
1005 |
|
}; |
1006 |
|
if ( tmax != tmax ){ |
1007 |
|
printf(" ERROR, tmax is nan! \n"); |
1008 |
|
return 0.; |
1009 |
|
}; |
1010 |
|
TString g=Form("%f",tmax); |
1011 |
|
TString *ts= new TString(""); |
1012 |
|
ts->Prepend(s.Data()); |
1013 |
|
ts->ReplaceAll("t",1,g.Data(),g.Capacity()); |
1014 |
|
ts->Prepend("("); |
1015 |
|
ts->Append(")"); |
1016 |
|
if ( debug ) printf(" ts %s tssize %i capac %i s %s g %s \n",ts->Data(),ts->Sizeof(),ts->Capacity(),s.Data(),g.Data()); |
1017 |
|
char in[50],post[50]; |
1018 |
|
strcpy(&in[0]," "); |
1019 |
|
strcpy(&in[0],ts->Data()); |
1020 |
|
strcpy(&post[0]," "); |
1021 |
|
if ( debug ) printf("Infix Expression is : ##%s##\n",&in[0]); |
1022 |
|
infix2postfix(&in[0],&post[0],1); |
1023 |
|
if ( debug ) printf("Postfix Expression is : ##%s##\n",&post[0]); |
1024 |
|
/* SAMPLE OUTPUT: |
1025 |
|
Enter Postfix Expression : 3 5 + 2 / |
1026 |
|
3 5 + 2 / EQUALS 4 |
1027 |
|
*/ |
1028 |
|
Float_t res = evaluate(&post[0]); |
1029 |
|
if ( debug ) printf("%s EQUALS %f\n",post,res); |
1030 |
|
return res; |
1031 |
|
} |
1032 |
|
|
1033 |
void CaloLong::Fit(Bool_t draw){ |
void CaloLong::Fit(Bool_t draw){ |
1034 |
// |
// |
1035 |
Process(); |
Process(); |
1201 |
if ( fitresult != 0 ){ |
if ( fitresult != 0 ){ |
1202 |
if ( debug ) printf(" The fit failed, no integrals calculation and asymm is set to -1. \n"); |
if ( debug ) printf(" The fit failed, no integrals calculation and asymm is set to -1. \n"); |
1203 |
asymm = -1.; |
asymm = -1.; |
1204 |
|
defE0 = -1.; |
1205 |
} else { |
} else { |
1206 |
|
if ( slmax.MaybeRegexp() ) lmax = this->Evaluate(slmax,tmax); |
1207 |
|
if ( sumax.MaybeRegexp() ) umax = this->Evaluate(sumax,tmax); |
1208 |
Int_t npp = 1000; |
Int_t npp = 1000; |
1209 |
|
double *xpp=new double[npp]; |
1210 |
|
double *wpp=new double[npp]; |
1211 |
|
lfit->CalcGaussLegendreSamplingPoints(npp,xpp,wpp,1e-12); |
1212 |
|
defE0 = lfit->IntegralFast(npp,xpp,wpp,lmax,umax); |
1213 |
|
// |
1214 |
double *xp=new double[npp]; |
double *xp=new double[npp]; |
1215 |
double *wp=new double[npp]; |
double *wp=new double[npp]; |
1216 |
lfit->CalcGaussLegendreSamplingPoints(npp,xp,wp,1e-12); |
lfit->CalcGaussLegendreSamplingPoints(npp,xp,wp,1e-12); |
1362 |
Clear(); |
Clear(); |
1363 |
//delete this; |
//delete this; |
1364 |
}; |
}; |
1365 |
|
|
1366 |
|
|
1367 |
|
|
1368 |
|
|
1369 |
|
|
1370 |
|
|
1371 |
|
|
1372 |
|
|
1373 |
|
|
1374 |
|
|
1375 |
|
|
1376 |
|
|
1377 |
|
|
1378 |
|
|
1379 |
|
|
1380 |
|
|
1381 |
|
|
1382 |
|
|
1383 |
|
|
1384 |
|
|