112 {
113
114
115
116
117
118
119
120 MsgStream log(
msgSvc(), name());
121 log << MSG::INFO << "in execute()" << endreq;
122
123 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
124 int run = eventHeader->runNumber();
125
126 m_run=run;
127
128 int event = eventHeader->eventNumber();
129 if(m_event%1000==0) {
130 std::cout << m_event << "-------------TofEnergyCalib run,event: " << run << "," << event << std::endl;
131 }
132 m_event++;
133
136
137 log << MSG::DEBUG <<"ncharg, nneu, tottks = "
138 << evtRecEvent->totalCharged() << " , "
139 << evtRecEvent->totalNeutral() << " , "
140 << evtRecEvent->totalTracks() <<endreq;
141
142 if(evtRecEvent->totalCharged() != 2) {
143 return StatusCode::SUCCESS;
144 }
145
146
148 StatusCode sc = service(
"RawDataProviderSvc",
tofDigiSvc);
149 if (sc != StatusCode::SUCCESS) {
150 log << MSG::ERROR << "TofRec Get Tof Raw Data Service Failed !! " << endreq;
151 return StatusCode::SUCCESS;
152 }
153
154
156 StatusCode scc = service(
"TofCaliSvc",
tofCaliSvc);
157 if (scc != StatusCode::SUCCESS) {
158 log << MSG::ERROR << "TofRec Get Calibration Service Failed !! " << endreq;
159 return StatusCode::SUCCESS;
160 }
161
162
165 if (sc != StatusCode::SUCCESS) {
166 log << MSG::ERROR << "TofRec Get QCorr Service Failed !! " << endreq;
167 return StatusCode::SUCCESS;
168 }
169
172 if (sc != StatusCode::SUCCESS) {
173 log << MSG::ERROR << "TofRec Get QElec Service Failed !! " << endreq;
174 return StatusCode::SUCCESS;
175 }
176
177
178 std::vector<TofData*> tofDataVec;
180 const unsigned int ADC_MASK = 0x00001FFF;
181
182 for(int i = 0; i < evtRecEvent->totalCharged(); i++) {
184
185 if(!(*itTrk)->isExtTrackValid()) continue;
187
188 if(!(*itTrk)->isTofTrackValid()) continue;
189
190
191 int npart, tof1, tof2;
192 Hep3Vector pos1, pos2;
194
197
198
199
200 if(tof1>=0 && tof1<88 && tof2>=88 && tof2<176) {
201 npart = 1;
202 } else if(tof1>=176 && tof1<224) {
203 tof1 -= 176;
204 npart = 2;
205 } else if(tof1>=224 && tof1<272) {
206 tof1 -= 224;
207 npart = 0;
208 } else {
209 continue;
210 }
211
214
217
218 double zpos1=0, zpos2=0, l1=0, l2=0, lext=0;
219 double z1, xy1, z2, xy2;
220
221 if(npart==1) {
222
223 const double tofDPhi = CLHEP::twopi / 88.;
224 double tofPhi1 = tof1*tofDPhi + tofDPhi/2;
225 double tofPhi2 = (tof2-88)*tofDPhi;
226
227
228 double extTheta1, extTheta2, extPhi1, extPhi2;
229 extTheta1 = pos1.theta();
230 extTheta2 = pos2.theta();
231 extPhi1 = pos1.phi();
232 extPhi2 = pos2.phi();
233
234
235
236 z1 = 5/
tan(extTheta1);
237 xy1 = 5/
cos(extPhi1-tofPhi1);
238 l1 = sqrt(z1*z1+xy1*xy1);
239 z2 = 5/
tan(extTheta2);
240 xy2 = 5/
cos(extPhi2-tofPhi2);
241 l2 = sqrt(z2*z2+xy2*xy2);
242 zpos1 = (pos1.z()+z1/2)/100;
243 zpos2 = (pos2.z()+z2/2)/100;
244
245
247 }
248
249 else {
250
251 double extTheta1 = pos1.theta();
252
253
254
255 l1 = 5./fabs(
cos(extTheta1));
256 zpos1 = (sqrt(pos1.x()*pos1.x()+pos1.y()*pos1.y())+5.*
tan(extTheta1)/2)/100;
257 }
258
259 vector<TofData*>::iterator it;
260
261
262 for(it=tofDataVec.begin();
263 it!=tofDataVec.end();
264 it++) {
265
269 if(im+layer*88==tof1-1 || im+layer*88==tof1+1 ||
270 im+layer*88==tof1-2 || im+layer*88==tof1+2) {
271
272 return StatusCode::SUCCESS;
273 }
274 }
275
276 for(it=tofDataVec.begin();
277 it!=tofDataVec.end();
278 it++) {
279
283
284 double adc1,adc2,tdc1,tdc2,ztdc,tofq;
285 if((*it)->barrel()) {
287 tdc1 = bTofData->
tdc1();
288 tdc2 = bTofData->
tdc2();
289 adc1 = bTofData->
adc1();
290 adc2 = bTofData->
adc2();
291
294 if(tofq<100||tofq>10000) continue;
295
296 npart = 1;
297
298 } else {
300
301 adc1 = eTofData->
adc();
302 tdc1 = eTofData->
tdc();
303 npart = 2;
304 }
305
306
307 if(im+layer*88==tof1) {
308 m_adc1 = adc1;
309 m_adc2 = adc2;
310 m_tdc1 = tdc1;
311 m_tdc2 = tdc2;
312 m_ztdc = ztdc;
313 m_q = tofq;
314 m_npart = npart;
315 m_number = tof1;
316 m_zpos = zpos1;
317 m_length = l1;
318 m_length_ext = lext;
319
320 m_energy = l1*10.25/5.;
321 m_energy_ext = lext*10.25/5.;
322
323
324 if(
abs(m_zpos)<0.6&&m_q>500&&m_q<4000){
325 m_num++;
326 m_EvsQ = m_EvsQ+ m_energy/m_q;
327 }
328 m_tuple->write();
329 } else if((*it)->barrel() && im+layer*88 == tof2) {
330 m_adc1 = adc1;
331 m_adc2 = adc2;
332 m_tdc1 = tdc1;
333 m_tdc2 = tdc2;
334 m_ztdc = ztdc;
335 m_q = tofq;
336 m_npart = npart;
337 m_number = tof2;
338 m_zpos = zpos2;
339 m_length = l2;
340 m_length_ext = lext;
341
342 m_energy = l2*10.25/5.;
343 m_energy_ext = lext*10.25/5.;
344
345 m_tuple->write();
346
347 if(
abs(m_zpos)<0.6&&m_q>500&&m_q<4000){
348 m_num++;
349 m_EvsQ = m_EvsQ+m_energy/m_q;
350
351 }
352
353
354 }
355 }
356
357 }
358
359
360
361 return sc;
362}
double tan(const BesAngle a)
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
IRawDataProviderSvc * tofDigiSvc
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
static int phi_module(const Identifier &id)
static int layer(const Identifier &id)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol