BOSS 6.6.4.p01
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( !calibration_barrel_item.empty() ) {
36 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item.begin();
37 for( ; iter != calibration_barrel_item.end(); iter++ ) {
38 if( (*iter) ) delete (*iter);
39 }
40 calibration_barrel_item.clear();
41 }
42 if( !calibration_barrel_item2.empty() ) {
43 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item2.begin();
44 for( ; iter != calibration_barrel_item2.end(); iter++ ) {
45 if( (*iter) ) delete (*iter);
46 }
47 calibration_barrel_item2.clear();
48 }
49 if( !calibration_endcap_item.empty() ) {
50 std::vector<TofCalibFit*>::iterator iter = calibration_endcap_item.begin();
51 for( ; iter != calibration_endcap_item.end(); iter++ ) {
52 if( (*iter) ) delete (*iter);
53 }
54 calibration_endcap_item.clear();
55 }
56
57 delete m_dataset;
58 return;
59}
60
61
62void TofCalibManager::addCalib( TofCalib* cal_item1, bool isbarrel ) {
63 if( isbarrel ) {
64 calib_barrel_item.push_back(cal_item1);
65 }
66 else {
67 calib_endcap_item.push_back(cal_item1);
68 }
69 return;
70}
71
72
73void TofCalibManager::addCalib( TofCalibFit* cal_item2, bool isbarrel ) {
74 if( isbarrel ) {
75 if( cal_item2->name()=="calib_barrel_sigma" ) {
76 calibration_barrel_item2.push_back(cal_item2);
77 }
78 else {
79 calibration_barrel_item.push_back(cal_item2);
80 }
81 }
82 else {
83 calibration_endcap_item.push_back(cal_item2);
84 }
85 return;
86}
87
88
90
91 if( !calib_barrel_item.empty() || !calibration_barrel_item.empty() ) {
92 std::cout << "Begin barrel counters calibration..." << std::endl;
93 std::cout << setiosflags(ios::left) << setw(10) << "TOF ID" << setw(8) << "Entries" << setw(30) << "What Calibration" << std::endl;
94 HepVector tcorrelation;
95 for( unsigned int i=0; i<NBarrel; i++ ) {
96 RecordSet* barrelData = m_dataset->getBarrelData(i);
97 if( !calib_barrel_item.empty() ) {
98 std::vector<TofCalib*>::iterator iter1 = calib_barrel_item.begin();
99 for( ; iter1!=calib_barrel_item.end(); iter1++ ) {
100 (*iter1)->reset();
101 (*iter1)->calculate( barrelData, i );
102 }
103 }
104 if( !calibration_barrel_item.empty() ) {
105 std::vector<TofCalibFit*>::iterator iter2 = calibration_barrel_item.begin();
106 for( ; iter2!=calibration_barrel_item.end(); iter2++ ) {
107 (*iter2)->calculate( barrelData, i );
108 if( i==(NBarrel-1) ) {
109 if( (*iter2)->name()=="calib_barrel_common" ) {
110 tcorrelation = (*iter2)->tcorrelation();
111 }
112 }
113 }
114 }
115 }
116
117 for( unsigned int i=0; i<NBarrel; i++ ) {
118 RecordSet* barrelData = m_dataset->getBarrelData(i);
119 if( !calibration_barrel_item2.empty() ) {
120 std::vector<TofCalibFit*>::iterator iter2 = calibration_barrel_item2.begin();
121 for( ; iter2!=calibration_barrel_item2.end(); iter2++ ) {
122 if( i==0 ) {
123 if( (*iter2)->name()=="calib_barrel_sigma" ) {
124 (*iter2)->setTCorrelation( tcorrelation );
125 }
126 }
127 (*iter2)->calculate( barrelData, i );
128 }
129 }
130 }
131 }
132
133 if( !calib_endcap_item.empty() || !calibration_endcap_item.empty() ) {
134 std::cout << "Begin endcap counters calibration..." << std::endl;
135 std::cout << setiosflags(ios::left) << setw(10)<<"TOF ID" << setw(8) << "Entries" << setw(30) << "What Calibration" << std::endl;
136 for( unsigned int i=0; i<NEndcap; i++ ) {
137 RecordSet* endcapData = m_dataset->getEndcapData(i);
138 if( !calib_endcap_item.empty() ) {
139 std::vector<TofCalib*>::iterator iter1 = calib_endcap_item.begin();
140 for( ; iter1!=calib_endcap_item.end(); iter1++ ) {
141 (*iter1)->reset();
142 (*iter1)->calculate( endcapData, i );
143 }
144 }
145 if( !calibration_endcap_item.empty() ) {
146 std::vector<TofCalibFit*>::iterator iter2 = calibration_endcap_item.begin();
147 for( ; iter2!=calibration_endcap_item.end(); iter2++ ) {
148 (*iter2)->calculate( endcapData, i );
149 }
150 }
151 }
152 }
153
154 return;
155}
156
157
158void TofCalibManager::fillTxt( string& dir ) {
159
160 if( !calib_barrel_item.empty() ) {
161 std::vector<TofCalib*>::iterator iter = calib_barrel_item.begin();
162 for( ; iter != calib_barrel_item.end(); iter++ ) {
163 string fname = dir + string("/") + (*iter)->name() + string(".txt");
164 (*iter)->fillTxt( fname.c_str() );
165 }
166 }
167
168 if( !calib_endcap_item.empty() ) {
169 std::vector<TofCalib*>::iterator iter = calib_endcap_item.begin();
170 for( ; iter != calib_endcap_item.end(); iter++ ) {
171 string fname = dir + string("/") + (*iter)->name() + string(".txt");
172 (*iter)->fillTxt( fname.c_str() );
173 }
174 }
175
176 if( !calibration_barrel_item.empty() ) {
177 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item.begin();
178 for( ; iter != calibration_barrel_item.end(); iter++ ) {
179 string fname = dir + string("/") + (*iter)->name() + string(".txt");
180 (*iter)->fillTxt( fname.c_str() );
181 }
182 }
183 if( !calibration_barrel_item2.empty() ) {
184 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item2.begin();
185 for( ; iter != calibration_barrel_item2.end(); iter++ ) {
186 string fname = dir + string("/") + (*iter)->name() + string(".txt");
187 (*iter)->fillTxt( fname.c_str() );
188 }
189 }
190
191 if( !calibration_endcap_item.empty() ) {
192 std::vector<TofCalibFit*>::iterator iter = calibration_endcap_item.begin();
193 for( ; iter != calibration_endcap_item.end(); iter++ ) {
194 string fname = dir + string("/") + (*iter)->name() + string(".txt");
195 (*iter)->fillTxt( fname.c_str() );
196 }
197 }
198
199 return;
200}
201
202
203void TofCalibManager::fillRoot( string& dir ) {
204 int count = 1;
205 char filename1[256];
206 sprintf( filename1, "%s/barrel%i.root", dir.c_str(), count );
207 TFile f1(filename1,"RECREATE");
208 TTree* ntbarrel = new TTree( "btrk", "barrel data after calibration" );
209
210 int run;
211 int event;
212 int tofid;
213 double qleft;
214 double qright;
215 double tleft;
216 double tright;
217 double zrhit;
218 double texp;
219 double path;
220 double phi;
221 double theta;
222 double p;
223 double t0;
224 double q0;
225 int hitcase;
226
227 ntbarrel->Branch( "run", &run, "run/I" );
228 ntbarrel->Branch( "event", &event, "event/I" );
229 ntbarrel->Branch( "tofid", &tofid, "tofid/I" );
230 ntbarrel->Branch( "qleft", &qleft, "qleft/D" );
231 ntbarrel->Branch( "qright", &qright, "qright/D" );
232 ntbarrel->Branch( "tleft", &tleft, "tleft/D" );
233 ntbarrel->Branch( "tright", &tright, "tright/D" );
234 ntbarrel->Branch( "zrhit", &zrhit, "zrhit/D" );
235 ntbarrel->Branch( "texp", &texp, "texp/D" );
236 ntbarrel->Branch( "path", &path, "path/D" );
237 ntbarrel->Branch( "phi", &phi, "phi/D" );
238 ntbarrel->Branch( "theta", &theta, "theta/D" );
239 ntbarrel->Branch( "p", &p, "p/D" );
240 ntbarrel->Branch( "t0", &t0, "t0/D" );
241 ntbarrel->Branch( "q0", &q0, "q0/D" );
242 ntbarrel->Branch( "hitcase",&hitcase,"hitcase/I");
243
244 int counter = 0;
245 std::cout << "begin to write..." << filename1 << std::endl;
246 for( unsigned int i=0; i<NBarrel; i++ ) {
247 std::cout << "\r\b Writing record ... " << (int((++counter)*100./NBarrel)) << "%";
248 RecordSet* barrelData = m_dataset->getBarrelData(i);
249 std::vector<Record*>::iterator iter = barrelData->begin();
250 for( ; iter!=barrelData->end(); iter++ ) {
251 run = (*iter)->run();
252 event = (*iter)->event();
253 tofid = (*iter)->tofid();
254 qleft = (*iter)->qleft();
255 qright = (*iter)->qright();
256 tleft = (*iter)->tleft();
257 tright = (*iter)->tright();
258 zrhit = (*iter)->zrhit();
259 texp = (*iter)->texp();
260 path = (*iter)->path();
261 phi = (*iter)->phi();
262 theta = (*iter)->theta();
263 p = (*iter)->p();
264 t0 = (*iter)->t0();
265 q0 = (*iter)->q0();
266 hitcase = (*iter)->hitcase();
267 ntbarrel->Fill();
268 }
269 }
270 std::cout << std::endl;
271 ntbarrel->Write();
272 delete ntbarrel;
273 f1.Close();
274
275 char filename2[256];
276 sprintf( filename2, "%s/endcap%i.root", dir.c_str(), count );
277 TFile f2(filename2,"RECREATE");
278 TTree* ntendcap = new TTree( "etrk", "endcap data after calibration" );
279
280 ntendcap->Branch( "run", &run, "run/I" );
281 ntendcap->Branch( "event", &event, "event/I" );
282 ntendcap->Branch( "tofid", &tofid, "tofid/I" );
283 ntendcap->Branch( "qleft", &qleft, "qleft/D" );
284 ntendcap->Branch( "qright", &qright, "qright/D" );
285 ntendcap->Branch( "tleft", &tleft, "tleft/D" );
286 ntendcap->Branch( "tright", &tright, "tright/D" );
287 ntendcap->Branch( "zrhit", &zrhit, "zrhit/D" );
288 ntendcap->Branch( "texp", &texp, "texp/D" );
289 ntendcap->Branch( "path", &path, "path/D" );
290 ntendcap->Branch( "phi", &phi, "phi/D" );
291 ntendcap->Branch( "theta", &theta, "theta/D" );
292 ntendcap->Branch( "p", &p, "p/D" );
293 ntendcap->Branch( "t0", &t0, "t0/D" );
294 ntendcap->Branch( "q0", &q0, "q0/D" );
295 ntendcap->Branch( "hitcase",&hitcase,"hitcase/I");
296
297 counter = 0;
298 std::cout << "begin to write..." << filename2 << std::endl;
299 for( unsigned int i=0; i<NEndcap; i++ ) {
300 std::cout << "\r\b Writing record ... " << (int((++counter)*100./NEndcap)) << "%";
301 RecordSet* endcapData = m_dataset->getEndcapData(i);
302 std::vector<Record*>::iterator iter = endcapData->begin();
303 for( ; iter!=endcapData->end(); iter++ ) {
304 run = (*iter)->run();
305 event = (*iter)->event();
306 tofid = (*iter)->tofid();
307 qleft = (*iter)->qleft();
308 qright = (*iter)->qright();
309 tleft = (*iter)->tleft();
310 tright = (*iter)->tright();
311 zrhit = (*iter)->zrhit();
312 texp = (*iter)->texp();
313 path = (*iter)->path();
314 phi = (*iter)->phi();
315 theta = (*iter)->theta();
316 p = (*iter)->p();
317 t0 = (*iter)->t0();
318 q0 = (*iter)->q0();
319 hitcase = (*iter)->hitcase();
320 ntendcap->Fill();
321 }
322 }
323 std::cout << std::endl;
324 ntendcap->Write();
325 delete ntendcap;
326 f2.Close();
327
328
329 if( !calibration_barrel_item.empty() ) {
330 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item.begin();
331 for( ; iter != calibration_barrel_item.end(); iter++ ) {
332 string fname = dir + string("/") + (*iter)->name() + string(".root");
333 (*iter)->fillRoot( fname.c_str() );
334 }
335 }
336 if( !calibration_barrel_item2.empty() ) {
337 std::vector<TofCalibFit*>::iterator iter = calibration_barrel_item2.begin();
338 for( ; iter != calibration_barrel_item2.end(); iter++ ) {
339 string fname = dir + string("/") + (*iter)->name() + string(".root");
340 (*iter)->fillRoot( fname.c_str() );
341 }
342 }
343
344 if( !calibration_endcap_item.empty() ) {
345 std::vector<TofCalibFit*>::iterator iter = calibration_endcap_item.begin();
346 for( ; iter != calibration_endcap_item.end(); iter++ ) {
347 string fname = dir + string("/") + (*iter)->name() + string(".root");
348 (*iter)->fillRoot( fname.c_str() );
349 }
350 }
351
352 return;
353}
TFile * f1
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< Record * > RecordSet
Definition: TofDataSet.h:89
const unsigned int NBarrel
Definition: TofDataSet.h:12
const unsigned int NEndcap
Definition: TofDataSet.h:13
const string & name() const
Definition: TofCalibFit.h:29
void addCalib(TofCalib *cal_item1, bool isbarrel)
static TofCalibManager * getManager()
void fillRoot(string &dir)
void fillTxt(string &dir)
RecordSet * getEndcapData(unsigned int i) const
Definition: TofDataSet.h:99
RecordSet * getBarrelData(unsigned int i) const
Definition: TofDataSet.h:98