BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCaliSvc/TofCaliSvc-00-01-13/test/convert2root.cxx File Reference
#include "TTree.h"
#include "TFile.h"
#include <assert.h>
#include <iostream>
#include <fstream>

Go to the source code of this file.

Functions

bool calib_conv2root ()
 
bool barrel_conv2root ()
 
bool endcap_conv2root ()
 
bool etf_conv2root ()
 
bool join ()
 
int main ()
 

Function Documentation

◆ barrel_conv2root()

bool barrel_conv2root ( )

Definition at line 128 of file TofCaliSvc/TofCaliSvc-00-01-13/test/convert2root.cxx.

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;
194 ifstream inf[N];
195 bool is_open[N]={false};
196 const char* filelist[N]={
197 "calib_barrel_left.txt", // 0
198 "calib_barrel_right.txt", // 1
199 "calib_barrel_left_offset1_bunch0.txt", // 2
200 "calib_barrel_left_offset2_bunch0.txt", // 3
201 "calib_barrel_right_offset1_bunch0.txt", // 4
202 "calib_barrel_right_offset2_bunch0.txt", // 5
203 "calib_barrel_left_offset1_bunch1.txt", // 6
204 "calib_barrel_left_offset2_bunch1.txt", // 7
205 "calib_barrel_right_offset1_bunch1.txt", // 8
206 "calib_barrel_right_offset2_bunch1.txt", // 9
207 "calib_barrel_left_offset1_bunch2.txt", // 10
208 "calib_barrel_left_offset2_bunch2.txt", // 11
209 "calib_barrel_right_offset1_bunch2.txt", // 12
210 "calib_barrel_right_offset2_bunch2.txt", // 13
211 "calib_barrel_left_offset1_bunch3.txt", // 14
212 "calib_barrel_left_offset2_bunch3.txt", // 15
213 "calib_barrel_right_offset1_bunch3.txt", // 16
214 "calib_barrel_right_offset2_bunch3.txt", // 17
215 "calib_barrel_sigma.txt", // 18
216 "calib_barrel_atten.txt", // 19
217 "calib_barrel_q0.txt", // 20
218 "calib_barrel_veff.txt", // 21
219 "calib_barrel_common.txt" // 22
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 //------------set p-------------------------
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 //-------set offset of bunch0 correction pars -------
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 //-------set offset of bunch1 correction pars -------
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 //-------set offset of bunch2 correction pars -------
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 //--------fit sigma vs z parameters---------
275 if(is_open[18]){
276 for(int j=0; j<15; j++) {
277 inf[18] >> fitfun[j];
278 }
279 }
280 //-----------atten lenght-------------------
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 //--------------Q0--------------------------
288 if(is_open[20]){
289 for(int j=2;j<5;j++){
290 inf[20] >> Atten[j];
291 }
292 }
293 //-------------speed------------------------
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}

Referenced by main().

◆ calib_conv2root()

bool calib_conv2root ( )

Definition at line 14 of file TofCaliSvc/TofCaliSvc-00-01-13/test/convert2root.cxx.

14 {
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;
18 int itofid[15]={0};
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");
27
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);
38 }
39
40 int itmp;
41 unsigned int barrel, layer, tofid, end;
42 ifstream inf;
43 bool is_open=false;
44 const char* file="calib_info.txt";
45 inf.open(file,ios::in);
46 if( inf.good() ) {
47 is_open=true;
48 }
49 else {
50 std::cerr<<"file: "<<file <<" can't be found!"<<std::endl;
51 }
52 try{
53 if( is_open ){
54 inf >> run1 >> run2 >> version;
55 inf >> qCorr >> qElec >> misLable;
56 for( unsigned int i=0; i<15; i++ ) {
57 inf >> itmp;
58 if( itmp != -1 ) {
59 tofid = unsigned int( itmp );
60 if( i>=0 && i<=9 ) {
61 if( i>=0 && i<=4 ) {
62 end = 0;
63 }
64 else if( i>=5 && i<=9 ) {
65 end = 1;
66 }
67 barrel = 1;
68 if( itmp>=0 && itmp<=87 ) {
69 layer = 0;
70 }
71 else if( itmp>=88 && itmp<=175 ) {
72 tofid = tofid - 88;
73 layer = 1;
74 }
75 else {
76 std::cout << "1 impossible tofid!" << std::endl;
77 }
78 itofid[i] = ( 0x20000000 | (barrel<<14) | (layer<<8) | (tofid<<1) | end );
79 }
80 else if( i>=10 && i<=14 ) {
81 if( version==0 ) {
82 barrel = 0;
83 layer = 0;
84 end = 0;
85 if( itmp>=48 && itmp<=95 ) {
86 barrel = 2;
87 tofid = tofid - 48;
88 }
89 itofid[i] = ( 0x20000000 | (barrel<<14) | (layer<<8) | (tofid<<1) | end );
90 }
91 else {
92 barrel = 3;
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 ) {
98 endcap = 1;
99 tofid = tofid - 35;
100 }
101 itofid[i] = ( 0x20000000 | (barrel<<14) | (endcap<<11) | (tofid<<5) | (strip<<1) | end );
102 }
103 }
104 else {
105 std::cout << "impossible tofid!" << std::endl;
106 }
107 }
108 else {
109 itofid[i] = 0x2fffffff;
110 }
111 }
112 t0->Fill();
113 }
114 }catch(...) {
115 return false;
116 }
117
118 TFile f("CalibInfo.root","RECREATE");
119 t0->Write();
120 f.Close();
121 delete t0;
122 t0=NULL;
123
124 return true;
125}
char * file
Definition: DQA_TO_DB.cxx:15

Referenced by main().

◆ endcap_conv2root()

bool endcap_conv2root ( )

Definition at line 347 of file TofCaliSvc/TofCaliSvc-00-01-13/test/convert2root.cxx.

347 {
348
349 TTree* t = new TTree( "EndTofPar", "endcap parameters" );
350 char brname[8];
351 char ptname[8];
352 double p[8]={0.};
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 );
357 }
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 );
366 }
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 );
372 }
373
374 try{
375 for(int k=0;k<96;k++){
376 t->Fill();
377 }
378 } catch(...){
379 return false;
380 }
381 //-------------------------------------------
382 TFile f("EndTofPar.root","RECREATE");
383 t->Write();
384 f.Close();
385 delete t;
386 t=NULL;
387
388 return true;
389}
int t()
Definition: t.c:1

Referenced by main().

◆ etf_conv2root()

bool etf_conv2root ( )

Definition at line 392 of file TofCaliSvc/TofCaliSvc-00-01-13/test/convert2root.cxx.

392 {
393
394 TTree* t = new TTree( "EtfTofPar","etf parameters" );
395 TTree* t1 = new TTree( "EtfTofBunch","etf parameters" );
396
397 char brname[60];
398 char ptname[60];
399 double p[60]={1.};
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);
404 }
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 );
410 }
411 double tmp;
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 );
417 }
418
419 const int K=5;
420 ifstream inf[K];
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"
428 };
429 for(int i=0;i<K;i++){
430 inf[i].open(filelist[i],ios::in);
431 if(inf[i].good())
432 is_open[i]=true;
433 else{
434 std::cerr<<"File: "<<filelist[i]<<" can't be opened"<<std::endl;
435 }
436 }
437 try{
438 for(int i=0;i<72;i++) {
439 for(int j=0;j<12;j++) {
440 //------------set p-------------------------
441 if(is_open[0] && is_open[1] && is_open[2]){
442 for(int k=0;k<7;k++) {
443 inf[0]>>p[k];
444 }
445 for(int k=0;k<13;k++) {
446 inf[1]>>p[k+20];
447 inf[2]>>p[k+40];
448 }
449 }
450 //-------------speed------------------------
451 if(is_open[3]){
452 for(int k=0;k<4;k++){
453 inf[3]>>Speed[k];
454 }
455 }
456 t->Fill();
457 }
458 }
459 //-------------bunch------------------------
460 if(is_open[4]){
461 for(int k=0;k<4;k++){
462 inf[4]>>pBunch[k]>>tmp;
463 }
464 }
465 t1->Fill();
466 }catch(...) {
467 return false;
468 }
469
470 for(int i=0;i<K;i++) { inf[i].close(); }
471
472 TFile f("EtfTofPar.root","RECREATE");
473 t->Write();
474 t1->Write();
475 f.Close();
476 delete t;
477 delete t1;
478 t=NULL;
479 t1=NULL;
480
481 return true;
482}

Referenced by main().

◆ join()

bool join ( )

Definition at line 485 of file TofCaliSvc/TofCaliSvc-00-01-13/test/convert2root.cxx.

485 {
486
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;}
491
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;}
496
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;}
504
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;}
511
512 TFile fnew("TofCalConst.root","RECREATE");
513 tnew0->Write();
514 tnew->Write();
515 tnew1->Write();
516 tnew2->Write();
517 tnew3->Write();
518 tnew4->Write();
519 f0.Close();
520 f.Close();
521 f1.Close();
522 f2.Close();
523 fnew.Close();
524
525 t0=NULL;
526 t=NULL;
527 t1=NULL;
528 t2=NULL;
529 t3=NULL;
530 t4=NULL;
531 tnew0=NULL;
532 tnew=NULL;
533 tnew1=NULL;
534 tnew2=NULL;
535 tnew3=NULL;
536 tnew4=NULL;
537
538 return true;
539}
TFile * f1

Referenced by main().

◆ main()