15 TTree* t0 =
new TTree(
"CalibInfo",
"run number and version number");
16 int run1=0, run2=0, version=0;
17 int qCorr=1, qElec=1, misLable=1;
19 char ebrname[5], wbrname[5], ecname[5];
20 char iebrname[5], iwbrname[5], iecname[5];
21 t0->Branch(
"Run1", &run1,
"Run1/I" );
22 t0->Branch(
"Run2", &run2,
"Run2/I" );
23 t0->Branch(
"Version", &version,
"Version/I" );
24 t0->Branch(
"qCorr", &qCorr,
"qCorr/I" );
25 t0->Branch(
"qElec", &qElec,
"qElec/I" );
26 t0->Branch(
"misLable",&misLable,
"misLable/I");
28 for(
unsigned int i=0; i<5; i++ ){
29 sprintf( ebrname,
"ebrId%d", i );
30 sprintf( iebrname,
"ebrId%d/I",i );
31 t0->Branch(ebrname,&itofid[i],iebrname);
32 sprintf( wbrname,
"wbrId%d", i );
33 sprintf( iwbrname,
"wbrId%d/I",i );
34 t0->Branch(wbrname,&itofid[i+5],iwbrname);
35 sprintf( ecname,
"ecId%d", i );
36 sprintf( iecname,
"ecId%d/I", i );
37 t0->Branch(ecname,&itofid[i+10],iecname);
41 unsigned int barrel, layer, tofid, end;
44 const char*
file=
"calib_info.txt";
45 inf.open(
file,ios::in);
50 std::cerr<<
"file: "<<
file <<
" can't be found!"<<std::endl;
54 inf >> run1 >> run2 >> version;
55 inf >> qCorr >> qElec >> misLable;
56 for(
unsigned int i=0; i<15; i++ ) {
59 tofid =
unsigned int( itmp );
64 else if( i>=5 && i<=9 ) {
68 if( itmp>=0 && itmp<=87 ) {
71 else if( itmp>=88 && itmp<=175 ) {
76 std::cout <<
"1 impossible tofid!" << std::endl;
78 itofid[i] = ( 0x20000000 | (barrel<<14) | (layer<<8) | (tofid<<1) | end );
80 else if( i>=10 && i<=14 ) {
85 if( itmp>=48 && itmp<=95 ) {
89 itofid[i] = ( 0x20000000 | (barrel<<14) | (layer<<8) | (tofid<<1) | end );
93 end =
unsigned int ( itmp/10000 );
94 tofid =
unsigned int ( (itmp - end*10000)/100 );
95 unsigned int strip =
unsigned int ( itmp%100 );
96 unsigned int endcap = 0;
97 if( tofid>=36 && tofid<=71 ) {
101 itofid[i] = ( 0x20000000 | (barrel<<14) | (endcap<<11) | (tofid<<5) | (strip<<1) | end );
105 std::cout <<
"impossible tofid!" << std::endl;
109 itofid[i] = 0x2fffffff;
118 TFile f(
"CalibInfo.root",
"RECREATE");
130 TTree* t1 =
new TTree(
"BarTofPar",
"barrel parameters" );
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);
141 double bunch0_poff[40]={1.},bunch1_poff[40]={1.},bunch2_poff[40]={1.},bunch3_poff[40]={1.};
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 );
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 );
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 );
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 );
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 );
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 );
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);
189 double Speed[2]={1.};
190 t1->Branch(
"Speed0", &Speed[0],
"Speed0/D" );
191 t1->Branch(
"Speed1", &Speed[1],
"Speed1/D" );
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"
221 for(
int m=0;m<N;m++){
222 inf[m].open(filelist[m],ios::in);
226 std::cerr<<
"file: "<<filelist[m]<<
" can't be found!"<<std::endl;
230 for(
int k=0;k<176;k++){
232 if(is_open[0]&&is_open[1]){
233 for(
int j=0;j<7;j++) {
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];
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];
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];
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];
276 for(
int j=0; j<15; j++) {
277 inf[18] >> fitfun[j];
282 for(
int j=0;j<2;j++){
285 Atten[0]=1./Atten[0];
289 for(
int j=2;j<5;j++){
295 for(
int j=0;j<2;j++){
298 Speed[0]=1./Speed[0];
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);
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);
320 inf[22] >> sigmaCorr[0] >> sigmaCorr[1] >> t0Offset[0] >> t0Offset[1];
327 for(
int m=0;m<N;m++) { inf[m].close(); }
329 TFile f(
"BarTofPar.root",
"RECREATE");
349 TTree*
t =
new TTree(
"EndTofPar",
"endcap parameters" );
353 for(
int i=0;i<8;i++){
354 sprintf( brname,
"P%d", i );
355 sprintf( ptname,
"p%d/D", i );
356 t->Branch( brname, &p[i], ptname );
358 double fcounter[5]={0.},Atten[5]={0.},Speed[4]={0.};
359 for(
int i=0;i<5;i++){
360 sprintf( brname,
"FCounter%d", i );
361 sprintf( ptname,
"fcounter%d/D", i );
362 t->Branch( brname, &fcounter[i], ptname );
363 sprintf( brname,
"Atten%d", i );
364 sprintf( ptname,
"Atten%d/D", i );
365 t->Branch( brname, &Atten[i], ptname );
367 double Speed[4]={0.};
368 for(
int i=0;i<4;i++){
369 sprintf( brname,
"Speed%d", i );
370 sprintf( ptname,
"Speed%d/D", i );
371 t->Branch( brname, &Speed[i], ptname );
375 for(
int k=0;k<96;k++){
382 TFile f(
"EndTofPar.root",
"RECREATE");
394 TTree*
t =
new TTree(
"EtfTofPar",
"etf parameters" );
395 TTree* t1 =
new TTree(
"EtfTofBunch",
"etf parameters" );
400 for(
int i=0;i<60;i++){
401 sprintf( brname,
"P%d", i );
402 sprintf( ptname,
"p%d/D", i );
403 t->Branch(brname,&p[i],ptname);
405 double Speed[4]={1.};
406 for(
int i=0;i<4;i++){
407 sprintf( brname,
"Speed%d", i );
408 sprintf( ptname,
"Speed%d/D", i );
409 t->Branch( brname, &Speed[i], ptname );
412 double pBunch[4]={1.};
413 for(
int i=0;i<4;i++){
414 sprintf( brname,
"pbunch%d", i );
415 sprintf( ptname,
"pbunch%d/D", i );
416 t1->Branch( brname, &pBunch[i], ptname );
421 bool is_open[K]={
false};
422 const char* filelist[K]={
423 "calib_etf_combine.txt",
424 "calib_etf_left.txt",
425 "calib_etf_right.txt",
426 "calib_etf_veff.txt",
427 "calib_etf_bunch.txt"
429 for(
int i=0;i<K;i++){
430 inf[i].open(filelist[i],ios::in);
434 std::cerr<<
"File: "<<filelist[i]<<
" can't be opened"<<std::endl;
438 for(
int i=0;i<72;i++) {
439 for(
int j=0;j<12;j++) {
441 if(is_open[0] && is_open[1] && is_open[2]){
442 for(
int k=0;k<7;k++) {
445 for(
int k=0;k<13;k++) {
452 for(
int k=0;k<4;k++){
461 for(
int k=0;k<4;k++){
462 inf[4]>>pBunch[k]>>tmp;
470 for(
int i=0;i<K;i++) { inf[i].close(); }
472 TFile f(
"EtfTofPar.root",
"RECREATE");
487 TFile f0(
"CalibInfo.root");
488 TTree* t0=(TTree*)f0.Get(
"CalibInfo");
489 TTree* tnew0 = t0->CloneTree();
490 if(0==tnew0) { std::cerr<<
" can't get tree :CalibInfo in file CalibInfo.root"<<std::endl;
return false;}
492 TFile f(
"EndTofPar.root");
493 TTree*
t=(TTree*)f.Get(
"EndTofPar");
494 TTree* tnew =
t->CloneTree();
495 if(0==tnew) { std::cerr<<
" can't get tree :EndTofPar in file EndTofPar.root"<<std::endl;
return false;}
497 TFile
f1(
"BarTofPar.root");
498 TTree* t1=(TTree*)
f1.Get(
"BarTofPar");
499 TTree* tnew1 = t1->CloneTree();
500 if(0==tnew1) { std::cerr<<
" can't get tree :BarTofPar in file BarTofPar.root"<<std::endl;
return false;}
501 TTree* t2=(TTree*)
f1.Get(
"BarTofParCommon");
502 TTree* tnew2 = t2->CloneTree();
503 if(0==tnew2) { std::cerr<<
" can't get tree :BarTofPar Common in file BarTofPar.root"<<std::endl;
return false;}
505 TFile f2(
"EtfTofPar.root");
506 TTree* t3=(TTree*)f2.Get(
"EtfTofPar");
507 TTree* tnew3 = t3->CloneTree();
508 TTree* t4=(TTree*)f2.Get(
"EtfTofBunch");
509 TTree* tnew4 = t4->CloneTree();
510 if(0==tnew4) { std::cerr<<
" can't get tree :EtfTofBunch in file EtfTofPar.root"<<std::endl;
return false;}
512 TFile fnew(
"TofCalConst.root",
"RECREATE");