BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCalibManager.cxx
Go to the documentation of this file.
2#include "TTree.h"
3#include "TFile.h"
4
5TofCalibManager* TofCalibManager::m_manager=0;
7 if( m_manager == 0 ) {
8 m_manager = new TofCalibManager;
9 }
10 return m_manager;
11}
12
13
15 m_dataset = new TofDataSet;
16 return;
17}
18
19
21 if( !calib_barrel_item.empty() ) {
22 std::vector<TofCalib*>::iterator iter = calib_barrel_item.begin();
23 for( ; iter != calib_barrel_item.end(); iter++ ) {
24 if( (*iter) ) delete (*iter);
25 }
26 calib_barrel_item.clear();
27 }
28 if( !calib_endcap_item.empty() ) {
29 std::vector<TofCalib*>::iterator iter = calib_endcap_item.begin();
30 for( ; iter != calib_endcap_item.end(); iter++ ) {
31 if( (*iter) ) delete (*iter);
32 }
33 calib_endcap_item.clear();
34 }
35 if( !calib_etf_item.empty() ) {
36 std::vector<TofCalib*>::iterator iter = calib_etf_item.begin();
37 for( ; iter != calib_etf_item.end(); iter++ ) {
38 if( (*iter) ) delete (*iter);
39 }
40 calib_etf_item.clear();
41 }
42 if( !calibration_barrel_item.empty() ) {
43 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item.begin();
44 for( ; iter != calibration_barrel_item.end(); iter++ ) {
45 if( (*iter) ) delete (*iter);
46 }
47 calibration_barrel_item.clear();
48 }
49 if( !calibration_barrel_item2.empty() ) {
50 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item2.begin();
51 for( ; iter != calibration_barrel_item2.end(); iter++ ) {
52 if( (*iter) ) delete (*iter);
53 }
54 calibration_barrel_item2.clear();
55 }
56 if( !calibration_endcap_item.empty() ) {
57 std::vector<TofCalibFit*>::iterator iter = calibration_endcap_item.begin();
58 for( ; iter != calibration_endcap_item.end(); iter++ ) {
59 if( (*iter) ) delete (*iter);
60 }
61 calibration_endcap_item.clear();
62 }
63
64 delete m_dataset;
65 return;
66}
67
68
69void TofCalibManager::addCalib( TofCalib* cal_item1, int isbarrel ) {
70 if( isbarrel==1 ) {
71 calib_barrel_item.push_back(cal_item1);
72 }
73 else if( isbarrel==0 ) {
74 calib_endcap_item.push_back(cal_item1);
75 }
76 else if( isbarrel==2 ) {
77 calib_etf_item.push_back(cal_item1);
78 }
79 else {
80 cout << "Tof::tofcalgsec::TofCalibManaer: addCalib: isbarrel is OUT of range!" << endl;
81 }
82 return;
83}
84
85
86void TofCalibManager::addCalib( TofCalibFit* cal_item2, bool isbarrel ) {
87 if( isbarrel ) {
88 if( cal_item2->name()=="calib_barrel_sigma" ) {
89 calibration_barrel_item2.push_back(cal_item2);
90 }
91 else {
92 calibration_barrel_item.push_back(cal_item2);
93 }
94 }
95 else {
96 // calibration_endcap_item.push_back(cal_item2);
97 calibration_etf_item.push_back(cal_item2);
98 }
99 return;
100}
101
102
104
105 if( !calib_barrel_item.empty() || !calibration_barrel_item.empty() ) {
106 std::cout << "Begin barrel counters calibration..." << std::endl;
107 std::cout << setiosflags(ios::left) << setw(10) << "TOF ID" << setw(8) << "Entries" << setw(30) << "What Calibration" << std::endl;
108 HepVector tcorrelation;
109 for( unsigned int i=0; i<NBarrel; i++ ) {
110 RecordSet* barrelData = m_dataset->getBarrelData(i);
111 if( !calib_barrel_item.empty() ) {
112 std::vector<TofCalib*>::iterator iter1 = calib_barrel_item.begin();
113 for( ; iter1!=calib_barrel_item.end(); iter1++ ) {
114 (*iter1)->reset();
115 (*iter1)->calculate( barrelData, i );
116 }
117 }
118 if( !calibration_barrel_item.empty() ) {
119 std::vector<TofCalibFit*>::iterator iter2 = calibration_barrel_item.begin();
120 for( ; iter2!=calibration_barrel_item.end(); iter2++ ) {
121 (*iter2)->calculate( barrelData, i );
122 if( i==(NBarrel-1) ) {
123 if( (*iter2)->name()=="calib_barrel_common" ) {
124 tcorrelation = (*iter2)->tcorrelation();
125 }
126 }
127 }
128 }
129 }
130
131 for( unsigned int i=0; i<NBarrel; i++ ) {
132 RecordSet* barrelData = m_dataset->getBarrelData(i);
133 if( !calibration_barrel_item2.empty() ) {
134 std::vector<TofCalibFit*>::iterator iter2 = calibration_barrel_item2.begin();
135 for( ; iter2!=calibration_barrel_item2.end(); iter2++ ) {
136 if( i==0 ) {
137 if( (*iter2)->name()=="calib_barrel_sigma" ) {
138 (*iter2)->setTCorrelation( tcorrelation );
139 }
140 }
141 (*iter2)->calculate( barrelData, i );
142 }
143 }
144 }
145 }
146
147 if( !calib_endcap_item.empty() || !calibration_endcap_item.empty() ) {
148 std::cout << "Begin endcap counters calibration..." << std::endl;
149 std::cout << setiosflags(ios::left) << setw(10)<<"TOF ID" << setw(8) << "Entries" << setw(30) << "What Calibration" << std::endl;
150 for( unsigned int i=0; i<NEndcap; i++ ) {
151 RecordSet* endcapData = m_dataset->getEndcapData(i);
152 if( !calib_endcap_item.empty() ) {
153 std::vector<TofCalib*>::iterator iter1 = calib_endcap_item.begin();
154 for( ; iter1!=calib_endcap_item.end(); iter1++ ) {
155 (*iter1)->reset();
156 (*iter1)->calculate( endcapData, i );
157 }
158 }
159 if( !calibration_endcap_item.empty() ) {
160 std::vector<TofCalibFit*>::iterator iter2 = calibration_endcap_item.begin();
161 for( ; iter2!=calibration_endcap_item.end(); iter2++ ) {
162 (*iter2)->calculate( endcapData, i );
163 }
164 }
165 }
166 }
167
168 if( !calib_etf_item.empty() || !calibration_etf_item.empty() ) {
169 std::cout << "Begin ETF(MRPC) calibration..." << std::endl;
170 std::cout << setiosflags(ios::left) << setw(10) << "TOF ID *12 + STRIP" << setw(8) << "Entries" << setw(30) << "What Calibration" << std::endl;
171 HepVector tcorrelation;
172 for( unsigned int i=0; i<NEtf*NStrip; i++ ) {
173 RecordSet* etfData = m_dataset->getEtfData(i);
174 if( !calib_etf_item.empty() ) {
175 std::vector<TofCalib*>::iterator iter1 = calib_etf_item.begin();
176 for( ; iter1!=calib_etf_item.end(); iter1++ ) {
177 (*iter1)->reset();
178 (*iter1)->calculate( etfData, i );
179 }
180 }
181 if( !calibration_etf_item.empty() ) {
182 std::vector<TofCalibFit*>::iterator iter2 = calibration_etf_item.begin();
183 for( ; iter2!=calibration_etf_item.end(); iter2++ ) {
184 (*iter2)->calculate( etfData, i );
185 }
186 }
187 }
188 }
189
190 return;
191}
192
193
194void TofCalibManager::fillTxt( string& dir ) {
195
196 if( !calib_barrel_item.empty() ) {
197 std::vector<TofCalib*>::iterator iter = calib_barrel_item.begin();
198 for( ; iter != calib_barrel_item.end(); iter++ ) {
199 string fname = dir + string("/") + (*iter)->name() + string(".txt");
200 (*iter)->fillTxt( fname.c_str() );
201 }
202 }
203
204 if( !calib_endcap_item.empty() ) {
205 std::vector<TofCalib*>::iterator iter = calib_endcap_item.begin();
206 for( ; iter != calib_endcap_item.end(); iter++ ) {
207 string fname = dir + string("/") + (*iter)->name() + string(".txt");
208 (*iter)->fillTxt( fname.c_str() );
209 }
210 }
211
212 if( !calib_etf_item.empty() ) {
213 std::vector<TofCalib*>::iterator iter = calib_etf_item.begin();
214 for( ; iter != calib_etf_item.end(); iter++ ) {
215 string fname = dir + string("/") + (*iter)->name() + string(".txt");
216 (*iter)->fillTxt( fname.c_str() );
217 }
218 }
219
220 if( !calibration_barrel_item.empty() ) {
221 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item.begin();
222 for( ; iter != calibration_barrel_item.end(); iter++ ) {
223 string fname = dir + string("/") + (*iter)->name() + string(".txt");
224 (*iter)->fillTxt( fname.c_str() );
225 }
226 }
227 if( !calibration_barrel_item2.empty() ) {
228 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item2.begin();
229 for( ; iter != calibration_barrel_item2.end(); iter++ ) {
230 string fname = dir + string("/") + (*iter)->name() + string(".txt");
231 (*iter)->fillTxt( fname.c_str() );
232 }
233 }
234
235 if( !calibration_endcap_item.empty() ) {
236 std::vector<TofCalibFit*>::iterator iter = calibration_endcap_item.begin();
237 for( ; iter != calibration_endcap_item.end(); iter++ ) {
238 string fname = dir + string("/") + (*iter)->name() + string(".txt");
239 (*iter)->fillTxt( fname.c_str() );
240 }
241 }
242
243 if( !calibration_etf_item.empty() ) {
244 std::vector<TofCalibFit*>::iterator iter = calibration_etf_item.begin();
245 for( ; iter != calibration_etf_item.end(); iter++ ) {
246 string fname = dir + string("/") + (*iter)->name() + string(".txt");
247 (*iter)->fillTxt( fname.c_str() );
248 }
249 }
250
251 return;
252}
253
254
255void TofCalibManager::fillRoot( string& dir ) {
256 int count = 1;
257 char filename1[256];
258 sprintf( filename1, "%s/barrel%i.root", dir.c_str(), count );
259 TFile f1(filename1,"RECREATE");
260 TTree* ntbarrel = new TTree( "btrk", "barrel data after calibration" );
261
262 int run;
263 int event;
264 int tofid;
265 int strip;
266 double qleft;
267 double qright;
268 double tleft;
269 double tright;
270 double zrhit;
271 double dt;
272 double texp;
273 double path;
274 double phi;
275 double theta;
276 double p;
277 double t0;
278 double q0;
279 int hitcase;
280
281 ntbarrel->Branch( "run", &run, "run/I" );
282 ntbarrel->Branch( "event", &event, "event/I" );
283 ntbarrel->Branch( "tofid", &tofid, "tofid/I" );
284 ntbarrel->Branch( "qleft", &qleft, "qleft/D" );
285 ntbarrel->Branch( "qright", &qright, "qright/D" );
286 ntbarrel->Branch( "tleft", &tleft, "tleft/D" );
287 ntbarrel->Branch( "tright", &tright, "tright/D" );
288 ntbarrel->Branch( "zrhit", &zrhit, "zrhit/D" );
289 ntbarrel->Branch( "texp", &texp, "texp/D" );
290 ntbarrel->Branch( "path", &path, "path/D" );
291 ntbarrel->Branch( "phi", &phi, "phi/D" );
292 ntbarrel->Branch( "theta", &theta, "theta/D" );
293 ntbarrel->Branch( "p", &p, "p/D" );
294 ntbarrel->Branch( "t0", &t0, "t0/D" );
295 ntbarrel->Branch( "q0", &q0, "q0/D" );
296 ntbarrel->Branch( "hitcase",&hitcase,"hitcase/I");
297
298 int counter = 0;
299 std::cout << "begin to write..." << filename1 << std::endl;
300 for( unsigned int i=0; i<NBarrel; i++ ) {
301 std::cout << "\r\b Writing record ... " << (int((++counter)*100./NBarrel)) << "%";
302 RecordSet* barrelData = m_dataset->getBarrelData(i);
303 std::vector<Record*>::iterator iter = barrelData->begin();
304 for( ; iter!=barrelData->end(); iter++ ) {
305 run = (*iter)->run();
306 event = (*iter)->event();
307 tofid = (*iter)->tofid();
308 qleft = (*iter)->qleft();
309 qright = (*iter)->qright();
310 tleft = (*iter)->tleft();
311 tright = (*iter)->tright();
312 zrhit = (*iter)->zrhit();
313 texp = (*iter)->texp();
314 path = (*iter)->path();
315 phi = (*iter)->phi();
316 theta = (*iter)->theta();
317 p = (*iter)->p();
318 t0 = (*iter)->t0();
319 q0 = (*iter)->q0();
320 hitcase = (*iter)->hitcase();
321 ntbarrel->Fill();
322 }
323 }
324 std::cout << std::endl;
325 ntbarrel->Write();
326 delete ntbarrel;
327 f1.Close();
328
329 char filename2[256];
330 sprintf( filename2, "%s/endcap%i.root", dir.c_str(), count );
331 TFile f2(filename2,"RECREATE");
332 TTree* ntendcap = new TTree( "etrk", "endcap data after calibration" );
333
334 ntendcap->Branch( "run", &run, "run/I" );
335 ntendcap->Branch( "event", &event, "event/I" );
336 ntendcap->Branch( "tofid", &tofid, "tofid/I" );
337 ntendcap->Branch( "qleft", &qleft, "qleft/D" );
338 ntendcap->Branch( "qright", &qright, "qright/D" );
339 ntendcap->Branch( "tleft", &tleft, "tleft/D" );
340 ntendcap->Branch( "tright", &tright, "tright/D" );
341 ntendcap->Branch( "zrhit", &zrhit, "zrhit/D" );
342 ntendcap->Branch( "texp", &texp, "texp/D" );
343 ntendcap->Branch( "path", &path, "path/D" );
344 ntendcap->Branch( "phi", &phi, "phi/D" );
345 ntendcap->Branch( "theta", &theta, "theta/D" );
346 ntendcap->Branch( "p", &p, "p/D" );
347 ntendcap->Branch( "t0", &t0, "t0/D" );
348 ntendcap->Branch( "q0", &q0, "q0/D" );
349 ntendcap->Branch( "hitcase",&hitcase,"hitcase/I");
350
351 counter = 0;
352 std::cout << "begin to write..." << filename2 << std::endl;
353 for( unsigned int i=0; i<NEndcap; i++ ) {
354 std::cout << "\r\b Writing record ... " << (int((++counter)*100./NEndcap)) << "%";
355 RecordSet* endcapData = m_dataset->getEndcapData(i);
356 std::vector<Record*>::iterator iter = endcapData->begin();
357 for( ; iter!=endcapData->end(); iter++ ) {
358 run = (*iter)->run();
359 event = (*iter)->event();
360 tofid = (*iter)->tofid();
361 qleft = (*iter)->qleft();
362 qright = (*iter)->qright();
363 tleft = (*iter)->tleft();
364 tright = (*iter)->tright();
365 zrhit = (*iter)->zrhit();
366 texp = (*iter)->texp();
367 path = (*iter)->path();
368 phi = (*iter)->phi();
369 theta = (*iter)->theta();
370 p = (*iter)->p();
371 t0 = (*iter)->t0();
372 q0 = (*iter)->q0();
373 hitcase = (*iter)->hitcase();
374 ntendcap->Fill();
375 }
376 }
377 std::cout << std::endl;
378 ntendcap->Write();
379 delete ntendcap;
380 f2.Close();
381
382 char filename3[256];
383 sprintf( filename3, "%s/etf%i.root", dir.c_str(), count );
384 TFile f3(filename3,"RECREATE");
385 TTree* ntetf = new TTree( "etf", "en data after calibration" );
386
387 ntetf->Branch( "run", &run, "run/I" );
388 ntetf->Branch( "event", &event, "event/I" );
389 ntetf->Branch( "tofid", &tofid, "tofid/I" );
390 ntetf->Branch( "strip", &strip, "strip/I" );
391 ntetf->Branch( "qleft", &qleft, "qleft/D" );
392 ntetf->Branch( "qright", &qright, "qright/D" );
393 ntetf->Branch( "tleft", &tleft, "tleft/D" );
394 ntetf->Branch( "tright", &tright, "tright/D" );
395 ntetf->Branch( "zrhit", &zrhit, "zrhit/D" );
396 ntetf->Branch( "dt", &dt, "dt/D" );
397 ntetf->Branch( "texp", &texp, "texp/D" );
398 ntetf->Branch( "path", &path, "path/D" );
399 ntetf->Branch( "phi", &phi, "phi/D" );
400 ntetf->Branch( "p", &p, "p/D" );
401 ntetf->Branch( "t0", &t0, "t0/D" );
402 ntetf->Branch( "q0", &q0, "q0/D" );
403 ntetf->Branch( "hitcase",&hitcase,"hitcase/I");
404
405 counter = 0;
406 std::cout << "begin to write..." << filename3 << std::endl;
407 for( unsigned int i=0; i<NEtf*NStrip; i++ ) {
408 std::cout << "\r\b Writing record ... " << (int((++counter)*100./(NEtf*NStrip))) << "%";
409 RecordSet* etfData = m_dataset->getEtfData(i);
410 std::vector<Record*>::iterator iter = etfData->begin();
411 for( ; iter!=etfData->end(); iter++ ) {
412 run = (*iter)->run();
413 event = (*iter)->event();
414 tofid = (*iter)->tofid();
415 strip = (*iter)->strip();
416 qleft = (*iter)->qleft();
417 qright = (*iter)->qright();
418 tleft = (*iter)->tleft();
419 tright = (*iter)->tright();
420 zrhit = (*iter)->zrhit();
421 dt = (*iter)->dt();
422 texp = (*iter)->texp();
423 path = (*iter)->path();
424 phi = (*iter)->phi();
425 p = (*iter)->p();
426 t0 = (*iter)->t0();
427 q0 = (*iter)->q0();
428 hitcase = (*iter)->hitcase();
429 ntetf->Fill();
430 }
431 }
432 std::cout << std::endl;
433 ntetf->Write();
434 delete ntetf;
435 f3.Close();
436
437 if( !calibration_barrel_item.empty() ) {
438 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item.begin();
439 for( ; iter != calibration_barrel_item.end(); iter++ ) {
440 string fname = dir + string("/") + (*iter)->name() + string(".root");
441 (*iter)->fillRoot( fname.c_str() );
442 }
443 }
444 if( !calibration_barrel_item2.empty() ) {
445 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item2.begin();
446 for( ; iter != calibration_barrel_item2.end(); iter++ ) {
447 string fname = dir + string("/") + (*iter)->name() + string(".root");
448 (*iter)->fillRoot( fname.c_str() );
449 }
450 }
451
452 if( !calibration_endcap_item.empty() ) {
453 std::vector<TofCalibFit*>::iterator iter = calibration_endcap_item.begin();
454 for( ; iter != calibration_endcap_item.end(); iter++ ) {
455 string fname = dir + string("/") + (*iter)->name() + string(".root");
456 (*iter)->fillRoot( fname.c_str() );
457 }
458 }
459
460 if( !calibration_etf_item.empty() ) {
461 std::vector<TofCalibFit*>::iterator iter = calibration_etf_item.begin();
462 for( ; iter != calibration_etf_item.end(); iter++ ) {
463 string fname = dir + string("/") + (*iter)->name() + string(".root");
464 (*iter)->fillRoot( fname.c_str() );
465 }
466 }
467
468 return;
469}
DOUBLE_PRECISION count[3]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
TGraph2DErrors * dt
Definition: McCor.cxx:45
std::vector< Record * > RecordSet
Definition: TofDataSet.h:98
const unsigned int NStrip
Definition: TofDataSet.h:15
const unsigned int NEtf
Definition: TofDataSet.h:14
const unsigned int NBarrel
Definition: TofDataSet.h:12
const unsigned int NEndcap
Definition: TofDataSet.h:13
const string & name() const
Definition: TofCalibFit.h:27
void addCalib(TofCalib *cal_item1, int isbarrel)
static TofCalibManager * getManager()
void fillRoot(string &dir)
void fillTxt(string &dir)
RecordSet * getEtfData(unsigned int i) const
Definition: TofDataSet.h:109
RecordSet * getEndcapData(unsigned int i) const
Definition: TofDataSet.h:108
RecordSet * getBarrelData(unsigned int i) const
Definition: TofDataSet.h:107
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)