114 {
115
116 TTree* t1 = new TTree( "BarTofPar","barrel parameters" );
117
118 double p[20]={1.};
119 char brname[20];
120 char ptname[20];
121 for(int i=0;i<20;i++){
122 sprintf( brname, "P%d", i );
123 sprintf( ptname, "p%d/D", i );
124 t1->Branch(brname,&p[i],ptname);
125 }
126
127 double bunch0_poff[40]={1.},bunch1_poff[40]={1.},bunch2_poff[40]={1.},bunch3_poff[40]={1.};
128 char broffname[40];
129 char ptoffname[40];
130 for(int i=0;i<40;i++){
131 sprintf( broffname, "Bunch0_Poff%d", i );
132 sprintf( ptoffname, "bunch0_poff%d/D", i );
133 t1->Branch( broffname, &bunch0_poff[i], ptoffname );
134 }
135 for(int i=0;i<40;i++){
136 sprintf( broffname, "Bunch1_Poff%d", i );
137 sprintf( ptoffname, "bunch1_poff%d/D", i );
138 t1->Branch( broffname, &bunch1_poff[i], ptoffname );
139 }
140 for(int i=0;i<40;i++){
141 sprintf( broffname, "Bunch2_Poff%d", i );
142 sprintf( ptoffname, "bunch2_poff%d/D", i );
143 t1->Branch( broffname, &bunch2_poff[i], ptoffname );
144 }
145 for(int i=0;i<40;i++){
146 sprintf( broffname, "Bunch3_Poff%d", i );
147 sprintf( ptoffname, "bunch3_poff%d/D", i );
148 t1->Branch( broffname, &bunch3_poff[i], ptoffname );
149 }
150
151 double fitfun[20]={0.};;
152 char fbrname1[5], fptname1[5], fbrname2[5], fptname2[5];
153 char fbrname3[10], fptname3[10];
154 for(int i=0;i<5;i++){
155 sprintf( fbrname1, "FLeft%d", i );
156 sprintf( fptname1, "fleft%d/D", i );
157 t1->Branch( fbrname1, &fitfun[i], fptname1 );
158 sprintf( fbrname2, "FRight%d", i );
159 sprintf( fptname2, "fright%d/D", i );
160 t1->Branch( fbrname2, &fitfun[5+i], fptname2 );
161 }
162 for(int i=0;i<10;i++){
163 sprintf( fbrname3, "FCounter%d", i );
164 sprintf( fptname3, "fcounter%d/D", i );
165 t1->Branch( fbrname3, &fitfun[10+i], fptname3 );
166 }
167
168 double Atten[8]={1.};
169 for(int i=0;i<8;i++){
170 sprintf( brname, "Atten%d", i );
171 sprintf( ptname, "Atten%d/D", i );
172 t1->Branch(brname, &Atten[i], ptname);
173 }
174
175 double Speed[2]={1.};
176 t1->Branch( "Speed0", &Speed[0], "Speed0/D" );
177 t1->Branch( "Speed1", &Speed[1], "Speed1/D" );
178
179 const int N = 23;
180 ifstream inf[N];
181 bool is_open[N]={false};
182 const char* filelist[N]={
183 "calib_barrel_left.txt",
184 "calib_barrel_right.txt",
185 "calib_barrel_left_offset1_bunch0.txt",
186 "calib_barrel_left_offset2_bunch0.txt",
187 "calib_barrel_right_offset1_bunch0.txt",
188 "calib_barrel_right_offset2_bunch0.txt",
189 "calib_barrel_left_offset1_bunch1.txt",
190 "calib_barrel_left_offset2_bunch1.txt",
191 "calib_barrel_right_offset1_bunch1.txt",
192 "calib_barrel_right_offset2_bunch1.txt",
193 "calib_barrel_left_offset1_bunch2.txt",
194 "calib_barrel_left_offset2_bunch2.txt",
195 "calib_barrel_right_offset1_bunch2.txt",
196 "calib_barrel_right_offset2_bunch2.txt",
197 "calib_barrel_left_offset1_bunch3.txt",
198 "calib_barrel_left_offset2_bunch3.txt",
199 "calib_barrel_right_offset1_bunch3.txt",
200 "calib_barrel_right_offset2_bunch3.txt",
201 "calib_barrel_sigma.txt",
202 "calib_barrel_atten.txt",
203 "calib_barrel_q0.txt",
204 "calib_barrel_veff.txt",
205 "calib_barrel_common.txt"
206 };
207 for(int m=0;m<N;m++){
208 inf[m].open(filelist[m],ios::in);
209 if(inf[m].good())
210 is_open[m]=true;
211 else
212 std::cerr<<"file: "<<filelist[N]<<" can't be found!"<<std::endl;
213 }
214
215 try{
216 for(int k=0;k<176;k++){
217
218 if(is_open[0]&&is_open[1]){
219 for(int j=0;j<7;j++) {
220 inf[0]>>p[j];
221 inf[1]>>p[j+10];
222 }
223 }
224
225 if(is_open[2]&&is_open[3]&&is_open[4]&&is_open[5]){
226 for(int j=0;j<7;j++) {
227 inf[2]>>bunch0_poff[j];
228 inf[3]>>bunch0_poff[j+10];
229 inf[4]>>bunch0_poff[j+20];
230 inf[5]>>bunch0_poff[j+30];
231 }
232 }
233
234 if(is_open[6]&&is_open[7]&&is_open[8]&&is_open[9]){
235 for(int j=0;j<7;j++) {
236 inf[6]>>bunch1_poff[j];
237 inf[7]>>bunch1_poff[j+10];
238 inf[8]>>bunch1_poff[j+20];
239 inf[9]>>bunch1_poff[j+30];
240 }
241 }
242
243
244 if(is_open[10]&&is_open[11]&&is_open[12]&&is_open[13]){
245 for(int j=0;j<7;j++) {
246 inf[10]>>bunch2_poff[j];
247 inf[11]>>bunch2_poff[j+10];
248 inf[12]>>bunch2_poff[j+20];
249 inf[13]>>bunch2_poff[j+30];
250 }
251 }
252 if(is_open[14]&&is_open[15]&&is_open[16]&&is_open[17]){
253 for(int j=0;j<7;j++) {
254 inf[14]>>bunch3_poff[j];
255 inf[15]>>bunch3_poff[j+10];
256 inf[16]>>bunch3_poff[j+20];
257 inf[17]>>bunch3_poff[j+30];
258 }
259 }
260
261 if(is_open[18]){
262 for(int j=0; j<15; j++) {
263 inf[18] >> fitfun[j];
264 }
265 }
266
267 if(is_open[19]){
268 for(int j=0;j<2;j++){
269 inf[19]>>Atten[j];
270 }
271 Atten[0]=1./Atten[0];
272 }
273
274 if(is_open[20]){
275 for(int j=2;j<5;j++){
276 inf[20] >> Atten[j];
277 }
278 }
279
280 if(is_open[21]){
281 for(int j=0;j<2;j++){
282 inf[21]>>Speed[j];
283 }
284 Speed[0]=1./Speed[0];
285 }
286 t1->Fill();
287 }
288 }catch(...) {
289 return false;
290 }
291
292 TTree* t2 = new TTree( "BarTofParCommon","common part of barrel" );
293 double t0Offset[2]={0.},sigmaCorr[8]={0.};
294 for(int i=0;i<2;i++){
295 sprintf(brname,"t0offset%d",i);
296 sprintf(ptname,"t0offset%d/D",i);
297 t2->Branch(brname,&t0Offset[i],ptname);
298 }
299 for(int i=0;i<8;i++){
300 sprintf(brname,"sigmaCorr%d",i);
301 sprintf(ptname,"sigmaCorr%d/D",i);
302 t2->Branch(brname,&sigmaCorr[i],ptname);
303 }
304 try{
305 if(is_open[10]){
306 inf[10] >> sigmaCorr[0] >> sigmaCorr[1] >> t0Offset[0] >> t0Offset[1];
307 }
308 t2->Fill();
309 } catch(...) {
310 return false;
311 }
312
313 for(int m=0;m<N;m++) { inf[m].close(); }
314
315 TFile f("BarTofPar.root","RECREATE");
316 t1->Write();
317 t2->Write();
318 f.Close();
319 delete t1;
320 delete t2;
321 t1=NULL;
322 t2=NULL;
323
324 return true;
325}