LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DrawSkewHits_tool.cc
Go to the documentation of this file.
1 
6 #include <cmath>
7 
14 
17 
22 
23 #include "TPolyLine.h"
24 
25 namespace evdb_tool {
26 
27  class DrawSkewHits : public IWFHitDrawer {
28  public:
29  explicit DrawSkewHits(const fhicl::ParameterSet& pset);
30 
31  ~DrawSkewHits();
32 
33  void configure(const fhicl::ParameterSet& pset) override;
34  void Draw(evdb::View2D&, raw::ChannelID_t&) const override;
35 
36  private:
37  double EvalExpoFit(double x, double tau1, double tau2, double amplitude, double peaktime) const;
38 
39  double EvalMultiExpoFit(double x,
40  int HitNumber,
41  int NHits,
42  std::vector<double> tau1,
43  std::vector<double> tau2,
44  std::vector<double> amplitude,
45  std::vector<double> peaktime) const;
46 
47  mutable std::vector<TPolyLine*> fPolyLineVec;
48  };
49 
50  //----------------------------------------------------------------------
51  // Constructor.
53  {
54  configure(pset);
55  }
56 
58 
60  {
61  return;
62  }
63 
64  void DrawSkewHits::Draw(evdb::View2D& view2D, raw::ChannelID_t& channel) const
65  {
69 
70  //grab the singleton with the event
72  if (!event) return;
73 
74  fPolyLineVec.clear();
75 
76  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
77  art::InputTag const which = recoOpt->fHitLabels[imod];
78 
80  event->getByLabel(which, hitVecHandle);
81 
82  // Get a container for the subset of hits we are working with and setup to fill it
84  bool stillSearching(true);
85  int fitParamsOffset(0);
86 
87  // Loop through all hits and find those on the channel in question, also count up to the start of these hits
88  for (size_t hitIdx = 0; hitIdx < hitVecHandle->size(); hitIdx++) {
89  art::Ptr<recob::Hit> hit(hitVecHandle, hitIdx);
90 
91  if (hit->Channel() == channel) {
92  hitPtrVec.push_back(hit);
93  stillSearching = false;
94  }
95  else if (!stillSearching)
96  break;
97 
98  if (stillSearching) fitParamsOffset++;
99  }
100 
101  // No hits no work
102  if (hitPtrVec.empty()) continue;
103 
104  // The fit parameters will be returned in an auxiliary object
105  auto hitResults = anab::FVectorReader<recob::Hit, 4>::create(*event, "dprawhit");
106  const auto& fitParamVecs = hitResults->vectors();
107 
108  // Containers for the piecess...
109  std::vector<double> hitPeakTimeVec;
110  std::vector<double> hitTau1Vec;
111  std::vector<double> hitTau2Vec;
112  std::vector<double> hitPeakAmpVec;
113  std::vector<int> hitStartTVec;
114  std::vector<int> hitEndTVec;
115  std::vector<int> hitNMultiHitVec;
116  std::vector<int> hitLocalIdxVec;
117 
118  // Ok, loop through the hits for this channnel and recover the parameters
119  for (size_t idx = 0; idx < hitPtrVec.size(); ++idx) {
120  const auto& fitParams = fitParamVecs[fitParamsOffset + idx];
121  const auto& hit = hitPtrVec[idx];
122 
123  hitPeakTimeVec.push_back(fitParams[0]);
124  hitTau1Vec.push_back(fitParams[1]);
125  hitTau2Vec.push_back(fitParams[2]);
126  hitPeakAmpVec.push_back(fitParams[3]);
127  hitStartTVec.push_back(hit->StartTick());
128  hitEndTVec.push_back(hit->EndTick());
129  hitNMultiHitVec.push_back(hit->Multiplicity());
130  hitLocalIdxVec.push_back(hit->LocalIndex());
131  }
132 
133  // Now we can go through these and start filling the polylines
134  for (size_t idx = 0; idx < hitPeakTimeVec.size(); idx++) {
135  if (hitNMultiHitVec[idx] > 1 && hitLocalIdxVec[idx] == 0) {
136  TPolyLine& p2 = view2D.AddPolyLine(1001, kRed, 3, 1);
137 
138  // set coordinates of TPolyLine based fitted function
139  for (int j = 0; j < 1001; ++j) {
140  double x = hitStartTVec[idx] +
141  j * (hitEndTVec[idx + hitNMultiHitVec[idx] - 1] - hitStartTVec[idx]) / 1000;
142  double y = EvalMultiExpoFit(
143  x, idx, hitNMultiHitVec[idx], hitTau1Vec, hitTau2Vec, hitPeakAmpVec, hitPeakTimeVec);
144  p2.SetPoint(j, x, y);
145  }
146 
147  fPolyLineVec.push_back(&p2);
148  p2.Draw("same");
149  }
150 
151  // Always draw the single peaks in addition to the sum of all peaks
152  // create TPolyLine that actually gets drawn
153  TPolyLine& p1 = view2D.AddPolyLine(1001, kOrange + 7, 3, 1);
154 
155  // set coordinates of TPolyLine based fitted function
156  for (int j = 0; j < 1001; ++j) {
157  double x = hitStartTVec[idx - hitLocalIdxVec[idx]] +
158  j *
159  (hitEndTVec[idx + hitNMultiHitVec[idx] - hitLocalIdxVec[idx] - 1] -
160  hitStartTVec[idx - hitLocalIdxVec[idx]]) /
161  1000;
162  double y = EvalExpoFit(
163  x, hitTau1Vec[idx], hitTau2Vec[idx], hitPeakAmpVec[idx], hitPeakTimeVec[idx]);
164  p1.SetPoint(j, x, y);
165  }
166 
167  fPolyLineVec.push_back(&p1);
168 
169  p1.Draw("same");
170  }
171  }
172 
173  return;
174  }
175 
177  double tau1,
178  double tau2,
179  double amplitude,
180  double peaktime) const
181  {
182  return (amplitude * exp(0.4 * (x - peaktime) / tau1) / (1 + exp(0.4 * (x - peaktime) / tau2)));
183  }
184 
185  //......................................................................
187  int HitNumber,
188  int NHits,
189  std::vector<double> tau1,
190  std::vector<double> tau2,
191  std::vector<double> amplitude,
192  std::vector<double> peaktime) const
193  {
194  double x_sum = 0.;
195 
196  for (int i = HitNumber; i < HitNumber + NHits; i++) {
197  x_sum += (amplitude[i] * exp(0.4 * (x - peaktime[i]) / tau1[i]) /
198  (1 + exp(0.4 * (x - peaktime[i]) / tau2[i])));
199  }
200 
201  return x_sum;
202  }
203 
205 }
Float_t x
Definition: compare.C:6
const art::Event * GetEvent() const
Definition: EventHolder.cxx:45
void configure(const fhicl::ParameterSet &pset) override
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
TPolyLine & AddPolyLine(int n, int c, int w, int s)
Definition: View2D.cxx:210
Declaration of signal hit object.
Float_t y
Definition: compare.C:6
static std::unique_ptr< FVectorReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:28
A collection of drawable 2-D objects.
Singleton to hold the current art::Event for the event display.
void Draw(evdb::View2D &, raw::ChannelID_t &) const override
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
static EventHolder * Instance()
Definition: EventHolder.cxx:15
std::vector< TPolyLine * > fPolyLineVec
bool empty() const
Definition: PtrVector.h:330
size_type size() const
Definition: PtrVector.h:302
Detector simulation of raw signals on wires.
double EvalExpoFit(double x, double tau1, double tau2, double amplitude, double peaktime) const
double EvalMultiExpoFit(double x, int HitNumber, int NHits, std::vector< double > tau1, std::vector< double > tau2, std::vector< double > amplitude, std::vector< double > peaktime) const
DrawSkewHits(const fhicl::ParameterSet &pset)
std::vector< art::InputTag > fHitLabels
module labels that produced hits
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Namespace collecting geometry-related classes utilities.
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:268
art framework interface to geometry description
Event finding and building.