All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Namespaces | Functions | Variables
PCAngleKinkFinder_module.cc File Reference
#include "art/Framework/Core/EDProducer.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Principal/Run.h"
#include "art/Framework/Principal/SubRun.h"
#include "canvas/Utilities/InputTag.h"
#include "fhiclcpp/ParameterSet.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "lardata/Utilities/AssociationUtil.h"
#include "lardataobj/RecoBase/PFParticle.h"
#include <memory>
#include "lardataobj/RecoBase/Wire.h"
#include "lardataobj/RecoBase/Vertex.h"
#include "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RecoBase/Cluster.h"
#include "larcore/Geometry/Geometry.h"
#include "larcorealg/Geometry/GeometryCore.h"
#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
#include "sbnobj/Common/Reco/PCAnglePlane.h"
#include "sbnobj/Common/Reco/PCAngleKink.h"
#include "TFitter.h"
#include "TMinuit.h"

Go to the source code of this file.

Classes

class  sbn::PCAngleKinkFinder
 
struct  sbn::PCAngleKinkFinder::FitResult
 

Namespaces

 sbn
 This module creates Common Analysis Files.
 

Functions

sbn::PCAngleKink BuildKink (const sbn::PCAngle &max, const sbn::PCAngle &lo, const sbn::PCAngle &hi, const sbn::PCAngleKinkFinder::FitResult &fit, float est_angle)
 
std::tuple< std::vector
< sbn::PCAngle >, unsigned > 
FlattenBranch (const sbn::PCAnglePlane &plane, unsigned i_branch, bool allow_incomplete, float min_dist)
 
float EstimateHeight (const std::vector< sbn::PCAngle > &angles, unsigned lo, unsigned hi)
 
int FindMaxIndex (const std::vector< sbn::PCAngle > &angles, unsigned lo, unsigned hi)
 
int FindFWHMHiIndex (const std::vector< sbn::PCAngle > &angles, unsigned start, unsigned end, float amp, float threshold)
 
int FindFWHMLoIndex (const std::vector< sbn::PCAngle > &angles, unsigned start, unsigned end, float amp, float threshold)
 
double ExpectedCosAngle (double dist_to_center, double radius, double mean_distance, double angle)
 
void FitLikelihood (int &npar, double *g, double &result, double *par, int flag)
 

Variables

static std::vector< float > fFitDataX
 
static std::vector< float > fFitDataY
 
static unsigned fFitCenter
 

Function Documentation

sbn::PCAngleKink BuildKink ( const sbn::PCAngle &  max,
const sbn::PCAngle &  lo,
const sbn::PCAngle &  hi,
const sbn::PCAngleKinkFinder::FitResult fit,
float  est_angle 
)

Definition at line 91 of file PCAngleKinkFinder_module.cc.

91  {
92  sbn::PCAngleKink kink;
93  kink.maxWire = max.wire;
94 
95  kink.fwhm_distance = sqrt((hi.hit_time_cm - lo.hit_time_cm) * (hi.hit_time_cm - lo.hit_time_cm)
96  + (hi.hit_wire_cm - lo.hit_wire_cm) * (hi.hit_wire_cm - lo.hit_wire_cm));
97  kink.max_angle = max.angle;
98  kink.est_angle = est_angle;
99 
100  kink.position_max = {max.hit_time_cm, max.hit_wire_cm};
101  kink.position_lo = {lo.hit_time_cm, lo.hit_wire_cm};
102  kink.position_hi = {hi.hit_time_cm, hi.hit_wire_cm};
103 
104  kink.vec_lo_at_max = max.lo_vector;
105  kink.vec_hi_at_max = max.hi_vector;
106 
107  kink.vec_lo_at_halfmax_lo = lo.lo_vector;
108  kink.vec_hi_at_halfmax_lo = lo.hi_vector;
109 
110  kink.vec_lo_at_halfmax_hi = hi.lo_vector;
111  kink.vec_hi_at_halfmax_hi = hi.hi_vector;
112 
113  kink.fit_chi2 = fit.chi2;
114  kink.fit_angle = fit.angle;
115  kink.fit_pitch = fit.pitch;
116 
117  return kink;
118 }
float EstimateHeight ( const std::vector< sbn::PCAngle > &  angles,
unsigned  lo,
unsigned  hi 
)

Definition at line 189 of file PCAngleKinkFinder_module.cc.

189  {
190  static const unsigned NAVG = 3;
191  static const unsigned IAVG = (NAVG - 1) / 2;
192 
193  // if the "peak is too small -- ignore
194  if (hi - lo + 1 < NAVG) return -1.;
195 
196  std::vector<float> avgd;
197  // average out the vector
198  for (unsigned i = IAVG + lo; i <= hi - IAVG; i++) {
199  float sum = 0.;
200  for (unsigned j = i - IAVG; j < i - IAVG + NAVG; j++) {
201  sum += angles[j].angle;
202  }
203 
204  avgd.push_back(sum / NAVG);
205  }
206 
207  return *std::max_element(avgd.begin(), avgd.end());
208 }
double ExpectedCosAngle ( double  dist_to_center,
double  radius,
double  mean_distance,
double  angle 
)

Definition at line 290 of file PCAngleKinkFinder_module.cc.

290  {
291  if (dist_to_center >= radius) return 1.;
292 
293  double theta = angle;
294  double A = dist_to_center;
295  double B = radius - dist_to_center;
296  double R = radius;
297  double l = mean_distance;
298 
299  // double M01 = (B*(B + lB)*(3*A*(A + lA)*lB + (B*B*lA + B*(4*A - lA)*lB + 2*A*lB*lB)*cos(theta))*sin(theta))/(12.*lB*(B*lA + A*lB));
300  //double M00 = (A*(A + lA)*lB*(2*B*lA*(2*A + lA) + A*(A - lA)*lB) + B*(B + lB)*cos(theta)*(6*A*lA*(A + lA)*lB + lA*(B*B*lA + B*(4*A - lA)*lB + 2*A*lB*lB)*cos(theta)))/(12.*lA*lB*(B*lA + A*lB));
301  //double M11 = (B*(B + lB)*(B*B*lA + B*(4*A - lA)*lB + 2*A*lB*lB)*sin(theta)*sin(theta))/(12.*lB*(B*lA + A*lB));
302 
303  double M01 = (B*(B + l)*(-6*A*(A + l)*(A + B - 2*R)*sin(theta) + (3*B*(A + B)*(B + l) - 6*B*(B + l)*R + 2*(2*B + l)*R*R)*sin(2*theta)))/(24.*l*R*R);
304  double M00 = (A*(A + l)*(3*A*(A + B)*(A + l) - 6*A*(A + l)*R + 2*(2*A + l)*R*R) + B*(B + l)*cos(theta)*(-6*A*(A + l)*(A + B - 2*R) + (3*B*(A + B)*(B + l) - 6*B*(B + l)*R + 2*(2*B + l)*R*R)*cos(theta)))/(12.*l*R*R);
305  double M11 = (B*(B + l)*(3*B*(A + B)*(B + l) - 6*B*(B + l)*R + 2*(2*B + l)*R*R)*sin(theta)*sin(theta))/(12.*l*R*R);
306 
307  double trace = M00 + M11;
308  double det = M00 * M11 - M01 * M01;
309  double eigen = 0.5 * (trace + sqrt(trace * trace - 4 *det));
310  double vecA = M01;
311  double vecB = eigen - M00;
312 
313  return vecA / sqrt(vecA * vecA + vecB * vecB);
314 }
M::value_type trace(const M &m)
finds tracks best matching by angle
float A
Definition: dedx.py:137
int FindFWHMHiIndex ( const std::vector< sbn::PCAngle > &  angles,
unsigned  start,
unsigned  end,
float  amp,
float  threshold 
)

Definition at line 238 of file PCAngleKinkFinder_module.cc.

238  {
239  // handle bad amplitude
240  if (amp < 0.) return -1;
241 
242  // go below half-the amplitude
243  int halfmax_ind = -1;
244 
245  // forward track to the end of this branch
246  //
247  // We always identify hits on the last part of any branch, so we don't need
248  // to worry about forward tracking to any other part of the branch
249  for (unsigned i = end; i < angles.size(); i++) {
250  if (angles[i].angle < amp/2.) {
251  halfmax_ind = i;
252  break;
253  }
254  }
255  return halfmax_ind;
256 }
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
finds tracks best matching by angle
int FindFWHMLoIndex ( const std::vector< sbn::PCAngle > &  angles,
unsigned  start,
unsigned  end,
float  amp,
float  threshold 
)

Definition at line 258 of file PCAngleKinkFinder_module.cc.

258  {
259  // handle bad amplitude
260  if (amp < 0.) return -1;
261 
262  // backtrack
263  int halfmax_ind = -1;
264 
265  for (int i = start; i >= 0; i--) {
266  if (angles[i].angle < amp / 2.) {
267  halfmax_ind = i;
268  break;
269  }
270  }
271 
272  return halfmax_ind;
273 }
finds tracks best matching by angle
int FindMaxIndex ( const std::vector< sbn::PCAngle > &  angles,
unsigned  lo,
unsigned  hi 
)

Definition at line 211 of file PCAngleKinkFinder_module.cc.

211  {
212  static const unsigned NAVG = 3;
213  static const unsigned IAVG = (NAVG - 1) / 2;
214 
215  // if the "peak is too small -- ignore
216  if (hi - lo + 1 < (int)NAVG) return -1.;
217 
218  std::vector<float> avgd;
219  // average out the vector
220  for (unsigned i = lo + IAVG; i <= hi - IAVG; i++) {
221  float sum = 0.;
222  for (unsigned j = i - IAVG; j < i - IAVG + NAVG; j++) {
223  sum += angles[j].angle;
224  }
225 
226  avgd.push_back(sum / NAVG);
227  }
228 
229  // index of the averaged
230  unsigned avgd_index = std::distance(avgd.begin(), std::max_element(avgd.begin(), avgd.end()));
231 
232  // convert this to index in angles list
233  unsigned angles_index = avgd_index + IAVG + lo;
234 
235  return angles_index;
236 }
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
void FitLikelihood ( int &  npar,
double *  g,
double &  result,
double *  par,
int  flag 
)

Definition at line 316 of file PCAngleKinkFinder_module.cc.

316  {
317  double angle = par[0];
318  double res = par[1];
319  double radius = par[2];
320  double mean_distance = par[3];
321 
322  double chi2 = 0.;
323  for (unsigned i = 0; i < fFitDataX.size(); i++) {
324  double expectation = acos(ExpectedCosAngle(fFitDataX[i], radius, mean_distance, angle));
325  chi2 += (expectation - fFitDataY[i]) * (expectation - fFitDataY[i]) / (fFitDataY[i] * fFitDataY[i] * res * res);
326  }
327 
328  result = chi2 / fFitDataX.size();
329 }
static std::vector< float > fFitDataY
double ExpectedCosAngle(double dist_to_center, double radius, double mean_distance, double angle)
finds tracks best matching by angle
static std::vector< float > fFitDataX
std::tuple<std::vector<sbn::PCAngle>, unsigned> FlattenBranch ( const sbn::PCAnglePlane &  plane,
unsigned  i_branch,
bool  allow_incomplete,
float  min_dist 
)

Definition at line 121 of file PCAngleKinkFinder_module.cc.

121  {
122  std::vector<sbn::PCAngle> ret;
123 
124  std::cout << "Flattening angles for branch: " << i_branch << " plane: " << plane.plane.Plane << " hierarchy: ";
125  for (int id: plane.branchHierarchy[i_branch]) std::cout << id << " ";
126  std::cout << std::endl;
127 
128  // start at the end of the branch and count backwards
129  for (unsigned i_branch_hierarchy = 0; i_branch_hierarchy < plane.branchHierarchy[i_branch].size(); i_branch_hierarchy++) {
130  // look up the index of the current branch
131  unsigned this_branch = std::distance(plane.branchIDs.begin(), std::find(plane.branchIDs.begin(), plane.branchIDs.end(), plane.branchHierarchy[i_branch][i_branch_hierarchy]));
132  if (this_branch == plane.branchIDs.size()) {
133  std::cout << "BAD: UNFOUND BRANCH ID\n";
134  continue;
135  }
136  std::cout << "BRANCH CHECK: " << plane.branchHierarchy[i_branch][i_branch_hierarchy] << " " << this_branch << " " << i_branch << std::endl;
137  for (int i = plane.angles[this_branch].size()-1; i >= 0; i--) {
138  // invalid if incomplete
139  bool is_complete = (plane.angles[this_branch][i].complete || allow_incomplete) &&
140  plane.angles[this_branch][i].dist_to_lo > min_dist && plane.angles[this_branch][i].dist_to_hi > min_dist &&
141  plane.angles[this_branch][i].angle > -99.;
142 
143  if (!is_complete) continue;
144 
145  // Check if this hit is replicated in the following branch
146  bool found_hit = false;
147  if (i_branch_hierarchy > 0) {
148  int i_check_branch_hierarchy = i_branch_hierarchy - 1;
149  unsigned chk_branch = plane.branchIDs.size();
150  int check_hitID = plane.angles[this_branch][i].hitID;
151  while (i_check_branch_hierarchy >= 0 && chk_branch == plane.branchIDs.size()) {
152  chk_branch = std::distance(plane.branchIDs.begin(), std::find(plane.branchIDs.begin(), plane.branchIDs.end(), plane.branchHierarchy[i_branch][i_check_branch_hierarchy]));
153  i_check_branch_hierarchy --;
154  }
155  if (chk_branch < plane.branchIDs.size()) {
156  for (unsigned j = 0; j < plane.angles[chk_branch].size(); j++) {
157  if (plane.angles[chk_branch][j].hitID == check_hitID) {
158  found_hit = true;
159  break;
160  }
161  }
162  }
163  }
164  // invalid if replicated
165  if (found_hit) continue;
166 
167  // Valid!
168  ret.push_back(plane.angles[this_branch][i]);
169  }
170  }
171 
172  // reverse the angles
173  std::reverse(ret.begin(), ret.end());
174 
175  // get the number of valid hits in the main branch
176  unsigned n_branch_hits = 0;
177  for (unsigned i = 0; i < plane.angles[i_branch].size(); i++) {
178  n_branch_hits += (plane.angles[i_branch][i].complete || allow_incomplete) &&
179  plane.angles[i_branch][i].dist_to_lo > min_dist && plane.angles[i_branch][i].dist_to_hi > min_dist &&
180  plane.angles[i_branch][i].angle > -99.;
181  }
182 
183  // get the index of the start of this branch
184  unsigned branch_start = ret.size() - n_branch_hits;
185  return {ret, branch_start};
186 }
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
BEGIN_PROLOG could also be cout

Variable Documentation

unsigned fFitCenter
static

Definition at line 88 of file PCAngleKinkFinder_module.cc.

std::vector<float> fFitDataX
static

Definition at line 86 of file PCAngleKinkFinder_module.cc.

std::vector<float> fFitDataY
static

Definition at line 87 of file PCAngleKinkFinder_module.cc.