17 #include "TPrincipal.h" 35 const art::FindManyP<recob::Hit>& fmh);
44 size_t num_sps_to_take);
52 const art::FindManyP<recob::Hit>& fmh,
53 double current_residual);
58 const art::FindManyP<recob::Hit>& fmh);
63 const art::FindManyP<recob::Hit>& fmh,
64 int& max_residual_point);
71 const art::FindManyP<recob::Hit>& fmh,
72 double current_residual);
80 IsResidualOK(
double new_residual,
double current_residual,
size_t no_sps)
92 TVector3& PCAEigenvector,
93 TVector3& TrackPosition);
96 TVector3& PCAEigenvector,
97 TVector3& TrackPosition,
98 int& max_residual_point);
106 const art::FindManyP<recob::Hit>& fmh);
109 TVector3 start_direction);
110 std::vector<art::Ptr<recob::SpacePoint>>
CreateFakeSPLine(TVector3 start_position,
111 TVector3 start_direction,
114 const art::FindManyP<recob::Hit>& dud_fmh);
119 const art::FindManyP<recob::Hit>& fmh);
164 pset.
get<
std::
string>(
"InitialTrackSpacePointsOutputLabel"))
168 <<
"We cannot make a track if you don't gives us at leats one hit. Change fStartFitSize " 169 "please to something sensible";
184 <<
"Start position not set, returning " <<
std::endl;
192 const art::FindManyP<recob::SpacePoint>& fmspp =
196 auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(
fPFParticleLabel);
199 const art::FindManyP<recob::Hit>& fmh =
203 std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.
key());
206 if (spacePoints.empty()) {
209 <<
"No space points, returning " <<
std::endl;
213 TVector3 ShowerStartPosition = {-999, -999, -999};
222 <<
"Direction not set, returning " <<
std::endl;
226 TVector3 ShowerDirection = {-999, -999, -999};
231 spacePoints, ShowerStartPosition, ShowerDirection);
235 for (
auto spacePoint : spacePoints) {
237 spacePoint, ShowerStartPosition, ShowerDirection);
238 if (proj < 0) { ++back_sps; }
239 if (proj > 0) {
break; }
241 spacePoints.erase(spacePoints.begin(), spacePoints.begin() + back_sps);
247 ShowerStartPosition);
252 for (
auto spacePoint : spacePoints) {
259 spacePoints.erase(spacePoints.begin(), spacePoints.begin() + frontsp);
263 for (
auto spacePoint : spacePoints) {
270 spacePoints.erase(spacePoints.begin() + sp_iter, spacePoints.end());
272 if (spacePoints.size() < 3) {
275 <<
"Not enough spacepoints bailing" <<
std::endl;
283 std::vector<art::Ptr<recob::SpacePoint>> track_sps =
287 std::vector<art::Ptr<recob::Hit>> trackHits;
288 for (
auto const& spacePoint : track_sps) {
289 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(spacePoint.key());
290 for (
auto const&
hit : hits) {
291 trackHits.push_back(
hit);
307 TPrincipal* pca =
new TPrincipal(3,
"");
310 for (
auto& sp : sps) {
315 sp_coord[0] = sp_position.X();
316 sp_coord[1] = sp_position.Y();
317 sp_coord[2] = sp_position.Z();
320 pca->AddRow(sp_coord);
324 pca->MakePrincipals();
327 const TMatrixD* Eigenvectors = pca->GetEigenVectors();
329 TVector3 Eigenvector = {(*Eigenvectors)[0][0], (*Eigenvectors)[1][0], (*Eigenvectors)[2][0]};
342 const art::FindManyP<recob::Hit>& fmh)
346 TPrincipal* pca =
new TPrincipal(3,
"");
348 float TotalCharge = 0;
351 for (
auto& sp : sps) {
371 wht *= std::sqrt(Charge / TotalCharge);
375 sp_coord[0] = sp_position.X() * wht;
376 sp_coord[1] = sp_position.Y() * wht;
377 sp_coord[2] = sp_position.Z() * wht;
380 pca->AddRow(sp_coord);
384 pca->MakePrincipals();
387 const TMatrixD* Eigenvectors = pca->GetEigenVectors();
389 TVector3 Eigenvector = {(*Eigenvectors)[0][0], (*Eigenvectors)[1][0], (*Eigenvectors)[2][0]};
402 const art::FindManyP<recob::Hit>& fmh)
407 int maxresidual_point = 0;
417 while (!ok && segment.size() != 1) {
420 for (
auto sp = segment.begin(); sp != segment.end(); ++sp) {
421 if (sp->key() == (unsigned)maxresidual_point) {
436 std::vector<art::Ptr<recob::SpacePoint>>
440 const art::FindManyP<recob::Hit>& fmh)
443 auto const clockData =
449 std::vector<art::Ptr<recob::SpacePoint>> sps_pool = sps;
450 std::vector<art::Ptr<recob::SpacePoint>> initial_track;
451 std::vector<art::Ptr<recob::SpacePoint>> track_segment_copy;
453 while (sps_pool.size() > 0) {
456 std::vector<art::Ptr<recob::SpacePoint>> track_segment;
467 if (track_segment.empty())
break;
469 track_segment_copy = track_segment;
476 sps_pool.insert(sps_pool.begin(), track_segment.back());
477 track_segment.pop_back();
478 double current_residual = 0;
479 size_t initial_segment_size = track_segment.size();
484 if (initial_segment_size == track_segment.size()) {
498 if (
fMakeTrackSeed && initial_track.empty()) initial_track = track_segment_copy;
503 return initial_track;
513 if (initial_track.empty())
return;
515 initial_track.back(), sps_pool.front());
516 while (distance > 1 && sps_pool.size() > 0) {
517 sps_pool.erase(sps_pool.begin());
519 initial_track.back(), sps_pool.front());
529 if (initial_track.empty())
return;
530 std::vector<art::Ptr<recob::SpacePoint>>
::iterator sps_it = initial_track.begin();
531 while (sps_it != std::next(initial_track.end(), -1)) {
532 std::vector<art::Ptr<recob::SpacePoint>>
::iterator next_sps_it = std::next(sps_it, 1);
547 size_t num_sps_to_take)
549 size_t new_segment_size = segment.size() + num_sps_to_take;
550 while (segment.size() < new_segment_size && sps_pool.size() > 0) {
551 segment.push_back(sps_pool[0]);
552 sps_pool.erase(sps_pool.begin());
573 const art::FindManyP<recob::Hit>& fmh,
574 double current_residual)
579 if (sps_pool.empty())
return !ok;
587 ok =
IsResidualOK(residual, current_residual, segment.size());
590 std::vector<art::Ptr<recob::SpacePoint>> sub_sps_pool;
594 std::vector<art::Ptr<recob::SpacePoint>> sub_sps_pool_cache = sub_sps_pool;
598 sub_sps_pool_cache.insert(sub_sps_pool_cache.begin(), segment.back());
600 clockData, detProp, segment, sub_sps_pool, fmh, current_residual);
605 while (sub_sps_pool.size() > 0) {
606 sps_pool.insert(sps_pool.begin(), sub_sps_pool.back());
607 sub_sps_pool.pop_back();
616 while (sub_sps_pool_cache.size() > 0) {
617 sps_pool.insert(sps_pool.begin(), sub_sps_pool_cache.back());
618 sub_sps_pool_cache.pop_back();
627 current_residual = residual;
639 const art::FindManyP<recob::Hit>& fmh)
642 TVector3 primary_axis;
648 TVector3 segment_centre;
665 const art::FindManyP<recob::Hit>& fmh,
666 int& max_residual_point)
669 TVector3 primary_axis;
675 TVector3 segment_centre;
682 double residual =
CalculateResidual(segment, primary_axis, segment_centre, max_residual_point);
693 const art::FindManyP<recob::Hit>& fmh,
694 double current_residual)
699 if (reduced_sps_pool.empty())
return !ok;
706 ok =
IsResidualOK(residual, current_residual, segment.size());
710 clockData, detProp, segment, reduced_sps_pool, fmh, current_residual);
715 TVector3& PCAEigenvector,
716 TVector3& TrackPosition)
721 for (
auto const& sp : sps) {
727 double len = pos.Dot(PCAEigenvector);
728 double perp = (pos - len * PCAEigenvector).Mag();
737 TVector3& PCAEigenvector,
738 TVector3& TrackPosition,
739 int& max_residual_point)
743 double max_residual = -999;
745 for (
auto const& sp : sps) {
751 double len = pos.Dot(PCAEigenvector);
752 double perp = (pos - len * PCAEigenvector).Mag();
756 if (perp > max_residual) {
758 max_residual_point = sp.key();
764 std::vector<art::Ptr<recob::SpacePoint>>
766 TVector3 start_direction)
768 std::vector<art::Ptr<recob::SpacePoint>> fake_sps;
769 std::vector<art::Ptr<recob::SpacePoint>> segment_a =
774 TVector3 sp_position =
777 direction.RotateX(10. * 3.142 / 180.);
778 std::vector<art::Ptr<recob::SpacePoint>> segment_b =
783 TVector3 branching_position =
787 direction_branch_a.RotateZ(15. * 3.142 / 180.);
788 std::vector<art::Ptr<recob::SpacePoint>> branch_a =
793 direction_branch_b.RotateY(20. * 3.142 / 180.);
794 std::vector<art::Ptr<recob::SpacePoint>> branch_b =
799 direction_branch_c.RotateX(3. * 3.142 / 180.);
800 std::vector<art::Ptr<recob::SpacePoint>> branch_c =
807 std::vector<art::Ptr<recob::SpacePoint>>
809 TVector3 start_direction,
812 std::vector<art::Ptr<recob::SpacePoint>> fake_sps;
814 size_t current_id = 500000;
816 double step_length = 0.2;
817 for (
double i_point = 0; i_point < npoints; i_point++) {
818 TVector3 new_position = start_position + i_point * step_length * start_direction;
819 Double32_t xyz[3] = {new_position.X(), new_position.Y(), new_position.Z()};
820 Double32_t
err[3] = {0., 0., 0.};
830 const art::FindManyP<recob::Hit>& dud_fmh)
832 TVector3 start_position(50, 50, 50);
833 TVector3 start_direction(0, 0, 1);
834 std::vector<art::Ptr<recob::SpacePoint>> fake_sps =
839 std::vector<art::Ptr<recob::SpacePoint>> track_sps =
843 for (
size_t i_sp = 0; i_sp < fake_sps.size(); i_sp++) {
844 graph_sps.SetPoint(graph_sps.GetN(),
845 fake_sps[i_sp]->XYZ()[0],
846 fake_sps[i_sp]->XYZ()[1],
847 fake_sps[i_sp]->XYZ()[2]);
849 TGraph2D graph_track_sps;
850 for (
size_t i_sp = 0; i_sp < track_sps.size(); i_sp++) {
851 graph_track_sps.SetPoint(graph_track_sps.GetN(),
852 track_sps[i_sp]->XYZ()[0],
853 track_sps[i_sp]->XYZ()[1],
854 track_sps[i_sp]->XYZ()[2]);
859 TCanvas* canvas = tfs->make<TCanvas>(
"test_inc_can",
"test_inc_can");
860 canvas->SetName(
"test_inc_can");
861 graph_sps.SetMarkerStyle(8);
862 graph_sps.SetMarkerColor(1);
863 graph_sps.SetFillColor(1);
866 graph_track_sps.SetMarkerStyle(8);
867 graph_track_sps.SetMarkerColor(2);
868 graph_track_sps.SetFillColor(2);
869 graph_track_sps.Draw(
"samep");
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
double DistanceBetweenSpacePoints(art::Ptr< recob::SpacePoint > const &sp_a, art::Ptr< recob::SpacePoint > const &sp_b) const
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
double ElectronLifetime() const
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double SpacePointTime(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
key_type key() const noexcept
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool CheckElement(const std::string &Name) const
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
int GetElement(const std::string &Name, T &Element) const
void err(const char *fmt,...)
Detector simulation of raw signals on wires.
double SpacePointCharge(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
Contains all timing reference information for the detector.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
TVector3 ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
2D representation of charge deposited in the TDC/wire plane
auto const & get(AssnsNode< L, R, D > const &r)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const