NAIA
 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 void TrdKBaseData::Fill(TrdKCluster *trdkPtr, TrTrackR *pTrTrack) {
18  AlignStatus = trdkPtr->IsReadAlignmentOK;
19  CalibStatus = trdkPtr->IsReadCalibOK;
20  if (!AlignStatus || !CalibStatus)
21  return;
22 
23  if (trdkPtr->NHits() < 1)
24  return;
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  if (!_isStandalone) {
72  int status = trdkPtr->GetTrTrackExtrapolation(trd_point, trd_dir);
73  if (status >= 0) {
74  for (unsigned int i = 0; i < trdkPtr->NHits(); i++) {
75  TrdKHit *hit = trdkPtr->GetHit(i);
76  if (!hit)
77  continue;
78  float tube_length = hit->Tube_Track_3DLength(&trd_point, &trd_dir);
79  if (tube_length <= 0.02)
80  continue;
81  float amplitude = hit->TRDHit_Amp;
82  if (amplitude <= 0)
83  continue;
84  if (amplitude > 32767)
85  amplitude = 32767;
86  unsigned int ilay = hit->TRDHit_Layer;
87  if (amplitude <= Edep[ilay])
88  continue; // MaxADC
89  Edep[ilay] = amplitude;
90  Pathlength[ilay] = tube_length;
91  }
92  }
93  }
94 
95  Cleanliness = trdkPtr->GetCleanliness();
96  IPChi2 = trdkPtr->GetIPChi2();
97 
98  if (isValid && !_isStandalone && pTrTrack) {
99  // here do deuterium...
100  auto fit_ID_maxspan =
101  std::max(trkBase->_fit_ID.at(TrTrack::Fit::Choutko).at(trkBase->GetBestSpan(TrTrack::Fit::Choutko)), 0);
102  // trick for getting the deuteron likelihood
103  pTrTrack->Interpolate(TRDCenter, trd_point, trd_dir, fit_ID_maxspan);
104  float rigidity = pTrTrack->GetRigidity(fit_ID_maxspan);
105  trdkPtr->SetTrTrack(&trd_point, &trd_dir, 2 * rigidity);
106 
107  // this is the reason why YOU DON'T USE REFERENCES OR POINTERS FOR FUNCTION RETURNS!
108  int hitDummy;
109  float pathlDummy, ampDummy;
110  trdkPtr->GetLikelihoodRatio_TrTrack(threshold, _tmpLR, _tmpL, hitDummy, pathlDummy, ampDummy, -1, 0);
111 
112  if (Likelihood.size() == TrdK::numLikelihoodTypes - 1) {
113  Likelihood.resize(TrdK::numLikelihoodTypes);
114  Likelihood[LikelihoodType::Deuterium] = _tmpL[1];
115  }
116  }
117 
118  m_pointAndDir.emplace_back(trd_point.x(), trd_point.y(), trd_point.z());
119  m_pointAndDir.emplace_back(trd_dir.x(), trd_dir.y(), trd_dir.z());
120 }
121 
122 } // namespace NAIA
void ResizeMembers()
Definition: TrdKFill.cpp:11
Charge estimated using the upper half of the TRD.
Definition: Utils.h:226
constexpr unsigned int numQualTypes
Definition: Utils.h:262
constexpr std::array< LikelihoodRType, numLikelihoodRTypes > likelihoodRTypes
Definition: Utils.h:255
Hits laying off the TRD track (all the rest)
Definition: Utils.h:266
TrdK container class description.
constexpr unsigned int numLikelihoodTypes
Definition: Utils.h:236
Charge estimated using the whole TRD.
Definition: Utils.h:225
constexpr std::array< LikelihoodType, numLikelihoodTypes > likelihoodTypes
Definition: Utils.h:240
constexpr unsigned int numChargeTypes
Definition: Utils.h:222
static constexpr float TRDCenter
Definition: TrdKFill.cpp:9
static constexpr float threshold
Definition: TrdKFill.cpp:8
constexpr unsigned int numLikelihoodRTypes
Definition: Utils.h:247
standard track fit
Definition: Utils.h:174
Charge estimated using the lower half of the TRD.
Definition: Utils.h:227