BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
EsTimeAlg.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <vector>
3#include <algorithm>
4
7#include "TrackUtil/Helix.h"
10
11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/AlgFactory.h"
13#include "GaudiKernel/ISvcLocator.h"
14#include "GaudiKernel/IDataManagerSvc.h"
15#include "GaudiKernel/SmartDataPtr.h"
16#include "GaudiKernel/IDataProviderSvc.h"
17#include "GaudiKernel/IJobOptionsSvc.h"
18#include "GaudiKernel/IMessageSvc.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/StatusCode.h"
21#include "GaudiKernel/PropertyMgr.h"
22#include "GaudiKernel/INTupleSvc.h"
23#include "GaudiKernel/IHistogramSvc.h"
24#include "AIDA/IHistogramFactory.h"
25
26#include "McTruth/McParticle.h"
28#include "MdcRawEvent/MdcDigi.h"
29#include "TofRawEvent/TofDigi.h"
30#include "McTruth/TofMcHit.h"
37#include "CLHEP/Vector/ThreeVector.h"
38#include "GaudiKernel/IPartPropSvc.h"
39#include "TrigEvent/TrigData.h"
44
50
52#include "Identifier/TofID.h"
53#include "Identifier/MdcID.h"
55
56#include "CLHEP/Vector/ThreeVector.h"
57#include "CLHEP/Geometry/Point3D.h"
58#ifndef ENABLE_BACKWARDS_COMPATIBILITY
60#endif
61
62
63using CLHEP::HepVector;
64using CLHEP::Hep3Vector;
65using CLHEP::HepMatrix;
66using CLHEP::HepSymMatrix;
67typedef std::vector<double> Vdouble;
68
69using namespace std;
70using namespace Event;
71
72// Constants
73
74const double VLIGHT=29.98;
75const double ELMAS2=0.511E-3*0.511E-3;
76const double MUMAS2=105.658E-3*105.658E-3;
77const double PIMAS2=139.569E-3*139.569E-3;
78const double PROTONMAS2=938.272E-3*938.272E-3;
79const double RCTOF2=81.*81.;
80const double RCEMC2=94.2*94.2;
81const double TDC2NSEC=0.5, NSEC2TDC=2.0;
82const double PI=3.141593,PIBY44=3.141593/44.;
83const double VELPROP=33.33;
84
85EsTimeAlg::EsTimeAlg(const std::string& name, ISvcLocator* pSvcLocator):
86 Algorithm(name, pSvcLocator){
87 for(int i = 0; i < 5; i++) m_pass[i] = 0;
88 m_flag=1;
89 m_nbunch=3;
91 m_beforrec=1;
94 m_evtNo=0;
95 m_ebeam=1.85;
97 m_debug=0;
98 declareProperty("MdcMethod",m_flag);
99 declareProperty("Nbunch" ,m_nbunch);
100 declareProperty("BunchtimeMC" ,m_bunchtime_MC=8.0);//assign bunch interval for MC; for data it's always obtained from calibration constants.
101 declareProperty("NtupleFlag",m_ntupleflag);
102 declareProperty("beforrec",m_beforrec);
103 declareProperty("Cosmic", m_optCosmic);
104 declareProperty("CosmScheme",m_cosmicScheme);
105 declareProperty("EventNo", m_evtNo);
106 declareProperty("Ebeam", m_ebeam);
107 declareProperty("UseRawTime", m_userawtime_opt);
108 declareProperty("RawOffset_b", toffset_rawtime=0.0);
109 declareProperty("RawOffset_e", toffset_rawtime_e=0.0);
110 declareProperty("Offset_dt_b", offset_dt=0.0);
111 declareProperty("Offset_dt_e", offset_dt_end=0.0);
112 declareProperty("debug", m_debug);
113 declareProperty("UseXT", m_useXT=true);
114 declareProperty("UseT0", m_useT0cal=true);
115 declareProperty("UseSw", m_useSw=false);
116 declareProperty("MdcOpt", m_mdcopt=false);
117 declareProperty("TofOpt", m_TofOpt=false);
118 declareProperty("TofOptCut",m_TofOpt_Cut=12.);
119 declareProperty("UseTimeFactor",m_useTimeFactor=true);
120 }
121
123
124 MsgStream log(msgSvc(), name());
125 log << MSG::INFO << "in initialize()" << endreq;
126 if(m_ntupleflag){
127
128 NTuplePtr nt2(ntupleSvc(),"FILE105/h2");
129
130 if ( nt2 ) m_tuple2 = nt2;
131 else {
132 m_tuple2=ntupleSvc()->book("FILE105/h2",CLID_ColumnWiseTuple,"Event Start Time");
133
134 if( m_tuple2 ) {
135
136 m_tuple2->addItem ("eventNo", g_eventNo);
137 m_tuple2->addItem ("runNo", g_runNo);
138 //#ifndef McTruth
139 m_tuple2->addItem ("NtrackMC", g_ntrkMC,0,5000);
140 m_tuple2->addItem ("MCtheta0", g_ntrkMC, g_theta0MC);
141 m_tuple2->addItem ("MCphi0", g_ntrkMC, g_phi0MC);
142 m_tuple2->addItem ("pxMC",g_ntrkMC, g_pxMC);
143 m_tuple2->addItem ("pyMC", g_ntrkMC, g_pyMC);
144 m_tuple2->addItem ("pzMC",g_ntrkMC, g_pzMC);
145 m_tuple2->addItem ("ptMC", g_ntrkMC, g_ptMC);
146 m_tuple2->addItem ("mct0",g_mcTestime);
147 //#endif
148 m_tuple2->addItem ("Ntrack", g_ntrk,0,5000);
149 m_tuple2->addItem ("ttof",g_ntrk, g_ttof);
150 m_tuple2->addItem ("velocity",g_ntrk,g_vel);
151 m_tuple2->addItem ("abmom",g_ntrk,g_abmom);
152 m_tuple2->addItem ("pid",g_ntrk,g_pid);
153 m_tuple2->addItem ("nmatchBarrel",g_nmatchbarrel);
154 m_tuple2->addItem ("nmatchBarrel_1",g_nmatchbarrel_1);
155 m_tuple2->addItem ("nmatchBarrel_2",g_nmatchbarrel_2);
156 m_tuple2->addItem ("nmatchend",g_nmatchend);
157 m_tuple2->addItem ("nmatch",g_nmatch_tot);
158 m_tuple2->addItem ("t0forward",g_ntrk,g_t0for);
159 m_tuple2->addItem ("t0backward",g_ntrk,g_t0back);
160 m_tuple2->addItem ("meant0",g_meant0);
161 m_tuple2->addItem ("nmatchmdc",g_nmatchmdc);
162 m_tuple2->addItem ("ndriftt",g_ndriftt);
163 m_tuple2->addItem ("MdcEsTime",g_EstimeMdc);
164 m_tuple2->addItem ("Mdct0mean",g_t0mean);
165 m_tuple2->addItem ("Mdct0try",g_t0);
166 m_tuple2->addItem ("Mdct0sq",g_T0);
167 m_tuple2->addItem ("trigtiming",g_trigtiming);
168 m_tuple2->addItem ( "meantdc" , g_meantdc);
169 // m_tuple2->addItem ( "meantev" , g_meantev);
170 m_tuple2->addItem ( "ntofup" , g_ntofup,0,500);
171 m_tuple2->addItem ( "ntofdown" , g_ntofdown,0,500);
172 m_tuple2->addIndexedItem ( "meantevup" , g_ntofup,g_meantevup);
173 m_tuple2->addIndexedItem ( "meantevdown" ,g_ntofdown, g_meantevdown);
174 m_tuple2->addItem ( "ntofup1" , g_ntofup1);
175 m_tuple2->addItem ( "ntofdown1" , g_ntofdown1);
176 m_tuple2->addItem ( "Testime_fzisan", g_Testime_fzisan);
177 m_tuple2->addItem ( "Testime", g_Testime);
178 m_tuple2->addItem ( "T0barrelTof", g_t0barrelTof);
179 m_tuple2->addItem ( "difftofb", g_difftof_b);
180 m_tuple2->addItem ( "difftofe", g_difftof_e);
181 m_tuple2->addItem ("EstFlag",m_estFlag);
182 m_tuple2->addItem ("EstTime",m_estTime);
183 }
184 else { // did not manage to book the N tuple....
185 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple2) << endmsg;
186 }
187 }
188 NTuplePtr nt9(ntupleSvc(),"FILE105/h9");
189
190 if ( nt9 ) m_tuple9 = nt9;
191 else {
192 m_tuple9=ntupleSvc()->book("FILE105/h9",CLID_ColumnWiseTuple,"Event Start time");
193
194 if( m_tuple9 ) {
195 m_tuple9->addItem ( "Nmatch" , g_nmatch,0,500);
196 m_tuple9->addIndexedItem ( "meantev" , g_nmatch,g_meantev);
197 }
198 else{
199 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple9) << endmsg;
200 }
201 }
202 NTuplePtr nt3(ntupleSvc(),"FILE105/calibconst");
203
204 if ( nt3 ) m_tuple3 = nt3;
205 else {
206 m_tuple3=ntupleSvc()->book("FILE105/calibconst",CLID_ColumnWiseTuple,"Event Start time");
207
208 if( m_tuple3 ) {
209 m_tuple3->addItem ( "t0offsetb" , g_t0offset_b);
210 m_tuple3->addItem ( "t0offsete" , g_t0offset_e);
211 m_tuple3->addItem ( "bunchtime", g_bunchtime);
212 }
213 else{
214 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple3) << endmsg;
215 }
216 }
217 }
218
219
220 // Get the Particle Properties Service
221 IPartPropSvc* p_PartPropSvc;
222 static const bool CREATEIFNOTTHERE(true);
223 StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
224 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
225 log << MSG::ERROR << " Could not initialize Particle Properties Service" << endreq;
226 return PartPropStatus;
227 }
228 m_particleTable = p_PartPropSvc->PDT();
229 //IRawDataProviderSvc* m_rawDataProviderSvc;
230 StatusCode RawDataStatus = service ("RawDataProviderSvc", m_rawDataProviderSvc, CREATEIFNOTTHERE);
231 if ( !RawDataStatus.isSuccess() ){
232 log<<MSG::ERROR << "Could not load RawDataProviderSvc!" << m_rawDataProviderSvc << endreq;
233 return RawDataStatus;
234 }
235
237 StatusCode sc_det = service("DetVerSvc", detVerSvc);
238 if( sc_det.isFailure() ) {
239 log << MSG::ERROR << "can't retrieve DetVerSvc instance" << endreq;
240 return sc_det;
241 }
243
244
245 StatusCode sc = service("CalibDataSvc", m_pCalibDataSvc, true);
246 if ( !sc.isSuccess() ) {
247 log << MSG::ERROR
248 << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
249 << endreq;
250 return sc;
251 } else {
252 log << MSG::DEBUG
253 << "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
254 << endreq;
255 }
256 sc = service("CalibRootCnvSvc", m_pRootSvc, true);
257 if ( !sc.isSuccess() ) {
258 log << MSG::ERROR
259 << "Could not get ICalibRootSvc interface of CalibRootCnvSvc"
260 << endreq;
261 return sc;
262 }
263 // Get properties from the JobOptionsSvc
264
265 sc = setProperties();
266
267 //Get TOF Calibtration Service
268 //IEstTofCaliSvc* tofCaliSvc;
269 StatusCode scc = service("EstTofCaliSvc", tofCaliSvc);
270 if (scc == StatusCode::SUCCESS) {
271 //log<<MSG::INFO<<"begin dump Calibration Constants"<<endreq;
272 // tofCaliSvc->Dump();
273 log << MSG::INFO << " Get EstTof Calibration Service Sucessfully!! " << endreq;
274 } else {
275 log << MSG::ERROR << " Get EstTof Calibration Service Failed !! " << endreq;
276 return scc;
277 }
278
280 {
281 StatusCode scc = Gaudi::svcLocator()->service("MdcCalibFunSvc", imdcCalibSvc);
282 if ( scc.isFailure() ){
283 log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endreq;
284 }
285 else{
286 m_mdcCalibFunSvc = dynamic_cast<MdcCalibFunSvc*>(imdcCalibSvc);
287 }
288 }
289
290
291
292 //Initailize MdcUtilitySvc
293
294 IMdcUtilitySvc * imdcUtilitySvc;
295 sc = service ("MdcUtilitySvc", imdcUtilitySvc);
296 m_mdcUtilitySvc = dynamic_cast<MdcUtilitySvc*> (imdcUtilitySvc);
297 if ( sc.isFailure() ){
298 log << MSG::FATAL << "Could not load MdcUtilitySvc!" << endreq;
299 return StatusCode::FAILURE;
300 }
301
302
303 return StatusCode::SUCCESS;
304}
305
307
308 MsgStream log(msgSvc(), name());
309 log << MSG::INFO << " tof " << endreq;
310
311 // Constants
312 EstParameter Estparam;
313 double offset=0, t_quality=0, tOffset_b=0, tOffset_e=0;
314 int idtof , tofid_helix[30]={-9},idmatch[3][88]={0},idmatch_emc[3][88]={0} ,idt[15]={0},particleId[30]={0}, tofid_emc[2]={0}, module[20]={0};
315 int idetf, etfid_helix[30]={-9}, idetfmatch[3][36]={-9}, idmatch_etf_emc[3][36]={0}, etfid_emc[2]={0};
316 int ntot=0,in=-1,out=-1, emcflag1=0, emcflag2=0, tof_flag=0; double bunchtime=m_bunchtime_MC;
317 double meant[15]={0.},adc[15]={0.}, momentum[15]={0.},r_endtof[10]={0.};
318 double ttof[30]={0.},helztof[30]={0.0},mcztof=0.0,forevtime=0.0,backevtime=0.0,meantev[200]={0.},meantevup[200]={0.0},meantevdown[200]={0.0};
319 double t0forward=0,t0backward=0,t0forward_trk=0,t0backward_trk=0;
320 double t0forward_add=0,t0backward_add=0,t_Est=-999;
321 double thetaemc_rec[20]={0.},phiemc_rec[20]={0.},energy_rec[20]={0.},xemc_rec[20]={0.},yemc_rec[20]={0.},zemc_rec[20]={0.};
322 double r_endetf[10]={0.}, tetf[30]={0.}, helzetf[30]={0.}, helpathetf[36]={0.}, abmom2etf[36]={0.};
323
324 int nmatch1=0,nmatch2=0,nmatch_barrel=0,nmatch_end=0,nmatch_mdc=0, nmatch_barrel_1=0, nmatch_barrel_2=0,nmatch=0,ntofup=0,ntofdown=0;
325 double sum_EstimeMdc=0,sum_EstimeMdcMC=0;
326 int nbunch=0,tEstFlag=0, runNo=0;
327 double helpath[88]={0.},helz[88]={0.},abmom2[88]={0.};
328 double mcTestime=0,trigtiming=0;
329 double mean_tdc_btof[2][88]={0.}, mean_tdc_etof[3][48]={0.}, mean_tdc_etf[3][36][12]={0.};
330 int optCosmic=m_optCosmic;
331 int m_userawtime=m_userawtime_opt;
332 double Testime_fzisan= -999.;//yzhang add
333 int TestimeFlag_fzisan= -999;//yzhang add
334 double TestimeQuality_fzisan= -999.;//yzhang add
335 double Tof_t0Arr[500]={-999.};
336
337 bool useEtofScin = ( m_phase<3 );
338 bool useEtofMRPC = ( m_phase>2 );
339
340 // Part 1: Get the event header, print out event and run number
341 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
342 if (!eventHeader) {
343 log << MSG::FATAL << "Could not find Event Header" << endreq;
344 return StatusCode::FAILURE;
345 }
346 log << MSG::INFO << "EsTimeAlg: retrieved event: " << eventHeader->eventNumber() << " run: " << eventHeader->runNumber() << endreq;
347 int eventNo=eventHeader->eventNumber();
348 runNo=eventHeader->runNumber();
349
350 if(m_ntupleflag && m_tuple2){g_runNo=runNo; g_eventNo=eventNo;}
351 if(runNo<0) {
352 offset_dt=0;
356 if( useEtofMRPC ) { toffset_rawtime_e = -20.0; }
357 }
358 if( runNo>0 && useEtofMRPC ) { toffset_rawtime_e = 1.7; }
359
360 if(runNo>0 && runNo<5336) offset_dt=5.8;
361 if(runNo>5462 && runNo<5466){ offset_dt=1.6; offset_dt_end=0.4;}
362 if(runNo>5538 && runNo<5920){ offset_dt=-0.2; offset_dt_end=-1.2;}
363 if(runNo>5924 && runNo<6322){ offset_dt=-0.2; offset_dt_end=-0.1;}
364 if(runNo>6400 && runNo<6423){ offset_dt=-2.4; offset_dt_end=-1.9;}
365 if(runNo>6514 && runNo<6668){ offset_dt=0; offset_dt_end=3.4;}
366 if(runNo>6667 && runNo<6715){ offset_dt=4; offset_dt_end=7.2;}
367 if(runNo>6715 && runNo<6720){ offset_dt=8; offset_dt_end=7.5;}
368 if(runNo>6879 && runNo<6909){ offset_dt=0.2; offset_dt_end=-0.1;}
369 if(m_ntupleflag && m_tuple3){
370 g_bunchtime=8;
371 g_t0offset_b=2.0;
372 g_t0offset_e=2.0;
373 }
374
375 m_pass[0]++;
376 if(m_evtNo==1 && m_pass[0]%1000 ==0){
377 cout<<"------------------- Events-----------------: "<<m_pass[0]<<endl;
378 }
379 if(m_debug==4) cout<<"m_userawtime: "<<m_userawtime<<endl;
380 if(m_debug==4) cout<<"EstTofCalibSvc est flag: "<<tofCaliSvc->ValidInfo()<<endl;
381
382 if( tofCaliSvc->chooseConstants(runNo, eventNo) == StatusCode:: FAILURE ) {
383 log << MSG::ERROR << "EstTof Calibration Const is NOT correct! " << endreq;
384 return StatusCode:: FAILURE;
385 }
386 if(tofCaliSvc->ValidInfo()==0&&m_userawtime_opt==0)
387 {
388 log << MSG::ERROR << "EstTof Calibration Const is Invalid! " << endreq;
389 return StatusCode::FAILURE;
390 }
391 if(tofCaliSvc->ValidInfo()==0||m_userawtime_opt==1) m_userawtime=1;
392 else m_userawtime=0;
393
394 SmartDataPtr<RecEsTimeCol> aRecestimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
395 if (!aRecestimeCol || aRecestimeCol->size()==0) {
396 if(m_debug==4) log << MSG::INFO << "Could not find RecEsTimeCol from fzsian" << endreq;
397 }else{
398 RecEsTimeCol::iterator it_evt = aRecestimeCol->begin();
399 for(; it_evt!=aRecestimeCol->end(); it_evt++){
400 Testime_fzisan = (*it_evt)->getTest();//yzhang add
401 TestimeFlag_fzisan = (*it_evt)->getStat(); //yzhang add
402 TestimeQuality_fzisan = (*it_evt)->getQuality(); //yzhang add
403
404 log << MSG::INFO << "fzisan : Test = "<<(*it_evt)->getTest()
405 << ", Status = "<<(*it_evt)->getStat() <<endreq;
406
407 if(m_ntupleflag && m_tuple2) g_Testime_fzisan = Testime_fzisan;
408 }}
409
410 std::string fullPath = "/Calib/EsTimeCal";
411 SmartDataPtr<CalibData::EsTimeCalibData> TEst(m_pCalibDataSvc, fullPath);
412 if(!TEst){ cout<<"ERROR EsTimeCalibData"<<endl;}
413 else{
414 int no = TEst->getTestCalibConstNo();
415 // std::cout<<"no==========="<<no<<std::endl;
416 // for(int i=0;i<no;i++){
417 // std::cout<<"i= "<<i<<" value="<< TEst->getTEstCalibConst(i)<<std::endl;
418 // }
419
420 unsigned int inumber = 0;
421 unsigned int calibNo = TEst->getSize();
422 if( calibNo > 1 ) {
423 for( unsigned int i=0; i<calibNo; i++, inumber++ ) {
424 if( ( TEst->getRunTo(i) != -1 ) && ( TEst->getRunTo(i) < TEst->getRunFrom(i) ) ) {
425 log << MSG::ERROR << "EsTimeCal -- The " << inumber << "th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endreq;
426 return StatusCode::FAILURE;
427 }
428 if( ( TEst->getRunFrom(i) == TEst->getRunTo(i) ) && ( TEst->getEventFrom(i) != -1 ) && ( TEst->getEventTo(i) != -1 ) && ( TEst->getEventFrom(i) > TEst->getEventTo(i) ) ) {
429 log << MSG::ERROR << "EsTimeCal -- The " << inumber << "th calibration constatns is ABNORMAL! Event From is LARGER than Event To!" << endreq;
430 return StatusCode::FAILURE;
431 }
432 }
433
434 inumber = 0;
435 bool filled = false;
436 for( unsigned int i=0; i<calibNo; i++, inumber++ ) {
437 int runFrom = TEst->getRunFrom(i);
438 int runTo = TEst->getRunTo(i);
439 int eventFrom = TEst->getEventFrom(i);
440 int eventTo = TEst->getEventTo(i);
441 if( ( runNo == runFrom ) && ( ( eventFrom == -1 ) || ( eventNo >= eventFrom ) ) ) {
442 if( ( runNo < runTo ) || ( ( runNo == runTo ) && ( ( eventTo == -1 ) || ( eventNo <= eventTo ) ) ) ) {
443 filled = true;
444 break;
445 }
446 }
447 if( runNo > runFrom ) {
448 if( ( runNo < runTo ) || ( ( runNo == runTo ) && ( ( eventTo == -1 ) || ( eventNo <= eventTo ) ) ) ) {
449 filled = true;
450 break;
451 }
452 }
453 }
454 if( !filled ) {
455 log << MSG::ERROR << "EsTimeCal -- For run number:" << runNo << ", NO suitable calibration constant is found!" << endreq;
456 return StatusCode::FAILURE;
457 }
458 }
459
460 log<<MSG::INFO<<"offset barrel t0="<< TEst->getToffsetb(inumber)
461 <<", offset endcap t0="<< TEst->getToffsete(inumber)
462 <<", bunch time ="<<TEst->getBunchTime(inumber)
463 <<endreq;
464 tOffset_b = TEst->getToffsetb(inumber);
465 tOffset_e = TEst->getToffsete(inumber);
466 bunchtime = TEst->getBunchTime(inumber);
467 }
468
469 if(m_userawtime) {
470 tOffset_b=0;
471 tOffset_e=0;
472 }
473 else
474 {
477 offset_dt=0;
479 }
480
482 {
483 bunchtime=RawDataUtil::TofTime(8*1024)*bunchtime/24.0;
484 }
485
486 if(runNo<0) bunchtime=m_bunchtime_MC;
487
488 //Part 2: Retrieve MC truth
489 int digiId;
490 if(runNo<0){
491 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
492 if (!mcParticleCol) {
493 log << MSG::INFO<< "Could not find McParticle" << endreq;
494 }
495 else{
496 McParticleCol::iterator iter_mc = mcParticleCol->begin();
497 digiId = 0;
498 ntrkMC = 0;
499 int charge = 0;
500
501 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
502 int statusFlags = (*iter_mc)->statusFlags();
503 int pid = (*iter_mc)->particleProperty();
504 log << MSG::INFO
505 << " MC ParticleId = " << pid
506 << " statusFlags = " << statusFlags
507 << " PrimaryParticle = " <<(*iter_mc)->primaryParticle()
508 << endreq;
509 if(m_ntupleflag && m_tuple2){
510 g_theta0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().theta();
511 g_phi0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().phi();
512 g_pxMC[ntrkMC] = (*iter_mc)->initialFourMomentum().px()/1000;
513 g_pyMC[ntrkMC] = (*iter_mc)->initialFourMomentum().py()/1000;
514 g_pzMC[ntrkMC] = (*iter_mc)->initialFourMomentum().pz()/1000;
515 g_ptMC[ntrkMC] = sqrt(((*iter_mc)->initialFourMomentum().px())*((*iter_mc)->initialFourMomentum().px())+((*iter_mc)->initialFourMomentum().py())*((*iter_mc)->initialFourMomentum().py()))/1000;
516 }
517 if( pid >0 ) {
518 if(m_particleTable->particle( pid )) charge = m_particleTable->particle( pid )->charge();
519 } else if ( pid <0 ) {
520 if(m_particleTable->particle( -pid )) {
521 charge = m_particleTable->particle( -pid )->charge();
522 charge *= -1;
523 }
524 } else {
525 log << MSG::WARNING << "wrong particle id, please check data" <<endreq;
526 }
527 log << MSG::DEBUG
528 << "MC ParticleId = " << pid << " charge = " << charge
529 << endreq;
530 if(charge !=0 && abs(cos((*iter_mc)->initialFourMomentum().theta()))<0.93){
531 ntrkMC++;
532 }
533 if(((*iter_mc)->primaryParticle())&& m_ntupleflag && m_tuple2){
534 g_mcTestime=(*iter_mc)->initialPosition().t();
535 mcTestime=(*iter_mc)->initialPosition().t();
536 }
537 }
538 if(m_ntupleflag && m_tuple2) g_ntrkMC = ntrkMC;
539 }
540 }//close if(runno<0)
541 if (m_debug) cout<<"bunchtime: "<<bunchtime<<endl;
542
543 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
544 if (!newtrkCol || newtrkCol->size()==0) {
545 log << MSG::INFO<< "Could not find RecMdcTrackCol" << endreq;
546 } else{
547 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
548 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
549 for( ; iter_trk != newtrkCol->end(); iter_trk++){
550 log << MSG::DEBUG << "retrieved MDC track:"
551 << " Track Id: " << (*iter_trk)->trackId()
552 << " Phi0: " << (*iter_trk)->helix(0)
553 << " kappa: " << (*iter_trk)->helix(2)
554 << " Tanl: " << (*iter_trk)->helix(4)
555 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
556 << endreq
557 << "Number of hits: "<< (*iter_trk)->getNhits()
558 << " Number of stereo hits " << (*iter_trk)->nster()
559 << endreq;
560 double kappa = (*iter_trk)->helix(2);
561 double tanl = (*iter_trk)->helix(4);
562 momentum[ntot] = 1./fabs(kappa) * sqrt(1.+tanl*tanl);
563 if((*iter_trk)->helix(3)>50.0) continue;
564 ntot++;
565 if (ntot>15) break;
566 }
567 }
568
569 //get EmcRec results
570 int emctrk=0;
571 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
572 if (!aShowerCol || aShowerCol->size()==0) {
573 log << MSG::WARNING << "Could not find RecEmcShowerCol" << endreq;
574 } else{
575 RecEmcShowerCol::iterator iShowerCol=aShowerCol->begin();
576 for(;iShowerCol!=aShowerCol->end();iShowerCol++,emctrk++){
577 if(emctrk>20) break;
578 phiemc_rec[emctrk]=(*iShowerCol)->position().phi();
579 thetaemc_rec[emctrk]=(*iShowerCol)->position().theta();
580 energy_rec[emctrk]=(*iShowerCol)->energy();
581 xemc_rec[emctrk]=(*iShowerCol)->x();
582 yemc_rec[emctrk]=(*iShowerCol)->y();
583 zemc_rec[emctrk]=(*iShowerCol)->z();
584 module[emctrk]=(*iShowerCol)->module();
585 }
586 }
587 for(int i=0; i<2; i++){
588 double fi_endtof = atan2(yemc_rec[i],xemc_rec[i] ); // atna2 from -pi to pi
589 if( fi_endtof<0 ) { fi_endtof=2*3.141593+fi_endtof; }
590 if( module[i]==1 ) {
591 int Tofid = (int)(fi_endtof/(3.141593/44));
592 if(Tofid>87) Tofid=Tofid-88;
593 tofid_emc[i]=Tofid;
594 idmatch_emc[1][Tofid]=1;
595 }
596 else{
597 if( useEtofScin ) {
598 int Tofid =(int)(fi_endtof/(3.141593/24));
599 if( Tofid>47) Tofid=Tofid-48;
600 tofid_emc[i]= Tofid;
601 if(module[i]==2) idmatch_emc[2][Tofid]=1;
602 if(module[i]==0) idmatch_emc[0][Tofid]=1;
603 }
604 if( useEtofMRPC ) {
605 int Tofid = (int)(fi_endtof/(3.141593/18));
606 if( Tofid>35) Tofid=Tofid-36;
607 etfid_emc[i]= Tofid;
608 if(module[i]==2) idmatch_etf_emc[2][Tofid]=1;
609 if(module[i]==0) idmatch_etf_emc[0][Tofid]=1;
610 }
611 }
612 }
613
614 ntrk=0;
615 if (ntot > 0) {
616 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
617 for( int idfztrk=0; iter_trk != newtrkCol->end(); iter_trk++,idfztrk++){
618 double mdcftrk[5];
619 mdcftrk[0] = (*iter_trk)->helix(0);
620 mdcftrk[1] = (*iter_trk)->helix(1);
621 mdcftrk[2] =-(*iter_trk)->helix(2);
622 mdcftrk[3] = (*iter_trk)->helix(3);
623 mdcftrk[4] = (*iter_trk)->helix(4);
624
625 if(optCosmic==0){
626 Emc_helix EmcHit;
627 // EMC acceptance
628 EmcHit.pathlCut(Estparam.pathlCut());
629 // Set max. path length(cm)
630 // MDC --> EMC match
631
632 if (EmcHit.Emc_Get(sqrt(RCEMC2),idfztrk,mdcftrk) > 0){
633 double z_emc = EmcHit.Z_emc;
634 double thetaemc_ext= EmcHit.theta_emc;
635 double phiemc_ext = EmcHit.phi_emc;
636
637 for(int t=0; t<emctrk;t++){
638 if((thetaemc_ext>=(thetaemc_rec[t]-0.1)) && (thetaemc_ext<=(thetaemc_rec[t]+0.1)) && (phiemc_ext>=(phiemc_rec[t]-0.1)) && (phiemc_ext<=(phiemc_rec[t]+0.1))){
639 if((energy_rec[t])>=(0.85*momentum[idfztrk]))
640 particleId[idfztrk]=1;
641 }
642 }
643 }
644 //get dE/dx results
645 if(particleId[idfztrk]!=1){
646
647 SmartDataPtr<RecMdcDedxCol> newdedxCol(eventSvc(),"/Event/Recon/RecMdcDedxCol");
648 if (!newdedxCol || newdedxCol->size()==0) {
649 log << MSG::WARNING<< "Could not find RecMdcDedxCol" << endreq;
650 }
651 else{
652 RecMdcDedxCol::iterator it_dedx = newdedxCol->begin();
653 for( int npid=0; it_dedx != newdedxCol->end(); it_dedx++,npid++) {
654 log << MSG::INFO << "retrieved MDC dE/dx: "
655 << "dEdx Id: " << (*it_dedx)->trackId()
656 << " particle Id: "<< (*it_dedx)->particleType() <<endreq;
657 if((*it_dedx)->particleType() == proton){
658 particleId[npid]= 5;
659 }
660 if(m_debug==4) cout<<"dedx pid: "<<particleId[npid]<<endl;
661 }
662 }
663 }
664 }//if(optCosmic==0)
665
666 idtof = -100;
667 idetf = -100;
668 TofFz_helix TofHit;
669
670 // TOF acceptance
671 TofHit.pathlCut(Estparam.pathlCut());
672 // Set max. path length(cm)
673
674 TofHit.ztofCut(Estparam.ztofCutmin(),Estparam.ztofCutmax()); // Set Ztof cut window (cm)
675 // MDC --> TOF match
676 int tofpart = TofHit.TofFz_Get(sqrt(RCTOF2),idfztrk,mdcftrk);
677 if(tofpart < 0) continue;
678 // if (TofHit.TofFz_Get(sqrt(RCTOF2),idfztrk,mdcftrk) < 0) continue;
679
680 bool useBarrelScin = ( tofpart==1 ); // barrel
681 bool useEndcapScin = ( ( tofpart==0 || tofpart==2 ) && useEtofScin ); // endcap for 96Scin and 92Scin+2MRPC;
682 bool useEndcapMRPC = ( ( tofpart==0 || tofpart==2 ) && useEtofMRPC ); // endcap for 72MRPC and 92Scin+2MRPC
683
684 if( useBarrelScin || useEndcapScin ) {
685 idtof = TofHit.Tofid;
686 tofid_helix[idfztrk] = TofHit.Tofid;
687 }
688 if( useEndcapMRPC ) {
689 idetf = TofHit.Etfid;
690 etfid_helix[idfztrk] = TofHit.Etfid;
691 }
692
693 log << MSG::INFO << "helix to tof hit part: "<<tofpart<<" tof id: "<< idtof << " etf id:" << idetf << endreq;
694 if( m_debug==4 ) cout << "helix to tof hit part, Id: "<<tofpart<<" , "<< idtof <<endl;
695 if( ( useBarrelScin && idtof>=0 && idtof<=87 ) || ( useEndcapScin && idtof>=0 && idtof<=47 ) || ( useEndcapMRPC && idetf>=0 && idetf<=35 ) ) { // barrel part: idtof:0~87; endcap part: idtof:0~47 (scintillator),idetf:0~35 (mrpc)
696
697 double abmom = 0.0;
698 if( useEndcapMRPC ) {
699 idetfmatch[tofpart][idetf]= 1;
700 helpathetf[idetf]= TofHit.Path_etf;
701 helz[idetf] = TofHit.Z_etf;
702 abmom = 1./fabs(TofHit.Kappa) * sqrt(1.+TofHit.Tanl*TofHit.Tanl);
703 if(abmom<0.1) continue;
704 abmom2etf[idetf] = abmom*abmom;
705 r_endetf[idfztrk]= TofHit.r_etf;
706 helzetf[idfztrk] = helz[idetf];
707 }
708
709 if( useBarrelScin || useEndcapScin ) {
710 idmatch[tofpart][idtof] = 1;
711 helpath[idtof] = TofHit.Pathl;
712 helz[idtof] = TofHit.Z_tof;
713 abmom = 1./fabs(TofHit.Kappa) * sqrt(1.+TofHit.Tanl*TofHit.Tanl);
714 if(abmom<0.1) continue;
715 abmom2[idtof] = abmom*abmom;
716 r_endtof[idfztrk]= TofHit.r_endtof;
717 helztof[idfztrk] = helz[idtof];
718 }
719
720 if( m_debug==4 ) {
721 cout << "Scintillator info trk number=" << idfztrk << " tofpart=" << tofpart << " idtof=" << idtof << " helpath=" << helpath[idtof] << " helz=" << helz[idtof] << " abmom=" << abmom2[idtof] << " r=" << r_endtof[idfztrk] << " helztof=" << helz[idtof] << endl;
722 cout << "MRPC info trk number=" << idfztrk << " tofpart=" << tofpart << " idetf=" << idetf << " helpath=" << helpathetf[idetf] << " helz=" << helzetf[idetf] << " abmom=" << abmom2etf[idetf] << " r=" << r_endetf[idfztrk] << " helztof=" << helzetf[idetf] << endl;
723 }
724
725 double vel = 1.0e-6;
726 if( optCosmic==0 ) {
727
728 if( useEndcapMRPC ) {
729 if( particleId[idfztrk] == 1 ) {
730 tetf[idfztrk] = sqrt(ELMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/VLIGHT;
731 vel = VLIGHT/sqrt(ELMAS2/abmom2etf[idetf]+1);
732 }
733 else if( particleId[idfztrk] == 5 ) {
734 tetf[idfztrk] = sqrt(PROTONMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/VLIGHT;
735 vel = VLIGHT/sqrt(PROTONMAS2/abmom2etf[idtof]+1);
736 }
737 else {
738 tetf[idfztrk] = sqrt(PIMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/VLIGHT;
739 vel = VLIGHT/sqrt(PIMAS2/abmom2etf[idtof]+1);
740 }
741 }
742
743 if( useBarrelScin || useEndcapScin ) {
744 if( particleId[idfztrk] == 1 ) {
745 ttof[idfztrk] = sqrt(ELMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
746 vel = VLIGHT/sqrt(ELMAS2/abmom2[idtof]+1);
747 }
748 else if( particleId[idfztrk] == 5 ) {
749 ttof[idfztrk] = sqrt(PROTONMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
750 vel = VLIGHT/sqrt(PROTONMAS2/abmom2[idtof]+1);
751 }
752 else {
753 ttof[idfztrk] = sqrt(PIMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
754 vel = VLIGHT/sqrt(PIMAS2/abmom2[idtof]+1);
755 }
756 }
757
758 }
759 else{
760
761 if( useEndcapMRPC ) {
762 tetf[idfztrk] = sqrt(MUMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/VLIGHT;
763 vel = VLIGHT/sqrt(MUMAS2/abmom2etf[idtof]+1);
764 }
765
766 if( useBarrelScin || useEndcapMRPC ) {
767 ttof[idfztrk] = sqrt(MUMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
768 vel = VLIGHT/sqrt(MUMAS2/abmom2[idtof]+1);
769 }
770 }
771
772 if(m_ntupleflag && m_tuple2){
773 g_vel[idfztrk] = vel;
774 g_abmom[idfztrk] = abmom;
775 if( useEndcapMRPC ) {
776 g_ttof[idfztrk] = tetf[idfztrk];
777 }
778 if( useBarrelScin || useEndcapScin ) {
779 g_ttof[idfztrk] = ttof[idfztrk];
780 }
781 g_pid[idfztrk] = particleId[idfztrk];
782 }
783 }
784 ntrk++;
785 }
786 if(m_ntupleflag && m_tuple2) g_ntrk= ntrk;
787 }
788
789 // C a l c u l a t e E v t i m e
790 // Retrieve TofMCHit truth
791 if(runNo<0){
792 SmartDataPtr<TofMcHitCol> tofmcHitCol(eventSvc(),"/Event/MC/TofMcHitCol");
793 if (!tofmcHitCol) {
794 log << MSG::ERROR<< "Could not find McParticle" << endreq;
795 // return StatusCode::FAILURE;
796 }
797 else{
798 TofMcHitCol::iterator iter_mctof = tofmcHitCol->begin();
799
800 for (;iter_mctof !=tofmcHitCol->end(); iter_mctof++, digiId++) {
801 log << MSG::INFO
802 << " TofMcHit Flight Time = " << (*iter_mctof)->getFlightTime()
803 << " zPosition = " << ((*iter_mctof)->getPositionZ())/10
804 << " xPosition = " <<((*iter_mctof)->getPositionX())/10
805 << " yPosition = " <<((*iter_mctof)->getPositionY())/10
806 << endreq;
807 }
808 }
809 }
810
811 ////choose cosmic
812 TofDataVector tofDigiVec = m_rawDataProviderSvc->tofDataVectorEstime();
813 //if(tofDigiVec.size()==0) return StatusCode::SUCCESS;
814 for(TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++) {
815 int barrelid;
816 int layerid;
817 int tofid;
818 int strip;
819
820 if( !( (*iter2)->is_mrpc() ) ) { // Scintillator
821 if( (*iter2)->barrel() ) { // Scintillator Barrel
822 barrelid = 1;
823 tofid = (*iter2)->tofId();
824 layerid = (*iter2)->layer();
825 if(layerid==1) tofid=tofid-88;
826 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) {
827 double ftdc = (*iter2)->tdc1();
828 double btdc = (*iter2)->tdc2();
829 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
830 }
831 else if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()>1 ) {
832 double ftdc = (*iter2)->tdc1();
833 double btdc = (*iter2)->tdc2();
834 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
835 }
836 }
837 else{ // Scintillator Endcap
838 tofid = (*iter2)->tofId();
839 if(tofid<48) barrelid=0;
840 if(tofid>47) barrelid=2;
841 if(barrelid==2) tofid=tofid-48;
842
843 if((*iter2)->times()==1){
844 double ftdc= (*iter2)->tdc();
845 mean_tdc_etof[barrelid][tofid]=ftdc;
846 }
847 else if(((*iter2)->times()>1) && ((*iter2)->times()<5)){
848 double ftdc= (*iter2)->tdc();
849 mean_tdc_etof[barrelid][tofid]=ftdc;
850 }
851 }
852 }
853 else { // MRPC Endcap
854 tofid = (*iter2)->tofId();
855 strip = (*iter2)->strip();
856 if( tofid<36 ) barrelid=0;
857 if( tofid>35 ) barrelid=2;
858 if(barrelid==2) tofid=tofid-36;
859 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) {
860 double ftdc = (*iter2)->tdc1();
861 double btdc = (*iter2)->tdc2();
862 mean_tdc_etf[barrelid][tofid][strip]=(ftdc+btdc)/2;
863 }
864 else if( ((*iter2)->quality()&0x5)==0x5 && (*iter2)->times()>1 ) {
865 double ftdc = (*iter2)->tdc1();
866 double btdc = (*iter2)->tdc2();
867 mean_tdc_etf[barrelid][tofid][strip]=(ftdc+btdc)/2;
868 }
869 }
870 }
871
872 double difftof_b=100, difftof_e=100;
873 int tofid1=tofid_emc[0];
874 int tofid2=tofid_emc[1];
875 if( module[0]==1 && module[1]==1 ) {
876 for(int i=0; i<2; i++){
877 for(int m=0; m<2; m++){
878 for(int j=-2; j<3; j++){
879 for(int k=-2; k<3; k++){
880 int p=tofid1+j;
881 int q=tofid2+k;
882 if(p<0) p=p+88;
883 if(p>87) p=p-88;
884 if(q<0) q=q+88;
885 if(q>87) q=q+88;
886 if(mean_tdc_btof[i][p]==0 || mean_tdc_btof[m][q]==0) continue;
887 double difftof_b_temp = mean_tdc_btof[i][p]-mean_tdc_btof[m][q];
888 if(abs(difftof_b_temp)<abs(difftof_b )) difftof_b =difftof_b_temp;
889 if(m_ntupleflag && m_tuple2) g_difftof_b=difftof_b;
890 }
891 }
892 }
893 }
894 }
895
896 if( useEtofMRPC ) {
897 if( module[0]!=1 && module[1]!=1 ) {
898 tofid1 = etfid_emc[0];
899 tofid2 = etfid_emc[1];
900 for(int i=-1; i<2; i++){
901 for(int j=-1; j<2; j++){
902 int m=tofid1+i;
903 int n=tofid2+j;
904 if(m<0) m=36+m;
905 if(m>35) m=m-36;
906 if(n<0) n=36+n;
907 if(n>35) n=n-36;
908 if( mean_tdc_etf[0][m] && mean_tdc_etf[2][n]){
909 double difftof_e_temp= mean_tdc_etf[0][m]-mean_tdc_etf[2][n];
910 if(abs(difftof_e_temp) < abs(difftof_e)) difftof_e= difftof_e_temp;
911 if(m_ntupleflag && m_tuple2) g_difftof_e=difftof_e;
912 }
913 }
914 }
915 }
916 }
917
918 if( useEtofScin ) {
919 if( module[0]!=1 && module[1]!=1 ) {
920 for(int i=-1; i<2; i++){
921 for(int j=-1; j<2; j++){
922 int m=tofid1+i;
923 int n=tofid2+j;
924 if(m<0) m=48+m;
925 if(m>47) m=m-48;
926 if(n<0) n=48+n;
927 if(n>47) n=n-48;
928 if( mean_tdc_etof[0][m] && mean_tdc_etof[2][n]){
929 double difftof_e_temp= mean_tdc_etof[0][m]-mean_tdc_etof[2][n];
930 if(abs(difftof_e_temp) < abs(difftof_e)) difftof_e= difftof_e_temp;
931 if(m_ntupleflag && m_tuple2) g_difftof_e=difftof_e;
932 }
933 }
934 }
935 }
936 }
937
938 if(m_optCosmic==1) optCosmic=1;
939 else optCosmic=0;
940
941 digiId = 0;
942 unsigned int tofid;
943 unsigned int barrelid;
944 unsigned int layerid;
945 t0forward_add = 0;
946 t0backward_add = 0;
947 TofDataVector::iterator iter2 = tofDigiVec.begin();
948 for (;iter2 != tofDigiVec.end(); iter2++, digiId++){
949 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
950 barrelid=(*iter2)->barrel();
951 if((*iter2)->barrel()==0) continue;
952 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) { // tof_flag=1
953 tofid = (*iter2)->tofId();
954 layerid = (*iter2)->layer();
955 if(layerid==1) tofid=tofid-88;
956 log<< MSG::INFO
957 <<" TofId = "<<tofid
958 <<" barrelid = "<<barrelid
959 <<" layerid = "<<layerid
960 <<" ForwordADC = "<<(*iter2)->adc1()
961 <<" ForwordTDC = "<<(*iter2)->tdc1()
962 <<" BackwordADC = "<<(*iter2)->adc2()
963 <<" BackwordTDC = "<<(*iter2)->tdc2()
964 << endreq;
965 //forb=0/1 for forward(z>0, east) and backward(z<0, west)
966 double ftdc = (*iter2)->tdc1();
967 double btdc = (*iter2)->tdc2();
968 if(m_debug==4) cout<<"barrel 1 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<" , "<<btdc<<endl;
969 double fadc = (*iter2)->adc1();
970 double badc = (*iter2)->adc2();
971 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
972 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
973 double ztof = fabs((ftdc-btdc)/2)*17.7 , ztof2 = ztof*ztof;
974 double mean_tdc = 0.5*(btdc+ftdc);
975 double cor_path = sqrt(RCTOF2+ztof2)/VLIGHT;
976
977 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
978 for(int i=0;i<=ntot;i++){
979 if(ttof[i]!=0 && ftdc>0){
980 if((tofid_helix[i] == tofid) || (tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)) {
981 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
982 if (optCosmic && tofid<44) {
983 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
984 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
985 meantevup[ntofup]=(backevtime+forevtime)/2;
986 ntofup++;
987 }
988 else{
989 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
990 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
991 meantevdown[ntofdown]=(backevtime+forevtime)/2;
992 ntofdown++;
993 }
994 if( (*iter2)->adc1()<0.0 || (*iter2)->adc2()<0.0 || m_userawtime){
995 t0forward_trk = ftdc - forevtime ;
996 t0backward_trk = btdc - backevtime ;
997 }
998 else{
999 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1000 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1001 if (optCosmic && tofid<44) {
1002 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1003 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1004 }
1005 }
1006
1007 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
1008 if(!m_TofOpt&& nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
1009 if(m_debug ==4 ) cout<<" t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
1010 if(m_ntupleflag && m_tuple2){
1011 g_t0for[nmatch1] = t0forward_trk ;
1012 g_t0back[nmatch2] = t0backward_trk ;
1013 g_meantdc=(ftdc+btdc)/2;
1014 if(tofid<44) g_ntofup1++;
1015 else g_ntofdown1++;
1016 }
1017 meantev[nmatch]=(backevtime+forevtime)/2;
1018 t0forward_add += t0forward_trk;
1019 t0backward_add += t0backward_trk;
1020 if(nmatch>499) break;
1021 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1022 nmatch++;
1023 nmatch1=nmatch1+1;
1024 nmatch2=nmatch2+1;
1025 nmatch_barrel++;
1026 }
1027 }
1028 }
1029 }
1030 }
1031 }
1032 }
1033
1034 if(nmatch_barrel != 0 ){
1035 if(m_ntupleflag && m_tuple2){
1036 g_t0barrelTof=( t0forward_add/nmatch_barrel + t0backward_add/nmatch_barrel)/2;
1037 }
1038 tof_flag = 1;
1039 t_quality=1;
1040 }
1041
1042 if(nmatch_barrel==0){
1043 digiId = 0;
1044 t0forward_add = 0;
1045 t0backward_add = 0;
1046 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1047 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1048 barrelid=(*iter2)->barrel();
1049 if((*iter2)->barrel()==0) continue;
1050 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()>1 ) { // tof_flag=2
1051 tofid = (*iter2)->tofId();
1052 layerid = (*iter2)->layer();
1053 if(layerid==1) tofid=tofid-88;
1054 log<< MSG::INFO
1055 <<" TofId = "<<tofid
1056 <<" barrelid = "<<barrelid
1057 <<" layerid = "<<layerid
1058 <<" ForwordADC = "<<(*iter2)->adc1()
1059 <<" ForwordTDC = "<<(*iter2)->tdc1()
1060 <<endreq;
1061 double ftdc= (*iter2)->tdc1();
1062 double btdc= (*iter2)->tdc2();
1063 double fadc= (*iter2)->adc1();
1064 double badc= (*iter2)->adc2();
1065 if(m_debug==4) cout<<"barrel 2 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<" , "<<btdc<<endl;
1066 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1067 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1068 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1069 for(int i=0;i<=ntot;i++){
1070 if(ttof[i]!=0 && ftdc>0){
1071 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof)||(tofid_helix[i] == idntof)){
1072 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1073 if (optCosmic && tofid<44) {
1074 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1075 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1076 meantevup[ntofup]=(backevtime+forevtime)/2;
1077 ntofup++;
1078 }
1079 else{
1080 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1081 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1082 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1083 ntofdown++;
1084 }
1085 if( (*iter2)->adc1()<0.0 || (*iter2)->adc2()<0.0 || m_userawtime){
1086 t0forward_trk = ftdc - forevtime ;
1087 t0backward_trk = btdc - backevtime ;
1088 }
1089 else{
1090 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1091 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1092 if (optCosmic && tofid<44) {
1093 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1094 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1095 }
1096 }
1097
1098 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
1099 if(!m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
1100 if(m_debug == 4) cout<<"t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
1101 if(m_ntupleflag && m_tuple2){
1102 g_t0for[nmatch1] = t0forward_trk ;
1103 g_t0back[nmatch2] = t0backward_trk ;
1104 g_meantdc=(ftdc+btdc)/2;
1105 if(tofid<44) g_ntofup1++;
1106 else g_ntofdown1++;
1107 }
1108 meantev[nmatch]=(backevtime+forevtime)/2;
1109 t0forward_add += t0forward_trk;
1110 t0backward_add += t0backward_trk;
1111 if(nmatch>499) break;
1112 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1113 nmatch++;
1114 nmatch1=nmatch1+1;
1115 nmatch2=nmatch2+1;
1116 nmatch_barrel++;
1117 }
1118 }
1119 }
1120 }
1121 }
1122 }
1123 }//close 2nd for loop -> only barrel part
1124 if(nmatch_barrel) tof_flag=2;
1125 }
1126
1127 if(ntot==0 || nmatch_barrel==0) {
1128 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1129 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1130 barrelid=(*iter2)->barrel();
1131 if((*iter2)->barrel()==0) continue;
1132 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) { // tof_flag=3
1133 tofid = (*iter2)->tofId();
1134 layerid = (*iter2)->layer();
1135 if(layerid==1) tofid=tofid-88;
1136 log<< MSG::INFO
1137 <<" TofId = "<<tofid
1138 <<" barrelid = "<<barrelid
1139 <<" layerid = "<<layerid
1140 <<" ForwordADC = "<<(*iter2)->adc1()
1141 <<" ForwordTDC = "<<(*iter2)->tdc1()
1142 <<endreq;
1143 double ftdc= (*iter2)->tdc1();
1144 double btdc= (*iter2)->tdc2();
1145 double fadc= (*iter2)->adc1();
1146 double badc= (*iter2)->adc2();
1147 if(m_debug==4) cout<<"barrel 3 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<" , "<<btdc<<endl;
1148 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1149 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1150 for(int i=0; i<2; i++){
1151 if(tofid_emc[i] == tofid || tofid_emc[i] == idptof || tofid_emc[i] == idntof){
1152 if(zemc_rec[0]||zemc_rec[1]){
1153 if(tofid ==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof){
1154 if(ftdc>2000.|| module[i]!=1) continue;
1155 ttof[i]= sqrt(ELMAS2/(m_ebeam*m_ebeam)+1)* sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]+zemc_rec[i]*zemc_rec[i])/VLIGHT;
1156 if(optCosmic==1 && tofid<44){
1157 backevtime = -ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
1158 forevtime = -ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
1159 meantevup[ntofup]=(backevtime+forevtime)/2;
1160 ntofup++;
1161 }
1162 else{
1163 backevtime = ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
1164 forevtime = ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
1165 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1166 ntofdown++;
1167 }
1168 if( (*iter2)->adc1()<0.0 || (*iter2)->adc2()<0.0 || m_userawtime){
1169 t0forward_trk=ftdc-forevtime;
1170 t0backward_trk=btdc-backevtime;
1171 }
1172 else{
1173 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1174 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1175 if (optCosmic && tofid<44) {
1176 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1177 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1178 }
1179 }
1180
1181 if(t0forward_trk<-1 || t0backward_trk<-1 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
1182 if(!m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
1183 if(m_debug == 4) cout<<"t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
1184 meantev[nmatch]=(backevtime+forevtime)/2;
1185 t0forward_add += t0forward_trk;
1186 t0backward_add += t0backward_trk;
1187 if(nmatch>499) break;
1188 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1189 nmatch++;
1190 nmatch_barrel++;
1191 emcflag1=1;
1192 }
1193 }
1194 }
1195 }
1196 }
1197 }//3rd for loop only barrel part
1198 if(nmatch_barrel) tof_flag=3;
1199 }
1200
1201 if( nmatch_barrel != 0 ) { //only matched barrel tracks
1202 t0forward = t0forward_add/nmatch_barrel;
1203 t0backward = t0backward_add/nmatch_barrel;
1204 if(optCosmic==0){
1205 if(m_TofOpt)
1206 {
1207 t_Est=EST_Trimmer(Opt_new(Tof_t0Arr,nmatch,m_TofOpt_Cut),tOffset_b,toffset_rawtime,offset_dt,bunchtime);
1208 }
1209 else t_Est=EST_Trimmer((t0forward+t0backward)/2,tOffset_b,toffset_rawtime,offset_dt,bunchtime);
1210 if(t_Est<0) t_Est=0;
1211 if(tof_flag==1) tEstFlag=111;
1212 else if(tof_flag==2) tEstFlag=121;
1213 else if(tof_flag==3) tEstFlag=131;
1214 }
1215 if(optCosmic){
1216 t_Est=(t0forward+t0backward)/2;//3. yzhang add tOffset_b for barrel cosmic
1217 if(tof_flag==1) tEstFlag=211;
1218 else if(tof_flag==2) tEstFlag=221;
1219 else if(tof_flag==3) tEstFlag=231;
1220 }
1221 if(m_ntupleflag && m_tuple2) g_meant0=(t0forward+t0backward)/2;
1222 }//close if(nmatch_barrel !=0)
1223
1224
1225 digiId = 0;
1226 t0forward_add = 0;
1227 t0backward_add = 0;
1228
1229 if(nmatch_barrel==0){
1230 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1231 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1232 barrelid=(*iter2)->barrel();
1233 if((*iter2)->barrel()==0) continue;
1234 if(((*iter2)->quality() & 0x5) ==0x4){ // tEstFlag=241
1235 tofid = (*iter2)->tofId();
1236 layerid = (*iter2)->layer();
1237 if(layerid==1) tofid=tofid-88;
1238 log<< MSG::INFO
1239 <<" TofId = "<<tofid
1240 <<" barrelid = "<<barrelid
1241 <<" layerid = "<<layerid
1242 <<" ForwordADC = "<<(*iter2)->adc1()
1243 <<" ForwordTDC = "<<(*iter2)->tdc1()
1244 <<endreq;
1245 //forb=0/1 for forward(z>0, east) and backward(z<0, west)
1246 double ftdc= (*iter2)->tdc1();
1247 double fadc= (*iter2)->adc1();
1248 if(m_debug==4) cout<<"barrel 4 ::layer, barrel, tofid, ftdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<endl;
1249 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1250 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1251 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1252 for(int i=0;i<=ntot;i++){
1253 if(ttof[i]!=0 && ftdc>0){
1254 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof) || (tofid_helix[i] == idntof)){
1255 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1256 if (optCosmic && tofid<44) {
1257 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1258 meantevup[ntofup]=forevtime;
1259 ntofup++;
1260 }
1261 else{
1262 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1263 meantevdown[ntofdown]=forevtime;
1264 ntofdown++;
1265 }
1266 if( (*iter2)->adc1()<0.0 || m_userawtime){
1267 t0forward_trk = ftdc - forevtime ;
1268 }
1269 else{
1270 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1271 }
1272
1273 if(t0forward_trk<-1) continue;
1274 if(!m_TofOpt&&nmatch_barrel_1!=0 && fabs((t0forward_trk)-(t0forward_add)/nmatch_barrel_1)>11) continue;
1275 if(m_debug == 4) cout<<"t0forward_trk: "<<t0forward_trk<<endl;
1276 if(m_ntupleflag && m_tuple2){
1277 g_t0for[nmatch1] = t0forward_trk ;
1278 g_meantdc=ftdc;
1279 if(tofid<44) g_ntofup1++;
1280 else g_ntofdown1++;
1281 }
1282 meantev[nmatch]=forevtime;
1283 t0forward_add += t0forward_trk;
1284 //t0v.push_back(t0forward_trk);
1285 if(nmatch>499) break;
1286 Tof_t0Arr[nmatch]=t0forward_trk;
1287 nmatch++;
1288 nmatch1++;
1289 nmatch_barrel_1++;
1290 }
1291 }
1292 }
1293 }
1294 }
1295 }
1296 else if(((*iter2)->quality() & 0x5) ==0x1){ // tEstFlag=241
1297 tofid = (*iter2)->tofId();
1298 layerid = (*iter2)->layer();
1299 if(layerid==1) tofid=tofid-88;
1300 log<< MSG::INFO
1301 <<" TofId = "<<tofid
1302 <<" barrelid = "<<barrelid
1303 <<" layerid = "<<layerid
1304 <<" BackwordADC = "<<(*iter2)->adc2()
1305 <<" BackwordTDC = "<<(*iter2)->tdc2()
1306 << endreq;
1307 //forb=0/1 for forward(z>0, east) and backward(z<0, west)
1308 double btdc= (*iter2)->tdc2();
1309 if(m_debug==4) cout<<"barrel 5 ::layer, barrel, tofid, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<btdc<<endl;
1310 double badc= (*iter2)->adc2();
1311 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1312 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1313 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1314 for(int i=0;i<=ntot;i++){
1315 if(ttof[i]!=0 && btdc>0){
1316 if((tofid_helix[i] == tofid) || (tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1317 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1318 if (optCosmic && tofid<44) {
1319 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1320 meantevup[ntofup]=backevtime;
1321 ntofup++;
1322 }
1323 else{
1324 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1325 meantevdown[ntofdown]=backevtime;
1326 ntofdown++;
1327 }
1328
1329 if( (*iter2)->adc2()<0.0 || m_userawtime){
1330 t0backward_trk = btdc - backevtime ;
1331 }
1332 else{
1333 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1334 }
1335
1336 if(t0backward_trk<-1) continue;
1337 if(!m_TofOpt&&nmatch_barrel_2!=0 && fabs((t0backward_trk)-(t0backward_add)/nmatch_barrel_2)>11) continue;
1338 if(m_debug == 4) cout<<"t0backward_trk: "<<t0backward_trk<<endl;
1339 if(m_ntupleflag && m_tuple2){
1340 g_t0back[nmatch2] = t0backward_trk ;
1341 g_meantdc=btdc;
1342 if(tofid<44) g_ntofup1++;
1343 else g_ntofdown1++;
1344 }
1345 meantev[nmatch]=backevtime;
1346 t0backward_add += t0backward_trk;
1347 if(nmatch>499) break;
1348 Tof_t0Arr[nmatch]=t0backward_trk;
1349 nmatch++;
1350 nmatch2++;
1351 nmatch_barrel_2++;
1352 }
1353 }
1354 }
1355 }
1356 }
1357 }
1358 }
1359 }
1360 if(nmatch_barrel_1 != 0 ){
1361 t0forward = t0forward_add/nmatch_barrel_1;
1362 if(optCosmic==0){
1363 if(m_TofOpt)
1364 {
1365 t_Est=EST_Trimmer(Opt_new(Tof_t0Arr,nmatch,m_TofOpt_Cut),tOffset_b,toffset_rawtime,offset_dt,bunchtime);
1366 }
1367 else t_Est=EST_Trimmer(t0forward,tOffset_b,toffset_rawtime,offset_dt,bunchtime);
1368 if(t_Est<0) t_Est=0;
1369 tEstFlag=141;
1370 }
1371 else{
1372 t_Est=t0forward;//5. yzhang add for nmatch_barrel_1 cosmic
1373 tEstFlag=241;
1374 }
1375 if(m_ntupleflag && m_tuple2) g_meant0=t0forward;
1376 }
1377 if(nmatch_barrel_2 != 0 ){
1378 t0backward = t0backward_add/nmatch_barrel_2;
1379 if(optCosmic==0){
1380 if(m_TofOpt)
1381 {
1382 t_Est=EST_Trimmer(Opt_new(Tof_t0Arr,nmatch,m_TofOpt_Cut),tOffset_b,toffset_rawtime,offset_dt,bunchtime);
1383 }
1384 else t_Est=EST_Trimmer(t0backward,tOffset_b,toffset_rawtime,offset_dt,bunchtime);
1385 if(t_Est<0) t_Est=0;
1386 tEstFlag=141;
1387 }
1388 else{
1389 t_Est=t0backward;//7. yzhang add tOffset_b for nmatch_barrel_2 cosmic
1390 tEstFlag=241;
1391 }
1392 if(m_ntupleflag && m_tuple2) g_meant0=t0backward;
1393 }
1394
1395 digiId = 0;
1396 t0forward_add = 0;
1397 t0backward_add = 0;
1398 if(nmatch_barrel==0){
1399 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1400 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1401 barrelid=(*iter2)->barrel();
1402 if((*iter2)->barrel()!=0) continue;
1403 if((*iter2)->times()!=1) continue;
1404 tofid = (*iter2)->tofId();
1405 // Scintillator Endcap TOF
1406 if( !( (*iter2)->is_mrpc() ) ) {
1407 if( tofid<48 ) { barrelid=0; }
1408 if( tofid>47 ) { barrelid=2; }
1409 if( barrelid==2 ) { tofid=tofid-48; }
1410 }
1411 // MRPC Endcap TOF
1412 else if( (*iter2)->is_mrpc() ) {
1413 if( ( TofID::endcap( Identifier( (*iter2)->identify() ) ) ) == 0 ) { barrelid=0; }
1414 else if( ( TofID::endcap( Identifier( (*iter2)->identify() ) ) ) == 1 ) { barrelid=2; }
1415 if( barrelid==2 ) { tofid=tofid-36; }
1416 }
1417
1418 log<< MSG::INFO
1419 <<" is_mrpc = " << (*iter2)->is_mrpc()
1420 <<" TofId = "<< tofid
1421 <<" barrelid = "<< barrelid
1422 <<endreq
1423 <<" ForwordADC = "<< (*iter2)->adc()
1424 <<" ForwordTDC = "<< (*iter2)->tdc()
1425 << endreq;
1426 double ftdc= (*iter2)->tdc();
1427 double fadc= (*iter2)->adc();
1428 if(m_debug ==4) cout<<"endcap::single hit,barrelid,tofid,tdc: "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<endl;
1429
1430 // Scintillator Endcap TOF
1431 if( !( (*iter2)->is_mrpc() ) && useEtofScin ) {
1432 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1433 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1434 // Collision Case
1435 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1436 for(int i=0;i<=ntot;i++){
1437 if(ttof[i]!=0 && ftdc>0 && ftdc<2000.){
1438 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1439 if( barrelid==0 || barrelid==2 ){
1440 if( r_endtof[i]>=41 && r_endtof[i]<=90 ) {
1441 if( optCosmic && ( tofid<24 || ( tofid>48 && tofid<71 ) ) ) {
1442 forevtime = -ttof[i] + r_endtof[i]*0.09 + 12.2;
1443 meantevup[ntofup] = forevtime;
1444 ntofup++;
1445 }
1446 else {
1447 forevtime = ttof[i] + r_endtof[i]*0.09 + 12.2;
1448 meantevdown[ntofdown] = forevtime;
1449 ntofdown++;
1450 }
1451 if( (*iter2)->adc()<0.0 || m_userawtime){
1452 t0forward_trk = ftdc - forevtime;
1453 }
1454 else{
1455 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1456 }
1457
1458 if(t0forward_trk<-1.) continue;
1459 if( !m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 ) continue;
1460 t0forward_add += t0forward_trk;
1461 if(nmatch>499) break;
1462 Tof_t0Arr[nmatch]=t0forward_trk;
1463 meantev[nmatch]=forevtime/2;
1464 nmatch++;
1465 nmatch_end++;
1466 }
1467 }
1468 }
1469 if( m_debug==4 ) { cout << "t0forward_trk:" << t0forward_trk << endl; }
1470 }
1471 }
1472 }
1473 }
1474 // MRPC Endcap TOF
1475 if( (*iter2)->is_mrpc() && useEtofMRPC ) {
1476 if( ((*iter2)->quality() & 0x5)!=0x5 ) continue;
1477 double btdc= (*iter2)->tdc2();
1478 double badc= (*iter2)->adc2();
1479 int idptof = ((tofid-1) == -1) ? 35 : tofid-1;
1480 int idntof = ((tofid+1) == 36) ? 0 : tofid+1;
1481 // B e a m d a t a c a s e <--- Implement for test!
1482 if( idetfmatch[barrelid][tofid]==1 || idetfmatch[barrelid][idptof]==1 || idetfmatch[barrelid][idntof]==1 ) {
1483 for( int i=0; i<=ntot; i++ ) {
1484 if( tetf[i]!=0 && ftdc>0 && ftdc<2000.) {
1485 if( etfid_helix[i]==tofid || etfid_helix[i]==idntof || etfid_helix[i] == idptof ) {
1486 if( barrelid==0 || barrelid==2 ) {
1487 if( r_endetf[i]>=41 && r_endetf[i]<=90 ) {
1488 if( optCosmic && ( tofid<18 || ( tofid>35 && tofid<54 ) ) ) {
1489 forevtime = -tetf[i] + 17.7;
1490 meantevup[ntofup] = forevtime;
1491 ntofup++;
1492 }
1493 else {
1494 forevtime = tetf[i] + 17.7;
1495 meantevdown[ntofdown] = forevtime;
1496 ntofdown++;
1497 }
1498 if( m_userawtime ) {
1499 double fbtdc = ( ftdc + btdc )/2.0;
1500 if( ftdc>0 && btdc<0 ) { fbtdc = ftdc; }
1501 else if( ftdc<0 && btdc>0 ) { fbtdc = btdc; }
1502 else if( ftdc<0 && btdc<0 ) continue;
1503 t0forward_trk = fbtdc - forevtime;
1504 }
1505 else {
1506 t0forward_trk = tofCaliSvc->EtfTime( (*iter2)->tdc1(), (*iter2)->tdc2(), (*iter2)->tofId(), (*iter2)->strip() )-tetf[i];
1507 }
1508
1509 if( t0forward_trk<-1 ) continue;
1510 if( m_TofOpt && nmatch_end!=0 && fabs(t0forward_trk-t0forward_add/nmatch_end)>9 ) continue;
1511 if( m_debug == 4 ) { cout << "t0forward_trk:" << t0forward_trk << endl; }
1512 t0forward_add += t0forward_trk;
1513 if(nmatch>499) break;
1514 Tof_t0Arr[nmatch] = t0forward_trk;
1515 meantev[nmatch] = forevtime;
1516 nmatch++;
1517 nmatch_end++;
1518 }
1519 }
1520 }
1521 }
1522 }
1523 }
1524 }
1525 }
1526 if( nmatch_end ) { tof_flag=5; }
1527 }
1528
1529 if( nmatch_barrel==0 && nmatch_end==0 ) {
1530 for( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end(); iter2++, digiId++ ) {
1531 barrelid=(*iter2)->barrel();
1532 if( (*iter2)->barrel()!=0 ) continue;
1533 if( (*iter2)->times()!=1 ) continue;
1534 tofid = (*iter2)->tofId();
1535 // Scintillator Endcap TOF
1536 if( !( (*iter2)->is_mrpc() ) ) {
1537 if( tofid<48 ) { barrelid=0; }
1538 if( tofid>47 ) { barrelid=2; }
1539 if( barrelid==2 ) { tofid=tofid-48; }
1540 }
1541 // MRPC Endcap TOF
1542 else if( (*iter2)->is_mrpc() ) {
1543 if( ( TofID::endcap( Identifier( (*iter2)->identify() ) ) ) == 0 ) { barrelid=0; }
1544 else if( ( TofID::endcap( Identifier( (*iter2)->identify() ) ) ) == 1 ) { barrelid=2; }
1545 if( barrelid==2 ) { tofid=tofid-36; }
1546 }
1547
1548 log<< MSG::INFO
1549 <<" is_mrpc = " << (*iter2)->is_mrpc()
1550 <<" TofId = "<< tofid
1551 <<" barrelid = "<< barrelid
1552 <<endreq
1553 <<" ForwordADC = "<< (*iter2)->adc()
1554 <<" ForwordTDC = "<< (*iter2)->tdc()
1555 << endreq;
1556 double ftdc= (*iter2)->tdc();
1557 double fadc= (*iter2)->adc();
1558 if(m_debug ==4) cout<<"endcap::single hit,barrelid,tofid,tdc: "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<endl;
1559
1560 // Scintillator Endcap TOF
1561 if( !( (*iter2)->is_mrpc() ) && useEtofScin ) {
1562 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1563 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1564 for( int i=0; i<2; i++ ) {
1565 if( zemc_rec[0] || zemc_rec[1] ) {
1566 if( tofid==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof ) {
1567 if( ftdc>2000. || module[i]==1 ) continue; // module[i]==1 barrel
1568 ttof[i]= sqrt(ELMAS2/(m_ebeam*m_ebeam)+1)*sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]+133*133)/VLIGHT;
1569 r_endtof[i]=sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
1570 if( optCosmic && ( tofid<24 || ( tofid>48 && tofid<71 ) ) ) {
1571 forevtime = -ttof[i] + r_endtof[i]*0.09 + 12.2;
1572 meantevup[ntofup] = forevtime;
1573 ntofup++;
1574 }
1575 else {
1576 forevtime = ttof[i] + r_endtof[i]*0.09 + 12.2;
1577 meantevdown[ntofdown] = forevtime;
1578 ntofdown++;
1579 }
1580 if( (*iter2)->adc()<0.0 || m_userawtime){
1581 t0forward_trk = ftdc - forevtime;
1582 }
1583 else{
1584 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1585 if(m_debug ==4) cout<<"emc flag t0forward_trk: "<<t0forward_trk<<endl;
1586 }
1587
1588 if( t0forward_trk<-1.) continue;
1589 if( !m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 ) continue;
1590 meantev[nmatch] = forevtime;
1591 t0forward_add += t0forward_trk;
1592 if(nmatch>499) break;
1593 Tof_t0Arr[nmatch] = t0forward_trk;
1594 nmatch++;
1595 nmatch_end++;
1596 emcflag2=1;
1597 }
1598 }
1599 }
1600 }
1601 // MRPC Endcap TOF
1602 if( (*iter2)->is_mrpc() && useEtofMRPC ) {
1603 double btdc= (*iter2)->tdc2();
1604 double badc= (*iter2)->adc2();
1605 int idptof = ((tofid-1) == -1) ? 35 : tofid-1;
1606 int idntof = ((tofid+1) == 36) ? 0 : tofid+1;
1607 for( int i=0; i<2; i++ ) {
1608 if( zemc_rec[0] || zemc_rec[1] ) {
1609 if( tofid==etfid_emc[i] || etfid_emc[i]==idntof || etfid_emc[i]==idptof ) {
1610
1611 if( ftdc>2000.|| module[i]==1 ) continue;
1612 tetf[i]= sqrt(ELMAS2/(m_ebeam*m_ebeam)+1)* sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]+133*133)/VLIGHT;
1613 r_endetf[i] = sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
1614 if( optCosmic && ( tofid<18 || ( tofid>35 && tofid<54 ) ) ) {
1615 forevtime = -tetf[i] + 17.7;
1616 meantevup[ntofup] = forevtime;
1617 ntofup++;
1618 }
1619 else {
1620 forevtime = tetf[i] + 17.7;
1621 meantevdown[ntofdown] = forevtime;
1622 ntofdown++;
1623 }
1624
1625 if( m_userawtime ) {
1626 double fbtdc = ( ftdc + btdc )/2.0;
1627 if( ftdc>0 && btdc<0 ) { fbtdc = ftdc; }
1628 else if( ftdc<0 && btdc>0 ) { fbtdc = btdc; }
1629 else if( ftdc<0 && btdc<0 ) continue;
1630 t0forward_trk = fbtdc - forevtime;
1631 }
1632 else {
1633 t0forward_trk = tofCaliSvc->EtfTime( (*iter2)->tdc1(), (*iter2)->tdc2(), (*iter2)->tofId(), (*iter2)->strip() )-tetf[i];
1634 }
1635
1636 if( t0forward_trk<-1 ) continue;
1637 if( !m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 ) continue;
1638 if( m_debug==4 ) { cout << "t0forward_trk:" << t0forward_trk << endl; }
1639 t0forward_add += t0forward_trk;
1640 if(nmatch>499) break;
1641 Tof_t0Arr[nmatch]=t0forward_trk;
1642 nmatch++;
1643 nmatch_end++;
1644 emcflag2=1;
1645 }
1646 }
1647 }
1648 }
1649 }
1650 if( nmatch_end ) { tof_flag=5; }
1651 }
1652
1653 if( nmatch_barrel==0 && nmatch_end==0 ) {
1654 for( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end(); iter2++, digiId++ ) {
1655 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1656 barrelid = (*iter2)->barrel();
1657 if( (*iter2)->barrel()!=0 ) continue;
1658 if( (*iter2)->times()>1 && (*iter2)->times()<5 ) {
1659 tofid = (*iter2)->tofId();
1660 // Scintillator Endcap TOF
1661 if( !( (*iter2)->is_mrpc() ) ) {
1662 if( tofid<48 ) { barrelid=0; }
1663 if( tofid>47 ) { barrelid=2; }
1664 if( barrelid==2 ) { tofid=tofid-48; }
1665 }
1666 // MRPC Endcap TOF
1667 else if( (*iter2)->is_mrpc() ) {
1668 if( ( TofID::endcap( Identifier( (*iter2)->identify() ) ) ) == 0 ) { barrelid=0; }
1669 else if( ( TofID::endcap( Identifier( (*iter2)->identify() ) ) ) == 1 ) { barrelid=2; }
1670 if( barrelid==2 ) { tofid=tofid-36; }
1671 }
1672 log<< MSG::INFO
1673 <<" TofId = "<<tofid
1674 <<" barrelid = "<<barrelid
1675 <<endreq
1676 <<" ForwordADC = "<< (*iter2)->adc()
1677 <<" ForwordTDC = "<< (*iter2)->tdc()
1678 << endreq;
1679 double ftdc = (*iter2)->tdc();
1680 double fadc = (*iter2)->adc();
1681 if( m_debug==4 ) { cout << "endcap::multi hit,barrelid,tofid,tdc: " << barrelid << " , " << tofid << " , " << ftdc << endl; }
1682
1683 // Scintillator Endcap TOF
1684 if( !( (*iter2)->is_mrpc() ) && useEtofScin ) {
1685 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1686 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1687 // B e a m d a t a c a s e
1688 if( idmatch[barrelid][tofid]==1 || idmatch[barrelid][idptof]==1 || idmatch[barrelid][idntof]==1 ) {
1689 for( int i=0; i<=ntot; i++ ) {
1690 if( ttof[i]!=0 && ftdc>0 ) {
1691 if( (tofid_helix[i]==tofid) || (tofid_helix[i]==idntof) || (tofid_helix[i]==idptof) ) {
1692 if( barrelid==0 || barrelid==2 ) {
1693 if( r_endtof[i]>=41 && r_endtof[i]<=90 ) {
1694 if( optCosmic && ( tofid<24 || ( tofid>48 && tofid<71 ) ) ) {
1695 forevtime = -ttof[i] + r_endtof[i]*0.09 + 12.2;
1696 meantevup[ntofup]=forevtime;
1697 ntofup++;
1698 }
1699 else{
1700 forevtime = ttof[i] + r_endtof[i]*0.09 + 12.2;
1701 meantevdown[ntofdown]=forevtime;
1702 ntofdown++;
1703 }
1704 if( (*iter2)->adc()<0.0 || m_userawtime){
1705 t0forward_trk=ftdc-forevtime;
1706 }
1707 else{
1708 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1709 }
1710
1711 if( t0forward_trk<-1.) continue;
1712 if( !m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 ) continue;
1713 meantev[nmatch] = forevtime;
1714 t0forward_add += t0forward_trk;
1715 if( nmatch>499 ) break;
1716 Tof_t0Arr[nmatch] = t0forward_trk;
1717 nmatch++;
1718 nmatch_end++;
1719 }
1720 }
1721 if( m_debug==4 ) { cout << "t0forward_trk:" << t0forward_trk << endl; }
1722 }
1723 }
1724 }
1725 }
1726 }
1727 // MRPC Endcap TOF
1728 if( (*iter2)->is_mrpc() && useEtofMRPC ) {
1729 double btdc= (*iter2)->tdc2();
1730 double badc= (*iter2)->adc2();
1731 int idptof = ((tofid-1) == -1) ? 35 : tofid-1;
1732 int idntof = ((tofid+1) == 36) ? 0 : tofid+1;
1733 // B e a m d a t a c a s e <--- Implement for test!
1734 if( idetfmatch[barrelid][tofid]==1 || idetfmatch[barrelid][idptof]==1 || idetfmatch[barrelid][idntof]==1 ) {
1735 for( int i=0; i<=ntot; i++ ) {
1736 if( tetf[i]!=0 && ftdc>0 && ftdc<2000.) {
1737 if( etfid_helix[i]==tofid || etfid_helix[i]==idntof || etfid_helix[i] == idptof ) {
1738 if( barrelid==0 || barrelid==2 ) {
1739 if( r_endetf[i]>=41 && r_endetf[i]<=90 ) {
1740 if( optCosmic && ( tofid<18 || ( tofid>35 && tofid<54 ) ) ) {
1741 forevtime = -tetf[i] + 17.7;
1742 meantevup[ntofup] = forevtime;
1743 ntofup++;
1744 }
1745 else {
1746 forevtime = tetf[i] + 17.7;
1747 meantevdown[ntofdown] = forevtime;
1748 ntofdown++;
1749 }
1750 if( m_userawtime ) {
1751 double fbtdc = ( ftdc + btdc )/2.0;
1752 if( ftdc>0 && btdc<0 ) { fbtdc = ftdc; }
1753 else if( ftdc<0 && btdc>0 ) { fbtdc = btdc; }
1754 else if( ftdc<0 && btdc<0 ) continue;
1755 t0forward_trk = fbtdc - forevtime;
1756 }
1757 else {
1758 t0forward_trk = tofCaliSvc->EtfTime( (*iter2)->tdc1(), (*iter2)->tdc2(), (*iter2)->tofId(), (*iter2)->strip() )-tetf[i];
1759 }
1760
1761 if( t0forward_trk<-1 ) continue;
1762 if( !m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end )>9 ) continue;
1763 if( m_debug == 4 ) { cout << "t0forward_trk:" << t0forward_trk << endl; }
1764 t0forward_add += t0forward_trk;
1765 if(nmatch>499) break;
1766 Tof_t0Arr[nmatch] = t0forward_trk;
1767 meantev[nmatch] = forevtime;
1768 nmatch++;
1769 nmatch_end++;
1770 }
1771 }
1772 }
1773 }
1774 }
1775 }
1776 }
1777 }
1778 }
1779 if( nmatch_end ) { tof_flag=7; }
1780 }
1781
1782 if(m_ntupleflag && m_tuple2){
1783 g_nmatchbarrel = nmatch_barrel;
1784 g_nmatchbarrel_1 = nmatch_barrel_1;
1785 g_nmatchbarrel_2 = nmatch_barrel_2;
1786 g_nmatchend = nmatch_end;
1787 }
1788
1789 if( nmatch_end !=0 ) {
1790 t0forward = t0forward_add/nmatch_end;
1791 if( optCosmic==0 ) {
1792 if( m_TofOpt ) {
1793 t_Est=EST_Trimmer(Opt_new(Tof_t0Arr,nmatch,m_TofOpt_Cut),tOffset_e,toffset_rawtime_e,offset_dt_end,bunchtime);
1794 }
1795 else { t_Est=EST_Trimmer(t0forward,tOffset_e,toffset_rawtime_e,offset_dt_end,bunchtime); }
1796 /*
1797 cout << "EsTimeAlg: Determine t_est:" << endl;
1798 cout << " tOffset_b " << tOffset_b << endl;
1799 cout << " toffset_rawtime " <<toffset_rawtime<< endl;
1800 cout << " offset_dt "<< offset_dt << endl;
1801 cout << " Opt_new "<< Opt_new(Tof_t0Arr,nmatch,m_TofOpt_Cut) << endl;
1802 cout << " Tof_t0Arr "<< *Tof_t0Arr << endl;
1803 cout << " nmatch "<< nmatch << endl;
1804 cout << " t_Est " << t_Est << endl;
1805 cout << " t_0forward " << t0forward << endl;
1806 cout << " tOffset_e " << tOffset_e << endl;
1807 cout << " toffset_raw_e " << toffset_rawtime_e << endl;
1808 cout << " offset_dt_end " << offset_dt_end << endl;
1809 cout << " bunchtime " << bunchtime << endl;
1810 cout << " m_TofOpt " << m_TofOpt << endl;
1811 cout << "--------------------------" << endl;
1812 */
1813 if(t_Est<0) t_Est=0;
1814 if(tof_flag==5) tEstFlag=151;
1815 else if(tof_flag==7) tEstFlag=171;
1816 if(emcflag2==1) tEstFlag=161;
1817 /* if(m_nbunch==6){
1818 nbunch=(int)(t0forward-offset)/4;
1819 if(((int)(t0forward-offset))%4>2 || ((int)(t0forward-offset))%4==2) nbunch=nbunch+1;
1820 // if(((int)(t0forward-offset))%4>2) nbunch=nbunch+1;
1821 t_Est=nbunch*4+offset;
1822 if(t_Est<0) t_Est=0;
1823 tEstFlag=151;
1824 }*/
1825 }
1826 if( optCosmic ) {
1827 t_Est=t0forward;//10. yzhang add for nmatch_end cosmic event
1828 if(tof_flag==5) tEstFlag=251;
1829 else if(tof_flag==7) tEstFlag=271;
1830 if(emcflag2==1) tEstFlag=261;
1831 }
1832 if(m_ntupleflag && m_tuple2) g_meant0=t0forward;
1833 }
1834
1835 double t0_comp=-999;
1836 double T0=-999;
1837
1838 if(nmatch_barrel==0 && nmatch_end==0 && m_flag==1){
1839 double mhit[43][300]={0.};
1840 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
1841 if (!mdcDigiCol) {
1842 log << MSG::INFO<< "Could not find MDC digi" << endreq;
1843 return StatusCode::FAILURE;
1844 }
1845
1846 IMdcGeomSvc* mdcGeomSvc;
1847 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
1848 if (sc != StatusCode::SUCCESS) {
1849 return StatusCode::FAILURE;
1850 }
1851
1852 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
1853 digiId = 0;
1854 Identifier mdcId;
1855 int layerId;
1856 int wireId;
1857
1858 for (;iter1 != mdcDigiCol->end(); iter1++, digiId++) {
1859 mdcId = (*iter1)->identify();
1860 layerId = MdcID::layer(mdcId);
1861 wireId = MdcID::wire(mdcId);
1862
1863 mhit[layerId][wireId]=RawDataUtil::MdcTime((*iter1)->getTimeChannel());
1864 mhit[layerId][wireId]-=1.28*(mdcGeomSvc->Layer(layerId)->Radius())/299.8;
1865
1866 mdcGeomSvc->Wire(layerId,wireId);
1867 // Apply crude TOF, Belle: tof=1.074*radius/c, here we use 1.28 instead of 1.074.
1868 double tof;
1869 // tof = 1.28 * mhit.geo->Lyr()->Radius()/299.8; //unit of Radius is mm.
1870 }
1871
1872 int Iused[43][300]={0},tmp=0;
1873 bool Lpat,Lpat11,Lpat12,Lpat2,Lpat31,Lpat32;
1874 double t0_all=0,t0_mean=0;
1875 double r[4]={0.};
1876 double chi2=999.0;
1877 double phi[4]={0.},corr[4]={0.},driftt[4]={0.};
1878 double ambig=1;
1879 double mchisq=50000;
1880
1881 //for(int i=2;i<10;i++){
1882 for(int i=5;i<10;i++){
1883
1884 double T1=0.5*0.1*(mdcGeomSvc->Layer(4*i+0)->PCSiz())/0.004;
1885 double T2=0.5*0.1*(mdcGeomSvc->Layer(4*i+1)->PCSiz())/0.004;
1886 double T3=0.5*0.1*(mdcGeomSvc->Layer(4*i+2)->PCSiz())/0.004;
1887 double T4=0.5*0.1*(mdcGeomSvc->Layer(4*i+3)->PCSiz())/0.004;
1888 r[0]=(mdcGeomSvc->Layer(4*i+0)->Radius())*0.1;
1889 r[1]=(mdcGeomSvc->Layer(4*i+1)->Radius())*0.1;
1890 r[2]=(mdcGeomSvc->Layer(4*i+2)->Radius())*0.1;
1891 r[3]=(mdcGeomSvc->Layer(4*i+3)->Radius())*0.1;
1892 double r0=r[0]-r[1]-(r[2]-r[1])/2;
1893 double r1=-(r[2]-r[1])/2;
1894 double r2=(r[2]-r[1])/2;
1895 double r3=r[3]-r[2]+(r[2]-r[1])/2;
1896
1897 for(int j=0;j<mdcGeomSvc->Layer(i*4+3)->NCell();j++){
1898
1899 int Icp=0;
1900 Icp=j-1;
1901 if(Icp<0) Icp=mdcGeomSvc->Layer(i*4+3)->NCell();
1902
1903 Lpat=(mhit[4*i][j]!=0) && (mhit[4*i][Icp]==0) &&( mhit[4*i][j+1]==0) && (Iused[4*i][j]==0);
1904 if(Lpat==1){
1905
1906 }
1907 if(Lpat){
1908 Lpat11=(mhit[4*i+1][Icp]==0)&&(Iused[4*i+1][j]==0)&&(mhit[4*i+1][j]!=0)&&(mhit[4*i+1][j+1]==0);
1909 Lpat12=(mhit[4*i+1][j]==0)&&(Iused[4*i+1][j+1]==0)&&(mhit[4*i+1][j+1]!=0)&&(mhit[4*i+1][j+2]==0);
1910 Lpat2=(mhit[4*i+2][Icp]==0)&&(Iused[4*i+2][j]==0)&&(mhit[4*i+2][j]!=0)&&(mhit[4*i+2][j+1]==0);
1911 Lpat31=(mhit[4*i+3][Icp]==0)&&(Iused[4*i+3][j]==0)&&(mhit[4*i+3][j]!=0)&&(mhit[4*i+3][j+1]==0);
1912 Lpat32=(mhit[4*i+3][j]==0)&&(Iused[4*i+3][j+1]==0)&&(mhit[4*i+3][j+1]!=0)&&(mhit[4*i+3][j+2]==0);
1913
1914 if(Lpat11 && Lpat2 && Lpat31 ){
1915
1916 Iused[4*i+0][j]=1;
1917 Iused[4*i+1][j]=1;
1918 Iused[4*i+2][j]=1;
1919 Iused[4*i+3][j]=1;
1920 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
1921 double t_j = mhit[4*i+1][j]+mhit[4*i+3][j];
1922 double l_j = T2+T4;
1923 double r_i = r0+r2;
1924 double r_j = r1+r3;
1925 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
1926 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
1927 double rt_j = r1*mhit[4*i+1][j]+r3*mhit[4*i+3][j];
1928 double rl_j = r1*T2+r3*T4;
1929
1930 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
1931
1932 if (deno!=0){
1933 double Pa=(4*(rt_i-rt_j+rl_j)-(t_i+t_j-l_j)*(r_i-r_j)-(t_i-t_j+l_j)*(r_i+r_j))/deno;
1934 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
1935 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
1936
1937 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
1938
1939 double chi2_tmp;
1940 for(int t0c=0;t0c<17;t0c+=8){
1941 chi2_tmp=(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)*(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)+(T2-mhit[4*i+1][j]+t0c-r1 * Pa-Pb)*(T2-mhit[4*i+1][j]+t0c-r1 * Pa-Pb)+(mhit[4*i+2][j]-t0c-r2 * Pa-Pb)*(mhit[4*i+2][j]-t0c-r2 * Pa-Pb) + (T4-mhit[4*i+3][j]+t0c-r3 * Pa-Pb)*(T4-mhit[4*i+3][j]+t0c-r3 * Pa-Pb);
1942 if(chi2_tmp<chi2){
1943 chi2=chi2_tmp;
1944 t0_comp=t0c;
1945 }
1946 }
1947 tmp+=1;
1948 }
1949 //use squareleas t0
1950
1951 for(int tmpT0=0;tmpT0<17;tmpT0+=8){
1952 driftt[0]=mhit[4*i+0][j]-tmpT0;
1953 driftt[1]=mhit[4*i+1][j]-tmpT0;
1954 driftt[2]=mhit[4*i+2][j]-tmpT0;
1955 driftt[3]=mhit[4*i+3][j]-tmpT0;
1956
1957 phi[0]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
1958 phi[1]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell());
1959 phi[2]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
1960 phi[3]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+3)->NCell());
1961 phi[0]-=ambig*driftt[0]*0.004/r[0];
1962 phi[1]+=ambig*driftt[1]*0.004/r[1];
1963 phi[2]-=ambig*driftt[2]*0.004/r[2];
1964 phi[3]+=ambig*driftt[3]*0.004/r[3];
1965 double s1, sx, sy, sxx, sxy; // The various sums.
1966 double delinv, denom;
1967 double weight; // weight for hits, calculated from sigmas.
1968 double sigma;
1969 double x[4];
1970 x[0]=r0;
1971 x[1]=r1;
1972 x[2]=r2;
1973 x[3]=r3;
1974 sigma=0.12;
1975 s1 = sx = sy = sxx = sxy = 0.0;
1976 double chisq = 0.0;
1977 for (int ihit = 0; ihit < 4; ihit++) {
1978 weight = 1. / (sigma * sigma);//NEED sigma of MdcHits
1979 s1 += weight;
1980 sx += x[ihit] * weight;
1981 sy += phi[ihit] * weight;
1982 sxx += x[ihit] * (x[ihit] * weight);
1983 sxy += phi[ihit] * (x[ihit] * weight);
1984 }
1985 double resid[4]={0.};
1986 /* Calculate parameters. */
1987 denom = s1 * sxx - sx * sx;
1988 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
1989 double intercept = (sy * sxx - sx * sxy) * delinv;
1990 double slope = (s1 * sxy - sx * sy) * delinv;
1991
1992 /* Calculate residuals. */
1993 for (int ihit = 0; ihit < 4; ihit++) {
1994 resid[ihit] = ( phi[ihit] - intercept - slope * x[ihit] );
1995 chisq += resid[ihit] * resid[ihit]/(sigma*sigma) ;
1996 }
1997 if(chisq<mchisq){
1998 mchisq=chisq;
1999 T0=tmpT0;
2000 }
2001 }
2002 }
2003 if(Lpat12 && Lpat2 && Lpat32){
2004 Iused[4*i+0][j]=1;
2005 Iused[4*i+1][j+1]=1;
2006 Iused[4*i+2][j]=1;
2007 Iused[4*i+3][j+1]=1;
2008
2009 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
2010 double t_j = mhit[4*i+1][j+1]+mhit[4*i+3][j+1];
2011 double l_j = T2+T4;
2012 double r_i = r0+r2;
2013 double r_j = r1+r3;
2014 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
2015 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
2016 double rt_j = r1*mhit[4*i+1][j+1]+r3*mhit[4*i+3][j+1];
2017 double rl_j = r1*T2+r3*T4;
2018 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
2019
2020 if (deno!=0){
2021 double Pa=(4*(rt_i-rt_j+rl_j)-(t_i+t_j-l_j)*(r_i-r_j)-(t_i-t_j+l_j)*(r_i+r_j))/deno;
2022 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
2023 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
2024 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
2025 tmp+=1;
2026 double chi2_tmp;
2027
2028 for(int t0c=0;t0c<17;t0c+=8){
2029 chi2_tmp=(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)*(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)+(T2-mhit[4*i+1][j+1]+t0c-r1 * Pa-Pb)*(T2-mhit[4*i+1][j+1]+t0c-r1 * Pa-Pb)+(mhit[4*i+2][j]-t0c-r2 * Pa-Pb)*(mhit[4*i+2][j]-t0c-r2 * Pa-Pb) + (T4-mhit[4*i+3][j+1]+t0c-r3 * Pa-Pb)*(T4-mhit[4*i+3][j+1]+t0c-r3 * Pa-Pb);
2030
2031 if(chi2_tmp<chi2){
2032 chi2=chi2_tmp;
2033 t0_comp=t0c;
2034 }
2035 }
2036 }
2037
2038 //use squareleast
2039
2040 for(int tmpT0=0;tmpT0<17;tmpT0+=8){
2041 driftt[0]=mhit[4*i+0][j]-tmpT0;
2042 driftt[1]=mhit[4*i+1][j+1]-tmpT0;
2043 driftt[2]=mhit[4*i+2][j]-tmpT0;
2044 driftt[3]=mhit[4*i+3][j+1]-tmpT0;
2045
2046 phi[0]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
2047 phi[1]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell());
2048 phi[2]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
2049 phi[3]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+3)->NCell());
2050 phi[0]-=ambig*driftt[0]*0.004/r[0];
2051 phi[1]+=ambig*driftt[1]*0.004/r[1];
2052 phi[2]-=ambig*driftt[2]*0.004/r[2];
2053 phi[3]+=ambig*driftt[3]*0.004/r[3];
2054 double s1, sx, sy, sxx, sxy; // The various sums.
2055 double delinv, denom;
2056 double weight; // weight for hits, calculated from sigmas.
2057 double sigma;
2058 double x[4];
2059 x[0]=r0;
2060 x[1]=r1;
2061 x[2]=r2;
2062 x[3]=r3;
2063 sigma=0.12;
2064 s1 = sx = sy = sxx = sxy = 0.0;
2065 double chisq = 0.0;
2066 for (int ihit = 0; ihit < 4; ihit++) {
2067 weight = 1. / (sigma * sigma);//NEED sigma of MdcHits
2068 s1 += weight;
2069 sx += x[ihit] * weight;
2070 sy += phi[ihit] * weight;
2071 sxx += x[ihit] * (x[ihit] * weight);
2072 sxy += phi[ihit] * (x[ihit] * weight);
2073 }
2074 double resid[4]={0.};
2075 /* Calculate parameters. */
2076 denom = s1 * sxx - sx * sx;
2077 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
2078 double intercept = (sy * sxx - sx * sxy) * delinv;
2079 double slope = (s1 * sxy - sx * sy) * delinv;
2080
2081 /* Calculate residuals. */
2082 for (int ihit = 0; ihit < 4; ihit++) {
2083 resid[ihit] = ( phi[ihit] - intercept - slope * x[ihit] );
2084 chisq += resid[ihit] * resid[ihit]/(sigma*sigma) ;
2085 }
2086
2087 if(chisq<mchisq){
2088 mchisq=chisq;
2089 T0=tmpT0;
2090 }
2091 }
2092 }
2093 }
2094 }
2095 }
2096
2097 if(tmp!=0){
2098 t0_mean=t0_all/tmp;
2099 }
2100 if(m_ntupleflag && m_tuple2) g_t0mean=t0_mean;
2101
2102 t_Est=T0 + tOffset_b;//11.yzhang add tOffset_b, MDC method calc. Tes
2103 tEstFlag=2;
2104 }
2105 if(m_ntupleflag && m_tuple2){
2106 g_t0=t0_comp;
2107 g_T0=T0;
2108 }
2109 if(nmatch_barrel==0 && nmatch_end==0 && nmatch_barrel_1==0&&nmatch_barrel_2==0&&m_mdcCalibFunSvc&&m_flag==2){
2110
2111 log << MSG::INFO << " mdc " << endreq;
2112
2113#define MXWIRE 6860
2114#define MXTKHIT 6860
2115#define MXTRK 15
2116
2117 // C o n s t a n t s
2118 double VELPROP=33.33;
2119
2120 // L o c a l v a r i a b l e s
2121 int nhits_ax = 0;
2122 int nhits_ax2 = 0;
2123 int nhits_st = 0;
2124 int nhits_st2 = 0;
2125
2126 double tev_ax[MXTKHIT];
2127 double tev_st[MXTKHIT];
2128 double tevv[MXTKHIT];
2129 double toft;
2130 double prop;
2131 double t0_minus_TDC[MXWIRE];
2132 // double adc[MXWIRE];
2133 double T0_cal=-230;
2134 double Mdc_t0Arr[500];
2135
2136 int expmc=1;
2137 double scale=1.;
2138 int expno, runno;
2139 ndriftt=0;
2140
2141 // A l l t r a c k s
2142 //Check if Fzisan track exist
2143 // if(ntot<=0) return 0; // it was "if(ntot<=0) return 0;"
2144 if(ntot > MXTRK) {
2145 ntot=MXTRK;
2146 }
2147
2148 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
2149 if (!newtrkCol || newtrkCol->size()==0) {
2150 log << MSG::INFO<< "Could not find RecMdcTrackCol" << endreq;
2151 return StatusCode::SUCCESS;
2152 }
2153 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
2154
2155 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
2156
2157 for( int tempntrack=0; iter_trk != newtrkCol->end(); iter_trk++,tempntrack++) {
2158 log << MSG::DEBUG << "retrieved MDC track:"
2159 << " Track Id: " << (*iter_trk)->trackId()
2160 << " Dr: " <<(*iter_trk)->helix(0)
2161 << " Phi0: " << (*iter_trk)->helix(1)
2162 << " kappa: " << (*iter_trk)->helix(2)
2163 << " Dz: " << (*iter_trk)->helix(3)
2164 << " Tanl: " << (*iter_trk)->helix(4)
2165 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
2166 << endreq
2167 << "Number of hits: "<< (*iter_trk)->getNhits()
2168 << " Number of stereo hits " << (*iter_trk)->nster()
2169 << endreq;
2170
2171 // Track variables
2172 const HepPoint3D pivot0(0.,0.,0.);
2173 HepVector a(5,0);
2174
2175 a[0] = (*iter_trk)->helix(0);
2176 a[1] = (*iter_trk)->helix(1);
2177 a[2] = (*iter_trk)->helix(2);
2178 a[3] = (*iter_trk)->helix(3);
2179 a[4] = (*iter_trk)->helix(4);
2180
2181 // Ill-fitted (dz=tanl=-9999.) or off-IP track in fzisan
2182 if (abs(a[0])>Estparam.MDC_drCut() || abs(a[3])>Estparam.MDC_dzCut() || abs(a[4])>500.) continue;
2183
2184 double phi0 = a[1];
2185 double kappa = abs(a[2]);
2186 double dirmag = sqrt(1. + a[4]*a[4]);
2187 // double unit_s = abs(rho * dirmag);
2188 double mom = abs(dirmag/kappa);
2189 double beta=mom/sqrt(mom*mom+PIMAS2);
2190 if (particleId[tempntrack]== 1) { beta=mom/sqrt(mom*mom+ELMAS2);}
2191 if(particleId[tempntrack]== 5) { beta=mom/sqrt(mom*mom+PROTONMAS2);}
2192
2193 // D e f i n e h e l i x
2194 Helix helix0(pivot0,a);
2195 double rho = helix0.radius();
2196 double unit_s = abs(rho * dirmag);
2197
2198 helix0.ignoreErrorMatrix();
2199 HepPoint3D hcen = helix0.center();
2200 double xc= hcen(0);
2201 double yc= hcen(1);
2202
2203 if( xc==0.0 && yc==0.0 ) continue;
2204
2205 double direction =1.;
2206 if(optCosmic!=0) {
2207 double phi = atan2(helix0.momentum(0.).y(),helix0.momentum(0.).x());
2208 if(phi> 0. && phi <= M_PI) direction=-1.;
2209 }
2210
2211 IMdcGeomSvc* mdcGeomSvc;
2212 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
2213 double zeast;
2214 double zwest;
2215 double m_vp[43]={0.}, m_zst[43]={0.};
2216 for(int lay=0; lay<43; lay++){
2217 zwest = mdcGeomSvc->Wire(lay, 0)->Forward().z();
2218 zeast = mdcGeomSvc->Wire(lay, 0)->Backward().z();
2219 // m_zwid[lay] = (zeast - zwest) / (double)m_nzbin;
2220
2221 if(lay < 8) m_vp[lay] = 220.0; // *10^9 mm/s
2222 else m_vp[lay] = 240.0; // *10^9 mm/s
2223
2224 if( 0 == (lay % 2) ){ // west end
2225 m_zst[lay] = zwest;
2226 } else{ // east end
2227 m_zst[lay] = zeast;
2228 }
2229 }
2230
2231 //Hits
2232 log << MSG::DEBUG << "hitList of this track:" << endreq;
2233 HitRefVec gothits = (*iter_trk)->getVecHits();
2234 HitRefVec::iterator it_gothit = gothits.begin();
2235 for( ; it_gothit != gothits.end(); it_gothit++){
2236
2237 log << MSG::DEBUG << "hits Id: "<<(*it_gothit)->getId()
2238 << " hits MDC layerId wireId " <<MdcID::layer((*it_gothit)->getMdcId())
2239 << " "<<MdcID::wire((*it_gothit)->getMdcId())
2240 << endreq
2241 << " hits TDC " <<(*it_gothit)->getTdc()
2242 << endreq;
2243
2244 int layer=MdcID::layer((*it_gothit)->getMdcId());
2245 int wid=MdcID::wire((*it_gothit)->getMdcId());
2246 double tdc=(*it_gothit)->getTdc() ;
2247 //cout<<"-----------mdc layer,wireid,tdc--------------: "<<layer<<","<<wid<<","<<tdc<<endl;
2248 double trkchi2=(*iter_trk)->chi2();
2249 if(trkchi2>100)continue;
2250 double hitChi2=(*it_gothit)->getChisqAdd();
2251 HepVector helix_par = (*iter_trk)->helix();
2252 HepSymMatrix helixErr=(*iter_trk)->err();
2253 // *** A x i a l s e g m e n t s
2254 if((layer>=8&&layer<=19) ||(layer>=36&&layer<=42)){
2255 // H i t s
2256 ////Geomdc_wire &GeoRef = GeoMgr[wid-1];
2257 // MdcGeoWire & GeoRef = Wire[wid-1];
2258
2259 const MdcGeoWire* GeoRef = mdcGeomSvc->Wire(layer,wid);
2260
2261 ////int layer = GeoRef->Layer();
2262 //// int local = GeoRef->Cell();
2263
2264 // int layer = mdcGeomSvc->Wire(wid-1)->Layer();
2265 // int local = mdcGeomSvc->Wire(wid-1)->Cell();
2266 // double fadc = adc[wid];
2267 //// if(mdc_adc_cut_(&expmc, &expno, &runno, &fadc, &layer, &local)==0) continue;
2268
2269 //Use or not to use inner 4 layers (layers with high bg.)
2270 if(Estparam.MDC_Inner()==0 && layer <=3) continue;
2271
2272 double xw = GeoRef->Forward().x()/10; // wire x position at z=0
2273 double yw = GeoRef->Forward().y()/10; // wire y position at z=0
2274 // move pivot to the wire (slant angle ignored)
2275 HepPoint3D pivot1(xw,yw,0.);
2276 helix0.pivot(pivot1);
2277 double zw=helix0.a()[3]; // z position
2278
2279 // T o F c o r r e c t i o n
2280 double dphi = (-xc*(xw-xc)-yc*(yw-yc)) /
2281 sqrt((xc*xc+yc*yc)*((xw-xc)*(xw-xc)+(yw-yc)*(yw-yc)));
2282 dphi = acos(dphi);
2283 double pathtof = abs(unit_s * dphi);
2284 if (kappa!=0) {
2285 toft = pathtof/VLIGHT/beta;
2286 } else {
2287 toft = pathtof/VLIGHT;
2288 }
2289
2290 // P r o p a g a t i o n d e l a y c o r r e c t i o n
2291 ////if (zw < GeoRef.zwb()) zw = GeoRef.zwb();
2292 ////if (zw > GeoRef.zwf()) zw = GeoRef.zwf();
2293
2294 if (zw >(GeoRef->Backward().z())/10) zw =(GeoRef->Backward().z())/10;
2295 if (zw <(GeoRef->Forward().z())/10) zw =(GeoRef->Forward().z())/10;
2296
2297 double slant = GeoRef ->Slant();
2298 prop = zw / cos(slant) / VELPROP;
2299 //Time walk correction
2300 double Tw = 0;
2301 //if(expmc==1) {
2302 // Calmdc_const3 &TwRef = Cal3Mgr[layer];
2303 // if(adc[wid]>0.) Tw = TwRef.tw(0) + TwRef.tw(1)/sqrt(adc[wid]);
2304 //}
2305
2306 double driftt;
2307 double dummy;
2308 int lr=2;
2309 //if((xw*helix0.x(0.).y()-yw*helix0.x(0.).x())<0) lr=-1;
2310 double p[3];
2311 p[0]=helix0.momentum(0.).x();
2312 p[1]=helix0.momentum(0.).y();
2313 double pos[2];
2314 pos[0]=xw; pos[1]=yw;
2315 double alpha;
2316 //// calmdc_getalpha_( p, pos, &alpha);
2317 // double dist = wir.distance(); this is wrong
2318 //double dist = abs(helix0.a()[0]); this if wrong
2319 double dist = 0.;
2320
2321 dist=(m_mdcUtilitySvc->doca(layer, wid, helix_par, helixErr))*10.0;
2322
2323 if(dist<0.) lr=1;
2324 else lr=0;
2325 dist=fabs(dist);
2326 if(dist> 0.4*(mdcGeomSvc->Layer(layer))->PCSiz()) continue;
2327
2328 //* drift distance cut
2329 // int ia;
2330 // ia = (int) ((alpha+90.)/10.);
2331 // double da = alpha+90. - ia*10.;
2332 // if (ia==0) ia=18;
2333
2334 // Calmdc_const &BndRef = Cal1Mgr[layer];
2335 // if(lr==-1) {
2336 //if(dist < BndRef.bndl(ia,0)) continue;
2337 //if(dist > BndRef.bndl(ia,3)) continue;
2338 //}
2339 //if(lr== 1) {
2340 // if(dist < BndRef.bndr(ia,0)) continue;
2341 // if(dist > BndRef.bndr(ia,3)) continue;
2342 // }
2343
2344 int idummy;
2345
2346 if(!m_useXT) {driftt = dist/Estparam.vdrift();}
2347 else {
2348 double entrance=(*it_gothit)->getEntra();
2349 driftt = m_mdcCalibFunSvc->distToDriftTime(dist, layer, wid,lr,entrance);
2350 }
2351 if(m_useT0cal)
2352 {
2353 T0_cal=m_mdcCalibFunSvc->getT0(layer, wid)+m_mdcCalibFunSvc->getTimeWalk(layer,tdc);
2354 }
2355
2356 double zprop = fabs(zw - m_zst[layer]);
2357 double tp = zprop / m_vp[layer];
2358 //cout<<"proptation time --tp ax: "<<tp<<endl;
2359 if(driftt>tdc) continue;
2360 double difft=tdc-driftt-toft-tp-T0_cal;
2361 if(ndriftt>=500) break;
2362 if(difft<-10) continue;
2363 Mdc_t0Arr[ndriftt]=difft;
2364 //cout<<"ax: tdc, driftt, toft, tp: "<<tdc<<" , "<<driftt<<" , "<<toft<<" , "<<tp<<" , "<<difft<<endl;
2365 sum_EstimeMdc=sum_EstimeMdc+difft;
2366 ndriftt++;
2367 /*if(Estparam.MDC_Xt()==2) {
2368 calmdc_d2t_bfld_( &driftt, &dist, &dummy, &dummy, &lr,
2369 &idummy, &layer, &alpha, &dummy, &dummy, &dummy);
2370 } else if(Estparam.MDC_Xt()==1) {
2371 driftt = dist/Estparam.vdrift();
2372
2373 }*/
2374 // htf[1]->accumulate( t0_minus_TDC[wid] );
2375
2376 double tev= -t0_minus_TDC[wid]+ driftt;
2377 if(Estparam.MDC_Tof() !=0) tev += direction*toft;
2378 if(Estparam.MDC_Prop()!=0) tev += prop;
2379 //// if(Estparam.MDC_Walk()!=0) tev += Tw;
2380
2381 // sum_tev_ax += tev;
2382 // htf[3+hid]->accumulate( tev );
2383 nhits_ax++;
2384 tev_ax[nhits_ax-1]=tev;
2385
2386 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev ***" <<tev <<endreq;
2387 double driftt_mea = t0_minus_TDC[wid];
2388 // if(abs(driftt-t0_minus_TDC[wid])<75.)
2389 if(abs(driftt - driftt_mea)<75.) {
2390 // sum_tev_ax2 += tev;
2391 nhits_ax2++;
2392 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev2 ***" <<tev <<endreq;
2393 }
2394 } // End axial hits
2395
2396 // S t e r e o s e g m e n t s
2397 else if(((layer>=4&&layer<=7)||(layer>=20&&layer<=35))&&m_useSw){
2398
2399 IMdcGeomSvc* mdcGeomSvc;
2400 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
2401 const MdcGeoWire* GeoRef = mdcGeomSvc->Wire(layer,wid);
2402
2403 //double fadc=adc[wid];
2404 //// if(mdc_adc_cut_(&expmc, &expno, &runno, &fadc, &layer, &local)==0) continue;
2405
2406 double bx= GeoRef->Backward().x()/10;
2407 double by= GeoRef->Backward().y()/10;
2408 double bz= GeoRef->Backward().z()/10;
2409 double fx= GeoRef->Forward().x()/10;
2410 double fy= GeoRef->Forward().y()/10;
2411 double fz= GeoRef->Forward().z()/10;
2412
2413 //// HepPoint3D fwd(GeoRef->Forward().x(),GeoRef->Forward().y(),GeoRef->Forward().z());
2414 //// HepPoint3D bck(GeoRef->Backward().x(),GeoRef->Backward().y(),GeoRef->Backward().z());
2415 HepPoint3D fwd(fx,fy,fz);
2416 HepPoint3D bck(bx,by,bz);
2417
2418 Hep3Vector wire = (CLHEP::Hep3Vector)bck - (CLHEP::Hep3Vector)fwd;
2419 HepPoint3D try1=(fwd + bck) * .5;
2420 helix0.pivot(try1);
2421 HepPoint3D try2 = (helix0.x(0).z() - bck.z())/ wire.z() * wire + bck;
2422 helix0.pivot(try2);
2423 HepPoint3D try3 = (helix0.x(0).z() - bck.z())/ wire.z() * wire + bck;
2424 helix0.pivot(try3);
2425
2426 double xh = helix0.x(0.).x();
2427 double yh = helix0.x(0.).y();
2428 double z = helix0.x(0.).z();
2429
2430 // T o F c o r r e c t i o n
2431 double dphi = (-xc*(xh-xc)-yc*(yh-yc)) /
2432 sqrt((xc*xc+yc*yc)*((xh-xc)*(xh-xc)+(yh-yc)*(yh-yc)));
2433 dphi = acos(dphi);
2434 double pathtof = abs(unit_s * dphi);
2435 if (kappa!=0) {
2436 toft = pathtof/VLIGHT/beta;
2437 } else {
2438 toft = pathtof/VLIGHT;
2439 }
2440
2441 // P r o p a g a t i o n d e l a y c o r r e c t i o n
2442
2443 if (z != 9999.) {
2444 // if (z < GeoRef->Forward().z()/10) z = GeoRef->Forward().z()/10;
2445 if(z < fz ) z = fz;
2446 // if (z >GeoRef->Backward().z()/10) z =GeoRef->Backward().z()/10;
2447 if(z > bz ) z = bz;
2448 double slant = GeoRef->Slant();
2449 prop = z / cos(slant) / VELPROP;
2450 } else {
2451 prop = 0.;
2452 }
2453
2454 //Time walk correction
2455 double Tw = 0;
2456 //if(expmc==1) {
2457 // Calmdc_const3 &TwRef = Cal3Mgr[layer];
2458 // if(adc[wid]>0.) Tw = TwRef.tw(0) + TwRef.tw(1)/sqrt(adc[wid]);
2459 // }
2460
2461 double driftt=0;
2462 double dummy;
2463
2464 double xw = fx + (bx-fx)/(bz-fz)*(z-fz);
2465 double yw = fy + (by-fy)/(bz-fz)*(z-fz);
2466 // move pivot to the wire (slant angle ignored)
2467 HepPoint3D pivot1(xw,yw,z);
2468 helix0.pivot(pivot1);
2469
2470 double zw=helix0.a()[3]; // z position
2471
2472 int lr=2;
2473 //if((xw*helix0.x(0.).y()-yw*helix0.x(0.).x())<0) lr=-1;
2474 double p[3];
2475 p[0]=helix0.momentum(0.).x();
2476 p[1]=helix0.momentum(0.).y();
2477 double pos[2];
2478 pos[0]=xw; pos[1]=yw;
2479 double alpha;
2480 //// calmdc_getalpha_( p, pos, &alpha);
2481 // double dist = wir.distance(); this is wrong
2482 //double dist = abs(helix0.a()[0]); this is wrong
2483 double dist=0.;
2484
2485 dist=(m_mdcUtilitySvc->doca(layer, wid, helix_par, helixErr))*10.0;
2486
2487 if(dist<0.) lr=1;
2488 else lr=0;
2489 dist=fabs(dist);
2490 if(dist> 0.4*(mdcGeomSvc->Layer(layer))->PCSiz()) continue;
2491
2492 //* drift distance cut
2493 // int ia;
2494 // ia = (int) ((alpha+90.)/10.);
2495 // double da = alpha+90. - ia*10.;
2496 // if (ia==0) ia=18;
2497
2498 // Calmdc_const &BndRef = Cal1Mgr[layer];
2499 // if(lr==-1) {
2500 // if(dist < BndRef.bndl(ia,0)) continue;
2501 // if(dist > BndRef.bndl(ia,3)) continue;
2502 // }
2503 //if(lr== 1) {
2504 // if(dist < BndRef.bndr(ia,0)) continue;
2505 // if(dist > BndRef.bndr(ia,3)) continue;
2506 // }
2507
2508 if(!m_useXT){driftt = dist/(Estparam.vdrift());}
2509 else {
2510 double entrance=(*it_gothit)->getEntra();
2511 driftt = m_mdcCalibFunSvc->distToDriftTime(dist, layer, wid,lr,entrance);
2512 }
2513 if(m_useT0cal)
2514 {
2515 T0_cal=m_mdcCalibFunSvc->getT0(layer, wid)+m_mdcCalibFunSvc->getTimeWalk(layer,tdc);
2516 }
2517
2518 double zprop = fabs(zw - m_zst[layer]);
2519 double tp = zprop / m_vp[layer];
2520 //cout<<"proptation time --tp st: "<<tp<<endl;
2521 if(driftt>tdc) continue;
2522 double difft=tdc-driftt-toft-tp-T0_cal;
2523 if(difft<-10) continue;
2524 if(ndriftt>=500) break;
2525 Mdc_t0Arr[ndriftt]=difft;
2526 //if(difft>-2 && difft<22)
2527 // if(fabs(hitChi2)<0.2)
2528 //if(difft>-20 && difft<30)
2529 sum_EstimeMdc=sum_EstimeMdc+difft;
2530 ndriftt++;
2531 //}
2532
2533 // htf[2]->accumulate( t0_minus_TDC[wid] );
2534
2535 double tev= -t0_minus_TDC[wid]+ driftt;
2536 if(Estparam.MDC_Tof() !=0) tev += direction*toft;
2537 if(Estparam.MDC_Prop()!=0) tev += prop;
2538 //// if(Estparam.MDC_Walk()!=0) tev += Tw;
2539
2540 // sum_tev_st += tev;
2541
2542 // htf[3+hid]->accumulate( tev );
2543
2544 nhits_st++;
2545 tev_st[nhits_st-1]= tev;
2546
2547 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev_st ***" <<tev <<endreq;
2548 double driftt_mea = t0_minus_TDC[wid];
2549 // if(abs(driftt-t0_minus_TDC[wid]) <75.)
2550 if(abs(driftt - driftt_mea) <75.) {
2551 // sum_tev_st2 += tev;
2552 nhits_st2++;
2553 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev_st2 ***" <<tev <<endreq;
2554 }
2555 } //* End stereo hits
2556
2557 }// End hits
2558 nmatch_mdc++;
2559 } //* End tracks
2560
2561
2562 if(m_ntupleflag && m_tuple2) g_nmatchmdc = nmatch_mdc;
2563 if(ndriftt!=0){
2564 if(m_mdcopt) {
2565 sum_EstimeMdc=Opt_new(Mdc_t0Arr,ndriftt,400.0);
2566 }
2567 else { sum_EstimeMdc= sum_EstimeMdc/ndriftt;}
2568 if(m_ntupleflag && m_tuple2) g_EstimeMdc=sum_EstimeMdc;
2569 t_Est=sum_EstimeMdc + tOffset_b;//12.yzhang add tOffset_b, calc. Tes after rec for ?
2570 if(t_Est<0) t_Est=0;
2571 if(optCosmic==0){
2572 tEstFlag=102;
2573 nbunch=((int)(t_Est-offset))/bunchtime;
2574 //if(((int)(t_Est-offset))%bunchtime>bunchtime/2) nbunch=nbunch+1;
2575 if((t_Est-offset-nbunch*bunchtime)>(bunchtime/2)) nbunch=nbunch+1;
2576 t_Est=nbunch*bunchtime+offset + tOffset_b;
2577 //tEstFlag=2;
2578 // }
2579 /* if(m_nbunch==6){
2580 nbunch=((int)(t_Est-offset))/4;
2581 if(((int)(t_Est-offset))%4>2 ||((int)(t_Est-offset))%4==2 ) nbunch=nbunch+1;
2582 t_Est=nbunch*4+offset;
2583 tEstFlag=2;
2584 }*/
2585 }
2586 if(optCosmic){
2587 t_Est=sum_EstimeMdc;
2588 tEstFlag=202;
2589 }
2590 }
2591 if(m_ntupleflag && m_tuple2) g_ndriftt=ndriftt;
2592 }
2593 //yzhang add, Store to TDS
2594 if(t_Est!=-999){
2595 //changed event start time flag after rec
2596 if((!m_beforrec) && (Testime_fzisan != t_Est) ){
2597 if(tEstFlag==211) tEstFlag=213;
2598 if(tEstFlag==212) tEstFlag=216;
2599 if(tEstFlag==111) tEstFlag=113;
2600 if(tEstFlag==112) tEstFlag=116;
2601 }
2602
2603 if( optCosmic /*&& (nmatch_barrel || nmatch_end)*/){
2604 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
2605 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
2606 }else if(!optCosmic){
2607 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
2608 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
2609 }
2610 }else{
2611 // no t_Est calc.
2612 if(m_beforrec){
2613 //store event start time from segment fitting method
2614 //FIXME add tOffset_b or tOffset_e ???
2615 double segTest = Testime_fzisan + tOffset_b;
2616 int segFlag = TestimeFlag_fzisan;
2617 double segQuality = TestimeQuality_fzisan;
2618 StatusCode scStoreTds = storeTDS(segTest,segFlag,segQuality);
2619 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
2620 }
2621 }
2622 //zhangy add, end of Store to TDS
2623
2624 // check RecEsTimeCol registered
2625 SmartDataPtr<RecEsTimeCol> arecestimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
2626 if (!arecestimeCol) {
2627 if(m_debug==4) log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
2628 return( StatusCode::SUCCESS);
2629 }
2630 RecEsTimeCol::iterator iter_evt = arecestimeCol->begin();
2631 for(; iter_evt!=arecestimeCol->end(); iter_evt++){
2632 log << MSG::INFO
2633 << "Test = "<<(*iter_evt)->getTest()
2634 << ", Status = "<<(*iter_evt)->getStat()
2635 <<endreq;
2636 if(m_ntupleflag && m_tuple2){
2637 g_Testime=(*iter_evt)->getTest();
2638 }
2639 // cout<<"register to TDS: "<<(*iter_evt)->getTest()<<", "<<(*iter_evt)->getStat()<<endl;
2640 }
2641
2642 if(m_ntupleflag){
2643 if(m_tuple2){
2644 for(g_ntofdown=0;g_ntofdown<ntofdown;g_ntofdown++){ g_meantevdown[g_ntofdown]=meantevdown[g_ntofdown];}
2645 for(g_ntofup=0;g_ntofup<ntofup;g_ntofup++){ g_meantevup[g_ntofup]=meantevup[g_ntofup];}
2646 g_nmatch_tot=nmatch;
2647 m_estFlag=tEstFlag;/////20100427 guanyh add
2648 m_estTime=t_Est;
2649 StatusCode status = m_tuple2->write();
2650 if (!status.isSuccess()) {
2651 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
2652 }
2653 }
2654 if(m_tuple9){
2655 for(g_nmatch=0;g_nmatch<nmatch;g_nmatch++)
2656 {
2657 g_meantev[g_nmatch]=meantev[g_nmatch];
2658 }
2659 StatusCode status = m_tuple9->write();
2660 if (!status.isSuccess()) {
2661 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
2662 }
2663 }
2664 }
2665 return StatusCode::SUCCESS;
2666 }
2667
2668 StatusCode EsTimeAlg::finalize() {
2669
2670 MsgStream log(msgSvc(), name());
2671 log << MSG::INFO << "in finalize()" << endreq;
2672 if(m_ntupleflag && m_tuple3){
2673 StatusCode status = m_tuple3->write();
2674 if (!status.isSuccess()) {
2675 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
2676 }
2677 }
2678 cout<<"EsTimeAlg::finalize(),total events in this run: "<<m_pass[0]<<endl;
2679 return StatusCode::SUCCESS;
2680 }
2681
2682 //make TDS
2683 StatusCode EsTimeAlg::storeTDS(double tEst, int tEstFlag, double quality){
2684 StatusCode sc;
2685 MsgStream log(msgSvc(), name());
2686
2687 //check whether Recon already registered
2688 DataObject *aReconEvent;
2689 eventSvc()->findObject("/Event/Recon",aReconEvent);
2690 if(aReconEvent==NULL) {
2691 //then register Recon
2692 aReconEvent = new ReconEvent();
2693 sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
2694 if(sc!=StatusCode::SUCCESS) {
2695 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
2696 return StatusCode::FAILURE;
2697 }
2698 }
2699
2700 //clear MdcFastTrk
2701 SmartIF<IDataManagerSvc> dataManagerSvc(eventSvc());
2702 DataObject *aRecMdcTrack;
2703 eventSvc()->findObject("/Event/Recon/RecMdcTrackCol",aRecMdcTrack);
2704 if(aRecMdcTrack!=NULL){
2705 dataManagerSvc->clearSubTree("/Event/Recon/RecMdcTrackCol");
2706 eventSvc()->unregisterObject("/Event/Recon/RecMdcTrackCol");
2707 }
2708
2709 if(tEst<0){
2710 return StatusCode::SUCCESS;
2711 }
2712
2713 //clear RecEsTimeCol
2714 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
2715 DataObject *aRecEsTime;
2716 eventSvc()->findObject("/Event/Recon/RecEsTimeCol",aRecEsTime);
2717 if(aRecEsTime!=NULL){
2718 dataManSvc->clearSubTree("/Event/Recon/RecEsTimeCol");
2719 eventSvc()->unregisterObject("/Event/Recon/RecEsTimeCol");
2720 }
2721
2722 // register event start time to TDS
2723 RecEsTimeCol *aRecEsTimeCol = new RecEsTimeCol;
2724 sc = eventSvc()->registerObject("/Event/Recon/RecEsTimeCol", aRecEsTimeCol);
2725 if(sc!=StatusCode::SUCCESS) {
2726 log << MSG::ERROR << "Could not register RecEsTimeCol" << endreq;
2727 return StatusCode::FAILURE;
2728 }
2729
2730 RecEsTime *arecestime = new RecEsTime;
2731 arecestime->setTest(tEst);
2732 arecestime->setStat(tEstFlag);
2733 arecestime->setQuality(quality);
2734 aRecEsTimeCol->push_back(arecestime);
2735
2736 return StatusCode::SUCCESS;
2737 }
2738
2739 double EsTimeAlg::Opt_new(const double *arr,const int size,const double sigma_cut)
2740 {
2741 Vdouble t0v_mdc;
2742 t0v_mdc.clear();
2743 double mean=-999;
2744 double sigma=9999;
2745 for(int i=0;i<size;i++){t0v_mdc.push_back(arr[i]);}
2746 if(size==0) mean=-999;
2747 if(size==1) mean=t0v_mdc[0];
2748 if(size==2) mean=0.5*(t0v_mdc[0]+t0v_mdc[1]);
2749 if(size>=3)
2750 {
2751 for(int n=0;n<size;n++){
2752 mean=0.0;
2753 sigma=0.0;
2754 for(int i=0;i<t0v_mdc.size();i++){mean+=t0v_mdc[i];}
2755 mean=mean/t0v_mdc.size();
2756 for(int i=0;i<t0v_mdc.size();i++){sigma+=(t0v_mdc[i]-mean)*(t0v_mdc[i]-mean);}
2757 sigma=sigma/t0v_mdc.size();
2758 if(sigma<sigma_cut) break;
2759 double tmp=fabs(mean-t0v_mdc[0]);
2760 int no=0;
2761 for(int j=0;j<t0v_mdc.size();j++)
2762 {
2763 if(fabs(mean-t0v_mdc[j])>=tmp){no=j;tmp=fabs(mean-t0v_mdc[j]);}
2764 }
2765 t0v_mdc.erase(t0v_mdc.begin()+no);
2766 if(t0v_mdc.size()<=2) break;
2767 }
2768 mean=0.0; for(int i=0;i<t0v_mdc.size();i++){mean+=t0v_mdc[i];}
2769 mean=mean/t0v_mdc.size();
2770 }
2771 return mean;
2772 }
2773
2774 double EsTimeAlg::EST_Trimmer(double t0_original,double t0_offset,double raw_offset,double t0_offset_dt,double bunchTime)
2775 {
2776 int Nbunch = (int)( t0_original - t0_offset - raw_offset )/bunchTime;
2777 if( (t0_original-t0_offset-raw_offset-bunchTime*Nbunch)>(bunchTime/2.) ) { Nbunch=Nbunch+1; }
2778 double t_Est = Nbunch * bunchTime + t0_offset + t0_offset_dt;
2779 return t_Est;
2780 }
double cos(const BesAngle a)
Definition: BesAngle.h:213
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
const int no
TTree * sigma
int runNo
Definition: DQA_TO_DB.cxx:12
@ proton
Definition: DstMdcDedx.h:9
const double VELPROP
Definition: EsTimeAlg.cxx:83
HepGeom::Point3D< double > HepPoint3D
Definition: EsTimeAlg.cxx:59
const double PROTONMAS2
Definition: EsTimeAlg.cxx:78
#define MXTRK
const double MUMAS2
Definition: EsTimeAlg.cxx:76
const double PIMAS2
Definition: EsTimeAlg.cxx:77
const double ELMAS2
Definition: EsTimeAlg.cxx:75
const double VLIGHT
Definition: EsTimeAlg.cxx:74
const double PI
Definition: EsTimeAlg.cxx:82
const double RCTOF2
Definition: EsTimeAlg.cxx:79
const double TDC2NSEC
Definition: EsTimeAlg.cxx:81
#define MXTKHIT
#define MXWIRE
std::vector< double > Vdouble
Definition: EsTimeAlg.cxx:67
const double PIBY44
Definition: EsTimeAlg.cxx:82
const double RCEMC2
Definition: EsTimeAlg.cxx:80
const double NSEC2TDC
Definition: EsTimeAlg.cxx:81
const double alpha
std::vector< double > Vdouble
Definition: Gam4pikp.cxx:54
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition: KKsem.h:33
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
Definition: KarFin.h:34
int eventNo
ObjectVector< RecEsTime > RecEsTimeCol
Definition: RecEsTime.h:53
SmartRefVector< RecMdcHit > HitRefVec
Definition: RecMdcTrack.h:22
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
#define M_PI
Definition: TConstant.h:4
std::vector< TofData * > TofDataVector
Definition: TofData.h:247
IDetVerSvc * detVerSvc
TTree * t
Definition: binning.cxx:23
double Z_emc
Definition: Emc_helix.h:29
double theta_emc
Definition: Emc_helix.h:30
double phi_emc
Definition: Emc_helix.h:31
int Emc_Get(double, int, double[])
Definition: Emc_helix.cxx:67
void pathlCut(double pathl_max)
Definition: Emc_helix.h:45
double offset_dt
Definition: EsTimeAlg.h:56
bool m_useXT
Definition: EsTimeAlg.h:79
int m_optCosmic
Definition: EsTimeAlg.h:48
int m_ntupleflag
Definition: EsTimeAlg.h:45
bool m_useTimeFactor
Definition: EsTimeAlg.h:85
int m_cosmicScheme
Definition: EsTimeAlg.h:49
bool m_useSw
Definition: EsTimeAlg.h:81
double m_bunchtime_MC
Definition: EsTimeAlg.h:44
double m_TofOpt_Cut
Definition: EsTimeAlg.h:84
int m_beforrec
Definition: EsTimeAlg.h:59
double toffset_rawtime_e
Definition: EsTimeAlg.h:55
EsTimeAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EsTimeAlg.cxx:85
double m_ebeam
Definition: EsTimeAlg.h:62
double offset_dt_end
Definition: EsTimeAlg.h:57
int m_userawtime_opt
Definition: EsTimeAlg.h:53
bool m_mdcopt
Definition: EsTimeAlg.h:82
StatusCode finalize()
Definition: EsTimeAlg.cxx:2668
bool m_TofOpt
Definition: EsTimeAlg.h:83
int m_phase
Definition: EsTimeAlg.h:52
StatusCode initialize()
Definition: EsTimeAlg.cxx:122
int m_evtNo
Definition: EsTimeAlg.h:61
int m_flag
Definition: EsTimeAlg.h:39
int m_nbunch
Definition: EsTimeAlg.h:42
double toffset_rawtime
Definition: EsTimeAlg.h:54
bool m_useT0cal
Definition: EsTimeAlg.h:80
StatusCode execute()
Definition: EsTimeAlg.cxx:306
int m_debug
Definition: EsTimeAlg.h:58
double pathlCut() const
double ztofCutmin() const
double MDC_Prop() const
double MDC_drCut() const
double ztofCutmax() const
double MDC_dzCut() const
int MDC_Debug() const
double MDC_Tof() const
double vdrift() const
double MDC_Inner() const
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
void ignoreErrorMatrix(void)
unsets error matrix. Error calculations will be ignored after this function call until an error matri...
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
virtual int phase()=0
virtual const double BTime1(double ADC, double TDC, double zHit, unsigned id)=0
virtual const double BTime2(double ADC, double TDC, double zHit, unsigned id)=0
virtual StatusCode chooseConstants(int run, int event)=0
virtual const double ETime(double ADC, double TDC, double rHit, unsigned id)=0
virtual const double EtfTime(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip)=0
virtual const bool ValidInfo()=0
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const MdcGeoWire *const Wire(unsigned id)=0
virtual TofDataVector & tofDataVectorEstime()=0
double distToDriftTime(double dist, int layid, int cellid, int lr, double entrance=0.0) const
double getT0(int layid, int cellid) const
double getTimeWalk(int layid, double Q) const
double Radius(void) const
Definition: MdcGeoLayer.h:160
double PCSiz(void) const
Definition: MdcGeoLayer.h:164
int NCell(void) const
Definition: MdcGeoLayer.h:165
double Slant(void) const
Definition: MdcGeoWire.h:132
HepPoint3D Forward(void) const
Definition: MdcGeoWire.h:129
HepPoint3D Backward(void) const
Definition: MdcGeoWire.h:128
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
double doca(int layer, int cell, const HepVector helix, const HepSymMatrix errMat, bool passCellRequired=true, bool doSag=true) const
static double MdcTime(int timeChannel)
Definition: RawDataUtil.h:8
static double TofTime(unsigned int timeChannel)
Definition: RawDataUtil.h:63
void setStat(int Stat)
Definition: RecEsTime.h:37
void setTest(double Test)
Definition: RecEsTime.h:36
void setQuality(double Quality)
Definition: RecEsTime.h:38
int TofFz_Get(double, int, double[])
Definition: Toffz_helix.cxx:76
double Kappa
Definition: Toffz_helix.h:39
double r_endtof
Definition: Toffz_helix.h:42
double Pathl
Definition: Toffz_helix.h:32
double Path_etf
Definition: Toffz_helix.h:34
double r_etf
Definition: Toffz_helix.h:43
void ztofCut(double ztof_min, double ztof_max)
Definition: Toffz_helix.h:56
void pathlCut(double pathl_max)
Definition: Toffz_helix.h:52
double Tanl
Definition: Toffz_helix.h:39
double Z_tof
Definition: Toffz_helix.h:35
double Z_etf
Definition: Toffz_helix.h:36
static int endcap(const Identifier &id)
Definition: TofID.cxx:124
double x[1000]
Definition: Event.h:21
float charge
void slope()
Definition: slope.cxx:12