50 , frMonitorData(monitorData)
51 , fTrackExtender(pars, mass)
52 , fCloneMerger(pars, mass)
53 , fTrackFitter(pars, mass, mode)
76 if (!std::isfinite(dqp))
return false;
77 if (!std::isfinite(Cqp))
return false;
79 if (dqp * dqp > tripletLinkChi2 * Cqp) {
82 dchi2 = dqp * dqp / Cqp;
93 if (!std::isfinite(dtx))
return false;
94 if (!std::isfinite(dty))
return false;
95 if (!std::isfinite(Ctx))
return false;
96 if (!std::isfinite(Cty))
return false;
98 if (dty * dty > tripletLinkChi2 * Cty)
return false;
99 if (dtx * dtx > tripletLinkChi2 * Ctx)
return false;
105 if (!std::isfinite(dchi2))
return false;
132 auto& caIterations =
fParameters.GetCAIterations();
133 for (
auto iter = caIterations.begin(); iter != caIterations.end(); ++iter) {
157 for (
unsigned int ih = 0; ih < wData.
Hits().
size(); ih++) {
188 for (
int iS = 0; iS <
fParameters.GetNstationsActive(); iS++) {
196 for (
int iS = 0; iS <
fParameters.GetNstationsActive(); iS++) {
201 wData.
Hit(iFstHit + ih) =
h;
206 LOG(info) <<
"===== Sliding Window hits: ";
207 for (
int i = 0; i < nHits; ++i) {
210 LOG(info) <<
"===== ";
223 for (
int iS = 0; iS <
fParameters.GetNstationsActive(); ++iS) {
225 fscal lasttime = std::numeric_limits<fscal>::infinity();
226 fscal starttime = -std::numeric_limits<fscal>::infinity();
227 fscal gridMinX = -0.1;
228 fscal gridMaxX = 0.1;
229 fscal gridMinY = -0.1;
230 fscal gridMaxY = 0.1;
235 gridMinX = std::min(gridMinX,
h.X());
236 gridMinY = std::min(gridMinY,
h.Y());
237 gridMaxX = std::max(gridMaxX,
h.X());
238 gridMaxY = std::max(gridMaxY,
h.Y());
241 assert(std::isfinite(time));
242 lasttime = std::min(lasttime, time);
243 starttime = std::max(starttime, time);
250 const fscal sizeY = gridMaxY - gridMinY;
251 const fscal sizeX = gridMaxX - gridMinX;
252 const int nBins2D = 1 + nSliceHits;
256 const fscal maxScale = 0.3 * scale;
257 const fscal minScale = 0.01 * scale;
259 fscal yStep = 0.3 * sizeY /
sqrt(nBins2D);
260 fscal xStep = 0.8 * sizeX /
sqrt(nBins2D);
261 yStep = std::clamp(yStep, minScale, maxScale);
262 xStep = std::clamp(xStep, minScale, maxScale);
264 auto& grid = wData.
Grid(iS);
265 grid.
BuildBins(gridMinX, gridMaxX, gridMinY, gridMaxY, xStep, yStep);
267 grid.StoreHits(wData.
Hits(),
282 for (
int ista = 0; ista <
fParameters.GetNstationsActive(); ++ista) {
315 auto& [vHitFirstTriplet, vHitNofTriplets, vTriplets] =
fTripletData;
316 vHitFirstTriplet.reset(wData.
Hits().size(), 0);
317 vHitNofTriplets.reset(wData.
Hits().size(), 0);
322 for (
int j = 0; j <
fParameters.GetNstationsActive(); j++) {
323 const size_t nHitsStation = wData.
TsHitIndices(j).size();
324 vTriplets[j].clear();
325 vTriplets[j].
reserve(2 * nHitsStation);
329 std::vector<std::pair<int, int>> staPattern;
330 for (
int gap = 0; gap <= wData.
CurrentIteration()->GetMaxStationGap(); gap++) {
331 for (
int i = 0; i <= gap; i++) {
332 staPattern.push_back(std::make_pair(1 + i, 2 + gap));
339 const auto& grid = wData.
Grid(istal);
340 for (
auto& entry : grid.GetEntries()) {
342 const size_t oldSize = vTriplets[istal].size();
343 for (
auto& pattern : staPattern) {
348 vHitNofTriplets[ihitl] = vTriplets[istal].size() - oldSize;
356 auto& [vHitFirstTriplet, vHitNofTriplets, vTriplets] =
fTripletData;
363 unsigned int nNeighbours = vHitNofTriplets[tr.GetMHit()];
364 unsigned int neighLocation = vHitFirstTriplet[tr.GetMHit()];
368 if (nNeighbours > 0) {
369 assert((
int) neighStation >= istal + 1
373 unsigned char level = 0;
375 for (
unsigned int iN = 0; iN < nNeighbours; ++iN, ++neighTriplet, ++neighLocation) {
377 ca::Triplet& neighbour = vTriplets[neighStation][neighTriplet];
382 if (tr.GetFNeighbour() == 0) {
383 tr.SetFNeighbour(neighLocation);
387 level = std::max(level,
static_cast<unsigned char>(neighbour.
GetLevel() + 1));
404 for (
int firstTripletLevel =
fParameters.GetNstationsActive() - 3; firstTripletLevel >= min_level;
405 firstTripletLevel--) {
415 const int firstTripletLevel)
418 int nlevel = (
fParameters.GetNstationsActive() - 2) - firstTripletLevel + 1;
420 const unsigned char min_best_l =
421 (firstTripletLevel > min_level) ? firstTripletLevel + 2 : min_level + 3;
430 for (
const auto&
h : wData.
Hits()) {
437 istaF <=
fParameters.GetNstationsActive() - 3 - firstTripletLevel; ++istaF) {
439 if (--nlevel == 0)
break;
443 const auto& fstTripLHit = wData.
Hit(first_trip.GetLHit());
452 if (fstTripLHit.Station() == 0) {
459 if (3 + first_trip.GetLevel() < minNhits) {
465 if (first_trip.GetLevel() < firstTripletLevel) {
470 curr_tr.
AddHit(first_trip.GetLHit());
471 curr_tr.
SetChi2(first_trip.GetChi2());
476 CAFindTrack(istaF, best_tr, &first_trip, curr_tr, min_best_l, new_tr, wData, vTriplets);
478 if (best_tr.
NofHits() < firstTripletLevel + 2)
continue;
480 if (best_tr.
NofHits() < min_level + 3)
continue;
482 if (best_tr.
NofHits() < minNhits) {
486 int ndf = best_tr.
NofHits() * 2 - 5;
491 ndf = best_tr.
NofHits() * 2 - 4;
510 <<
" found, L = " << best_tr.
NofHits() <<
" chi2= " << best_tr.
Chi2() <<
" hits: ";
511 for (
auto hitIdLoc : tr.
Hits()) {
512 const auto hitId = wData.
Hit(hitIdLoc).
Id();
515 LOG(info) << s.str();
527 for (
int iComp = 0; (iComp < 100); ++iComp) {
529 bool repeatCompetition =
false;
536 for (
auto& hitId : tr.Hits()) {
538 auto updateStrip = [&](
int& strip) {
539 if ((strip >= 0) && (strip != tr.Id())) {
541 if (!other.IsAlive() && tr.IsBetterThan(other)) {
572 for (
const auto& hitIndex : tr.Hits()) {
573 if (!tr.IsAlive())
break;
579 for (
auto hitId : tr.Hits()) {
590 repeatCompetition =
true;
594 if (!repeatCompetition)
break;
606 <<
": alive = " << tr.
IsAlive();
616 for (
auto iHit : tr.
Hits()) {
628 s <<
"store track " << iCandidate <<
" chi2= " << tr.
Chi2() <<
"\n";
630 for (
auto hitLoc : tr.
Hits()) {
631 auto hitId = wData.
Hit(hitLoc).
Id();
634 LOG(info) << s.str();
661 const auto& hitM = wData.
Hit(curr_trip->
GetMHit());
662 const auto& hitR = wData.
Hit(curr_trip->
GetRHit());
673 int ndf = curr_tr.
NofHits() * 2 - 5;
676 ndf = curr_tr.
NofHits() * 2 - 4;
693 for (
Tindex in = 0; in < N_neighbour; in++) {
704 const auto& hitL = wData.
Hit(new_trip.
GetLHit());
714 unsigned char new_L = curr_tr.
NofHits() + 1;
725 if ((mc01 == mc02) && (mc02 == mc03)) {
726 LOG(info) <<
" sta " << ista <<
" mc0 " << mc01 <<
" " << mc02 <<
" " << mc03 <<
" mc1 " << mc11 <<
" "
727 << mc12 <<
" " << mc13 <<
" chi2 " << curr_tr.
Chi2() / (2 * (curr_tr.
NofHits() + 2) - 4)
728 <<
" new " << new_chi2 / (2 * (new_L + 2) - 4);
729 LOG(info) <<
" hits " << curr_trip->
GetLHit() <<
" " << curr_trip->
GetMHit() <<
" "
734 int ndf = 2 * (new_L + 2) - 5;
737 ndf = 2 * (new_L + 2) - 4;
740 ndf = 2 * (new_L + 2) - 4;
749 new_tr[ista] = curr_tr;
752 const int new_ista = ista + new_trip.
GetMSta() - new_trip.
GetLSta();
753 new_tr[ista].
SetChi2(new_chi2);
755 CAFindTrack(new_ista, best_tr, &new_trip, new_tr[ista], min_best_l, new_tr, wData, vTriplets);
A class to store hit information in a backet-sorted way on 2D grid.
A class wrapper over clones merger algorithm for the CA track finder (declaration)
source file for the ca::Track class
Triplet constructor for the CA tracker.
static vector< vector< QAHit > > hits
friend fvec sqrt(const fvec &a)
static constexpr size_t size()
Data class with information on a STS local track.
void AddHit(ca::HitIndex_t hitIndex)
void SetStation(int iStation)
const Vector< ca::HitIndex_t > & Hits() const
void SetAlive(bool isAlive)
void Exec(const ca::InputData &input, WindowData &wData)
Registers.
static int GetMcTrackIdForCaHit(int iHit)
Gets number of stations before the pipe (MVD stations in CBM)
static int GetMcTrackIdForWindowHit(int iGridHit)
Get mc track ID for a hit (debug tool)
void RemoveUsedHits(const ca::Vector< ca::Hit > &hits, const ca::Vector< unsigned char > &hitKeyFlags)
Remove grid entries that correspond to the used hits.
void BuildBins(fscal xMin, fscal xMax, fscal yMin, fscal yMax, fscal binWidthX, fscal binWidthY)
Build the grid.
ca::Hit class describes a generic hit for the CA tracker
HitKeyIndex_t BackKey() const
Get the back key index.
std::string ToString() const
Simple string representation of the hit class.
HitKeyIndex_t FrontKey() const
Get the front key index.
HitIndex_t Id() const
Get the hit id.
A set of parameters for the CA Track finder iteration.
int GetMinNhits() const
Gets min n hits.
float GetTrackChi2Cut() const
Gets track chi2 upper cut.
int GetMaxStationGap() const
Gets flag: true - triplets are also built with skipping <= GetMaxStationGap stations.
int GetMinNhitsStation0() const
Gets min n hits for tracks that start on station 0.
float GetTargetPosSigmaX() const
Gets sigma target position in X direction [cm].
bool GetTrackFromTripletsFlag() const
float GetTripletLinkChi2() const
Gets min value of dp/dp_error, for which two tiplets are neighbours.
bool GetPrimaryFlag() const
Checks flag: true - only primary tracks are searched, false - [all or only secondary?...
const std::string & GetName() const
Gets the name of the iteration.
float GetTargetPosSigmaY() const
Gets sigma target position in Y direction [cm].
int GetFirstStationIndex() const
Gets station index of the first station used in tracking.
bool GetExtendTracksFlag() const
Sets flag: true - extends track candidates with unused hits.
void StopTimer(ETimerKey key)
Stops timer.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
void StartTimer(ETimerKey key)
Starts timer.
A container for all external parameters of the CA tracking algorithm.
fscal ExtendBranch(ca::Branch &t, WindowData &wData)
Try to extrapolate and find additional hits on other stations.
TrackExtender fTrackExtender
Object of the track extender algorithm.
TripletData_t fTripletData
void CreateTracks(WindowData &wData, const ca::Iteration &caIteration, TripletArray_t &vTriplets)
TrackFitter fTrackFitter
Object of the track extender algorithm.
CloneMerger fCloneMerger
Object of the clone merger algorithm.
void CAFindTrack(int ista, ca::Branch &best_tr, const ca::Triplet *curr_trip, ca::Branch &curr_tr, unsigned char min_best_l, ca::Branch *new_tr, WindowData &wData, TripletArray_t &vTriplets)
void CreateTrackCandidates(WindowData &wData, TripletArray_t &vTriplets, const int min_level, const int firstTripletLevel)
ca::Branch fNewTr[constants::size::MaxNstations]
const Parameters< fvec > & fParameters
Object of Framework parameters class.
Vector< ca::Branch > fvTrackCandidates
static unsigned int TripletId2Triplet(unsigned int id)
void DoCompetitionLoop(const WindowData &wData)
void SelectTracks(WindowData &wData)
Vector< ca::Triplet > fvTriplets
std::array< Vector< ca::Triplet >, constants::size::MaxNstations > TripletArray_t
fscal fDefaultMass
mass of the propagated particle [GeV/c2]
TrackFinderWindow(const ca::Parameters< fvec > &pars, const fscal mass, const ca::TrackingMode &mode, ca::TrackingMonitorData &monitorData)
Default constructor.
void ConstructTriplets(WindowData &wData)
static constexpr bool fDebug
void PrepareGrid(const Vector< Hit > &hits, WindowData &wData)
bool checkTripletMatch(const ca::Triplet &l, const ca::Triplet &r, fscal &dchi2, WindowData &wData) const
static unsigned int PackTripletId(unsigned int iStation, unsigned int iTriplet)
void CaTrackFinderSlice(const ca::InputData &input, WindowData &wData)
ca::TrackingMode fTrackingMode
void PrepareCAIteration(const ca::Iteration &caIteration, WindowData &wData, const bool isFirst)
void SearchNeighbors(WindowData &wData)
TrackingMonitorData & frMonitorData
Reference to monitor data.
void ReadWindowData(const Vector< Hit > &hits, WindowData &wData)
static unsigned int TripletId2Station(unsigned int id)
Vector< int > fvHitKeyToTrack
void FitCaTracks(const ca::InputData &input, WindowData &wData)
Fit tracks, found by the CA tracker.
Class representing an output track in the CA tracking algorithm.
int fNofHits
Number of hits in track.
void CreateTripletsForHit(Vector< ca::Triplet > &tripletsOut, int istal, int istam, int istar, ca::HitIndex_t ihl)
---— FUNCTIONAL PART ---—
Triplet class represents a short 3-hits track segment called a "triplet".
bool IsMomentumFitted() const
unsigned char GetLevel() const
ca::HitIndex_t GetRHit() const
ca::HitIndex_t GetMHit() const
ca::HitIndex_t GetLHit() const
unsigned int GetFNeighbour() const
int GetNNeighbours() const
void SetNNeighbours(int n)
void push_back(Tinput value)
Pushes back a value to the vector.
void reserve(std::size_t count)
Reserves a new size for the vector.
Container for internal data, processed on a single time window.
HitIndex_t & HitStartIndexOnStation(int iStation)
Index of the first hit on the station.
HitIndex_t & NofHitsOnStation(int iStation)
Number of hits on station.
Vector< Track > & RecoTracks()
Accesses reconstructed track container.
void ResetHitData(int nHits)
Resets hit data.
void ResetHitSuppressionFlags()
Reset suppressed hit flags.
ca::Grid & Grid(int iStation)
Gets grid for station index.
HitIndex_t TsHitIndex(int iSt, int iHit) const
Maps hit index from the time window to the time slice.
void SetCurrentIteration(const Iteration *ptr)
Accesses current iteration.
const Iteration * CurrentIteration() const
Accesses current iteration.
Vector< unsigned char > & HitKeyFlags()
Access to the hit key flags container.
kf::FieldValue< fvec > & TargB()
Accesses magnetic field in starting point (target or first station)
uint8_t IsHitSuppressed(int iHit) const
Gets hit suppression flag.
Vector< HitIndex_t > & TsHitIndices(int iSt)
Accesses container of hit index map from the time window to the time slice.
Vector< ca::Hit > & Hits()
Gets hit vector.
kf::MeasurementXy< fvec > & TargetMeasurement()
Measurement of the target with the uncertainty.
unsigned char IsHitKeyUsed(HitKeyIndex_t iKey) const
Hit key flag: if this hit or cluster was already used.
ca::Hit & Hit(int iHit)
Gets hit by index.
Vector< HitIndex_t > & RecoHitIndices()
Accesses indices of hits, used by reconstructed tracks.
constexpr int MaxNstations
Max number of stations, 2^6 = 64.
TODO: SZh 8.11.2022: add selection of parameterisation.
@ Triplet
number of triplets
unsigned int HitIndex_t
Index of ca::Hit.
@ PrepareIteration
(iterations loop)