All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpacePoint3DDrawerHitCharge_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file SpacePoint3DDrawerHitCharge_tool.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
10 
11 #include "nuevdb/EventDisplayBase/View3D.h"
12 
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "art/Utilities/ToolMacros.h"
15 #include "canvas/Persistency/Common/FindManyP.h"
16 
17 #include "TMath.h"
18 #include "TPolyMarker3D.h"
19 
20 namespace evdb_tool
21 {
22 
24 {
25 public:
26  explicit SpacePoint3DDrawerHitCharge(const fhicl::ParameterSet&);
27 
29 
30  void Draw(const std::vector<art::Ptr<recob::SpacePoint>>&, // Space points
31  evdb::View3D*, // 3D display
32  int, // Color
33  int, // Marker
34  float, // Size) const override;
35  const art::FindManyP<recob::Hit>* // pointer to associated hits
36  ) const;
37 
38 private:
39  double getSpacePointCharge(const art::Ptr<recob::SpacePoint>&,
40  const art::FindManyP<recob::Hit>* ) const;
41  double chargeIntegral(double,double,double,double,int,int) const;
42 
46 };
47 
48 //----------------------------------------------------------------------
49 // Constructor.
51 {
52 // fNumPoints = pset.get< int>("NumPoints", 1000);
53 // fFloatBaseline = pset.get<bool>("FloatBaseline", false);
54  // For now only draw cryostat=0.
55  fUseAbsoluteScale = pset.get<bool >("UseAbsoluteScale", false);
56  fMinHitCharge = pset.get<float>("MinHitCharge", 0.);
57  fMaxHitCharge = pset.get<float>("MaxHitCharge", 2500.);
58 
59  return;
60 }
61 
63 {
64  return;
65 }
66 
67 void SpacePoint3DDrawerHitCharge::Draw(const std::vector<art::Ptr<recob::SpacePoint>>& hitsVec,
68  evdb::View3D* view,
69  int color,
70  int marker,
71  float size,
72  const art::FindManyP<recob::Hit>* hitAssnVec) const
73 {
74  // Let's not crash
75  if (hitsVec.empty() || !hitAssnVec) return;
76 
77  // Get services.
78  art::ServiceHandle<evd::ColorDrawingOptions const> cst;
79 
80  using HitPosition = std::array<double,6>;
81  std::map<int,std::vector<HitPosition>> colorToHitMap;
82 
83  float minHitCharge(std::numeric_limits<float>::max());
84  float maxHitCharge(std::numeric_limits<float>::lowest());
85 
87  {
88  minHitCharge = fMinHitCharge;
89  maxHitCharge = fMaxHitCharge;
90  }
91  else
92  // Find the range in the input space point list
93  {
94  for(const auto& spacePoint : hitsVec)
95  {
96  //float hitCharge = getSpacePointCharge(spacePoint, hitAssnVec);
97  float hitCharge = spacePoint->ErrXYZ()[1];
98 
99  minHitCharge = std::min(minHitCharge, hitCharge);
100  maxHitCharge = std::max(maxHitCharge, hitCharge);
101  }
102  }
103 
104  // Make sure we really have something here
105  if (maxHitCharge > minHitCharge)
106  {
107  float hitChiSqScale((cst->fRecoQHigh[geo::kCollection] - cst->fRecoQLow[geo::kCollection]) / (maxHitCharge - minHitCharge));
108 
109  for(const auto& spacePoint : hitsVec)
110  {
111  float hitCharge = getSpacePointCharge(spacePoint, hitAssnVec);
112 
113  if (hitCharge > 0.)
114  {
115  float chgFactor = cst->fRecoQLow[geo::kCollection] + hitChiSqScale * hitCharge;
116  int chargeColorIdx = cst->CalQ(geo::kCollection).GetColor(chgFactor);
117  const double* pos = spacePoint->XYZ();
118  const double* err = spacePoint->ErrXYZ();
119 
120  colorToHitMap[chargeColorIdx].push_back(HitPosition()={{pos[0],pos[1],pos[2],err[3],err[3],err[5]}});
121  }
122  }
123 
124  for(auto& hitPair : colorToHitMap)
125  {
126  TPolyMarker3D& pm = view->AddPolyMarker3D(hitPair.second.size(), hitPair.first, kFullDotLarge, 0.25);
127  for (const auto& hit : hitPair.second) pm.SetNextPoint(hit[0],hit[1],hit[2]);
128  }
129  }
130 
131  return;
132 }
133 
134 double SpacePoint3DDrawerHitCharge::getSpacePointCharge(const art::Ptr<recob::SpacePoint>& spacePoint,
135  const art::FindManyP<recob::Hit>* hitAssnVec) const
136 {
137  double totalCharge(0.);
138 
139  // Need to recover the integrated charge from the collection plane, so need to loop through associated hits
140  const std::vector<art::Ptr<recob::Hit>>& hit2DVec(hitAssnVec->at(spacePoint.key()));
141 
142  float hitCharge(0.);
143  int lowIndex(std::numeric_limits<int>::min());
144  int hiIndex(std::numeric_limits<int>::max());
145 
146  for(const auto& hit2D : hit2DVec)
147  {
148  int hitStart = hit2D->PeakTime() - 2. * hit2D->RMS() - 0.5;
149  int hitStop = hit2D->PeakTime() + 2. * hit2D->RMS() + 0.5;
150 
151  lowIndex = std::max(hitStart, lowIndex);
152  hiIndex = std::min(hitStop + 1, hiIndex);
153 
154  hitCharge += hit2D->Integral();
155  }
156 
157  if (!hit2DVec.empty()) hitCharge /= float(hit2DVec.size());
158 
159  if (hitCharge > 0.)
160  {
161  if (hiIndex > lowIndex)
162  {
163  for(const auto& hit2D : hit2DVec)
164  totalCharge += chargeIntegral(hit2D->PeakTime(),hit2D->PeakAmplitude(),hit2D->RMS(),1.,lowIndex,hiIndex);
165 
166  totalCharge /= float(hit2DVec.size());
167  }
168  }
169 
170  return totalCharge;
171 }
172 
174  double peakAmp,
175  double peakWidth,
176  double areaNorm,
177  int low,
178  int hi) const
179 {
180  double integral(0);
181 
182  for(int sigPos = low; sigPos < hi; sigPos++) integral += peakAmp * TMath::Gaus(double(sigPos)+0.5,peakMean,peakWidth);
183 
184  return integral;
185 }
186 
187 DEFINE_ART_CLASS_TOOL(SpacePoint3DDrawerHitCharge)
188 }
Declaration of signal hit object.
EResult err(const char *call)
double getSpacePointCharge(const art::Ptr< recob::SpacePoint > &, const art::FindManyP< recob::Hit > *) const
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
process_name hit
Definition: cheaterreco.fcl:51
standard_dbscan3dalg useful for diagnostics hits not in a line will not be clustered on on only for track like only for track like on on the smaller the less shower like tracks low
The color scales used by the event display.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
double chargeIntegral(double, double, double, double, int, int) const
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