NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
TrdKFill.cpp
Go to the documentation of this file.
1 #include "Containers/TrdK.h"
2 
3 #include <iostream>
4 
5 namespace NAIA {
6 using namespace TrdK;
7 
8 static constexpr float threshold = 15;
9 static constexpr float TRDCenter = 115;
10 
12  NHits.resize(TrdK::numQualTypes);
13  Amps.resize(TrdK::numQualTypes);
14  Charge.resize(TrdK::numChargeTypes);
15 }
16 
17 bool TrdKBaseData::Fill(TrdKCluster *trdkPtr, TrTrackR *pTrTrack) {
18  AlignStatus = TrdKCluster::IsReadAlignmentOK;
19  CalibStatus = TrdKCluster::IsReadCalibOK;
20  if (!AlignStatus || !CalibStatus)
21  return false;
22 
23  if (trdkPtr->NHits() < 1)
24  return false;
25 
26  double _tmpLR[3], _tmpL[3];
27  float trd_pathl;
28 
29  int isValid;
30  int nhits;
31  float amps;
32  if (!_isStandalone) {
33  isValid = trdkPtr->GetLikelihoodRatio_TrTrack(threshold, _tmpLR, _tmpL, nhits, trd_pathl, amps);
34  } else {
35  isValid = trdkPtr->GetLikelihoodRatio_TRDRefit(threshold, _tmpLR, _tmpL, nhits, trd_pathl, amps);
36  }
37 
38  ResizeMembers();
39 
40  NHits[QualType::OnTrack] = nhits;
41  Amps[QualType::OnTrack] = amps;
42 
43  AMSPoint trd_point;
44  AMSDir trd_dir;
45  if (isValid) {
46  Likelihood.resize(TrdK::numLikelihoodTypes - 1);
47  for (auto ltype : likelihoodTypes) {
48  // we deal with deuterium later...
49  if (ltype == LikelihoodType::Deuterium)
50  continue;
51 
52  Likelihood[ltype] = _tmpL[ltype];
53  }
54 
55  LikelihoodRatio.resize(TrdK::numLikelihoodRTypes);
56  for (auto ltype : likelihoodRTypes) {
57  LikelihoodRatio[ltype] = _tmpLR[ltype];
58  }
59  }
60 
61  ChargeStatus = trdkPtr->CalculateTRDCharge(0, _beta);
62  Charge[ChargeType::Total] = trdkPtr->GetTRDCharge();
63  Charge[ChargeType::Upper] = trdkPtr->GetTRDChargeUpper();
64  Charge[ChargeType::Lower] = trdkPtr->GetTRDChargeLower();
65 
66  trdkPtr->GetOffTrackHit_TrTrack(NHits[QualType::OffTrack], Amps[QualType::OffTrack]);
67 
68  trdkPtr->FitTRDTrack();
69  trdkPtr->GetTRDRefittedTrack(trd_point, trd_dir);
70 
71  // Once again, I come to you to complain about the worst API ever designed: gbatch
72  // 5 LOC when 2 would have been enough
73  double tmp;
74  AMSEventR::Head()->GetStoermerCutoff(tmp, -1, trd_dir);
75  DirectionalStoermerCutoff[0] = tmp;
76  AMSEventR::Head()->GetStoermerCutoff(tmp, 1, trd_dir);
77  DirectionalStoermerCutoff[1] = tmp;
78 
79  if (!_isStandalone) {
80  int status = trdkPtr->GetTrTrackExtrapolation(trd_point, trd_dir);
81  if (status >= 0) {
82  for (unsigned int i = 0; i < trdkPtr->NHits(); i++) {
83  TrdKHit *hit = trdkPtr->GetHit(i);
84  if (!hit)
85  continue;
86  float tube_length = hit->Tube_Track_3DLength(&trd_point, &trd_dir);
87  if (tube_length <= 0.02)
88  continue;
89  float amplitude = hit->TRDHit_Amp;
90  if (amplitude <= 0)
91  continue;
92  if (amplitude > 32767)
93  amplitude = 32767;
94  unsigned int ilay = hit->TRDHit_Layer;
95  if (amplitude <= Edep[ilay])
96  continue; // MaxADC
97  Edep[ilay] = amplitude;
98  Pathlength[ilay] = tube_length;
99  }
100  }
101  }
102 
103  Cleanliness = trdkPtr->GetCleanliness();
104  IPChi2 = trdkPtr->GetIPChi2();
105 
106  if (isValid && !_isStandalone && pTrTrack) {
107  // here do deuterium...
108  auto fit_ID_maxspan =
109  std::max(trkBase->_fit_ID.at(TrTrack::Fit::Choutko).at(trkBase->GetBestSpan(TrTrack::Fit::Choutko)), 0);
110  // trick for getting the deuteron likelihood
111  pTrTrack->Interpolate(TRDCenter, trd_point, trd_dir, fit_ID_maxspan);
112  float rigidity = pTrTrack->GetRigidity(fit_ID_maxspan);
113  trdkPtr->SetTrTrack(&trd_point, &trd_dir, 2 * rigidity);
114 
115  // this is the reason why YOU DON'T USE REFERENCES OR POINTERS FOR FUNCTION RETURNS!
116  int hitDummy;
117  float pathlDummy, ampDummy;
118  trdkPtr->GetLikelihoodRatio_TrTrack(threshold, _tmpLR, _tmpL, hitDummy, pathlDummy, ampDummy, -1, 0);
119 
120  if (Likelihood.size() == TrdK::numLikelihoodTypes - 1) {
121  Likelihood.resize(TrdK::numLikelihoodTypes);
122  Likelihood[LikelihoodType::Deuterium] = _tmpL[1];
123  }
124  }
125 
126  m_pointAndDir.emplace_back(trd_point.x(), trd_point.y(), trd_point.z());
127  m_pointAndDir.emplace_back(trd_dir.x(), trd_dir.y(), trd_dir.z());
128 
129  return true;
130 }
131 
132 } // namespace NAIA
void ResizeMembers()
Definition: TrdKFill.cpp:11
Charge estimated using the upper half of the TRD.
Definition: Utils.h:233
constexpr unsigned int numQualTypes
Definition: Utils.h:269
constexpr std::array< LikelihoodRType, numLikelihoodRTypes > likelihoodRTypes
Definition: Utils.h:262
Hits laying off the TRD track (all the rest)
Definition: Utils.h:273
TrdK container class description.
constexpr unsigned int numLikelihoodTypes
Definition: Utils.h:243
Charge estimated using the whole TRD.
Definition: Utils.h:232
constexpr std::array< LikelihoodType, numLikelihoodTypes > likelihoodTypes
Definition: Utils.h:247
constexpr unsigned int numChargeTypes
Definition: Utils.h:229
static constexpr float TRDCenter
Definition: TrdKFill.cpp:9
static constexpr float threshold
Definition: TrdKFill.cpp:8
constexpr unsigned int numLikelihoodRTypes
Definition: Utils.h:254
standard track fit
Definition: Utils.h:180
Charge estimated using the lower half of the TRD.
Definition: Utils.h:234