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++){
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;
198 bool is_open[N]={false};
199 const char* filelist[N]={
200 "calib_barrel_left.txt",
201 "calib_barrel_right.txt",
202 "calib_barrel_left_offset1_bunch0.txt",
203 "calib_barrel_left_offset2_bunch0.txt",
204 "calib_barrel_right_offset1_bunch0.txt",
205 "calib_barrel_right_offset2_bunch0.txt",
206 "calib_barrel_left_offset1_bunch1.txt",
207 "calib_barrel_left_offset2_bunch1.txt",
208 "calib_barrel_right_offset1_bunch1.txt",
209 "calib_barrel_right_offset2_bunch1.txt",
210 "calib_barrel_left_offset1_bunch2.txt",
211 "calib_barrel_left_offset2_bunch2.txt",
212 "calib_barrel_right_offset1_bunch2.txt",
213 "calib_barrel_right_offset2_bunch2.txt",
214 "calib_barrel_left_offset1_bunch3.txt",
215 "calib_barrel_left_offset2_bunch3.txt",
216 "calib_barrel_right_offset1_bunch3.txt",
217 "calib_barrel_right_offset2_bunch3.txt",
218 "calib_barrel_sigma.txt",
219 "calib_barrel_atten.txt",
220 "calib_barrel_q0.txt",
221 "calib_barrel_veff.txt",
222 "calib_barrel_common.txt"
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
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
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
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
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
278 if(is_open[18]){
279 for(int j=0; j<15; j++) {
280 inf[18] >> fitfun[j];
281 }
282 }
283
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
291 if(is_open[20]){
292 for(int j=2;j<5;j++){
293 inf[20] >> Atten[j];
294 }
295 }
296
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();
336 delete t1;
337 delete t2;
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")