101 {
102
108
111 double chisq;
112 double ndf;
115 char funname[200];
116
117
118 TF1* ftminCosm[
NLAYER][2];
119 double t0FitCosm[
NLAYER][2];
120
121 bool fgT0Ini = false;
123 ifstream fparIni(
"fitT0_inival.txt");
124 if(fparIni.is_open()){
125 string strtmp;
126 for(
int lay=0; lay<
NLAYER; lay++){
127 fparIni >> strtmp >> strtmp;
128 for(int i=0; i<6; i++) fparIni >> t0ParIni[lay][2][i];
129 }
130 fparIni.close();
131 fgT0Ini = true;
132 cout << "read initial values of T0 fit from fitT0_inival.txt" << endl;
133 }
134 if(!fgT0Ini) cout << "set initial values of T0 fit to default values" << endl;
135
137 for(
int lay=0; lay<
NLAYER; lay++){
138 for(
int lr=0; lr<
NLR; lr++){
139 fitTminFg[lay][lr] = 0;
140 chindfTmin[lay][lr] = -1;
141 sprintf(funname,
"ftmin%02d_%d", lay, lr);
142 ftmin[lay][lr] = new TF1(funname, funTmin, 0, 150, 6);
143 if(lr<2) continue;
144
146
147
148
149
150
151
152 double c1Ini = (m_hTrec[lay][lr]->GetMaximum());
153
154 if(fgT0Ini){
155 for(int i=0; i<6; i++){
156 if(fabs(t0ParIni[lay][2][i] + 9999)<0.01) continue;
157 ftmin[lay][lr] -> SetParameter(i, t0ParIni[lay][2][i]);
158 }
159 } else{
160 ftmin[lay][lr] -> SetParameter(0, 0);
161 ftmin[lay][lr] -> SetParameter(1, c1Ini);
162 ftmin[lay][lr] -> SetParameter(2, 0);
163 ftmin[lay][lr] -> SetParameter(4, initT0);
164 if(lay<4) ftmin[lay][lr] -> SetParameter(5, 4);
165 else ftmin[lay][lr] -> SetParameter(5, 1.5);
166 }
167
168 if(lay<4) m_hTrec[lay][lr] ->
Fit(funname,
"Q",
"", 0, 140);
170 gStyle -> SetOptFit(11);
171 chisq = ftmin[lay][lr]->GetChisquare();
172 ndf = ftmin[lay][lr]->GetNDF();
173 chindfTmin[lay][lr] = chisq / ndf;
174
175
176
177
178
179
180
181
182
184 fitTminFg[lay][lr] = 1;
185 t0Fit[lay][lr] = ftmin[lay][lr]->GetParameter(4);
188 for(int i=0; i<6; i++) t0FitPar[lay][lr][i] = ftmin[lay][lr]->GetParameter(i);
189 }
190 }
191
192 if(0 == fitTminFg[lay][lr]){
194 t0Cal[lay][lr] = calconst->
getT0(wir);
196 }
197 }
198
199 for(int iud=0; iud<2; iud++){
200 sprintf(funname,
"ftminCosm_%02d_%d", lay, iud);
201 ftminCosm[lay][iud] = new TF1(funname, funTmin, 0, 150, 6);
202 ftminCosm[lay][iud] -> SetParameter(0, 0);
203 ftminCosm[lay][iud] -> SetParameter(4, initT0);
204 ftminCosm[lay][iud] -> SetParameter(5, 1);
206 gStyle -> SetOptFit(11);
208 t0FitCosm[lay][iud] = ftminCosm[lay][iud]->GetParameter(4);
209 }
210 }
211
212
214 for(
int lay=0; lay<
NLAYER; lay++){
215 for(
int lr=0; lr<
NLR; lr++){
216 fitTmaxFg[lay][lr] = 0;
217 chindfTmax[lay][lr] = -1;
218 sprintf(funname,
"ftmax%02d_%d", lay, lr);
219 ftmax[lay][lr] = new TF1(funname, funTmax, 250, 500, 4);
220
222 ftmax[lay][lr] -> SetParameter(2,
gInitTm[lay]);
223 ftmax[lay][lr] -> SetParameter(3, 10);
225 gStyle -> SetOptFit(11);
226 chisq = ftmax[lay][lr]->GetChisquare();
227 ndf = ftmax[lay][lr]->GetNDF();
228 chindfTmax[lay][lr] = chisq / ndf;
230 fitTmaxFg[lay][lr] = 1;
231 tmax[lay][lr] = ftmax[lay][lr]->GetParameter(2);
232 }
233 }
234
235 if(0 == fitTmaxFg[lay][lr]){
236 tmax[lay][lr] = (calconst->
getXtpar(lay, 0, lr, 6)) + t0Fit[lay][2];
237 }
238 }
239 }
240
241
243 for(
int lay=0; lay<
NLAYER; lay++){
244 ft0 << setw(5) << lay << setw(3) << fitTminFg[lay][2]
245 << setw(15) << t0Cal[lay][2] << setw(15) << t0Fit[lay][2]
246 << setw(15) << chindfTmin[lay][2] << endl;
247 }
248 ft0 << endl;
249 for(
int lay=0; lay<
NLAYER; lay++){
250 ft0 << setw(5) << lay
251 << setw(3) << fitTmaxFg[lay][0] << setw(10) << tmax[lay][0]
252 << setw(10) << chindfTmax[lay][0]
253 << setw(3) << fitTmaxFg[lay][1] << setw(10) << tmax[lay][1]
254 << setw(10) << chindfTmax[lay][1]
255 << setw(3) << fitTmaxFg[lay][2] << setw(10) << tmax[lay][2]
256 << setw(10) << chindfTmax[lay][2]
257 << setw(10) << tmax[lay][0] - t0Fit[lay][2]
258 << setw(10) << tmax[lay][1] - t0Fit[lay][2]
259 << setw(10) << tmax[lay][2] - t0Fit[lay][2]
260 << endl;
261 }
262 ft0 << endl;
263 for(
int lay=0; lay<
NLAYER; lay++){
264 ft0 << setw(5) << lay << setw(15) << chindfTmin[lay][2];
265 for(int i=0; i<6; i++) ft0 << setw(15) << t0FitPar[lay][2][i];
266 ft0 << endl;
267 }
268 ft0.close();
269 cout << "preT0.dat was written." << endl;
270
271
273 for(
int lay=0; lay<
NLAYER; lay++){
274 ft0cosm << setw(5) << lay << setw(15) << t0Fit[lay][2]
275 << setw(15) << t0FitCosm[lay][0] << setw(15) << t0FitCosm[lay][1] << endl;
276 }
277 ft0cosm.close();
278
279
280 for(
int i=0; i<
NWIRE; i++){
281 int lay = m_pGeom -> getWire(i) -> getLayerId();
283 calconst -> resetT0(i, t0Cal[lay][2]);
284 calconst -> resetDelT0(i, 0.0);
285 }
286 }
287
288
290 double tm;
291 for(
int lay=0; lay<
NLAYER; lay++){
293
294 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
295 for(
int lr=0; lr<
NLR; lr++){
296 tm = tmax[lay][lr] - t0Fit[lay][2];
299 calconst -> resetXtpar(lay, iEntr, lr, 6, tm);
300 }
301 }
302 }
303 }
304 }
305
306 renameHist();
307 for(
int lay=0; lay<
NLAYER; lay++){
308 for(
int lr=0; lr<
NLR; lr++){
309 delete ftmin[lay][lr];
310 delete ftmax[lay][lr];
311 }
312 }
313}
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
double gTminFitRange[NLAYER][2]
double gTmaxFitRange[NLAYER][2]
double getT0(int wireid) const
double getXtpar(int lay, int entr, int lr, int order)
const MdcCosWire * getWire(int iwire) const