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);
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 );
91 else if( version==1 ) {
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 );
103 else if( version==2 ) {
108 std::cout <<
"impossible tofid!" << std::endl;
112 itofid[i] = 0x2fffffff;
121 TFile
f(
"CalibInfo.root",
"RECREATE");
133 TTree* t1 =
new TTree(
"BarTofPar",
"barrel parameters" );
138 for(
int i=0;i<20;i++){
141 t1->Branch(brname,&p[i],ptname);
144 double bunch0_poff[40]={1.},bunch1_poff[40]={1.},bunch2_poff[40]={1.},bunch3_poff[40]={1.};
147 for(
int i=0;i<40;i++){
148 sprintf( broffname,
"Bunch0_Poff%d", i );
149 sprintf( ptoffname,
"bunch0_poff%d/D", i );
150 t1->Branch( broffname, &bunch0_poff[i], ptoffname );
152 for(
int i=0;i<40;i++){
153 sprintf( broffname,
"Bunch1_Poff%d", i );
154 sprintf( ptoffname,
"bunch1_poff%d/D", i );
155 t1->Branch( broffname, &bunch1_poff[i], ptoffname );
157 for(
int i=0;i<40;i++){
158 sprintf( broffname,
"Bunch2_Poff%d", i );
159 sprintf( ptoffname,
"bunch2_poff%d/D", i );
160 t1->Branch( broffname, &bunch2_poff[i], ptoffname );
162 for(
int i=0;i<40;i++){
163 sprintf( broffname,
"Bunch3_Poff%d", i );
164 sprintf( ptoffname,
"bunch3_poff%d/D", i );
165 t1->Branch( broffname, &bunch3_poff[i], ptoffname );
168 double fitfun[20]={0.};;
169 char fbrname1[5], fptname1[5], fbrname2[5], fptname2[5];
170 char fbrname3[10], fptname3[10];
171 for(
int i=0;i<5;i++){
172 sprintf( fbrname1,
"FLeft%d", i );
173 sprintf( fptname1,
"fleft%d/D", i );
174 t1->Branch( fbrname1, &fitfun[i], fptname1 );
175 sprintf( fbrname2,
"FRight%d", i );
176 sprintf( fptname2,
"fright%d/D", i );
177 t1->Branch( fbrname2, &fitfun[5+i], fptname2 );
179 for(
int i=0;i<10;i++){
180 sprintf( fbrname3,
"FCounter%d", i );
181 sprintf( fptname3,
"fcounter%d/D", i );
182 t1->Branch( fbrname3, &fitfun[10+i], fptname3 );
185 double Atten[8]={1.};
186 for(
int i=0;i<8;i++){
187 sprintf( brname,
"Atten%d", i );
188 sprintf( ptname,
"Atten%d/D", i );
189 t1->Branch(brname, &Atten[i], ptname);
192 double Speed[2]={1.};
193 t1->Branch(
"Speed0", &Speed[0],
"Speed0/D" );
194 t1->Branch(
"Speed1", &Speed[1],
"Speed1/D" );
198 bool is_open[N]={
false};
199 const char* filelist[N]={
200 "calib_barrel_left.txt",
201 "calib_barrel_right.txt",
202 "calib_barrel_left_offset1_bunch0.txt",
203 "calib_barrel_left_offset2_bunch0.txt",
204 "calib_barrel_right_offset1_bunch0.txt",
205 "calib_barrel_right_offset2_bunch0.txt",
206 "calib_barrel_left_offset1_bunch1.txt",
207 "calib_barrel_left_offset2_bunch1.txt",
208 "calib_barrel_right_offset1_bunch1.txt",
209 "calib_barrel_right_offset2_bunch1.txt",
210 "calib_barrel_left_offset1_bunch2.txt",
211 "calib_barrel_left_offset2_bunch2.txt",
212 "calib_barrel_right_offset1_bunch2.txt",
213 "calib_barrel_right_offset2_bunch2.txt",
214 "calib_barrel_left_offset1_bunch3.txt",
215 "calib_barrel_left_offset2_bunch3.txt",
216 "calib_barrel_right_offset1_bunch3.txt",
217 "calib_barrel_right_offset2_bunch3.txt",
218 "calib_barrel_sigma.txt",
219 "calib_barrel_atten.txt",
220 "calib_barrel_q0.txt",
221 "calib_barrel_veff.txt",
222 "calib_barrel_common.txt"
224 for(
int m=0;m<N;m++){
225 inf[m].open(filelist[m],ios::in);
229 std::cerr<<
"file: "<<filelist[m]<<
" can't be found!"<<std::endl;
233 for(
int k=0;k<176;k++){
235 if(is_open[0]&&is_open[1]){
236 for(
int j=0;j<7;j++) {
242 if(is_open[2]&&is_open[3]&&is_open[4]&&is_open[5]){
243 for(
int j=0;j<7;j++) {
244 inf[2]>>bunch0_poff[j];
245 inf[3]>>bunch0_poff[j+10];
246 inf[4]>>bunch0_poff[j+20];
247 inf[5]>>bunch0_poff[j+30];
251 if(is_open[6]&&is_open[7]&&is_open[8]&&is_open[9]){
252 for(
int j=0;j<7;j++) {
253 inf[6]>>bunch1_poff[j];
254 inf[7]>>bunch1_poff[j+10];
255 inf[8]>>bunch1_poff[j+20];
256 inf[9]>>bunch1_poff[j+30];
261 if(is_open[10]&&is_open[11]&&is_open[12]&&is_open[13]){
262 for(
int j=0;j<7;j++) {
263 inf[10]>>bunch2_poff[j];
264 inf[11]>>bunch2_poff[j+10];
265 inf[12]>>bunch2_poff[j+20];
266 inf[13]>>bunch2_poff[j+30];
269 if(is_open[14]&&is_open[15]&&is_open[16]&&is_open[17]){
270 for(
int j=0;j<7;j++) {
271 inf[14]>>bunch3_poff[j];
272 inf[15]>>bunch3_poff[j+10];
273 inf[16]>>bunch3_poff[j+20];
274 inf[17]>>bunch3_poff[j+30];
279 for(
int j=0; j<15; j++) {
280 inf[18] >> fitfun[j];
285 for(
int j=0;j<2;j++){
288 Atten[0]=1./Atten[0];
292 for(
int j=2;j<5;j++){
298 for(
int j=0;j<2;j++){
301 Speed[0]=1./Speed[0];
309 TTree* t2 =
new TTree(
"BarTofParCommon",
"common part of barrel" );
310 double t0Offset[2]={0.},sigmaCorr[8]={0.};
311 for(
int i=0;i<2;i++){
312 sprintf(brname,
"t0offset%d",i);
313 sprintf(ptname,
"t0offset%d/D",i);
314 t2->Branch(brname,&t0Offset[i],ptname);
316 for(
int i=0;i<8;i++){
317 sprintf(brname,
"sigmaCorr%d",i);
318 sprintf(ptname,
"sigmaCorr%d/D",i);
319 t2->Branch(brname,&sigmaCorr[i],ptname);
323 inf[22] >> sigmaCorr[0] >> sigmaCorr[1] >> t0Offset[0] >> t0Offset[1];
330 for(
int m=0;m<N;m++) { inf[m].close(); }
332 TFile
f(
"BarTofPar.root",
"RECREATE");
352 TTree*
t =
new TTree(
"EndTofPar",
"endcap parameters" );
356 for(
int i=0;i<8;i++){
359 t->Branch( brname, &p[i], ptname );
361 double fcounter[5]={0.},Atten[5]={0.},Speed[4]={0.};
362 for(
int i=0;i<5;i++){
363 sprintf( brname,
"FCounter%d", i );
364 sprintf( ptname,
"fcounter%d/D", i );
365 t->Branch( brname, &fcounter[i], ptname );
366 sprintf( brname,
"Atten%d", i );
367 sprintf( ptname,
"Atten%d/D", i );
368 t->Branch( brname, &Atten[i], ptname );
370 double Speed[4]={0.};
371 for(
int i=0;i<4;i++){
372 sprintf( brname,
"Speed%d", i );
373 sprintf( ptname,
"Speed%d/D", i );
374 t->Branch( brname, &Speed[i], ptname );
378 for(
int k=0;k<96;k++){
385 TFile
f(
"EndTofPar.root",
"RECREATE");
397 TTree*
t =
new TTree(
"EtfTofPar",
"etf parameters" );
398 TTree* t1 =
new TTree(
"EtfTofBunch",
"etf parameters" );
403 for(
int i=0;i<60;i++){
406 t->Branch(brname,&p[i],ptname);
408 double Speed[4]={1.};
409 for(
int i=0;i<4;i++){
410 sprintf( brname,
"Speed%d", i );
411 sprintf( ptname,
"Speed%d/D", i );
412 t->Branch( brname, &Speed[i], ptname );
415 double pBunch[4]={1.};
416 for(
int i=0;i<4;i++){
417 sprintf( brname,
"pbunch%d", i );
418 sprintf( ptname,
"pbunch%d/D", i );
419 t1->Branch( brname, &pBunch[i], ptname );
424 bool is_open[K]={
false};
425 const char* filelist[K]={
426 "calib_etf_combine.txt",
427 "calib_etf_left.txt",
428 "calib_etf_right.txt",
429 "calib_etf_veff.txt",
430 "calib_etf_bunch.txt"
432 for(
int i=0;i<K;i++){
433 inf[i].open(filelist[i],ios::in);
437 std::cerr<<
"File: "<<filelist[i]<<
" can't be opened"<<std::endl;
441 for(
int i=0;i<72;i++) {
442 for(
int j=0;j<12;j++) {
444 if(is_open[0] && is_open[1] && is_open[2]){
445 for(
int k=0;k<7;k++) {
448 for(
int k=0;k<13;k++) {
455 for(
int k=0;k<4;k++){
464 for(
int k=0;k<4;k++){
465 inf[4]>>pBunch[k]>>tmp;
473 for(
int i=0;i<K;i++) { inf[i].close(); }
475 TFile
f(
"EtfTofPar.root",
"RECREATE");
490 TFile f0(
"CalibInfo.root");
491 TTree* t0=(TTree*)f0.Get(
"CalibInfo");
492 TTree* tnew0 = t0->CloneTree();
493 if(0==tnew0) { std::cerr<<
" can't get tree :CalibInfo in file CalibInfo.root"<<std::endl;
return false;}
495 TFile
f(
"EndTofPar.root");
496 TTree*
t=(TTree*)
f.Get(
"EndTofPar");
497 TTree* tnew =
t->CloneTree();
498 if(0==tnew) { std::cerr<<
" can't get tree :EndTofPar in file EndTofPar.root"<<std::endl;
return false;}
500 TFile
f1(
"BarTofPar.root");
501 TTree* t1=(TTree*)
f1.Get(
"BarTofPar");
502 TTree* tnew1 = t1->CloneTree();
503 if(0==tnew1) { std::cerr<<
" can't get tree :BarTofPar in file BarTofPar.root"<<std::endl;
return false;}
504 TTree* t2=(TTree*)
f1.Get(
"BarTofParCommon");
505 TTree* tnew2 = t2->CloneTree();
506 if(0==tnew2) { std::cerr<<
" can't get tree :BarTofPar Common in file BarTofPar.root"<<std::endl;
return false;}
508 TFile f2(
"EtfTofPar.root");
509 TTree* t3=(TTree*)f2.Get(
"EtfTofPar");
510 TTree* tnew3 = t3->CloneTree();
511 TTree* t4=(TTree*)f2.Get(
"EtfTofBunch");
512 TTree* tnew4 = t4->CloneTree();
513 if(0==tnew4) { std::cerr<<
" can't get tree :EtfTofBunch in file EtfTofPar.root"<<std::endl;
return false;}
515 TFile fnew(
"TofCalConst.root",
"RECREATE");