All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Attributes | List of all members
evdb_tool::DrawGausHits Class Reference
Inheritance diagram for evdb_tool::DrawGausHits:
evdb_tool::IWFHitDrawer

Public Member Functions

 DrawGausHits (const fhicl::ParameterSet &pset)
 
 ~DrawGausHits ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void Draw (evdb::View2D &, raw::ChannelID_t &) const override
 
- Public Member Functions inherited from evdb_tool::IWFHitDrawer
virtual ~IWFHitDrawer () noexcept=default
 

Private Types

using HitParams_t = struct HitParams_t{float hitCenter
 
using ROIHitParamsVec = std::vector< HitParams_t >
 
using HitParamsVec = std::vector< ROIHitParamsVec >
 

Private Attributes

float hitSigma
 
float hitHeight
 
float hitStart
 
float hitEnd
 
int fNumPoints
 
bool fFloatBaseline
 
std::vector< int > fColorVec
 
std::vector< std::unique_ptr
< TF1 > > 
fHitFunctionVec
 

Detailed Description

Definition at line 28 of file DrawGausHits_tool.cc.

Member Typedef Documentation

using evdb_tool::DrawGausHits::HitParams_t = struct HitParams_t { float hitCenter
private

Definition at line 39 of file DrawGausHits_tool.cc.

Definition at line 47 of file DrawGausHits_tool.cc.

Definition at line 46 of file DrawGausHits_tool.cc.

Constructor & Destructor Documentation

evdb_tool::DrawGausHits::DrawGausHits ( const fhicl::ParameterSet &  pset)
explicit

Definition at line 57 of file DrawGausHits_tool.cc.

57 { configure(pset); }
void configure(const fhicl::ParameterSet &pset) override
evdb_tool::DrawGausHits::~DrawGausHits ( )

Definition at line 59 of file DrawGausHits_tool.cc.

59 {}

Member Function Documentation

void evdb_tool::DrawGausHits::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements evdb_tool::IWFHitDrawer.

Definition at line 62 of file DrawGausHits_tool.cc.

63  {
64  fNumPoints = pset.get<int>("NumPoints", 1000);
65  fFloatBaseline = pset.get<bool>("FloatBaseline", false);
66 
67  fColorVec.clear();
68  fColorVec.push_back(kRed);
69  fColorVec.push_back(kGreen);
70  fColorVec.push_back(kMagenta);
71  fColorVec.push_back(kCyan);
72 
73  fHitFunctionVec.clear();
74 
75  return;
76  }
std::vector< int > fColorVec
std::vector< std::unique_ptr< TF1 > > fHitFunctionVec
void evdb_tool::DrawGausHits::Draw ( evdb::View2D &  view2D,
raw::ChannelID_t channel 
) const
overridevirtual

Implements evdb_tool::IWFHitDrawer.

Definition at line 79 of file DrawGausHits_tool.cc.

80  {
81  art::ServiceHandle<evd::RecoDrawingOptions const> recoOpt;
82 
83  //grab the singleton with the event
84  const art::Event* event = evdb::EventHolder::Instance()->GetEvent();
85  if (!event) return;
86 
87  fHitFunctionVec.clear();
88 
89  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
90  // Step one is to recover the hits for this label that match the input channel
91  art::InputTag const which = recoOpt->fHitLabels[imod];
92 
93  art::Handle<std::vector<recob::Hit>> hitVecHandle;
94  event->getByLabel(which, hitVecHandle);
95 
96  // Get a container for the subset of hits we are drawing
97  art::PtrVector<recob::Hit> hitPtrVec;
98 
99  try {
100  for (size_t hitIdx = 0; hitIdx < hitVecHandle->size(); hitIdx++) {
101  art::Ptr<recob::Hit> hit(hitVecHandle, hitIdx);
102 
103  if (hit->Channel() == channel) hitPtrVec.push_back(hit);
104  }
105  }
106  catch (cet::exception& e) {
107  mf::LogWarning("DrawGausHits") << "DrawGausHits"
108  << " failed with message:\n"
109  << e;
110  }
111 
112  if (hitPtrVec.empty()) continue;
113 
114  // Apparently you cannot trust some hit producers to put the hits in the correct order!
115  std::sort(hitPtrVec.begin(), hitPtrVec.end(), [](const auto& left, const auto& right) {
116  return left->PeakTime() < right->PeakTime();
117  });
118 
119  // Get associations to wires
120  art::FindManyP<recob::Wire> wireAssnsVec(hitPtrVec, *event, which);
121  std::vector<float> wireDataVec;
122 
123  // Recover the full (zero-padded outside ROI's) deconvolved waveform for this wire
124  if (wireAssnsVec.isValid() && wireAssnsVec.size() > 0) {
125  auto hwafp = wireAssnsVec.at(0).front();
126  if (!hwafp.isNull() && hwafp.isAvailable()) { wireDataVec = hwafp->Signal(); }
127  }
128 
129  // Now go through and process the hits back into the hit parameters
130  using ROIHitParamsVec = std::vector<HitParams_t>;
131  using HitParamsVec = std::vector<ROIHitParamsVec>;
132 
133  // Get an initial container for common hits on ROI
134  HitParamsVec hitParamsVec;
135  ROIHitParamsVec roiHitParamsVec;
136  raw::TDCtick_t lastEndTick(10000);
137 
138  for (const auto& hit : hitPtrVec) {
139  // check roi end condition
140  if (hit->PeakTime() - 3. * hit->RMS() > lastEndTick) {
141  if (!roiHitParamsVec.empty()) hitParamsVec.push_back(roiHitParamsVec);
142  roiHitParamsVec.clear();
143  }
144 
145  HitParams_t hitParams;
146 
147  hitParams.hitCenter = hit->PeakTime();
148  hitParams.hitSigma = hit->RMS();
149  hitParams.hitHeight = hit->PeakAmplitude();
150  hitParams.hitStart = hit->StartTick(); //PeakTime() - 3. * hit->RMS();
151  hitParams.hitEnd = hit->EndTick(); //PeakTime() + 3. * hit->RMS();
152 
153  lastEndTick = hitParams.hitEnd;
154 
155  roiHitParamsVec.emplace_back(hitParams);
156 
157  } //end loop over reco hits
158 
159  // Just in case (probably never called...)
160  if (!roiHitParamsVec.empty()) hitParamsVec.push_back(roiHitParamsVec);
161 
162  size_t roiCount(0);
163 
164  for (const auto& roiHitParamsVec : hitParamsVec) {
165  // Create a histogram here...
166  double roiStart = roiHitParamsVec.front().hitStart;
167  double roiStop = roiHitParamsVec.back().hitEnd;
168 
169  std::string funcString = "gaus(0)";
170  std::string funcName = Form("hitshape_%05zu_c%02zu", size_t(channel), roiCount++);
171 
172  for (size_t idx = 1; idx < roiHitParamsVec.size(); idx++)
173  funcString += "+gaus(" + std::to_string(3 * idx) + ")";
174 
175  // Include a baseline
176  float baseline(0.);
177 
178  if (fFloatBaseline && !wireDataVec.empty()) baseline = wireDataVec.at(roiStart);
179 
180  funcString += "+" + std::to_string(baseline);
181 
182  fHitFunctionVec.emplace_back(
183  std::make_unique<TF1>(funcName.c_str(), funcString.c_str(), roiStart, roiStop));
184  TF1& hitFunc = *fHitFunctionVec.back().get();
185 
186  hitFunc.SetLineColor(fColorVec[imod % fColorVec.size()]);
187 
188  size_t idx(0);
189  for (const auto& hitParams : roiHitParamsVec) {
190  hitFunc.SetParameter(idx + 0, hitParams.hitHeight);
191  hitFunc.SetParameter(idx + 1, hitParams.hitCenter);
192  hitFunc.SetParameter(idx + 2, hitParams.hitSigma);
193 
194  TPolyLine& hitHeight = view2D.AddPolyLine(2, kBlack, 1, 1);
195 
196  hitHeight.SetPoint(0, hitParams.hitCenter, baseline);
197  hitHeight.SetPoint(1, hitParams.hitCenter, hitParams.hitHeight + baseline);
198 
199  hitHeight.Draw("same");
200 
201  TPolyLine& hitSigma = view2D.AddPolyLine(2, kGray, 1, 1);
202 
203  hitSigma.SetPoint(
204  0, hitParams.hitCenter - hitParams.hitSigma, 0.6 * hitParams.hitHeight + baseline);
205  hitSigma.SetPoint(
206  1, hitParams.hitCenter + hitParams.hitSigma, 0.6 * hitParams.hitHeight + baseline);
207 
208  hitSigma.Draw("same");
209 
210  idx += 3;
211  }
212 
213  hitFunc.Draw("same");
214  }
215  } //end loop over HitFinding modules
216 
217  return;
218  }
std::vector< HitParams_t > ROIHitParamsVec
walls no right
Definition: selectors.fcl:105
std::vector< ROIHitParamsVec > HitParamsVec
process_name hit
Definition: cheaterreco.fcl:51
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
BEGIN_PROLOG baseline
walls no left
Definition: selectors.fcl:105
std::vector< int > fColorVec
std::string to_string(WindowPattern const &pattern)
do i e
std::vector< std::unique_ptr< TF1 > > fHitFunctionVec
struct HitParams_t{float hitCenter HitParams_t

Member Data Documentation

std::vector<int> evdb_tool::DrawGausHits::fColorVec
private

Definition at line 51 of file DrawGausHits_tool.cc.

bool evdb_tool::DrawGausHits::fFloatBaseline
private

Definition at line 50 of file DrawGausHits_tool.cc.

std::vector<std::unique_ptr<TF1> > evdb_tool::DrawGausHits::fHitFunctionVec
mutableprivate

Definition at line 52 of file DrawGausHits_tool.cc.

int evdb_tool::DrawGausHits::fNumPoints
private

Definition at line 49 of file DrawGausHits_tool.cc.

float evdb_tool::DrawGausHits::hitEnd
private

Definition at line 43 of file DrawGausHits_tool.cc.

float evdb_tool::DrawGausHits::hitHeight
private

Definition at line 41 of file DrawGausHits_tool.cc.

float evdb_tool::DrawGausHits::hitSigma
private

Definition at line 40 of file DrawGausHits_tool.cc.

float evdb_tool::DrawGausHits::hitStart
private

Definition at line 42 of file DrawGausHits_tool.cc.


The documentation for this class was generated from the following file: