70 MsgStream log(
msgSvc(), name());
71 log << MSG::INFO <<
"in execute()" << endreq;
73 int numOfChargedTrks = 0;
79 int numOfMatchedShower = 0;
83 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
86 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
87 return( StatusCode::FAILURE);
89 log << MSG::INFO <<
": retrieved event: " << eventHeader->eventNumber() <<
" run: " << eventHeader->runNumber() << endreq;
93 RecMdcTrackCol::iterator beginOfMdcTrkCol = RecMdcTrackCol::iterator(NULL);
96 log<<MSG::INFO<<
"Could not find RecMdcTrackCol!"<<endreq;
100 beginOfMdcTrkCol = recMdcTrackCol->begin();
101 numOfChargedTrks = recMdcTrackCol->size();
105 RecMdcKalTrackCol::iterator beginOfMdcKalTrackCol = RecMdcKalTrackCol::iterator(NULL);
108 log<<MSG::INFO<<
"Could not find MdcKalTrackCol!"<<endreq;
112 numOfKalTrks = mdcKalTrackCol->size();
113 beginOfMdcKalTrackCol = mdcKalTrackCol->begin();
118 RecMdcDedxCol::iterator beginOfDedxCol = RecMdcDedxCol::iterator(NULL);
121 log<<MSG::INFO<<
"Could not find MdcDedxCol!"<<endreq;
124 numOfDedx = mdcDedxCol->size();
125 beginOfDedxCol = mdcDedxCol->begin();
130 RecExtTrackCol::iterator beginOfExtTrackCol = RecExtTrackCol::iterator(NULL);
133 log<<MSG::INFO<<
"Could not find RecExtTrackCol!"<<endreq;
137 beginOfExtTrackCol = extTrackCol->begin();
138 numOfExt = extTrackCol->size();
142 RecTofTrackCol::iterator beginOfTofTrackCol = RecTofTrackCol::iterator(NULL);
145 log<<MSG::INFO<<
"Could not find RecTofTrackCol!"<<endreq;
149 beginOfTofTrackCol = TofTrackCol->begin();
150 numOfTof = TofTrackCol->size();
154 RecEmcShowerCol::iterator beginOfEmcTrackCol = RecEmcShowerCol::iterator(NULL);
157 log<<MSG::INFO<<
"Could not find RecEmcShowerCol!"<<endreq;
161 beginOfEmcTrackCol = emcRecShowerCol->begin();
162 numOfShower = emcRecShowerCol->size();
166 RecMucTrackCol::iterator beginOfMucTrackCol = RecMucTrackCol::iterator(NULL);
169 log<<MSG::INFO<<
"Could not find RecMucTrackCol!"<<endreq;
173 beginOfMucTrackCol = mucTrackCol->begin();
174 numOfMucTrks = mucTrackCol->size();
179 int MaxHit = numOfChargedTrks+numOfShower+numOfTof;
181 vector<bool> dEdxMatched;
182 vector<bool> kalTrkMatched;
183 vector<bool> extMatched;
184 vector<bool> TofMatched;
185 vector<bool> emcMatched;
186 vector<bool> mucMatched;
188 for(
int i=0;i<MaxHit;i++)
190 dEdxMatched.push_back(
false);
191 kalTrkMatched.push_back(
false);
192 extMatched.push_back(
false);
193 TofMatched.push_back(
false);
194 emcMatched.push_back(
false);
195 mucMatched.push_back(
false);
202 if(numOfChargedTrks+numOfShower)
204 for(
int i=0;i<numOfChargedTrks;i++)
207 int mdcTrkID = (*(beginOfMdcTrkCol+i))->trackId();
209 aNewEvtRecTrack->
setMdcTrack(*(beginOfMdcTrkCol+i));
211 for(
int j=0;j<numOfKalTrks;j++)
212 if( !kalTrkMatched[j] && mdcTrkID==(*(beginOfMdcKalTrackCol+j))->trackId() )
216 kalTrkMatched[j]=
true;
219 for(
int j=0;j<numOfDedx;j++)
220 if( !dEdxMatched[j] && mdcTrkID==(*(beginOfDedxCol+j))->trackId() )
222 aNewEvtRecTrack->
setMdcDedx(*(beginOfDedxCol+j));
227 for(
int j=0;j<numOfExt;j++)
228 if( !extMatched[j] && mdcTrkID==(*(beginOfExtTrackCol+j))->trackId() )
230 aNewEvtRecTrack->
setExtTrack(*(beginOfExtTrackCol+j));
234 for(
int j=0;j<numOfTof;j++)
235 if( !TofMatched[j] && mdcTrkID==(*(beginOfTofTrackCol+j))->trackID() )
237 aNewEvtRecTrack->
addTofTrack(*(beginOfTofTrackCol+j));
241 for(
int j=0;j<numOfMucTrks;j++)
242 if( !mucMatched[j] && mdcTrkID==(*(beginOfMucTrackCol+j))->trackId() )
244 aNewEvtRecTrack->
setMucTrack(*(beginOfMucTrackCol+j));
252 myEnergyMatched = -1.;
256 if(m_Output==1)myExted = 1.;
258 Hep3Vector extPos = (aNewEvtRecTrack->
extTrack())->emcPosition();
259 double extTheta = extPos.theta();
260 double extPhi = extPos.phi();
262 double dAngleMin = 9999.;
263 int indexOfEmcNearest = -1;
265 for(
int j=0;j<numOfShower;j++)
269 HepPoint3D emcPot = (*(beginOfEmcTrackCol+j))->position();
270 Hep3Vector emcPos(emcPot.x(),emcPot.y(),emcPot.z());
271 double dAngle = extPos.angle(emcPos);
275 indexOfEmcNearest = j;
279 if(indexOfEmcNearest>=0)
281 HepPoint3D emcPot = (*(beginOfEmcTrackCol+indexOfEmcNearest))->position();
282 double theta = emcPot.theta();
283 double phi = emcPot.phi();
284 double deltaTheta = (extTheta-theta);
288 double tanLamda = (*(beginOfMdcTrkCol+i))->helix(4);
289 double kappa = (*(beginOfMdcTrkCol+i))->helix(2);
290 double p = sqrt(1+tanLamda*tanLamda)/fabs(kappa);
291 double aThetaCut = thetaCut(p,myEmcThetaNSigmaCut,myParticleId);
292 double aPhiCUt = phiCut(p,myEmcPhiNSigmaCut,myParticleId);
293 if(fabs(deltaTheta)<aThetaCut && fabs(deltaPhi)<aPhiCUt)
295 aNewEvtRecTrack->
setEmcShower(*(beginOfEmcTrackCol+indexOfEmcNearest));
297 emcMatched[indexOfEmcNearest]=
true;
298 numOfMatchedShower++;
299 if(m_Output==1)myMatched = 1.;
302 else if(fabs(deltaTheta)<myEmcThetaCut && fabs(deltaPhi)<myEmcPhiCut)
304 aNewEvtRecTrack->
setEmcShower(*(beginOfEmcTrackCol+indexOfEmcNearest));
306 emcMatched[indexOfEmcNearest]=
true;
307 numOfMatchedShower++;
308 if(m_Output==1)myMatched = 1.;
312 aNewEvtRecTrackCol->push_back(aNewEvtRecTrack);
314 myEnergyMatched = 0.;
320 for(
int i=0;i<numOfShower;i++)
325 aNewEvtRecTrack->
setTrackId(
id+numOfChargedTrks);
330 HepPoint3D emcPos((*(beginOfEmcTrackCol+i))->position());
331 double emcPhi = emcPos.phi();
332 emcPhi = emcPhi < 0 ? emcPhi+CLHEP::twopi : emcPhi;
334 int module=9999, nphi1=9999, nphi2=9999, nphi1_mrpc=9999;
335 module = (*(beginOfEmcTrackCol+i))->module();
337 nphi1 = (int)(emcPhi*88./CLHEP::twopi);
338 nphi2 = (int)(emcPhi*88./CLHEP::twopi+0.5);
341 nphi1 = (int)(emcPhi*48./CLHEP::twopi+0.5);
345 double fi_endtof_mrpc = atan2(emcPos.y(),emcPos.x())-3.141592654/2.;
346 if(fi_endtof_mrpc<0) fi_endtof_mrpc += 2*3.141592654;
347 nphi1_mrpc=((int)(fi_endtof_mrpc/(3.141593/18)))+1;
349 if(nphi1_mrpc%2==0){nphi1_mrpc=nphi1_mrpc/2;}
350 else {nphi1_mrpc=(nphi1_mrpc+1)/2;}
352 if(emcPos.z()>0) {(nphi1_mrpc -= 19); nphi1_mrpc=nphi1_mrpc*(-1);}
358 int partid_dPhiMin = 7;
359 bool mrpcmatch =
false;
361 int indexOfTofNearest = -1;
362 for(
int j=0;j<numOfTof;j++) {
363 if( !TofMatched[j] ) {
365 Identifier id((*(beginOfTofTrackCol+j))->tofID());
375 if(module!=barrel_ec)
continue;
379 dPhi =
abs(im - nphi1);
381 dPhi =
abs(im - nphi2);
384 dPhi = dPhi>=44 ? 88-dPhi : dPhi;
386 dPhi = dPhi>=24 ? 48-dPhi : dPhi;
391 indexOfTofNearest = j;
398 int module_mrpc = (int)im/25;
400 if(module==1)
continue;
401 if(module==0 && (barrel_ec==5 || barrel_ec==6))
continue;
402 if(module==2 && (barrel_ec==3 || barrel_ec==4))
continue;
405 dphi =
abs(module_mrpc-nphi1_mrpc);
410 partid_dPhiMin=barrel_ec;
411 indexOfTofNearest = j;
433 if(indexOfTofNearest>=0) {
434 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
435 double matWindow = 0;
436 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
438 matWindow = 0.01277+0.004268/sqrt(eShower);
443 if(indexOfTofNearest>=0 && dPhiMin<=1) {
445 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
446 double matWindow = 0;
448 matWindow = 0.01277+0.004268/sqrt(eShower);
452 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
453 if(fabs(tofPos.theta()-emcPos.theta())<matWindow || module!=1) {
454 aNewEvtRecTrack->
addTofTrack(*(beginOfTofTrackCol+indexOfTofNearest));
455 TofMatched[indexOfTofNearest]=
true;
461 aNewEvtRecTrackCol->push_back(aNewEvtRecTrack);
468 if(myMsgFlag) cout<<
"Charged tracks: "<<numOfChargedTrks<<
" Ext track: "<<numOfExt <<
" Shower:"<<numOfShower<<
" Matched shower:"<<numOfMatchedShower<<endl;
471 DataObject *aDataObject1;
473 if ( aDataObject1 == NULL ) {
476 if ( sc.isFailure() ) {
477 log << MSG::FATAL <<
"Could not register EvtRecObject in TDS!" << endreq;
478 return StatusCode::FAILURE;
482 DataObject* aDataObject2;
484 if ( aDataObject2 == NULL ) {
486 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
490 if ( sc.isFailure() ) {
491 log << MSG::FATAL <<
"Could not register EvtRecEvent in TDS!" << endreq;
492 return( StatusCode::FAILURE);
497 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
502 DataObject* aDataObject3;
504 if ( aDataObject3 != NULL ) {
506 SmartIF<IDataManagerSvc> dataMgrSvc(eventSvc());
512 if ( sc.isFailure() ) {
513 log << MSG::FATAL <<
"Could not register EvtRecTrackCol in TDS!" << endreq;
514 return( StatusCode::FAILURE);
521 log<<MSG::FATAL<<
"Could not find RecTrackListCol in TDS!"<<endreq;
524 EvtRecTrackCol::iterator itOfRecTrkListCol = evtRecTrackCol->begin();
526 for(
int i=0;itOfRecTrkListCol!=evtRecTrackCol->end();itOfRecTrkListCol++,i++)
528 cout<<
"******************** Track "<<i<<
": *********************"<<endl;
529 cout<<
"Track ID: "<<(*itOfRecTrkListCol)->trackId()<<endl;
530 if((*itOfRecTrkListCol)->isMdcTrackValid())
532 RecMdcTrack* mdcTrk = (*itOfRecTrkListCol)->mdcTrack();
533 double kappa = mdcTrk->
helix(2);
534 double tanl = mdcTrk->
helix(4);
535 cout<<
"Mdc kappa, tanl: "<<kappa<<
", "<<tanl<<endl;
537 if((*itOfRecTrkListCol)->isExtTrackValid())
539 RecExtTrack* extTrack = (*itOfRecTrkListCol)->extTrack();
541 cout<<
"Ext Emc pos:"<<emcPos.x()<<
","<<emcPos.y()<<
","<<emcPos.z()<<endl;
543 if((*itOfRecTrkListCol)->isEmcShowerValid())
545 RecEmcShower* emcTrack = (*itOfRecTrkListCol)->emcShower();
547 double x = emcPos.x();
548 double y = emcPos.y();
549 double z = emcPos.z();
550 cout<<
"Emc rec pos:"<<
x<<
","<<y<<
","<<z<<endl;
554 return StatusCode::SUCCESS;