@@ -391,6 +391,7 @@ namespace caf
391391 const geo::WireReadoutGeom& wireReadout,
392392 unsigned producer,
393393 caf::SRShower &srshower,
394+ Det_t det,
394395 bool allowEmpty)
395396 {
396397
@@ -411,11 +412,56 @@ namespace caf
411412 // It's sth like this but not quite. And will need to pass a simb::MCtruth object vtx position anyway.
412413 // srshower.conversion_gap = (shower.ShowerStart() - vertex.Position()).Mag();
413414
414- if (shower.best_plane () != -999 ){
415- srshower.bestplane = shower.best_plane ();
416- srshower.bestplane_dEdx = srshower.plane [shower.best_plane ()].dEdx ;
417- srshower.bestplane_energy = srshower.plane [shower.best_plane ()].energy ;
418- }
415+ for (int p = 0 ; p < 3 ; ++p) srshower.plane [p].nHits = 0 ;
416+ for (auto const & hit:hits) ++srshower.plane [hit->WireID ().Plane ].nHits ;
417+
418+ if (det == kSBND )
419+ {
420+ int bestplane_for_energy = -999 ;
421+ int mosthits = -1 ;
422+ for (int p = 0 ; p < 3 ; ++p)
423+ {
424+ if ((int )srshower.plane [p].nHits > mosthits)
425+ {
426+ mosthits = srshower.plane [p].nHits ;
427+ bestplane_for_energy = p;
428+ }
429+ }
430+
431+ if (bestplane_for_energy != -999 )
432+ {
433+ srshower.bestplane_for_energy = bestplane_for_energy;
434+ srshower.bestplane_energy = srshower.plane [bestplane_for_energy].energy ;
435+ }
436+
437+ if (shower.best_plane () != -999 && srshower.plane [shower.best_plane ()].dEdx != -999 )
438+ {
439+ srshower.bestplane_for_dedx = shower.best_plane ();
440+ srshower.bestplane_dEdx = srshower.plane [shower.best_plane ()].dEdx ;
441+ }
442+ else
443+ {
444+ for (int p = 2 ; p >= 0 ; --p)
445+ {
446+ if (srshower.plane [p].dEdx != -999 )
447+ {
448+ srshower.bestplane_for_dedx = p;
449+ srshower.bestplane_dEdx = srshower.plane [shower.best_plane ()].dEdx ;
450+ break ;
451+ }
452+ }
453+ }
454+ }
455+ else
456+ {
457+ if (shower.best_plane () != -999 )
458+ {
459+ srshower.bestplane_for_energy = shower.best_plane ();
460+ srshower.bestplane_for_dedx = shower.best_plane ();
461+ srshower.bestplane_dEdx = srshower.plane [shower.best_plane ()].dEdx ;
462+ srshower.bestplane_energy = srshower.plane [shower.best_plane ()].energy ;
463+ }
464+ }
419465
420466 if (shower.has_open_angle ())
421467 srshower.open_angle = shower.OpenAngle ();
@@ -438,9 +484,6 @@ namespace caf
438484 srshower.end = shower.ShowerStart ()+ (shower.Length () * shower.Direction ());
439485 }
440486
441- for (int p = 0 ; p < 3 ; ++p) srshower.plane [p].nHits = 0 ;
442- for (auto const & hit:hits) ++srshower.plane [hit->WireID ().Plane ].nHits ;
443-
444487 for (geo::PlaneGeo const & plane: wireReadout.Iterate <geo::PlaneGeo>()) {
445488
446489 const double angleToVert (wireReadout.WireAngleToVertical (plane.View (), plane.ID ()) - 0.5 *M_PI);
0 commit comments