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