12 #include "tfit_CuCu200NF.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 );
51 class FitTree :
public TObject {
95 {
"timeB",
"time for 80 anodes", 256, 3, 0.,128., 0.,3. };
98 int t0fitM (
int hybrid,
107 cout <<
" H " << hybrid
115 sprintf( o_name,
"B%iL%02iW%iH%iE%i_leaf.root",barrel,ladder,wafer,hybrid,edge);
116 cout <<
" o_name: " << o_name << endl;
120 char * fName =
"afs_rhic.bnl.gov_star_users_fisyak_work_SvtSsdAlignment_Pass102_CuCu62PlotsTBNFP25rCut0.5cm.root";
121 TFile * f =
new TFile( fName );
122 TFile fout(o_name,
"RECREATE",
"fit parameters tree");
128 TTree * tree =
new TTree(
"Fit0T",
"t0 fit output tree");
129 tree->Branch(
"fit_res",&pFitOut,8000,99);
134 sprintf( nome,
"B%iL%02iW%iH%i",barrel,ladder,wafer,hybrid);
136 TH1F *hs =
new TH1F(Form(
"hybrid %i_%i_%i",ladder,wafer,hybrid),
138 plotTB.nx, plotTB.xmin, plotTB.xmax );
141 for (Int_t anode =1; anode <=3; anode++) {
142 TString Name(
"timeB");
143 Name += Form(
"L%02iB%iW%02iH%iA%i", ladder, barrel, wafer, hybrid, anode);
145 TH1F *hist = (TH1F *) f->Get(Name);
146 if (! hist)
continue;
153 TCanvas *c1 =
new TCanvas(
"fit",
"t0fit", 300,10,700,650);
160 FitOut.fName = fName;
162 FitOut.barrel = barrel;
163 FitOut.ladder = ladder;
164 FitOut.wafer = wafer;
165 FitOut.hybrid = hybrid;
166 FitOut.Entries = hs->GetEntries();
167 cout <<
" Entries = " << FitOut.Entries << endl;
168 if ( FitOut.Entries < 100 ) cout <<
" histogram is empty: " << nome << endl;
169 cout <<
" B " << FitOut.barrel
170 <<
" L " << FitOut.ladder
171 <<
" W " << FitOut.wafer
172 <<
" H " << FitOut.hybrid
173 <<
" nome: " << FitOut.hName <<
""
178 double par0 = FitOut.Entries/220.;
179 cout <<
" par[0] set to " << par0 << endl;
181 int idx = barrel*10000 + ladder*100 + wafer*10 + hybrid;
182 double t0_init = 10.;
183 double tmax_init = 117.;
184 int init = InitEdge ( idx, t0_init, tmax_init);
185 cout <<
" Init: " << init
186 <<
" t0 = " << t0_init
187 <<
" tmax = " << tmax_init
190 TF1 * fit =
new TF1(
"fit0",tmin, Rmin, Rmax, Npar);
191 fit->SetParameter(0,par0);
192 fit->SetParLimits(0,0.,2000.);
193 fit->SetParameter(1,t0_init);
194 fit->SetParameter(2,3.3);
195 fit->SetParLimits(2,0.,1000.);
196 fit->SetParameter(3,par0*2.);
197 fit->SetParLimits(3,0.,2000.);
198 fit->SetParameter(4,10.0);
199 fit->SetParameter(5,3.3);
206 if (edge ==0 ) FitOut.fitflag = hs->Fit(
"fit0",
"LIBr");
207 cout <<
" fit status = " << FitOut.fitflag << endl;
209 if ( FitOut.fitflag != 0 ) cout <<
"Fit failed: " << FitOut.fitflag << endl;
211 FitOut.chi2 = fit->GetChisquare();
212 cout <<
" Chi**2 = " << FitOut.chi2 << endl;
213 cout <<
" Npar = " << FitOut.Nparr << endl;
214 for (
int jpar = 0; jpar < Npar; jpar++){
215 FitOut.prr[jpar]=fit->GetParameter(jpar);
216 FitOut.err[jpar]=fit->GetParError(jpar);
217 cout <<
" par " << jpar
218 <<
" = " << FitOut.prr[jpar]
219 <<
" +- " << FitOut.err[jpar]
221 if ( FitOut.prr[jpar] < 0.) cout <<
" WARNING! " << FitOut.prr[jpar] << endl;
229 if ( edge == 0 && FitOut.fitflag == 0)
230 {FitOut.comment =
"good"; FitOut.fitID = 2;}
231 else {FitOut.comment =
"nofit"; FitOut.fitID = -2;}
232 cout <<
" " << FitOut.hName
233 <<
" comment: " << FitOut.comment
234 <<
"; fit ID: " << FitOut.fitID
241 if (init == 0) Rmin = tmax_init - 3.;
242 TF1 * ftM =
new TF1(
"fitM",tmax, Rmin, Rmax, NpaM);
243 ftM->SetParameter(0, par0);
244 ftM->SetParLimits(0, 0.,2000.);
245 ftM->SetParameter(1, tmax_init);
246 ftM->SetParameter(2, 2.2);
252 if (edge ==1 ) FitOut.ftMflag = hs->Fit(
"fitM",
"LIBr");
253 cout <<
" fit status = " << FitOut.ftMflag << endl;
255 if ( FitOut.ftMflag != 0 ) cout <<
"Fit failed: " << FitOut.ftMflag << endl;
257 FitOut.chi2M = ftM->GetChisquare();
258 cout <<
" Chi**2 = " << FitOut.chi2M << endl;
259 cout <<
" Npar = " << FitOut.NparM << endl;
260 for (
int jpar = 0; jpar < NpaM; jpar++){
261 FitOut.prM[jpar]=ftM->GetParameter(jpar);
262 FitOut.erM[jpar]=ftM->GetParError(jpar);
263 cout <<
" par " << jpar
264 <<
" = " << FitOut.prM[jpar]
265 <<
" +- " << FitOut.erM[jpar]
267 if ( FitOut.prM[jpar] < 0.) cout <<
" WARNING! " << FitOut.prM[jpar] << endl;
275 if ( edge == 1 && FitOut.ftMflag == 0 )
276 {FitOut.commentM =
"good"; FitOut.ftMID = 2;}
277 else {FitOut.commentM =
"nofit"; FitOut.ftMID = -2;}
278 cout <<
" " << FitOut.hName
279 <<
" comment M: " << FitOut.commentM
280 <<
"; fit ID M: " << FitOut.ftMID