BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcCalibFunSvc.cxx
Go to the documentation of this file.
1#include "MdcCalibFunSvc/MdcCalibFunSvc.h"
2#include "GaudiKernel/Kernel.h"
3#include "GaudiKernel/IInterface.h"
4#include "GaudiKernel/StatusCode.h"
5#include "GaudiKernel/SvcFactory.h"
6#include "GaudiKernel/MsgStream.h"
7
8#include "GaudiKernel/IIncidentSvc.h"
9#include "GaudiKernel/Incident.h"
10#include "GaudiKernel/IIncidentListener.h"
11
12#include "GaudiKernel/ISvcLocator.h"
13#include "GaudiKernel/Bootstrap.h"
14
15#include "GaudiKernel/IDataProviderSvc.h"
16#include "GaudiKernel/SmartDataPtr.h"
17#include "GaudiKernel/DataSvc.h"
18
19#include "CalibData/CalibModel.h"
20#include "CalibData/Mdc/MdcCalibData.h"
21#include "CalibData/Mdc/MdcDataConst.h"
22#include "EventModel/EventHeader.h"
23#include "GaudiKernel/SmartDataPtr.h"
24
25#include "TFile.h"
26#include "TTree.h"
27#include "TList.h"
28
29#include <iomanip>
30#include <iostream>
31#include <fstream>
32#include <math.h>
33
34using namespace std;
35
36typedef map<int, double>::value_type valType;
37
38MdcCalibFunSvc::MdcCalibFunSvc( const string& name, ISvcLocator* svcloc) :
39 Service (name, svcloc), m_layInfSig(-1) {
40
41 // declare properties
42 declareProperty("CheckConst", m_checkConst = false);
43 declareProperty("LayerInfSig", m_layInfSig);
44 declareProperty("XtMode", m_xtMode = 1);
45 declareProperty("NewXtFile", m_xtfile);
46 declareProperty("ReadWireEffDb", m_readWireEffDb = true);
47 declareProperty("WireEffFile", m_wireEffFile);
48 declareProperty("LinearXT", m_linearXT = false);
49 declareProperty("FixSigma", m_fixSigma = false);
50 declareProperty("FixSigmaValue", m_fixSigmaValue = 130.0); // micron
51 m_outputXtMode = true;
52}
53
55}
56
57StatusCode MdcCalibFunSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
58 if( IID_IMdcCalibFunSvc.versionMatch(riid) ){
59 *ppvInterface = static_cast<IMdcCalibFunSvc*> (this);
60 } else{
61 return Service::queryInterface(riid, ppvInterface);
62 }
63 return StatusCode::SUCCESS;
64}
65
67 MsgStream log(messageService(), name());
68 log << MSG::INFO << "MdcCalibFunSvc::initialize()" << endreq;
69
70 StatusCode sc = Service::initialize();
71 if( sc.isFailure() ) return sc;
72
73 IIncidentSvc* incsvc;
74 sc = service("IncidentSvc", incsvc);
75 int priority = 100;
76 if( sc.isSuccess() ){
77 incsvc -> addListener(this, "NewRun", priority);
78 }
79
80 sc = service("CalibDataSvc", m_pCalDataSvc, true);
81 if( sc == StatusCode::SUCCESS ){
82 log << MSG::INFO << "Retrieve IDataProviderSvc" << endreq;
83 }else{
84 log << MSG::FATAL << "can not get IDataProviderSvc" << endreq;
85 }
86
87 sc = service("MdcGeomSvc", m_pMdcGeomSvc);
88 if( sc != StatusCode::SUCCESS ){
89 log << MSG::ERROR << "can not use MdcGeomSvc" << endreq;
90 return StatusCode::FAILURE;
91 }
92
93 if(m_fixSigma) cout << "Fix MDC sigma to " << m_fixSigmaValue << " micron." << endl;
94
95 m_updateNum = 0;
96 for(int wir=0; wir<6796; wir++) m_wireEff[wir] = 1.0;
97 for(int lay=0; lay<NLAYER; lay++){
98 for(int iEntr=0; iEntr<NXTENTR; iEntr++){
99 for(int lr=0; lr<2; lr++) m_nR2t[lay][iEntr][lr] = 0;
100 }
101 }
102
103 return StatusCode::SUCCESS;
104}
105
107 MsgStream log(messageService(), name());
108 log << MSG::INFO << "MdcCalibFunSvc::finalize()" << endreq;
109
110 m_xtmap.clear();
111 m_t0.clear();
112 m_delt0.clear();
113 m_qtpar0.clear();
114 m_qtpar1.clear();
115 m_sdmap.clear();
116
117 return StatusCode::SUCCESS;
118}
119
120void MdcCalibFunSvc::handle(const Incident& inc){
121 MsgStream log( messageService(), name() );
122 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
123
124 if ( inc.type() == "NewRun" ){
125 log << MSG::DEBUG << "NewRun" << endreq;
126
127 if( ! initCalibConst() ){
128 log << MSG::ERROR
129 << "can not initilize Mdc Calib Constants" << endl
130 << " Please insert the following statement "
131 << "in your \"jobOption.txt\" "
132 << "before the include file of Mdc Reconstruction: "
133 << endl << " "
134 << "#include \"$CALIBSVCROOT/share/job-CalibData.txt\""
135 << endl
136 << " If still error, please contact with Wu Linghui "
137 << "([email protected])."
138 << endreq;
139 }
140 }
141}
142
143double MdcCalibFunSvc::getTprop(int lay, double z) const{
144 double vp = getVprop(lay);
145 double tp = fabs(z - m_zst[lay]) / vp;
146 return tp;
147}
148
149double MdcCalibFunSvc::driftTimeToDist(double drifttime, int layid, int cellid,
150 int lr, double entrance) const {
151 double dist;
152 if(0 == m_xtMode){
153 dist = t2dPoly(drifttime, layid, cellid, lr, entrance);
154 } else{
155 if((0==lr) || (1==lr)) dist = t2dInter(drifttime, layid, cellid, lr, entrance);
156 else{
157 double dl = t2dInter(drifttime, layid, cellid, lr, entrance);
158 double dr = t2dInter(drifttime, layid, cellid, lr, entrance);
159 dist = (dl + dr) * 0.5;
160 }
161 }
162// cout << setw(15) << drifttime << setw(15) << dist << endl;
163 if(m_linearXT) dist = 0.03 * drifttime;
164 return dist;
165}
166
167double MdcCalibFunSvc::t2dPoly(double drifttime, int layid, int cellid,
168 int lr, double entrance) const {
169 int ord;
170 double xtpar[8];
171 double dist = 0.0;
172
173 int entr = getXtEntrIndex(entrance);
174 getXtpar(layid, entr, lr, xtpar);
175
176 if(drifttime < xtpar[6]){
177 for(ord=0; ord<6; ord++){
178 dist += xtpar[ord] * pow(drifttime, ord);
179 }
180 } else{
181 for(ord=0; ord<6; ord++){
182 dist += xtpar[ord] * pow(xtpar[6], ord);
183 }
184 dist += xtpar[7] * (drifttime - xtpar[6]);
185 }
186
187 return dist;
188}
189
190double MdcCalibFunSvc::t2dInter(double drifttime, int layid, int cellid,
191 int lr, double entrance) const {
192 double dist;
193 int iEntr = getXtEntrIndex(entrance);
194 int nBin = m_nNewXt[layid][iEntr][lr];
195 if(drifttime < m_vt[layid][iEntr][lr][0]){
196 dist = m_vd[layid][iEntr][lr][0];
197 } else if(drifttime < m_vt[layid][iEntr][lr][nBin-1]){
198 for(int i=0; i<(nBin-1); i++){
199 if((drifttime>=m_vt[layid][iEntr][lr][i]) && (drifttime<m_vt[layid][iEntr][lr][i+1])){
200 double t1 = m_vt[layid][iEntr][lr][i];
201 double t2 = m_vt[layid][iEntr][lr][i+1];
202 double d1 = m_vd[layid][iEntr][lr][i];
203 double d2 = m_vd[layid][iEntr][lr][i+1];
204 dist = (drifttime-t1) * (d2-d1) / (t2-t1) + d1;
205 break;
206 }
207 }
208 } else{
209 dist = m_vd[layid][iEntr][lr][nBin-1];
210 }
211 return dist;
212}
213
214double MdcCalibFunSvc::distToDriftTime(double dist, int layid, int cellid,
215 int lr, double entrance) const {
216 int i = 0;
217 double time;
218 int ord;
219 double xtpar[8];
220 double dxdtpar[5];
221 double x;
222 double dxdt;
223 double deltax;
224
225 int entr = getXtEntrIndex(entrance);
226 getXtpar(layid, entr, lr, xtpar);
227
228 double tm1 = xtpar[6];
229 double tm2 = 2000.0;
230 double dm1 = driftTimeToDist(tm1, layid, cellid, lr, entrance);
231 double dm2 = driftTimeToDist(tm2, layid, cellid, lr, entrance);
232
233 if(dist < 0){
234 cout << "Warning in MdcCalibFunSvc: driftDist < 0" << endl;
235 time = 0.0;
236 } else if(dist < xtpar[0]){
237 time = 0.0;
238 } else if(dist < dm1){
239 for(ord=0; ord<5; ord++){
240 dxdtpar[ord] = (double)(ord+1) * xtpar[ord+1];
241 }
242 time = dist / 0.03;
243 while(1){
244 if( i > 50 ){
245 cout << "Warning in MdcCalibFunSvc: "
246 << "can not get the exact value in the dist-to-time conversion."
247 << endl;
248 time = dist / 0.03;
249 break;
250 }
251
252 x = 0.0;
253 for(ord=0; ord<6; ord++)
254 x += xtpar[ord] * pow(time, ord);
255
256 deltax = x - dist;
257 if( fabs(deltax) < 0.001 ){
258 break;
259 }
260
261 dxdt = 0.0;
262 for(ord=0; ord<5; ord++)
263 dxdt += dxdtpar[ord] * pow(time, ord);
264
265 time = time - (deltax / dxdt);
266 i++;
267 }
268 } else if(dist < dm2){
269 time = (dist - dm1) * (tm2 - tm1) / (dm2 - dm1) + tm1;
270 } else{
271 time = tm2;
272 }
273
274 if(m_linearXT) time = dist / 0.03;
275 return time;
276}
277
278double MdcCalibFunSvc::getSigma(int layid, int lr, double dist,
279 double entrance, double tanlam,
280 double z, double Q) const {
281 double sigma;
282 if( (0 == lr) || (1 == lr) ){
283 sigma = getSigmaLR(layid, lr, dist, entrance, tanlam, z, Q);
284 } else{
285 double sl = getSigmaLR(layid, 0, dist, entrance, tanlam, z, Q);
286 double sr = getSigmaLR(layid, 1, dist, entrance, tanlam, z, Q);
287 sigma = (sl + sr) * 0.5;
288 }
289
290 if(m_fixSigma) sigma = 0.001 * m_fixSigmaValue;
291 if(layid == m_layInfSig) sigma = 9999.0;
292 return sigma;
293}
294
295double MdcCalibFunSvc::getSigmaLR(int layid, int lr, double dist,
296 double entrance, double tanlam,
297 double z, double Q) const {
298
299 double sigma = 9999.0;
300 double par[NSDBIN];
301
302 int entr = getSdEntrIndex(entrance);
303 getSdpar(layid, entr, lr, par);
304
305 int nmaxBin;
306 double dw = 0.5; // width of each distance bin
307 double dmin = 0.25; // mm
308 if(layid < 8){
309 nmaxBin = 20; // 11->20 2011-12-10
310 } else{
311 nmaxBin = 20; // 15->20 2011-12-10
312 }
313
314 double dref[2];
315 double distAbs = fabs(dist);
316 if(distAbs < dmin){
317 sigma = par[0];
318 } else{
319 int bin = (int)((distAbs - dmin) / dw);
320 if(bin >= nmaxBin){
321 sigma = par[nmaxBin];
322 } else if(bin < 0){
323 sigma = par[0];
324 } else{
325 dref[0] = (double)bin * dw + 0.25;
326 dref[1] = (double)(bin+1) * dw + 0.25;
327 if((dref[1] - dref[0]) <= 0){
328 sigma = 9999.0;
329 } else{
330 sigma = (par[bin+1] - par[bin]) * (distAbs - dref[0]) /
331 (dref[1] - dref[0]) + par[bin];
332 }
333 }
334 }
335 return sigma;
336}
337
338double MdcCalibFunSvc::getSigma1(int layid, int lr, double dist,
339 double entrance, double tanlam,
340 double z, double Q) const {
341 double sigma1 = getSigma(layid, lr, dist, entrance, tanlam, z, Q);
342 return sigma1;
343}
344
345double MdcCalibFunSvc::getSigma2(int layid, int lr, double dist,
346 double entrance, double tanlam,
347 double z, double Q) const {
348
349 return 0.0;
350}
351
352double MdcCalibFunSvc::getF(int layid, int lr, double dist,
353 double entrance, double tanlam,
354 double z, double Q) const {
355
356 return 1.0;
357}
358
359double MdcCalibFunSvc::getSigmaToT(int layid, int lr, double tdr, double entrance,
360 double tanlam, double z, double Q) const{
361 if(!m_fgR2t){
362 cout << "ERROR: can not get sigma-time functions" << endl;
363 return -999.0;
364 } else if( (0 == lr) || (1 == lr) ){
365 return getSigmaToTLR(layid, lr, tdr, entrance, tanlam, z, Q);
366 } else{
367 double sl = getSigmaToTLR(layid, 0, tdr, entrance, tanlam, z, Q);
368 double sr = getSigmaToTLR(layid, 1, tdr, entrance, tanlam, z, Q);
369 double sigma = (sl + sr) * 0.5;
370 return sigma;
371 }
372}
373
374double MdcCalibFunSvc::getSigmaToTLR(int layid, int lr, double tdr, double entrance,
375 double tanlam, double z, double Q) const{
376 double sigma;
377 int iEntr = getXtEntrIndex(entrance);
378 int nBin = m_nR2t[layid][iEntr][lr];
379 if(tdr < m_tR2t[layid][iEntr][lr][0]){
380 sigma = m_sR2t[layid][iEntr][lr][0];
381 } else if(tdr < m_tR2t[layid][iEntr][lr][nBin-1]){
382 for(int i=0; i<(nBin-1); i++){
383 if((tdr>=m_tR2t[layid][iEntr][lr][i]) && (tdr<m_tR2t[layid][iEntr][lr][i+1])){
384 double t1 = m_tR2t[layid][iEntr][lr][i];
385 double t2 = m_tR2t[layid][iEntr][lr][i+1];
386 double s1 = m_sR2t[layid][iEntr][lr][i];
387 double s2 = m_sR2t[layid][iEntr][lr][i+1];
388 sigma = (tdr-t1) * (s2-s1) / (t2-t1) + s1;
389 break;
390 }
391 }
392 } else{
393 sigma = m_sR2t[layid][iEntr][lr][nBin-1];
394 }
395 return sigma;
396}
397
398int MdcCalibFunSvc::getNextXtpar(int& key, double& par){
399 if( m_xtiter != m_xtmap.end() ){
400 key = (*m_xtiter).first;
401 par = (*m_xtiter).second;
402 m_xtiter++;
403 return 1;
404 }
405 else return 0;
406}
407
408void MdcCalibFunSvc::getXtpar(int layid, int entr, int lr, double par[]) const{
409 int parId;
410 for(int ord=0; ord<8; ord++){
411 parId = getXtparId(layid, entr, lr, ord);
412 par[ord] = m_xtpar[parId];
413 }
414}
415
417 MsgStream log(messageService(), name());
418 log << MSG::INFO << "read calib const from TCDS" << endreq;
419
420 for(int layid=0; layid<NLAYER; layid++){
421 for(int entr=0; entr<NXTENTR; entr++){
422 for(int lr=0; lr<2; lr++){
423 double br_t,br_d;
424 TTree* newXtTree = getNewXtparTree(layid,entr,lr);
425 if(!newXtTree) return false;
426 newXtTree -> SetBranchAddress("t", &br_t);
427 newXtTree -> SetBranchAddress("d", &br_d);
428 int nEntries = newXtTree -> GetEntries();
429 if((nEntries<10) || (nEntries>=200)){
430 log << MSG::ERROR << "wrong X-T constants: layer " << layid
431 << ", iEntr " << entr << ", lr " << lr << endreq;
432 return false;
433 }
434 m_nNewXt[layid][entr][lr] = nEntries;
435 for(int i=0; i<nEntries; i++){
436 newXtTree->GetEntry(i);
437 m_vt[layid][entr][lr][i] = br_t;
438 m_vd[layid][entr][lr][i] = br_d;
439 }//end loop entries
440 }//end lr
441 }//end entr
442 }//end layid
443
444 return true;
445}
446
447TTree* MdcCalibFunSvc::getNewXtparTree(int layid, int entr, int lr) const{
448 MsgStream log(messageService(), name());
449 string fullPath = "/Calib/MdcCal";
450 SmartDataPtr<CalibData::MdcCalibData> calConst(m_pCalDataSvc, fullPath);
451 if( ! calConst ){
452 log << MSG::ERROR << "can not get MdcCalibConst via SmartPtr" << endreq;
453 return NULL;
454 }
455
456 TTree* newXtTree = calConst->getNewXtpar(layid,entr,lr);
457 return newXtTree;
458}
459
461 for(int layid=0; layid<NLAYER; layid++){
462 int br_iEntr,br_lr;
463 double br_s,br_t;
464 TTree* r2tTree = getR2tTree(layid);
465 if(!r2tTree) return false;
466 r2tTree -> SetBranchAddress("iEntr", &br_iEntr);
467 r2tTree -> SetBranchAddress("lr", &br_lr);
468 r2tTree -> SetBranchAddress("s", &br_s);
469 r2tTree -> SetBranchAddress("t", &br_t);
470 int nEntries = r2tTree -> GetEntries();
471 for(int i=0; i<nEntries; i++){
472 r2tTree->GetEntry(i);
473 int bin = m_nR2t[layid][br_iEntr][br_lr];
474 if(bin>=200){
475 cout << "Error: number of sigma-time bins overflow" << endl;
476 return false;
477 }
478 m_tR2t[layid][br_iEntr][br_lr][bin] = br_t;
479 m_sR2t[layid][br_iEntr][br_lr][bin] = br_s;
480 m_nR2t[layid][br_iEntr][br_lr]++;
481 }
482 }
483 for(int layid=0; layid<NLAYER; layid++){
484 for(int iEntr=0; iEntr<NXTENTR; iEntr++){
485 for(int lr=0; lr<2; lr++){
486 if((m_nR2t[layid][iEntr][lr]<10) || (m_nR2t[layid][iEntr][lr]>=200)) return false;
487 }
488 }
489 }
490 return true;
491}
492
493TTree* MdcCalibFunSvc::getR2tTree(int layid) const{
494 MsgStream log(messageService(), name());
495 string fullPath = "/Calib/MdcCal";
496 SmartDataPtr<CalibData::MdcCalibData> calConst(m_pCalDataSvc, fullPath);
497 if( ! calConst ){
498 log << MSG::ERROR << "can not get MdcCalibConst via SmartPtr" << endreq;
499 return NULL;
500 }
501
502 TTree* r2tTree = calConst->getR2tpar(layid);
503 return r2tTree;
504}
505
506
507double MdcCalibFunSvc::getT0(int layid, int cellid) const {
508 int wireid = m_pMdcGeomSvc->Wire(layid, cellid)->Id();
509 double t0 = getT0(wireid);
510
511 return t0;
512}
513
514double MdcCalibFunSvc::getTimeWalk(int layid, double Q) const {
515 double tw = 0.0;
516 double qtpar[2];
517 int ord;
518
519 if(Q < 0.0001) Q = 0.0001;
520
521 for(ord=0; ord<2; ord++){
522 qtpar[ord] = getQtpar(layid, ord);
523 }
524
525 tw = qtpar[0] + qtpar[1] / sqrt( Q );
526 if(m_run < 0) tw = 0.0; // for MC
527
528 return tw;
529}
530
531double MdcCalibFunSvc::getWireEff(int layid, int cellid) const {
532 int wireid = m_pMdcGeomSvc->Wire(layid, cellid)->Id();
533 return m_wireEff[wireid];
534}
535
536double MdcCalibFunSvc::getQtpar(int layid, int ord) const {
537 if(0 == ord) return m_qtpar0[layid];
538 else if(1 == ord) return m_qtpar1[layid];
539 else {
540 cout << "wrong order number" << endl;
541 return 0.0;
542 }
543}
544
545void MdcCalibFunSvc::getSdpar(int layid, int entr, int lr, double par[]) const{
546 int parId;
547 if( (entr < 0) || (entr >= 18) ){
548 entr = 17;
549 }
550 for(int bin=0; bin<NSDBIN; bin++){
551 parId = getSdparId(layid, entr, lr, bin);
552 par[bin] = m_sdpar[parId];
553 }
554}
555
556int MdcCalibFunSvc::getNextSdpar(int& key, double& par){
557 if( m_sditer != m_sdmap.end() ){
558 key = (*m_sditer).first;
559 par = (*m_sditer).second;
560 m_sditer++;
561 return 1;
562 }
563 else return 0;
564}
565
566int MdcCalibFunSvc::getXtEntrIndex(double entrance) const {
567 int i;
568 int index;
569 int idmax = 17;
570 double aglpi = 3.141592653;
571 double aglmin = -1.570796327; // -90 degree
572 double aglmax = 1.570796327; // 90 degree
573 double delAngle = 0.174532925; // 10 degree
574
575 MsgStream log(messageService(), name());
576 if(entrance < aglmin){
577 log << MSG::WARNING << "entrance angle < -pi/2" << endreq;
578 while(1){
579 entrance += aglpi;
580 if(entrance >= aglmin) break;
581 }
582 } else if(entrance > aglmax){
583 log << MSG::WARNING << "entrance angle > pi/2" << endreq;
584 while(1){
585 entrance -= aglpi;
586 if(entrance <= aglmax) break;
587 }
588 }
589
590 index = (int)((entrance-aglmin) / delAngle);
591 if(index < 0) index = 0;
592 else if(index > idmax) index = idmax;
593
594 return index;
595}
596
597int MdcCalibFunSvc::getSdEntrIndex(double entrance) const {
598 int i;
599 int index;
600 int idmax = 5;
601 double aglpi = 3.141592653;
602 double aglmin = -1.570796327; // -90 degree
603 double aglmax = 1.570796327; // 90 degree
604 double delAngle = 0.523598776; // 30 degree
605
606 MsgStream log(messageService(), name());
607 if(entrance < aglmin){
608 log << MSG::WARNING << "entrance angle < -pi/2" << endreq;
609 while(1){
610 entrance += aglpi;
611 if(entrance >= aglmin) break;
612 }
613 } else if(entrance > aglmax){
614 log << MSG::WARNING << "entrance angle > pi/2" << endreq;
615 while(1){
616 entrance -= aglpi;
617 if(entrance <= aglmax) break;
618 }
619 }
620
621 index = (int)((entrance-aglmin) / delAngle);
622 if(index < 0) index = 0;
623 else if(index > idmax) index = idmax;
624
625 return index;
626}
627
628bool MdcCalibFunSvc::initCalibConst(){
629 MsgStream log(messageService(), name());
630 log << MSG::INFO << "read calib const from TCDS" << endreq;
631
632 IDataProviderSvc* eventSvc = NULL;
633 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
634 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
635 if (!eventHeader) {
636 log << MSG::FATAL << "Could not find Event Header" << endreq;
637 return( StatusCode::FAILURE);
638 }
639 m_run = eventHeader->runNumber();
640
641 // clear calibration constants vectors
642 m_xtmap.clear();
643 m_xtpar.clear();
644 m_t0.clear();
645 m_delt0.clear();
646 m_qtpar0.clear();
647 m_qtpar1.clear();
648 m_sdmap.clear();
649 m_sdpar.clear();
650
651 string fullPath = "/Calib/MdcCal";
652 SmartDataPtr<CalibData::MdcCalibData> calConst(m_pCalDataSvc, fullPath);
653 if( ! calConst ){
654 log << MSG::ERROR << "can not get MdcCalibConst via SmartPtr"
655 << endreq;
656 return false;
657 }
658
659 // initialize XT parameter
660 int layid;
661 int entr;
662 int lr;
663 int ord;
664 int key;
665 double par;
666 calConst -> setXtBegin();
667 while( calConst->getNextXtpar(key, par) ){
668 m_xtmap.insert( valType(key, par) );
669 }
670
671 int parId;
672 unsigned mapsize = m_xtmap.size();
673 m_xtpar.resize(mapsize);
674 log << MSG::INFO << "size of xtmap: " << mapsize << endreq;
675
676 calConst -> setXtBegin();
677 while( calConst->getNextXtpar(key, par) ){
678 layid = (key >> XTLAYER_INDEX) & XTLAYER_DECO;
679 entr = (key >> XTENTRA_INDEX) & XTENTRA_DECO;
680 lr = (key >> XTLR_INDEX) & XTLR_DECO;
681 ord = (key >> XTORDER_INDEX) & XTORDER_DECO;
682
683 parId = getXtparId(layid, entr, lr, ord);
684 m_xtpar[parId] = par;
685 }
686
687 // initialize T0 parameter
688 int wid;
689 double t0;
690 double delt0;
691 for(wid=0; wid<NWIRE; wid++){
692 t0 = calConst->getT0(wid);
693 delt0 = calConst->getDelT0(wid);
694
695 m_t0.push_back(t0);
696 m_delt0.push_back(delt0);
697 }
698
699 // initialize QT parameter
700 double qtpar0;
701 double qtpar1;
702 for(layid=0; layid<NLAYER; layid++){
703 qtpar0 = calConst -> getQtpar0(layid);
704 qtpar1 = calConst -> getQtpar1(layid);
705
706 m_qtpar0.push_back(qtpar0);
707 m_qtpar1.push_back(qtpar1);
708 }
709
710 // initialize resolution parameter
711 calConst -> setSdBegin();
712 while( calConst -> getNextSdpar(key, par) ){
713 m_sdmap.insert( valType(key, par) );
714// cout << setw(15) << key << setw(15) << par << endl;
715 }
716
717 mapsize = m_sdmap.size();
718 m_sdpar.resize(mapsize);
719 log << MSG::INFO << "size of sdmap: " << mapsize << endreq;
720
721 calConst -> setSdBegin();
722 while( calConst -> getNextSdpar(key, par) ){
723 layid = (key >> SDLAYER_INDEX) & SDLAYER_DECO;
724 entr = (key >> SDENTRA_INDEX) & SDENTRA_DECO;
725 lr = (key >> SDLR_INDEX) & SDLR_DECO;
726 ord = (key >> SDBIN_INDEX) & SDBIN_DECO;
727
728 parId = getSdparId(layid, entr, lr, ord);
729 m_sdpar[parId] = par;
730 }
731
732 double zeast;
733 double zwest;
734 for(layid=0; layid<NLAYER; layid++){
735 zwest = m_pMdcGeomSvc->Wire(layid, 0)->Forward().z();
736 zeast = m_pMdcGeomSvc->Wire(layid, 0)->Backward().z();
737
738 if(0 == (layid % 2)) m_zst[layid] = zwest; // west end
739 else m_zst[layid] = zeast; // east end
740 }
741
742 // read new-XT
743 log << MSG::INFO << "read new xt from TCDS" << endreq;
744 if (!getNewXtpar()){
745 log << MSG::WARNING << "can not get MDC New XT Trees" << endreq;
746 m_xtMode = 0;
747 }
748 if(m_run < 0) m_xtMode = 0;
749 if(0 == m_xtMode) log << MSG::INFO << "use old X-T functions " << endreq;
750 else log << MSG::INFO << "use new X-T functions " << endreq;
751 if(m_outputXtMode){
752 if(0 == m_xtMode) cout << "use old X-T functions " << endl;
753 else cout << "use new X-T functions " << endl;
754 m_outputXtMode = false;
755 }
756
757 // read r-t
758 for(layid=0; layid<NLAYER; layid++){
759 for(entr=0; entr<NXTENTR; entr++){
760 for(lr=0; lr<2; lr++) m_nR2t[layid][entr][lr] = 0;
761 }
762 }
763 m_fgR2t = true;
764 log << MSG::INFO << "read new sigma-time from TCDS" << endreq;
765 if (!getR2tpar()){
766 log << MSG::WARNING << "can not get sigma-time functions" << endreq;
767 m_fgR2t = false;
768 } else{
769 log << MSG::INFO << "read sigma-time successfully " << endreq;
770 }
771
772 // read wire efficiency
773 if(m_readWireEffDb){
774 fullPath = "/Calib/MdcDataConst";
775 log << MSG::INFO <<"Read Wire Eff from TCDS: "<< fullPath << endreq;
776 log << MSG::INFO << "Read wire eff!" << endreq;
777
778 SmartDataPtr<CalibData::MdcDataConst> dataConst(m_pCalDataSvc, fullPath);
779 if(!dataConst){
780 log << MSG::ERROR << "can not get MdcDataConst via SmartPtr" << endreq;
781 return false;
782 }
783 for(int wir=0; wir<NWIRE; wir++) {
784 m_wireEff[wir] = dataConst->getWireEff(wir);
785 }
786 } else{
787 log << MSG::INFO <<"Read Wire Eff from file: "<< m_wireEffFile << endreq;
788 ifstream fEff(m_wireEffFile.c_str());
789 if(!fEff.is_open()){
790 log << MSG::ERROR << "can not open wire eff file: " << m_wireEffFile << endreq;
791 return false;
792 } else{
793 string strtmp;
794 for(int i=0; i<4; i++) fEff >> strtmp;
795 for(int wir=0; wir<NWIRE; wir++) fEff >> strtmp >> strtmp >> strtmp >> m_wireEff[wir];
796 fEff.close();
797 }
798 }
799 if(m_checkConst) checkConst();
800 m_updateNum++;
801
802 return true;
803}
804
805int MdcCalibFunSvc::getXtKey(int layid, int lr, int ord, int entr) const{
806
807 int key = ( (layid << XTLAYER_INDEX) & XTLAYER_MASK ) |
808 ( (entr << XTENTRA_INDEX) & XTENTRA_MASK ) |
809 ( (lr << XTLR_INDEX) & XTLR_MASK ) |
810 ( (ord << XTORDER_INDEX) & XTORDER_MASK );
811
812 return key;
813}
814
815int MdcCalibFunSvc::getSdKey(int layid, int entr, int lr, int ord) const {
816 int key = ( (layid << SDLAYER_INDEX) & SDLAYER_MASK ) |
817 ( (entr << SDENTRA_INDEX) & SDENTRA_MASK ) |
818 ( (lr << SDLR_INDEX) & SDLR_MASK ) |
819 ( (ord << SDBIN_INDEX) & SDBIN_MASK );
820
821 return key;
822}
823
824void MdcCalibFunSvc::checkConst(){
825 char fname[200];
826 sprintf(fname, "checkXt_%d.txt", m_updateNum);
827 ofstream fxt(fname);
828 unsigned mapsize = m_xtmap.size();
829 unsigned vsize = m_xtpar.size();
830 fxt << setw(10) << mapsize << setw(10) << vsize << endl << endl;
831 int key;
832 double par;
833 std::map<int, double>::iterator xtiter = m_xtmap.begin();
834 while( xtiter != m_xtmap.end() ){
835 key = (*xtiter).first;
836 par = (*xtiter).second;
837 fxt << setw(20) << key << setw(20) << par << endl;
838 xtiter++;
839 }
840 fxt << endl;
841 for(unsigned i=0; i<vsize; i++){
842 fxt << setw(5) << i << setw(15) << m_xtpar[i] << endl;
843 }
844 fxt.close();
845
846 sprintf(fname, "checkT0_%d.txt", m_updateNum);
847 ofstream ft0(fname);
848 ft0 << setw(10) << m_t0.size() << setw(10) << m_delt0.size() << endl;
849 for(unsigned i=0; i<m_t0.size(); i++){
850 ft0 << setw(5) << i << setw(15) << m_t0[i] << setw(15) << m_delt0[i] << endl;
851 }
852 ft0.close();
853
854 sprintf(fname, "checkQt_%d.txt", m_updateNum);
855 ofstream fqt(fname);
856 fqt << setw(10) << m_qtpar0.size() << setw(10) << m_qtpar1.size() << endl;
857 for(unsigned i=0; i<m_qtpar0.size(); i++){
858 fqt << setw(5) << i << setw(15) << m_qtpar0[i] << setw(15) << m_qtpar1[i] << endl;
859 }
860 fqt.close();
861
862 sprintf(fname, "checkSd_%d.txt", m_updateNum);
863 ofstream fsd(fname);
864 mapsize = m_sdmap.size();
865 vsize = m_sdpar.size();
866 fsd << setw(10) << mapsize << setw(10) << vsize << endl << endl;
867 std::map<int, double>::iterator sditer = m_sdmap.begin();
868 while( sditer != m_sdmap.end() ){
869 key = (*sditer).first;
870 par = (*sditer).second;
871 fsd << setw(20) << key << setw(20) << par << endl;
872 sditer++;
873 }
874 fsd << endl;
875 for(unsigned i=0; i<vsize; i++){
876 fsd << setw(5) << i << setw(15) << m_sdpar[i] << endl;
877 }
878 fsd.close();
879
880 sprintf(fname, "checkNewXt_%d.txt", m_updateNum);
881 ofstream fnewxt(fname);
882 for(int lay=0; lay<43; lay++){
883 for(int iEntr=0; iEntr<18; iEntr++){
884 for(int lr=0; lr<2; lr++){
885 fnewxt << setw(5) << lay << setw(5) << iEntr << setw(3) << lr
886 << setw(5) << m_nNewXt[lay][iEntr][lr] << endl;
887 for(int bin=0; bin<m_nNewXt[lay][iEntr][lr]; bin++){
888 fnewxt << setw(15) << m_vt[lay][iEntr][lr][bin]
889 << setw(15) << m_vd[lay][iEntr][lr][bin] << endl;
890 }
891 }
892 }
893 }
894 fnewxt.close();
895
896 sprintf(fname, "checkR2t_%d.txt", m_updateNum);
897 ofstream fr2t(fname);
898 for(int lay=0; lay<43; lay++){
899 for(int iEntr=0; iEntr<18; iEntr++){
900 for(int lr=0; lr<2; lr++){
901 fr2t << setw(5) << lay << setw(5) << iEntr << setw(3) << lr
902 << setw(5) << m_nR2t[lay][iEntr][lr] << endl;
903 for(int bin=0; bin<m_nR2t[lay][iEntr][lr]; bin++){
904 fr2t << setw(15) << m_tR2t[lay][iEntr][lr][bin]
905 << setw(15) << m_sR2t[lay][iEntr][lr][bin] << endl;
906 }
907 }
908 }
909 }
910 fr2t.close();
911}
912
std::map< int, double >::value_type valType
data SetBranchAddress("time",&time)
Double_t x[10]
Double_t time
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
Definition: FoamA.h:85
map< int, double >::value_type valType
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
Definition: Taupair.h:42
virtual const MdcGeoWire *const Wire(unsigned id)=0
int getNextXtpar(int &key, double &par)
virtual StatusCode finalize()
double getSigmaToT(int layid, int lr, double tdr, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
int getSdEntrIndex(double entrance) const
TTree * getR2tTree(int layid) const
double getSigmaToTLR(int layid, int lr, double tdr, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
void getSdpar(int layid, int entr, int lr, double par[]) const
double distToDriftTime(double dist, int layid, int cellid, int lr, double entrance=0.0) const
double getSigma2(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
double getWireEff(int layid, int cellid) const
double getSigma(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
double getT0(int layid, int cellid) const
double driftTimeToDist(double drifttime, int layid, int cellid, int lr, double entrance=0.0) const
double getSigmaLR(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
double getQtpar(int layid, int ord) const
TTree * getNewXtparTree(int layid, int entr, int lr) const
void getXtpar(int layid, int entr, int lr, double par[]) const
MdcCalibFunSvc(const std::string &name, ISvcLocator *svcloc)
double getSigma1(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
int getXtEntrIndex(double entrance) const
virtual StatusCode initialize()
void handle(const Incident &)
int getNextSdpar(int &key, double &par)
double getTprop(int lay, double z) const
double getF(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
double getTimeWalk(int layid, double Q) const
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)