34 base_class (name, svcloc){
37 declareProperty(
"UseDatabase",m_dbFlag =
false);
38 declareProperty(
"UseEndcapTuning",m_EndcapTuning = 1);
39 declareProperty(
"EffFile", m_effFile = std::string(
"no path"));
40 declareProperty(
"ResFile", m_resFile = std::string(
"no path"));
41 declareProperty(
"EffFile_endcap", m_effFile_endcap = std::string(
"no path"));
42 declareProperty(
"ResFile_endcap", m_resFile_endcap = std::string(
"no path"));
43 declareProperty(
"path_mdc", m_path = std::string(
"no path"));
44 declareProperty(
"Host" , host = std::string(
"bes3db2.ihep.ac.cn"));
45 declareProperty(
"DbName" , dbName = std::string(
"offlinedb"));
46 declareProperty(
"UserName" , userName = std::string(
"guest"));
47 declareProperty(
"Password" , password = std::string(
"guestpass"));
48 declareProperty(
"SerialNo" , serialNo = 0);
49 declareProperty(
"fromDB", m_fromDB =
true);
50 declareProperty(
"ParBossVer", m_ParBossVer = std::string(
"unknown"));
52 int no[43]={40,44,48,56,64,72,80,80,76,76,88,88,100,100,112,112,128,128,140,140,160,160,160,160,176,176,176,176,208,208,208,208,240,240,240,240,256,256,256,256,288,288,288};
54 for(
int i=0;i<43;i++){
193 double lay,
bin,expect,hit;
195 std::istringstream readMCEff;
198 readMCEff.str(eff_con);
201 ifstream in(eff_con.c_str());
207 istreambuf_iterator<char>
iter(in) ;
208 string strCache = string(
iter, (istreambuf_iterator<char>()) );
209 readMCEff.str(strCache);
214 ifstream fin(eff_con.c_str());
217 cout <<
" ERROR: the mdc tunning eff file " << m_effFile <<
" not exist, please check the input! " << endl;
221 if(!readMCEff.good()){
222 cout <<
" ERROR: mdc tuning eff file " << m_effFile <<
" not exist. " << endl;
227 cout <<
" Open mdc tuning eff file: " << m_effFile << endl;
230 getline(readMCEff,line);
231 for(j=0;j<docaNo;j++){
232 readMCEff>>
bin>>docaEff[i][j]>>expect>>hit;
235 getline(readMCEff,line);
236 for(j=0;j<thetaNo;j++){
237 readMCEff>>
bin>>thetaEff[i][j]>>expect>>hit;
240 getline(readMCEff,line);
241 for(j=0;j<cellNo[i];j++){
242 readMCEff>>
bin>>cellEff[i][j]>>expect>>hit;
248 getline(readMCEff,line);
249 for(j=0;j<docaNo;j++){
250 readMCEff>>
bin>>docaEff_2[i][j]>>expect>>hit;
253 getline(readMCEff,line);
254 for(j=0;j<thetaNo;j++){
255 readMCEff>>
bin>>thetaEff_2[i][j]>>expect>>hit;
259 getline(readMCEff,line);
260 for(j=0;j<cellNo[i];j++){
261 readMCEff>>
bin>>cellEff_2[i][j]>>expect>>hit;
310 std::istringstream readMCRes;
313 readMCRes.str(res_con);
317 ifstream in(res_con.c_str());
318 istreambuf_iterator<char>
iter(in) ;
319 string strCache = string(
iter, (istreambuf_iterator<char>()) );
320 readMCRes.str(strCache);
322 if(!readMCRes.good()){
323 cout <<
" ERROR: mdc tuning file: " << m_resFile <<
" not exist. " << endl;
326 cout <<
" MdcTunningSvc::setMcRes2() Open mdc tuning resfile " << m_resFile << endl;
329 getline(readMCRes,line);
330 getline(readMCRes,line);
331 for(j=0;j<docaNo;j++){
332 readMCRes>>
bin>>docaF[i][j][0]>>docaMean1[i][j][0]>>docaSigma1[i][j][0]>>docaMean2[i][j][0]>>docaSigma2[i][j][0];
335 getline(readMCRes,line);
336 getline(readMCRes,line);
337 for(j=0;j<docaNo;j++){
338 readMCRes>>
bin>>docaF[i][j][1]>>docaMean1[i][j][1]>>docaSigma1[i][j][1]>>docaMean2[i][j][1]>>docaSigma2[i][j][1];
343 getline(readMCRes,line);
344 getline(readMCRes,line);
345 for(j=0;j<docaNo;j++){
346 readMCRes>>
bin>>docaF_2[i][j][0]>>docaMean1_2[i][j][0]>>docaSigma1_2[i][j][0]>>docaMean2_2[i][j][0]>>docaSigma2_2[i][j][0];
349 getline(readMCRes,line);
350 getline(readMCRes,line);
351 for(j=0;j<docaNo;j++){
352 readMCRes>>
bin>>docaF_2[i][j][1]>>docaMean1_2[i][j][1]>>docaSigma1_2[i][j][1]>>docaMean2_2[i][j][1]>>docaSigma2_2[i][j][1];
365 std::istringstream readMCRes;
367 readMCRes.str(res_con);
370 ifstream in(res_con.c_str());
371 istreambuf_iterator<char>
iter(in) ;
372 string strCache = string(
iter, (istreambuf_iterator<char>()) );
373 readMCRes.str(strCache);
376 ifstream fin(res_con.c_str());
380 cout <<
" ERROR: the mdc tunning res file " << m_resFile <<
" not exist, please check the input!" << endl;
383 if(!readMCRes.good()){
384 cout <<
" ERROR: the mdc tuning res file: " << m_resFile <<
" not exist, please check the input! " << endl;
389 cout <<
" MdcTunningSvc::setMcRes3() Open mdc tuning resfile: " << m_resFile << endl;
392 getline(readMCRes,line);
393 getline(readMCRes,line);
394 for(j=0;j<docaNo;j++){
395 readMCRes>>
bin>>docaF[i][j][0]>>docaMean1[i][j][0]>>docaSigma1[i][j][0]>>docaMean2[i][j][0]>>docaSigma2[i][j][0]>>resLargest[i][j][0]>>resSmallest[i][j][0]>>resRatio[i][j][0];
398 getline(readMCRes,line);
399 getline(readMCRes,line);
400 for(j=0;j<docaNo;j++){
401 readMCRes>>
bin>>docaF[i][j][1]>>docaMean1[i][j][1]>>docaSigma1[i][j][1]>>docaMean2[i][j][1]>>docaSigma2[i][j][1]>>resLargest[i][j][1]>>resSmallest[i][j][1]>>resRatio[i][j][1];
407 getline(readMCRes,line);
408 getline(readMCRes,line);
409 for(j=0;j<docaNo;j++){
410 readMCRes>>
bin>>docaF_2[i][j][0]>>docaMean1_2[i][j][0]>>docaSigma1_2[i][j][0]>>docaMean2_2[i][j][0]>>docaSigma2_2[i][j][0]>>resLargest_2[i][j][0]>>resSmallest_2[i][j][0]>>resRatio_2[i][j][0];
413 getline(readMCRes,line);
414 getline(readMCRes,line);
415 for(j=0;j<docaNo;j++){
417 readMCRes>>
bin>>docaF_2[i][j][1]>>docaMean1_2[i][j][1]>>docaSigma1_2[i][j][1]>>docaMean2_2[i][j][1]>>docaSigma2_2[i][j][1]>>resLargest_2[i][j][1]>>resSmallest_2[i][j][1]>>resRatio_2[i][j][1];
467 for(
int jj =0;jj<9;jj++){
468 if((driftD<mindD)||(driftD>maxdD)){
470 }
else if((driftD>=jj)&&(driftD<(jj+1))){
474 double y0D = (m_BesMdcRes -> getD_dD(layerId ,bindD)) ;
475 double y1D = (m_BesMdcRes -> getD_dD(layerId, bindD+1)) ;
476 double yD = y0D + (y1D-y0D)*(driftD - bindD);
477 double y0M = (m_BesMdcRes -> getM_dD(layerId ,bindD)) ;
478 double y1M = (m_BesMdcRes -> getM_dD(layerId ,bindD+1));
479 double yM = y0M + (y1M-y0M)*(driftD - bindD);
480 double dely = yD - yM ;
500 double minCos = -0.8 ;
501 double minCos2 = -0.7 ;
502 double maxCos = 0.8 ;
504 for(
int ii = 0; ii <16; ii++){
505 if((costta<minCos)||(costta>maxCos)){
507 }
else if((costta>=(minCos + ii*0.1))&&(costta<(minCos2 + ii*0.1))){
512 double y0D = (m_BesMdcRes -> getD_theta(layerId ,binTa));
513 double y1D = (m_BesMdcRes -> getD_theta(layerId ,binTa+1));
514 double y0M = (m_BesMdcRes -> getM_theta(layerId,binTa));
515 double y1M = (m_BesMdcRes -> getM_theta(layerId,binTa+1));
517 double yD[16],yM[16],Del[16];
518 for(
int ll =0;ll<16;ll++){
519 yD[ll] = y0D + (y1D - y0D)/0.1*(costta - (minCos + ll*0.1));
520 yM[ll] = y0M + (y1M - y0D)/0.1*(costta - (minCos + ll*0.1));
521 Del[ll] = yD[ll] - yM[ll] ;
526 if((binTa>=0)&&(binTa<=5)){
527 delTha = Del[binTa] * 0.118 ;
528 }
else if((binTa>5)&&(binTa<=10)){
529 delTha = Del[binTa] * 0.518 ;
530 }
else if((binTa>10)&&(binTa<=15)){
531 delTha = Del[binTa] * 0.218 ;
545 if(posFlag==0)driftD *= -1;
547 if(layerId<0 || layerId>42)std::cout<<
" MdcTuningSvc:wrong LayerId "<<layerId<<std::endl;
548 if(cellId<0 || cellId>=cellNo[layerId])std::cout<<
"MdcTuningSvc:wrong cellId "<<cellId<<std::endl;
550 if(fabs(cosTheta)>1){
551 std::cout<<
"MdcTuningSvc:wrong coseTheta "<<cosTheta<<std::endl;
555 int thetaBin=(int)floor((cosTheta+1)*thetaNo/2.);
558 int docaBin=(int)floor((driftD+12)*docaNo/24.);
559 if(m_EndcapTuning==0)
560 eff = docaEff[layerId][docaBin] * thetaEff[layerId][thetaBin] * cellEff[layerId][cellId];
562 if(fabs(cosTheta)<=0.83)
563 eff = docaEff[layerId][docaBin] * thetaEff[layerId][thetaBin] * cellEff[layerId][cellId];
565 eff = docaEff_2[layerId][docaBin] * thetaEff_2[layerId][thetaBin] * cellEff_2[layerId][cellId];
576double MdcTunningSvc::GetRes(
int layerId,
int cellId,
double driftD,
double cosTheta,
int posFlag,
double entranceAngle,
double& mean,
double&
sigma){
583 if(posFlag==0)driftD *= -1;
585 if(layerId<0 || layerId>42)std::cout<<
" MdcTuningSvc:wrong LayerId "<<layerId<<std::endl;
586 if(cellId<0 || cellId>=cellNo[layerId])std::cout<<
"MdcTuningSvc:wrong cellId "<<cellId<<std::endl;
588 if(fabs(cosTheta)>1){
589 std::cout<<
"MdcTuningSvc:wrong cosTheta "<<cosTheta<<std::endl;
596 int docaBin=(int)floor((driftD+12)*docaNo/24.);
598 mean=docaRes[layerId][docaBin][0][0];
599 sigma=docaRes[layerId][docaBin][0][1];
601 mean=docaRes[layerId][docaBin][1][0];
602 sigma=docaRes[layerId][docaBin][1][1];
611double MdcTunningSvc::GetRes2(
int layerId,
int cellId,
double driftD,
double cosTheta,
int posFlag,
double entranceAngle,
double&
f,
double& mean1,
double& sigma1,
double& mean2,
double& sigma2){
618 if(posFlag==0)driftD *= -1;
620 if(layerId<0 || layerId>42)std::cout<<
" MdcTuningSvc:wrong LayerId "<<layerId<<std::endl;
621 if(cellId<0 || cellId>=cellNo[layerId])std::cout<<
"MdcTuningSvc:wrong cellId "<<cellId<<std::endl;
623 if(fabs(cosTheta)>1){
624 std::cout<<
"MdcTuningSvc:wrong cosTheta "<<cosTheta<<std::endl;
631 int docaBin=(int)floor((driftD+12)*docaNo/24.);
632 if(m_EndcapTuning==0) {
634 f=docaF[layerId][docaBin][0];
635 mean1=docaMean1[layerId][docaBin][0];
636 sigma1=docaSigma1[layerId][docaBin][0];
637 mean2=docaMean2[layerId][docaBin][0];
638 sigma2=docaSigma2[layerId][docaBin][0];
640 f=docaF[layerId][docaBin][1];
641 mean1=docaMean1[layerId][docaBin][1];
642 sigma1=docaSigma1[layerId][docaBin][1];
643 mean2=docaMean2[layerId][docaBin][1];
644 sigma2=docaSigma2[layerId][docaBin][1];
647 if(fabs(cosTheta)<=0.83) {
649 f=docaF[layerId][docaBin][0];
650 mean1=docaMean1[layerId][docaBin][0];
651 sigma1=docaSigma1[layerId][docaBin][0];
652 mean2=docaMean2[layerId][docaBin][0];
653 sigma2=docaSigma2[layerId][docaBin][0];
655 f=docaF[layerId][docaBin][1];
656 mean1=docaMean1[layerId][docaBin][1];
657 sigma1=docaSigma1[layerId][docaBin][1];
658 mean2=docaMean2[layerId][docaBin][1];
659 sigma2=docaSigma2[layerId][docaBin][1];
663 f=docaF_2[layerId][docaBin][0];
664 mean1=docaMean1_2[layerId][docaBin][0];
665 sigma1=docaSigma1_2[layerId][docaBin][0];
666 mean2=docaMean2_2[layerId][docaBin][0];
667 sigma2=docaSigma2_2[layerId][docaBin][0];
669 f=docaF_2[layerId][docaBin][1];
670 mean1=docaMean1_2[layerId][docaBin][1];
671 sigma1=docaSigma1_2[layerId][docaBin][1];
672 mean2=docaMean2_2[layerId][docaBin][1];
673 sigma2=docaSigma2_2[layerId][docaBin][1];
684double MdcTunningSvc::GetRes3(
int layerId,
int cellId,
double driftD,
double cosTheta,
int posFlag,
double entranceAngle,
double&
f,
double& mean1,
double& sigma1,
double& mean2,
double& sigma2,
double& ResLargest,
double& ResSmallest,
double& ResRatio){
691 if(posFlag==0)driftD *= -1;
693 if(layerId<0 || layerId>42)std::cout<<
" MdcTuningSvc:wrong LayerId "<<layerId<<std::endl;
694 if(cellId<0 || cellId>=cellNo[layerId])std::cout<<
"MdcTuningSvc:wrong cellId "<<cellId<<std::endl;
696 if(fabs(cosTheta)>1){
697 std::cout<<
"MdcTuningSvc:wrong cosTheta "<<cosTheta<<std::endl;
704 int docaBin=(int)floor((driftD+12)*docaNo/24.);
705 if(m_EndcapTuning==0) {
707 f=docaF[layerId][docaBin][0];
708 mean1=docaMean1[layerId][docaBin][0];
709 sigma1=docaSigma1[layerId][docaBin][0];
710 mean2=docaMean2[layerId][docaBin][0];
711 sigma2=docaSigma2[layerId][docaBin][0];
712 ResLargest=resLargest[layerId][docaBin][0];
713 ResSmallest=resSmallest[layerId][docaBin][0];
714 ResRatio=resRatio[layerId][docaBin][0];
717 f=docaF[layerId][docaBin][1];
718 mean1=docaMean1[layerId][docaBin][1];
719 sigma1=docaSigma1[layerId][docaBin][1];
720 mean2=docaMean2[layerId][docaBin][1];
721 sigma2=docaSigma2[layerId][docaBin][1];
722 ResLargest=resLargest[layerId][docaBin][1];
723 ResSmallest=resSmallest[layerId][docaBin][1];
724 ResRatio=resRatio[layerId][docaBin][1];
727 if(fabs(cosTheta)<=0.83) {
729 f=docaF[layerId][docaBin][0];
730 mean1=docaMean1[layerId][docaBin][0];
731 sigma1=docaSigma1[layerId][docaBin][0];
732 mean2=docaMean2[layerId][docaBin][0];
733 sigma2=docaSigma2[layerId][docaBin][0];
734 ResLargest=resLargest[layerId][docaBin][0];
735 ResSmallest=resSmallest[layerId][docaBin][0];
736 ResRatio=resRatio[layerId][docaBin][0];
738 f=docaF[layerId][docaBin][1];
739 mean1=docaMean1[layerId][docaBin][1];
740 sigma1=docaSigma1[layerId][docaBin][1];
741 mean2=docaMean2[layerId][docaBin][1];
742 sigma2=docaSigma2[layerId][docaBin][1];
743 ResLargest=resLargest[layerId][docaBin][1];
744 ResSmallest=resSmallest[layerId][docaBin][1];
745 ResRatio=resRatio[layerId][docaBin][1];
749 f=docaF_2[layerId][docaBin][0];
750 mean1=docaMean1_2[layerId][docaBin][0];
751 sigma1=docaSigma1_2[layerId][docaBin][0];
752 mean2=docaMean2_2[layerId][docaBin][0];
753 sigma2=docaSigma2_2[layerId][docaBin][0];
754 ResLargest=resLargest_2[layerId][docaBin][0];
755 ResSmallest=resSmallest_2[layerId][docaBin][0];
756 ResRatio=resRatio_2[layerId][docaBin][0];
758 f=docaF_2[layerId][docaBin][1];
759 mean1=docaMean1_2[layerId][docaBin][1];
760 sigma1=docaSigma1_2[layerId][docaBin][1];
761 mean2=docaMean2_2[layerId][docaBin][1];
762 sigma2=docaSigma2_2[layerId][docaBin][1];
763 ResLargest=resLargest_2[layerId][docaBin][1];
764 ResSmallest=resSmallest_2[layerId][docaBin][1];
765 ResRatio=resRatio_2[layerId][docaBin][1];
829 }
else{ driftD = driftD ;}
831 if( (driftD < mindD) || (driftD > maxdD) ){
834 for(
double dd =-9.; dd<9.;dd++){
836 if( (driftD>=dd ) && (driftD < (dd+1.)) ){
843 double y0D = (m_BesMdcRes -> getD_iEntr(lay,iEntr,bindD) );
844 double y1D = (m_BesMdcRes -> getD_iEntr(lay,iEntr,bindD+1) );
845 double yD = y0D + (y1D-y0D)*(driftD - dD[bindD]);
846 double y0M = (m_BesMdcRes -> getM_iEntr(lay,iEntr,bindD) );
847 double y1M = (m_BesMdcRes -> getM_iEntr(lay,iEntr,bindD+1));
848 double yM = y0M + (y1M-y0M)*(driftD - dD[bindD]);
849 double dely = yD - yM ;
861 MsgStream log(messageService(), name());
862 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
863 int run=eventHeader->runNumber();
865 log << MSG::INFO <<
"MdcTuningSvc::getMdcTuningTableInfo() run =" << run << endreq;
866 if(m_ParBossVer==std::string(
"unknown"))
867 cout <<
"MdcTuningSvc::getMdcTuningTableInfo() : ERROR: there is no ParBossVer " << endl;
868 else log << MSG::INFO <<
"MdcTuningSvc::getMdcTuningTableInfo() : ParBossVer = " << m_ParBossVer << endl;
877 for(
int i=0;i<1000;i++){
881 cout <<
" ==================== " << endl;
883 sprintf(stmt1,
"select MdcRes,MdcEff from MdcTuning where RunFrom <= %d and RunTo >= %d and SftVer = \"%s\"",run1,run1,m_ParBossVer.c_str());
884 cout <<
" stmt1: " << stmt1 << endl;
887 int status = m_dbsvc->
query(
"offlinedb",stmt1,result);
889 cout <<
" ERROR: can not read MdcRes, MdcEff from the MdcTuning table " << endl;
890 log << MSG::ERROR <<
" ERROR Read MdcRes, MdcEff from the MdcTuning table " << endreq;
891 return StatusCode::FAILURE;
894 if(result.size()>=1){
917 sprintf(stmt2,
"select MdcRes,MdcEff from MdcTuning where RunFrom <= %d and RunTo >= %d and SftVer = \"%s\"",run2,run2,m_ParBossVer.c_str());
920 status = m_dbsvc->
query(
"offlinedb",stmt2,result);
922 log << MSG::ERROR <<
" ERROR Read MdcRes, MdcEff.dEdxTuning from the MdcTuning table " << endreq;
923 return StatusCode::FAILURE;
927 if(result.size()>=1){
939 if(cnt!=0&&cnt!=1000) {
940 log << MSG::INFO <<
" get MDC tuning data from run " << run + cnt*j <<
" instead of run " << run<< endreq;
943 cout <<
" cnt = " << cnt << endl;
945 log << MSG::ERROR <<
" can not read Data from DB" << endreq;
947 return StatusCode::FAILURE;
959 int row = result.size()-1;
960 cout <<
" row = " << row << endl;
963 cout <<
" ERROR: can not read Data from DB, please check MdcTunningSvc Version. " << endl;
964 return StatusCode::FAILURE;
967 string ggg = result[row]->GetString(
"MdcEff");
968 string fff = result[row]->GetString(
"MdcRes");
970 log << MSG::DEBUG <<
" MdcTunning Data: MdcEff: " << ggg <<
" MdcRes: " << fff << endreq;
977 if(!stEff)
return StatusCode::FAILURE;
978 if(!stRes)
return StatusCode::FAILURE;
979 return StatusCode::SUCCESS;
double GetRes2(int layerId, int cellId, double driftD, double cosTheta, int posFlag, double entranceAngle, double &f, double &mean1, double &sigma1, double &mean2, double &sigma2)
double GetRes3(int layerId, int cellId, double driftD, double cosTheta, int posFlag, double entranceAngle, double &f, double &mean1, double &sigma1, double &mean2, double &sigma2, double &ResLargest, double &ResSmallest, double &ResRatio)