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();
227 for(
int i=0;i<1484;i++){
234 dt->SetPoint(i,
energy,thetaid,peak1);
235 dt->SetPointError(i,0,0,peakerr1);
236 dtErr->SetPoint(i,
energy,thetaid,res);
237 dtErr->SetPointError(i,0,0,reserr);
238 if(i<28) e25min[int(thetaid)]=
energy;
239 if(i>=1484-28) e25max[int(thetaid)]=
energy;
246 for(
int ih=0;ih<10;ih++){
252 int dumring,dumphi,dummod,dumid;
254 HotList = getenv(
"ABSCORROOT");
255 HotList +=
"/share/hotcry.txt";
257 hotcrys.exceptions( ifstream::failbit | ifstream::badbit );
258 hotcrys.open(HotList.c_str(),ios::in);
259 for(
int il=0; il<numhots; il++){
260 hotcrys>>hrunstart[il];
261 hotcrys>>hrunend[il];
272 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
273 return StatusCode::SUCCESS;
282 MsgStream log(
msgSvc(), name());
283 log << MSG::INFO <<
"in execute()" << endreq;
285 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
286 int runNo=eventHeader->runNumber();
290 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())
return SUCCESS;
291 if(evtRecEvent->totalTracks()>50)
return SUCCESS;
294 ISvcLocator* svcLocator = Gaudi::svcLocator();
295 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc",iGeoSvc);
296 if(sc!=StatusCode::SUCCESS) {
297 cout<<
"Error: Can't get EmcRecGeoSvc"<<endl;
300 for(
int i = 0; i< evtRecEvent->totalTracks(); i++) {
302 if(!(*itTrk)->isEmcShowerValid())
continue;
336 unsigned int module, ntheta, nphi;
347 double e5x5=emcTrk->
e5x5();
350 if(usetof==1 && (*itTrk)->isTofTrackValid()){
351 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
352 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
359 if (module==0||module==2) thetaId = thetaModule;
360 if (module==1 && thetaModule<=21) thetaId = thetaModule + 6;
361 if (module==1 && thetaModule>21) thetaId = 43 - thetaModule + 6;
364 energyC=ECorrMC(e5x5+etof,thetaId);
368 energyC=ECorrMC(e5x5,thetaId);
392 double lnE = std::log(energyC);
394 if (energyC>1.0) lnE=std::log(1.0);
395 if (energyC<0.07) lnE=std::log(0.07);
399 if(
runNo>0 && dodatacor==1) {
400 lnEcor =
ai[0]+
ai[1]*lnE+
ai[2]*lnE*lnE+
ai[3]*lnE*lnE*lnE;
403 if(lnEcor<0.5)
continue;
413 for(
int ih=0;ih<10;ih++){
414 if(hrunstart[ih]==-1||hrunend[ih]==-1||hcell[ih]==-1)
continue;
423 unsigned int theModule;
425 theModule = 43 - thetaModule;
429 theModule = thetaModule;
436 }
else if(theModule==20) {
450 double theta01,theta23,length,d;
451 theta01 = (center01-IR).theta();
452 theta23 = (center23-IR).theta();
453 length = (center01-IR).mag();
454 d = length*
tan(theta01-theta23);
457 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
458 if (xIn < (-d/2) && theModule!=21){
460 theModule=theModule+1 ;
466 }
else if(theModule==20) {
477 theta01 = (center01-IR).theta();
478 theta23 = (center23-IR).theta();
479 length = (center01-IR).mag();
480 d = length*
tan(theta01-theta23);
482 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
484 }
else if (xIn > (d/2) && theModule!=0 ){
486 theModule=theModule-1 ;
491 }
else if(theModule==20) {
503 theta01 = (center01-IR).theta();
504 theta23 = (center23-IR).theta();
505 length = (center01-IR).mag();
506 d = length*
tan(theta01-theta23);
508 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
515 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
516 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
518 if(nphi==0&&yIn>100) yIn=yIn-360;
519 if(nphi==119&&yIn<-100) yIn=yIn+360;
523 if(nphi!=0) phiModule=phiModule-1;
524 if(nphi==0) phiModule=119;
525 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
526 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
527 if(phiModule==0&&yIn>100) yIn=yIn-360;
528 if(phiModule==119&&yIn<-100) yIn=yIn+360;
535 if(nphi!=119) phiModule=phiModule+1;
536 if(nphi==119) phiModule=0;
538 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
539 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
540 if(phiModule==0&&yIn>100) yIn=yIn-360;
541 if(phiModule==119&&yIn<-100) yIn=yIn+360;
544 enecor=m_par[theModule][0]
545 +m_par[theModule][1]*xIn
546 +m_par[theModule][2]*xIn*xIn
547 +m_par[theModule][3]*xIn*xIn*xIn
548 +m_par[theModule][4]*xIn*xIn*xIn*xIn
549 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
550 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
553 +m_par[theModule][7]*yIn
554 +m_par[theModule][8]*yIn*yIn
555 +m_par[theModule][9]*yIn*yIn*yIn
556 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
564 double energyCC= energyC/(lnEcor*enecor);
581 if(!recEmcShowerCol){
582 return( StatusCode::SUCCESS);
585 if(!dstEmcShowerCol){
586 return( StatusCode::SUCCESS);
590 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())
return SUCCESS;
591 for(
int i=0;i<recEmcShowerCol->size();i++){
592 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
593 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
595 (*iter_dst)->setEnergy((*iter_rec)->energy());
596 (*iter_dst)->setStatus((*iter_rec)->status());
600 return( StatusCode::SUCCESS);
606 MsgStream log(
msgSvc(), name());
607 log << MSG::INFO <<
"in finalize()" << endmsg;
608 return StatusCode::SUCCESS;
613double AbsCor::E25min(
int n)
const
617double AbsCor::E25max(
int n)
const
624double AbsCor::ECorrMC(
double eg,
double theid)
const
627 if(eg<E25min(
int(theid))) eg=E25min(
int(theid));
628 if(eg>E25max(
int(theid))) eg=E25max(
int(theid))-0.001;
630 if(theid<=0)theid=0.001;
631 if(theid>=27)theid=26.999;
632 Float_t einter = eg + 0.00001;
633 Float_t tinter = theid+0.0001;
635 double ecor=dt->Interpolate(einter,tinter);
637 if(!(ecor))
return Energy5x5;
638 if(ecor<0.5)
return Energy5x5;
639 double EnergyCor=Energy5x5/ecor;
644double AbsCor::ErrMC(
double eg,
double theid)
const
647 if(eg<E25min(
int(theid))) eg=E25min(
int(theid));
648 if(eg>E25max(
int(theid))) eg=E25max(
int(theid))-0.001;
649 if(theid<=0)theid=0.001;
650 if(theid>=27)theid=26.999;
651 Float_t einter = eg + 0.00001;
652 Float_t tinter = theid+0.0001;
653 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