LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SpacePoint3DDrawerHitCharge_tool.cc
Go to the documentation of this file.
1 
10 
12 
16 
17 #include "TMath.h"
18 #include "TPolyMarker3D.h"
19 
20 namespace evdb_tool {
21 
23  public:
25 
27 
28  void Draw(const std::vector<art::Ptr<recob::SpacePoint>>&, // Space points
29  evdb::View3D*, // 3D display
30  int, // Color
31  int, // Marker
32  float, // Size) const override;
33  const art::FindManyP<recob::Hit>* // pointer to associated hits
34  ) const;
35 
36  private:
38  const art::FindManyP<recob::Hit>*) const;
39  double chargeIntegral(double, double, double, double, int, int) const;
40 
44  };
45 
46  //----------------------------------------------------------------------
47  // Constructor.
49  {
50  // fNumPoints = pset.get< int>("NumPoints", 1000);
51  // fFloatBaseline = pset.get<bool>("FloatBaseline", false);
52  // For now only draw cryostat=0.
53  fUseAbsoluteScale = pset.get<bool>("UseAbsoluteScale", false);
54  fMinHitCharge = pset.get<float>("MinHitCharge", 0.);
55  fMaxHitCharge = pset.get<float>("MaxHitCharge", 2500.);
56 
57  return;
58  }
59 
61  {
62  return;
63  }
64 
66  evdb::View3D* view,
67  int color,
68  int marker,
69  float size,
70  const art::FindManyP<recob::Hit>* hitAssnVec) const
71  {
72  // Let's not crash
73  if (hitsVec.empty() || !hitAssnVec) return;
74 
75  // Get services.
77 
78  using HitPosition = std::array<double, 6>;
79  std::map<int, std::vector<HitPosition>> colorToHitMap;
80 
81  float minHitCharge(std::numeric_limits<float>::max());
82  float maxHitCharge(std::numeric_limits<float>::lowest());
83 
84  if (fUseAbsoluteScale) {
85  minHitCharge = fMinHitCharge;
86  maxHitCharge = fMaxHitCharge;
87  }
88  else
89  // Find the range in the input space point list
90  {
91  for (const auto& spacePoint : hitsVec) {
92  //float hitCharge = getSpacePointCharge(spacePoint, hitAssnVec);
93  float hitCharge = spacePoint->ErrXYZ()[1];
94 
95  minHitCharge = std::min(minHitCharge, hitCharge);
96  maxHitCharge = std::max(maxHitCharge, hitCharge);
97  }
98  }
99 
100  // Make sure we really have something here
101  if (maxHitCharge > minHitCharge) {
102  float hitChiSqScale((cst->fRecoQHigh[geo::kCollection] - cst->fRecoQLow[geo::kCollection]) /
103  (maxHitCharge - minHitCharge));
104 
105  for (const auto& spacePoint : hitsVec) {
106  float hitCharge = getSpacePointCharge(spacePoint, hitAssnVec);
107 
108  if (hitCharge > 0.) {
109  float chgFactor = cst->fRecoQLow[geo::kCollection] + hitChiSqScale * hitCharge;
110  int chargeColorIdx = cst->CalQ(geo::kCollection).GetColor(chgFactor);
111  const double* pos = spacePoint->XYZ();
112  const double* err = spacePoint->ErrXYZ();
113 
114  colorToHitMap[chargeColorIdx].push_back(
115  HitPosition() = {{pos[0], pos[1], pos[2], err[3], err[3], err[5]}});
116  }
117  }
118 
119  for (auto& hitPair : colorToHitMap) {
120  TPolyMarker3D& pm =
121  view->AddPolyMarker3D(hitPair.second.size(), hitPair.first, kFullDotLarge, 0.25);
122  for (const auto& hit : hitPair.second)
123  pm.SetNextPoint(hit[0], hit[1], hit[2]);
124  }
125  }
126 
127  return;
128  }
129 
131  const art::Ptr<recob::SpacePoint>& spacePoint,
132  const art::FindManyP<recob::Hit>* hitAssnVec) const
133  {
134  double totalCharge(0.);
135 
136  // Need to recover the integrated charge from the collection plane, so need to loop through associated hits
137  const std::vector<art::Ptr<recob::Hit>>& hit2DVec(hitAssnVec->at(spacePoint.key()));
138 
139  float hitCharge(0.);
140  int lowIndex(std::numeric_limits<int>::min());
141  int hiIndex(std::numeric_limits<int>::max());
142 
143  for (const auto& hit2D : hit2DVec) {
144  int hitStart = hit2D->PeakTime() - 2. * hit2D->RMS() - 0.5;
145  int hitStop = hit2D->PeakTime() + 2. * hit2D->RMS() + 0.5;
146 
147  lowIndex = std::max(hitStart, lowIndex);
148  hiIndex = std::min(hitStop + 1, hiIndex);
149 
150  hitCharge += hit2D->Integral();
151  }
152 
153  if (!hit2DVec.empty()) hitCharge /= float(hit2DVec.size());
154 
155  if (hitCharge > 0.) {
156  if (hiIndex > lowIndex) {
157  for (const auto& hit2D : hit2DVec)
158  totalCharge += chargeIntegral(
159  hit2D->PeakTime(), hit2D->PeakAmplitude(), hit2D->RMS(), 1., lowIndex, hiIndex);
160 
161  totalCharge /= float(hit2DVec.size());
162  }
163  }
164 
165  return totalCharge;
166  }
167 
169  double peakAmp,
170  double peakWidth,
171  double areaNorm,
172  int low,
173  int hi) const
174  {
175  double integral(0);
176 
177  for (int sigPos = low; sigPos < hi; sigPos++)
178  integral += peakAmp * TMath::Gaus(double(sigPos) + 0.5, peakMean, peakWidth);
179 
180  return integral;
181  }
182 
184 }
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
Declaration of signal hit object.
double getSpacePointCharge(const art::Ptr< recob::SpacePoint > &, const art::FindManyP< recob::Hit > *) const
int GetColor(double x) const
Definition: ColorScale.cxx:126
std::vector< double > fRecoQHigh
high edge of ADC values for drawing raw digits
std::vector< double > fRecoQLow
low edge of ADC values for drawing raw digits
The color scales used by the event display.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
double chargeIntegral(double, double, double, double, int, int) const
key_type key() const noexcept
Definition: Ptr.h:166
T get(std::string const &key) const
Definition: ParameterSet.h:314
const evdb::ColorScale & CalQ(geo::SigType_t st) const
Detector simulation of raw signals on wires.
std::size_t color(std::string const &procname)
void Draw(const std::vector< art::Ptr< recob::SpacePoint >> &, evdb::View3D *, int, int, float, const art::FindManyP< recob::Hit > *) const
A collection of 3D drawable objects.
TPolyMarker3D & AddPolyMarker3D(int n, int c, int st, double sz)
Definition: View3D.cxx:75
Signal from collection planes.
Definition: geo_types.h:152