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