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"
8#include "EventModel/EventModel.h"
9#include "EventModel/Event.h"
10#include "EventModel/EventHeader.h"
12#include "EvtRecEvent/EvtRecEvent.h"
13#include "EvtRecEvent/EvtRecTrack.h"
14#include "EmcRecEventModel/RecEmcEventModel.h"
15#include "DstEvent/DstEmcShower.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
34#include "EmcRecEventModel/RecEmcEventModel.h"
35#include "EmcRecGeoSvc/EmcRecBarrelGeo.h"
36#include "EmcRecGeoSvc/EmcRecGeoSvc.h"
37#include "Identifier/TofID.h"
38#include "EvTimeEvent/RecEsTime.h"
42#include "AbsCor/AbsCor.h"
43#include "Identifier/Identifier.h"
44#include "TGraphErrors.h"
46#include "TGraph2DErrors.h"
60 Algorithm(name, pSvcLocator) {
64 declareProperty(
"NTupleOut",ntOut=
false);
65 declareProperty(
"McCor", mccor=0);
66 declareProperty(
"EdgeCor", edgecor=0);
67 declareProperty(
"HotCellMask", hotcellmask=0);
68 declareProperty(
"UseTof", usetof=1);
69 declareProperty(
"DoDataCor", dodatacor = 1);
70 declareProperty(
"DoPi0Cor",dopi0Cor=1);
71 declareProperty(
"MCUseTof", MCuseTof=1);
78 MsgStream log(
msgSvc(), name());
79 log << MSG::INFO <<
"in initialize()" << endmsg;
83 if ( nt1 ) m_tuple1 = nt1;
85 m_tuple1 =
ntupleSvc()->book (
"FILE1/ec", CLID_ColumnWiseTuple,
"ks N-Tuple example");
87 status = m_tuple1->addItem (
"ef", m_ef);
88 status = m_tuple1->addItem (
"e5", m_e5);
89 status = m_tuple1->addItem (
"ec", m_ec);
90 status = m_tuple1->addItem (
"ct", m_ct);
91 status = m_tuple1->addItem (
"cedge", m_cedge);
94 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
95 return StatusCode::FAILURE;
100 m_index =
new int*[56];
101 for (
int j=0;j<56;j++ ) {
102 m_index[j] =
new int[120];
103 for (
int k=0; k<120; k++) {
108 m_par =
new double*[22];
109 for (
int j=0;j<22;j++ ) {
110 m_par[j] =
new double[11];
111 for (
int k=0; k<11; k++) {
116 m_parphi =
new double*[22];
117 for (
int j=0;j<22;j++ ) {
118 m_parphi[j] =
new double[5];
119 for (
int k=0; k<5; k++) {
127 EnParInFile = getenv(
"ABSCORROOT");
128 EnParInFile +=
"/share/para.dat";
129 EnParIn.open(EnParInFile.c_str());
130 for(
int i=0;i<22;i++) {
132 EnParIn>>m_par[i][0]>>m_par[i][1]>>m_par[i][2]>>m_par[i][3]>>m_par[i][4]
133 >>m_par[i][5]>>m_par[i][6]>>m_par[i][7]>>m_par[i][8]>>m_par[i][9]
140 string EnParInFilephi = getenv(
"ABSCORROOT");
141 EnParInFilephi +=
"/share/paraphi.dat";
142 EnParInphi.open(EnParInFilephi.c_str());
143 for(
int i=0;i<22;i++) {
144 EnParInphi>>m_parphi[i][0]>>m_parphi[i][1]>>m_parphi[i][2]>>m_parphi[i][3]>>m_parphi[i][4];
170 string DataPathcbeam;
171 DataPathcbeam = getenv(
"ABSCORROOT");
172 DataPathcbeam +=
"/share/cbeam.txt";
174 incbeam.exceptions( ifstream::failbit | ifstream::badbit );
175 incbeam.open(DataPathcbeam.c_str(),ios::in);
176 for(
int i=0; i<56; i++){
177 double tid,peak,peake,sig,sige;
188 DataPathc3p = getenv(
"ABSCORROOT");
190 string DataPathc3ptof;
191 DataPathc3ptof = getenv(
"ABSCORROOT");
193 cout<<
"mccor = "<<mccor<<endl;
195 DataPathc3p +=
"/share/c3p.txt";
196 DataPathc3ptof +=
"/share/c3ptof.txt";
199 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
200 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
201 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
202 for(
int i=0; i<4; i++){
209 string paraPath = getenv(
"ABSCORROOT");
214 paraPath +=
"/share/evsetTof.txt";
217 paraPath +=
"/share/evset.txt";
221 in2.open(paraPath.c_str());
223 double energy,thetaid,peak1,peakerr1,res,reserr;
224 dt =
new TGraph2DErrors();
225 dtErr =
new TGraph2DErrors();
226 for(
int i=0;i<560;i++){
233 dt->SetPoint(i,
energy,thetaid,peak1);
234 dt->SetPointError(i,0,0,peakerr1);
235 dtErr->SetPoint(i,
energy,thetaid,res);
236 dtErr->SetPointError(i,0,0,reserr);
237 if(i<28) e25min[int(thetaid)]=
energy;
238 if(i>=560-28) e25max[int(thetaid)]=
energy;
244 for(
int ih=0;ih<10;ih++){
250 int dumring,dumphi,dummod,dumid;
252 HotList = getenv(
"ABSCORROOT");
253 HotList +=
"/share/hotcry.txt";
255 hotcrys.exceptions( ifstream::failbit | ifstream::badbit );
256 hotcrys.open(HotList.c_str(),ios::in);
257 for(
int il=0; il<numhots; il++){
258 hotcrys>>hrunstart[il];
259 hotcrys>>hrunend[il];
270 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
271 return StatusCode::SUCCESS;
280 MsgStream log(
msgSvc(), name());
281 log << MSG::INFO <<
"in execute()" << endreq;
283 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
284 int runNo=eventHeader->runNumber();
288 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())
return SUCCESS;
289 if(evtRecEvent->totalTracks()>50)
return SUCCESS;
292 ISvcLocator* svcLocator = Gaudi::svcLocator();
293 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc",iGeoSvc);
294 if(sc!=StatusCode::SUCCESS) {
295 cout<<
"Error: Can't get EmcRecGeoSvc"<<endl;
298 for(
int i = 0; i< evtRecEvent->totalTracks(); i++) {
300 if(!(*itTrk)->isEmcShowerValid())
continue;
304 int st = emcTrk->
status();
305 if(st>10000)
continue;
330 unsigned int module, ntheta, nphi;
341 double e5x5=emcTrk->
e5x5();
344 if(usetof==1 && (*itTrk)->isTofTrackValid()){
345 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
346 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
353 if (module==0||module==2) thetaId = thetaModule;
354 if (module==1 && thetaModule<=21) thetaId = thetaModule + 6;
355 if (module==1 && thetaModule>21) thetaId = 43 - thetaModule + 6;
358 energyC=ECorrMC(e5x5+etof,thetaId);
362 energyC=ECorrMC(e5x5,thetaId);
386 double lnE = std::log(energyC);
388 if (energyC>1.0) lnE=std::log(1.0);
389 if (energyC<0.07) lnE=std::log(0.07);
393 if(
runNo>0 && dodatacor==1) {
394 lnEcor =
ai[0]+
ai[1]*lnE+
ai[2]*lnE*lnE+
ai[3]*lnE*lnE*lnE;
397 if(lnEcor<0.5)
continue;
407 for(
int ih=0;ih<10;ih++){
408 if(hrunstart[ih]==-1||hrunend[ih]==-1||hcell[ih]==-1)
continue;
417 unsigned int theModule;
419 theModule = 43 - thetaModule;
423 theModule = thetaModule;
430 }
else if(theModule==20) {
444 double theta01,theta23,length,d;
445 theta01 = (center01-IR).theta();
446 theta23 = (center23-IR).theta();
447 length = (center01-IR).mag();
448 d = length*
tan(theta01-theta23);
451 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
452 if (xIn < (-d/2) && theModule!=21){
454 theModule=theModule+1 ;
460 }
else if(theModule==20) {
471 theta01 = (center01-IR).theta();
472 theta23 = (center23-IR).theta();
473 length = (center01-IR).mag();
474 d = length*
tan(theta01-theta23);
476 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
478 }
else if (xIn > (d/2) && theModule!=0 ){
480 theModule=theModule-1 ;
485 }
else if(theModule==20) {
497 theta01 = (center01-IR).theta();
498 theta23 = (center23-IR).theta();
499 length = (center01-IR).mag();
500 d = length*
tan(theta01-theta23);
502 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
509 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
510 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
512 if(nphi==0&&yIn>100) yIn=yIn-360;
513 if(nphi==119&&yIn<-100) yIn=yIn+360;
517 if(nphi!=0) phiModule=phiModule-1;
518 if(nphi==0) phiModule=119;
519 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
520 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
521 if(phiModule==0&&yIn>100) yIn=yIn-360;
522 if(phiModule==119&&yIn<-100) yIn=yIn+360;
529 if(nphi!=119) phiModule=phiModule+1;
530 if(nphi==119) phiModule=0;
532 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
533 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
534 if(phiModule==0&&yIn>100) yIn=yIn-360;
535 if(phiModule==119&&yIn<-100) yIn=yIn+360;
538 enecor=m_par[theModule][0]
539 +m_par[theModule][1]*xIn
540 +m_par[theModule][2]*xIn*xIn
541 +m_par[theModule][3]*xIn*xIn*xIn
542 +m_par[theModule][4]*xIn*xIn*xIn*xIn
543 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
544 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
547 +m_par[theModule][7]*yIn
548 +m_par[theModule][8]*yIn*yIn
549 +m_par[theModule][9]*yIn*yIn*yIn
550 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
558 double energyCC= energyC/(lnEcor*enecor);
575 if(!recEmcShowerCol){
576 return( StatusCode::SUCCESS);
579 if(!dstEmcShowerCol){
580 return( StatusCode::SUCCESS);
584 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())
return SUCCESS;
585 for(
int i=0;i<recEmcShowerCol->size();i++){
586 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
587 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
589 (*iter_dst)->setEnergy((*iter_rec)->energy());
590 (*iter_dst)->setStatus((*iter_rec)->status());
594 return( StatusCode::SUCCESS);
600 MsgStream log(
msgSvc(), name());
601 log << MSG::INFO <<
"in finalize()" << endmsg;
602 return StatusCode::SUCCESS;
607double AbsCor::E25min(
int n)
const
611double AbsCor::E25max(
int n)
const
618double AbsCor::ECorrMC(
double eg,
double theid)
const
621 if(eg<E25min(
int(theid))) eg=E25min(
int(theid));
622 if(eg>E25max(
int(theid))) eg=E25max(
int(theid))-0.001;
624 if(theid<=0)theid=0.001;
625 if(theid>=27)theid=26.999;
626 Float_t einter = eg + 0.00001;
627 Float_t tinter = theid+0.0001;
629 double ecor=dt->Interpolate(einter,tinter);
631 if(!(ecor))
return Energy5x5;
632 if(ecor<0.5)
return Energy5x5;
633 double EnergyCor=Energy5x5/ecor;
638double AbsCor::ErrMC(
double eg,
double theid)
const
641 if(eg<E25min(
int(theid))) eg=E25min(
int(theid));
642 if(eg>E25max(
int(theid))) eg=E25max(
int(theid))-0.001;
643 if(theid<=0)theid=0.001;
644 if(theid>=27)theid=26.999;
645 Float_t einter = eg + 0.00001;
646 Float_t tinter = theid+0.0001;
647 double err=dtErr->Interpolate(einter,tinter);
HepGeom::Point3D< double > HepPoint3D
EvtRecTrackCol::iterator EvtRecTrackIterator
double tan(const BesAngle a)
************Class m_ypar INTEGER m_KeyWgt INTEGER m_nphot 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