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

Classes

struct  FitResult
 

Public Member Functions

 PCAngleKinkFinder (fhicl::ParameterSet const &p)
 
 PCAngleKinkFinder (PCAngleKinkFinder const &)=delete
 
 PCAngleKinkFinder (PCAngleKinkFinder &&)=delete
 
PCAngleKinkFinderoperator= (PCAngleKinkFinder const &)=delete
 
PCAngleKinkFinderoperator= (PCAngleKinkFinder &&)=delete
 
void produce (art::Event &e) override
 

Private Member Functions

FitResult Fit (const std::vector< sbn::PCAngle > &angles, unsigned lo, unsigned hi, unsigned center, float est_angle, float est_pitch)
 

Private Attributes

std::string fPFParticleLabel
 
std::string fAngleLabel
 
float fHitThreshold
 
float fMinDist
 
bool fAllowIncomplete
 
float fPCARadius
 
float fFitResolution
 

Detailed Description

Definition at line 46 of file PCAngleKinkFinder_module.cc.

Constructor & Destructor Documentation

sbn::PCAngleKinkFinder::PCAngleKinkFinder ( fhicl::ParameterSet const &  p)
explicit

Definition at line 275 of file PCAngleKinkFinder_module.cc.

276  : EDProducer{p},
277  fPFParticleLabel(p.get<std::string>("PFParticleLabel")),
278  fAngleLabel(p.get<std::string>("AngleLabel")),
279  fHitThreshold(p.get<float>("HitThreshold")),
280  fMinDist(p.get<float>("MinDist")),
281  fAllowIncomplete(p.get<bool>("AllowIncomplete")),
282  fPCARadius(p.get<float>("PCARadius")),
283  fFitResolution(p.get<float>("FitResolution", 0.05))
284 {
285  produces<std::vector<sbn::PCAngleKink>>();
286  produces<art::Assns<recob::PFParticle, sbn::PCAngleKink>>();
287 
288 }
pdgs p
Definition: selectors.fcl:22
sbn::PCAngleKinkFinder::PCAngleKinkFinder ( PCAngleKinkFinder const &  )
delete
sbn::PCAngleKinkFinder::PCAngleKinkFinder ( PCAngleKinkFinder &&  )
delete

Member Function Documentation

sbn::PCAngleKinkFinder::FitResult sbn::PCAngleKinkFinder::Fit ( const std::vector< sbn::PCAngle > &  angles,
unsigned  lo,
unsigned  hi,
unsigned  center,
float  est_angle,
float  est_pitch 
)
private

Definition at line 331 of file PCAngleKinkFinder_module.cc.

331  {
332  // setup the fitdata
333  fFitDataX.clear();
334  fFitDataY.clear();
335  for (unsigned i = lo; i <= hi; i++) {
336  fFitDataX.push_back( sqrt((angles[i].hit_time_cm - angles[center].hit_time_cm) * (angles[i].hit_time_cm - angles[center].hit_time_cm) +
337  (angles[i].hit_wire_cm - angles[center].hit_wire_cm) * (angles[i].hit_wire_cm - angles[center].hit_wire_cm)) );
338  fFitDataY.push_back(angles[i].angle);
339  }
340  fFitCenter = center;
341 
342  // setup the fitter
343  TFitter fitter(5); // 5 param
344  fitter.SetFCN(&FitLikelihood);
345  fitter.SetParameter(0, "angle", est_angle, 0.1, 0, M_PI);
346  fitter.SetParameter(1, "resolution", fFitResolution, 0., fFitResolution, fFitResolution);
347  fitter.SetParameter(2, "radius", fPCARadius, 0., fPCARadius, fPCARadius);
348  fitter.SetParameter(3, "pitch", est_pitch, 0., est_pitch, est_pitch);
349  fitter.GetMinuit()->FixParameter(1);
350  fitter.GetMinuit()->FixParameter(2);
351  fitter.GetMinuit()->FixParameter(3);
352 
353  fitter.ExecuteCommand("MIGRAD", 0, 0);
354 
356 
357  ret.angle = fitter.GetParameter(0);
358  ret.pitch = fitter.GetParameter(3);
359 
360  double chi2;
361  double edm;
362  double errdef;
363  int nvpar;
364  int nparx;
365 
366  fitter.GetStats(chi2, edm, errdef, nvpar, nparx);
367  std::cout << "Fit chi2: " << chi2 << std::endl;
368  std::cout << "Fit angle: " << ret.angle << std::endl;
369 
370  ret.chi2 = chi2;
371 
372  return ret;
373 }
static std::vector< float > fFitDataY
void FitLikelihood(int &npar, double *g, double &result, double *par, int flag)
static unsigned fFitCenter
finds tracks best matching by angle
static std::vector< float > fFitDataX
BEGIN_PROLOG could also be cout
PCAngleKinkFinder& sbn::PCAngleKinkFinder::operator= ( PCAngleKinkFinder const &  )
delete
PCAngleKinkFinder& sbn::PCAngleKinkFinder::operator= ( PCAngleKinkFinder &&  )
delete
void sbn::PCAngleKinkFinder::produce ( art::Event &  e)
override

Definition at line 375 of file PCAngleKinkFinder_module.cc.

376 {
377  // output stuff
378  std::unique_ptr<std::vector<sbn::PCAngleKink>> outKinks(new std::vector<sbn::PCAngleKink>);
379  std::unique_ptr<art::Assns<recob::PFParticle, sbn::PCAngleKink>> assn(new art::Assns<recob::PFParticle, sbn::PCAngleKink>);
380 
381  art::PtrMaker<sbn::PCAngleKink> kinkPtrMaker {evt};
382 
383  // get the PFParticle's and the associated data
384  art::Handle<std::vector<recob::PFParticle>> pfparticle_handle;
385  evt.getByLabel(fPFParticleLabel, pfparticle_handle);
386 
387  std::vector<art::Ptr<recob::PFParticle>> pfparticles;
388  art::fill_ptr_vector(pfparticles, pfparticle_handle);
389 
390  // organize the PFPlist into a map
391  std::map<unsigned, art::Ptr<recob::PFParticle>> id_to_pfp;
392  for (unsigned i = 0; i < pfparticles.size(); i++) {
393  id_to_pfp[pfparticles[i]->Self()] = pfparticles[i];
394  }
395 
396  art::FindManyP<sbn::PCAnglePlane> pfparticleAngles(pfparticles, evt, fAngleLabel);
397 
398  // iterate over each particle
399  for (unsigned i_part = 0; i_part < pfparticles.size(); i_part++) {
400  art::Ptr<recob::PFParticle> thisPFP = pfparticles[i_part];
401  std::cout << "NEW Particle: " << thisPFP->Self() << std::endl;
402  const std::vector<art::Ptr<sbn::PCAnglePlane>> &thisAngles = pfparticleAngles.at(i_part);
403 
404  if (!thisAngles.size()) continue;
405 
406  std::vector<sbn::PCAngleKink> thisKinks;
407  for (const art::Ptr<sbn::PCAnglePlane> &angle: thisAngles) {
408  for (unsigned i_branch = 0; i_branch < angle->nBranches; i_branch++) {
409  // flatten the structure of this branch
410  auto [branchAngles, branch_start] = FlattenBranch(*angle, i_branch, fAllowIncomplete, fMinDist);
411  bool in_hit = false;
412  int hit_start_ind = -1;
413  for (unsigned i_hit = branch_start; i_hit < branchAngles.size(); i_hit++) {
414  bool this_in_hit = branchAngles[i_hit].angle > fHitThreshold;
415  // New hit! set it up
416  if (!in_hit && this_in_hit) {
417  hit_start_ind = i_hit;
418  }
419  // end of hit! finish it up
420  else if (in_hit && (!this_in_hit || i_hit+1 == branchAngles.size())) {
421  float height = EstimateHeight(branchAngles, hit_start_ind, i_hit);
422 
423  int hi_hit_ind = FindFWHMHiIndex(branchAngles, hit_start_ind, i_hit, height, fHitThreshold);
424  int lo_hit_ind = FindFWHMLoIndex(branchAngles, hit_start_ind, i_hit, height, fHitThreshold);
425  // invalid hit
426  // check if hit is valid
427  if (hi_hit_ind >= 0 && lo_hit_ind >= 0) {
428  std::cout << "NEW KINK: Particle: " << thisPFP->Self() << " Branch Ind: " << i_branch << " Plane: " << angle->plane.Plane << std::endl;
429  std::cout << "EST HEIGHT: " << height << " IND LO: " << lo_hit_ind << " IND HI: " << hi_hit_ind << std::endl;
430 
431  // build out the kink information
432  int max_ind = FindMaxIndex(branchAngles, lo_hit_ind, hi_hit_ind);
433 
434  // estimate the track pitch -- distance between successive hits
435  float dist_lo_sum = 0.;
436  for (int i = lo_hit_ind; i < max_ind; i++) {
437  dist_lo_sum += sqrt((branchAngles[i].hit_time_cm - branchAngles[i+1].hit_time_cm) * (branchAngles[i].hit_time_cm - branchAngles[i+1].hit_time_cm) +
438  (branchAngles[i].hit_wire_cm - branchAngles[i+1].hit_wire_cm) * (branchAngles[i].hit_wire_cm - branchAngles[i+1].hit_wire_cm));
439  }
440  // float pitch_lo = dist_lo_sum / (max_ind - lo_hit_ind);
441 
442  float dist_hi_sum = 0.;
443  for (int i = max_ind; i < hi_hit_ind; i++) {
444  dist_hi_sum += sqrt((branchAngles[i].hit_time_cm - branchAngles[i+1].hit_time_cm) * (branchAngles[i].hit_time_cm - branchAngles[i+1].hit_time_cm) +
445  (branchAngles[i].hit_wire_cm - branchAngles[i+1].hit_wire_cm) * (branchAngles[i].hit_wire_cm - branchAngles[i+1].hit_wire_cm));
446  }
447  // float pitch_hi = dist_hi_sum / (hi_hit_ind - max_ind);
448  float pitch = (dist_lo_sum + dist_hi_sum) / (hi_hit_ind - lo_hit_ind);
449 
450 
451  sbn::PCAngleKinkFinder::FitResult fit = Fit(branchAngles, lo_hit_ind, hi_hit_ind, max_ind, height, pitch);
452 
453  const sbn::PCAngle &max = branchAngles[max_ind];
454  const sbn::PCAngle &lo = branchAngles[lo_hit_ind];
455  const sbn::PCAngle &hi = branchAngles[hi_hit_ind];
456 
457  sbn::PCAngleKink kink = BuildKink(max, lo, hi, fit, height);
458  thisKinks.push_back(kink);
459  // update the hit index to the end of this hit
460  i_hit = hi_hit_ind;
461  }
462  }
463 
464  in_hit = this_in_hit;
465  }
466  }
467  }
468 
469  // save the kinks
470  for (const sbn::PCAngleKink &k: thisKinks) {
471  outKinks->push_back(k);
472  art::Ptr<sbn::PCAngleKink> thisKinkPtr = kinkPtrMaker(outKinks->size()-1);
473  assn->addSingle(thisPFP, thisKinkPtr);
474  }
475  }
476 
477  evt.put(std::move(outKinks));
478  evt.put(std::move(assn));
479 
480 }
FitResult Fit(const std::vector< sbn::PCAngle > &angles, unsigned lo, unsigned hi, unsigned center, float est_angle, float est_pitch)
int FindFWHMLoIndex(const std::vector< sbn::PCAngle > &angles, unsigned start, unsigned end, float amp, float threshold)
int FindMaxIndex(const std::vector< sbn::PCAngle > &angles, unsigned lo, unsigned hi)
std::tuple< std::vector< sbn::PCAngle >, unsigned > FlattenBranch(const sbn::PCAnglePlane &plane, unsigned i_branch, bool allow_incomplete, float min_dist)
finds tracks best matching by angle
TCEvent evt
Definition: DataStructs.cxx:8
pdgs k
Definition: selectors.fcl:22
sbn::PCAngleKink BuildKink(const sbn::PCAngle &max, const sbn::PCAngle &lo, const sbn::PCAngle &hi, const sbn::PCAngleKinkFinder::FitResult &fit, float est_angle)
float EstimateHeight(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)
BEGIN_PROLOG could also be cout

Member Data Documentation

bool sbn::PCAngleKinkFinder::fAllowIncomplete
private

Definition at line 73 of file PCAngleKinkFinder_module.cc.

std::string sbn::PCAngleKinkFinder::fAngleLabel
private

Definition at line 70 of file PCAngleKinkFinder_module.cc.

float sbn::PCAngleKinkFinder::fFitResolution
private

Definition at line 75 of file PCAngleKinkFinder_module.cc.

float sbn::PCAngleKinkFinder::fHitThreshold
private

Definition at line 71 of file PCAngleKinkFinder_module.cc.

float sbn::PCAngleKinkFinder::fMinDist
private

Definition at line 72 of file PCAngleKinkFinder_module.cc.

float sbn::PCAngleKinkFinder::fPCARadius
private

Definition at line 74 of file PCAngleKinkFinder_module.cc.

std::string sbn::PCAngleKinkFinder::fPFParticleLabel
private

Definition at line 69 of file PCAngleKinkFinder_module.cc.


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