172 MsgStream log(
msgSvc(), name());
173 log << MSG::INFO <<
"in execute()" << endreq;
176 setFilterPassed(
false);
178 SmartDataPtr<Event::EventHeader> evtHead(eventSvc(),
"/Event/EventHeader");
180 log << MSG::FATAL<<
"Could not retrieve event header" << endreq;
181 return StatusCode::FAILURE;
183 long t_runNo = evtHead->runNumber();
184 long t_evtNo = evtHead->eventNumber();
185 if (m_debug) std::cout <<
"sew "<<++i_evt<<
" run "<<t_runNo<<
" evt " << t_evtNo << std::endl;
190 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
191 if (!aevtimeCol || aevtimeCol->size()==0) {
192 log << MSG::WARNING<<
"Could not find RecEsTimeCol"<< endreq;
193 return StatusCode::SUCCESS;
195 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
196 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
197 m_bunchT0 = (*iter_evt)->getTest();
203 if (!recMdcTrackCol || ! recMdcHitCol)
return StatusCode::SUCCESS;
204 if (2!=recMdcTrackCol->size()){
206 return StatusCode::SUCCESS;
208 if(m_debug)std::cout<<name()<<
" nTk==2 begin sewing"<< std::endl;
212 double dParam[5]={0.,0.,0.,0.,0.};
215 RecMdcTrackCol::iterator besthel;
217 int besthelId = -999;
218 RecMdcTrackCol::iterator it = recMdcTrackCol->begin();
219 for (
int iTk=0; it != recMdcTrackCol->end(); it++,iTk++) {
222 double d0 = -tk->
helix(0);
223 double phi0 = tk->
helix(1)+ CLHEP::halfpi;
224 double omega = Bz*tk->
helix(2)/-333.567;
225 double z0 = tk->
helix(3);
226 double tanl = tk->
helix(4);
231 if(m_debug)std::cout<<__FILE__<<
" "<<__LINE__<<
"tk"<<iTk
232 <<
"("<<d0<<
","<<phi0<<
"," <<
","<<omega<<
","<<z0<<
","<<tanl<<
")"<<std::endl;
252 float bchisq = tk->
chi2();
253 int bndof = tk->
ndof();
262 if(besthelId == -999)
return StatusCode::SUCCESS;
269 std::cout<<__FILE__<<
" param diff: " <<
"\n D0 " << dParam[0]
270 <<
"\n Phi0 " << dParam[1] <<
"\n Omega " << dParam[2]
271 <<
"\n Z0 " << dParam[3] <<
"\n Tanl " << dParam[4] << std::endl;
276 m_csmcPhi0=dParam[1];
277 m_csmcOmega=dParam[2];
279 m_csmcTanl=dParam[4];
280 m_xtupleCsmcSew->write();
284 if( (fabs(dParam[0])>m_cosmicSewPar[0]) ||
285 (fabs(dParam[1])>m_cosmicSewPar[1]) ||
286 (fabs(dParam[2])>m_cosmicSewPar[2]) ||
287 (fabs(dParam[3])>m_cosmicSewPar[3]) ||
288 (fabs(dParam[4])>m_cosmicSewPar[4]) ){
289 if(m_debug)std::cout<<__FILE__<<
" 2 trk param not satisfied skip!"<<std::endl;
291 if(fabs(dParam[0])>m_cosmicSewPar[0]) std::cout<<
" cut by d0 "<<std::endl;
292 if(fabs(dParam[1])>m_cosmicSewPar[1]) std::cout<<
" cut by phi0 "<<std::endl;
293 if(fabs(dParam[2])>m_cosmicSewPar[2]) std::cout<<
" cut by omega "<<std::endl;
294 if(fabs(dParam[3])>m_cosmicSewPar[3]) std::cout<<
" cut by z0"<<std::endl;
295 if(fabs(dParam[4])>m_cosmicSewPar[4]) std::cout<<
" cut by tanl"<<std::endl;
298 return StatusCode::SUCCESS;
304 double d0 = -tk->
helix(0);
305 double phi0 = tk->
helix(1)+ CLHEP::halfpi;
306 double omega = Bz*tk->
helix(2)/-333.567;
307 double z0 = tk->
helix(3);
308 double tanl = tk->
helix(4);
311 if(m_debug)std::cout<<__FILE__<<
" best helix: No."<<tk->
trackId()<<
" Pat param=("<<d0<<
" "<<phi0
312 <<
" "<<omega<<
" "<<z0<<
" "<<tanl<<
")"<< std::endl;
318 newTrack = linefactory.
makeTrack(tt, chisum, *m_context, m_bunchT0*1.e-9);
321 newTrack = helixfactory.
makeTrack(tt, chisum, *m_context, m_bunchT0*1.e-9);
328 it = recMdcTrackCol->begin();
329 for (
int iTk=0; it != recMdcTrackCol->end(); it++,iTk++) {
346 if(m_debug)std::cout<<__FILE__<<
" sew fit failed!!!"<< std::endl;
347 HitRefVec::iterator it= skippedHits.begin();
348 for (;it!=skippedHits.end();++it){
delete it->data();}
361 std::cout<<__FILE__<<
" sew cosmic fit good "<< std::endl;
362 newTrack->
print(std::cout);
365 SmartDataPtr<MdcHitCol> m_hitCol(eventSvc(),
"/Event/Hit/MdcHitCol");
368 StatusCode sc = eventSvc()->registerObject(
"/Event/Hit/MdcHitCol",m_hitCol);
369 if(!sc.isSuccess()) {
370 std::cout<<
" Could not register MdcHitCol" <<endreq;
371 return StatusCode::FAILURE;
374 uint32_t getDigiFlag = 0;
376 const MdcDigi* m_digiMap[43][288];
377 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
378 for (;
iter != mdcDigiVec.end();
iter++ ) {
383 m_digiMap[layer][wire] = aDigi;
387 HitRefVec::iterator itHitSkipped = skippedHits.begin();
388 for (;itHitSkipped!=skippedHits.end();++itHitSkipped){
398 double doca = m_mdcUtilitySvc->
docaPatPar(layer,wire,helix,err);
399 double newDoca = fabs(doca);
401 if ( flagLR == 0 ){ newDoca = -fabs(doca); }
403 if(m_debug>=3)std::cout<<
"("<<layer<<
","<<wire<<
") new doca "<<newDoca<<
" resid "<<fabs(fabs(newDoca)-fabs(h->
getDriftDistLeft()))<<std::endl;
407 MdcHit *thehit =
new MdcHit(m_digiMap[layer][wire], m_gm);
411 m_hitCol->push_back(thehit);
414 getInfo(helix,0,poca,tempDir);
415 if(m_debug>3)std::cout<<
"track poca "<<poca<<std::endl;
417 getInfo(helix,docaFltLen,pos,dir);
419 if(pos.y()>poca.y()){
420 int wireAmb = patAmbig(flagLR);
422 double tof = docaFltLen/
Constants::c + (m_bunchT0)*1.e-9;
428 double dist = thehit->
driftDist(tof, wireAmb, eAngle, dAngle, z);
429 double sigma = thehit->
sigma(dist,wireAmb,eAngle,dAngle,z);
431 if(m_debug>3&&fabs(fabs(h->
getDoca())-fabs(dist))>0.02)
433 <<
" new dd "<<dist <<
" newAmbig "<<wireAmb
436 <<
" new sigma "<<
sigma<<
" "<<std::endl;
447 store(newTrack, skippedHits);
449 setFilterPassed(
true);
455 return StatusCode::SUCCESS;
469 SmartDataPtr<MdcHitCol> m_hitCol(eventSvc(),
"/Event/Hit/MdcHitCol");
472 StatusCode sc = eventSvc()->registerObject(
"/Event/Hit/MdcHitCol",m_hitCol);
473 if(!sc.isSuccess()) {
474 std::cout<<
" Could not register MdcHitCol" <<endreq;
480 uint32_t getDigiFlag = 0;
482 if (0 == mdcDigiVec.size()){
483 std::cout <<
" No hits in MdcDigiVec" << std::endl;
486 const MdcDigi* m_digiMap[43][288];
487 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
488 for (;
iter != mdcDigiVec.end();
iter++ ) {
493 m_digiMap[layer][wire] = aDigi;
498 getInfo(helix,0,poca,tempDir);
499 if(m_debug>3)std::cout<<
"track poca "<<poca<<std::endl;
501 HitRefVec::iterator itHit = recMdcHits.begin();
502 for (;itHit!=recMdcHits.end();++itHit){
511 if(pos.y()>poca.y()){
514 if(m_debug>3) std::cout<<
" Up track, change sign of fltLen "<<std::endl;
516 int newFlagLR = bes3FlagLR(newAmbig);
518 if(m_cosmicSewSkip && layer<20){
536 skippedHits.push_back(newSkippedHit);
538 MdcHit *thehit =
new MdcHit(m_digiMap[layer][wire], m_gm);
542 m_hitCol->push_back(thehit);
547 if(m_debug>3) std::cout<<name()<<
" ("<<layer<<
","<<wire<<
") fltLen "<<h->
getFltLen()<<
" newFltLen "<<newFltLen<<
" newAmbig "<<newAmbig<<
" pos.y() "<<pos.y()<<std::endl;
556 MsgStream log(
msgSvc(), name());
558 assert (aTrack !=
NULL);
561 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
562 DataObject *aTrackCol;
563 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
564 if(aTrackCol !=
NULL) {
565 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
566 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
569 DataObject *aRecHitCol;
570 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
571 if(aRecHitCol !=
NULL) {
572 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
573 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
580 if(!sc.isSuccess()) {
581 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
589 if(!sc.isSuccess()) {
590 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
593 int trackId = trackList->size() - 1;
595 if(m_debug)std::cout<<__FILE__<<
" "<<__LINE__<<
" STORED"<< std::endl;
600 mdcTrack.
storeTrack(trackId, trackList, hitList, tkStat);
603 RecMdcTrackCol::iterator it = trackList->begin();
606 HitRefVec::iterator itHit = hl.begin();
608 for (;itHit!=hl.end();++itHit){
611 SmartRef<RecMdcHit> refHit(h);
612 hitRefVec.push_back(refHit);
615 if(m_debug) std::cout<<__FILE__<<
" "<<__LINE__<<
"refHit stored "<< ihl<< std::endl;
617 HitRefVec::iterator itHitSkipped = skippedHits.begin();
619 for (;itHitSkipped!=skippedHits.end();++itHitSkipped){
621 (*itHitSkipped)->setTrkId(trackId);
622 hitList->push_back(*itHitSkipped);
623 SmartRef<RecMdcHit> refHitSkipped(*itHitSkipped);
624 hitRefVec.push_back(refHitSkipped);
626 if(m_debug) std::cout<<__FILE__<<
" "<<__LINE__<<
"skippedHits stored "<< iskipped<< std::endl;
627 (*it)->setVecHits(hitRefVec);
629 (*it)->setNhits((*it)->getVecHits().size());
633 if((*it)->helix(2)<0.00001)(*it)->setNdof((*it)->getNhits()-4);
634 else (*it)->setNdof((*it)->getNhits()-5);
636 if(m_debug) std::cout<<__FILE__<<
" "<<__LINE__<<
" stored "<< (*it)->getVecHits().size()<< std::endl;