SpacePoint3DDrawerHitCharge_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file SpacePoint3DDrawerHitCharge_tool.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
9 
12 #include "canvas/Persistency/Common/FindManyP.h"
13 
14 #include "TMath.h"
15 #include "TPolyMarker3D.h"
16 
17 namespace evdb_tool
18 {
19 
21 {
22 public:
24 
26 
27  void Draw(const std::vector<art::Ptr<recob::SpacePoint>>&, // Space points
28  evdb::View3D*, // 3D display
29  int, // Color
30  int, // Marker
31  float, // Size) const override;
32  const art::FindManyP<recob::Hit>* // pointer to associated hits
33  ) const;
34 
35 private:
37  const art::FindManyP<recob::Hit>* ) const;
38  double chargeIntegral(double,double,double,double,int,int) const;
39 
43 };
44 
45 //----------------------------------------------------------------------
46 // Constructor.
48 {
49 // fNumPoints = pset.get< int>("NumPoints", 1000);
50 // fFloatBaseline = pset.get<bool>("FloatBaseline", false);
51  // For now only draw cryostat=0.
52  fUseAbsoluteScale = pset.get<bool >("UseAbsoluteScale", false);
53  fMinHitCharge = pset.get<float>("MinHitCharge", 0.);
54  fMaxHitCharge = pset.get<float>("MaxHitCharge", 2500.);
55 
56  return;
57 }
58 
60 {
61  return;
62 }
63 
65  evdb::View3D* view,
66  int color,
67  int marker,
68  float size,
69  const art::FindManyP<recob::Hit>* hitAssnVec) const
70 {
71  // Let's not crash
72  if (hitsVec.empty() || !hitAssnVec) return;
73 
74  // Get services.
76 
77  using HitPosition = std::array<double,6>;
78  std::map<int,std::vector<HitPosition>> colorToHitMap;
79 
80  float minHitCharge(std::numeric_limits<float>::max());
81  float maxHitCharge(std::numeric_limits<float>::lowest());
82 
84  {
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  {
93  //float hitCharge = getSpacePointCharge(spacePoint, hitAssnVec);
94  float hitCharge = spacePoint->ErrXYZ()[1];
95 
96  minHitCharge = std::min(minHitCharge, hitCharge);
97  maxHitCharge = std::max(maxHitCharge, hitCharge);
98  }
99  }
100 
101  // Make sure we really have something here
102  if (maxHitCharge > minHitCharge)
103  {
104  float hitChiSqScale((cst->fRecoQHigh[geo::kCollection] - cst->fRecoQLow[geo::kCollection]) / (maxHitCharge - minHitCharge));
105 
106  for(const auto& spacePoint : hitsVec)
107  {
108  float hitCharge = getSpacePointCharge(spacePoint, hitAssnVec);
109 
110  if (hitCharge > 0.)
111  {
112  float chgFactor = cst->fRecoQLow[geo::kCollection] + hitChiSqScale * hitCharge;
113  int chargeColorIdx = cst->CalQ(geo::kCollection).GetColor(chgFactor);
114  const double* pos = spacePoint->XYZ();
115  const double* err = spacePoint->ErrXYZ();
116 
117  colorToHitMap[chargeColorIdx].push_back(HitPosition()={{pos[0],pos[1],pos[2],err[3],err[3],err[5]}});
118  }
119  }
120 
121  for(auto& hitPair : colorToHitMap)
122  {
123  TPolyMarker3D& pm = view->AddPolyMarker3D(hitPair.second.size(), hitPair.first, kFullDotLarge, 0.25);
124  for (const auto& hit : hitPair.second) pm.SetNextPoint(hit[0],hit[1],hit[2]);
125  }
126  }
127 
128  return;
129 }
130 
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  {
145  int hitStart = hit2D->PeakTime() - 2. * hit2D->RMS() - 0.5;
146  int hitStop = hit2D->PeakTime() + 2. * hit2D->RMS() + 0.5;
147 
148  lowIndex = std::max(hitStart, lowIndex);
149  hiIndex = std::min(hitStop + 1, hiIndex);
150 
151  hitCharge += hit2D->Integral();
152  }
153 
154  if (!hit2DVec.empty()) hitCharge /= float(hit2DVec.size());
155 
156  if (hitCharge > 0.)
157  {
158  if (hiIndex > lowIndex)
159  {
160  for(const auto& hit2D : hit2DVec)
161  totalCharge += chargeIntegral(hit2D->PeakTime(),hit2D->PeakAmplitude(),hit2D->RMS(),1.,lowIndex,hiIndex);
162 
163  totalCharge /= float(hit2DVec.size());
164  }
165  }
166 
167  return totalCharge;
168 }
169 
171  double peakAmp,
172  double peakWidth,
173  double areaNorm,
174  int low,
175  int hi) const
176 {
177  double integral(0);
178 
179  for(int sigPos = low; sigPos < hi; sigPos++) integral += peakAmp * TMath::Gaus(double(sigPos)+0.5,peakMean,peakWidth);
180 
181  return integral;
182 }
183 
185 }
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
struct vector vector
double getSpacePointCharge(const art::Ptr< recob::SpacePoint > &, const art::FindManyP< recob::Hit > *) const
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
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
double chargeIntegral(double, double, double, double, int, int) const
key_type key() const noexcept
Definition: Ptr.h:216
T get(std::string const &key) const
Definition: ParameterSet.h:271
const evdb::ColorScale & CalQ(geo::SigType_t st) const
static int max(int a, int b)
void err(const char *fmt,...)
Definition: message.cpp:226
Detector simulation of raw signals on wires.
std::size_t color(std::string const &procname)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void Draw(const std::vector< art::Ptr< recob::SpacePoint >> &, evdb::View3D *, int, int, float, const art::FindManyP< recob::Hit > *) const
Signal from collection planes.
Definition: geo_types.h:146