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
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(
"UseTof", usetof=1);
68 declareProperty(
"DoDataCor", dodatacor = 1);
72TGraphErrors *
dt =
new TGraphErrors();
75 MsgStream log(
msgSvc(), name());
76 log << MSG::INFO <<
"in initialize()" << endmsg;
80 if ( nt1 ) m_tuple1 = nt1;
82 m_tuple1 =
ntupleSvc()->book (
"FILE1/ec", CLID_ColumnWiseTuple,
"ks N-Tuple example");
84 status = m_tuple1->addItem (
"ef", m_ef);
85 status = m_tuple1->addItem (
"e5", m_e5);
86 status = m_tuple1->addItem (
"ec", m_ec);
87 status = m_tuple1->addItem (
"ct", m_ct);
88 status = m_tuple1->addItem (
"cedge", m_cedge);
91 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
92 return StatusCode::FAILURE;
97 m_index =
new int*[56];
98 for (
int j=0;j<56;j++ ) {
99 m_index[j] =
new int[120];
100 for (
int k=0; k<120; k++) {
105 m_par =
new double*[22];
106 for (
int j=0;j<22;j++ ) {
107 m_par[j] =
new double[11];
108 for (
int k=0; k<11; k++) {
113 m_parphi =
new double*[22];
114 for (
int j=0;j<22;j++ ) {
115 m_parphi[j] =
new double[5];
116 for (
int k=0; k<5; k++) {
124 EnParInFile = getenv(
"ABSCORROOT");
125 EnParInFile +=
"/share/para.dat";
126 EnParIn.open(EnParInFile.c_str());
127 for(
int i=0;i<22;i++) {
129 EnParIn>>m_par[i][0]>>m_par[i][1]>>m_par[i][2]>>m_par[i][3]>>m_par[i][4]
130 >>m_par[i][5]>>m_par[i][6]>>m_par[i][7]>>m_par[i][8]>>m_par[i][9]
137 string EnParInFilephi = getenv(
"ABSCORROOT");
138 EnParInFilephi +=
"/share/paraphi.dat";
139 EnParInphi.open(EnParInFilephi.c_str());
140 for(
int i=0;i<22;i++) {
141 EnParInphi>>m_parphi[i][0]>>m_parphi[i][1]>>m_parphi[i][2]>>m_parphi[i][3]>>m_parphi[i][4];
149 DataPathevse = getenv(
"ABSCORROOT");
150 DataPathevse +=
"/share/barmccorevse10bin.txt";
152 inpi0.exceptions( ifstream::failbit | ifstream::badbit );
153 inpi0.open(DataPathevse.c_str(),ios::in);
155 double epoint[11],peak[11],peakerr[11];
156 for(Int_t i=0;i<11;i++){
161 for(Int_t i=0;i<11;i++){
162 dt->SetPoint(i, epoint[i],peak[i]);
163 dt->SetPointError(i,0,peakerr[i]);
166 string DataPathcbeam;
167 DataPathcbeam = getenv(
"ABSCORROOT");
168 DataPathcbeam +=
"/share/cbeam.txt";
170 incbeam.exceptions( ifstream::failbit | ifstream::badbit );
171 incbeam.open(DataPathcbeam.c_str(),ios::in);
172 for(
int i=0; i<56; i++){
173 double tid,peak,peake,sig,sige;
183 DataPathc3p = getenv(
"ABSCORROOT");
185 string DataPathc3ptof;
186 DataPathc3ptof = getenv(
"ABSCORROOT");
188 cout<<
"mccor = "<<mccor<<endl;
190 DataPathc3p +=
"/share/c3p.txt";
191 DataPathc3ptof +=
"/share/c3ptof.txt";
194 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
195 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
196 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
197 for(
int i=0; i<4; i++){
207 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
208 return StatusCode::SUCCESS;
214 MsgStream log(
msgSvc(), name());
215 log << MSG::INFO <<
"in execute()" << endreq;
217 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
218 int runNo=eventHeader->runNumber();
222 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())
return SUCCESS;
223 if(evtRecEvent->totalTracks()>50)
return SUCCESS;
226 ISvcLocator* svcLocator = Gaudi::svcLocator();
227 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc",iGeoSvc);
228 if(sc!=StatusCode::SUCCESS) {
229 cout<<
"Error: Can't get EmcRecGeoSvc"<<endl;
232 for(
int i = 0; i< evtRecEvent->totalTracks(); i++) {
234 if(!(*itTrk)->isEmcShowerValid())
continue;
237 int st = emcTrk->
status();
238 if(st>10000)
continue;
241 if(emcTrk->
e5x5()<0.015)
continue;
259 if(usetof==1 && (*itTrk)->isTofTrackValid()){
260 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
261 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
264 double energyC=emcTrk->
energy()+etof;
275 double lnE = std::log(energyC);
277 if(
runNo>0 && dodatacor==1) lnEcor =
ai[0]+
ai[1]*lnE+
ai[2]*lnE*lnE+
ai[3]*lnE*lnE*lnE;
278 if(lnEcor<0.5)
continue;
283 unsigned int module, ntheta, nphi;
301 unsigned int theModule;
303 theModule = 43 - thetaModule;
307 theModule = thetaModule;
314 }
else if(theModule==20) {
328 double theta01,theta23,
length,d;
329 theta01 = (center01-IR).theta();
330 theta23 = (center23-IR).theta();
331 length = (center01-IR).mag();
335 xIn =
length*
tan(theta01-(pos-IR).theta())-d/2;
336 if (xIn < (-d/2) && theModule!=21){
338 theModule=theModule+1 ;
344 }
else if(theModule==20) {
355 theta01 = (center01-IR).theta();
356 theta23 = (center23-IR).theta();
357 length = (center01-IR).mag();
360 xIn =
length*
tan(theta01-(pos-IR).theta())-d/2;
362 }
else if (xIn > (d/2) && theModule!=0 ){
364 theModule=theModule-1 ;
369 }
else if(theModule==20) {
381 theta01 = (center01-IR).theta();
382 theta23 = (center23-IR).theta();
383 length = (center01-IR).mag();
386 xIn =
length*
tan(theta01-(pos-IR).theta())-d/2;
393 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
394 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
396 if(nphi==0&&yIn>100) yIn=yIn-360;
397 if(nphi==119&&yIn<-100) yIn=yIn+360;
401 if(nphi!=0) phiModule=phiModule-1;
402 if(nphi==0) phiModule=119;
403 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
404 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
405 if(phiModule==0&&yIn>100) yIn=yIn-360;
406 if(phiModule==119&&yIn<-100) yIn=yIn+360;
413 if(nphi!=119) phiModule=phiModule+1;
414 if(nphi==119) phiModule=0;
416 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
417 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
418 if(phiModule==0&&yIn>100) yIn=yIn-360;
419 if(phiModule==119&&yIn<-100) yIn=yIn+360;
422 enecor=m_par[theModule][0]
423 +m_par[theModule][1]*xIn
424 +m_par[theModule][2]*xIn*xIn
425 +m_par[theModule][3]*xIn*xIn*xIn
426 +m_par[theModule][4]*xIn*xIn*xIn*xIn
427 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
428 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
431 +m_par[theModule][7]*yIn
432 +m_par[theModule][8]*yIn*yIn
433 +m_par[theModule][9]*yIn*yIn*yIn
434 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
440 double energyCC= energyC/(lnEcor*enecor);
456 if(!recEmcShowerCol){
457 return( StatusCode::SUCCESS);
460 if(!dstEmcShowerCol){
461 return( StatusCode::SUCCESS);
465 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())
return SUCCESS;
466 for(
int i=0;i<recEmcShowerCol->size();i++){
467 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
468 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
470 (*iter_dst)->setEnergy((*iter_rec)->energy());
471 (*iter_dst)->setStatus((*iter_rec)->status());
475 return( StatusCode::SUCCESS);
481 MsgStream log(
msgSvc(), name());
482 log << MSG::INFO <<
"in finalize()" << endmsg;
483 return StatusCode::SUCCESS;
HepGeom::Point3D< double > HepPoint3D
double tan(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
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