11 TColor::CreateColorWheel();
13 TFile *
f =
new TFile(
"bfield.root");
14 TTree *Bfield = (TTree*)gROOT->FindObject(
"Bfield");
30 Double_t z_bounds[] = {-30.0, -10.0, +10.0, +30.0, +67.0, +100.0, +125.0, +148.0, +175.0, 205.0, +236.0, 0.0};
33 Double_t rmin_inches = 1.0;
34 Double_t rmax_inches = 26.0;
35 UInt_t
Nr = (UInt_t)(26.0-1.0)+1;
37 while(z_bounds[Nsec+1]!=0.0){
48 fname<<
"BfieldParameters_"<<Bi<<
".root";
49 TFile *fout =
new TFile(fname.str().c_str(),
"RECREATE");
53 TCanvas *
c1 =
new TCanvas(
"c1");
55 ss<<
"BfieldParameters_"<<Bi<<
".ps";
56 string gfname = ss.str();
57 c1->Print((gfname+
"[").c_str());
59 int colors[] = {kBlue, kRed, kGreen, kMagenta, kCyan};
71 TH1D *phist =
new TH1D(
"phist",
"Parameters", 26, 0.5*2.54, 26.5*2.54);
73 phist->SetXTitle(
"R (cm)");
74 phist->SetYTitle(
"Value of Chebyshev coefficient");
77 TH1D *z_bounds_hist =
new TH1D(
"z_bounds_hist",
"Z boundaries for sections", Nsec+1, 0.5, Nsec+1.5);
78 for(UInt_t sec=0; sec<=Nsec; sec++)z_bounds_hist->Fill(sec+1, z_bounds[sec]*2.54);
81 TH1D *sec_pars[50][50];
82 for(UInt_t sec=1; sec<=Nsec; sec++){
83 for(UInt_t i=0; i<=order1; i++){
85 sprintf(hname,
"sec%d_p%d", sec, i);
86 sec_pars[sec][i] = (TH1D*)phist->Clone(hname);
89 title<<
"Parameter "<<i<<
" for section "<<sec<<
" "<<Bi;
90 sec_pars[sec][i]->SetTitle(title.str().c_str());
95 for(Double_t r_inches=rmin_inches; r_inches<=rmax_inches; r_inches+=1.0){
99 for(UInt_t sec=1; sec<=Nsec; sec++){
100 if(z_bounds[sec]==0.0)
break;
102 Double_t r = 2.54*r_inches;
103 Double_t
zmin = z_bounds[sec-1];
104 Double_t
zmax = z_bounds[sec];
107 stringstream funcname;
108 funcname<<
"sec"<<sec<<
"_r"<<(UInt_t)r_inches;
109 func[sec] =
FitSection(order1, Bfield, Bi, zmin, zmax, r, funcname.str().c_str());
112 for(UInt_t i=0; i<=order1; i++){
113 sec_pars[sec][i]->SetBinContent(sec_pars[sec][i]->FindBin(r) ,func[sec]->GetParameter(i+2));
119 cut<<
"(abs(r-"<<r<<
")<"<<0.1<<
")";
122 Bfield->SetMarkerStyle(8);
123 Bfield->SetMarkerSize(0.7);
124 Bfield->Draw(varexp.str().c_str(), cut.str().c_str());
127 for(UInt_t sec=1; sec<=Nsec; sec++){
128 func[sec]->SetLineColor(colors[(sec-1)%Ncolors]);
130 func[sec]->Draw(
"same");
135 c1->Print(gfname.c_str());
140 TH1D *pphist =
new TH1D(
"pphist",
"Parameterization of Parameters", order2+1, -0.5, (
double)order2 + 0.5);
142 pphist->SetXTitle(
"Order of Chebyshev coefficient");
143 pphist->SetYTitle(
"Value of Chebyshev coefficient");
146 for(UInt_t sec=1; sec<=Nsec; sec++){
149 for(UInt_t i=0; i<=order1; i++){
154 sprintf(hname,
"sec%d_pp%d", sec, i);
155 TH1D *sec_ppars = (TH1D*)pphist->Clone(hname);
156 for(
int j=0; j<=order2; j++)sec_ppars->SetBinContent(j, f1->GetParameter(j+2));
159 f1->SetLineColor(colors[(sec-1)%Ncolors]);
160 sec_pars[sec][i]->SetMarkerStyle(8);
161 sec_pars[sec][i]->SetMarkerSize(0.7);
163 sec_pars[sec][i]->Draw(
"P");
165 c1->Print(gfname.c_str());
171 c1->Print((gfname+
"]").c_str());
183 TF1*
FitSection(
int order, TTree *Bfield,
const char *Bi, Double_t z_min_inches, Double_t z_max_inches, Double_t r,
const char *fname)
185 cout<<
"Fitting "<<fname<<
" at r="<<r<<endl;
189 Double_t delta_z = 2.54;
190 Double_t delta_r = 2.54;
193 Double_t z_min = z_min_inches*delta_z - delta_z/2.0;
194 Double_t z_max = z_max_inches*delta_z + delta_z/2.0;
195 Double_t epsilon = delta_z/1000.0;
196 UInt_t NbinsZ = floor((z_max - z_min + epsilon)/delta_z);
201 TH1D *Bi_vs_znorm =
new TH1D(
"Bi_vs_znorm",
"Bi as function of modified z coordinate", NbinsZ, z_min, z_max);
207 cut<<Bi<<
"*(abs(r-"<<r<<
")<"<<delta_r/10.0<<
")";
208 Bfield->Project(
"Bi_vs_znorm",
"z", cut.str().c_str());
211 TF1 *myfunc = (TF1*)func->Clone(fname);
TF1 * FitSection(int order, TTree *Bfield, const char *Bi, Double_t z_min_inches, Double_t z_max_inches, Double_t r, const char *fname)
sprintf(text,"Post KinFit Cut")
void ParameterizeBField(void)
void Parameterize(TTree *Bfield, const char *Bi)
double func(double *x, double *par)
TF1 * chebyshev_Fit(TH1D *h, UInt_t order=9)