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