CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
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 join ()
 
int main ()
 

Function Documentation

◆ barrel_conv2root()

bool barrel_conv2root ( )

Definition at line 114 of file TofCaliSvc/TofCaliSvc-00-01-05/test/convert2root.cxx.

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

Referenced by main().

◆ calib_conv2root()

bool calib_conv2root ( )

Definition at line 14 of file TofCaliSvc/TofCaliSvc-00-01-05/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 barrel = 0;
82 layer = 0;
83 end = 0;
84 if( itmp>=48 && itmp<=95 ) {
85 barrel = 2;
86 tofid = tofid - 48;
87 }
88 itofid[i] = ( 0x20000000 | (barrel<<14) | (layer<<8) | (tofid<<1) | end );
89 }
90 else {
91 std::cout << "impossible tofid!" << std::endl;
92 }
93 }
94 else {
95 itofid[i] = 0x2fffffff;
96 }
97 }
98 t0->Fill();
99 }
100 }catch(...) {
101 return false;
102 }
103
104 TFile f("CalibInfo.root","RECREATE");
105 t0->Write();
106 f.Close();
107 delete t0;
108 t0=NULL;
109
110 return true;
111}

Referenced by main().

◆ endcap_conv2root()

bool endcap_conv2root ( )

Definition at line 333 of file TofCaliSvc/TofCaliSvc-00-01-05/test/convert2root.cxx.

333 {
334
335 TTree* t = new TTree( "EndTofPar", "endcap parameters" );
336 double p[8]={0.};;
337 char brname[8];
338 char ptname[8];
339 for(int i=0;i<8;i++){
340 sprintf( brname, "P%d", i );
341 sprintf( ptname, "p%d/D", i );
342 t->Branch( brname, &p[i], ptname );
343 }
344 double fcounter[5]={0.},Atten[5]={0.},Speed[4]={0.};
345 for(int i=0;i<5;i++){
346 sprintf( brname, "FCounter%d", i );
347 sprintf( ptname, "fcounter%d/D", i );
348 t->Branch( brname, &fcounter[i], ptname );
349 sprintf( brname, "Atten%d", i );
350 sprintf( ptname, "Atten%d/D", i );
351 t->Branch( brname, &Atten[i], ptname );
352 }
353 for(int i=0;i<4;i++){
354 sprintf( brname, "Speed%d", i );
355 sprintf( ptname, "Speed%d/D", i );
356 t->Branch( brname, &Speed[i], ptname );
357 }
358
359 const int N=4;
360 ifstream inf[N];
361 bool is_open[N]={false};
362 const char* filelist[N]={
363 "calib_endcap_left.txt",
364 "calib_endcap_sigma.txt",
365 "calib_endcap_atten.txt",
366 "calib_endcap_veff.txt"
367 };
368 for(int m=0;m<N;m++){
369 inf[m].open(filelist[m],ios::in);
370 if(inf[m].good())
371 is_open[m]=true;
372 else{
373 std::cerr<<"File: "<<filelist[m]<<" can't be opened"<<std::endl;
374 }
375 }
376 try{
377 for(int k=0;k<96;k++){
378 //------------set p-------------------------
379 if(is_open[0]&&is_open[1]){
380 for(int j=0;j<7;j++){
381 inf[0]>>p[j];
382 }
383 }
384 //-----------sigma correction---------------
385 if(is_open[1]){
386 for(int j=0;j<3;j++){
387 inf[1]>>fcounter[j];
388 }
389 }
390 //-----------atten lenght------------------
391 if(is_open[2]){
392 for(int j=0;j<5;j++){
393 inf[2]>>Atten[j];
394 }
395 }
396 //-------------speed-----------------------
397 if(is_open[3]){
398 for(int j=0;j<4;j++){
399 inf[3]>>Speed[j];
400 }
401 }
402 t->Fill();
403 }
404 } catch(...){
405 return false;
406 }
407 for(int m=0;m<N;m++)
408 inf[m].close();
409 //-------------------------------------------
410 TFile f("EndTofPar.root","RECREATE");
411 t->Write();
412 f.Close();
413 delete t;
414 t=NULL;
415
416 return true;
417}
int t()
Definition t.c:1

Referenced by main().

◆ join()

bool join ( )

Definition at line 420 of file TofCaliSvc/TofCaliSvc-00-01-05/test/convert2root.cxx.

420 {
421
422 TFile f0("CalibInfo.root");
423 TTree* t0=(TTree*)f0.Get("CalibInfo");
424 TTree* tnew0 = t0->CloneTree();
425 if(0==tnew0) { std::cerr<<" can't get tree :CalibInfo in file CalibInfo.root"<<std::endl; return false;}
426
427 TFile f("EndTofPar.root");
428 TTree* t=(TTree*)f.Get("EndTofPar");
429 TTree* tnew = t->CloneTree();
430 if(0==tnew) { std::cerr<<" can't get tree :EndTofPar in file EndTofPar.root"<<std::endl; return false;}
431
432 TFile f1("BarTofPar.root");
433 TTree* t1=(TTree*)f1.Get("BarTofPar");
434 TTree* tnew1 = t1->CloneTree();
435 if(0==tnew1) { std::cerr<<" can't get tree :BarTofPar in file BarTofPar.root"<<std::endl; return false;}
436 TTree* t2=(TTree*)f1.Get("BarTofParCommon");
437 TTree* tnew2 = t2->CloneTree();
438 if(0==tnew2) { std::cerr<<" can't get tree :BarTofPar Common in file BarTofPar.root"<<std::endl; return false;}
439
440 TFile fnew("TofCalConst.root","RECREATE");
441 tnew0->Write();
442 tnew->Write();
443 tnew1->Write();
444 tnew2->Write();
445 f0.Close();
446 f.Close();
447 f1.Close();
448 fnew.Close();
449 t0=NULL;
450 t=NULL;
451 t1=NULL;
452 t2=NULL;
453 tnew0=NULL;
454 tnew=NULL;
455 tnew1=NULL;
456 tnew2=NULL;
457
458 return true;
459}
TFile * f1

Referenced by main().

◆ main()