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;
397 int module_mrpc = TofID::module(
id);
400 dphi =
abs(module_mrpc-nphi1_mrpc);
405 partid_dPhiMin=barrel_ec;
406 indexOfTofNearest = j;
428 if(indexOfTofNearest>=0) {
429 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
430 double matWindow = 0;
431 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
433 matWindow = 0.01277+0.004268/sqrt(eShower);
438 if(indexOfTofNearest>=0 && dPhiMin<=1) {
440 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
441 double matWindow = 0;
443 matWindow = 0.01277+0.004268/sqrt(eShower);
447 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
448 if(fabs(tofPos.theta()-emcPos.theta())<matWindow || module!=1) {
449 aNewEvtRecTrack->
addTofTrack(*(beginOfTofTrackCol+indexOfTofNearest));
450 TofMatched[indexOfTofNearest]=
true;
456 aNewEvtRecTrackCol->push_back(aNewEvtRecTrack);
463 if(myMsgFlag) cout<<
"Charged tracks: "<<numOfChargedTrks<<
" Ext track: "<<numOfExt <<
" Shower:"<<numOfShower<<
" Matched shower:"<<numOfMatchedShower<<endl;
466 DataObject *aDataObject1;
468 if ( aDataObject1 ==
NULL ) {
471 if ( sc.isFailure() ) {
472 log << MSG::FATAL <<
"Could not register EvtRecObject in TDS!" << endreq;
473 return StatusCode::FAILURE;
477 DataObject* aDataObject2;
479 if ( aDataObject2 ==
NULL ) {
481 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
485 if ( sc.isFailure() ) {
486 log << MSG::FATAL <<
"Could not register EvtRecEvent in TDS!" << endreq;
487 return( StatusCode::FAILURE);
492 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
497 DataObject* aDataObject3;
499 if ( aDataObject3 !=
NULL ) {
501 SmartIF<IDataManagerSvc> dataMgrSvc(eventSvc());
507 if ( sc.isFailure() ) {
508 log << MSG::FATAL <<
"Could not register EvtRecTrackCol in TDS!" << endreq;
509 return( StatusCode::FAILURE);
516 log<<MSG::FATAL<<
"Could not find RecTrackListCol in TDS!"<<endreq;
519 EvtRecTrackCol::iterator itOfRecTrkListCol = evtRecTrackCol->begin();
521 for(
int i=0;itOfRecTrkListCol!=evtRecTrackCol->end();itOfRecTrkListCol++,i++)
523 cout<<
"******************** Track "<<i<<
": *********************"<<endl;
524 cout<<
"Track ID: "<<(*itOfRecTrkListCol)->trackId()<<endl;
525 if((*itOfRecTrkListCol)->isMdcTrackValid())
527 RecMdcTrack* mdcTrk = (*itOfRecTrkListCol)->mdcTrack();
528 double kappa = mdcTrk->
helix(2);
529 double tanl = mdcTrk->
helix(4);
530 cout<<
"Mdc kappa, tanl: "<<kappa<<
", "<<tanl<<endl;
532 if((*itOfRecTrkListCol)->isExtTrackValid())
534 RecExtTrack* extTrack = (*itOfRecTrkListCol)->extTrack();
536 cout<<
"Ext Emc pos:"<<emcPos.x()<<
","<<emcPos.y()<<
","<<emcPos.z()<<endl;
538 if((*itOfRecTrkListCol)->isEmcShowerValid())
540 RecEmcShower* emcTrack = (*itOfRecTrkListCol)->emcShower();
542 double x = emcPos.x();
543 double y = emcPos.y();
544 double z = emcPos.z();
545 cout<<
"Emc rec pos:"<<
x<<
","<<
y<<
","<<z<<endl;
549 return StatusCode::SUCCESS;