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"
13#include "GaudiKernel/INTupleSvc.h"
14#include "GaudiKernel/NTuple.h"
15#include "GaudiKernel/Bootstrap.h"
16#include "GaudiKernel/IHistogramSvc.h"
17#include "CLHEP/Vector/ThreeVector.h"
18using CLHEP::Hep3Vector;
19#include "CLHEP/Vector/LorentzVector.h"
20using CLHEP::HepLorentzVector;
21#include "CLHEP/Vector/TwoVector.h"
22using CLHEP::Hep2Vector;
23#include "CLHEP/Geometry/Point3D.h"
24#ifndef ENABLE_BACKWARDS_COMPATIBILITY
43typedef std::vector<int>
Vint;
49 Algorithm(name, pSvcLocator) {
52 declareProperty(
"Event", m_event = 0);
53 declareProperty(
"IsData", m_isData =
true);
58 MsgStream log(
msgSvc(), name());
60 log << MSG::INFO <<
"in initialize()" << endmsg;
64 if ( nt ) m_tuple = nt;
66 m_tuple =
ntupleSvc()->book (
"FILE1/dimu", CLID_ColumnWiseTuple,
"ks N-Tuple example");
68 status = m_tuple->addItem (
"npart", m_npart);
69 status = m_tuple->addItem (
"number", m_number);
70 status = m_tuple->addItem (
"adc1", m_adc1);
71 status = m_tuple->addItem (
"adc2", m_adc2);
72 status = m_tuple->addItem (
"tdc1", m_tdc1);
73 status = m_tuple->addItem (
"tdc2", m_tdc2);
74 status = m_tuple->addItem (
"zpos", m_zpos);
75 status = m_tuple->addItem (
"length", m_length);
76 status = m_tuple->addItem (
"energy", m_energy);
77 status = m_tuple->addItem (
"lengthext", m_length_ext);
78 status = m_tuple->addItem (
"energyext", m_energy_ext);
79 status = m_tuple->addItem (
"ztdc", m_ztdc);
80 status = m_tuple->addItem (
"q", m_q);
83 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple) << endmsg;
84 return StatusCode::FAILURE;
91 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
92 return StatusCode::SUCCESS;
105 MsgStream log(
msgSvc(), name());
106 log << MSG::INFO <<
"in execute()" << endreq;
108 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
109 int run = eventHeader->runNumber();
110 int event = eventHeader->eventNumber();
111 if(m_event%1000==0) {
112 std::cout << m_event <<
"-------------TofEnergyCalib run,event: " << run <<
"," <<
event << std::endl;
119 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
120 << evtRecEvent->totalCharged() <<
" , "
121 << evtRecEvent->totalNeutral() <<
" , "
122 << evtRecEvent->totalTracks() <<endreq;
124 if(evtRecEvent->totalCharged() != 2) {
125 return StatusCode::SUCCESS;
130 StatusCode sc = service(
"RawDataProviderSvc",
tofDigiSvc);
131 if (sc != StatusCode::SUCCESS) {
132 log << MSG::ERROR <<
"TofRec Get Tof Raw Data Service Failed !! " << endreq;
133 return StatusCode::SUCCESS;
138 StatusCode scc = service(
"TofCaliSvc",
tofCaliSvc);
139 if (scc != StatusCode::SUCCESS) {
140 log << MSG::ERROR <<
"TofRec Get Calibration Service Failed !! " << endreq;
141 return StatusCode::SUCCESS;
147 if (sc != StatusCode::SUCCESS) {
148 log << MSG::ERROR <<
"TofRec Get QCorr Service Failed !! " << endreq;
149 return StatusCode::SUCCESS;
154 if (sc != StatusCode::SUCCESS) {
155 log << MSG::ERROR <<
"TofRec Get QElec Service Failed !! " << endreq;
156 return StatusCode::SUCCESS;
160 std::vector<TofData*> tofDataVec;
162 const unsigned int ADC_MASK = 0x00001FFF;
164 for(
int i = 0; i < evtRecEvent->totalCharged(); i++) {
167 if(!(*itTrk)->isExtTrackValid())
continue;
170 if(!(*itTrk)->isTofTrackValid())
continue;
173 int npart, tof1, tof2;
174 Hep3Vector pos1, pos2;
182 if(tof1>=0 && tof1<88 && tof2>=88 && tof2<176) {
184 }
else if(tof1>=176 && tof1<224) {
187 }
else if(tof1>=224 && tof1<272) {
200 double zpos1=0, zpos2=0, l1=0, l2=0, lext=0;
201 double z1, xy1, z2, xy2;
205 const double tofDPhi = CLHEP::twopi / 88.;
206 double tofPhi1 = tof1*tofDPhi + tofDPhi/2;
207 double tofPhi2 = (tof2-88)*tofDPhi;
210 double extTheta1, extTheta2, extPhi1, extPhi2;
211 extTheta1 = pos1.theta();
212 extTheta2 = pos2.theta();
213 extPhi1 = pos1.phi();
214 extPhi2 = pos2.phi();
218 z1 = 5/
tan(extTheta1);
219 xy1 = 5/
cos(extPhi1-tofPhi1);
220 l1 = sqrt(z1*z1+xy1*xy1);
221 z2 = 5/
tan(extTheta2);
222 xy2 = 5/
cos(extPhi2-tofPhi2);
223 l2 = sqrt(z2*z2+xy2*xy2);
224 zpos1 = (pos1.z()+z1/2)/100;
225 zpos2 = (pos2.z()+z2/2)/100;
233 double extTheta1 = pos1.theta();
237 l1 = 5./fabs(
cos(extTheta1));
238 zpos1 = (sqrt(pos1.x()*pos1.x()+pos1.y()*pos1.y())+5.*
tan(extTheta1)/2)/100;
241 vector<TofData*>::iterator it;
244 for(it=tofDataVec.begin();
245 it!=tofDataVec.end();
251 if(im+layer*88==tof1-1 || im+layer*88==tof1+1 ||
252 im+layer*88==tof1-2 || im+layer*88==tof1+2) {
254 return StatusCode::SUCCESS;
258 for(it=tofDataVec.begin();
259 it!=tofDataVec.end();
266 double adc1,adc2,tdc1,tdc2,ztdc,tofq;
267 if((*it)->barrel()) {
269 tdc1 = bTofData->
tdc1();
270 tdc2 = bTofData->
tdc2();
271 adc1 = bTofData->
adc1();
272 adc2 = bTofData->
adc2();
276 if(tofq<100||tofq>10000)
continue;
283 adc1 = eTofData->
adc();
284 tdc1 = eTofData->
tdc();
289 if(im+layer*88==tof1) {
302 m_energy = l1*10.25/5.;
303 m_energy_ext = lext*10.25/5.;
306 }
else if((*it)->barrel() && im+layer*88 == tof2) {
319 m_energy = l2*10.25/5.;
320 m_energy_ext = lext*10.25/5.;
335 MsgStream log(
msgSvc(), name());
336 log << MSG::INFO <<
"in finalize()" << endmsg;
337 return StatusCode::SUCCESS;
double tan(const BesAngle a)
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
IRawDataProviderSvc * tofDigiSvc
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
HepGeom::Point3D< double > HepPoint3D
const double tof1Path() const
const Hep3Vector tof1Position() const
const int tof1VolumeNumber() const
const Hep3Vector tof2Momentum() const
const Hep3Vector tof1Momentum() const
const double tof2Path() const
const int tof2VolumeNumber() const
const Hep3Vector tof2Position() const
virtual TofDataVector & tofDataVectorTof(double estime=0)=0
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
TofEnergyCalib(const std::string &name, ISvcLocator *pSvcLocator)
static int phi_module(const Identifier &id)
static int layer(const Identifier &id)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol