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