NAIA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
TrTrack.cpp
Go to the documentation of this file.
1 #include "fmt/format.h"
2 #include <bitset>
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 
10 using namespace TrTrack;
11 
12 float ApplyGeomCorrection(const TrackFitVariable<float> &Rigidity, Fit fit, Span span, TrGeometry trGeom) {
13  if (!ContainsKeys(Rigidity, fit, span)) {
14  return 0;
15  }
16 
17  static constexpr float corr = 0.0993e-3;
18 
19  switch (trGeom) {
21  if (span == Span::InnerOnly || span == Span::InnerL1)
22  break;
23  else
24  return Rigidity.at(fit).at(span);
27  break;
28  default:
29  return Rigidity.at(fit).at(span);
30  }
31 
32  return 1.0 / (1.0 / Rigidity.at(fit).at(span) + corr);
33 }
34 
36  return ApplyGeomCorrection(RigidityCorr, fit, span, trGeom);
37 }
38 
40  return ApplyGeomCorrection(Rigidity, fit, span, trGeom);
41 }
42 
44  return ApplyGeomCorrection(RigidityTOI, fit, span, trGeom);
45 }
46 
47 bool TrTrackBaseData::FitIDExists(Fit fit, Span span) const {
48  return (RigidityCorr.find(fit) != end(RigidityCorr) && RigidityCorr.at(fit).find(span) != end(RigidityCorr.at(fit)));
49 }
50 
52  Span bestspan = FitIDExists(fit, Span::FullSpan)
54  : (FitIDExists(fit, Span::InnerL1) > 0
56  : (FitIDExists(fit, Span::InnerL9) > 0 ? Span::InnerL9 : Span::InnerOnly));
57  return bestspan;
58 }
59 
61  RigidityCorr.clear();
62  TrChiSq.clear();
63 
64  Charge.clear();
65  InnerCharge.clear();
66  LayerChargeXY.clear();
67  LayerChargeStatus.clear();
68 
69  _beta = 1.0f;
70  _fit_ID.clear();
71 }
72 
74  TrTrackHitPos.clear();
75  TrackFeetDistance.clear();
76 
77  Rigidity.clear();
78  RigidityTOI.clear();
79  InvRigErr.clear();
80  PartialRigidity.clear();
81  PartialInvRigErr.clear();
82  PartialTrChiSq.clear();
83 
84  TrTrackResidual.clear();
85  TrTrackFitPos.clear();
86 
87  UnbiasedCharge.clear();
88  ChargeRMS.clear();
89  InnerChargeRMS.clear();
90 
91  LayerCharge.clear();
92 
93  LayerEdep.clear();
94 
95  NClusters.clear();
96  ClustersEdep.clear();
97  MaxClusterEdep.clear();
98  MaxClusterDistance.clear();
99  ClusterSignalRatio.clear();
100 
101  _fit_ID.clear();
102 }
103 
104 void TrTrackBaseData::Dump() const {
105  fmt::print("{:=^120} \n", " TrTrackBaseData ");
106  if (!RigidityCorr.empty()) {
107  for (const auto &fitIter : RigidityCorr) {
108  fmt::print("Fit {}\n", TrTrack::fitNames[fitIter.first]);
109  fmt::print(" {:<30} {:>15} {:>15} {:>15}\n", "Span", "RigidityCorr", "TrChiSqX", "TrChiSqY");
110  for (auto spanIter : fitIter.second) {
111  fmt::print(" - {:<28} = {:> 12.4f} GV {:> 15.4f} {:> 15.4f}\n", TrTrack::spanNames[spanIter.first],
112  spanIter.second, TrChiSq.at(fitIter.first).at(spanIter.first).at(Side::X),
113  TrChiSq.at(fitIter.first).at(spanIter.first).at(Side::Y));
114  }
115  }
116  }
117 
118  if (!Charge.empty()) {
119  fmt::print("{:-^120}\n", "");
120  fmt::print("{:<32} {:>15} {:>15} {:>15} {:>32}\n", "Charge type", "Standard", "Hu Liu", "Yi Jia", "status");
121 
122  fmt::print(" - {:<28} = ", "Global charge");
123  for (auto chType : TrTrack::recoTypes) {
124  fmt::print("{:> 15.4f} ", ContainsKeys(Charge, chType) ? Charge.at(chType) : 0);
125  }
126  fmt::print("\n");
127 
128  fmt::print(" - {:<28} = ", "Inner tracker charge");
129  for (auto chType : TrTrack::recoTypes) {
130  fmt::print("{:> 15.4f} ", ContainsKeys(InnerCharge, chType) ? InnerCharge.at(chType) : 0);
131  }
132  fmt::print("\n");
133 
134  for (size_t ijl = 0; ijl < 9; ijl++) {
135  fmt::print(" - {:<28} = ", fmt::format("Layer {}", ijl));
136  for (auto chType : TrTrack::recoTypes) {
137  if (ContainsKeys(LayerChargeXY, ijl, chType))
138  fmt::print("{:> 15.4f} ", LayerChargeXY.at(ijl).at(chType));
139  else
140  fmt::print("{:>15} ", "");
141  }
142  std::bitset<32> dummy(ContainsKeys(LayerChargeStatus, ijl) ? LayerChargeStatus.at(ijl) : 0xFFFF);
143  fmt::print("{:>32} ", dummy.to_string());
144  fmt::print("\n");
145  }
146  }
147 
148  fmt::print("{:-^120}\n", "");
149 }
150 
151 void TrTrackPlusData::Dump() const {
152  fmt::print("{:=^120} \n", " TrTrackPlusData ");
153  if (!Rigidity.empty()) {
154  for (const auto &fitIter : Rigidity) {
155  fmt::print("Fit {}\n", TrTrack::fitNames[fitIter.first]);
156  if (RigidityTOI.find(fitIter.first) == end(RigidityTOI)) {
157  fmt::print(" {:<30} {:>15} {:>15} {:>15}\n", "Span", "Rigidity", "", "InvRigErr");
158  for (auto spanIter : fitIter.second) {
159  fmt::print(" - {:<28} = {:> 12.4f} GV {:>15} {:>15}\n", TrTrack::spanNames[spanIter.first], spanIter.second,
160  "", InvRigErr.at(fitIter.first).at(spanIter.first));
161  }
162  } else {
163  fmt::print(" {:<30} {:>15} {:>15} {:>15}\n", "Span", "Rigidity", "RigidityTOI", "InvRigErr");
164  for (auto spanIter : fitIter.second) {
165  fmt::print(" - {:<28} = {:> 12.4f} GV {:> 12.4f} GV {:>15}\n", TrTrack::spanNames[spanIter.first],
166  spanIter.second, RigidityTOI.at(fitIter.first).at(spanIter.first),
167  InvRigErr.at(fitIter.first).at(spanIter.first));
168  }
169  }
170  }
171  }
172 
173  fmt::print("{:-^120}\n", "");
174  fmt::print("{:<32} {:>15} {:>15} {:>15} {:>15}\n", "\"Partial\" variables", "Rigidity", "InvRigErr", "TrChiSqX",
175  "TrChiSqY");
176  for (unsigned int ijl = 0; ijl < 9; ijl++) {
177  if (!ContainsKeys(PartialRigidity, ijl))
178  continue;
179 
180  for (auto &fitIter : PartialRigidity.at(ijl)) {
181  auto fit = fitIter.first;
182 
183  fmt::print(" - {:<28} = {:>15} {:>15} {:>15} {:>15}\n",
184  fmt::format("Layer {} - Fit {}", ijl + 1, TrTrack::fitNames[fit]), PartialRigidity.at(ijl).at(fit),
185  PartialInvRigErr.at(ijl).at(fit), PartialTrChiSq.at(ijl).at(fit).at(TrTrack::Side::X),
186  PartialTrChiSq.at(ijl).at(fit).at(TrTrack::Side::Y));
187  }
188  }
189 
190  if (!ChargeRMS.empty()) {
191  fmt::print("{:-^120}\n", "");
192  fmt::print("{:<32} {:>15} {:>15} {:>15}\n", "Charge type", "Standard", "Hu Liu", "Yi Jia");
193 
194  fmt::print(" - {:<28} = ", "Global charge RMS");
195  for (auto chType : TrTrack::recoTypes) {
196  fmt::print("{:> 15.4f} ", ContainsKeys(ChargeRMS, chType) ? ChargeRMS.at(chType) : 0);
197  }
198  fmt::print("\n");
199 
200  fmt::print(" - {:<28} = ", "Inner tracker charge RMS");
201  for (auto chType : TrTrack::recoTypes) {
202  fmt::print("{:> 15.4f} ", ContainsKeys(InnerChargeRMS, chType) ? InnerChargeRMS.at(chType) : 0);
203  }
204  fmt::print("\n");
205 
206  for (size_t ijl = 0; ijl < 9; ijl++) {
207  fmt::print(" - {:<28} = ", fmt::format("Layer {} X", ijl));
208  for (auto chType : TrTrack::recoTypes) {
209  if (ContainsKeys(LayerCharge, ijl, chType, TrTrack::Side::X))
210  fmt::print("{:> 15.4f} ", LayerCharge.at(ijl).at(chType).at(TrTrack::Side::X));
211  else
212  fmt::print("{:>15} ", "");
213  }
214  fmt::print("\n");
215  fmt::print(" - {:<28} = ", fmt::format("Layer {} Y", ijl));
216  for (auto chType : TrTrack::recoTypes) {
217  if (ContainsKeys(LayerCharge, ijl, chType, TrTrack::Side::Y))
218  fmt::print("{:> 15.4f} ", LayerCharge.at(ijl).at(chType).at(TrTrack::Side::Y));
219  else
220  fmt::print("{:>15} ", "");
221  }
222  fmt::print("\n");
223  }
224  }
225  fmt::print("{:-^120}\n", "");
226 }
227 } // namespace NAIA
constexpr std::array< ChargeRecoType, numChargeRecos > recoTypes
Definition: Utils.h:90
std::map< TrTrack::Fit, std::map< TrTrack::Span, T >> TrackFitVariable
Definition: TrTrack.h:33
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:47
void Dump() const
Dump on screen container content.
Definition: TrTrack.cpp:151
static const std::array< std::string, numFits > fitNames
Definition: Utils.h:181
TrTrack::Span GetBestSpan(TrTrack::Fit fit=TrTrack::Fit::Choutko) const
Get the best Span available for this track.
Definition: TrTrack.cpp:51
float GetGeomCorrectedRigidity(TrTrack::Fit fit, TrTrack::Span span, TrTrack::TrGeometry trGeom=TrTrack::TrGeometry::Default) const
Get the Rigidity variable after applying the geometry volume correction.
Definition: TrTrack.cpp:39
Track constructed with inner tracker + layer9 hits.
Definition: Utils.h:154
float ApplyGeomCorrection(const TrackFitVariable< float > &Rigidity, Fit fit, Span span, TrGeometry trGeom)
Definition: TrTrack.cpp:12
TrTrack container class description.
void Clear()
Clear container content.
Definition: TrTrack.cpp:60
SingleTreeChain::EventItr end(SingleTreeChain &chain)
static const std::string BranchName
Definition: TrTrack.h:256
std::enable_if< std::is_convertible< T, Key >::value, bool >::type ContainsKeys(const std::map< Key, Value > &container, T key)
Definition: Utils.hpp:69
float GetGeomCorrectedRigidityTOI(TrTrack::Fit fit, TrTrack::Span span, TrTrack::TrGeometry trGeom=TrTrack::TrGeometry::Default) const
Get the RigidityTOI variable after applying the geometry volume correction.
Definition: TrTrack.cpp:43
float GetGeomCorrectedRigidityCorr(TrTrack::Fit fit, TrTrack::Span span, TrTrack::TrGeometry trGeom=TrTrack::TrGeometry::Default) const
Get the RigidityCorr variable after applying the geometry volume correction.
Definition: TrTrack.cpp:35
static const std::string BranchName
Definition: TrTrack.h:241
static const std::array< std::string, numSpans > spanNames
Definition: Utils.h:165
void Dump() const
Dump on screen container content.
Definition: TrTrack.cpp:104
void Clear()
Clear container content.
Definition: TrTrack.cpp:73