22 fname<<
"solenoid"<<based_on<<
"_params";
23 ofstream fout_master(fname.str().c_str());
26 time_t now = time(NULL);
27 fout_master<<
"#"<<endl;
28 fout_master<<
"# Solenoidal field parameterization"<<endl;
29 fout_master<<
"#"<<endl;
30 fout_master<<
"# This file auto-generated by ParameterizeBField_codegen.C macro."<<endl;
31 fout_master<<
"# "<<ctime(&now);
32 fout_master<<
"# Produced by "<<getenv(
"USER")<<
" on "<<getenv(
"HOST")<<endl;
33 fout_master<<
"#"<<endl;
34 fout_master<<
"# input based on: "<<based_on<<endl;
35 fout_master<<
"#"<<endl;
36 fout_master<<
"# This is the master parameters list. The parameterization of the"<<endl;
37 fout_master<<
"# field is broken up into several sections in z. Each section has"<<endl;
38 fout_master<<
"# its own set of parameters kept in its own namepath."<<endl;
39 fout_master<<
"#"<<endl;
40 fout_master<<
"# Each line below represents a section. Sections are either representing"<<endl;
41 fout_master<<
"# Bx or Bz. Given in the table are the limits over with the section"<<endl;
42 fout_master<<
"# covers."<<endl;
43 fout_master<<
"#"<<endl;
44 fout_master<<
"#"<<endl;
45 fout_master<<
"#% Bi sec zmin zmax zmid znorm rmin rmax rmid rnorm namepath"<<endl;
48 WriteFile(
"BfieldParameters_Bz.root",
"Bz", fout_master, fname);
49 WriteFile(
"BfieldParameters_Bx.root",
"Bx", fout_master, fname);
58 void WriteFile(
const char *input_fname,
string element, ofstream &fout_master, stringstream &fname)
60 #define MAX_SECTIONS 100
63 TFile *
f =
new TFile(input_fname);
65 cout<<
"------------------- Ignore errors in this section --------------------"<<endl;
70 TH1D *z_bounds_hist = (TH1D*)gROOT->FindObject(
"z_bounds_hist");
71 UInt_t Nsec = z_bounds_hist->GetNbinsX()-1;
72 for(UInt_t sec=1; sec<=Nsec; sec++){
73 zmin[sec-1] = z_bounds_hist->GetBinContent(z_bounds_hist->FindBin(sec));
74 zmax[sec-1] = z_bounds_hist->GetBinContent(z_bounds_hist->FindBin(sec+1));
77 hname<<
"sec"<<(sec)<<
"_p0";
78 TH1D *sec_p0 = (TH1D*)gROOT->FindObject(hname.str().c_str());
80 rmin[sec-1] = sec_p0->GetXaxis()->GetXmin();
81 rmax[sec-1] = sec_p0->GetXaxis()->GetXmax();
86 for(order1=0; order1<20; order1++){
88 hname<<
"sec1"<<
"_p"<<order1;
89 TH1D *sec1_p = (TH1D*)gROOT->FindObject(hname.str().c_str());
90 if(!sec1_p){order1--;
break;}
94 TH1D *sec1_pp0 = (TH1D*)gROOT->FindObject(
"sec1_pp0");
95 UInt_t order2 = sec1_pp0->GetNbinsX()-1;
97 cout<<
"----------------------------------------------------------------------"<<endl;
100 time_t now = time(NULL);
102 cout<<
"Writing parameters for: "<<element<<endl;
103 cout<<
" sections = "<<Nsec<<endl;
104 cout<<
"1st level order = "<<order1<<endl;
105 cout<<
"2nd level order = "<<order2<<endl;
109 for(UInt_t sec=1; sec<=Nsec; sec++){
112 stringstream my_fname;
113 my_fname<<fname.str()<<
"_"<<element<<
"_sec"<<sec;
114 ofstream fout(my_fname.str().c_str());
115 cout<<
"Writing parameters to "<<fname.str()<<endl;
118 fout_master<<element;
119 fout_master<<
"\t"<<sec;
120 fout_master<<
"\t"<<zmin[sec-1];
121 fout_master<<
"\t"<<zmax[sec-1];
122 fout_master<<
"\t"<<(zmax[sec-1]+zmin[sec-1])/2.0;
123 fout_master<<
"\t"<<(zmax[sec-1]-zmin[sec-1])/2.0;
124 fout_master<<
"\t"<<rmin[sec-1];
125 fout_master<<
"\t"<<rmax[sec-1];
126 fout_master<<
"\t"<<(rmax[sec-1]+rmin[sec-1])/2.0;
127 fout_master<<
"\t"<<(rmax[sec-1]-rmin[sec-1])/2.0;
128 fout_master<<
"\t"<<
"Magnets/Solenoid/"<<my_fname.str();
133 fout<<
"# Solenoidal field parameterization"<<endl;
135 fout<<
"# This file auto-generated by ParameterizeBField_codegen.C macro."<<endl;
136 fout<<
"# "<<ctime(&now);
137 fout<<
"# Produced by "<<getenv(
"USER")<<
" on "<<getenv(
"HOST")<<endl;
139 fout<<
"# input file: "<<f->GetName()<<endl;
140 fout<<
"# section: "<<sec<<
" (out of "<<Nsec<<
")"<<endl;
141 fout<<
"# 1st level order: "<<order1<<endl;
142 fout<<
"# 2nd level order: "<<order2<<endl;
144 fout<<
"# In the following table, values are coefficients of Chebyshev"<<endl;
145 fout<<
"# polynomials. There are 2 levels of parameterization corresponding"<<endl;
146 fout<<
"# to the 2 dimensions in which the field map is parameterized (z and r)."<<endl;
148 fout<<
"# The first level fits the field as a function of z in lab coordinates."<<endl;
149 fout<<
"# The second level parametrizes those coefficients as a function of r"<<endl;
150 fout<<
"# also in lab coordinates."<<endl;
155 int chars_per_val = 14;
156 string header((order2+1)*chars_per_val,
' ');
157 for(UInt_t j=0; j<=order2; j++){
160 string &s = name.str();
161 header.replace((j+1)*chars_per_val-s.length()-2, s.length(), s);
163 fout<<
"#"<<header<<endl;
166 for(UInt_t i=0; i<=order1; i++){
168 hname<<
"sec"<<sec<<
"_pp"<<i;
169 TH1D *
h = (TH1D*)gROOT->FindObject(hname.str().c_str());
171 string line((order2+1)*chars_per_val,
' ');
172 for(UInt_t j=0; j<=order2; j++){
174 val<<h->GetBinContent(j);
175 string &s = val.str();
176 if(s.length()>=chars_per_val){
177 cerr<<
"ERROR: too many characters in val! ("<<__FILE__<<
":"<<__LINE__<<
")"<<endl;
180 line.replace((j+1)*chars_per_val-s.length(), s.length(), s);
void WriteFile(const char *input_fname, string element, ofstream &fout_master, stringstream &fname)
void ParameterizeBField_codegen(const char *based_on="_1500_poisson_20090814_01")