CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
EstTofCaliSvc/EstTofCaliSvc-00-00-08/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 barrel_con2root ()
 
bool endcap_con2root ()
 
bool join ()
 
int main ()
 

Function Documentation

◆ barrel_con2root()

bool barrel_con2root ( )

Definition at line 12 of file EstTofCaliSvc/EstTofCaliSvc-00-00-08/test/convert2root.cxx.

12 {
13 //this method so bothered
14
15 TTree* t0=new TTree("EsTimeOffset","EsTimeOffset");
16 double offset[2]={0.};;
17 char estbrname[20];
18 char estptname[20];
19 for(int i = 0; i<2; i++){
20 sprintf(estbrname, "Offset%d",i);
21 sprintf(estptname, "Offset%d/D",i);
22 t0->Branch(estbrname, &offset[i], estptname);
23 }
24
25 ifstream inf0;
26 ifstream inf01;
27 inf0.open("calib_EsTimeOffset.txt",ios::in);
28 inf01.open("EsTimeOffset.txt", ios::in);
29 if(inf0.good() && inf01.good()) {
30 try{
31 inf0 >> offset[0] ;
32 inf01 >> offset[1] ;
33 t0->Fill();
34 }catch(...) {
35 return false;
36 }
37 }
38 else {
39 std::cerr<<"file: calib_estimeOffset.txt or est_estimeOffset can't be found!"<<std::endl;
40 }
41 inf0.close();
42 inf01.close();
43
44 TTree* t=new TTree("BarTofPar","barrel parameters");
45 //create a full tree;
46 double p[20]={0.};;
47 char brname[20];//branch name
48 char ptname[20];//pattern name
49 for(int i=0;i<20;i++){
50 sprintf(brname,"P%d",i);
51 sprintf(ptname,"p%d/D",i);
52 t->Branch(brname,&p[i],ptname);
53 }
54 double w[4];
55 for(int i=0;i<4;i++){
56 sprintf(brname,"W%d",i);
57 sprintf(ptname,"w%d/D",i);
58 t->Branch(brname,&w[i],ptname);
59 }
60 double Atten[8]={0.};
61 for(int i=0;i<8;i++){
62 sprintf(brname, "Atten%d",i);
63 sprintf(ptname, "Atten%d/D",i);
64 t->Branch(brname, &Atten[i], ptname);
65 }
66 double Speed[2]={0.},Q0[1]={0.};
67 t->Branch("Speed0",&Speed[0],"Speed0/D");
68 t->Branch("Speed1",&Speed[1],"Speed1/D");
69 t->Branch("Q0",Q0,"Q0[1]/D");
70 double fitfun[20]={0.};;
71 char fbrname1[5];//branch name
72 char fptname1[5];//pattern name
73 char fbrname2[5];//branch name
74 char fptname2[5];//pattern name
75 char fbrname3[10];//branch name
76 char fptname3[10];//pattern name
77 for(int i=0;i<5;i++){
78 sprintf(fbrname1,"FLeft%d",i);
79 sprintf(fptname1,"fleft%d/D",i);
80 t->Branch(fbrname1,&fitfun[i],fptname1);
81 sprintf(fbrname2,"FRight%d",i);
82 sprintf(fptname2,"fright%d/D",i);
83 t->Branch(fbrname2,&fitfun[5+i],fptname2);
84 }
85 for(int i=0;i<10;i++){
86 sprintf(fbrname3,"FCounter%d",i);
87 sprintf(fptname3,"fcounter%d/D",i);
88 t->Branch(fbrname3,&fitfun[10+i],fptname3);
89 }
90 const int N=10;
91 ifstream inf[N];
92 bool is_open[N]={false};
93 const char* filelist[N]={"calib_barrel_left.txt","calib_barrel_right.txt","calib_barrel_w.txt","calib_barrel_atten.txt","calib_barrel_veff.txt","calib_barrel_sigma.txt","calib_barrel_left1.txt","calib_barrel_right1.txt","calib_barrel_common.txt","calib_barrel_q0.txt"};
94 for(int m=0;m<N;m++){
95 inf[m].open(filelist[m],ios::in);
96 if(inf[m].good())
97 is_open[m]=true;
98 else
99 std::cerr<<"file: "<<filelist[N]<<" can't be found!"<<std::endl;
100 }
101 try{
102 for(int k=0;k<176;k++){
103 //------------set p-------------------------
104 if(is_open[0]&&is_open[1]){
105 for(int j=0;j<7;j++){
106 inf[0]>>p[j];
107 // cout<<p[j]<<' ';
108 }
109 for(int l=10;l<17;l++)
110 inf[1]>>p[l];
111 }
112 //--------------w pars---------------------
113 if(is_open[2]){
114 for(int j=0;j<4;j++)
115 inf[2]>>w[j];
116 }
117 //-----------atten lenght------------------
118 if(is_open[3]){
119 for(int j=0;j<2;j++){
120 inf[3]>>Atten[j];
121 }
122 Atten[0]=1./Atten[0];
123 }
124 //-------------speed-----------------------
125 if(is_open[4]){
126 for(int j=0;j<2;j++){
127 inf[4]>>Speed[j];
128 }
129 Speed[0]=1./Speed[0];
130 }
131 if(is_open[5]){
132 for(int j=0; j<4; j++) {
133 inf[5] >> fitfun[j];
134 }
135 for(int j=5; j<9; j++) {
136 inf[5] >> fitfun[j];
137 }
138 for(int j=10; j<13; j++) {
139 inf[5] >> fitfun[j];
140 }
141 }
142 //--------------Q0-----------------
143 if(is_open[9]){
144 for(int j=2;j<5;j++){
145 inf[9] >> Atten[j];
146 }
147 }
148 //-------------Q0----------------------------
149 // for(int j=0;j<1;j++)
150 // inf[5]>>Q0[j];
151 //-------------fill-----------------------
152 t->Fill();
153 }
154 }catch(...) {
155 return false;
156 }
157
158 TTree* t1=new TTree("BarTofParInner","barrel inner layer parameters");
159 //create a full tree;
160 double p1[20]={0.};;
161 char brname1[20];//branch name
162 char ptname1[20];//pattern name
163 for(int i=0;i<20;i++){
164 sprintf(brname1,"P%d",i);
165 sprintf(ptname1,"p%d/D",i);
166 t1->Branch(brname1,&p1[i],ptname1);
167 }
168 try{
169 for(int k=0;k<88;k++){
170 //------------set p-------------------------
171 if(is_open[6]&&is_open[7]){
172 for(int j=0;j<7;j++){
173 inf[6]>>p1[j];
174 // cout<<p[j]<<' ';
175 }
176 for(int l=10;l<17;l++)
177 inf[7]>>p1[l];
178 }
179 t1->Fill();
180 }
181 } catch(...) {
182 return false;
183 }
184
185 TTree* t2=new TTree("BarTofParCommon","common part of barrel");
186 double t0Offset[2]={0.},sigmaCorr[8]={0.};
187 for(int i=0;i<2;i++){
188 sprintf(brname,"t0offset%d",i);
189 sprintf(ptname,"t0offset%d/D",i);
190 t2->Branch(brname,&t0Offset[i],ptname);
191 }
192 for(int i=0;i<8;i++){
193 sprintf(brname,"sigmaCorr%d",i);
194 sprintf(ptname,"sigmaCorr%d/D",i);
195 t2->Branch(brname,&sigmaCorr[i],ptname);
196 }
197 try{
198 if(is_open[8]){
199 inf[8] >> sigmaCorr[0] >> sigmaCorr[1] >> t0Offset[0] >> t0Offset[1];
200 }
201 t2->Fill();
202 } catch(...) {
203 return false;
204 }
205 for(int m=0;m<N;m++)
206 inf[m].close();
207 //-------------------------------------------
208 TFile f("BarTofPar.root","RECREATE");
209 t0->Write();
210 t->Write();
211 t1->Write();
212 t2->Write();
213 f.Close();
214 delete t0;
215 delete t;
216 delete t1;
217 delete t2;
218 t0=NULL;
219 t=NULL;
220 t1=NULL;
221 t2=NULL;
222 return true;
223}
std::ifstream ifstream
Definition: bpkt_streams.h:44
int t()
Definition: t.c:1

Referenced by main().

◆ endcap_con2root()

bool endcap_con2root ( )

Definition at line 229 of file EstTofCaliSvc/EstTofCaliSvc-00-00-08/test/convert2root.cxx.

229 {
230 //this method so bothered
231
232 TTree* t0=new TTree("EsTimeOffset","EsTimeOffset");
233 double offset[2]={0.};
234 char estbrname[20];
235 char estptname[20];
236 for(int i = 0; i<2; i++){
237 sprintf(estbrname, "Offset%d",i);
238 sprintf(estptname, "Offset%d/D",i);
239 t0->Branch(estbrname, &offset[i], estptname);
240 }
241
242 ifstream inf0;
243 ifstream inf01;
244 inf0.open("calib_estimeOffset.txt",ios::in);
245 inf01.open("est_estimeOffset.txt", ios::in);
246 if(inf0.good()&& inf01.good()) {
247 try{
248 inf0 >> offset[0] ;
249 inf01 >> offset[1] ;
250 t0->Fill();
251 }catch(...) {
252 return false;
253 }
254 }
255 else {
256 std::cerr<<"file: calib_estimeOffset.txt or est_estimeOffset can't be found!"<<std::endl;
257 }
258 inf0.close();
259 inf01.close();
260
261 TTree* t=new TTree("EndTofPar","endcap parameters");
262 //create a full tree;
263 double p[8]={0.};;
264 char brname[8];//branch name
265 char ptname[8];//pattern name
266 for(int i=0;i<8;i++){
267 sprintf(brname,"P%d",i);
268 sprintf(ptname,"p%d/D",i);
269 t->Branch(brname,&p[i],ptname);
270 }
271 double Atten[5]={0.},Speed[3]={0.},Q0[1]={0.};
272 t->Branch("Atten0",&Atten[0],"Atten0/D");
273 t->Branch("Atten1",&Atten[1],"Atten1/D");
274 t->Branch("Atten2",&Atten[2],"Atten2/D");
275 t->Branch("Atten3",&Atten[3],"Atten3/D");
276 t->Branch("Atten4",&Atten[4],"Atten4/D");
277 t->Branch("Speed0",&Speed[0],"Speed0/D");
278 t->Branch("Speed1",&Speed[1],"Speed1/D");
279 t->Branch("Speed2",&Speed[2],"Speed2/D");
280 t->Branch("Q0",Q0,"Q0[1]/D");
281 const int N=3;
282 ifstream inf[N];
283 bool is_open[N]={false};
284 const char* filelist[N]={"calib_endcap_left.txt","calib_endcap_atten.txt","calib_endcap_veff.txt"};
285 for(int m=0;m<N;m++){
286 inf[m].open(filelist[m],ios::in);
287 if(inf[m].good())
288 is_open[m]=true;
289 else{
290 std::cerr<<"File: "<<filelist[m]<<" can't be opened"<<std::endl;
291 }
292 }
293 try{
294 for(int k=0;k<96;k++){
295 //------------set p-------------------------
296 if(is_open[0]&&is_open[1]){
297 for(int j=0;j<5;j++){
298 inf[0]>>p[j];
299 // cout<<p[j]<<' ';
300 }
301 }
302 //-----------atten lenght------------------
303 if(is_open[1]){
304 for(int j=0;j<3;j++){
305 inf[1]>>Atten[j];
306 }
307 Atten[0]=1./Atten[0];
308 }
309 //-------------speed-----------------------
310 if(is_open[2]){
311 for(int j=0;j<3;j++){
312 inf[2]>>Speed[j];
313 }
314 Speed[0]=1./Speed[0];
315 }
316 //-------------Q0----------------------------
317 // for(int j=0;j<1;j++)
318 // inf[5]>>Q0[j];
319 //-------------fill-----------------------
320 t->Fill();
321 }
322 } catch(...){
323 return false;
324 }
325 for(int m=0;m<N;m++)
326 inf[m].close();
327 //-------------------------------------------
328 TFile f("EndTofPar.root","RECREATE");
329 t0->Write();
330 t->Write();
331 f.Close();
332 delete t0;
333 delete t;
334 t=NULL;
335 t=NULL;
336 return true;
337}

Referenced by main().

◆ join()

bool join ( )

Definition at line 338 of file EstTofCaliSvc/EstTofCaliSvc-00-00-08/test/convert2root.cxx.

338 {
339
340 TTree* t0=new TTree("EsTimeOffset","EsTimeOffset");
341 double offset[2]={0.};
342 char estbrname[20];
343 char estptname[20];
344 for(int i = 0; i<2; i++){
345 sprintf(estbrname, "Offset%d",i);
346 sprintf(estptname, "Offset%d/D",i);
347 t0->Branch(estbrname, &offset[i], estptname);
348 }
349
350 ifstream inf0;
351 ifstream inf01;
352 inf0.open("calib_estimeOffset.txt",ios::in);
353 inf01.open("est_estimeOffset.txt", ios::in);
354 if(inf0.good()&& inf01.good()) {
355 try{
356 inf0 >> offset[0] ;
357 inf01 >> offset[1] ;
358 t0->Fill();
359 }catch(...) {
360 return false;
361 }
362 }
363 else {
364 std::cerr<<"file: calib_estimeOffset.txt or est_estimeOffset can't be found!"<<std::endl;
365 }
366 inf0.close();
367 inf01.close();
368
369 TFile f("EndTofPar.root");
370 TTree* t=(TTree*)f.Get("EndTofPar");
371 if(0==t) { std::cerr<<" can't get tree :EndTofPar in file EndTofPar.root"<<std::endl; return false;}
372 TFile f1("BarTofPar.root");
373 TTree* t1=(TTree*)f1.Get("BarTofPar");
374 if(0==t1) { std::cerr<<" can't get tree :BarTofPar in file BarTofPar.root"<<std::endl; return false;}
375 TTree* t2=(TTree*)f1.Get("BarTofParInner");
376 if(0==t2) { std::cerr<<" can't get tree :BarTofPar Inner Layer in file BarTofPar.root"<<std::endl; return false;}
377 TTree* t3=(TTree*)f1.Get("BarTofParCommon");
378 if(0==t3) { std::cerr<<" can't get tree :BarTofPar Common in file BarTofPar.root"<<std::endl; return false;}
379 TFile fnew("TofCalConst.root","RECREATE");
380 t0->Write();
381 t->Write();
382 t1->Write();
383 t2->Write();
384 t3->Write();
385 f.Close();
386 f1.Close();
387 fnew.Close();
388 t0=NULL;
389 t=NULL;
390 t1=NULL;
391 t2=NULL;
392 t3=NULL;
393 return true;
394}
TFile * f1

Referenced by main().

◆ main()