11 unsigned int Locate(vector<double>&xx,
double x){
13 if (x==xx[0])
return 0;
14 else if (x==xx[n-1])
return n-2;
18 int ascnd=(xx[n-1]>=xx[0]);
21 if ( (x>=xx[jm])==ascnd)
54 double sqrt_t=
sqrt(my_t);
55 double t3=my_t*my_t*my_t;
56 double delta_mag=fabs(delta);
57 double a=a1+a2*delta_mag;
58 double b=b1+b2*delta_mag;
59 double c=c1+c2*delta_mag+c3*delta*delta;
60 f_delta=a*sqrt_t+b*my_t+c*t3;
61 f_0=a1*sqrt_t+b1*my_t+c1*t3;
66 double sqrt_t=
sqrt(my_t);
67 double delta_mag=fabs(delta);
79 double delta_sq=delta*delta;
80 double a=a1+a2*delta_mag+a3*delta_sq;
81 double b=b1+b2*delta_mag+b3*delta_sq;
82 f_delta=a*sqrt_t+b*my_t;
83 f_0=a1*sqrt_t+b1*my_t;
97 double frac=(t-cdc_drift_table[
index])/dt;
98 double d_0=0.01*(double(index)+frac);
105 d=f_delta*(d_0/f_0*P+1.-P);
114 TFile *
thisFile = TFile::Open(inputROOTFile);
115 TH1I *Bz_hist = (TH1I *) thisFile->Get(
"/CDC_TimeToDistance/Bz");
116 TF2 *
f1,*
f2;
const Int_t npar = 18;
117 bool isFieldOff =
false;
118 if (Bz_hist == 0) isFieldOff =
true;
124 TProfile *constants = (TProfile*) thisFile->Get(
"/CDC_TimeToDistance/CDC_TD_Constants");
148 for (
unsigned int i=1; i<=78; i++){
152 int run = (int) constants->GetBinContent(125);
156 Double_t parameters[npar] =
158 long_drift_func[1][0], long_drift_func[1][1], long_drift_func[1][2],
159 long_drift_func[2][0], long_drift_func[2][1], long_drift_func[2][2],
161 short_drift_func[1][0], short_drift_func[1][1], short_drift_func[1][2],
162 short_drift_func[2][0], short_drift_func[2][1], short_drift_func[2][2]};
165 f1->SetParameters(parameters);
166 f2->SetParameters(parameters);
176 TProfile2D *profile = (TProfile2D *) thisFile->Get(
"/CDC_TimeToDistance/Predicted Drift Distance Vs Delta Vs t_drift");
179 gStyle->SetOptStat(0);
181 TCanvas *
c1 =
new TCanvas (
"c1",
"c1", 800, 600);
182 Double_t contours[21] =
183 { 0.00, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
184 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0};
186 profile->SetContour(21, contours);
187 profile->Draw(
"colz");
188 f1->SetContour(21, contours);
189 profile->Draw(
"cont2 list same");
190 f1->Draw(
"cont2 list same");
192 c1->SaveAs(Form(
"Before/Before_Run%i.png", run));
194 TProfile2D *profileRebin = profile->Rebin2D(4,4,
"Rebin");
195 TFitResultPtr fr = profileRebin->Fit(
"f2",
"S");
196 TCanvas *
c2 =
new TCanvas (
"c2",
"c2", 800, 600);
198 profile->Draw(
"colz");
199 f2->SetContour(21, contours);
200 profile->Draw(
"cont2 list same");
201 f2->Draw(
"cont2 list same");
203 c2->SaveAs(Form(
"After/After_Run%i.png", run));
205 TCanvas *
c3 =
new TCanvas (
"c3",
"c3", 800, 600);
206 f1->Draw(
"cont2 list");
208 f2->Draw(
"cont2 list same");
210 c3->SaveAs(Form(
"Combined/Combined_Run%i.png", run));
212 if ((Int_t) fr == 0){
213 ofstream outputTextFile;
214 outputTextFile.open(Form(
"ccdb/ccdb_Format_%i.txt",run));
215 outputTextFile << fr->Parameter(0) <<
" " << fr->Parameter(1) <<
" " << fr->Parameter(2) <<
" " ;
216 outputTextFile << fr->Parameter(3) <<
" " << fr->Parameter(4) <<
" " << fr->Parameter(5) <<
" " ;
217 outputTextFile << fr->Parameter(6) <<
" " << fr->Parameter(7) <<
" " << fr->Parameter(8) <<
" " ;
219 outputTextFile << fr->Parameter(9) <<
" " << fr->Parameter(10) <<
" " << fr->Parameter(11) <<
" " ;
220 outputTextFile << fr->Parameter(12) <<
" " << fr->Parameter(13) <<
" " << fr->Parameter(14) <<
" " ;
221 outputTextFile << fr->Parameter(15) <<
" " << fr->Parameter(16) <<
" " << fr->Parameter(17) <<
" " ;
223 outputTextFile.close();
227 TH2I *resVsT = (TH2I*)thisFile->Get(
"/CDC_TimeToDistance/Residual Vs. Drift Time");
228 TCanvas *
c4 =
new TCanvas(
"c4",
"c4", 800, 600);
229 resVsT->Draw(
"colz");
230 c4->SaveAs(Form(
"ResVsT/ResVsT_Run%i.png", run));
232 TCanvas *
c5 =
new TCanvas(
"c5",
"c5", 800, 600);
234 p = (TH1D*)resVsT->ProjectionY();
237 p->Fit(
"gaus",
"sqWR",
"", -0.01, 0.01);
238 c5->SaveAs(Form(
"Proj/Proj_ResVsT_Run%i.png", run));
240 TCanvas *
c6 =
new TCanvas(
"c6",
"c6", 1600, 900);
241 c6->Divide(3, 2, 0.001, 0.001);
243 profile->SetContour(21, contours);
244 profile->Draw(
"colz");
245 f1->SetContour(21, contours);
246 profile->Draw(
"cont2 list same");
247 f1->Draw(
"cont2 list same");
251 profile->Draw(
"colz");
252 f2->SetContour(21, contours);
253 profile->Draw(
"cont2 list same");
254 f2->Draw(
"cont2 list same");
258 f1->Draw(
"cont2 list");
260 f2->Draw(
"cont2 list same");
264 resVsT->Draw(
"colz");
271 c6->SaveAs(Form(
"Monitoring/Monitoring_Run%i.png", run));
273 gApplication->Terminate();
unsigned int Locate(vector< double > &xx, double x)
double short_drift_func[3][3]
static char index(char c)
Double_t TimeToDistance(Double_t *x, Double_t *par)
double long_drift_func[3][3]
vector< double > cdc_drift_table
double magnet_correction[2][2]
void FitTimeToDistance(TString inputROOTFile="hd_root.root")