86 MsgStream log(
msgSvc(), name());
87 log << MSG::INFO <<
"in initialize()" << endmsg;
92 if ( nt1 ) m_tuple1 = nt1;
94 m_tuple1 =
ntupleSvc()->book (
"FILE1/ec", CLID_ColumnWiseTuple,
"ks N-Tuple example");
96 status = m_tuple1->addItem (
"ef", m_ef);
97 status = m_tuple1->addItem (
"e5", m_e5);
98 status = m_tuple1->addItem (
"ec", m_ec);
99 status = m_tuple1->addItem (
"ct", m_ct);
100 status = m_tuple1->addItem (
"cedge", m_cedge);
103 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
104 return StatusCode::FAILURE;
109 m_index =
new int*[56];
110 for (
int j=0;j<56;j++ ) {
111 m_index[j] =
new int[120];
112 for (
int k=0; k<120; k++) {
117 m_par =
new double*[22];
118 for (
int j=0;j<22;j++ ) {
119 m_par[j] =
new double[11];
120 for (
int k=0; k<11; k++) {
125 m_parphi =
new double*[22];
126 for (
int j=0;j<22;j++ ) {
127 m_parphi[j] =
new double[5];
128 for (
int k=0; k<5; k++) {
136 EnParInFile = getenv(
"ABSCORROOT");
137 EnParInFile +=
"/share/para.dat";
138 EnParIn.open(EnParInFile.c_str());
139 for(
int i=0;i<22;i++) {
141 EnParIn>>m_par[i][0]>>m_par[i][1]>>m_par[i][2]>>m_par[i][3]>>m_par[i][4]
142 >>m_par[i][5]>>m_par[i][6]>>m_par[i][7]>>m_par[i][8]>>m_par[i][9]
149 string EnParInFilephi = getenv(
"ABSCORROOT");
150 EnParInFilephi +=
"/share/paraphi.dat";
151 EnParInphi.open(EnParInFilephi.c_str());
152 for(
int i=0;i<22;i++) {
153 EnParInphi>>m_parphi[i][0]>>m_parphi[i][1]>>m_parphi[i][2]>>m_parphi[i][3]>>m_parphi[i][4];
179 string DataPathcbeam;
180 DataPathcbeam = getenv(
"ABSCORROOT");
181 DataPathcbeam +=
"/share/cbeam.txt";
183 incbeam.exceptions( ifstream::failbit | ifstream::badbit );
184 incbeam.open(DataPathcbeam.c_str(),ios::in);
185 for(
int i=0; i<56; i++){
186 double tid,peak,peake,sig,sige;
197 DataPathc3p = getenv("ABSCORROOT");
198 DataPathc3p += "/share/c3p.txt";
200 string DataPathc3ptof;
201 DataPathc3ptof = getenv("ABSCORROOT");
202 DataPathc3ptof += "/share/c3ptof.txt";
203 cout<<"mccor = "<<mccor<<endl;
204 //DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
208 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
209 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
210 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
211 for(int i=0; i<4; i++){
218 string paraPath = getenv(
"ABSCORROOT");
223 paraPath +=
"/share/evsetTof.txt";
226 paraPath +=
"/share/evset.txt";
230 in2.open(paraPath.c_str());
232 double energy,thetaid,peak1,peakerr1,res,reserr;
233 dt =
new TGraph2DErrors();
234 dtErr =
new TGraph2DErrors();
236 for(
int i=0;i<1484;i++){
243 dt->SetPoint(i,
energy,thetaid,peak1);
244 dt->SetPointError(i,0,0,peakerr1);
245 dtErr->SetPoint(i,
energy,thetaid,res);
246 dtErr->SetPointError(i,0,0,reserr);
247 if(i<28) e25min[int(thetaid)]=
energy;
248 if(i>=1484-28) e25max[int(thetaid)]=
energy;
256 for(
int ih=0;ih<10;ih++){
262 int dumring,dumphi,dummod,dumid;
264 HotList = getenv(
"ABSCORROOT");
265 HotList +=
"/share/hotcry.txt";
267 hotcrys.exceptions( ifstream::failbit | ifstream::badbit );
268 hotcrys.open(HotList.c_str(),ios::in);
269 for(
int il=0; il<numhots; il++){
270 hotcrys>>hrunstart[il];
271 hotcrys>>hrunend[il];
282 string CorFunparaPath;
284 CorFunparaPath = getenv("ABSCORROOT");
286 // Read energy correction Function parameters from PhotonCor/McCor
288 if (IYear==2009) CorFunparaPath += "/share/evsetTofCorFunctionPar2009Jpsi.txt";
289 if (IYear==2012) CorFunparaPath += "/share/evsetTofCorFunctionPar2012Jpsi.txt";
290 if (IYear==2018) CorFunparaPath += "/share/evsetTofCorFunctionPar2018Jpsi.txt";
291 if (IYear==2019) CorFunparaPath += "/share/evsetTofCorFunctionPar2019Jpsi.txt";
295 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
299 in2corfun.open(CorFunparaPath.c_str());
302 for(int i=0;i<28;i++){
303 in2corfun>>m_corFunPar[i][0];
304 in2corfun>>m_corFunPar[i][1];
305 in2corfun>>m_corFunPar[i][2];
306 in2corfun>>m_corFunPar[i][3];
307 in2corfun>>m_corFunPar[i][4];
308 in2corfun>>m_corFunPar[i][5];
316 ISvcLocator* svcLocator = Gaudi::svcLocator();
317 StatusCode sc = svcLocator->service(
"EmcShEnCalibSvc", m_EmcShEnCalibSvc);
319 if( sc != StatusCode::SUCCESS){
320 std::cout <<
"can not use EmcShEnCalibSvc in AbsCor" << endl;
323 std::cout<<
"getPi0CalibFile() and getSingleGammaCalibFile() still are empty in initialize()"<< std::endl;
324 std::cout<<
"will be assigned a value in execute()"<< std::endl;
325 std::cout <<
"Test EmcShEnCalibSvc in AbsCor initialize getPi0CalibFile()= "
326 << m_EmcShEnCalibSvc -> getPi0CalibFile()
327 <<
"Test EmcShEnCalibSvc in AbsCor getSingleGammaCalibFile()= "
328 << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()
334 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
335 return StatusCode::SUCCESS;
341 MsgStream log(
msgSvc(), name());
342 log << MSG::INFO <<
"in execute()" << endreq;
344 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
345 int runNo=eventHeader->runNumber();
350 if (runNum>=runFrom&&runNum<=runTo) {
356 if (m_inFlag==
false){
358 runFrom=m_EmcShEnCalibSvc -> getRunFrom();
359 runTo=m_EmcShEnCalibSvc -> getRunTo();
363 cout <<
"current run=" <<
runNo<<endl;
364 cout <<
"in AbsCor open getPi0CalibFile()= " << m_EmcShEnCalibSvc -> getPi0CalibFile()<<endl;
365 cout <<
"open getSingleGammaCalibFile()= " << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()<<endl;
366 cout <<
"getRunFrom()="<< runFrom<<endl;
367 cout <<
"getRunTo()="<< runTo<<endl;
370 string CorFunparaPath;
373 CorFunparaPath = m_EmcShEnCalibSvc -> getSingleGammaCalibFile();
375 CorFunparaPath = m_CorFunparaPath;
376 cout<<
"no read database, but using the set:"<<CorFunparaPath<<endl;
380 CorFunparaPath = getenv(
"ABSCORROOT");
381 CorFunparaPath +=
"/share/evsetCorFunctionPar.txt";
385 in2corfun.open(CorFunparaPath.c_str());
388 for(
int i=0;i<28;i++){
389 in2corfun>>m_corFunPar[i][0];
390 in2corfun>>m_corFunPar[i][1];
391 in2corfun>>m_corFunPar[i][2];
392 in2corfun>>m_corFunPar[i][3];
393 in2corfun>>m_corFunPar[i][4];
394 in2corfun>>m_corFunPar[i][5];
400 DataPathc3p = getenv(
"ABSCORROOT");
401 DataPathc3p +=
"/share/c3p.txt";
403 string DataPathc3ptof;
405 DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
407 DataPathc3ptof = m_DataPathc3ptof;
408 cout<<
"no read database, but using the set:"<<DataPathc3ptof<<endl;
412 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
413 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
414 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
415 for(
int i=0; i<4; i++){
426 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())
return SUCCESS;
427 if(evtRecEvent->totalTracks()>50)
return SUCCESS;
430 ISvcLocator* svcLocator = Gaudi::svcLocator();
431 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc",iGeoSvc);
432 if(sc!=StatusCode::SUCCESS) {
433 cout<<
"Error: Can't get EmcRecGeoSvc"<<endl;
436 for(
int i = 0; i< evtRecEvent->totalTracks(); i++) {
438 if(!(*itTrk)->isEmcShowerValid())
continue;
476 unsigned int module, ntheta, nphi;
477 module = EmcID::barrel_ec(id);
487 double e5x5=emcTrk->
e5x5();
490 if(usetof==1 && (*itTrk)->isTofTrackValid()){
491 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
492 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
499 if (module==0||module==2) thetaId = thetaModule;
500 if (module==1 && thetaModule<=21) thetaId = thetaModule + 6;
501 if (module==1 && thetaModule>21) thetaId = 43 - thetaModule + 6;
502 double DthetaId=double(thetaId);
505 if (thetaId<6) etof=0.0;
506 if (MCCorUseFunction==1){
507 energyC=ECorrFunctionMC(e5x5+etof,DthetaId);
508 }
else if (MCCorUseFunction==0){
509 energyC=ECorrMC(e5x5+etof,DthetaId);
513 if (MCCorUseFunction==1){
514 energyC=ECorrFunctionMC(e5x5,DthetaId);
515 }
else if (MCCorUseFunction==0){
516 energyC=ECorrMC(e5x5,DthetaId);
540 double lnE = std::log(energyC);
542 if (energyC>1.0) lnE=std::log(1.0);
543 if (energyC<0.05) lnE=std::log(0.05);
547 if(
runNo>0 && dodatacor==1) {
548 lnEcor =
ai[0]+
ai[1]*lnE+
ai[2]*lnE*lnE+
ai[3]*lnE*lnE*lnE;
551 if(lnEcor<0.5)
continue;
561 for(
int ih=0;ih<10;ih++){
562 if(hrunstart[ih]==-1||hrunend[ih]==-1||hcell[ih]==-1)
continue;
571 unsigned int theModule;
573 theModule = 43 - thetaModule;
577 theModule = thetaModule;
584 }
else if(theModule==20) {
598 double theta01,theta23,length,d;
599 theta01 = (center01-IR).theta();
600 theta23 = (center23-IR).theta();
601 length = (center01-IR).mag();
602 d = length*
tan(theta01-theta23);
605 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
606 if (xIn < (-d/2) && theModule!=21){
608 theModule=theModule+1 ;
614 }
else if(theModule==20) {
625 theta01 = (center01-IR).theta();
626 theta23 = (center23-IR).theta();
627 length = (center01-IR).mag();
628 d = length*
tan(theta01-theta23);
630 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
632 }
else if (xIn > (d/2) && theModule!=0 ){
634 theModule=theModule-1 ;
639 }
else if(theModule==20) {
651 theta01 = (center01-IR).theta();
652 theta23 = (center23-IR).theta();
653 length = (center01-IR).mag();
654 d = length*
tan(theta01-theta23);
656 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
663 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
664 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
666 if(nphi==0&&yIn>100) yIn=yIn-360;
667 if(nphi==119&&yIn<-100) yIn=yIn+360;
671 if(nphi!=0) phiModule=phiModule-1;
672 if(nphi==0) phiModule=119;
673 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
674 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
675 if(phiModule==0&&yIn>100) yIn=yIn-360;
676 if(phiModule==119&&yIn<-100) yIn=yIn+360;
683 if(nphi!=119) phiModule=phiModule+1;
684 if(nphi==119) phiModule=0;
686 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
687 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
688 if(phiModule==0&&yIn>100) yIn=yIn-360;
689 if(phiModule==119&&yIn<-100) yIn=yIn+360;
692 enecor=m_par[theModule][0]
693 +m_par[theModule][1]*xIn
694 +m_par[theModule][2]*xIn*xIn
695 +m_par[theModule][3]*xIn*xIn*xIn
696 +m_par[theModule][4]*xIn*xIn*xIn*xIn
697 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
698 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
701 +m_par[theModule][7]*yIn
702 +m_par[theModule][8]*yIn*yIn
703 +m_par[theModule][9]*yIn*yIn*yIn
704 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
712 double energyCC= energyC/(lnEcor*enecor);
729 if(!recEmcShowerCol){
730 return( StatusCode::SUCCESS);
733 if(!dstEmcShowerCol){
734 return( StatusCode::SUCCESS);
738 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())
return SUCCESS;
739 for(
int i=0;i<recEmcShowerCol->size();i++){
740 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
741 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
743 (*iter_dst)->setEnergy((*iter_rec)->energy());
744 (*iter_dst)->setStatus((*iter_rec)->status());
748 return( StatusCode::SUCCESS);