40 std::lower_bound(
fSetup.GetActiveLayers().cbegin(),
fSetup.GetActiveLayers().cbegin() +
fSetup.GetNofLayers(),
42 [](
const auto& s,
int edge) { return s.IsInField() > edge; })
43 -
fSetup.GetActiveLayers().cbegin();
49 "event:iter:sta:p:q:vx:vy:vz:x0:y0:z0:x1:y1:z1:ax:ay:az:adx:ady:dx:dy:dz");
56 "tripletSW",
"event:iter:sta:jumpL:jumpM:p:q:vx:vy:vz:x0:y0:z0:x1:y1:z1:x2:y2:z2:ax:ay:az:adx:ady:dx:dy:dz");
80 const int sta0 = sta1 / 2;
82 assert(0 <= sta0 && sta0 < sta1 && sta1 <
fSetup.GetNofLayers());
90 if (sta2 >=
fSetup.GetNofLayers()) {
93 sta0 = (sta1 <= 0) ? 0 : std::clamp(sta0, 0, sta1 - 1);
95 if (
fSetup.GetNofLayers() >= 3) {
96 assert(0 <= sta0 && sta0 < sta1 && sta1 < sta2 && sta2 <
fSetup.GetNofLayers());
116 const bool matchMc =
fParameters.GetConfig().DevMatchDoubletsViaMc();
128 sa.
GetSearchWindow(hitl.X(), hitl.Y(), hitl.Z(), hitl.RangeX(), hitl.RangeY());
131 sqrt(
frWData.CurrentIteration()->GetDoubletChi2Cut()) / 3.5,
132 fParameters.GetConfig().GetMaxDoubletsPerSinglet(), mc);
137 if (trueHitId >= 0) {
140 float x = 0.5 * (area2D.
xMax + area2D.
xMin);
141 float y = 0.5 * (area2D.
yMax + area2D.
yMin);
146 trueHit.
Y(), trueHit.
Z(),
x,
y, z, 0.5 * (area2D.
xMax - area2D.
xMin), 0.5 * (area2D.
yMax - area2D.
yMin),
147 trueHit.
X() -
x, trueHit.
Y() -
y, trueHit.
Z() - z);
170 auto it2 = hitsM.begin();
171 for (
auto it = hitsM.begin(); it != hitsM.end(); it++) {
176 if (
frWData.IsHitSuppressed(indM)) {
183 fscal dz = hitm.
Z() - hitl.
Z();
184 fscal tx = (hitm.
X() - hitl.
X()) / dz;
185 fscal ty = (hitm.
Y() - hitl.
Y()) / dz;
187 for (
auto itClone = it + 1; itClone != hitsM.end(); itClone++) {
189 const int indClone = *itClone;
192 const fscal dzc = hitClone.
Z() - hitm.
Z();
194 if (
fStaM->IsTimeMeasured()) {
195 const fscal dt = hitm.
T() - hitClone.
T();
201 const fscal dx = hitm.
X() + tx * dzc - hitClone.
X();
206 const fscal dy = hitm.
Y() + ty * dzc - hitClone.
Y();
211 if (
fParameters.GetConfig().DevSuppressOverlapHitsViaMc()) {
214 || (mc !=
fFramework.GetMcMatchForCaHit(hitClone.
Id()))) {
226 hitsM.
shrink(std::distance(hitsM.begin(), it2));
251 const double maxSlope =
frWData.CurrentIteration()->GetMaxSlope();
252 const double tripletChi2Cut =
frWData.CurrentIteration()->GetTripletChi2Cut();
260 for (
unsigned int i2 = 0; i2 <
fDoubletData.size(); i2++) {
267 fscal tx = (h1.
X() - h0.
X()) / dz;
268 fscal ty = (h1.
Y() - h0.
Y()) / dz;
269 if ((fabs(tx) > maxSlope) || (fabs(ty) > maxSlope)) {
275 if (
fParameters.GetConfig().DevMatchTripletsViaMc()) {
278 if (mc.
IsEmpty() || mc != mc1) {
287 fscal dz1 = grid.GetMinZ() - sta.GetZref()[0];
288 fscal dz2 = grid.GetMaxZ() - sta.GetZref()[0];
289 fscal dx1 = tx * dz1;
290 fscal dx2 = tx * dz2;
291 fscal dy1 = ty * dz1;
292 fscal dy2 = ty * dz2;
293 assert(std::min(dx1, dx2) <= 0.f && std::max(dx1, dx2) >= 0.f);
294 assert(std::min(dy1, dy2) <= 0.f && std::max(dy1, dy2) >= 0.f);
295 area2D.xMin += std::min(dx1, dx2);
296 area2D.xMax += std::max(dx1, dx2);
297 area2D.yMin += std::min(dy1, dy2);
298 area2D.yMax += std::max(dy1, dy2);
301 collectedHits.clear();
303 fParameters.GetConfig().GetMaxTripletsPerDoublet(), mc);
308 if (!mc1.IsEmpty() && mc1 == mc2 && mc1.GetNofLinks() == 1 && mc2.GetNofLinks() == 1) {
311 if (trueHitId >= 0) {
315 float x = 0.5 * (area2D.xMax + area2D.xMin);
316 float y = 0.5 * (area2D.yMax + area2D.yMin);
323 h0.
X(), h0.
Y(), h0.
Z(), h1.
X(), h1.
Y(), h1.
Z(), trueHit.
X(), trueHit.
Y(), trueHit.
Z(),
x,
y, z,
324 0.5 * (area2D.xMax - area2D.xMin), 0.5 * (area2D.yMax - area2D.yMin), trueHit.
X() -
x, trueHit.
Y() -
y,
330 if (
static_cast<int>(collectedHits.size()) >=
fParameters.GetConfig().GetMaxTripletsPerDoublet()) {
337 collectedHits.clear();
356 assert(hitsM.size() == hitsR.size());
361 const bool isMomentumFitted = ((
fStaL->IsInField()) || (
fStaM->IsInField()) || (
fStaR->IsInField()));
370 auto fldValueL =
fField.GetFieldValue(
fIstaL, hitL.
X(), hitL.
Y());
371 const auto& target =
fSetup.GetTarget();
372 const auto fldValueTarget =
fField.GetPrimVertexField().Get(target.GetX(), target.GetY(), target.GetZ());
376 for (
size_t i3 = 0; i3 < hitsM.size(); ++i3) {
398 fscal hL = hitL.
Z() - hitM.
Z();
399 fscal hR = hitR.
Z() - hitM.
Z();
403 fscal msX = 0., msY = 0.;
406 fscal tx = (hitL.
X() - hitM.
X()) / hL;
407 fscal ty = (hitL.
Y() - hitM.
Y()) / hL;
411 fscal cL = c_light *
sqrt(1.f + xx + yy);
413 auto [Sx, Sy, Sz] = fld.GetDoubleIntegrals(hitM.
X(), hitM.
Y(), hitM.
Z(), hitL.
X(), hitL.
Y(), hitL.
Z());
415 JxL4 = cL * (Sx * xy - Sy * (xx + 1.f) + Sz * ty);
416 JyL4 = cL * (Sx * (yy + 1.f) - Sy * xy - Sz * tx);
419 msX = (1.f + xx) * a;
420 msY = (1.f + yy) * a;
426 fscal tx = (hitR.
X() - hitM.
X()) / hR;
427 fscal ty = (hitR.
Y() - hitM.
Y()) / hR;
431 fscal cL = c_light *
sqrt(1.f + xx + yy);
433 auto [Sx, Sy, Sz] = fld.GetDoubleIntegrals(hitM.
X(), hitM.
Y(), hitM.
Z(), hitR.
X(), hitR.
Y(), hitR.
Z());
435 JxR4 = cL * (Sx * xy - Sy * (xx + 1.f) + Sz * ty);
436 JyR4 = cL * (Sx * (yy + 1.f) - Sy * xy - Sz * tx);
441 fscal d = hR * JxL4 - hL * JxR4;
442 qp = (hL * (hitM.
X() - hitR.
X()) + hR * (hitL.
X() - hitM.
X())) / d;
443 Cqp = (hL * hL * hitR.
dX2() + (hL - hR) * (hL - hR) * hitM.
dX2() + hR * hR * hitL.
dX2() + hL * hL * hR * hR * msX)
451 fscal dz01 = 1. / (hitM.
Z() - hitL.
Z());
453 fscal tx = (hitM.
X() - hitL.
X()) * dz01;
457 fscal ty = (hitM.
Y() - hitL.
Y()) * dz01;
463 fscal yL = hitL.
Y() - JyL4 * qp;
464 fscal lS = hitL.
dY2() + JyL4 * JyL4 * Cqp;
469 fscal yR = hitR.
Y() - JyR4 * qp;
470 fscal rS = hitR.
dY2() + JyR4 * JyR4 * Cqp;
472 fscal zeta = (hL * (yM - yR) + hR * (yL - yM));
473 fscal c = hL * hL * rS + (hL - hR) * (hL - hR) * mS + hR * hR * lS + hR * hR * hL * hL * msY;
475 chi2y = zeta * zeta / c;
484 fscal xTarget = target.GetX()[0];
485 fscal yTarget = target.GetY()[0];
486 fscal zTarget = target.GetZ()[0];
496 std::tie(Sx, Sy, Sz) = fldTarget.GetDoubleIntegrals(
x,
y, z, xTarget, yTarget, zTarget);
498 fscal JxTgt4 = cL * (Sx * xy - Sy * (xx +
fscal(1.)) + Sz * ty);
499 fscal JyTgt4 = cL * (Sx * (yy +
fscal(1.)) - Sy * xy - Sz * tx);
503 fscal zeta0 =
x +
h * tx + JxTgt4 * qp - xTarget;
504 fscal zeta1 =
y +
h * ty + JyTgt4 * qp - yTarget;
506 fscal S00 = m.Dx2()[0] + JxTgt4 * JxTgt4 * Cqp;
507 fscal S10 = m.Dxy()[0] + JxTgt4 * JyTgt4 * Cqp;
508 fscal S11 = m.Dy2()[0] + JyTgt4 * JyTgt4 * Cqp;
510 fscal si =
fscal(1.) / (S00 * S11 - S10 * S10);
517 chi2Tgt = zeta0 * zeta0 * S00 +
fscal(2.) * zeta0 * zeta1 * S10 + zeta1 * zeta1 * S11;
523 fscal chi2 = chi2x + chi2y;
525 if (chi2 >
frWData.CurrentIteration()->GetTripletFinalChi2Cut()) {
529 if (!std::isfinite(chi2) || chi2 < 0) {
535 tripletsOut.
emplace_back(ihitl, ihitm, ihitr,
fIstaL,
fIstaM,
fIstaR, 0, 0, 0, chi2, qp, Cqp, tx, Ctx, ty, Cty,
543 const int iSta,
const fscal areaExtension,
const int maxNhits,
const McMatch& mc)
546 collectedHits.clear();
547 collectedHits.
reserve(maxNhits);
549 const auto& sta =
fSetup.GetActiveLayer(iSta);
550 const auto& grid =
frWData.Grid(iSta);
558 areaDx = areaExtension * areaDx;
559 areaDy = areaExtension * areaDy;
561 fscal dxExtended = areaDx + grid.GetMaxRangeX();
562 fscal dyExtended = areaDy + grid.GetMaxRangeY();
563 ca::GridArea area(grid, areaX, areaY, dxExtended, dyExtended);
566 LOG(info) <<
"search area: x " << areaX <<
" +-" << areaDx <<
", y " << areaY <<
" +-" << areaDy;
568 if (
fParameters.GetConfig().DevIgnoreHitSearchAreas()) {
574 if (
frWData.IsHitSuppressed(ih)) {
580 LOG(info) <<
"hit in the search area: " << hit.
ToString();
581 LOG(info) <<
" check the hit.. ";
588 LOG(info) <<
" hit mc does not match";
595 float dx = hit.
X() - areaX;
596 float dy = hit.
Y() - areaY;
597 if (fabs(dx) > areaDx + hit.
RangeX() || fabs(dy) > areaDy + hit.
RangeY()) {
605 if (sta.IsTimeMeasured()) {
606 if (fabs(time - hit.
T()) > 1.4 * (timeRange + hit.
RangeT())) {
608 LOG(info) <<
" hit time does not match";
629 const auto& grid =
frWData.Grid(iSta);
639 double bestDist2 = 1.e10;
642 if (
frWData.IsHitSuppressed(ih)) {
649 double dx = areaX - hit.
X();
650 double dy = areaY - hit.
Y();
651 double dist2 = dx * dx + dy * dy;
652 if (dist2 < bestDist2) {
Tracking Debugger class (implementation)
Macros for the CA tracking algorithm.
Triplet constructor for the CA tracker.
friend fvec sqrt(const fvec &a)
Track fit utilities for the CA tracking based on the Kalman filter.
Generates beam ions for transport simulation.
Class DoubletSearchWindowMap parameterisation for hit search area for doublets in the CA tracking.
SearchWindowMap::SearchWindow GetSearchWindow(float x, float y, float z, float dx, float dy) const
Class for accessing objects in the 2D area that are stored in ca::Grid.
bool GetNextObjectId(ca::HitIndex_t &objectId)
look up the next object id in the requested area
void DoLoopOverEntireGrid()
debug mode: loop over the entire GetEntries() vector ignoring the search area
ca::Hit class describes a generic hit for the CA tracker
fscal Z() const
Get the Z coordinate.
fscal RangeX() const
Get the +/- range of uncertainty of X coordinate.
std::string ToString() const
Simple string representation of the hit class.
fscal dX2() const
Get the uncertainty of X coordinate.
fscal Y() const
Get the Y coordinate.
fscal RangeY() const
Get the +/- range of uncertainty of Y coordinate.
fscal RangeT() const
Get the +/- range of uncertainty of time.
fscal T() const
Get the time.
fscal X() const
Get the X coordinate.
HitIndex_t Id() const
Get the hit id.
fscal dY2() const
Get the uncertainty of Y coordinate.
double GetStartX() const
Gets x component of the track vertex [cm].
double GetStartZ() const
Gets z component of the track vertex [cm].
double GetCharge() const
Gets charge [e].
int GetEventId() const
Gets index of MC event containing this track in external data structures.
double GetP() const
Gets absolute momentum [GeV/c].
double GetStartY() const
Gets y component of the track vertex [cm].
A container for all external parameters of the CA tracking algorithm.
Vector< ca::HitIndex_t > fDoubletData
void CreateTripletsForHit(Vector< ca::Triplet > &tripletsOut, int istal, int istam, int istar, ca::HitIndex_t ihl)
---— FUNCTIONAL PART ---—
static constexpr bool fDebugCollectHits
fscal fDefaultMass
mass of the propagated particle [GeV/c2]
int fIstaR
right station index
const SearchWindowMapContainer & fSwMaps
Search windows.
TripletConstructorSW(const ca::Framework &framework, const ca::Parameters< fvec > &pars, WindowData &wData, const fscal mass, const ca::TrackingMode &mode)
---— Constructors and destructor ---—
void FitTriplets(Vector< ca::Triplet > &tripletsOut)
Fit triplets on station.
int FindClosestHitWithMc(const SearchWindowMap::SearchWindow &area2D, const int iSta, const McMatch &mc)
bool InitStations(int istal, int istam, int istar)
ca::TrackingMode fTrackingMode
int fIstaL
left station index
const kf::ActiveLayer< fvec > * fStaM
mid station
bool fIsTargetField
is the magnetic field present at the target
const Parameters< fvec > & fParameters
Object of Framework parameters class.
void CollectHits(Vector< ca::HitIndex_t > &collectedHits, const SearchWindowMap::SearchWindow &area2D, fscal time, fscal timeRange, const int iSta, const fscal areaExtension, const int maxNhits, const McMatch &mc)
const cbm::algo::kf::Setup< fvec > & fSetup
Reference to the setup.
const kf::ActiveLayer< fvec > * fStaR
right station
const cbm::algo::kf::Field< fvec > & fField
Reference to field.
static constexpr bool fDebugTriplets
void SuppressDoubletClones()
Find the doublets. Reformat data in the portion of doublets.
const kf::ActiveLayer< fvec > * fStaL
left station
int fIstaM
middle station index
const ca::Framework & fFramework
Reference to the Framework object.
static constexpr bool fDebugDublets
ca::HitIndex_t fIhitL
index of the left hit in fAlgo->fWindowHits
Class TripletSearchWindowMap parameterisation for hit search area for Triplets in the CA tracking.
std::tuple< SearchWindowMap::SearchWindow, float > GetSearchWindowAndMs(float x1, float y1, float z1, float dx1, float dy1, float x2, float y2, float z2, float dx2, float dy2) const
void shrink(std::size_t count)
Reduces the vector to a given size.
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 emplace_back(Tinput &&... value)
Creates a parameter in the end of the vector.
Container for internal data, processed on a single time window.
static Debugger & Instance()
Instance.
virtual void FillNtuple(const char *name, float v[])=0
Add an entry to ntuple.
virtual void AddNtuple(const char *name, const char *varlist)=0
Set new ntuple.
Magnetic field region, corresponding to a hit triplet.
static FieldRegion CopyConvert(const FieldRegion< I > &other)
Creates a converted copy of the field with a different floating point type.
The class describes a 2D - measurement (x, y) in XY coordinate system.
TODO: SZh 8.11.2022: add selection of parameterisation.
unsigned int HitIndex_t
Index of ca::Hit.
constexpr auto SpeedOfLight
Speed of light [cm/ns].