From 40af0d1fdcdb87221f12cbe6fc79d01640271b59 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Sun, 15 May 2022 00:55:23 +0200
Subject: [PATCH] L1Algo: removed direct initialization of target position

---
 reco/L1/CbmL1.cxx                        |  3 ---
 reco/L1/L1Algo/L1Algo.cxx                | 17 ++++++++++++++---
 reco/L1/L1Algo/L1Algo.h                  | 24 ++++++++++++------------
 reco/L1/L1Algo/L1CATrackFinder.cxx       | 14 +++++++-------
 reco/L1/L1Algo/L1TrackExtender.cxx       |  2 +-
 reco/L1/ParticleFinder/CbmL1PFFitter.cxx |  4 ++--
 6 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index a9b184d296..c8c4b4f2b1 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -399,9 +399,6 @@ InitStatus CbmL1::Init()
   {  // initialize field in the target region
     assert(CbmKF::Instance()->vTargets.size() > 0);
     auto& target      = CbmKF::Instance()->vTargets[0];
-    algo->fCbmTargetX = target.x;
-    algo->fCbmTargetY = target.y;
-    algo->fCbmTargetZ = target.z;
 
     for (int i = 0; i < 3; i++) {
       Double_t point[3] = {0., 0., target.z + 2.5 * i};
diff --git a/reco/L1/L1Algo/L1Algo.cxx b/reco/L1/L1Algo/L1Algo.cxx
index a752cafbd2..cb73b1d137 100644
--- a/reco/L1/L1Algo/L1Algo.cxx
+++ b/reco/L1/L1Algo/L1Algo.cxx
@@ -93,7 +93,13 @@ void L1Algo::Init(const bool UseHitErrors, const TrackingMode mode, const bool M
 
   // Print out the bits of the init manager
   LOG(info) << "InitManager " << fInitManager.GetInitController().ToString();
-  
+ 
+  // Get real target position
+  fRealTargetX = fInitManager.GetTargetPosition()[0];
+  fRealTargetY = fInitManager.GetTargetPosition()[1];
+  fRealTargetZ = fInitManager.GetTargetPosition()[2];
+
+  // Get number of station
   fNstations = fInitManager.GetStationsNumber();
 
   // Get field near target
@@ -112,6 +118,11 @@ void L1Algo::Init(const bool UseHitErrors, const TrackingMode mode, const bool M
   LOG(info) << "  ***********************";
   LOG(info) << "";
 
+  LOG(info) << "----- Nominal target position -----";
+  LOG(info) << "\t target X = " << fRealTargetX;
+  LOG(info) << "\t target Y = " << fRealTargetY;
+  LOG(info) << "\t target Z = " << fRealTargetZ;
+
   LOG(info) << "----- Number of stations -----";
   LOG(info) << "\tTotal stations:           " << fNstations;
   LOG(info) << "\tStations before pipe:     " << fNstationsBeforePipe;
@@ -199,8 +210,8 @@ void L1Algo::GetHitCoor(const L1Hit& _h, fscal& _x, fscal& _y, char iS)
   L1Station& sta = fStations[int(iS)];
   fscal u        = _h.u;
   fscal v        = _h.v;
-  _x             = (sta.xInfo.sin_phi[0] * u + sta.xInfo.cos_phi[0] * v) / (_h.z - fCbmTargetZ[0]);
-  _y             = (sta.yInfo.cos_phi[0] * u + sta.yInfo.sin_phi[0] * v) / (_h.z - fCbmTargetZ[0]);
+  _x             = (sta.xInfo.sin_phi[0] * u + sta.xInfo.cos_phi[0] * v) / (_h.z - fRealTargetZ[0]);
+  _y             = (sta.yInfo.cos_phi[0] * u + sta.yInfo.sin_phi[0] * v) / (_h.z - fRealTargetZ[0]);
 }
 
 void L1Algo::GetHitCoor(const L1Hit& _h, fscal& _x, fscal& _y, fscal& _z, const L1Station& sta)
diff --git a/reco/L1/L1Algo/L1Algo.h b/reco/L1/L1Algo/L1Algo.h
index 55c7a385c8..9458d4c627 100644
--- a/reco/L1/L1Algo/L1Algo.h
+++ b/reco/L1/L1Algo/L1Algo.h
@@ -398,7 +398,7 @@ public:
   /// Gets a pointer to the L1Algo initialization object
   L1InitManager* GetInitManager() { return &fInitManager; }
 
-  fvec GetCbmTargetZ() const { return fCbmTargetZ; }
+  fvec GetTargetZ() const { return fRealTargetZ; }
 
 private:
   L1Parameters fParameters {};                ///< Object of L1Algo parameters class
@@ -687,17 +687,17 @@ private:
 
   /// parameters which are different for different iterations. Set in the begin of CAL1TrackFinder
 
-  float fPickGather {L1Utils::kNaN};     // same for attaching additional hits to track
-  float fPickNeighbour {L1Utils::kNaN};  // (fPickNeighbour < dp/dp_error)  =>  triplets are neighbours
-  fvec fMaxInvMom {L1Utils::kNaN};       // max considered q/p for tracks
-  fvec fMaxSlopePV {L1Utils::kNaN};      // max slope (tx\ty) in prim vertex
-  float fMaxSlope {L1Utils::kNaN};       // max slope (tx\ty) in 3d hit position of a triplet
-  fvec fCbmTargetX {L1Utils::kNaN};      // target position
-  fvec fCbmTargetY {L1Utils::kNaN};
-  fvec fCbmTargetZ {L1Utils::kNaN};
-  fvec fTargX {L1Utils::kNaN};  // target position for the current iteration
-  fvec fTargY {L1Utils::kNaN};
-  fvec fTargZ {L1Utils::kNaN};
+  float fPickGather {L1Utils::kNaN};     ///< same for attaching additional hits to track
+  float fPickNeighbour {L1Utils::kNaN};  ///< (fPickNeighbour < dp/dp_error)  =>  triplets are neighbours
+  fvec fMaxInvMom {L1Utils::kNaN};       ///< max considered q/p for tracks
+  fvec fMaxSlopePV {L1Utils::kNaN};      ///< max slope (tx\ty) in prim vertex
+  float fMaxSlope {L1Utils::kNaN};       ///< max slope (tx\ty) in 3d hit position of a triplet
+  fvec fRealTargetX {L1Utils::kNaN};      ///< real target position x coordinate
+  fvec fRealTargetY {L1Utils::kNaN};      ///< real target position y coordinate
+  fvec fRealTargetZ {L1Utils::kNaN};      ///< real target position z coordinate
+  fvec fTargX {L1Utils::kNaN};           ///< target position x coordinate for the current iteration (modifiable)
+  fvec fTargY {L1Utils::kNaN};           ///< target position y coordinate for the current iteration (modifiable)
+  fvec fTargZ {L1Utils::kNaN};           ///< target position z coordinate for the current iteration (modifiable)
 
   L1FieldValue fTargB _fvecalignment {};               // field in the target point
   L1XYMeasurementInfo TargetXYInfo _fvecalignment {};  // target constraint  [cm]
diff --git a/reco/L1/L1Algo/L1CATrackFinder.cxx b/reco/L1/L1Algo/L1CATrackFinder.cxx
index 8502c2daaf..fe2614da90 100644
--- a/reco/L1/L1Algo/L1CATrackFinder.cxx
+++ b/reco/L1/L1Algo/L1CATrackFinder.cxx
@@ -416,7 +416,7 @@ inline void L1Algo::f20(
     // Pick_m22 is not used, search for mean squared, 2nd version
 
     // -- collect possible doublets --
-    const fscal iz         = 1.f / (T1.z[i1_4] - fCbmTargetZ[0]);
+    const fscal iz         = 1.f / (T1.z[i1_4] - fRealTargetZ[0]);
     const float& timeError = T1.C55[i1_4];
     const float& time      = T1.t[i1_4];
 
@@ -726,7 +726,7 @@ inline void L1Algo::f30(  // input
 #ifdef DO_NOT_SELECT_TRIPLETS
         if (isec == TRACKS_FROM_TRIPLETS_ITERATION) Pick_r22 = Pick_r2 + 1;
 #endif  // DO_NOT_SELECT_TRIPLETS
-        const fscal iz = 1.f / (T2.z[i2_4] - fCbmTargetZ[0]);
+        const fscal iz = 1.f / (T2.z[i2_4] - fRealTargetZ[0]);
         L1HitAreaTime area(vGridTime[&star - fStations.begin()], T2.x[i2_4] * iz, T2.y[i2_4] * iz,
                            (sqrt(Pick_r22 * (T2.C00 + stam.XYInfo.C00)) + fMaxDZ * fabs(T2.tx))[i2_4] * iz,
                            (sqrt(Pick_r22 * (T2.C11 + stam.XYInfo.C11)) + fMaxDZ * fabs(T2.ty))[i2_4] * iz, time,
@@ -1885,9 +1885,9 @@ void L1Algo::CATrackFinder()
         //fMaxSlope = 2.748;  // corresponds to 70 grad
 
         // define the target
-        fTargX = fCbmTargetX;
-        fTargY = fCbmTargetY;
-        fTargZ = fCbmTargetZ;
+        fTargX = fRealTargetX;
+        fTargY = fRealTargetY;
+        fTargZ = fRealTargetZ;
 
         float SigmaTargetX = caIteration.GetTargetPosSigmaX();
         float SigmaTargetY = caIteration.GetTargetPosSigmaY();  // target constraint [cm]
@@ -1911,7 +1911,7 @@ void L1Algo::CATrackFinder()
         //    || (isec == kAllSecJumpIter)) {  //use outer radius of the 1st station as a constraint // ?
         //  L1Station& st = fStations[0];
         //  SigmaTargetX = SigmaTargetY = 10;  //st.Rmax[0];
-        //  fTargZ                      = fCbmTargetZ;  // fCbmTargetZ-1.;
+        //  fTargZ                      = fRealTargetZ;  // fRealTargetZ-1.;
         //  st.fieldSlice.GetFieldValue(0, 0, fTargB);
         //}
 
@@ -2395,7 +2395,7 @@ void L1Algo::CATrackFinder()
                 float xcoor, ycoor = 0;
                 L1Station stah = fStations[0];
                 StripsToCoor(tempPoint.U(), tempPoint.V(), xcoor, ycoor, stah);
-                float zcoor = tempPoint.Z() - fCbmTargetZ[0];
+                float zcoor = tempPoint.Z() - fRealTargetZ[0];
 
                 float timeFlight = sqrt(xcoor * xcoor + ycoor * ycoor + zcoor * zcoor) / 30.f;  // c = 30[cm/ns]
                 sumTime += (hit.t - timeFlight);
diff --git a/reco/L1/L1Algo/L1TrackExtender.cxx b/reco/L1/L1Algo/L1TrackExtender.cxx
index 8f0ac6d786..1746a9e9bb 100644
--- a/reco/L1/L1Algo/L1TrackExtender.cxx
+++ b/reco/L1/L1Algo/L1TrackExtender.cxx
@@ -267,7 +267,7 @@ void L1Algo::FindMoreHits(L1Branch& t, L1TrackPar& T, const bool dir,
     fscal r2_best = 1e8;  // best distance to hit
     int iHit_best = -1;   // index of the best hit
 
-    const fscal iz = 1.f / (T.z[0] - fCbmTargetZ[0]);
+    const fscal iz = 1.f / (T.z[0] - fRealTargetZ[0]);
 
 
     L1HitAreaTime area(vGridTime[ista], T.x[0] * iz, T.y[0] * iz,
diff --git a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
index 93a28ce71a..39f5912524 100644
--- a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
+++ b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
@@ -490,7 +490,7 @@ void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<L1FieldRe
     }
 
     fB[0]     = CbmL1::Instance()->algo->GetVtxFieldValue();
-    zField[0] = CbmL1::Instance()->algo->GetCbmTargetZ();
+    zField[0] = CbmL1::Instance()->algo->GetTargetZ();
     fld.Set(fB[2], zField[2], fB[1], zField[1], fB[0], zField[0]);
     field.push_back(fld);
 
@@ -629,7 +629,7 @@ void CbmL1PFFitter::CalculateFieldRegion(vector<CbmStsTrack>& Tracks, vector<L1F
     }
 
     fB[0]     = CbmL1::Instance()->algo->GetVtxFieldValue();
-    zField[0] = CbmL1::Instance()->algo->GetCbmTargetZ();
+    zField[0] = CbmL1::Instance()->algo->GetTargetZ();
     fld.Set(fB[2], zField[2], fB[1], zField[1], fB[0], zField[0]);
     field.push_back(fld);
   }
-- 
GitLab