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