1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/Bootstrap.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/PropertyMgr.h"
5#include "GaudiKernel/IJobOptionsSvc.h"
6#include "GaudiKernel/INTupleSvc.h"
33 IJobOptionsSvc* jobSvc;
34 Gaudi::svcLocator()->service(
"JobOptionsSvc", jobSvc);
35 jobSvc->setMyProperties(
"TofShower", &m_propMgr);
44 std::cerr <<
"Invalid ntuple in TofEnergyRec!" << std::endl;
46 m_tuple->addItem (
"part", m_part);
47 m_tuple->addItem (
"layer", m_layer);
48 m_tuple->addItem (
"im", m_im);
49 m_tuple->addItem (
"end", m_end);
50 m_tuple->addItem (
"zpos", m_zpos);
51 m_tuple->addItem (
"adc1", m_adc1);
52 m_tuple->addItem (
"adc2", m_adc2);
53 m_tuple->addItem (
"tdc1", m_tdc1);
54 m_tuple->addItem (
"tdc2", m_tdc2);
55 m_tuple->addItem (
"energy", m_energy);
60 std::cerr <<
"Invalid ntuple1 in TofEnergyRec!" << std::endl;
62 m_tuple1->addItem (
"part", m_shower_part);
63 m_tuple1->addItem (
"layer", m_shower_layer);
64 m_tuple1->addItem (
"im", m_shower_im);
65 m_tuple1->addItem (
"zpos", m_shower_zpos);
66 m_tuple1->addItem (
"energy", m_shower_energy);
71 std::cerr <<
"Invalid ntuple2 in TofEnergyRec!" << std::endl;
73 m_tuple2->addItem (
"dist", m_seed_dist);
80 ISvcLocator* svcLocator = Gaudi::svcLocator();
82 StatusCode sc = svcLocator->service(
"TofCaliSvc",
tofCaliSvc);
83 if (sc != StatusCode::SUCCESS) {
84 cout <<
"TofEnergyRec Get Calibration Service Failed !! " << endl;
88 sc = svcLocator->service(
"TofQCorrSvc",
tofQCorrSvc);
89 if (sc != StatusCode::SUCCESS) {
90 cout <<
"TofEnergyRec Get QCorr Service Failed !! " << endl;
94 sc = svcLocator->service(
"TofQElecSvc",
tofQElecSvc);
95 if (sc != StatusCode::SUCCESS) {
96 cout <<
"TofEnergyRec Get QElec Service Failed !! " << endl;
100 sc = svcLocator->service(
"TofEnergyCalibSvc", m_TofEnergyCalibSvc);
101 if( sc != StatusCode::SUCCESS){
102 cout <<
"can not use TofEnergyCalibSvc" << endreq;
119 vector<TofData*>::iterator it;
120 for(it=tofDataVec.begin();
121 it!=tofDataVec.end();
138 if((*it)->barrel()) {
142 if(bTofData->
tdc1()<=0||bTofData->
tdc1()>8000||bTofData->
tdc2()<=0||bTofData->
tdc2()>8000)
continue;
144 double adc1,adc2,tdc1,tdc2;
145 tdc1 = bTofData->
tdc1();
146 tdc2 = bTofData->
tdc2();
147 adc1 = bTofData->
adc1();
148 adc2 = bTofData->
adc2();
152 if(fabs(zpos)>115)
continue;
154 if(tofq<100||tofq>10000)
continue;
166 CalibPar[0]=m_TofEnergyCalibSvc -> getPara1();
167 CalibPar[1]=m_TofEnergyCalibSvc -> getPara2();
168 CalibPar[2]=m_TofEnergyCalibSvc -> getPara3();
169 CalibPar[3]=m_TofEnergyCalibSvc -> getPara4();
170 CalibPar[4]=m_TofEnergyCalibSvc -> getPara5();
172 double TofEnCalibConst=CalibPar[0]+CalibPar[1]*zpos+CalibPar[2]*pow(zpos,2)+CalibPar[3]*pow(zpos,3)+CalibPar[4]*pow(zpos,4);
173 double energy = tofq*TofEnCalibConst;
186 m_adc1 = bTofData->
adc1();
187 m_adc2 = bTofData->
adc2();
188 m_tdc1 = bTofData->
tdc1();
189 m_tdc2 = bTofData->
tdc2();
211 if( barrel_ec!=3 || ( endcap!=0 && endcap!=1 ) ) {
212 cout <<
"TofEnergyRec Get ETF(MRPC) data ERROR !! barrel_ec:" << barrel_ec <<
" endcap:" << endcap << endl;
225 if(etfData->
tdc1()<=0||etfData->
tdc1()>8000||etfData->
tdc2()<=0||etfData->
tdc2()>8000)
continue;
227 double adc1,adc2,tdc1,tdc2;
228 tdc1 = etfData->
tdc1();
229 tdc2 = etfData->
tdc2();
230 adc1 = etfData->
adc1();
231 adc2 = etfData->
adc2();
235 if(fabs(zpos)>115)
continue;
237 if(tofq<100||tofq>10000)
continue;
239 double energy = tofq*m_calibConst;
251 m_adc1 = etfData->
adc1();
252 m_adc2 = etfData->
adc2();
253 m_tdc1 = etfData->
tdc1();
254 m_tdc2 = etfData->
tdc2();
266 vector<int> NeighborVec;
267 vector<Identifier> NeighborIdVec;
269 NeighborIdVec.clear();
278 int num = im+layer*88;
281 NeighborVec.push_back(1);
282 NeighborVec.push_back(87);
283 NeighborVec.push_back(88);
284 NeighborVec.push_back(89);
286 NeighborVec.push_back(0);
287 NeighborVec.push_back(86);
288 NeighborVec.push_back(88);
289 NeighborVec.push_back(175);
291 NeighborVec.push_back(
num+1);
292 NeighborVec.push_back(
num-1);
293 NeighborVec.push_back(
num+88);
294 NeighborVec.push_back(
num+88+1);
298 NeighborVec.push_back(89);
299 NeighborVec.push_back(175);
300 NeighborVec.push_back(0);
301 NeighborVec.push_back(87);
302 }
else if(
num==175) {
303 NeighborVec.push_back(88);
304 NeighborVec.push_back(174);
305 NeighborVec.push_back(86);
306 NeighborVec.push_back(87);
308 NeighborVec.push_back(
num+1);
309 NeighborVec.push_back(
num-1);
310 NeighborVec.push_back(
num-88);
311 NeighborVec.push_back(
num-88-1);
315 int size=NeighborVec.size();
316 for(
int i=0;i<size;i++) {
317 layer = NeighborVec[i]/88;
318 im = NeighborVec[i]%88;
325 NeighborVec.push_back(1);
326 NeighborVec.push_back(47);
328 NeighborVec.push_back(0);
329 NeighborVec.push_back(46);
331 NeighborVec.push_back(im-1);
332 NeighborVec.push_back(im+1);
335 int size=NeighborVec.size();
336 for(
int i=0;i<size;i++) {
350 NeighborVec.push_back(1);
351 NeighborVec.push_back(35);
352 }
else if( module==35 ) {
353 NeighborVec.push_back(0);
354 NeighborVec.push_back(34);
356 NeighborVec.push_back(module-1);
357 NeighborVec.push_back(module+1);
360 int size=NeighborVec.size();
361 for(
int i=0;i<size;i++) {
362 int im = NeighborVec[i];
363 for(
int j=-2; j<3; j++ ) {
365 if( ist<0 || ist>11 )
continue;
366 NeighborIdVec.push_back(
TofID::cell_id(barrel_ec,endcap,module,ist,end));
372 return NeighborIdVec;
377 vector<Identifier> NeighborVec,tmpNeighborVec,tmpNextNeighborVec;
378 vector<Identifier>::iterator ci_NV,ci_tmpNV,ci_tmpNNV;
382 bool flagNeighbor=
false;
385 for(ci_tmpNV=tmpNeighborVec.begin();
386 ci_tmpNV!=tmpNeighborVec.end();
390 for(ci_tmpNNV=tmpNextNeighborVec.begin();
391 ci_tmpNNV!=tmpNextNeighborVec.end();
394 for(ci_NV=NeighborVec.begin();
395 ci_NV!=NeighborVec.end();
397 if(*ci_tmpNNV==*ci_NV){
417 NeighborVec.push_back(*ci_tmpNNV);
439 vector<TofData*>::iterator it;
440 for(it=tofDataVec.begin();
441 it!=tofDataVec.end();
444 if( !((*it)->is_mrpc()) ) {
445 if((*it)->barrel()) {
450 if(bTofData->
energy()<5.)
continue;
458 vector<Identifier>::iterator iNeigh;
459 for(iNeigh=NeighborVec.begin();
460 iNeigh!=NeighborVec.end();
466 vector<TofData*>::iterator it2;
467 for(it2=tofDataVec.begin();
468 it2!=tofDataVec.end();
470 if((*it2)->identify()==*iNeigh) {
485 if(eTofData->
energy()<5.)
continue;
488 vector<Identifier>::iterator iNeigh;
489 for(iNeigh=NeighborVec.begin(); iNeigh!=NeighborVec.end(); iNeigh++)
491 vector<TofData*>::iterator it2;
492 for(it2=tofDataVec.begin(); it2!=tofDataVec.end(); it2++)
494 if((*it2)->identify()==*iNeigh) {
510 if(etfData->
energy()<2.)
continue;
513 vector<Identifier>::iterator iNeigh;
514 for(iNeigh=NeighborVec.begin(); iNeigh!=NeighborVec.end(); iNeigh++)
517 vector<TofData*>::iterator it2;
518 for(it2=tofDataVec.begin(); it2!=tofDataVec.end(); it2++)
520 if((*it2)->identify()==*iNeigh) {
533 m_seedVec.push_back(
Identifier((*it)->identify()));
548 vector<Identifier>::iterator iSeed;
550 for(iSeed=m_seedVec.begin(); iSeed!=m_seedVec.end(); iSeed++)
565 RecTofTrackCol::iterator iTrack, iMatch;
566 for(iTrack=recTofTrackCol->begin(); iTrack!=recTofTrackCol->end(); iTrack++)
570 if( barrel_ec==1 && status->
is_barrel() ) {
571 dphi=
abs(im-(*iTrack)->tofID());
572 dphi = dphi>=44 ? 88-dphi : dphi;
573 }
else if( barrel_ec==2 && !(status->
is_barrel()) && ((*iTrack)->tofID()>47) ) {
574 dphi=
abs(im-(*iTrack)->tofID()+48);
575 dphi = dphi>=24 ? 48-dphi : dphi;
576 }
else if( barrel_ec==0 && !(status->
is_barrel()) && ((*iTrack)->tofID()<48) ) {
577 dphi=
abs(im-(*iTrack)->tofID());
578 dphi = dphi>=24 ? 48-dphi : dphi;
594 vector<TofData*>::iterator it;
595 for(it=tofDataVec.begin(); it!=tofDataVec.end(); it++)
597 if((*it)->identify()==*iSeed) {
599 if((*it)->barrel()) {
603 seedPos=bTofData->
zpos();
617 vector<Identifier>::iterator iNeigh;
618 for(iNeigh=NeighborVec.begin(); iNeigh!=NeighborVec.end(); iNeigh++)
621 vector<TofData*>::iterator it2;
622 for(it2=tofDataVec.begin(); it2!=tofDataVec.end(); it2++)
624 if((*it2)->identify()==*iNeigh) {
626 if((*it)->barrel()) {
629 if(fabs(bTofData2->
zpos())>2)
continue;
631 m_seed_dist = seedPos-bTofData2->
zpos();
634 if(fabs(seedPos-bTofData2->
zpos())>0.3)
continue;
651 (*iMatch)->setEnergy(
energy/1000);
665 recTofTrackCol->push_back(tof);
668 m_shower_part = barrel_ec;
669 m_shower_layer = layer;
671 m_shower_zpos = zpos;
691 int dphi=999, dtheta=999;
692 RecTofTrackCol::iterator iTrack, iMatch;
693 for(iTrack=recTofTrackCol->begin(); iTrack!=recTofTrackCol->end(); iTrack++)
697 if( barrel_ec==3 && endcap==0 && ((*iTrack)->tofID()<36) ) {
698 dphi =
abs(im-(*iTrack)->tofID());
699 dphi = dphi>=18 ? 36-dphi : dphi;
700 dtheta =
abs( strip - status->
layer() );
701 }
else if( barrel_ec==3 && endcap==1 && ((*iTrack)->tofID()>35) ) {
702 dphi=
abs(im-(*iTrack)->tofID()+36);
703 dphi = dphi>=18 ? 36-dphi : dphi;
704 dtheta =
abs( strip - status->
layer() );
706 if( (
abs(dphi)==0 &&
abs(dtheta)<=2 ) || (
abs(dphi)==1 &&
abs(dtheta)<=1 ) ) {
720 vector<TofData*>::iterator it;
721 for(it=tofDataVec.begin(); it!=tofDataVec.end(); it++)
723 if((*it)->identify()==*iSeed) {
727 seedPos=etfData->
zpos();
733 vector<Identifier>::iterator iNeigh;
734 for(iNeigh=NeighborVec.begin(); iNeigh!=NeighborVec.end(); iNeigh++)
736 vector<TofData*>::iterator it2;
737 for(it2=tofDataVec.begin(); it2!=tofDataVec.end(); it2++)
739 if((*it)->barrel())
continue;
740 if((*it2)->identify()==*iNeigh) {
742 if(fabs(etfData2->
zpos())>2)
continue;
744 m_seed_dist = seedPos-etfData2->
zpos();
747 if(fabs(seedPos-etfData2->
zpos())>0.3)
continue;
760 (*iMatch)->setEnergy(
energy/1000);
774 recTofTrackCol->push_back(tof);
777 m_shower_part = barrel_ec;
778 m_shower_layer = strip;
780 m_shower_zpos = zpos;
792 string paraPath = getenv(
"TOFENERGYRECROOT");
793 paraPath +=
"/share/peak.dat";
795 in.open(paraPath.c_str());
797 for(
int i=0;i<176;i++) {
802 paraPath = getenv(
"TOFENERGYRECROOT");
803 paraPath +=
"/share/calib.dat";
805 in1.open(paraPath.c_str());
807 for(
int i=0;i<176;i++) {
808 in1>>m_calib[i][0]>>m_calib[i][1]>>m_calib[i][2]>>m_calib[i][3];
816 return m_ecalib[nsci];
832 return m_calib[n][m];
************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
ObjectVector< RecTofTrack > RecTofTrackCol
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
void setStatus(unsigned int status)
void setEnergy(double energy)
void setZrHit(double zrhit)
virtual const double BPh(double ADC1, double ADC2, double zHit, unsigned int id)=0
virtual const double ZTDC(double tleft, double tright, unsigned id)=0
void setEnergy(double energy)
void setZpos(double zpos)
unsigned int identify() const
unsigned int layer() const
unsigned int value() const
void setStatus(unsigned int status)
static int endcap(const Identifier &id)
static int strip(const Identifier &id)
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
static bool is_scin(const Identifier &id)
static int end(const Identifier &id)
static bool is_mrpc(const Identifier &id)
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static int layer(const Identifier &id)
static int module(const Identifier &id)
double calib(const int n, const int m) const
double ecalib(const int nsci) const
void findSeed(vector< TofData * > &tofDataVec)
void BookNtuple(NTuple::Tuple *&tuple, NTuple::Tuple *&tuple1, NTuple::Tuple *&tuple2)
void setEcalib(const int nsci, const double ecalib)
void energyCalib(vector< TofData * > &tofDataVec, RecTofTrackCol *recTofTrackCol)
vector< Identifier > getNextNeighbors(const Identifier &id)
void setCalib(const int n, const int m, const double ecalib)
vector< Identifier > getNeighbors(const Identifier &id)
void findShower(vector< TofData * > &tofDataVec, RecTofTrackCol *recTofTrackCol, double)