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