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>);
381 art::PtrMaker<sbn::PCAngleKink> kinkPtrMaker {
evt};
384 art::Handle<std::vector<recob::PFParticle>> pfparticle_handle;
387 std::vector<art::Ptr<recob::PFParticle>> pfparticles;
388 art::fill_ptr_vector(pfparticles, pfparticle_handle);
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];
396 art::FindManyP<sbn::PCAnglePlane> pfparticleAngles(pfparticles,
evt,
fAngleLabel);
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);
404 if (!thisAngles.size())
continue;
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++) {
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;
416 if (!in_hit && this_in_hit) {
417 hit_start_ind = i_hit;
420 else if (in_hit && (!this_in_hit || i_hit+1 == branchAngles.size())) {
421 float height =
EstimateHeight(branchAngles, hit_start_ind, i_hit);
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;
432 int max_ind =
FindMaxIndex(branchAngles, lo_hit_ind, hi_hit_ind);
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));
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));
448 float pitch = (dist_lo_sum + dist_hi_sum) / (hi_hit_ind - lo_hit_ind);
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];
457 sbn::PCAngleKink kink =
BuildKink(max, lo, hi, fit, height);
458 thisKinks.push_back(kink);
464 in_hit = this_in_hit;
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);
477 evt.put(std::move(outKinks));
478 evt.put(std::move(assn));
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
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
std::string fPFParticleLabel