BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCaliSvc/TofCaliSvc-00-01-19/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 131 of file TofCaliSvc/TofCaliSvc-00-01-19/test/convert2root.cxx.

131 {
132
133 TTree* t1 = new TTree( "BarTofPar","barrel parameters" );
134
135 double p[20]={1.};
136 char brname[20];
137 char ptname[20];
138 for(int i=0;i<20;i++){
139 sprintf( brname, "P%d", i );
140 sprintf( ptname, "p%d/D", i );
141 t1->Branch(brname,&p[i],ptname);
142 }
143
144 double bunch0_poff[40]={1.},bunch1_poff[40]={1.},bunch2_poff[40]={1.},bunch3_poff[40]={1.};
145 char broffname[40];
146 char ptoffname[40];
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 );
151 }
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 );
156 }
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 );
161 }
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 );
166 }
167
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 );
178 }
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 );
183 }
184
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);
190 }
191
192 double Speed[2]={1.};
193 t1->Branch( "Speed0", &Speed[0], "Speed0/D" );
194 t1->Branch( "Speed1", &Speed[1], "Speed1/D" );
195
196 const int N = 23;
197 ifstream inf[N];
198 bool is_open[N]={false};
199 const char* filelist[N]={
200 "calib_barrel_left.txt", // 0
201 "calib_barrel_right.txt", // 1
202 "calib_barrel_left_offset1_bunch0.txt", // 2
203 "calib_barrel_left_offset2_bunch0.txt", // 3
204 "calib_barrel_right_offset1_bunch0.txt", // 4
205 "calib_barrel_right_offset2_bunch0.txt", // 5
206 "calib_barrel_left_offset1_bunch1.txt", // 6
207 "calib_barrel_left_offset2_bunch1.txt", // 7
208 "calib_barrel_right_offset1_bunch1.txt", // 8
209 "calib_barrel_right_offset2_bunch1.txt", // 9
210 "calib_barrel_left_offset1_bunch2.txt", // 10
211 "calib_barrel_left_offset2_bunch2.txt", // 11
212 "calib_barrel_right_offset1_bunch2.txt", // 12
213 "calib_barrel_right_offset2_bunch2.txt", // 13
214 "calib_barrel_left_offset1_bunch3.txt", // 14
215 "calib_barrel_left_offset2_bunch3.txt", // 15
216 "calib_barrel_right_offset1_bunch3.txt", // 16
217 "calib_barrel_right_offset2_bunch3.txt", // 17
218 "calib_barrel_sigma.txt", // 18
219 "calib_barrel_atten.txt", // 19
220 "calib_barrel_q0.txt", // 20
221 "calib_barrel_veff.txt", // 21
222 "calib_barrel_common.txt" // 22
223 };
224 for(int m=0;m<N;m++){
225 inf[m].open(filelist[m],ios::in);
226 if(inf[m].good())
227 is_open[m]=true;
228 else
229 std::cerr<<"file: "<<filelist[m]<<" can't be found!"<<std::endl;
230 }
231
232 try{
233 for(int k=0;k<176;k++){
234 //------------set p-------------------------
235 if(is_open[0]&&is_open[1]){
236 for(int j=0;j<7;j++) {
237 inf[0]>>p[j];
238 inf[1]>>p[j+10];
239 }
240 }
241 //-------set offset of bunch0 correction pars -------
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];
248 }
249 }
250 //-------set offset of bunch1 correction pars -------
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];
257 }
258 }
259
260 //-------set offset of bunch2 correction pars -------
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];
267 }
268 }
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];
275 }
276 }
277 //--------fit sigma vs z parameters---------
278 if(is_open[18]){
279 for(int j=0; j<15; j++) {
280 inf[18] >> fitfun[j];
281 }
282 }
283 //-----------atten lenght-------------------
284 if(is_open[19]){
285 for(int j=0;j<2;j++){
286 inf[19]>>Atten[j];
287 }
288 Atten[0]=1./Atten[0];
289 }
290 //--------------Q0--------------------------
291 if(is_open[20]){
292 for(int j=2;j<5;j++){
293 inf[20] >> Atten[j];
294 }
295 }
296 //-------------speed------------------------
297 if(is_open[21]){
298 for(int j=0;j<2;j++){
299 inf[21]>>Speed[j];
300 }
301 Speed[0]=1./Speed[0];
302 }
303 t1->Fill();
304 }
305 }catch(...) {
306 return false;
307 }
308
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);
315 }
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);
320 }
321 try{
322 if(is_open[22]){
323 inf[22] >> sigmaCorr[0] >> sigmaCorr[1] >> t0Offset[0] >> t0Offset[1];
324 }
325 t2->Fill();
326 } catch(...) {
327 return false;
328 }
329
330 for(int m=0;m<N;m++) { inf[m].close(); }
331
332 TFile f("BarTofPar.root","RECREATE");
333 t1->Write();
334 t2->Write();
335 f.Close();
336 delete t1;
337 delete t2;
338 t1=NULL;
339 t2=NULL;
340
341 return true;
342}
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")

Referenced by main().

◆ calib_conv2root()

bool calib_conv2root ( )

Definition at line 14 of file TofCaliSvc/TofCaliSvc-00-01-19/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 if( version==1 ) {
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 else if( version==2 ) {
104 itofid[i] = itmp;
105 }
106 }
107 else {
108 std::cout << "impossible tofid!" << std::endl;
109 }
110 }
111 else {
112 itofid[i] = 0x2fffffff;
113 }
114 }
115 t0->Fill();
116 }
117 }catch(...) {
118 return false;
119 }
120
121 TFile f("CalibInfo.root","RECREATE");
122 t0->Write();
123 f.Close();
124 delete t0;
125 t0=NULL;
126
127 return true;
128}
char * file
Definition: DQA_TO_DB.cxx:15

Referenced by main().

◆ endcap_conv2root()

bool endcap_conv2root ( )

Definition at line 350 of file TofCaliSvc/TofCaliSvc-00-01-19/test/convert2root.cxx.

350 {
351
352 TTree* t = new TTree( "EndTofPar", "endcap parameters" );
353 char brname[8];
354 char ptname[8];
355 double p[8]={0.};
356 for(int i=0;i<8;i++){
357 sprintf( brname, "P%d", i );
358 sprintf( ptname, "p%d/D", i );
359 t->Branch( brname, &p[i], ptname );
360 }
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 );
369 }
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 );
375 }
376
377 try{
378 for(int k=0;k<96;k++){
379 t->Fill();
380 }
381 } catch(...){
382 return false;
383 }
384 //-------------------------------------------
385 TFile f("EndTofPar.root","RECREATE");
386 t->Write();
387 f.Close();
388 delete t;
389 t=NULL;
390
391 return true;
392}
TTree * t
Definition: binning.cxx:23

Referenced by main().

◆ etf_conv2root()

bool etf_conv2root ( )

Definition at line 395 of file TofCaliSvc/TofCaliSvc-00-01-19/test/convert2root.cxx.

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

Referenced by main().

◆ join()

bool join ( )

Definition at line 488 of file TofCaliSvc/TofCaliSvc-00-01-19/test/convert2root.cxx.

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

Referenced by main().

◆ main()