81 if (!std::isfinite(dqp))
return false;
82 if (!std::isfinite(Cqp))
return false;
84 if (dqp * dqp > tripletLinkChi2 * Cqp) {
87 dchi2 = dqp * dqp / Cqp;
98 if (!std::isfinite(dtx))
return false;
99 if (!std::isfinite(dty))
return false;
100 if (!std::isfinite(Ctx))
return false;
101 if (!std::isfinite(Cty))
return false;
103 if (dty * dty > tripletLinkChi2 * Cty)
return false;
104 if (dtx * dtx > tripletLinkChi2 * Ctx)
return false;
110 if (!std::isfinite(dchi2))
return false;
139 auto& caIterations =
fParameters.GetCAIterations();
140 for (
unsigned int iterInd = 0; iterInd < caIterations.size(); ++iterInd) {
141 auto& iter = caIterations[iterInd];
165 for (
unsigned int ih = 0; ih < wData.
Hits().
size(); ih++) {
187 if (!
fParameters.GetConfig().DevUseParSearchWindows()) {
198 for (
int iS = 0; iS <
fParameters.GetNstationsActive(); iS++) {
206 for (
int iS = 0; iS <
fParameters.GetNstationsActive(); iS++) {
211 wData.
Hit(iFstHit + ih) =
h;
216 LOG(info) <<
"===== Sliding Window hits: ";
217 for (
int i = 0; i < nHits; ++i) {
220 LOG(info) <<
"===== ";
233 for (
int iS = 0; iS <
fParameters.GetNstationsActive(); ++iS) {
235 fscal lasttime = std::numeric_limits<fscal>::infinity();
236 fscal starttime = -std::numeric_limits<fscal>::infinity();
237 fscal gridMinX = -0.1;
238 fscal gridMaxX = 0.1;
239 fscal gridMinY = -0.1;
240 fscal gridMaxY = 0.1;
245 gridMinX = std::min(gridMinX,
h.X());
246 gridMinY = std::min(gridMinY,
h.Y());
247 gridMaxX = std::max(gridMaxX,
h.X());
248 gridMaxY = std::max(gridMaxY,
h.Y());
251 assert(std::isfinite(time));
252 lasttime = std::min(lasttime, time);
253 starttime = std::max(starttime, time);
260 const fscal sizeY = gridMaxY - gridMinY;
261 const fscal sizeX = gridMaxX - gridMinX;
262 const int nBins2D = 1 + nSliceHits;
265 const fscal zRef =
fParameters.GetActiveSetup().GetActiveLayer(iS).GetZref()[0];
266 const fscal scale = zRef -
fSetup.GetTarget().GetZ()[0];
267 const fscal maxScale = 0.3 * scale;
268 const fscal minScale = 0.01 * scale;
270 fscal yStep = 0.3 * sizeY /
sqrt(nBins2D);
271 fscal xStep = 0.8 * sizeX /
sqrt(nBins2D);
272 yStep = std::clamp(yStep, minScale, maxScale);
273 xStep = std::clamp(xStep, minScale, maxScale);
275 auto& grid = wData.
Grid(iS);
276 grid.
BuildBins(gridMinX, gridMaxX, gridMinY, gridMaxY, xStep, yStep, zRef);
278 grid.StoreHits(wData.
Hits(),
292 if (iterationIndex != 0) {
293 for (
int ista = 0; ista <
fParameters.GetNstationsActive(); ++ista) {
308 const auto& trg =
fSetup.GetTarget();
309 wData.
TargB() =
fField.GetPrimVertexField().Get(trg.GetX(), trg.GetY(), trg.GetZ());
327 auto& [vHitFirstTriplet, vHitNofTriplets, vTriplets] =
fTripletData;
328 vHitFirstTriplet.reset(wData.
Hits().size(), 0);
329 vHitNofTriplets.reset(wData.
Hits().size(), 0);
335 for (
int j = 0; j <
fParameters.GetNstationsActive(); j++) {
336 const size_t nHitsStation = wData.
TsHitIndices(j).size();
337 vTriplets[j].clear();
338 vTriplets[j].
reserve(2 * nHitsStation);
342 std::vector<std::pair<int, int>> staPattern;
343 for (
int gap = 0; gap <= wData.
CurrentIteration()->GetMaxStationGap(); gap++) {
344 for (
int i = 0; i <= gap; i++) {
345 staPattern.push_back(std::make_pair(1 + i, 2 + gap));
352 const auto& grid = wData.
Grid(istal);
353 for (
auto& entry : grid.GetEntries()) {
355 const size_t oldSize = vTriplets[istal].size();
356 for (
auto& pattern : staPattern) {
357 if (
fParameters.GetConfig().DevUseParSearchWindows()) {
366 vHitNofTriplets[ihitl] = vTriplets[istal].size() - oldSize;
374 auto& [vHitFirstTriplet, vHitNofTriplets, vTriplets] =
fTripletData;
381 unsigned int nNeighbours = vHitNofTriplets[tr.GetMHit()];
382 unsigned int neighLocation = vHitFirstTriplet[tr.GetMHit()];
386 if (nNeighbours > 0) {
387 assert((
int) neighStation >= istal + 1
391 unsigned char level = 0;
393 for (
unsigned int iN = 0; iN < nNeighbours; ++iN, ++neighTriplet, ++neighLocation) {
395 ca::Triplet& neighbour = vTriplets[neighStation][neighTriplet];
400 if (tr.GetFNeighbour() == 0) {
401 tr.SetFNeighbour(neighLocation);
403 tr.SetNNeighbours(neighLocation - tr.GetFNeighbour() + 1);
405 level = std::max(level,
static_cast<unsigned char>(neighbour.
GetLevel() + 1));
422 for (
int firstTripletLevel =
fParameters.GetNstationsActive() - 3; firstTripletLevel >= min_level;
423 firstTripletLevel--) {
433 const int firstTripletLevel)
436 int nlevel = (
fParameters.GetNstationsActive() - 2) - firstTripletLevel + 1;
438 const unsigned char min_best_l =
439 (firstTripletLevel > min_level) ? firstTripletLevel + 2 : min_level + 3;
448 for (
const auto&
h : wData.
Hits()) {
455 istaF <=
fParameters.GetNstationsActive() - 3 - firstTripletLevel; ++istaF) {
457 if (--nlevel == 0)
break;
461 const auto& fstTripLHit = wData.
Hit(first_trip.GetLHit());
470 if (fstTripLHit.Station() == 0) {
477 if (3 + first_trip.GetLevel() < minNhits) {
483 if (first_trip.GetLevel() < firstTripletLevel) {
488 curr_tr.
AddHit(first_trip.GetLHit());
489 curr_tr.
SetChi2(first_trip.GetChi2());
494 CAFindTrack(istaF, best_tr, &first_trip, curr_tr, min_best_l, new_tr, wData, vTriplets);
496 if (best_tr.
NofHits() < firstTripletLevel + 2)
continue;
498 if (best_tr.
NofHits() < min_level + 3)
continue;
500 if (best_tr.
NofHits() < minNhits) {
504 int ndf = best_tr.
NofHits() * 2 - 5;
509 ndf = best_tr.
NofHits() * 2 - 4;
530 <<
" found, L = " << best_tr.
NofHits() <<
" chi2= " << best_tr.
Chi2() <<
" hits: ";
531 for (
auto hitIdLoc : tr.
Hits()) {
532 const auto hitId = wData.
Hit(hitIdLoc).
Id();
533 s << hitId <<
" (mc " <<
fFramework.GetBestMcTrackIdForCaHit(hitId) <<
") ";
535 LOG(info) << s.str();
547 for (
int iComp = 0; (iComp < 100); ++iComp) {
549 bool repeatCompetition =
false;
556 for (
auto& hitId : tr.Hits()) {
558 auto updateStrip = [&](
int& strip) {
559 if ((strip >= 0) && (strip != tr.Id())) {
561 if (!other.IsAlive() && tr.IsBetterThan(other)) {
592 for (
const auto& hitIndex : tr.Hits()) {
593 if (!tr.IsAlive())
break;
599 for (
auto hitId : tr.Hits()) {
610 repeatCompetition =
true;
614 if (!repeatCompetition)
break;
626 <<
": alive = " << tr.
IsAlive();
636 for (
auto iHit : tr.
Hits()) {
648 s <<
"store track " << iCandidate <<
" chi2= " << tr.
Chi2() <<
"\n";
650 for (
auto hitLoc : tr.
Hits()) {
651 auto hitId = wData.
Hit(hitLoc).
Id();
652 s <<
fFramework.GetBestMcTrackIdForCaHit(hitId) <<
" ";
654 LOG(info) << s.str();
681 const auto& hitM = wData.
Hit(curr_trip->
GetMHit());
682 const auto& hitR = wData.
Hit(curr_trip->
GetRHit());
693 int ndf = curr_tr.
NofHits() * 2 - 5;
696 ndf = curr_tr.
NofHits() * 2 - 4;
713 for (
Tindex in = 0; in < N_neighbour; in++) {
724 const auto& hitL = wData.
Hit(new_trip.
GetLHit());
734 unsigned char new_L = curr_tr.
NofHits() + 1;
746 if ((mc01 == mc02) && (mc02 == mc03)) {
747 LOG(info) <<
" sta " << ista <<
" mc0 " << mc01 <<
" " << mc02 <<
" " << mc03 <<
" mc1 " << mc11 <<
" "
748 << mc12 <<
" " << mc13 <<
" chi2 " << curr_tr.
Chi2() / (2 * (curr_tr.
NofHits() + 2) - 4)
749 <<
" new " << new_chi2 / (2 * (new_L + 2) - 4);
750 LOG(info) <<
" hits " << curr_trip->
GetLHit() <<
" " << curr_trip->
GetMHit() <<
" "
755 int ndf = 2 * (new_L + 2) - 5;
758 ndf = 2 * (new_L + 2) - 4;
761 ndf = 2 * (new_L + 2) - 4;
770 new_tr[ista] = curr_tr;
773 const int new_ista = ista + new_trip.
GetMSta() - new_trip.
GetLSta();
774 new_tr[ista].
SetChi2(new_chi2);
776 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.
Triplet constructor for the CA tracker.
static vector< vector< QAHit > > hits
friend fvec sqrt(const fvec &a)
static constexpr size_t size()
Generates beam ions for transport simulation.
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.
void AddHit(ca::HitIndex_t hitIndex)
void SetStation(int iStation)
const Vector< ca::HitIndex_t > & Hits() const
void SetAlive(bool isAlive)
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, fscal zRef)
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.
A container for all external parameters of the CA tracking algorithm.
TrackExtender fTrackExtender
Object of the track extender algorithm.
TripletData_t fTripletData
void PrepareCAIteration(int iterationIndex, const ca::Iteration &caIteration, WindowData &wData)
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.
const cbm::algo::kf::Field< fvec > & fField
Reference to magnetic field object.
Vector< ca::Branch > fvTrackCandidates
static unsigned int TripletId2Triplet(unsigned int id)
void DoCompetitionLoop(const WindowData &wData)
void SelectTracks(WindowData &wData)
Vector< ca::Triplet > fvTriplets
fscal fDefaultMass
mass of the propagated particle [GeV/c2]
void ConstructTriplets(WindowData &wData)
int GetBestMcTrackIdForWindowHit(int iHit) const
Get mc track ID for a hit (debug tool)
McMatch GetMcMatchForWindowHit(int iHit) const
WindowData * pwData
Pointer to the window data object.
static constexpr bool fDebug
void PrepareGrid(const Vector< Hit > &hits, WindowData &wData)
const Framework & fFramework
Reference to the Framework object.
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 SearchNeighbors(WindowData &wData)
TrackingMonitorData & frMonitorData
Reference to monitor data.
TrackFinderWindow(const ca::Framework &framework, const ca::Parameters< fvec > &pars, const fscal mass, const ca::TrackingMode &mode, ca::TrackingMonitorData &monitorData)
Default constructor.
const cbm::algo::kf::Setup< fvec > & fSetup
Reference to the setup.
void ReadWindowData(const Vector< Hit > &hits, WindowData &wData)
std::array< Vector< ca::Triplet >, constants::size::MaxNstations > TripletArray_t
static unsigned int TripletId2Station(unsigned int id)
Vector< int > fvHitKeyToTrack
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 ---—
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
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.
void SetCurrentIteration(int ind, const Iteration *ptr)
Accesses current iteration.
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.
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
MonitorData< ECounter, ETimer > TrackingMonitorData
unsigned int HitIndex_t
Index of ca::Hit.
@ PrepareIteration
(iterations loop)