12 {
13
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
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
46 double p[20]={0.};;
47 char brname[20];
48 char ptname[20];
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 }
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];
72 char fptname1[5];
73 char fbrname2[5];
74 char fptname2[5];
75 char fbrname3[10];
76 char fptname3[10];
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;
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
104 if(is_open[0]&&is_open[1]){
105 for(int j=0;j<7;j++){
106 inf[0]>>p[j];
107
108 }
109 for(int l=10;l<17;l++)
110 inf[1]>>p[l];
111 }
112
113 if(is_open[2]){
114 for(int j=0;j<4;j++)
116 }
117
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
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
143 if(is_open[9]){
144 for(int j=2;j<5;j++){
145 inf[9] >> Atten[j];
146 }
147 }
148
149
150
151
153 }
154 }catch(...) {
155 return false;
156 }
157
158 TTree* t1=new TTree("BarTofParInner","barrel inner layer parameters");
159
160 double p1[20]={0.};;
161 char brname1[20];
162 char ptname1[20];
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
171 if(is_open[6]&&is_open[7]){
172 for(int j=0;j<7;j++){
173 inf[6]>>p1[j];
174
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();
211 t1->Write();
212 t2->Write();
213 f.Close();
214 delete t0;
216 delete t1;
217 delete t2;
218 t0=NULL;
220 t1=NULL;
221 t2=NULL;
222 return true;
223}