26 #include "FairRootManager.h"
27 #include "FairRunAna.h"
28 #include "FairRuntimeDb.h"
29 #include "FairGeanePro.h"
30 #include "FairGeaneUtil.h"
31 #include "FairTrackParP.h"
34 #include "TDatabasePDG.h"
38 #include "TClonesArray.h"
45 #define IDEAL false // CHECKING
48 #define THROWAWAY false
130 for(
int iplane = 0; iplane < 8; iplane++) {
140 FairRootManager *ioman = FairRootManager::Instance();
142 cout <<
"-I- -------------------" << endl;
143 cout <<
"-I- PndSttMvdGemTracking: using branches "
148 cout <<
"-I- to change one or more of these use PndSttMvdGemTracking:SetBranchName( TStrings ); the order of TStrings is mvd pixel name, mvd strip name, stt name, gem name" << endl;
151 cout <<
"-I- -------------------" << endl;
156 cout <<
"-E- PndSttMvdGemTracking: "
157 <<
"RootManager not instantised!" << endl;
165 Error(
"PndSttMvdGemTracking:Init",
"stt + mvd trackcand - array not found!");
172 Error(
"PndSttMvdGemTracking:Init",
"stt + mvd track - array not found!");
180 Error(
"PndSttMvdGemTracking:Init",
"stt + mvd trackID - array not found!");
188 Error(
"PndSttMvdGemTracking:Init",
"gem hit - array not found!");
195 Error(
"PndSttMvdGemTracking:Init",
"gem point - array not found!");
202 Error(
"PndSttMvdGemTracking:Init",
"mctrack - array not found!");
209 Error(
"PndSttMvdGemTracking:Init",
"mvd pixel hit - array not found!");
216 Error(
"PndSttMvdGemTracking:Init",
"mvd strip hit - array not found!");
223 Error(
"PndSttMvdGemTracking:Init",
"stt hit - array not found!");
230 Error(
"PndSttMvdGemTracking:Init",
"mvd point - array not found!");
237 Error(
"PndSttMvdGemTracking:Init",
"stt point - array not found!");
249 fPro =
new FairGeanePro();
260 if(
fPdgFromMC) cout <<
"-I- PndSttMvdGemTracking: Taking PDG from MC (keeping backup default opt = " <<
fDefaultPdgCode <<
")" << endl;
261 else cout <<
"-I- PndSttMvdGemTracking: using default PDG " <<
fDefaultPdgCode << endl;
263 cout <<
"-I- PndSttMvdGemTracking: Intialisation successfull" << endl;
270 FairRuntimeDb*
rtdb = FairRun::Instance()->GetRuntimeDb();
284 if(
fVerbose > 0) cout <<
"********* SPndSttMvdGemTracking::SetupGEMPlanes ************" << endl;
291 if(
fVerbose > 0) cout <<
"NSTAT " << nstations << endl;
293 if(nstations == 0) cerr <<
"PndSttMvdGemTracking::SetupGEMPlanes: NO GEOMETRY FOR GEMs!" << endl;
306 for(
int istat = 0; istat < nstations; istat++) {
308 for(
int isens = 0; isens < station->
GetNSensors(); isens++) {
311 posindex = (istat + 1) * 10 + (isens + 1);
313 if(
fVerbose > 0) cout <<
"istat/isens/posindex/ordering " << istat + 1 <<
" " << isens + 1 <<
" " << posindex <<
" " <<
fOrdering.size() <<
" " <<
fOrdering[
fOrdering.size() - 1] << endl;
320 new(clref[size]) TVector3(sensor->
GetX0(), sensor->
GetY0(), sensor->
GetZ0());
326 fDj.SetXYZ(1., 0., 0.);
327 fDk.SetXYZ(0., 1., 0.);
344 TString hname =
"hdist"; hname += ipos;
345 hdist[ipos] =
new TH1F(hname, hname, 200, 0, 100);
347 hdist2[ipos] =
new TH1F(hname, hname, 200, 0, 100);
348 hname =
"hsigma"; hname += ipos;
349 hsigma[ipos] =
new TH1F(hname, hname, 200, 0, 20);
351 hsigma2[ipos] =
new TH1F(hname, hname, 200, 0, 20);
352 hname =
"hchosen"; hname += ipos;
353 hchosen[ipos] =
new TH1F(hname, hname, 200, 0, 100);
355 hchosen2[ipos] =
new TH1F(hname, hname, 200, 0, 100);
356 hname =
"hmcdist"; hname += ipos;
357 hmcdist[ipos] =
new TH1F(hname, hname, 200, 0, 100);
358 hname =
"hmcx"; hname += ipos;
359 hmcx[ipos] =
new TH1F(hname, hname, 200, 0, 100);
360 hname =
"hmcy"; hname += ipos;
361 hmcy[ipos] =
new TH1F(hname, hname, 200, 0, 100);
373 if(
fVerbose > 0) cout <<
"******* PndSttMvdGemTracking::Reset *******" << endl;
376 cout <<
"press any key" << endl;
378 cout <<
"GOING ON" << endl;
380 display =
new TCanvas(
"display",
"display", 0, 0, 800, 500);
385 for(
int istat = 0; istat < nstations; istat++) {
387 for(
int isens = 0; isens < station->
GetNSensors(); isens++) {
390 iposname += ipos; ipostitle += ipos;
394 display->cd(ipos + 1);
h[ipos]->Draw();
406 for(
int ihit = 0; ihit <
nhits; ihit++) {
407 for(
int itrk = 0; itrk < ntracks; itrk++)
distancemap[itrk][ihit] = -1;
418 for(
int ihit = 0; ihit <
nhits; ihit++)
hitmap(ipos, ihit) = -1;
421 if(
fVerbose > 0) cout <<
"npositions/nhits " << fNPositions <<
" " << nhits << endl;
432 if(nhits == 0)
return;
436 for(
int ihit = 0; ihit <
nhits; ihit++) {
441 << hit->GetX() <<
" "
442 << hit->GetY() <<
" "
443 << hit->GetZ() <<
" "
459 if(
fVerbose > 0) cout << posindex <<
" " << idx <<
" " << index << endl;
463 TMarker *gmrk =
new TMarker(hit->GetX(), hit->GetY(), 7);
473 hitmap(index, idx) = ihit;
489 cout <<
"==================== EVENT " <<
evt << endl;
492 <<
" " << FairRootManager::Instance()->GetBranchId(
fGemBranchName)
493 <<
" " << FairRootManager::Instance()->GetBranchId(
fSttBranchName) << endl;
506 cout <<
"stt + mvd track array " << ntracks << endl;
507 cout <<
"gem hits " << nhits << endl;
511 if(ntracks == 0)
return;
520 Reset(nhits, ntracks);
533 for (Int_t itrk = 0; itrk < ntracks; itrk++)
537 if(
fVerbose > 0) cout <<
"----------- TRACK " << itrk <<
"------------" << endl;
543 cout <<
"-W- PndSttMvdGemTracking::Exec: Empty PndTrack at " << itrk << endl;
549 cout <<
"-W- PndSttMvdGemTracking::Exec: Empty PndTrackCand at " << itrk << endl;
555 cout <<
"press any key" << endl;
557 cout <<
"GOING ON, nex track" << endl;
561 Copy(completeCand, completeTrack, sttmvdCand, sttmvd);
565 if(nhits == 0) { flag[itrk] = -1;
continue; }
570 if(lastpar.GetMomentum().Z() > 999990.) { flag[itrk] = -2;
continue; }
571 FairTrackParP *gempar =
new FairTrackParP();
573 if(
fabs(lastpar.GetPosition().X()) > 42. ||
fabs(lastpar.GetPosition().Y()) > 42.) { flag[itrk] = -3;
continue; }
574 if(lastpar.GetMomentum().Mag() < 0.15) {
576 cout <<
"TOO LOW MOMENTUM " << itrk << endl;
577 lastpar.GetPosition().Print();
578 lastpar.GetMomentum().Print();
589 if(lastpar.GetPosition().Z() > sensor->
GetZ0()) {
591 cout <<
"Z OUT OF BOUNDS" << endl;
592 lastpar.GetPosition().
Print();
593 lastpar.GetMomentum().Print();
601 if(
fVerbose > 0) cout <<
"SetParameters for track " << itrk << endl;
604 if (
fabs(tmppar.GetMomentum().Z()) < 1.e-5) {
605 if(
fVerbose > 0) cout <<
" CANNOT PROPAGATE because z mom == 0" << endl;
611 FairTrackParP *gempartest =
new FairTrackParP();
613 if(
fVerbose > 0) cout <<
" CANNOT PROPAGATE " << endl;
621 int charge = tmppar.GetQ();
640 int mccharge = (int) TMath::Sign(1., TDatabasePDG::Instance()->GetParticle(mctrk->
GetPdgCode())->Charge()/3.);
641 if(mccharge != charge &&
fVerbose > 0) cout <<
"WRONG CHARGE " << charge <<
" " << mccharge <<
" " << mctrk->
GetPdgCode() << endl;
657 Int_t closestonfirst = -1;
670 if (prop == kFALSE) {
678 std::vector<int> assignedhits =
AssignHits(itrk, gempar, ipos);
679 for(
size_t ihit = 0; ihit < assignedhits.size(); ihit++)
AddHitToTrack(assignedhits[ihit], itrk);
681 if(closestonfirst == -1) closestonfirst =
GetClosestOnFirst(gempar, ipos, closestdistance);
683 Double_t covMat[15]; gempar->GetCov(covMat);
684 tmppar.SetTrackPar(gempar->GetX(), gempar->GetY(), gempar->GetZ(),
685 gempar->GetPx(), gempar->GetPy(), gempar->GetPz(), gempar->GetQ(),
687 gempar->GetOrigin(), gempar->GetIVer(), gempar->GetJVer(), gempar->GetKVer());
693 distancemap[itrk][closestonfirst] = closestdistance;
700 if(nhits == 0)
return;
719 cout <<
"track " << itrk <<
" has " << nofhits << endl;
720 std::vector<int> hitsoftrack;
722 for(
int ihit = 0; ihit < nofhits; ihit++) cout <<
" " << hitsoftrack[ihit];
732 if(
fVerbose > 0) cout <<
i <<
" ACTUALLY ASSIGNING TRACK " << itrk << endl;
736 for(
size_t j = 0; j < thistrackhits.size(); j++) {
737 int ihit = thistrackhits[j];
739 if(!gemhit)
continue;
740 if(
fVerbose > 0) cout <<
"ACTUALLY add hit " << ihit <<
" to track " << itrk << endl;
746 if(
fVerbose > 0 && completeTrack->
GetRefIndex() != itrk) cout <<
"************** ERROR ****************" << endl;
748 completeTrack->
SetFlag(flag[itrk]);
768 Int_t size = clref.GetEntriesFast();
775 std::vector<PndTrackCandHit> sttmvdhits = sttmvdCand->
GetSortedHits();
776 for(
size_t ihit = 0; ihit < sttmvdCand->
GetNHits(); ihit++) {
787 Int_t size2 = clref2.GetEntriesFast();
791 completeTrack->
SetRefIndex(
"SttMvdGemTrackCand", size);
801 if(!completeCand)
continue;
802 if(
fVerbose > 0) cout <<
"complete cand " << itrk <<
" has nhits " << completeCand->
GetNHits() << endl;
806 for (
size_t ihit = 0; ihit < completeCand->
GetNHits(); ihit++) {
811 if(
fVerbose > 0) cout <<
"iHit " << iHit <<
" detId " << detId <<
"(" << FairRootManager::Instance()->GetBranchId(
fGemBranchName) <<
")" << endl;
812 if(detId != FairRootManager::Instance()->GetBranchId(
fGemBranchName))
continue;
815 if(!gemhit)
continue;
818 Int_t
refIndex = gemhit->GetRefIndex();
822 TMarker *g2mrkb =
new TMarker(gemhit->GetX(), gemhit->GetY(), 30);
827 g2mrkb->SetMarkerSize(2);
828 g2mrkb->SetMarkerColor(1);
829 g2mrkb->Draw(
"SAME");
839 Int_t mcIndex = gempnt->GetTrackID();
846 TMarker *g2mrk =
new TMarker(gemhit->GetX(), gemhit->GetY(), 30);
853 g2mrk->SetMarkerSize(2);
854 if(mcIndex == completeCand->
getMcTrackId()) g2mrk->SetMarkerColor(2);
855 else if (mcIndex != completeCand->
getMcTrackId()) g2mrk->SetMarkerColor(1);
864 std::vector<int> recoTrack;
866 for(
int itrk = 0; itrk < ntracks; itrk++) {
868 if(!completeCand)
continue;
872 for(
int ihit = 0; ihit <
nhits; ihit++) {
874 if(!gemhit)
continue;
875 Int_t
refIndex = gemhit->GetRefIndex();
876 if(refIndex == -1)
continue;
878 if(!gempnt)
continue;
880 Int_t mcIndex = gempnt->GetTrackID();
881 if(mcIndex == -1)
continue;
882 std::vector<int>::iterator recoTrackIter;
883 recoTrackIter = find(recoTrack.begin(), recoTrack.end(), mcIndex);
884 Int_t where= recoTrackIter - recoTrack.begin();
887 std::vector<int> truepoints;
888 if(
fabs(gempnt->GetX() - gemhit->GetX()) < 1 &&
889 fabs(gempnt->GetY() - gemhit->GetY()) < 1) {
890 std::vector<int>::iterator iter;
891 iter = find(truepoints.begin(), truepoints.end(),
refIndex);
892 Int_t where2 = iter - truepoints.begin();
896 std::vector<int>::iterator iter3;
899 if(where != (
int)recoTrack.size() && where2 == (int)truepoints.size() && where3 != (int)
usabletracks.size()) {
904 truepoints.push_back(refIndex);
911 TMarker *gpntmrk =
new TMarker(gempnt->GetX(), gempnt->GetY(), 7);
912 gpntmrk->SetMarkerColor(5);
914 gpntmrk->Draw(
"SAME");
939 for(
int ipnt = 0; ipnt <
fGemPointArray->GetEntriesFast(); ipnt++) {
942 double x0 = pnt->GetX();
943 double y0 = pnt->GetY();
944 double z0 = pnt->GetZ();
947 if(z0 < 116.5) ipos = 0;
948 else if(z0 < 118.) ipos = 1;
949 else if(z0 < 152.4) ipos = 2;
950 else if(z0 < 154) ipos = 3;
951 else if(z0 < 188.4) ipos = 4;
952 else if(z0 < 190) ipos = 5;
954 cout <<
"MC POINT " << x0 <<
" " << y0 <<
" " << z0 <<
" " << pnt->GetTrackID() << endl;
956 TMarker *gpntmrk =
new TMarker(x0, y0, 3);
957 gpntmrk->SetMarkerColor(7);
960 gpntmrk->Draw(
"SAME");
967 cout <<
"SUMMARY OF EVENT" << endl;
968 cout <<
"mvd + stt tracks " <<
fTrackArray->GetEntriesFast() << endl;
969 cout <<
"gem hits " <<
fGemHitArray->GetEntriesFast() << endl;
978 for(
int iplane = 0; iplane < 8; iplane++) cout <<
countplane[iplane] <<
" ";
980 cout <<
"nohit on plane: ";
981 for(
int iplane = 0; iplane < 8; iplane++) cout <<
countnohitonplane[iplane] <<
" ";
983 cout <<
"prop 1 turn: ";
984 for(
int iplane = 0; iplane < 8; iplane++) cout <<
countprop[0][iplane] <<
" ";
986 cout <<
"prop 2 turn: ";
987 for(
int iplane = 0; iplane < 8; iplane++) cout <<
countprop[1][iplane] <<
" ";
995 TVector3 dj = tmppar->GetJVer();
996 TVector3 dk = tmppar->GetKVer();
997 fPro->PropagateFromPlane(dj, dk);
1002 cout <<
"propagation from " << endl;
1003 tmppar->GetPosition().Print();
1004 tmppar->GetMomentum().Print();
1011 if(tmppar->GetPosition().Z() > sensorpos->Z()) {
1012 if(
fVerbose > 0) cout <<
"-> Z OUT OF BOUNDS: backpropagation" << endl;
1013 fPro->setBackProp();
1019 cout <<
"propagation to " << prop << endl;
1020 gempar->GetPosition().Print();
1021 gempar->GetMomentum().Print();
1032 Double_t xc, yc, radius, fitm, fitp;
1037 if(fitm == 0)
return kFALSE;
1039 double Fi = - charge * scos / radius;
1057 double sens_rad = -1;
1059 for(
int istat = 0; istat < nstations; istat++) {
1061 for(
int isens = 0; isens < station->
GetNSensors(); isens++) {
1064 posindex = (istat + 1) * 10 + (isens + 1);
1073 if(
fabs(x) > sens_rad ||
fabs(y) > sens_rad) {
1074 if(
fVerbose > 0) cout <<
"OUT OF SENSOR " << x <<
" " << y <<
" " << sens_rad << endl;
1080 TVector2
v(x0 - xc, y0 - yc);
1082 TVector2
p(x - xc, y - yc);
1084 scos = - charge * Fi * radius;
1085 z = fitm * scos + fitp;
1094 versor[0] /= Distance;
1095 versor[1] /= Distance;
1097 double px = - charge * radius * 0.006 * versor[1];
1098 double py = charge * radius * 0.006 * versor[0];
1105 gempar->SetTrackPar(x, y, z,
1124 if(
fVerbose > 0) cout <<
"FORBID MULTI ASSIGNED HITS : DELETING HITS" << endl;
1126 for(
int ihit = 0; ihit <
nhits; ihit++) {
1133 Int_t trkcounter = 0;
1134 Int_t tmptrack = -1;
1139 for(
int jtrk = 0; jtrk < tracksassociated; jtrk++) {
1144 if(tmptrack != -1) {
1146 if(
fVerbose > 0) cout <<
"hit " << ihit <<
" deleted from track " << tmptrack << endl;
1153 if(
fVerbose > 0) cout <<
"hit " << ihit <<
" deleted from track " << itrk << endl;
1164 if(
fVerbose > 0) cout <<
"ONLY ONE HIT FOR EACH TRACK : DELETING HITS" << endl;
1171 std::vector<double> tmpposdistance;
1172 std::vector<int> tmpposhitindex;
1175 tmpposdistance.push_back(-1);
1176 tmpposhitindex.push_back(-1);
1179 for(
size_t j = 0; j < thistrackhits.size(); j++) {
1180 int ihit = thistrackhits[j];
1183 if(!gemhit)
continue;
1190 if(tmpposdistance[index] == -1){
1192 tmpposhitindex[index] = ihit;
1198 cout <<
"hit " << ihit <<
" and " << tmpposhitindex[index] <<
" on the same plane" << endl;
1199 cout <<
"distance " << ihit <<
" " <<
distancemap[itrk][ihit] << endl;
1200 cout <<
"distance " << tmpposhitindex[index] <<
" " << tmpposdistance[index] << endl;
1203 if(
distancemap[itrk][ihit] < tmpposdistance[index]) {
1208 tmpposhitindex[index] = ihit;
1214 if(
fVerbose > 0) cout << tmpposhitindex[index] <<
" wins" << endl;
1238 cout <<
"PndSttMvdGemTracking::GetTrackIndex " << i <<
" Out Of Bounds" << endl;
1246 std::vector< std::pair<int, int> >::iterator iter;
1248 std::pair<int, int> thispair = *iter;
1249 if(thispair.second != tmphit) {
1250 tmphit = thispair.second;
1253 if(counter == i)
return tmphit;
1256 cout <<
"PndSttMvdGemTracking::GetTrackIndex " << i <<
" Out Of Bounds" << endl;
1283 std::vector< std::pair<int, int> >::iterator iter;
1285 std::pair<int, int> thispair = *iter;
1286 if(thispair.first == itrk) counter++;
1288 if(
fVerbose > 0) std::cout <<
"track " << itrk <<
" has " << counter <<
" hits" << std::endl;
1293 std::pair<int, int> thispair(itrk, ihit);
1295 std::vector<int>::iterator iter;
1299 if(
fVerbose > 0) cout <<
"ADD HIT " << ihit <<
" TO TRK " << itrk << endl;
1304 std::pair<int, int> thispair(itrk, ihit);
1305 std::vector< std::pair<int, int> >::iterator iter;
1308 if(
fVerbose != 0) std::cout <<
"where " << where << std::endl;
1310 std::vector<int>::iterator iter2;
1314 if(
fVerbose > 0) cout <<
"DELETE HIT " << ihit <<
" FROM TRK " << itrk << endl;
1320 std::vector<int> thishittracks;
1321 std::vector< std::pair<int, int> >::iterator iter;
1323 std::pair<int, int> thispair = *iter;
1324 if(thispair.second == ihit) thishittracks.push_back(thispair.first);
1327 std::cout <<
"hit " << ihit <<
" belongs to " << thishittracks.size() <<
" tracks: " ;
1328 for(
size_t j = 0; j < thishittracks.size(); j++) std::cout << thishittracks[j] <<
" ";
1329 std::cout << std::endl;
1331 return thishittracks;
1335 std::vector<int> thistrackhits;
1336 std::vector< std::pair<int, int> >::iterator iter;
1338 std::pair<int, int> thispair = *iter;
1339 if(thispair.first == itrk) thistrackhits.push_back(thispair.second);
1342 std::cout <<
"track " << itrk <<
" has " << thistrackhits.size() <<
" hits: " ;
1343 for(
size_t j = 0; j < thistrackhits.size(); j++) std::cout << thistrackhits[j] <<
" ";
1344 std::cout << std::endl;
1346 return thistrackhits;
1354 std::vector<int>::iterator iter;
1355 for(iter = thistrackhitsonplane.begin(); iter != thistrackhitsonplane.end(); iter++) {
1358 Bool_t hitfound = kFALSE;
1359 for(
int jhit = 0; jhit < hitonsensor; jhit++) {
1360 Int_t hitindex = (int)
hitmap(ipos, jhit);
1362 if(hitindex == ihit) hitfound = kTRUE;
1364 if(hitfound == kFALSE) {
1366 thistrackhitsonplane.erase(iter);
1370 return thistrackhitsonplane;
1383 int posindex = istat * 10 + isens;
1387 if(hit->GetZ() < 117) posindex = 11;
1388 else if(hit->GetZ() < 118) posindex = 12;
1389 else if(hit->GetZ() < 153) posindex = 21;
1390 else if(hit->GetZ() < 154) posindex = 22;
1391 else if(hit->GetZ() < 189) posindex = 31;
1392 else if(hit->GetZ() < 190) posindex = 32;
1407 if(
fVerbose > 0) cout << k <<
" ITRK " << itrk << endl;
1410 Int_t nhitinthistrack = hitvector.size();
1413 if(nhitinthistrack ==
fNPositions) {
if(
fVerbose > 0) cout <<
"all pos filled" << endl;
continue; }
1417 std::vector<int> missingpositions;
1418 for(
int ipos = 0; ipos <
fNPositions; ipos++) missingpositions.push_back(ipos);
1422 std::vector<int>::iterator iter;
1423 for(
size_t i = 0;
i < hitvector.size();
i++) {
1425 if(!gemhit)
continue;
1429 iter = std::find(missingpositions.begin(), missingpositions.end(), ipos);
1430 Int_t where = iter - missingpositions.begin();
1431 if(where != (
int)missingpositions.size()) {
1432 if(
fVerbose > 0) cout <<
"here" << endl;
1433 missingpositions.erase(iter);
1440 for(
size_t i = 0;
i < missingpositions.size();
i++) {
1441 Int_t ipos = missingpositions[
i];
1442 if(
fVerbose > 0) cout <<
"missing position " << ipos << endl;
1449 Int_t tmphitindex = -1;
1450 for(Int_t ihit = 0; ihit <
hitcounter(ipos, 0); ihit++) {
1451 int hitindex = (int)
hitmap(ipos, ihit);
1454 if(!gemhit)
continue;
1460 tmphitindex = hitindex;
1463 if(tmphitindex != -1) {
1465 if(
fVerbose > 0) cout <<
"ADDED " << tmphitindex <<
" TO TRK " << itrk <<
" at distance " << tmpdist << endl;
1474 if(
fVerbose > 0) cout <<
"RETRACKING" << endl;
1482 cout <<
"TRK " << itrk <<
" has hits ";
1483 for(
size_t ihit = 0; ihit < alreadyassociatedhits.size(); ihit++) cout <<
" " << alreadyassociatedhits[ihit];
1491 if(!completeTrack)
continue;
1496 FairTrackParP *gempar =
new FairTrackParP();
1504 if(alreadyassociatedhitsonplane.size() > 1) cout <<
"ERROR!! more than 1 hit on a plane assigned! " << alreadyassociatedhitsonplane.size() << endl;
1509 if (prop == kFALSE) {
1519 std::vector<int> assignedhits =
AssignHits(itrk, gempar, ipos);
1523 if(assignedhits.size() == 0) {
1526 if(alreadyassociatedhitsonplane.size() == 0)
continue;
1528 int oldhit = alreadyassociatedhitsonplane[0];
1529 if(
fVerbose > 0) cout <<
"delete old hit " << oldhit << endl;
1537 if(assignedhits.size() > 1) {
1539 std::vector<int>::iterator iter;
1544 for(iter = assignedhits.begin(); iter != assignedhits.end(); iter++) {
1545 std::vector<int>::iterator iter2;
1547 if(
CHECKCOMBI > 0 &&
fCombiMap[ihit] != 0) { assignedhits.erase(iter); iter--;
continue; }
1549 iter2 = std::find(assignedhits.begin(), assignedhits.end(), tmphit);
1550 int where = iter2 - assignedhits.begin();
1551 if(where != (
int)assignedhits.size()) {
1552 if(
fVerbose > 0) cout <<
"deleting old " << *iter2 << endl;
1553 assignedhits.erase(iter2);
1560 if(
fVerbose > 0) cout <<
"deleting new " << *iter << endl;
1561 assignedhits.erase(iter);
1566 if(assignedhits.size() > 1) cout <<
"ERROR!! still more than 1 hit assigned!" << endl;
1570 std::vector<int>::iterator iter;
1571 iter = std::find(alreadyassociatedhits.begin(), alreadyassociatedhits.end(), assignedhits[0]);
1572 int where = iter - alreadyassociatedhits.begin();
1575 if(where == (
int)alreadyassociatedhits.size()) {
1578 if(alreadyassociatedhitsonplane.size() > 0) {
1580 int oldhit = alreadyassociatedhitsonplane[0];
1581 if(
fVerbose > 0) cout <<
"deleting old hit2 " << oldhit << endl;
1584 if(
fVerbose > 0) cout <<
"adding " << assignedhits[0] <<
" to track " << itrk << endl;
1593 if(!gemhit)
continue;
1598 TMatrixT<double> extrap(5, 1);
1599 extrap[0][0] = gempar->GetQp();
1600 extrap[1][0] = gempar->GetTV();
1601 extrap[2][0] = gempar->GetTW();
1602 extrap[3][0] = gempar->GetV();
1603 extrap[4][0] = gempar->GetW();
1605 TMatrixT<double> extrap_cov(5, 5);
1606 Double_t covMat[15], covMat55[5][5];
1607 gempar->GetCov(covMat);
1609 util.FromVec15ToMat25(covMat, covMat55);
1610 for(
int icov = 0; icov < 5; icov++)
for(
int jcov = 0; jcov < 5; jcov++) extrap_cov(icov, jcov) = covMat55[icov][jcov];
1613 TMatrixT<double> H(2, 5);
1626 TMatrixT<double> measurement(2, 1);
1627 measurement[0][0] = gemhit->GetX();
1628 measurement[1][0] = gemhit->GetY();
1640 dR = gemhit->
GetDr();
1641 dP = gemhit->
GetDp();
1648 TMatrixT<double> measurement_cov(2, 2);
1649 measurement_cov[0][0] = errx * errx;
1650 measurement_cov[1][1] = erry * erry;
1652 TMatrixT<double>
kalman(5, 1);
1653 TMatrixT<double> kalman_cov(5, 5);
1656 Kalman(extrap, measurement, H, extrap_cov, measurement_cov, kalman, kalman_cov);
1658 Double_t kalmanCov15[15], kalmanCov55[5][5];
1659 for(
int icov = 0; icov < 5; icov++)
for(
int jcov = 0; jcov < 5; jcov++) kalmanCov55[icov][jcov] = kalman_cov(icov, jcov);
1660 util.FromMat25ToVec15(kalmanCov55, kalmanCov15);
1662 tmppar.SetTrackPar(kalman[3][0], kalman[4][0],
1663 kalman[1][0], kalman[2][0], kalman[0][0],
1666 gempar->GetOrigin(), gempar->GetIVer(), gempar->GetJVer(), gempar->GetKVer(),
1677 TVector3 gemErr(gempar->GetDV(),
1695 dR = gemhit->
GetDr();
1696 dP = gemhit->
GetDp();
1703 TVector3 hitErr(errx, erry, 0.0);
1705 cout <<
"errors " << endl;
1709 TVector3 distVec = gempar->GetPosition() - gemhit->
GetPosition();
1710 double distance = distVec.Perp();
1715 double distErr = (1./distance) *
TMath::Sqrt((distVec.X() * distVec.X()) *
1716 (gemErr.X() * gemErr.X() +
1717 hitErr.X() * hitErr.X()) +
1718 (distVec.Y() * distVec.Y()) *
1719 (gemErr.Y() * gemErr.Y() +
1720 hitErr.Y() * hitErr.Y()) );
1722 if(
fVerbose > 0) cout <<
"distance " << distance <<
" err " << distErr << endl;
1725 double maxdistance = 0;
1728 maxdistance =
fTimes * distErr;
1729 if(maxdistance < 1) maxdistance = 1;
1730 if(maxdistance > 10) maxdistance = 10;
1732 if(
fTurn == 2 && gempar->GetMomentum().Mag() >= 0.5) maxdistance = 5;
1741 hdist[ipos]->Fill(distance);
1742 hsigma[ipos]->Fill(maxdistance);
1744 else if(
fTurn == 2) {
1745 hdist2[ipos]->Fill(distance);
1746 hsigma2[ipos]->Fill(maxdistance);
1754 TArc *earc =
new TArc(gempar->GetPosition().X(), gempar->GetPosition().Y(), maxdistance);
1755 earc->SetFillStyle(0);
1756 if(
fTurn == 1) earc->SetLineColor(3);
1757 else if(
fTurn == 2) earc->SetLineColor(2);
1767 if(distance <= maxdistance) {
1778 std::vector<int> assignedhits;
1782 for(
int ihit = 0; ihit < hitonsensor; ihit++) {
1783 int hitindex = (int)
hitmap(ipos, ihit);
1785 if(!gemhit)
continue;
1790 if(distance >= 0.) {
1806 if(
fVerbose > 0) cout <<
"this hit " << hitindex <<
" BELONGS to this track " << itrk <<
"!!!!!!!!!!!!!" << endl;
1813 if(
fVerbose != 0) cout <<
"assign " << hitindex <<
" to track " << itrk << endl;
1815 assignedhits.push_back(hitindex);
1818 TMarker *g1mrk =
new TMarker(gemhit->GetX(), gemhit->GetY(), 7);
1819 g1mrk->SetMarkerColor(4);
1821 g1mrk->Draw(
"SAME");
1826 else if(
fVerbose > 0) cout <<
"this hit " << hitindex <<
" DOES NOT BELONG to this track " << itrk <<
"!!!!!!!!!!!!!" << endl;
1829 return assignedhits;
1834 TMatrixT<double> extrap_cov, TMatrixT<double> measurement_cov,
1835 TMatrixT<double> &
kalman, TMatrixT<double> &kalman_cov)
1841 TMatrixT<double> extrapHT_cov(extrap_cov, TMatrixT<double>::kMultTranspose, H);
1842 TMatrixT<double> HextrapHT_cov(H, TMatrixT<double>::kMult, extrapHT_cov);
1843 TMatrixT<double> sum_cov = measurement_cov + HextrapHT_cov;
1847 TMatrixT<double> Hsum_cov(H, TMatrixT<double>::kTransposeMult, sum_cov);
1848 TMatrixT<double> gain(extrap_cov, TMatrixT<double>::kMult, Hsum_cov);
1852 TMatrixT<double> Hextrap(H, TMatrixT<double>::kMult, extrap);
1853 TMatrixT<double> meas_Hextrap = measurement - Hextrap;
1854 TMatrixT<double> gainmeas_Hextrap(gain, TMatrixT<double>::kMult, meas_Hextrap);
1855 kalman = extrap + gainmeas_Hextrap;
1859 TMatrixT<double> gainH(gain, TMatrixT<double>::kMult, H);
1860 TMatrixT<double> I(5, 5);
1861 for(
int imat = 0; imat < 5; imat++) {
1862 for(
int jmat = 0; jmat < 5; jmat++) {
1864 if(imat == jmat) I[imat][jmat] = 1;
1867 TMatrixT<double> I_gainH = I - gainH;
1868 kalman_cov = TMatrixT<double>(I_gainH, TMatrixT<double>::kMult, extrap_cov);
1882 cout <<
"start from " << endl;
1883 lastpar.GetPosition().Print();
1884 cout <<
"lastpar error " << lastpar.GetDX() <<
" " << lastpar.GetDY() <<
" " << lastpar.GetDZ() << endl;
1888 FairTrackParP startpar;
1892 if(mcIndex == -1)
return lastpar;
1900 Int_t nsttmvdhits = sttmvdCand->
GetNHits();
1904 FairHit *fhit = NULL;
1905 FairMCPoint *fpnt = NULL;
1913 if(detId != FairRootManager::Instance()->GetBranchId(
fSttBranchName))
return lastpar;
1918 if(!fhit)
return lastpar;
1920 if(!fpnt)
return lastpar;
1924 if(!fhit)
return lastpar;
1926 if(!fpnt)
return lastpar;
1928 else if(detId == FairRootManager::Instance()->GetBranchId(
fSttBranchName)) {
1930 if(!fhit)
return lastpar;
1932 if(!fpnt)
return lastpar;
1936 startpar = FairTrackParP(TVector3(fpnt->GetX(), fpnt->GetY(), fpnt->GetZ()),
1937 TVector3(fpnt->GetPx(), fpnt->GetPy(), fpnt->GetPz()),
1938 TVector3(0.1, 0.1, 0.1), TVector3(0.1, 0.1, 0.1),
1939 (int) TMath::Sign(1., TDatabasePDG::Instance()->GetParticle(mctrk->
GetPdgCode())->Charge()/3.),
1940 TVector3(fpnt->GetX(), fpnt->GetY(), fpnt->GetZ()),
1941 TVector3(1., 0., 0.), TVector3(0., 1., 0.));
1949 bool startpoint =
false;
1958 startpoint =
Prefit(sttmvd, sttmvdCand, position, momentum);
1961 if(startpoint ==
true) {
1963 TVector3 iver = momentum; iver.SetMag(1.);
1964 TVector3 jver = momentum.Orthogonal(); jver.SetMag(1.);
1965 TVector3 kver = iver.Cross(jver); kver.SetMag(1.);
1967 startpar = FairTrackParP(position,
1969 TVector3(lastpar.GetDX(), lastpar.GetDY(), 3.),
1970 TVector3(lastpar.GetDPx(), lastpar.GetDPy(), lastpar.GetDPz()),
1972 position, jver, kver);
1976 startpar = FairTrackParP(lastpar.GetPosition(),
1977 lastpar.GetMomentum(),
1978 TVector3(lastpar.GetDX(), lastpar.GetDY(), 3.),
1979 TVector3(lastpar.GetDPx(), lastpar.GetDPy(), lastpar.GetDPz()),
1981 lastpar.GetOrigin(), lastpar.GetJVer(), lastpar.GetKVer());
2049 cout <<
"from prefit " << endl;
2050 startpar.GetPosition().Print();
2051 startpar.GetMomentum().Print();
2064 TVector3 dj1 = first.GetJVer();
2065 TVector3 dk1 = first.GetKVer();
2068 TVector3 o2 = last.GetOrigin();
2069 TVector3 dj2 = last.GetJVer();
2070 TVector3 dk2 = last.GetKVer();
2072 fPro->PropagateFromPlane(dj1,dk1);
2073 fPro->PropagateToPlane(o2, dj2, dk2);
2075 FairTrackParP *propag =
new FairTrackParP();
2077 int charge = first.GetQ();
2078 int pdg[5] = {-11 * charge, -13 * charge, 211 * charge, 321 * charge, 2212 * charge};
2080 double tmpdistance = 100000;
2081 for(
int ipdg = 0; ipdg < 5; ipdg++) {
2082 prop =
fPro->Propagate(&first, propag, pdg[ipdg]);
2084 TVector3 proppos = propag->GetPosition();
2085 TVector3 lastpos = last.GetPosition();
2086 double distance = (lastpos - proppos).Mag();
2087 cout <<
"this pdg " << pdg[ipdg] <<
" " << distance << endl;
2089 if(distance < tmpdistance) {
2090 tmpdistance = distance;
2095 cout <<
"CHOSEN PDG " << tmppdg <<
" " << tmpdistance << endl;
2101 TFile*
file = FairRootManager::Instance()->GetOutFile();
2103 file->mkdir(
"PndSttMvdGemTracking");
2104 file->cd(
"PndSttMvdGemTracking");
2106 hdist[ipos]->Write();
2114 hchosen[ipos]->SetFillColor(3);
2120 hmcdist[ipos]->SetFillColor(4);
2123 hmcx[ipos]->SetFillColor(4);
2124 hmcx[ipos]->Write();
2126 hmcy[ipos]->SetFillColor(4);
2127 hmcy[ipos]->Write();
2128 delete hmcy[ipos]; }
2137 for(Int_t itrk = 0; itrk <
fTrackArray->GetEntriesFast(); itrk++) {
2139 if(!sttmvdTrack)
continue;
2141 if(!sttmvdCand)
continue;
2145 if(mcIndex == -1)
continue;
2155 Int_t nsttmvdhits = sttmvdCand->
GetNHits();
2159 FairHit *fhit = NULL;
2160 FairMCPoint *fpnt = NULL;
2165 if(fhit->GetRefIndex() != -1 && fhit) fpnt = (FairMCPoint*)
fMvdPointArray->At(fhit->GetRefIndex());
2170 if(fhit->GetRefIndex() != -1 && fhit) fpnt = (FairMCPoint*)
fMvdPointArray->At(fhit->GetRefIndex());
2172 else if(detId == FairRootManager::Instance()->GetBranchId(
fSttBranchName)) {
2174 if(fhit->GetRefIndex() != -1 && fhit) fpnt = (FairMCPoint*)
fSttPointArray->At(fhit->GetRefIndex());
2177 TVector3 position(fpnt->GetX(), fpnt->GetY(), fpnt->GetZ());
2178 TVector3 momentum(fpnt->GetPx(), fpnt->GetPy(), fpnt->GetPz());
2188 FairTrackParP *gempar =
new FairTrackParP();
2190 int charge = tmppar.GetQ();
2200 if (prop == kFALSE)
continue;
2201 TVector3 extrappos = gempar->GetPosition();
2204 for(
int ipnt = 0; ipnt <
fGemPointArray->GetEntriesFast(); ipnt++) {
2206 if(!gempnt)
continue;
2207 Int_t pntMcIndex = gempnt->GetTrackID();
2209 if(pntMcIndex != mcIndex)
continue;
2210 TVector3 gempos(gempnt->GetX(), gempnt->GetY(), gempnt->GetZ());
2212 if(
fabs(gempos.Z() - extrappos.Z()) < 0.1) {
2213 double distance = (gempos - extrappos).Perp();
2214 hmcdist[ipos]->Fill(distance);
2215 hmcx[ipos]->Fill(gempos.X() - extrappos.X());
2216 hmcy[ipos]->Fill(gempos.Y() - extrappos.Y());
2228 for(
int ihit = 0; ihit < hitonsensor; ihit++) {
2229 int hitindex = (int)
hitmap(ipos, ihit);
2231 if(!gemhit)
continue;
2234 TVector3 extrapos = gempar->GetPosition();
2236 Double_t distance = (gemhitpos - extrapos).Perp();
2237 if(distance < tmpdistance) {
2238 tmpdistance = distance;
2242 closestdistance = tmpdistance;
2244 if(closestdistance < 0)
return -1;
2259 TMatrixT<double> points(nhits, 11);
2260 Double_t xc, yc, radius, fitm, fitp;
2266 Int_t firsthitid = -1, lasthitid = -1;
2267 for(
int ihit = 0; ihit <
nhits; ihit++)
2274 points[ihit][0] = -1;
2275 points[ihit][1] = detId;
2276 points[ihit][2] = 0;
2277 points[ihit][3] = 0;
2278 points[ihit][4] = 0;
2279 points[ihit][5] = 0;
2280 points[ihit][6] = 0;
2281 points[ihit][7] = 0;
2282 points[ihit][8] = 0;
2283 points[ihit][9] = 0;
2284 points[ihit][10] = -1;
2286 if(detId == FairRootManager::Instance()->GetBranchId(
fGemBranchName))
continue;
2291 if(!mvdhit) { cout <<
"mvd hit " << ihit <<
" " << hitId <<
" does not exist" << endl;
continue;}
2292 points[ihit][0] = hitId;
2293 points[ihit][2] = mvdhit->GetX();
2294 points[ihit][3] = mvdhit->GetY();
2295 points[ihit][4] = mvdhit->GetZ();
2299 points[ihit][10] = 2;
2302 if(firsthitid == -1) firsthitid = ihit;
2306 else if(detId == FairRootManager::Instance()->GetBranchId(
fSttBranchName)) {
2308 if(!stthit) { cout <<
"stt hit " << ihit <<
" " << hitId <<
" does not exist" << endl;
continue; }
2309 TVector3 xyz(0, 0, 0);
2310 TVector3 dxyz(0, 0, 0);
2316 if(wireDirection == TVector3(0., 0., 1.)) {
2318 if(intfin ==
false) {
2325 if(firsthitid == -1) firsthitid = ihit;
2328 points[ihit][10] = 0;
2333 points[ihit][10] = 1;
2336 points[ihit][0] = hitId;
2337 points[ihit][2] = xyz.X();
2338 points[ihit][3] = xyz.Y();
2339 points[ihit][4] = xyz.Z();
2340 points[ihit][5] = dxyz.X();
2341 points[ihit][6] = dxyz.Y();
2342 points[ihit][7] = dxyz.Z();
2350 for(
int iteration = 0; iteration < 1; iteration++) {
2351 Bool_t fitting =
Fit(points, xc, yc, radius);
2352 if(fitting ==
false) {
2358 for(
int ihit = 0; ihit <
nhits; ihit++) {
2360 Int_t hitId = (Int_t) points[ihit][0];
2361 Int_t detId = (Int_t) points[ihit][1];
2363 if(hitId == -1)
continue;
2364 Int_t fitflag = (Int_t) points[ihit][10];
2365 if(fitflag != 0)
continue;
2366 if(detId != FairRootManager::Instance()->GetBranchId(
fSttBranchName))
continue;
2368 if(!stthit)
continue;
2370 TVector3 xyz(0, 0, 0);
2371 TVector3 dxyz(0, 0, 0);
2373 if(intfin ==
false) {
2377 points[ihit][2] = xyz.X();
2378 points[ihit][3] = xyz.Y();
2379 points[ihit][4] = xyz.Z();
2380 points[ihit][5] = dxyz.X();
2381 points[ihit][6] = dxyz.Y();
2382 points[ihit][7] = dxyz.Z();
2386 if(firsthitid == -1) firsthitid = ihit;
2396 Bool_t zfitting =
ZFit(points, charge, xc, yc, radius, fitm, fitp);
2397 if(zfitting ==
false) {
2404 if(firsthitid == -1 || lasthitid == -1)
return kFALSE;
2416 TVector2
v(x0 - xc, y0 - yc);
2417 Double_t alpha1 =
TMath::ATan2(points[firsthitid][3] - y0 + radius * TMath::Sin(Phi0), points[firsthitid][2] - x0 + radius * TMath::Cos(Phi0));
2418 TVector2
p1(points[firsthitid][2] - xc, points[firsthitid][3] - yc);
2421 Double_t alpha2 =
TMath::ATan2(points[lasthitid][3] - y0 + radius * TMath::Sin(Phi0), points[lasthitid][2] - x0 + radius * TMath::Cos(Phi0));
2422 TVector2
p2(points[lasthitid][2] - xc, points[lasthitid][3] - yc);
2426 Double_t scos = - charge * radius * Fi2;
2428 double z = (fitm * scos + fitp);
2431 versor[0] = xc - points[lasthitid][2];
2432 versor[1] = yc - points[lasthitid][3];
2435 versor[0] /= Distance;
2436 versor[1] /= Distance;
2438 double px = - charge * radius * 0.006 * versor[1];
2439 double py = charge * radius * 0.006 * versor[0];
2442 lastpos.SetXYZ(points[lasthitid][2], points[lasthitid][3], z);
2443 lastmom.SetXYZ(px, py, pz);
2460 if(wiredirection != TVector3(0.,0.,1.)) {
2477 Double_t m = (point.Y() - yc)/(point.X() - xc);
2478 Double_t q = point.Y() - m*point.X();
2491 if(
fabs(point.X() - xc) < 1e-6) {
2498 y1 = point.Y() +
sqrt(isochrone * isochrone - (x1 - point.X()) * (x1 - point.X()));
2501 y2 = point.Y() -
sqrt(isochrone * isochrone - (x2 - point.X()) * (x2 - point.X()));
2506 yb1 = yc +
sqrt(radius * radius - (xb1 - xc) * (xb1 - xc));
2509 yb2 = yc -
sqrt(radius * radius - (xb2 - xc) * (xb2 - xc));
2519 if(((m*(q - point.Y()) - point.X())*(m*(q - point.Y()) - point.X()) - (m*m + 1)*((q - point.Y())*(q - point.Y()) + point.X()*point.X() - isochrone*isochrone)) < 0.) {
if(
fVerbose > 0) cout <<
"IntersectionFinder round errors: " << isochrone << endl;
2522 x1 = (-(m*(q - point.Y()) - point.X()) +
sqrt((m*(q - point.Y()) - point.X())*(m*(q - point.Y()) - point.X()) - (m*m + 1)*((q - point.Y())*(q - point.Y()) + point.X()*point.X() - isochrone*isochrone))) / (m*m + 1);
2525 x2 = (-(m*(q - point.Y()) - point.X()) -
sqrt((m*(q - point.Y()) - point.X())*(m*(q - point.Y()) - point.X()) - (m*m + 1)*((q - point.Y())*(q - point.Y()) + point.X()*point.X() - isochrone*isochrone))) / (m*m + 1);
2530 xb1 = (-(m*(q - yc) - xc) +
sqrt((m*(q - yc) - xc)*(m*(q - yc) - xc) - (m*m + 1)*((q - yc)*(q - yc) + xc*xc - (radius) *(radius) ))) / (m*m + 1);
2533 xb2 = (-(m*(q - yc) - xc) -
sqrt((m*(q - yc) - xc)*(m*(q - yc) - xc) - (m*m + 1)*((q - yc)*(q - yc) + xc*xc - (radius) *(radius)))) / (m*m + 1);
2538 Double_t distb1 =
sqrt((yb1 - point.Y())*(yb1 - point.Y()) + (xb1 - point.X())*(xb1 - point.X()));
2539 Double_t distb2 =
sqrt((yb2 - point.Y())*(yb2 - point.Y()) + (xb2 - point.X())*(xb2 - point.X()));
2543 if(distb1 > distb2) xyb.Set(xb2, yb2);
2544 else xyb.Set(xb1, yb1);
2547 Double_t dist1 =
sqrt((xyb.Y() - y1)*(xyb.Y() - y1) + (xyb.X() - x1)*(xyb.X() - x1));
2548 Double_t dist2 =
sqrt((xyb.Y() - y2)*(xyb.Y() - y2) + (xyb.X() - x2)*(xyb.X() - x2));
2551 if(dist1 > dist2) xyz.SetXYZ(x2, y2, stthit->GetZ());
2552 else xyz.SetXYZ(x1, y1, stthit->GetZ());
2557 dxyz.SetXYZ(sigx, sigy, 0);
2565 Int_t
nhits = points.GetRowUpb() + 1;
2566 int lasthitid = -1, firsthitid = -1;
2567 for(
int ihit = 0; ihit <
nhits; ihit++) {
2568 if(points[ihit][0] != -1 && points[ihit][10] != -1 && points[ihit][10] != 1) {
2569 if(firsthitid == -1) firsthitid = ihit;
2574 if(firsthitid == -1 || lasthitid == -1)
return kFALSE;
2576 Double_t trasl[2] = {points[firsthitid][2], points[firsthitid][3]};
2579 if(firsthitid >= lasthitid)
return false;
2581 points[lasthitid][2] - points[firsthitid][2]);
2582 Double_t Suu, Su, Sv, Suv, S1, Suuu, Suuv, Suuuu;
2596 for(
int ihit = 0; ihit <
nhits; ihit++)
2598 Int_t hitId = (Int_t) points[ihit][0];
2599 Int_t detId = (Int_t) points[ihit][1];
2600 if(hitId == -1)
continue;
2601 Int_t fitflag = (Int_t) points[ihit][10];
2602 if(fitflag == 1 || fitflag == -1)
continue;
2603 if(detId == FairRootManager::Instance()->GetBranchId(
fSttBranchName) && points[ihit][8] < 0.1)
continue;
2604 fitpoint.SetXYZ(points[ihit][2], points[ihit][3], points[ihit][4]);
2612 xtrasl = fitpoint.X() - trasl[0];
2613 ytrasl = fitpoint.Y() - trasl[1];
2626 u = xtrasl / (xtrasl*xtrasl + ytrasl*ytrasl);
2627 v = ytrasl / (xtrasl*xtrasl + ytrasl*ytrasl);
2629 Double_t dvdx = (-2 * xtrasl * ytrasl)/pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
2630 Double_t dvdy = (xtrasl*xtrasl - ytrasl*ytrasl) / pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
2635 sigv2 = dvdx * dvdx * sigx * sigx + dvdy * dvdy * sigy * sigy + 2 * dvdx * dvdy * sigx * sigy;
2637 if(sigv2 == 0) sigv2 = 1e-5;
2639 Su = Su + (u/sigv2);
2640 Sv = Sv + (v/sigv2);
2642 Suv = Suv + ((u*
v)/sigv2);
2643 Suu = Suu + ((u*u)/sigv2);
2645 Suuu = Suuu + ((u*u*u)/sigv2);
2646 Suuv = Suuv + ((u*u*
v)/sigv2);
2648 Suuuu = Suuuu + ((u*u*u*u)/sigv2);
2654 TMatrixT<double> matrix(3,3);
2661 matrix[1][2] = Suuu;
2664 matrix[2][1] = Suuu;
2665 matrix[2][2] = Suuuu;
2669 determ = matrix.Determinant();
2679 TMatrixT<double> column(3,1);
2682 column[2][0] = Suuv;
2684 TMatrixT<double> column2(3,1);
2685 column2.Mult(matrix, column);
2692 if(
fabs(a)<0.000001) {
2698 Double_t xcrot, ycrot, xc, yc, epsilon,
R;
2701 epsilon = -c*pow((1+(b*b)), -3/2);
2702 R = epsilon +
sqrt((xcrot*xcrot)+(ycrot*ycrot));
2750 Int_t
nhits = points.GetRowUpb() + 1;
2754 for(
int ihit = 0; ihit <
nhits; ihit++)
2756 Int_t detId = (Int_t) points[ihit][1];
2757 Int_t hitId = (Int_t) points[ihit][0];
2759 if(hitId == -1)
continue;
2760 Int_t fitflag = (Int_t) points[ihit][10];
2762 if(fitflag != 2)
continue;
2765 if(detId == FairRootManager::Instance()->GetBranchId(
fSttBranchName) ||
2766 detId == FairRootManager::Instance()->GetBranchId(
fGemBranchName))
continue;
2768 TVector2
v(x0 - xc, y0 - yc);
2769 Double_t alpha =
TMath::ATan2(points[ihit][3] - y0 + radius * TMath::Sin(Phi0), points[ihit][2] - x0 + radius * TMath::Cos(Phi0));
2770 TVector2
p(points[ihit][2] - xc, points[ihit][3] - yc);
2774 scos = - charge * radius * Fi;
2778 Double_t sigz2 = points[ihit][7] * points[ihit][7];
2780 if(sigz2 == 0) sigz2 = 1e-5;
2783 Sx = Sx + (scos /(sigz2));
2784 Sz = Sz + (points[ihit][4]/(sigz2));
2785 Sxz = Sxz + ((scos * points[ihit][4])/(sigz2));
2786 Sxx = Sxx + ((scos * scos)/(sigz2));
2787 S1z = S1z + 1/(sigz2);
2791 if(zcounter <= 1)
return kFALSE;
2792 Detz = S1z*Sxx - Sx*Sx;
2794 cout <<
"DET Z = 0" << endl;
2796 fitp = (1/Detz)*(Sxx*Sz - Sx*Sxz);
2797 fitm = (1/Detz)*(S1z*Sxz - Sx*Sz);
2807 if(
fVerbose > 0) cout <<
"GET INITIAL PARAMS" << endl;
2809 TVector3 recomom = recopar.GetMomentum();
2810 TVector3 recopos = recopar.GetPosition();
2811 Int_t charge = recopar.GetQ();
2813 radius = recomom.Perp()/0.006;
2816 if(
fabs(recomom.X()) > 1e-10) {
2824 else beta = TMath::Sign(1., recomom.Y()) *
TMath::Pi();
2827 xc = recopos.X() + radius *
TMath::Cos(beta);
2828 yc = recopos.Y() - radius *
TMath::Sin(beta);
2831 xc = recopos.X() - radius *
TMath::Cos(beta);
2832 yc = recopos.Y() + radius *
TMath::Sin(beta);
2847 TVector3 recoposlast = recoparlast.GetPosition();
2851 cout <<
"charge/xc/yc/radius " << charge <<
" " << xc <<
" " << yc <<
" " << radius << endl;
2854 recoparlast.GetMomentum().Print();
2855 recoposlast.Print();
2859 fitm = recomom.Z() / recomom.Perp();
2869 Double_t scosfirst = 0, scoslast = 0.;
2871 if(
fVerbose > 0) cout <<
"Phi0 " << Phi0 * TMath::RadToDeg() << endl;
2873 TVector2
v(x0 - xc, y0 - yc);
2875 TVector2
p1(recopos.X() - xc, recopos.Y() - yc);
2879 cout <<
"alpha1, Fi1 " << alpha1 * TMath::RadToDeg() <<
" " << Fi1 * TMath::RadToDeg() << endl;
2884 TVector2
p2(recoposlast.X() - xc, recoposlast.Y() - yc);
2889 cout <<
"alpha2, Fi2 " << alpha2 * TMath::RadToDeg() <<
" " << Fi2 * TMath::RadToDeg() << endl;
2893 scosfirst = - charge * radius * Fi1;
2894 scoslast = - charge * radius * Fi2;
2898 fitp = (recopos.Z() + recoposlast.Z() - fitm * (scosfirst + scoslast)) / 2.;
2902 cout <<
"positions first/last" << endl;
2904 recoposlast.Print();
2906 cout <<
"scosfirst/scoslast " << scosfirst <<
" " << scoslast << endl;
2907 cout <<
"fitm/fitp " << fitm <<
" " << fitp << endl;
2908 cout <<
"z1/z2 " << fitp + fitm * scosfirst <<
" " << fitp + fitm * scoslast << endl;
2916 Double_t Fi = - charge * TMath::ACos(v * p / (v.Mod() * p.Mod()));
2918 double pi2 = 2 *
pi;
2921 if((charge > 0 && ((Phi0 > 0 && ((alpha > 0 && alpha > Phi0) ||
2922 (alpha < 0 && alpha < Phi0 - pi)))
2924 ((Phi0 < 0 && ((alpha > 0 && alpha < pi + Phi0) ||
2925 (alpha < 0 && alpha > Phi0)))) ))) Fi = - (pi2 + Fi) ;
2926 else if((charge < 0 && ((Phi0 > 0 && ((alpha > 0 && alpha < Phi0) ||
2927 (alpha < 0 && alpha > Phi0 - pi)))
2929 ((Phi0 < 0 && ((alpha > 0 && alpha > pi + Phi0) ||
2930 (alpha < 0 && alpha < Phi0)))) ))) Fi = pi2 - Fi ;
2939 double pi2 = 2 *
pi;
2941 if(charge < 0 && Fi < Fi_pre) Fi += pi2;
2942 else if(charge > 0 && Fi > Fi_pre) Fi -= pi2;
2950 if(nhits == 0)
return;
2953 TMatrixT<double>
sensor(nhits, 5);
2955 TMatrixT<double> nhitsonsensor2(
fNPositions, nhits);
2959 std::vector< std::vector<int> > mcpoints;
2961 for (Int_t ihit = 0; ihit <
nhits; ihit++) {
2965 sensor[ihit][0] = ihit;
2966 sensor[ihit][1] = hit->GetX();
2967 sensor[ihit][2] = hit->GetY();
2973 sensor[ihit][3] = ipos;
2974 sensor[ihit][4] =
true;
2993 nhitsonsensor2[ipos][(int) nhitsonsensor[ipos][0]] = ihit;
2994 nhitsonsensor[ipos][0]++;
2999 std::vector< std::vector<int> > accepted;
3001 std::vector<int> acc;
3002 accepted.push_back(acc);
3017 for(
int ihit = 0; ihit <
nhits; ihit++) {
3019 if(sensor[ihit][3] != 0 &&
3020 sensor[ihit][3] != 2 &&
3021 sensor[ihit][3] != 4)
continue;
3022 int first = (int) sensor[ihit][3];
3023 if(sensor[ihit][4] ==
false)
continue;
3025 double x1 = sensor[ihit][1];
3026 double y1 = sensor[ihit][2];
3030 for(
int jhit = 0; jhit <
nhits; jhit++) {
3032 if(sensor[jhit][3] != first + 1)
continue;
3033 int second = (int) sensor[jhit][3];
3034 if(sensor[jhit][4] ==
false)
continue;
3037 double x2 = sensor[jhit][1];
3038 double y2 = sensor[jhit][2];
3040 double distance =
TMath::Sqrt((x1 - x2) * (x1 - x2) +
3041 (y1 - y2) * (y1 - y2));
3044 std::vector< int > acc1 = accepted[first];
3045 std::vector< int > acc2 = accepted[second];
3046 bool alreadythere1 =
false, alreadythere2 =
false;
3047 for(
size_t j = 0; j < acc1.size(); j++) {
3048 if(sensor[ihit][0] == acc1[j]) {
3049 alreadythere1 =
true;
3053 for(
size_t j = 0; j < acc2.size(); j++) {
3054 if(sensor[jhit][0] == acc2[j]) {
3055 alreadythere2 =
true;
3060 if(alreadythere1 ==
false) {
3062 acc1.push_back((
int) sensor[ihit][0]);
3063 accepted[first] = acc1;
3074 int posindex = stat * 10 + sens;
3077 posindex = 0;
break;
3079 posindex = 1;
break;
3081 posindex = 2;
break;
3083 posindex = 3;
break;
3085 posindex = 4;
break;
3087 posindex = 5;
break;
3092 for(
int khit = 0; khit <
nhits; khit++) {
3094 if(ihit == khit)
continue;
3095 if(sensor[khit][3] != posindex)
continue;
3102 sensor[khit][4] =
false;
3106 sensor[khit][4] =
false;
3109 sensor[ihit][4] =
false;
3115 TMarker *amrk =
new TMarker(x1, y1, 21);
3116 amrk->SetMarkerColor(5);
3124 if(alreadythere2 ==
false) {
3126 acc2.push_back((
int) sensor[jhit][0]);
3127 accepted[second] = acc2;
3139 int posindex = stat * 10 + sens;
3142 posindex = 0;
break;
3144 posindex = 1;
break;
3146 posindex = 2;
break;
3148 posindex = 3;
break;
3150 posindex = 4;
break;
3152 posindex = 5;
break;
3156 for(
int khit = 0; khit <
nhits; khit++) {
3157 if(jhit == khit)
continue;
3158 if(sensor[khit][3] != posindex)
continue;
3164 sensor[khit][4] =
false;
3168 sensor[khit][4] =
false;
3171 sensor[jhit][4] =
false;
3176 TMarker *amrk2 =
new TMarker(x2, y2, 21);
3177 amrk2->SetMarkerColor(5);
3179 amrk2->Draw(
"SAME");
3185 if(counter2 == nhitsonsensor[first + 1][0])
break;
3187 if(counter1 == (nhitsonsensor[0][0] + nhitsonsensor[2][0] + nhitsonsensor[4][0]))
break;
3210 if(nhits == 0)
return;
3212 if(
fVerbose > 0) cout <<
"CHECK COMBINATORIAL: DELETE FAKE HITS" << endl;
3215 for(Int_t it = 0; it < ntracks; it++) {
3219 if(thistrackhits.size() == 0)
continue;
3228 addhit[ipos][0] = 0;
3229 for(
size_t j = 0; j < thistrackhits.size(); j++)
combi[ipos][j] = -1;
3232 for(
size_t j = 0; j < thistrackhits.size(); j++) {
3233 int ihit = thistrackhits[j];
3236 if(!gemhit)
continue;
3242 int hitpos = (int) addhit[index][0];
3243 combi[index][hitpos] = ihit;
3248 cout <<
"itrk " << itrk <<
" " << nhits <<
" " << thistrackhits.size() << endl;
3258 for(
size_t i = 0;
i < thistrackhits.size();
i++) {
3259 if(
combi[ipos][
i] != -1) count++;
3262 if(
fVerbose > 0) cout << count <<
" hits on pos " << ipos << endl;
3265 if(count <= 1)
continue;
3269 for(
size_t i = 0;
i < thistrackhits.size();
i++) {
3270 int ihit = (int)
combi[ipos][
i];
3271 if(ihit == -1)
continue;
3275 if(
fVerbose > 0) cout << count2 <<
" true hits on pos " << ipos << endl;
3278 if(count2 == 0)
continue;
3280 for(
size_t i = 0;
i < thistrackhits.size();
i++) {
3281 int ihit = (int)
combi[ipos][
i];
3283 if(
fVerbose > 0) cout <<
"delete " << ihit <<
" from track " << itrk << endl;
3296 if(nhits == 0)
return kFALSE;
3298 for(
int ihit = 0; ihit <
nhits; ihit++)
3300 Int_t detId = (Int_t) points[ihit][1];
3301 Int_t hitId = (Int_t) points[ihit][0];
3303 if(hitId == -1)
continue;
3304 Int_t fitflag = (Int_t) points[ihit][10];
3305 if(fitflag != 1)
continue;
3306 if(detId != FairRootManager::Instance()->GetBranchId(
fSttBranchName))
continue;
3321 if(wireDirection == TVector3(0., 0., 1.))
continue;
3326 TVector3 first = pos + wireDirection * halflength;
3327 TVector3 second = pos - wireDirection * halflength;
3331 double xint, yint, x1, y1, x2, y2, delta;
3334 if(
fabs(second.X() - first.X()) < 1.e-5) {
3338 delta = radius * radius - (x1 - xc) * (x1 - xc);
3339 if(delta < 0)
continue;
3346 Double_t m = (second.Y() - first.Y())/(second.X() - first.X());
3347 Double_t q = first.Y() - m * first.X();
3350 delta = (m * (q - yc) - xc) - (m * m + 1) * ((q - yc) * (q - yc) + xc * xc - radius * radius);
3351 if(delta < 0)
continue;
3353 x1 = (- (m * (q - yc) - xc) + delta) / (m * m + 1);
3355 x2 = (- (m * (q - yc) - xc) - delta) / (m * m + 1);
3359 double d1 = 0, d2 = 0;
3360 d1 =
TMath::Sqrt((y1 - first.Y()) * (y1 - first.Y()) + (x1 - first.X()) * (x1 - first.X()));
3361 d2 =
TMath::Sqrt((y2 - first.Y()) * (y2 - first.Y()) + (x2 - first.X()) * (x2 - first.X()));
3373 Double_t ll = ((xint - first.X()) + (yint - first.Y())) / (wireDirection.X() + wireDirection.Y());
3374 double zint = first.Z() + wireDirection.Z() * ll;
3376 points[ihit][2] = xint;
3377 points[ihit][3] = yint;
3378 points[ihit][4] = zint;
3379 points[ihit][5] = 1.;
3380 points[ihit][6] = 1.;
3381 points[ihit][7] = 1.;
3393 cout <<
"UPDATE MC TRACK ID" << endl;
3394 cout <<
"ORIGINAL MC " << completeCand->
getMcTrackId() << endl;
3397 std::map<int, int> mctrackids;
3400 for (
size_t ihit = 0; ihit < completeCand->
GetNHits(); ihit++) {
3411 Int_t
refIndex = fhit->GetRefIndex();
3412 if(refIndex == -1)
continue;
3419 Int_t
refIndex = fhit->GetRefIndex();
3420 if(refIndex == -1)
continue;
3424 else if(detId == FairRootManager::Instance()->GetBranchId(
fSttBranchName)) {
3427 Int_t
refIndex = fhit->GetRefIndex();
3428 if(refIndex == -1)
continue;
3432 else if (detId == FairRootManager::Instance()->GetBranchId(
fGemBranchName)) {
3435 Int_t
refIndex = fhit->GetRefIndex();
3436 if(refIndex == -1)
continue;
3441 int trackID = fpnt->GetTrackID();
3442 cout <<
"HIT ID " << iHit <<
" DET ID " << detId <<
" TRACK ID " << trackID << endl;
3450 mctrackids[trackID]++;
3454 int tmptrackID = -1;
3455 for(
size_t itrk = 0; itrk < mctrackids.size(); itrk++) {
3456 if(counter < mctrackids[itrk]) {
3457 counter = mctrackids[itrk];
3462 cout <<
"NEW MC " << completeCand->
getMcTrackId() << endl;
3472 if (mctrackid == -1) {
3473 std::cout <<
"-W- PndSttMvdGemTracking: no mctrackid - use default hypo " <<
fDefaultPdgCode << std::endl;
3480 std::cout <<
"-W- PndSttMvdGemTracking: no mctrack " << mctrackid <<
" - use default hypo " <<
fDefaultPdgCode << std::endl;
3486 if(pdg >= 100000000)
3488 std::cout <<
"-W- PndSttMvdGemTracking: we have an ion here " << pdg <<
" - use default hypo " <<
fDefaultPdgCode << std::endl;
3491 else if (TDatabasePDG::Instance()->GetParticle(mctrack->
GetPdgCode())->Charge() == 0)
3493 std::cout <<
"-W- PndSttMvdGemTracking: we have an neutral here " << pdg <<
" - use default hypo " <<
fDefaultPdgCode << std::endl;
3500 std::cout <<
"-W- PndSttMvdGemTracking: no correlated mctrackid at all - use default hypo " <<
fDefaultPdgCode << std::endl;
3508 double mccharge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge()/3.;
3509 if((charge * mccharge) > 0.)
return pdg;
TClonesArray * fTrackIDArray
Double_t CompareToPreviousPhi(Double_t Fi, Double_t Fi_pre, int charge)
std::vector< int >::iterator fOrderingIterator
void SetRefIndex(TString branch, Int_t i)
PndGemDigiPar * fGemParameters
void OrderGemHits(Int_t nhits)
Int_t GetPosIndex(PndGemHit *hit)
Int_t countreconstructablehit
void Copy(PndTrackCand *completeCand, PndTrack *completeTrack, PndTrackCand *sttmvdCand, PndTrack *sttmvd)
std::vector< int > GetHitsAssociatedToTrackOnPlane(Int_t itrk, Int_t ipos)
void CheckCombinatorial(Int_t nhits, Int_t ntracks)
friend F32vec4 sqrt(const F32vec4 &a)
void SetBranchNames(TString mvdpixel, TString mvdstrip, TString stt, TString gem)
Int_t countsecnotassigned
Bool_t Fit(TMatrixT< double > points, Double_t &outxc, Double_t &outyc, Double_t &outradius)
static T Sqrt(const T &x)
TClonesArray * fTrackCandArray
std::vector< PndTrackCandHit > GetSortedHits()
PndTrackCandHit GetSortedHit(UInt_t i)
Double_t IsAssignable(FairTrackParP *gempar, PndGemHit *gemhit)
virtual void Exec(Option_t *opt)
TVector3 GetMomentum() const
std::vector< int > trackindexes
void SetPersistency(Bool_t val=kTRUE)
Double_t CalculatePhi(TVector2 v, TVector2 p, double alpha, double Phi0, int charge)
Int_t CountHitsInTrack(Int_t itrk)
TClonesArray * fCompleteTrackCandArray
Digitization Parameter Class for GEM part.
Bool_t IntersectionFinder(Double_t xc, Double_t yc, Double_t radius, PndSttHit *stthit, TVector3 &xyz, TVector3 &dxyz)
Int_t GetCorrTrackID(Int_t i=0) const
TClonesArray * fTrackArray
std::vector< std::pair< int, int > > trackvector
Int_t GetChargeCorrectedPdgFromMC(int trackid, int charge)
Bool_t ZFit(TMatrixT< double > points, Int_t charge, Double_t xc, Double_t yc, Double_t radius, Double_t &fitm, Double_t &fip)
TClonesArray * fCompleteTrackArray
TClonesArray * fGemPointArray
PndGemSensor * GetSensor(Int_t iSensor)
Int_t GetClosestOnFirst(FairTrackParP *gempar, Int_t ipos, Double_t &closestdistance)
Short_t GetNCorrTrackId(void) const
Int_t GetSensorNr() const
std::vector< int > GetHitsAssociatedToTrack(Int_t itrk)
TClonesArray * fSensPositions
void EvaluatePerformances(Int_t nhits, Int_t ntracks)
std::vector< int > fOrdering
virtual InitStatus Init()
TString fStartTrackBranchName
TClonesArray * fMvdPixelHitArray
void AddRemainingHits(Int_t ntracks)
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
Int_t GetNSensors() const
TString fMvdStripBranchName
Bool_t PropagateToGemPlane(FairTrackParP *tmppar, FairTrackParP *gempar, Int_t ipos)
Int_t GetPdgFromMC(int trackid)
Double_t GetIsochrone() const
TClonesArray * fMvdStripHitArray
TMatrixT< double > distancemap
static T ATan2(const T &y, const T &x)
FairTrackParP GetParamLast()
TClonesArray * FillTubeArray()
Int_t GetHitIndex(Int_t i)
Bool_t Prefit(PndTrack *sttmvdTrack, PndTrackCand *sttmvdCand, TVector3 &lastpos, TVector3 &lastmom)
Double_t GetIsochroneError() const
TMatrixT< float > hitcounter
TClonesArray * fMCTrackArray
Int_t countreconstructablepoint
friend F32vec4 fabs(const F32vec4 &a)
void Kalman(TMatrixT< double > extrap, TMatrixT< double > measurement, TMatrixT< double > H, TMatrixT< double > extrap_cov, TMatrixT< double > measurement_cov, TMatrixT< double > &kalman, TMatrixT< double > &kalman_cov)
std::map< int, bool > fProTracks
void DeleteHitFromTrack(Int_t ihit, Int_t itrk)
void ForbidMultiAssignedHits(Int_t nhits, Int_t ntracks)
Int_t GetStationNr() const
TClonesArray * fMvdPointArray
Int_t countnohitonplane[8]
void AddHitToTrack(Int_t ihit, Int_t itrk)
Int_t countprinotassigned
Bool_t ZFind(Int_t nhits, TMatrixT< double > points, Double_t xc, Double_t yc, Double_t radius)
Bool_t PropagateToGemPlaneAsHelix(PndTrack *sttmvd, FairTrackParP *gempar, Int_t ipos)
void SetTrackBranchNames(TString startingtrack, TString startingtrackcand)
TString fMvdPixelBranchName
TVector3 GetPosition() const
TClonesArray * fGemHitArray
FairTrackParP SetStartParameters(PndTrack *sttmvd, PndTrackCand *sttmvdCand)
std::vector< int > GetTracksAssociatedToHit(Int_t ihit)
TString fStartTrackCandBranchName
Int_t SelectPdgCode(PndTrack *sttmvd)
PndSttMvdTracking * sttmvd
Int_t GetDigiNr(Int_t iside) const
virtual void SetParContainers()
void OnlyOneHitToEachTrack(Int_t nhits, Int_t ntracks)
Double_t GetOuterRadius() const
std::vector< int > AssignHits(Int_t itrk, FairTrackParP *gempar, Int_t ipos)
TClonesArray * fTubeArray
Int_t GetRefIndex() const
TVector3 GetStartVertex() const
PndTrackCand * GetTrackCandPtr()
Int_t GetMotherID() const
void UpdateMCTrackId(PndTrackCand *completeCand)
Bool_t GetInitialParams(PndTrack *sttmvd, Double_t &xc, Double_t &yc, Double_t &radius, Double_t &fitm, Double_t &fitp)
void SetTrackCand(const PndTrackCand &cand)
std::vector< int > notassignedhits
TVector3 GetWireDirection()
void ConsiderCombinatorialEffect(Int_t nhits)
std::map< int, bool > towhichplane
TClonesArray * fSttHitArray
Int_t GetTrackIndex(Int_t i)
TString fStartTrackIDBranchName
FairTrackParP GetParamFirst()
PndGeoSttPar * fSttParameters
PndGemStation * GetStation(Int_t iStation)
std::map< int, int > fCombiMap
TClonesArray * fSttPointArray
void Reset(Int_t nhits, Int_t ntracks)
std::vector< int > usabletracks