1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
19#include "GaudiKernel/INTupleSvc.h"
20#include "GaudiKernel/NTuple.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/IHistogramSvc.h"
23#include "CLHEP/Vector/ThreeVector.h"
24#include "CLHEP/Vector/LorentzVector.h"
25#include "CLHEP/Vector/TwoVector.h"
26using CLHEP::Hep3Vector;
27using CLHEP::Hep2Vector;
28using CLHEP::HepLorentzVector;
29#include "CLHEP/Geometry/Point3D.h"
30#ifndef ENABLE_BACKWARDS_COMPATIBILITY
42#include "TGraphErrors.h"
44#include "TGraph2DErrors.h"
56 Algorithm(name, pSvcLocator) {
60 declareProperty(
"NTupleOut",ntOut=
false);
61 declareProperty(
"McCor", mccor=0);
62 declareProperty(
"EdgeCor", edgecor=0);
63 declareProperty(
"HotCellMask", hotcellmask=0);
64 declareProperty(
"UseTof", usetof=1);
65 declareProperty(
"DoDataCor", dodatacor = 1);
66 declareProperty(
"DoPi0Cor",dopi0Cor=1);
67 declareProperty(
"MCUseTof", MCuseTof=1);
68 declareProperty(
"MCCorUseFunction", MCCorUseFunction=1);
69 declareProperty(
"IYear",IYear=2009);
79 MsgStream log(
msgSvc(), name());
80 log << MSG::INFO <<
"in initialize()" << endmsg;
85 if ( nt1 ) m_tuple1 = nt1;
87 m_tuple1 =
ntupleSvc()->book (
"FILE1/ec", CLID_ColumnWiseTuple,
"ks N-Tuple example");
89 status = m_tuple1->addItem (
"ef", m_ef);
90 status = m_tuple1->addItem (
"e5", m_e5);
91 status = m_tuple1->addItem (
"ec", m_ec);
92 status = m_tuple1->addItem (
"ct", m_ct);
93 status = m_tuple1->addItem (
"cedge", m_cedge);
96 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
97 return StatusCode::FAILURE;
102 m_index =
new int*[56];
103 for (
int j=0;j<56;j++ ) {
104 m_index[j] =
new int[120];
105 for (
int k=0; k<120; k++) {
110 m_par =
new double*[22];
111 for (
int j=0;j<22;j++ ) {
112 m_par[j] =
new double[11];
113 for (
int k=0; k<11; k++) {
118 m_parphi =
new double*[22];
119 for (
int j=0;j<22;j++ ) {
120 m_parphi[j] =
new double[5];
121 for (
int k=0; k<5; k++) {
129 EnParInFile = getenv(
"ABSCORROOT");
130 EnParInFile +=
"/share/para.dat";
131 EnParIn.open(EnParInFile.c_str());
132 for(
int i=0;i<22;i++) {
134 EnParIn>>m_par[i][0]>>m_par[i][1]>>m_par[i][2]>>m_par[i][3]>>m_par[i][4]
135 >>m_par[i][5]>>m_par[i][6]>>m_par[i][7]>>m_par[i][8]>>m_par[i][9]
142 string EnParInFilephi = getenv(
"ABSCORROOT");
143 EnParInFilephi +=
"/share/paraphi.dat";
144 EnParInphi.open(EnParInFilephi.c_str());
145 for(
int i=0;i<22;i++) {
146 EnParInphi>>m_parphi[i][0]>>m_parphi[i][1]>>m_parphi[i][2]>>m_parphi[i][3]>>m_parphi[i][4];
172 string DataPathcbeam;
173 DataPathcbeam = getenv(
"ABSCORROOT");
174 DataPathcbeam +=
"/share/cbeam.txt";
176 incbeam.exceptions( ifstream::failbit | ifstream::badbit );
177 incbeam.open(DataPathcbeam.c_str(),ios::in);
178 for(
int i=0; i<56; i++){
179 double tid,peak,peake,sig,sige;
190 DataPathc3p = getenv("ABSCORROOT");
191 DataPathc3p += "/share/c3p.txt";
193 string DataPathc3ptof;
194 DataPathc3ptof = getenv("ABSCORROOT");
195 DataPathc3ptof += "/share/c3ptof.txt";
196 cout<<"mccor = "<<mccor<<endl;
197 //DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
201 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
202 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
203 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
204 for(int i=0; i<4; i++){
211 string paraPath = getenv(
"ABSCORROOT");
216 paraPath +=
"/share/evsetTof.txt";
219 paraPath +=
"/share/evset.txt";
223 in2.open(paraPath.c_str());
225 double energy,thetaid,peak1,peakerr1,res,reserr;
226 dt =
new TGraph2DErrors();
227 dtErr =
new TGraph2DErrors();
229 for(
int i=0;i<1484;i++){
236 dt->SetPoint(i,
energy,thetaid,peak1);
237 dt->SetPointError(i,0,0,peakerr1);
238 dtErr->SetPoint(i,
energy,thetaid,res);
239 dtErr->SetPointError(i,0,0,reserr);
240 if(i<28) e25min[int(thetaid)]=
energy;
241 if(i>=1484-28) e25max[int(thetaid)]=
energy;
249 for(
int ih=0;ih<10;ih++){
255 int dumring,dumphi,dummod,dumid;
257 HotList = getenv(
"ABSCORROOT");
258 HotList +=
"/share/hotcry.txt";
260 hotcrys.exceptions( ifstream::failbit | ifstream::badbit );
261 hotcrys.open(HotList.c_str(),ios::in);
262 for(
int il=0; il<numhots; il++){
263 hotcrys>>hrunstart[il];
264 hotcrys>>hrunend[il];
275 string CorFunparaPath;
277 CorFunparaPath = getenv("ABSCORROOT");
279 // Read energy correction Function parameters from PhotonCor/McCor
281 if (IYear==2009) CorFunparaPath += "/share/evsetTofCorFunctionPar2009Jpsi.txt";
282 if (IYear==2012) CorFunparaPath += "/share/evsetTofCorFunctionPar2012Jpsi.txt";
283 if (IYear==2018) CorFunparaPath += "/share/evsetTofCorFunctionPar2018Jpsi.txt";
284 if (IYear==2019) CorFunparaPath += "/share/evsetTofCorFunctionPar2019Jpsi.txt";
288 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
292 in2corfun.open(CorFunparaPath.c_str());
295 for(int i=0;i<28;i++){
296 in2corfun>>m_corFunPar[i][0];
297 in2corfun>>m_corFunPar[i][1];
298 in2corfun>>m_corFunPar[i][2];
299 in2corfun>>m_corFunPar[i][3];
300 in2corfun>>m_corFunPar[i][4];
301 in2corfun>>m_corFunPar[i][5];
309 ISvcLocator* svcLocator = Gaudi::svcLocator();
310 StatusCode sc = svcLocator->service(
"EmcShEnCalibSvc", m_EmcShEnCalibSvc);
312 if( sc != StatusCode::SUCCESS){
313 std::cout <<
"can not use EmcShEnCalibSvc in AbsCor" << endl;
316 std::cout<<
"getPi0CalibFile() and getSingleGammaCalibFile() still are empty in initialize()"<< std::endl;
317 std::cout<<
"will be assigned a value in execute()"<< std::endl;
318 std::cout <<
"Test EmcShEnCalibSvc in AbsCor initialize getPi0CalibFile()= "
319 << m_EmcShEnCalibSvc -> getPi0CalibFile()
320 <<
"Test EmcShEnCalibSvc in AbsCor getSingleGammaCalibFile()= "
321 << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()
327 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
328 return StatusCode::SUCCESS;
334 MsgStream log(
msgSvc(), name());
335 log << MSG::INFO <<
"in execute()" << endreq;
337 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
338 int runNo=eventHeader->runNumber();
343 unsigned int runFrom=m_EmcShEnCalibSvc -> getRunFrom();
344 unsigned int runTo=m_EmcShEnCalibSvc -> getRunTo();
350 if (runNum>=runFrom0&&runNum<=runTo0&&m_ReadFile==
true){
356 if (runFrom0!=runFrom) runFrom0 = runFrom;
357 if (runTo0!=runTo) runTo0 = runTo;
360 cout <<
"current run=" <<
runNo<<endl;
361 cout <<
"in AbsCor open getPi0CalibFile()= " << m_EmcShEnCalibSvc -> getPi0CalibFile()<<endl;
362 cout <<
"open getSingleGammaCalibFile()= " << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()<<endl;
363 cout <<
"getRunFrom()="<< runFrom<<endl;
364 cout <<
"getRunTo()="<< runTo<<endl;
367 string CorFunparaPath;
369 CorFunparaPath = m_EmcShEnCalibSvc -> getSingleGammaCalibFile();
372 CorFunparaPath = getenv(
"ABSCORROOT");
373 CorFunparaPath +=
"/share/evsetCorFunctionPar.txt";
377 in2corfun.open(CorFunparaPath.c_str());
380 for(
int i=0;i<28;i++){
381 in2corfun>>m_corFunPar[i][0];
382 in2corfun>>m_corFunPar[i][1];
383 in2corfun>>m_corFunPar[i][2];
384 in2corfun>>m_corFunPar[i][3];
385 in2corfun>>m_corFunPar[i][4];
386 in2corfun>>m_corFunPar[i][5];
392 DataPathc3p = getenv(
"ABSCORROOT");
393 DataPathc3p +=
"/share/c3p.txt";
395 string DataPathc3ptof;
396 DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
399 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
400 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
401 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
402 for(
int i=0; i<4; i++){
411 cout<<
"-----------read parameter file-------"<<endl;
417 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())
return SUCCESS;
418 if(evtRecEvent->totalTracks()>50)
return SUCCESS;
421 ISvcLocator* svcLocator = Gaudi::svcLocator();
422 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc",iGeoSvc);
423 if(sc!=StatusCode::SUCCESS) {
424 cout<<
"Error: Can't get EmcRecGeoSvc"<<endl;
427 for(
int i = 0; i< evtRecEvent->totalTracks(); i++) {
429 if(!(*itTrk)->isEmcShowerValid())
continue;
467 unsigned int module, ntheta, nphi;
478 double e5x5=emcTrk->
e5x5();
481 if(usetof==1 && (*itTrk)->isTofTrackValid()){
482 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
483 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
490 if (module==0||module==2) thetaId = thetaModule;
491 if (module==1 && thetaModule<=21) thetaId = thetaModule + 6;
492 if (module==1 && thetaModule>21) thetaId = 43 - thetaModule + 6;
493 double DthetaId=double(thetaId);
496 if (thetaId<6) etof=0.0;
497 if (MCCorUseFunction==1){
498 energyC=ECorrFunctionMC(e5x5+etof,DthetaId);
499 }
else if (MCCorUseFunction==0){
500 energyC=ECorrMC(e5x5+etof,DthetaId);
504 if (MCCorUseFunction==1){
505 energyC=ECorrFunctionMC(e5x5,DthetaId);
506 }
else if (MCCorUseFunction==0){
507 energyC=ECorrMC(e5x5,DthetaId);
531 double lnE = std::log(energyC);
533 if (energyC>1.0) lnE=std::log(1.0);
534 if (energyC<0.05) lnE=std::log(0.05);
538 if(
runNo>0 && dodatacor==1) {
539 lnEcor =
ai[0]+
ai[1]*lnE+
ai[2]*lnE*lnE+
ai[3]*lnE*lnE*lnE;
542 if(lnEcor<0.5)
continue;
552 for(
int ih=0;ih<10;ih++){
553 if(hrunstart[ih]==-1||hrunend[ih]==-1||hcell[ih]==-1)
continue;
562 unsigned int theModule;
564 theModule = 43 - thetaModule;
568 theModule = thetaModule;
575 }
else if(theModule==20) {
589 double theta01,theta23,length,d;
590 theta01 = (center01-IR).theta();
591 theta23 = (center23-IR).theta();
592 length = (center01-IR).mag();
593 d = length*
tan(theta01-theta23);
596 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
597 if (xIn < (-d/2) && theModule!=21){
599 theModule=theModule+1 ;
605 }
else if(theModule==20) {
616 theta01 = (center01-IR).theta();
617 theta23 = (center23-IR).theta();
618 length = (center01-IR).mag();
619 d = length*
tan(theta01-theta23);
621 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
623 }
else if (xIn > (d/2) && theModule!=0 ){
625 theModule=theModule-1 ;
630 }
else if(theModule==20) {
642 theta01 = (center01-IR).theta();
643 theta23 = (center23-IR).theta();
644 length = (center01-IR).mag();
645 d = length*
tan(theta01-theta23);
647 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
654 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
655 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
657 if(nphi==0&&yIn>100) yIn=yIn-360;
658 if(nphi==119&&yIn<-100) yIn=yIn+360;
662 if(nphi!=0) phiModule=phiModule-1;
663 if(nphi==0) phiModule=119;
664 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
665 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
666 if(phiModule==0&&yIn>100) yIn=yIn-360;
667 if(phiModule==119&&yIn<-100) yIn=yIn+360;
674 if(nphi!=119) phiModule=phiModule+1;
675 if(nphi==119) phiModule=0;
677 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
678 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
679 if(phiModule==0&&yIn>100) yIn=yIn-360;
680 if(phiModule==119&&yIn<-100) yIn=yIn+360;
683 enecor=m_par[theModule][0]
684 +m_par[theModule][1]*xIn
685 +m_par[theModule][2]*xIn*xIn
686 +m_par[theModule][3]*xIn*xIn*xIn
687 +m_par[theModule][4]*xIn*xIn*xIn*xIn
688 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
689 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
692 +m_par[theModule][7]*yIn
693 +m_par[theModule][8]*yIn*yIn
694 +m_par[theModule][9]*yIn*yIn*yIn
695 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
703 double energyCC= energyC/(lnEcor*enecor);
720 if(!recEmcShowerCol){
721 return( StatusCode::SUCCESS);
724 if(!dstEmcShowerCol){
725 return( StatusCode::SUCCESS);
729 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())
return SUCCESS;
730 for(
int i=0;i<recEmcShowerCol->size();i++){
731 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
732 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
734 (*iter_dst)->setEnergy((*iter_rec)->energy());
735 (*iter_dst)->setStatus((*iter_rec)->status());
739 return( StatusCode::SUCCESS);
745 MsgStream log(
msgSvc(), name());
746 log << MSG::INFO <<
"in finalize()" << endmsg;
747 return StatusCode::SUCCESS;
752double AbsCor::E25min(
int n)
const
756double AbsCor::E25max(
int n)
const
763double AbsCor::ECorrMC(
double eg,
double theid)
const
766 if(eg<E25min(
int(theid))) eg=E25min(
int(theid));
767 if(eg>E25max(
int(theid))) eg=E25max(
int(theid))-0.001;
769 if(theid<=0)theid=0.001;
770 if(theid>=27)theid=26.999;
771 Float_t einter = eg + 0.00001;
772 Float_t tinter = theid+0.0001;
774 double ecor=dt->Interpolate(einter,tinter);
776 if(!(ecor))
return Energy5x5;
777 if(ecor<0.5)
return Energy5x5;
778 double EnergyCor=Energy5x5/ecor;
783double AbsCor::ErrMC(
double eg,
double theid)
const
786 if(eg<E25min(
int(theid))) eg=E25min(
int(theid));
787 if(eg>E25max(
int(theid))) eg=E25max(
int(theid))-0.001;
788 if(theid<=0)theid=0.001;
789 if(theid>=27)theid=26.999;
790 Float_t einter = eg + 0.00001;
791 Float_t tinter = theid+0.0001;
792 double err=dtErr->Interpolate(einter,tinter);
798double AbsCor::ECorrFunctionMC(
double eg,
double theid)
const
800 if(theid<0||theid>27){
801 cout<<
"in AbsCor EcorrFunctionMC error::thetaId is out of the region [0,27]"<<endl;
809 ecor = m_corFunPar[ith][0]/(m_corFunPar[ith][1]+
exp(-x))
810 + m_corFunPar[ith][2]
811 + m_corFunPar[ith][3]*x
812 + m_corFunPar[ith][4]*x*x
813 + m_corFunPar[ith][5]*x*x*x;
815 double EnergyCor=Energy5x5/ecor;
HepGeom::Point3D< double > HepPoint3D
double tan(const BesAngle a)
EvtComplex exp(const EvtComplex &c)
EvtRecTrackCol::iterator EvtRecTrackIterator
************Class m_ypar INTEGER m_KeyWgt INTEGER m_KeyIHVP INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input READ never touch them !$ !debug facility $ !maximum weight $ !inverse alfaQED $ !minimum real photon energy
AbsCor(const std::string &name, ISvcLocator *pSvcLocator)
HepPoint3D position() const
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static unsigned int theta_module(const Identifier &id)
static unsigned int phi_module(const Identifier &id)
virtual HepPoint3D GetCrystalPoint(const Identifier &id, const int i) const =0
_EXTERN_ std::string DstEmcShowerCol
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol
_EXTERN_ std::string RecEmcShowerCol