170 #include "StFtpcTracker.hh"
171 #include "StFtpcPoint.hh"
172 #include "StFtpcTrack.hh"
174 #include "StMessMgr.h"
202 mHitsCreated = (Bool_t)kFALSE;
203 mVertexCreated = (Bool_t)kFALSE;
204 mTrackCreated = (Bool_t)kFALSE;
215 mBench =
new TBenchmark();
221 mHitsCreated = (Bool_t)kFALSE;
224 mTrack =
new TObjArray(2000);
225 mTrack->SetOwner(kTRUE);
228 mVertexCreated = (Bool_t)kFALSE;
239 mBench =
new TBenchmark();
246 mHitsCreated = (Bool_t) kFALSE;
247 mVertexCreated = (Bool_t) kFALSE;
248 mTrackCreated = (Bool_t) kFALSE;
262 if (mTrack && mTrackCreated) {
264 delete mTrack; mTrack=0;
267 if (mHit && mHitsCreated) {
272 if (mVertex && mVertexCreated) {
273 delete mVertex; mVertex=0;
277 delete mBench; mBench=0;
302 for (Int_t i = 0; i < iterations; i++) {
307 if (hemisphere == 1) {
322 Char_t sector, UChar_t iterations)
325 TObjArray tracks(GetNumberOfTracks());
327 for (Int_t tt = 0; tt < GetNumberOfTracks(); tt++) {
332 if (track->GetSector() == sector) {
335 tracks.AddLast(track);
339 for (Int_t i = 0; i < iterations; i++) {
352 Double_t lowAngle, Double_t highAngle,
353 Double_t lowRadius, Double_t highRadius,
358 TObjArray tracks(GetNumberOfTracks());
360 for (Int_t tt = 0; tt < GetNumberOfTracks(); tt++) {
365 if (track->GetMeanR() >= lowRadius && track->GetMeanR() < highRadius &&
366 track->GetMeanAlpha() >= lowAngle && track->GetMeanAlpha() < highAngle) {
369 tracks.AddLast(track);
373 for (Int_t i = 0; i < iterations; i++) {
390 Double_t total_charge = 0.0 ;
399 Double_t *dedx_arr=0;
401 Int_t *index_arr = 0;
406 Double_t xx, yy, rr, px, py, pz, pp, ftmp;
407 Double_t cos_lambda, cos_alpha;
412 Double_t *weighted=0;
414 Double_t average_dedx;
418 if (StFtpcTrackingParams::Instance()->DebugLevel() < 8) {
419 LOG_DEBUG <<
" No track = " << GetNumberOfTracks() << endm;
420 LOG_DEBUG <<
" max_track = " << StFtpcTrackingParams::Instance()->MaxTrack() << endm;
421 LOG_DEBUG <<
" max_hit = " << StFtpcTrackingParams::Instance()->MaxHit() << endm;
422 LOG_DEBUG <<
" min_hit = " << StFtpcTrackingParams::Instance()->MinHit() << endm;;
423 LOG_DEBUG <<
" ftrunc = " << StFtpcTrackingParams::Instance()->FracTrunc() << endm;
425 LOG_DEBUG <<
" name= (no name), nok = (" << GetNumberOfClusters()
426 <<
"), maxlen = (" << GetNumberOfClusters() <<
")" << endm;
427 LOG_DEBUG <<
" name= (no mane), nok = (" << GetNumberOfTracks()
428 <<
"), maxlen = (" << GetNumberOfTracks() <<
")" << endm;
438 int nMaxHit = StFtpcTrackingParams::Instance()->MaxHit();
439 if (dedx_arrT.GetSize()<nMaxHit) dedx_arrT.Set(nMaxHit);
441 dedx_arr = dedx_arrT.GetArray();;
442 if (index_arrT.GetSize()<nMaxHit) index_arrT.Set(nMaxHit);
443 index_arr = index_arrT.GetArray();
447 for (itrk = 0; itrk < TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack()); itrk++) {
453 for (icluster = 0; icluster < track->GetNumberOfPoints(); icluster++) {
454 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
455 hit_p = hit->GetHitNumber();
458 total_charge += hit->GetCharge();
462 if (StFtpcTrackingParams::Instance()->DebugLevel() < 2 ) {
463 LOG_DEBUG <<
"total_charge = " << total_charge <<
", hit_p = " << hit_p
464 <<
", de = " << hit->GetCharge() << endm;
469 if (all_hit < StFtpcTrackingParams::Instance()->MinHit() || all_hit > StFtpcTrackingParams::Instance()->MaxHit()) {
471 if (StFtpcTrackingParams::Instance()->DebugLevel() < 5) {
472 LOG_DEBUG <<
" number of hits = " << all_hit << endm;
487 for (icluster = 0, ihit = 0; icluster < track->GetNumberOfPoints(); icluster++) {
488 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
489 hit_p = hit->GetHitNumber();
493 if (StFtpcTrackingParams::Instance()->NoAngle() != 0) {
501 rr = TMath::Sqrt(xx*xx + yy*yy);
505 ftmp = (xx*px + yy*py)/pp;
506 cos_lambda = TMath::Sqrt(1. - ftmp*ftmp);
507 ftmp = yy*px - xx*py;
508 cos_alpha = fabs(pz) / TMath::Sqrt(pz*pz + ftmp*ftmp);
511 if (StFtpcTrackingParams::Instance()->DebugLevel() < 2 ) {
512 LOG_DEBUG <<
" ANGLES: dip= "<< 180./3.14159 * TMath::ACos(cos_lambda) <<
"("
513 << cos_lambda <<
"); cross= " << 180./3.14159 * TMath::ACos(cos_alpha)
514 <<
"(" << cos_alpha <<
") [deg]; P=(" << px <<
", " << py <<
", "
518 if ( cos_alpha == 0. || cos_lambda == 0. ) {
519 dedx_arr[ihit] = StFtpcTrackingParams::Instance()->ALargeNumber();
523 dedx_arr[ihit] = hit->GetCharge() * cos_alpha*cos_lambda;
525 if(dedx_arr[ihit]<0) {
526 LOG_DEBUG << dedx_arr[ihit] <<
" " << hit->GetCharge()
527 <<
" " << cos_alpha <<
" " << cos_lambda << endm;
537 Sorter(dedx_arr, index_arr, all_hit);
543 for (ihit = 0; ihit < (Int_t)(all_hit*StFtpcTrackingParams::Instance()->FracTrunc()); ihit++) {
545 dedx_mean += dedx_arr[ihit];
548 if (acc_hit < 1)
continue;
550 dedx_mean /= (Double_t)acc_hit;
553 track->SetdEdx(dedx_mean);
554 track->SetNumdEdxHits(acc_hit);
556 if(track->GetdEdx() == 0) {
557 LOG_DEBUG <<
"track " << itrk <<
" dedx " << track->GetdEdx()
558 <<
" ndedx " << track->GetNumdEdxHits() << endm;
565 if(StFtpcTrackingParams::Instance()->IdMethod() == 1) {
566 LOG_DEBUG <<
"Using truncated mean over whole chamber method by R. Witt." << endm;
567 int nClusters = GetNumberOfClusters();
568 if (weightedT.GetSize() <nClusters) weightedT.Set(nClusters);
569 weighted =weightedT.GetArray();
570 if (index_arrT.GetSize()<nClusters) index_arrT.Set(nClusters);
571 index_arr = index_arrT.GetArray();
573 weightedT.Reset();index_arrT.Reset(-2);
577 for (itrk = 0; itrk < TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack()); itrk++) {
584 average_dedx += track->GetdEdx();
586 for (icluster = 0; icluster < track->GetNumberOfPoints(); icluster++) {
587 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
588 hit_p = hit->GetHitNumber();
592 if (StFtpcTrackingParams::Instance()->NoAngle() != 0) {
600 rr = TMath::Sqrt(xx*xx + yy*yy);
604 ftmp = (xx*px + yy*py)/pp;
605 cos_lambda = TMath::Sqrt(1. - ftmp*ftmp);
606 ftmp = yy*px - xx*py;
607 cos_alpha = fabs(pz) / TMath::Sqrt(pz*pz + ftmp*ftmp);
610 if (cos_alpha == 0. || cos_lambda == 0.) {
611 weighted[hit_p] = StFtpcTrackingParams::Instance()->ALargeNumber();
615 weighted[hit_p] = hit->GetCharge() * cos_alpha*cos_lambda / track->GetdEdx();
618 index_arr[hit_p] = hit_p;
623 average_dedx /= TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack());
625 Sorter(weighted, index_arr, GetNumberOfClusters());
628 n_untracked = GetNumberOfClusters() - n_tracked;
630 for(ihit = 0; ihit < GetNumberOfClusters(); ihit++) {
632 if(index_arr[ihit]>=0) {
634 if(ihit >= (n_untracked +(Int_t)(StFtpcTrackingParams::Instance()->FracTrunc()*(Double_t) n_tracked))) {
640 for (itrk = 0; itrk < TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack()); itrk++) {
646 for (icluster=0; icluster<track->GetNumberOfPoints(); icluster++) {
655 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
656 hit_p = hit->GetHitNumber();
660 for(ihit=n_untracked; ihit<GetNumberOfClusters(); ihit++) {
662 if(hit_p == index_arr[ihit]) {
665 if (StFtpcTrackingParams::Instance()->NoAngle() != 0) {
673 rr = TMath::Sqrt(xx*xx + yy*yy);
677 ftmp = (xx*px+yy*py)/pp;
678 cos_lambda = TMath::Sqrt(1. - ftmp*ftmp);
680 cos_alpha = fabs(pz) / TMath::Sqrt(pz*pz + ftmp*ftmp);
683 if (cos_alpha == 0. || cos_lambda == 0.) {
688 dedx_mean += hit->GetCharge() * cos_alpha*cos_lambda;
695 if (acc_hit < 1)
continue;
697 dedx_mean /= (Double_t)acc_hit;
698 track->SetdEdx(dedx_mean);
699 track->SetNumdEdxHits(acc_hit);
704 if (StFtpcTrackingParams::Instance()->DebugLevel() < 11) {
705 LOG_DEBUG <<
" total charges in 2 FTPCs " << total_charge << endm;
706 LOG_DEBUG <<
" processed tracks = " << itrk_ok << endm;
724 for (i=0; i<len-2; ++i) {
726 for (j = len-1; j > i; --j) {
728 if (arr[i] > arr[j]) {
749 for (Int_t i=0; i<mTrack->GetEntriesFast(); i++) {
751 track->Fit(mVertex, mMaxDca, primary_fit);
762 Int_t StFtpcTracker::FitAnddEdx(Bool_t primary_fit)
765 mBench->Start(
"fit");
771 Double_t total_charge = 0.0 ;
780 Double_t *dedx_arr=0;
787 Double_t xx, yy, rr, px, py, pz, pp, ftmp;
788 Double_t cos_lambda, cos_alpha;
794 Double_t *weighted=0;
795 Double_t average_dedx;
804 int nMaxHit = StFtpcTrackingParams::Instance()->MaxHit();
805 if (dedx_arrT.GetSize()<nMaxHit) dedx_arrT.Set(nMaxHit);
807 dedx_arr = dedx_arrT.GetArray();;
808 if (index_arrT.GetSize()<nMaxHit) index_arrT.Set(nMaxHit);
809 index_arr = index_arrT.GetArray();
813 for (itrk = 0; itrk < TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack()); itrk++) {
816 track->Fit(mVertex, mMaxDca, primary_fit);
819 for (icluster = 0; icluster < track->GetNumberOfPoints(); icluster++) {
820 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
821 hit_p = hit->GetHitNumber();
824 total_charge += hit->GetCharge();
830 if (all_hit < StFtpcTrackingParams::Instance()->MinHit() || all_hit > StFtpcTrackingParams::Instance()->MaxHit()) {
841 if (pp<1.e-3)
continue;
844 for (icluster = 0, ihit = 0; icluster < track->GetNumberOfPoints(); icluster++) {
845 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
846 hit_p = hit->GetHitNumber();
850 if (StFtpcTrackingParams::Instance()->NoAngle() != 0) {
858 rr = TMath::Sqrt(xx*xx + yy*yy);
862 ftmp = (xx*px + yy*py)/pp;
863 cos_lambda = TMath::Sqrt(1. - ftmp*ftmp);
864 ftmp = yy*px - xx*py;
865 cos_alpha = fabs(pz) / TMath::Sqrt(pz*pz + ftmp*ftmp);
868 if ( cos_alpha == 0. || cos_lambda == 0. ) {
869 dedx_arr[ihit] = StFtpcTrackingParams::Instance()->ALargeNumber();
873 dedx_arr[ihit] = hit->GetCharge() * cos_alpha*cos_lambda;
882 Sorter(dedx_arr, index_arr, all_hit);
888 for (ihit = 0; ihit < (Int_t)(all_hit*StFtpcTrackingParams::Instance()->FracTrunc()); ihit++) {
890 dedx_mean += dedx_arr[ihit];
893 if (acc_hit < 1)
continue;
895 dedx_mean /= (Double_t)acc_hit;
898 track->SetdEdx(dedx_mean);
899 track->SetNumdEdxHits(acc_hit);
903 if (itrk > GetNumberOfTracks()) {
909 if(StFtpcTrackingParams::Instance()->IdMethod() == 1) {
910 LOG_DEBUG <<
"Using truncated mean over whole chamber method by R. Witt." << endm;
911 int nClusters=GetNumberOfClusters();
912 if (weightedT.GetSize()<nClusters) weightedT.Set(nClusters);
913 weighted = weightedT.GetArray();
914 if (index_arrT.GetSize()<nClusters) index_arrT.Set(nClusters);
915 index_arr = index_arrT.GetArray();
917 for(ihit=0; ihit<GetNumberOfClusters(); ihit++) {
919 index_arr[ihit] = -2;
924 for (itrk = 0; itrk < TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack()); itrk++) {
930 if (pp <1.e-3)
continue;
931 average_dedx += track->GetdEdx();
933 for (icluster = 0; icluster < track->GetNumberOfPoints(); icluster++) {
934 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
935 hit_p = hit->GetHitNumber();
939 if (StFtpcTrackingParams::Instance()->NoAngle() != 0) {
947 rr = TMath::Sqrt(xx*xx + yy*yy);
951 ftmp = (xx*px + yy*py)/pp;
952 cos_lambda = TMath::Sqrt(1. - ftmp*ftmp);
953 ftmp = yy*px - xx*py;
954 cos_alpha = fabs(pz) / TMath::Sqrt(pz*pz + ftmp*ftmp);
957 if (cos_alpha == 0. || cos_lambda == 0.) {
958 weighted[hit_p] = StFtpcTrackingParams::Instance()->ALargeNumber();
962 weighted[hit_p] = hit->GetCharge() * cos_alpha*cos_lambda / track->GetdEdx();
965 index_arr[hit_p] = hit_p;
970 if (average_dedx) average_dedx /= TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack());
972 Sorter(weighted, index_arr, GetNumberOfClusters());
975 n_untracked = GetNumberOfClusters() - n_tracked;
977 for(ihit = 0; ihit < GetNumberOfClusters(); ihit++) {
979 if(index_arr[ihit]>=0) {
981 if(ihit >= (n_untracked +(Int_t)(StFtpcTrackingParams::Instance()->FracTrunc()*(Double_t) n_tracked))) {
987 for (itrk = 0; itrk < TMath::Min(GetNumberOfTracks(), StFtpcTrackingParams::Instance()->MaxTrack()); itrk++) {
993 for (icluster=0; icluster<track->GetNumberOfPoints(); icluster++) {
1001 if (pp <1.E-3)
continue;
1002 hit = (
StFtpcPoint*)((TObjArray*)track->GetHits())->At(icluster);
1003 hit_p = hit->GetHitNumber();
1007 for(ihit=n_untracked; ihit<GetNumberOfClusters(); ihit++) {
1009 if(hit_p == index_arr[ihit]) {
1012 if (StFtpcTrackingParams::Instance()->NoAngle() != 0) {
1020 rr = TMath::Sqrt(xx*xx + yy*yy);
1024 ftmp = (xx*px+yy*py)/pp;
1025 cos_lambda = TMath::Sqrt(1. - ftmp*ftmp);
1027 cos_alpha = fabs(pz) / TMath::Sqrt(pz*pz + ftmp*ftmp);
1030 if (cos_alpha == 0. || cos_lambda == 0.) {
1035 dedx_mean += hit->GetCharge() * cos_alpha*cos_lambda;
1046 dedx_mean /= (Double_t)acc_hit;
1047 track->SetdEdx(dedx_mean);
1048 track->SetNumdEdxHits(acc_hit);
1055 mBench->Stop(
"fit");
1056 LOG_DEBUG <<
"Fit and dE/dx calc. finished (" << mBench->GetCpuTime(
"fit") <<
" s)." << endm;
1057 mTime += mBench->GetCpuTime(
"fit");
1066 mBench->Stop(
"fit");
1067 LOG_DEBUG <<
"Fit, dE/dx, writing finished (" << mBench->GetCpuTime(
"fit") <<
" s)." << endm;
1068 mTime += mBench->GetCpuTime(
"fit");
1071 LOG_WARN <<
"Tracks not written (No tracks found!)." << endm;
Int_t Fit(Bool_t primary_fit)
StFtpcTracker()
Default constructor. Sets the pointers to 0 an cut for momentum fit loosely.
virtual ~StFtpcTracker()
Destructor.
void EstimateVertex(StFtpcVertex *vertex, UChar_t iterations=1)
Vertex estimation with fit tracks for FTPC east and west.
void Sorter(Double_t *arr, Int_t *index, Int_t len)