12 #include "tfit_CuCu.C"
23 Double_t tmin ( Double_t *v, Double_t *par )
26 Double_t argS = (x - par[1])*par[2];
27 Double_t argG = (x - par[1])*par[2];
28 Double_t fitval = par[0]*TMath::Freq( argS )+
29 par[3]*TMath::Exp(-0.5*argG*argG);
41 Double_t tmax ( Double_t *v, Double_t *par )
44 Double_t argS = (par[1] - x )*par[2];
45 Double_t fitval = par[0]*TMath::Freq( argS );
95 {
"timeB",
"time for 80 anodes", 256, 3, 0.,128., 0.,3. };
102 char * fName =
"afs_rhic.bnl.gov_star_users_fisyak_work_SvtSsdAlignment_Pass102_CuCu62PlotsTBNFP25rCut0.5cm.root";
103 TFile * f =
new TFile( fName );
105 char * outName =
"tfit_CuCu62_L3";
106 char ftName[128] =
"";
107 char foName[128] =
"";
108 strcat(ftName, outName); strcat(ftName,
".root");
109 strcat(foName, outName); strcat(foName,
".txt");
110 cout << ftName << endl;
111 cout << foName << endl;
112 TFile fout(ftName,
"RECREATE",
"fit parameters tree");
113 FILE * pFile = fopen (foName,
"wt");
114 if (pFile == 0)
return -1;
120 TTree * tree =
new TTree(
"Fit0T",
"t0 fit output tree");
121 tree->Branch(
"fit_res",&pFitOut,8000,99);
125 TCanvas *c1 =
new TCanvas(
"fit",
"t0fit", 300,10,700,650);
129 const int NL[4] = {8, 12, 16, 20};
130 const int NW[4] = {4, 6, 7, 16};
132 for (
int barrel = 1; barrel <= 3; barrel++){
133 for (
int ladder = 1; ladder <= NL[barrel-1]; ladder++){
134 for (
int wafer = 1; wafer <= NW[barrel-1]; wafer++) {
135 for (
int hybrid = 1; hybrid <= 2; hybrid++){
140 sprintf( nome,
"B%iL%02iW%iH%i",barrel,ladder,wafer,hybrid);
142 TH1F *hs =
new TH1F(Form(
"hybrid %i_%i_%i",ladder,wafer,hybrid),
145 plotTB.nx, plotTB.xmin, plotTB.xmax );
148 for (Int_t anode =1; anode <=3; anode++) {
149 TString Name(
"timeB");
150 Name += Form(
"L%02iB%iW%02iH%iA%i", ladder, barrel, wafer, hybrid, anode);
152 TH1F *hist = (TH1F *) f->Get(Name);
153 if (! hist)
continue;
163 FitOut.fName = fName;
165 FitOut.barrel = barrel;
166 FitOut.ladder = ladder;
167 FitOut.wafer = wafer;
168 FitOut.hybrid = hybrid;
169 FitOut.Entries = hs->GetEntries();
171 cout <<
" ********************************************************** " << endl;
172 cout <<
" Entries = " << FitOut.Entries << endl;
173 if ( FitOut.Entries < 100 ) cout <<
" histogram is empty: " << nome << endl;
174 if ( FitOut.Entries < 100 )
continue;
175 cout <<
" B " << FitOut.barrel
176 <<
" L " << FitOut.ladder
177 <<
" W " << FitOut.wafer
178 <<
" H " << FitOut.hybrid
179 <<
" nome: " << FitOut.hName <<
""
184 double par0 = FitOut.Entries/220.;
186 int idx = barrel*10000 + ladder*100 + wafer*10 + hybrid;
187 double t0_init = 10.;
188 double tmax_init = 120.;
189 double d_length = 29928.;
190 int init = InitEdge ( idx, t0_init, tmax_init, d_length);
191 cout <<
" Init: " << init
192 <<
" t0 = " << t0_init
193 <<
" tmax = " << tmax_init
194 <<
" par0 = " << par0
200 TF1 * fit =
new TF1(
"fit0",tmin, 0., 16., Npar);
201 fit->SetParameter(0,par0);
202 fit->SetParLimits(0,0.,2000.);
203 fit->SetParameter(1,t0_init);
204 fit->SetParameter(2,12.3);
205 fit->SetParLimits(2,0.,1000.);
206 fit->SetParameter(3,par0*2.);
207 fit->SetParLimits(3,0.,2000.);
215 FitOut.fitflag = hs->Fit(
"fit0",
"LIBr");
216 cout <<
" fit status = " << FitOut.fitflag << endl;
218 if ( FitOut.fitflag != 0 ) cout <<
"Fit failed: " << FitOut.fitflag << endl;
220 FitOut.chi2 = fit->GetChisquare();
221 cout <<
" Chi**2 = " << FitOut.chi2 << endl;
222 cout <<
" Npar = " << FitOut.Nparr << endl;
223 for (
int jpar = 0; jpar < Npar; jpar++){
224 FitOut.prr[jpar]=fit->GetParameter(jpar);
225 FitOut.err[jpar]=fit->GetParError(jpar);
226 cout <<
" par " << jpar
227 <<
" = " << FitOut.prr[jpar]
228 <<
" +- " << FitOut.err[jpar]
230 if ( FitOut.prr[jpar] < 0.) cout <<
" WARNING! " << FitOut.prr[jpar] << endl;
240 if ( in ==
's') { cout <<
" operator intervention " << endl;
return -3;}
241 if ( in ==
'g') {FitOut.comment =
"good "; FitOut.fitID = 1;}
242 else {FitOut.comment =
"refit"; FitOut.fitID = -1;}
243 cout <<
" " << FitOut.hName
244 <<
" comment : " << FitOut.comment
245 <<
" fit ID : " << FitOut.fitID
253 if (init == 0) Rmin = tmax_init - 3.;
254 TF1 * ftM =
new TF1(
"fitM",tmax, Rmin, 128., NpaM);
255 ftM->SetParameter(0, par0);
256 ftM->SetParLimits(0, 0.,2000.);
257 ftM->SetParameter(1, tmax_init);
258 ftM->SetParameter(2, 12.2);
264 FitOut.ftMflag = hs->Fit(
"fitM",
"LIBr");
265 cout <<
" fit status = " << FitOut.ftMflag << endl;
267 if ( FitOut.ftMflag != 0 ) cout <<
"Fit failed: " << FitOut.ftMflag << endl;
269 FitOut.chi2M = ftM->GetChisquare();
270 cout <<
" Chi**2 = " << FitOut.chi2M << endl;
271 cout <<
" Npar = " << FitOut.NparM << endl;
272 for (
int jpar = 0; jpar < NpaM; jpar++){
273 FitOut.prM[jpar]=ftM->GetParameter(jpar);
274 FitOut.erM[jpar]=ftM->GetParError(jpar);
275 cout <<
" par " << jpar
276 <<
" = " << FitOut.prM[jpar]
277 <<
" +- " << FitOut.erM[jpar]
279 if ( FitOut.prM[jpar] < 0.) cout <<
" WARNING! " << FitOut.prM[jpar] << endl;
289 if ( in ==
'q') { cout <<
" quit " << endl;
return -3;}
290 if ( in ==
's') { cout <<
" stopped " << endl; fout.Write(); fout.Close(); fclose (pFile);
return -4;}
291 if ( in ==
'g') {FitOut.commentM =
"good "; FitOut.ftMID = 1;}
292 else {FitOut.commentM =
"refit"; FitOut.ftMID = -1;}
293 cout <<
" " << FitOut.hName
294 <<
" comment M: " << FitOut.commentM
295 <<
" fit ID M: " << FitOut.ftMID
303 const double timeb = 40.;
304 const double d_veldef = 6.75;
316 if ( FitOut.fitID>0 &&
318 (FitOut.prM[1] - FitOut.prr[1])> 0. )
319 d_velosity = d_length/( FitOut.prM[1] - FitOut.prr[1])/timeb;
320 else d_velosity = d_veldef;
323 sprintf(row_name,
"B%iL%02iW%iH%i", barrel, ladder, wafer, hybrid);
325 fprintf (pFile,
" { %i, %4i, %i, %i, %i, %2i, %i, %i, ",
326 type, idx, nrows, npr, barrel, ladder, wafer, hybrid);
327 fprintf (pFile,
"%7.3f, %6.3f, %7.3f, %6.3f, %7.1f, ",
328 FitOut.prr[1], FitOut.err[1], FitOut.prM[1], FitOut.erM[1], d_length );
329 fprintf (pFile,
"{%6.4f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f }}, ",
330 v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9] );
331 fprintf (pFile,
" // %2i %2i %2i %2i %s %s %s \n",
332 FitOut.fitflag, FitOut.fitID, FitOut.ftMflag, FitOut.ftMID,
333 FitOut.comment, FitOut.commentM, row_name );