NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
TrTrack.cpp
Go to the documentation of this file.
1 #include <bitset>
2 #include <fmt/format.h>
3 
4 #include "Containers/TrTrack.h"
5 
6 namespace NAIA {
7 const std::string TrTrackBase::BranchName = "TrTrackBaseData";
8 const std::string TrTrackPlus::BranchName = "TrTrackPlusData";
9 const std::string SecondTrTrackBase::BranchName = "SecondTrTrackBaseData";
10 const std::string TrTrackBaseStandalone::BranchName = "TrTrackBaseDataSt";
11 
12 using namespace TrTrack;
13 
14 bool TrTrackBaseData::FitIDExists(Fit fit, Span span) const {
15  return (Rigidity.find(fit) != end(Rigidity) && Rigidity.at(fit).find(span) != end(Rigidity.at(fit)));
16 }
17 
19  Span bestspan = FitIDExists(fit, Span::FullSpan)
21  : (FitIDExists(fit, Span::InnerL1) > 0
23  : (FitIDExists(fit, Span::InnerL9) > 0 ? Span::InnerL9 : Span::InnerOnly));
24  return bestspan;
25 }
26 
28  TrTrackHitPos.clear();
29  TrTrackFitPos.clear();
30 
31  Rigidity.clear();
32  TrChiSq.clear();
33 
34  Charge.clear();
35  ChargeRMS.clear();
36  InnerCharge.clear();
37  InnerChargeRMS.clear();
38  LayerChargeXY.clear();
39  LayerChargeStatus.clear();
40 
41  _beta = 1.0f;
42  _fit_ID.clear();
43 }
44 
46  TrackFeetDistance.clear();
47 
48  RigidityTOI.clear();
49  InvRigErr.clear();
50  PartialRigidity.clear();
51  PartialInvRigErr.clear();
52  PartialTrChiSq.clear();
53  PartialTrTrackResidual.clear();
54 
55  TrTrackResidual.clear();
56  UnbiasedCharge.clear();
57  LayerCharge.clear();
58  LayerEdep.clear();
59 
60  NClusters.clear();
61  ClustersEdep.clear();
62  MaxClusterEdep.clear();
63  MaxClusterDistance.clear();
64  ClusterSignalRatio.clear();
65 
66  DirectionalStoermerCutoff = {0, 0};
67 
68  _fit_ID.clear();
69 }
70 
71 void TrTrackBaseData::Dump() const {
72  fmt::print("{:=^120} \n", " TrTrackBaseData ");
73  if (!Rigidity.empty()) {
74  for (const auto &fitIter : Rigidity) {
75  fmt::print("Fit {}\n", TrTrack::fitNames[fitIter.first]);
76  fmt::print(" {:<30} {:>15} {:>15} {:>15}\n", "Span", "Rigidity", "TrChiSqX", "TrChiSqY");
77  for (auto spanIter : fitIter.second) {
78  fmt::print(" - {:<28} = {:> 12.4f} GV {:> 15.4f} {:> 15.4f}\n", TrTrack::spanNames[spanIter.first],
79  spanIter.second, TrChiSq.at(fitIter.first).at(spanIter.first).at(Side::X),
80  TrChiSq.at(fitIter.first).at(spanIter.first).at(Side::Y));
81  }
82  }
83  }
84 
85  if (!Charge.empty()) {
86  fmt::print("{:-^120}\n", "");
87  fmt::print("{:<32} {:>15} {:>15} {:>15} {:>32}\n", "Charge type", "Standard", "Hu Liu", "Yi Jia", "status");
88 
89  fmt::print(" - {:<28} = ", "Global charge");
90  for (auto chType : TrTrack::recoTypes) {
91  fmt::print("{:> 15.4f} ", ContainsKeys(Charge, chType) ? Charge.at(chType) : 0);
92  }
93  fmt::print("\n");
94 
95  fmt::print(" - {:<28} = ", "Inner tracker charge");
96  for (auto chType : TrTrack::recoTypes) {
97  fmt::print("{:> 15.4f} ", ContainsKeys(InnerCharge, chType) ? InnerCharge.at(chType) : 0);
98  }
99  fmt::print("\n");
100 
101  fmt::print(" - {:<28} = ", "Global charge RMS");
102  for (auto chType : TrTrack::recoTypes) {
103  fmt::print("{:> 15.4f} ", ContainsKeys(ChargeRMS, chType) ? ChargeRMS.at(chType) : 0);
104  }
105  fmt::print("\n");
106 
107  fmt::print(" - {:<28} = ", "Inner tracker charge RMS");
108  for (auto chType : TrTrack::recoTypes) {
109  fmt::print("{:> 15.4f} ", ContainsKeys(InnerChargeRMS, chType) ? InnerChargeRMS.at(chType) : 0);
110  }
111  fmt::print("\n");
112 
113  for (size_t ijl = 0; ijl < 9; ijl++) {
114  if (!ContainsKeys(LayerChargeXY, ijl))
115  continue;
116 
117  fmt::print(" - {:<28} = ", fmt::format("Layer {}", ijl));
118  for (auto chType : TrTrack::recoTypes) {
119  if (ContainsKeys(LayerChargeXY, ijl, chType))
120  fmt::print("{:> 15.4f} ", LayerChargeXY.at(ijl).at(chType));
121  else
122  fmt::print("{:>15} ", "");
123  }
124  std::bitset<32> dummy(ContainsKeys(LayerChargeStatus, ijl) ? LayerChargeStatus.at(ijl) : 0xFFFF);
125  fmt::print("{:>32} ", dummy.to_string());
126  fmt::print("\n");
127  }
128  }
129 
130  fmt::print("{:-^120}\n", "");
131 }
132 
133 void TrTrackPlusData::Dump() const {
134  fmt::print("{:=^120} \n", " TrTrackPlusData ");
135  if (!InvRigErr.empty()) {
136  for (const auto &fitIter : InvRigErr) {
137  fmt::print("Fit {}\n", TrTrack::fitNames[fitIter.first]);
138  if (RigidityTOI.find(fitIter.first) == end(RigidityTOI)) {
139  fmt::print(" {:<30} {:>15} {:>15}\n", "Span", "", "InvRigErr");
140  for (auto spanIter : fitIter.second) {
141  fmt::print(" - {:<28} = {:>15} {:>15}\n", TrTrack::spanNames[spanIter.first], "",
142  InvRigErr.at(fitIter.first).at(spanIter.first));
143  }
144  } else {
145  fmt::print(" {:<30} {:>15} {:>15}\n", "Span", "RigidityTOI", "InvRigErr");
146  for (auto spanIter : fitIter.second) {
147  fmt::print(" - {:<28} = {:> 12.4f} GV {:>15}\n", TrTrack::spanNames[spanIter.first],
148  RigidityTOI.at(fitIter.first).at(spanIter.first), InvRigErr.at(fitIter.first).at(spanIter.first));
149  }
150  }
151  }
152  }
153 
154  fmt::print("{:-^120}\n", "");
155  fmt::print("{:<32} {:>15} {:>15} {:>15} {:>15}\n", "\"Partial\" variables", "Rigidity", "InvRigErr", "TrChiSqX",
156  "TrChiSqY");
157  for (unsigned int ijl = 0; ijl < 9; ijl++) {
158  if (!ContainsKeys(PartialRigidity, ijl))
159  continue;
160 
161  for (auto &fitIter : PartialRigidity.at(ijl)) {
162  auto fit = fitIter.first;
163 
164  fmt::print(" - {:<28} = {:>15} {:>15} {:>15} {:>15}\n",
165  fmt::format("Layer {} - Fit {}", ijl + 1, TrTrack::fitNames[fit]), PartialRigidity.at(ijl).at(fit),
166  PartialInvRigErr.at(ijl).at(fit), PartialTrChiSq.at(ijl).at(fit).at(TrTrack::Side::X),
167  PartialTrChiSq.at(ijl).at(fit).at(TrTrack::Side::Y));
168  }
169  }
170 
171  if (!LayerCharge.empty()) {
172  fmt::print("{:-^120}\n", "");
173  fmt::print("{:<32} {:>15} {:>15} {:>15}\n", "Charge type", "Standard", "Hu Liu", "Yi Jia");
174  for (size_t ijl = 0; ijl < 9; ijl++) {
175  fmt::print(" - {:<28} = ", fmt::format("Layer {} X", ijl));
176  for (auto chType : TrTrack::recoTypes) {
177  if (ContainsKeys(LayerCharge, ijl, chType, TrTrack::Side::X))
178  fmt::print("{:> 15.4f} ", LayerCharge.at(ijl).at(chType).at(TrTrack::Side::X));
179  else
180  fmt::print("{:>15} ", "");
181  }
182  fmt::print("\n");
183  fmt::print(" - {:<28} = ", fmt::format("Layer {} Y", ijl));
184  for (auto chType : TrTrack::recoTypes) {
185  if (ContainsKeys(LayerCharge, ijl, chType, TrTrack::Side::Y))
186  fmt::print("{:> 15.4f} ", LayerCharge.at(ijl).at(chType).at(TrTrack::Side::Y));
187  else
188  fmt::print("{:>15} ", "");
189  }
190  fmt::print("\n");
191  }
192  }
193  fmt::print("{:-^120}\n", "");
194 }
195 
197  auto result = std::bitset<9>{0};
198 
199  for (unsigned int i = 0u; i < 9; ++i) {
200  if (ContainsKeys(TrTrackHitPos, i, side)) {
201  result[i] = true;
202  }
203  }
204 
205  return result;
206 }
207 } // namespace NAIA
constexpr std::array< ChargeRecoType, numChargeRecos > recoTypes
Definition: Utils.h:96
static const std::string BranchName
Definition: TrTrack.h:264
bool FitIDExists(TrTrack::Fit fit, TrTrack::Span span) const
Check if a given combination of fit and span is available for this track.
Definition: TrTrack.cpp:14
static const std::string BranchName
Definition: TrTrack.h:249
void Dump() const
Dump on screen container content.
Definition: TrTrack.cpp:133
static const std::array< std::string, numFits > fitNames
Definition: Utils.h:188
TrTrack::Span GetBestSpan(TrTrack::Fit fit=TrTrack::Fit::Choutko) const
Get the best Span available for this track.
Definition: TrTrack.cpp:18
Track constructed with inner tracker + layer9 hits.
Definition: Utils.h:160
TrTrack container class description.
void Clear()
Clear container content.
Definition: TrTrack.cpp:27
static const std::string BranchName
Definition: TrTrack.h:234
std::bitset< 9 > GetTrackPattern(TrTrack::Side side)
Get the track pattern for a given tracker side. One bit per layer, set to 1 if there is a hit on that...
Definition: TrTrack.cpp:196
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
static const std::string BranchName
Definition: TrTrack.h:219
NAIAChain::EventItr end(NAIAChain &chain)
Definition: NAIAChain.h:298
static const std::array< std::string, numSpans > spanNames
Definition: Utils.h:171
void Dump() const
Dump on screen container content.
Definition: TrTrack.cpp:71
void Clear()
Clear container content.
Definition: TrTrack.cpp:45