NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
UnbExtHitFill.cpp
Go to the documentation of this file.
1 #include "Containers/UnbExtHit.h"
2 
3 namespace NAIA {
4 
5 bool UnbExtHitBaseData::Fill(AMSEventR *evPtr, bool use_trd) {
6 
7  auto fillHit = [this](ExtHit type, TrRecHitR *hit, int imult, float beta, const TVector3 &interp_direction) {
8  float tof_dxdz = interp_direction.x() / interp_direction.z();
9  float tof_dydz = interp_direction.y() / interp_direction.z();
10 
11  m_hits[type].ChargeStatus = hit->GetQStatus();
12  m_hits[type].HitPosX = hit->GetCoord(imult).x();
13  m_hits[type].HitPosY = hit->GetCoord(imult).y();
14  m_hits[type].Charge[TrTrack::ChargeRecoType::STD] = hit->GetQ(2, beta, 0, 0, imult, tof_dxdz, tof_dydz);
15  m_hits[type].Charge[TrTrack::ChargeRecoType::HL] = hit->GetQH(2, beta, 0, imult, tof_dxdz, tof_dydz);
16  m_hits[type].Charge[TrTrack::ChargeRecoType::YJ] = hit->GetQYJ(2, beta, 0, imult, tof_dxdz, tof_dydz);
17  };
18 
19  constexpr auto tof_beta_type = Tof::BetaType::BetaH;
20  constexpr auto tof_charge_type = Tof::ChargeType::Upper;
21 
22  // need at least a good beta and charge measurement
23  if (!ContainsKeys(tofBase->Beta, tof_beta_type) || !ContainsKeys(tofBase->Charge, tof_charge_type))
24  return false;
25 
26  float tof_beta = tofBase->Beta.at(tof_beta_type);
27  const auto &interp_direction = use_trd ? trdBase->GetLineDirection() : tofBase->GetLineDirection();
28 
29  // Search unbiased hits on external layers
30  TrRecHitR *hitL1 = nullptr;
31  TrRecHitR *hitL9 = nullptr;
32  int multL1{0};
33  int multL9{0};
34 
35  if (floor(tofBase->Charge.at(tof_charge_type) + 0.5) > 1) {
36  // Case Helium or higher we use the highest charge hit
37  float prev_charge1 = 0;
38  float prev_charge9 = 0;
39  for (TrRecHitR &hit : evPtr->TrRecHit()) {
40  if (hit.OnlyY() || (hit.GetLayerJ() != 1 && hit.GetLayerJ() != 9))
41  continue;
42 
43  // Solve multiplicity with tof standalone
44  int imult{0};
45  TVector3 vInterp =
46  use_trd ? trdBase->InterpolateAtZ(hit.GetCoord().z()) : tofBase->InterpolateAtZ(hit.GetCoord().z());
47  AMSPoint interp_point = AMSPoint(vInterp[0], vInterp[1], vInterp[2]);
48  hit.HitPointDist(interp_point, imult); // again, how can I know imult is an output variable?
49 
50  float interp_dxdz = interp_direction.x() / interp_direction.z();
51  float interp_dydz = interp_direction.y() / interp_direction.z();
52 
53  float hit_charge = hit.GetQYJ(2, tof_beta, 0, imult, interp_dxdz, interp_dydz);
54 
55  if (hit.GetLayerJ() == 1) {
56  if (hit_charge > prev_charge1) {
57  hitL1 = &hit;
58  multL1 = imult;
59  prev_charge1 = hit_charge;
60  }
61  } else if (hit.GetLayerJ() == 9) {
62  if (hit_charge > prev_charge9) {
63  hitL9 = &hit;
64  multL9 = imult;
65  prev_charge9 = hit_charge;
66  }
67  }
68  }
69 
70  if (hitL1 != nullptr) {
71  fillHit(ExtHit::L1, hitL1, multL1, tof_beta, interp_direction);
72  }
73  if (hitL9 != nullptr) {
74  fillHit(ExtHit::L9, hitL9, multL9, tof_beta, interp_direction);
75  }
76 
77  } else if (tofBase->Charge.at(tof_charge_type) > 0) {
80 
81  TVector3 vL1Int = use_trd ? trdBase->InterpolateAtZ(l1Z) : tofBase->InterpolateAtZ(l1Z);
82  TVector3 vL9Int = use_trd ? trdBase->InterpolateAtZ(l9Z) : tofBase->InterpolateAtZ(l9Z);
83 
84  AMSPoint interp_point_L1 = AMSPoint(vL1Int[0], vL1Int[1], vL1Int[2]);
85  AMSPoint interp_point_L9 = AMSPoint(vL9Int[0], vL9Int[1], vL9Int[2]);
86 
87  float prev_dist1 = std::numeric_limits<float>::max();
88  float prev_dist9 = std::numeric_limits<float>::max();
89  int mult1 = -1, mult9 = -1;
90 
91  for (TrRecHitR &hit : evPtr->TrRecHit()) {
92  if (hit.OnlyY() || (hit.GetLayerJ() != 1 && hit.GetLayerJ() != 9))
93  continue;
94 
95  if (hit.GetLayerJ() == 1) {
96  if (hit.HitPointDist(interp_point_L1, mult1).norm() < prev_dist1) {
97  hitL1 = &hit;
98  prev_dist1 = hitL1->HitPointDist(interp_point_L1, mult1).norm();
99  }
100  } else if (hit.GetLayerJ() == 9) {
101  if (hit.HitPointDist(interp_point_L9, mult9).norm() < prev_dist9) {
102  hitL9 = &hit;
103  prev_dist9 = hitL9->HitPointDist(interp_point_L9, mult9).norm();
104  }
105  }
106  }
107 
108  if (hitL1 != nullptr)
109  fillHit(ExtHit::L1, hitL1, mult1, tof_beta, interp_direction);
110  if (hitL9 != nullptr)
111  fillHit(ExtHit::L9, hitL9, mult9, tof_beta, interp_direction);
112  }
113 
114  return true;
115 }
116 } // namespace NAIA
UnbExtHit container class description.
const TrdKBaseData * trdBase
needed to get basic info without computing twice
Definition: UnbExtHit.h:104
TofBetaVariable< float > Beta
Beta measurement, one for each type. See Tof::BetaType for list of types.
Definition: Tof.h:49
Hu Liu reconstruction.
Definition: Utils.h:92
constexpr std::array< float, numFitPositionHeights > fitPositionHeightZ
Definition: Utils.h:135
Charge estimated using the upper half of the TRD.
Definition: Utils.h:233
TVector3 InterpolateAtZ(float z) const
Get Trd track interpolation at given height.
Definition: TrdK.cpp:98
IHEP reconstruction.
Definition: Utils.h:349
TVector3 InterpolateAtZ(float z) const
Get Tof track interpolation at given height.
Definition: Tof.cpp:33
TofChargeVariable< float > Charge
Charge measurement obtained using only layers for which GoodPathl is true. One for each type...
Definition: Tof.h:50
const TofBaseData * tofBase
Definition: UnbExtHit.h:103
std::map< ExtHit, HitData > m_hits
Definition: UnbExtHit.h:119
const TVector3 & GetLineDirection() const
Get the direction of the Tof clusters linear fit.
Definition: Tof.h:97
ExtHit
Handy enum to distinguish L1 and L9.
Definition: UnbExtHit.h:42
std::enable_if< std::is_convertible< Key, size_t >::value, bool >::type ContainsKeys(const std::array< T, N > &container, Key key)
Definition: Utils.hpp:53
const TVector3 & GetLineDirection() const
Get the direction of the TrdK clusters linear fit.
Definition: TrdK.h:140
Yi Jia reconstruction.
Definition: Utils.h:93
Standard tracker charge reconstruction.
Definition: Utils.h:91