19 #include "StPhysicalHelix.hh"
20 #include "StThreeVector.hh"
21 #include "StThreeVectorF.hh"
22 #include "PhysicalConstants.h"
23 #include "SystemOfUnits.h"
24 #include "StTrackDefinitions.h"
25 #include "StTrackMethod.h"
26 #include "StDedxMethod.h"
29 #include "StPrimaryVertex.h"
30 #include "StEventTypes.h"
31 #include "StDetectorId.h"
35 #include "StFtpcPoint.hh"
36 #include "StFtpcTrack.hh"
37 #include "StFtpcTrackingParams.hh"
38 #include "TObjArray.h"
40 #include "StFtpcTrackToStEvent.hh"
42 StFtpcTrackToStEvent::StFtpcTrackToStEvent() : mEvent(0), mTrackStore(0), mTrkNodeMap() {
46 unsigned short bit = 1 << ftpcConformal;
47 mStiEncoded = kHelix2StepId + bit;
50 StFtpcTrackToStEvent::~StFtpcTrackToStEvent()
87 LOG_WARN <<
"StFtpcTrackToStEvent::FillEvent(). ERROR:"
88 <<
"Null StEvent ("<<e<<
") || TObjArray of tracks ("<<t<<
"). Exit"<<endm;
95 StSPtrVecTrackNode& trNodeVec = mEvent->trackNodes();
96 StSPtrVecTrackDetectorInfo& detInfoVec = mEvent->trackDetectorInfo();
99 int fillTrackCount1=0;
100 int fillTrackCount2=0;
102 int currentTrackKey = GetHighestTrackKey(trNodeVec);
104 for (Int_t trackIt = 0; trackIt < mTrackStore->GetEntriesFast();++trackIt) {
107 if (kTrack->GetP()<=1e-6)
continue;
109 FillDetectorInfo(detInfo, kTrack, kTRUE);
117 FillTrack(gTrack, kTrack);
119 detInfoVec.push_back(detInfo);
120 gTrack->setDetectorInfo(detInfo);
121 gTrack->setKey(++currentTrackKey);
122 trackNode->addTrack(gTrack);
123 trNodeVec.push_back(trackNode);
124 FillTopologyMap(gTrack, kTrack);
125 mTrkNodeMap.insert(map<StFtpcTrack*,StTrackNode*>::value_type (kTrack, trNodeVec.back()));
126 if (trackNode->entries(global)<1) {
127 LOG_WARN <<
"StFtpcTrackToStEvent::FillEvent() - ERROR - Track Node has no entries!" << endm;
133 catch (runtime_error & rte ) {
134 LOG_WARN <<
"StFtpcTrackToStEvent::FillEvent() -W- runtime-e filling track"<<rte.what() << endm;
141 LOG_WARN <<
"StFtpcTrackToStEvent::FillEvent() - WARNING - Unknown exception filling track."<<endm;
149 LOG_WARN <<
"There were "<<errorCount<<
"runtime_errors while filling StEvent"<<endm;
156 StEvent* StFtpcTrackToStEvent::FillEventPrimaries(
StEvent* e, TObjArray* t) {
158 if (!mTrkNodeMap.size()) {
159 LOG_WARN <<
"StFtpcTrackToStEvent::FillEventPrimaries(): "
160 <<
"Mapping between the StTrackNodes and the StFtpcTracks is empty. Exit." << endm;
165 LOG_WARN <<
"StFtpcTrackToStEvent::FillEventPrimaries(): "
166 <<
"Null StEvent ("<<e<<
") || TObjArray of tracks ("<<t<<
"). Exit"<<endm;
173 StSPtrVecTrackDetectorInfo& detInfoVec = mEvent->trackDetectorInfo();
176 LOG_WARN <<
"Failed to find a primary vertex. No primary FTPC tracks written to StEvent."<<endm;
185 int fillTrackCount1=0;
186 int fillTrackCount2=0;
188 for (Int_t trackIt = 0; trackIt<mTrackStore->GetEntriesFast();++trackIt,++mTrackN) {
193 throw runtime_error(
"StFtpcTrackToStEvent::FillEventPrimaries() -F- (StFtpcTrack*)mTrackStore->At(trackIt)");
196 map<StFtpcTrack*, StTrackNode*>::iterator itKtrack = mTrkNodeMap.find(kTrack);
198 if (itKtrack == mTrkNodeMap.end()) {
203 StTrackNode* currentTrackNode = (*itKtrack).second;
206 if (kTrack->ComesFromMainVertex()) {
210 if (currentTrackNode->entries()>10) {
211 throw runtime_error(
"StFtpcTrackToStEvent::FillEventPrimaries() -F- currentTrackNode->entries()>10");
214 if (currentTrackNode->entries(global)<1) {
215 throw runtime_error(
"StFtpcTrackToStEvent::FillEventPrimaries() -F- currentTrackNode->entries(global)<1");
220 FillDetectorInfo(detInfo, kTrack, kFALSE);
224 FillTrack(pTrack, kTrack);
226 detInfoVec.push_back(detInfo);
227 pTrack->setDetectorInfo(detInfo);
228 pTrack->setKey(currentGlobalTrack->key());
229 currentTrackNode->addTrack(pTrack);
230 vertex->addDaughter(pTrack);
231 FillTopologyMap(pTrack, kTrack);
235 catch (runtime_error & rte ) {
236 LOG_WARN <<
"StFtpcTrackToStEvent::FillEventPrimaries() - runtime exception, filling track: "
237 << rte.what() << endm;
243 LOG_WARN <<
"StFtpcTrackToStEvent::FillEventPrimaries() - Unknown exception, filling track."<<endm;
250 if (skippedCount>0) LOG_WARN <<
"StFtpcTrackToStEvent::FillEventPrimaries() -I- A total of "<<skippedCount<<
" StFtpcTracks were skipped"<<endm;
258 TObjArray *hitVec = track->GetHits();
260 detInfo->setFirstPoint(((
StFtpcPoint*)hitVec->Last())->GetStFtpcHit()->position());
261 detInfo->setLastPoint(((
StFtpcPoint*)hitVec->First())->GetStFtpcHit()->position());
262 detInfo->setNumberOfPoints(EncodedStEventFitPoints(track), track->GetDetectorId());
264 for (Int_t iHit = hitVec->GetEntriesFast()-1; iHit >= 0; iHit--) {
266 StHit *hh =
dynamic_cast<StHit*
>(pt->GetStFtpcHit());
267 if (hh) detInfo->addHit(hh, global);
272 void StFtpcTrackToStEvent::FillGeometry(
StTrack* gTrack,
StFtpcTrack* track,
bool outer) {
275 throw runtime_error(
"StFtpcTrackToStEvent::FillGeometry() -F- gTrack==0");
279 throw runtime_error(
"StFtpcTrackToStEvent::FillGeometry() -F- track==0");
286 hit = track->GetLastPointOnTrack();
290 hit = track->GetFirstPointOnTrack();
294 Double_t r0 = TMath::Sqrt(hit.X()*hit.X() + hit.Y()*hit.Y());
297 Double_t phi0 = TMath::ATan2(hit.Y(), hit.X());
300 Double_t z0 = hit.Z();
303 Double_t psi = TMath::ATan2(track->GetPy(), track->GetPx());
305 psi += 2*TMath::Pi();
308 origin.setX(r0 * TMath::Cos(phi0));
309 origin.setY(r0 * TMath::Sin(phi0));
315 if (!finite(origin.x()) ||
316 !finite(origin.y()) ||
317 !finite(origin.z()) || !finite(track->curvature())) {
318 LOG_ERROR <<
"StFtpcTrackToStEvent::FillGeometry() Encountered non-finite numbers!!!! Bail out completely!!! " << endm;
327 Double_t Ptotal = TMath::Sqrt(track->GetPt()*track->GetPt() + track->GetPz()*track->GetPz());
328 Double_t psiLast = psi + track->
h()*track->curvature()*track->GetTrackLength()*(track->GetPt()/Ptotal);
330 psiLast += 2*TMath::Pi();
333 StThreeVectorF P(track->GetPt() * TMath::Cos(psiLast), track->GetPt() * TMath::Sin(psiLast), track->GetPz());
338 TMath::ATan2(track->GetPz(),(track->GetPt()+1.e-10)),
343 gTrack->setOuterGeometry(geometry);
348 StThreeVectorF P(track->GetPt() * TMath::Cos(psi), track->GetPt() * TMath::Sin(psi), track->GetPz());
353 TMath::ATan2(track->GetPz(),(track->GetPt()+1.e-10)),
358 gTrack->setGeometry(geometry);
368 unsigned short geantIdPidHyp = 9999;
371 unsigned short nFitPoints = EncodedStEventFitPoints(track);
375 chi2[0] = track->GetChiSq()[0]/(nFitPoints-3.);
376 chi2[1] = track->GetChiSq()[1]/(nFitPoints-2.);
379 for (Int_t i = 0; i < 15; i++) {
387 fitTraits.setNumberOfFitPoints(nFitPoints, track->GetDetectorId());
388 fitTraits.setPrimaryVertexUsedInFit(gTrack->type() == primary);
389 gTrack->setFitTraits(fitTraits);
396 double dEdx = track->GetdEdx();
397 double errordEdx = 0.;
398 double nPoints = track->GetNumdEdxHits();
401 if (StFtpcTrackingParams::Instance()->IdMethod() == 0) {
402 method = kTruncatedMeanId;
405 else if (StFtpcTrackingParams::Instance()->IdMethod() == 1) {
406 method = kEnsembleTruncatedMeanId;
410 method = kUndefinedMethodId;
413 if(!finite(dEdx) || dEdx>9999) {
417 LOG_WARN <<
"StFtpcTrackToStEvent::Error: dEdx non-finite."<<endm;
420 else if(!finite(errordEdx)) {
424 LOG_WARN <<
"StFtpcTrackToStEvent::Error: errordEdx non-finite."<<endm;
428 static_cast<short>(method),
429 static_cast<unsigned short>(nPoints),
430 static_cast<float>(dEdx),
431 static_cast<float>(errordEdx));
432 gTrack->addPidTraits(pidTrait);
439 FilldEdxInfo(gTrack, track);
447 if (gTrack->type()==global) {
450 if (track->ComesFromMainVertex()) {
454 if (TMath::Abs(track->GetCharge()) != 1.) {
458 if (TMath::Abs(track->GetPt()) < 1.e-3) {
462 gTrack->setFlag(flag);
465 else if (gTrack->type()==primary) {
466 gTrack->setFlag(801);
469 gTrack->setEncodedMethod(mStiEncoded);
471 gTrack->setImpactParameter(ImpactParameter(track));
472 gTrack->setLength(track->GetTrackLength());
473 gTrack->setNumberOfPossiblePoints(static_cast<unsigned short>(track->GetNMax()), track->GetDetectorId());
475 FillGeometry(gTrack, track,
false);
476 FillGeometry(gTrack, track,
true);
477 FillFitTraits(gTrack, track);
478 FillPidTraits(gTrack, track);
483 unsigned short StFtpcTrackToStEvent::EncodedStEventFitPoints(
StFtpcTrack* track) {
488 return ((
unsigned short)track->GetHits()->GetEntriesFast());
492 float StFtpcTrackToStEvent::ImpactParameter(
StFtpcTrack* track) {
494 if (!mEvent->primaryVertex()) {
499 return track->GetDca();
505 unsigned long word0 = (gTrack->type()==primary) ? 1 : 0;
506 unsigned long word1 = (1<<31);
508 for (Int_t i = 0; i < ftpcTrack->GetHits()->GetEntriesFast(); i++){
510 word0 |= (1<<pt->GetPadRow());
514 gTrack->setTopologyMap(newmap);
520 int StFtpcTrackToStEvent::GetHighestTrackKey(StSPtrVecTrackNode& trNodeVec) {
527 Int_t highestKey = 0;
528 Int_t currentKey = 0;
530 for (
unsigned int j = 0; j < trNodeVec.size(); j++) {
531 globTrack = trNodeVec[j]->track(global);
532 if (globTrack==0)
continue;
534 currentKey = globTrack->key();
535 if (currentKey > highestKey) highestKey = currentKey;
StEvent * FillEvent(StEvent *, TObjArray *)
int h() const
y-center of circle in xy-plane