22 #include "Math/RotationX.h" 23 #include "Math/RotationY.h" 24 #include "Math/RotationZ.h" 27 #include "TPrincipal.h" 54 size_t num_sps_to_take);
63 double current_residual);
74 int& max_residual_point);
82 double current_residual);
84 bool IsResidualOK(
double new_residual,
double current_residual)
const 92 bool IsResidualOK(
double new_residual,
double current_residual,
size_t no_sps)
const 104 int& max_residual_point)
const;
171 pset.
get<
std::string>(
"InitialTrackSpacePointsOutputLabel"))
175 <<
"We cannot make a track if you don't gives us at leats one hit. Change fStartFitSize " 176 "please to something sensible";
190 <<
"Start position not set, returning " << std::endl;
202 auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(
fPFParticleLabel);
209 std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.
key());
212 if (spacePoints.empty()) {
215 <<
"No space points, returning " << std::endl;
228 <<
"Direction not set, returning " << std::endl;
237 spacePoints, ShowerStartPosition, ShowerDirection);
241 for (
auto spacePoint : spacePoints) {
243 spacePoint, ShowerStartPosition, ShowerDirection);
244 if (proj < 0) { ++back_sps; }
245 if (proj > 0) {
break; }
247 spacePoints.erase(spacePoints.begin(), spacePoints.begin() + back_sps);
253 ShowerStartPosition);
258 for (
auto const& spacePoint : spacePoints) {
259 double dist = (spacePoint->position() - ShowerStartPosition).R();
263 spacePoints.erase(spacePoints.begin(), spacePoints.begin() + frontsp);
267 for (
auto const& spacePoint : spacePoints) {
268 double dist = (spacePoint->position() - ShowerStartPosition).R();
272 spacePoints.erase(spacePoints.begin() + sp_iter, spacePoints.end());
274 if (spacePoints.size() < 3) {
277 <<
"Not enough spacepoints bailing" << std::endl;
285 std::vector<art::Ptr<recob::SpacePoint>> track_sps =
289 std::vector<art::Ptr<recob::Hit>> trackHits;
290 for (
auto const& spacePoint : track_sps) {
291 std::vector<art::Ptr<recob::Hit>>
hits = fmh.at(spacePoint.key());
292 for (
auto const&
hit : hits) {
293 trackHits.push_back(
hit);
308 TPrincipal pca(3,
"");
311 for (
auto& sp : sps) {
312 auto const sp_position = sp->position();
313 double sp_coord[3] = {sp_position.X(), sp_position.Y(), sp_position.Z()};
314 pca.AddRow(sp_coord);
318 pca.MakePrincipals();
321 const TMatrixD* Eigenvectors = pca.GetEigenVectors();
323 return {(*Eigenvectors)[0][0], (*Eigenvectors)[1][0], (*Eigenvectors)[2][0]};
333 TPrincipal pca(3,
"");
335 float TotalCharge = 0;
338 for (
auto& sp : sps) {
339 auto const sp_position = sp->position();
351 wht *= std::sqrt(Charge / TotalCharge);
354 double sp_coord[3] = {sp_position.X() * wht, sp_position.Y() * wht, sp_position.Z() * wht};
355 pca.AddRow(sp_coord);
359 pca.MakePrincipals();
362 const TMatrixD* Eigenvectors = pca.GetEigenVectors();
364 return {(*Eigenvectors)[0][0], (*Eigenvectors)[1][0], (*Eigenvectors)[2][0]};
378 int maxresidual_point = 0;
388 while (!ok && segment.size() != 1) {
391 for (
auto sp = segment.begin(); sp != segment.end(); ++sp) {
392 if (sp->key() == (unsigned)maxresidual_point) {
407 std::vector<art::Ptr<recob::SpacePoint>>
414 auto const clockData =
420 std::vector<art::Ptr<recob::SpacePoint>> sps_pool = sps;
421 std::vector<art::Ptr<recob::SpacePoint>> initial_track;
422 std::vector<art::Ptr<recob::SpacePoint>> track_segment_copy;
424 while (sps_pool.size() > 0) {
427 std::vector<art::Ptr<recob::SpacePoint>> track_segment;
438 if (track_segment.empty())
break;
440 track_segment_copy = track_segment;
447 sps_pool.insert(sps_pool.begin(), track_segment.back());
448 track_segment.pop_back();
449 double current_residual = 0;
450 size_t initial_segment_size = track_segment.size();
455 if (initial_segment_size == track_segment.size()) {
469 if (
fMakeTrackSeed && initial_track.empty()) initial_track = track_segment_copy;
474 return initial_track;
483 if (initial_track.empty())
return;
485 initial_track.back(), sps_pool.front());
486 while (distance > 1 && sps_pool.size() > 0) {
487 sps_pool.erase(sps_pool.begin());
489 initial_track.back(), sps_pool.front());
498 if (initial_track.empty())
return;
499 std::vector<art::Ptr<recob::SpacePoint>>
::iterator sps_it = initial_track.begin();
500 while (sps_it != std::next(initial_track.end(), -1)) {
501 std::vector<art::Ptr<recob::SpacePoint>>
::iterator next_sps_it = std::next(sps_it, 1);
515 size_t num_sps_to_take)
517 size_t new_segment_size = segment.size() + num_sps_to_take;
518 while (segment.size() < new_segment_size && sps_pool.size() > 0) {
519 segment.push_back(sps_pool[0]);
520 sps_pool.erase(sps_pool.begin());
540 double current_residual)
545 if (sps_pool.empty())
return !ok;
553 ok =
IsResidualOK(residual, current_residual, segment.size());
556 std::vector<art::Ptr<recob::SpacePoint>> sub_sps_pool;
560 std::vector<art::Ptr<recob::SpacePoint>> sub_sps_pool_cache = sub_sps_pool;
564 sub_sps_pool_cache.insert(sub_sps_pool_cache.begin(), segment.back());
566 clockData, detProp, segment, sub_sps_pool, fmh, current_residual);
571 while (sub_sps_pool.size() > 0) {
572 sps_pool.insert(sps_pool.begin(), sub_sps_pool.back());
573 sub_sps_pool.pop_back();
582 while (sub_sps_pool_cache.size() > 0) {
583 sps_pool.insert(sps_pool.begin(), sub_sps_pool_cache.back());
584 sub_sps_pool_cache.pop_back();
593 current_residual = residual;
627 int& max_residual_point)
642 return CalculateResidual(segment, primary_axis, segment_centre, max_residual_point);
651 double current_residual)
656 if (reduced_sps_pool.empty())
return !ok;
663 ok =
IsResidualOK(residual, current_residual, segment.size());
667 clockData, detProp, segment, reduced_sps_pool, fmh, current_residual);
677 for (
auto const& sp : sps) {
680 auto const pos = sp->position() - TrackPosition;
683 double len = pos.Dot(PCAEigenvector);
684 double perp = (pos - len * PCAEigenvector).R();
695 int& max_residual_point)
const 698 double max_residual = -999;
700 for (
auto const& sp : sps) {
703 auto const pos = sp->position() - TrackPosition;
706 double len = pos.Dot(PCAEigenvector);
707 double perp = (pos - len * PCAEigenvector).R();
711 if (perp > max_residual) {
713 max_residual_point = sp.key();
719 std::vector<art::Ptr<recob::SpacePoint>>
723 std::vector<art::Ptr<recob::SpacePoint>> fake_sps;
724 std::vector<art::Ptr<recob::SpacePoint>> segment_a =
729 auto const sp_position = fake_sps.back()->position();
730 auto const direction = ROOT::Math::RotationX{10. * 3.142 / 180.}(start_direction);
731 std::vector<art::Ptr<recob::SpacePoint>> segment_b =
736 auto const branching_position = fake_sps.back()->position();
738 auto const direction_branch_a = ROOT::Math::RotationZ{15. * 3.142 / 180.}(direction);
739 std::vector<art::Ptr<recob::SpacePoint>> branch_a =
743 auto const direction_branch_b = ROOT::Math::RotationY{20. * 3.142 / 180.}(direction);
744 std::vector<art::Ptr<recob::SpacePoint>> branch_b =
748 auto const direction_branch_c = ROOT::Math::RotationX{3. * 3.142 / 180.}(direction);
749 std::vector<art::Ptr<recob::SpacePoint>> branch_c =
761 std::vector<art::Ptr<recob::SpacePoint>> fake_sps;
763 size_t current_id = 500000;
765 double step_length = 0.2;
766 for (
double i_point = 0; i_point < npoints; i_point++) {
767 auto const new_position = start_position + i_point * step_length * start_direction;
768 Double32_t xyz[3] = {new_position.X(), new_position.Y(), new_position.Z()};
769 Double32_t err[3] = {0., 0., 0.};
782 std::vector<art::Ptr<recob::SpacePoint>> fake_sps =
787 std::vector<art::Ptr<recob::SpacePoint>> track_sps =
791 for (
size_t i_sp = 0; i_sp < fake_sps.size(); i_sp++) {
792 graph_sps.SetPoint(graph_sps.GetN(),
793 fake_sps[i_sp]->XYZ()[0],
794 fake_sps[i_sp]->XYZ()[1],
795 fake_sps[i_sp]->XYZ()[2]);
797 TGraph2D graph_track_sps;
798 for (
size_t i_sp = 0; i_sp < track_sps.size(); i_sp++) {
799 graph_track_sps.SetPoint(graph_track_sps.GetN(),
800 track_sps[i_sp]->XYZ()[0],
801 track_sps[i_sp]->XYZ()[1],
802 track_sps[i_sp]->XYZ()[2]);
807 TCanvas* canvas = tfs->make<TCanvas>(
"test_inc_can",
"test_inc_can");
808 canvas->SetName(
"test_inc_can");
809 graph_sps.SetMarkerStyle(8);
810 graph_sps.SetMarkerColor(1);
811 graph_sps.SetFillColor(1);
814 graph_track_sps.SetMarkerStyle(8);
815 graph_track_sps.SetMarkerColor(2);
816 graph_track_sps.SetFillColor(2);
817 graph_track_sps.Draw(
"samep");
double DistanceBetweenSpacePoints(art::Ptr< recob::SpacePoint > const &sp_a, art::Ptr< recob::SpacePoint > const &sp_b) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Declaration of signal hit object.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
double ElectronLifetime() const
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double SpacePointTime(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
key_type key() const noexcept
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const
Detector simulation of raw signals on wires.
double SpacePointCharge(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Contains all timing reference information for the detector.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
geo::Point_t ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
2D representation of charge deposited in the TDC/wire plane
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)
cet::coded_exception< error, detail::translate > exception