Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AtData/AtHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AtHit : public TObject {
Double_t GetTimeStampCorrInter() const { return fTimeStampCorrInter; }
const std::vector<AtHit::MCSimPoint> &GetMCSimPointArray() const { return fMCSimPointArray; }

static Bool_t SortHit(const AtHit &lhs, const AtHit &rhs) { return lhs.GetPadNum() < rhs.GetPadNum(); }
static Bool_t SortHit(const AtHit &lhs, const AtHit &rhs) { return lhs.GetPadNum() > rhs.GetPadNum(); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be reverted and a function like

static Bool_t SortHitReverse(const AtHit &lhs, const AtHit &rhs) { return lhs.GetPadNum() > rhs.GetPadNum(); }

added

static Bool_t SortHit(const std::unique_ptr<AtHit> &lhs, const std::unique_ptr<AtHit> &rhs)
{
return SortHit(*lhs, *rhs);
Expand Down
2 changes: 1 addition & 1 deletion AtData/AtTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AtTrack : public TObject {
const HitVector &GetHitArray() const { return fHitArray; }

std::vector<AtHit> GetHitArrayObject() { return ContainerManip::GetObjectVector(fHitArray); }
// const std::vector<AtHit> &GetHitArrayConst() const { return fHitArray; }
//const std::vector<AtHit> &GetHitArrayConst() const { return fHitArray; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will probably fail the linter (clang-format)

const AtPatterns::AtPattern *GetPattern() const { return fPattern.get(); }

Double_t GetGeoTheta() const { return fGeoThetaAngle; }
Expand Down
6 changes: 3 additions & 3 deletions AtReconstruction/AtFitter/AtGenfit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ AtFITTER::AtGenfit::AtGenfit(Float_t magfield, Float_t minbrho, Float_t maxbrho,
std::cout << " AtFITTER::AtGenfit::AtGenfit(): Checking materials that GENFIT will use "
<< "\n";

auto *gGeoMan = dynamic_cast<TGeoManager *>(gROOT->FindObject("FAIRGeom"));
/*auto *gGeoMan = dynamic_cast<TGeoManager *>(gROOT->FindObject("FAIRGeom"));
TObjArray *volume_list = gGeoMan->GetListOfVolumes();
if (!volume_list) {
std::cout << cRED << " Warning! Null list of geometry volumes." << cNORMAL << "\n";
Expand All @@ -105,7 +105,7 @@ AtFITTER::AtGenfit::AtGenfit(Float_t magfield, Float_t minbrho, Float_t maxbrho,
// Int_t mat_indx = mat->GetIndex();
std::cout << cYELLOW << " - Material : " << mat->GetName() << cNORMAL << "\n";
}

*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yassid Will this break things for experiments? I'm not that familiar with the GenFit code.

// PDG definitions
const Double_t kAu2Gev = 0.9314943228;
const Double_t khSlash = 1.0545726663e-27;
Expand Down Expand Up @@ -609,7 +609,7 @@ std::vector<std::unique_ptr<AtFittedTrack>> AtFITTER::AtGenfit::ProcessTracks(st
// Backward extrapolation
try {

for (auto iStep = 0; iStep < 200; ++iStep) {
for (auto iStep = 0; iStep < 600; ++iStep) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yassid Same questions on this bit. I image this should track teach hit cluster for the backwards propogation to smooth?


trackRep->extrapolateBy(fitState, stepXtr * iStep);
mom_ext_buff = fitState.getMom();
Expand Down
25 changes: 23 additions & 2 deletions AtReconstruction/AtPatternRecognition/AtPRA.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,28 @@ std::cout << " Processing track with " << track.GetHitArray().size() << " points
RansacSmoothRadius.SetMinHitsPattern(0.1 * track.GetHitArray().size());
RansacSmoothRadius.SetDistanceThreshold(6.0);
RansacSmoothRadius.SetNumIterations(1000);
auto circularTracks = RansacSmoothRadius.Solve(ContainerManip::GetConstPointerVector(track.GetHitArray()))
track.SortHitArrayTime();
auto &hitArray = track.GetHitArray();
size_t numHits = hitArray.size();
size_t numHitsToUse;
if (numHits >= 50)
numHitsToUse = numHits * 10 / 10; // 50% of the hits

if (numHits < 50)
numHitsToUse = numHits;

std::sort(hitArray.begin(), hitArray.end(), [](const std::unique_ptr<AtHit> &a, const std::unique_ptr<AtHit> &b) {
return a->GetTimeStamp() > b->GetTimeStamp();
});

std::vector<std::unique_ptr<AtHit>> first20PercentHits;
first20PercentHits.reserve(numHitsToUse);

for (size_t i = 0; i < numHitsToUse; ++i) {
first20PercentHits.push_back(std::make_unique<AtHit>(*hitArray[i]));
}

auto circularTracks = RansacSmoothRadius.Solve(ContainerManip::GetConstPointerVector(first20PercentHits)) // Only part of the spiral is used
Comment on lines +51 to +72
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added as a flag in the class. Something like bool fFitPercentage so the old behavior is preserved for those that rely on it.

.GetTrackCand(); // Only part of the spiral is used
// This function also sets the coefficients
// i.e. radius of curvature and center
Expand All @@ -60,7 +81,7 @@ std::cout << " Processing track with " << track.GetHitArray().size() << " points
// auto circle = dynamic_cast<const AtPatterns::AtPatternCircle2D *>(circularTracks.at(0).GetPattern());

auto circle = std::make_unique<AtPatterns::AtPatternCircle2D>();
circle->AtPattern::FitPattern(ContainerManip::GetConstPointerVector(track.GetHitArray()));
circle->AtPattern::FitPattern(ContainerManip::GetConstPointerVector(first20PercentHits));

auto center = circle->GetCenter();
auto radius = circle->GetRadius();
Expand Down
3 changes: 3 additions & 0 deletions AtReconstruction/AtPatternRecognition/AtSampleConsensus.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ AtSampleConsensus::GeneratePatternFromHits(const std::vector<const AtHit *> &hit
AtPatternEvent AtSampleConsensus::Solve(AtEvent *event)
{
auto hitVec = ContainerManip::GetConstPointerVector(event->GetHits());
std::cout<<"AtSampleConsensus::Solve"<<std::endl;

return Solve(hitVec, event);
}

Expand All @@ -71,6 +73,7 @@ AtPatternEvent AtSampleConsensus::Solve(const std::vector<AtHit> &hitArray, AtBa

AtPatternEvent AtSampleConsensus::Solve(const std::vector<const AtHit *> &hitArray, AtBaseEvent *event)
{

// Return early if we were passed an event and it is marked bad
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest just reverting all the changes in this file. Or moving the cout to a LOG(DEBUG)

if (event != nullptr && !event->IsGood())
return {*event};
Expand Down
Empty file.
210 changes: 207 additions & 3 deletions AtReconstruction/AtPatternRecognition/AtTrackFinderTC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "AtHit.h" // for AtHit
#include "AtPatternEvent.h" // for AtPatternEvent
#include "AtTrack.h" // for AtTrack
#include "AtTrackTransformer.h" // for AtTrackTransformer
#include "AtTrackTransformer.h"
#include "AtFitter.h" // for AtTrackTransformer
#include "AtTrackFinder.h"

#include <Math/Point3D.h> // for PositionVector3D

Expand All @@ -25,6 +27,11 @@ constexpr auto cRED = "\033[1;31m";
constexpr auto cYELLOW = "\033[1;33m";
constexpr auto cNORMAL = "\033[0m";
constexpr auto cGREEN = "\033[1;32m";
std::vector<AtTrack *> candTrackPool;
std::vector<AtTrack> mergedTrackPool;
Bool_t fEnableSingleVertexTrack = kTRUE;
Double_t fClusterSize = 20.0;

Comment on lines +30 to +34
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be members of the class. If they're changed they require rebuilding - they should be changeable on a per-instance bases.

Technically the pools can live here, but right now they are in the global namespace which is bad. If they're defined in the file like this, they should live in an anonymous namespace like

namespace {
std::vector<AtTrack *> candTrackPool;
std::vector<AtTrack> mergedTrackPool;
}

but I don't really like that solution since it breaks with the patterns used in the rest of the codebase


AtPATTERN::AtTrackFinderTC::AtTrackFinderTC() : AtPATTERN::AtPRA() {}

Expand Down Expand Up @@ -87,12 +94,24 @@ std::unique_ptr<AtPatternEvent> AtPATTERN::AtTrackFinderTC::FindTracks(AtEvent &
add_clusters(cloud_xyz, cl_group, opt_params.is_gnuplot());

// Post processing
// process_pointcloud(cloud_xyz, 25, 0);
//process_pointcloud(cloud_xyz, 25, 0);

// Adapt clusters to AtTrack
return clustersToTrack(cloud_xyz, cl_group, event);
}

const double tolerance = 3.0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a parameter set on a per-instance level (no recompiling if changed - will work for all experiments)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this also lives int he global namespace?

Bool_t SameTrack(AtTrack *trA, AtTrack *trB)
{
auto theta0 = trA->GetGeoTheta();
auto theta = trB->GetGeoTheta();

if (std::abs((theta0 * TMath::RadToDeg()) - (theta * TMath::RadToDeg())) <= tolerance)
return true;
else
return false;
}

void AtPATTERN::AtTrackFinderTC::eventToClusters(AtEvent &event, PointCloud &cloud)
{
Int_t nHits = event.GetNumHits();
Expand All @@ -112,7 +131,6 @@ void AtPATTERN::AtTrackFinderTC::eventToClusters(AtEvent &event, PointCloud &clo
std::unique_ptr<AtPatternEvent>
AtPATTERN::AtTrackFinderTC::clustersToTrack(PointCloud &cloud, const std::vector<cluster_t> &clusters, AtEvent &event)
{

std::vector<AtTrack> tracks;
// std::vector<Point> points = cloud;
auto points = cloud;
Expand Down Expand Up @@ -160,11 +178,197 @@ AtPATTERN::AtTrackFinderTC::clustersToTrack(PointCloud &cloud, const std::vector
for (const auto &point : points)
retEvent->AddNoise(event.GetHit(point.GetID()));

for (auto &track : tracks) {
if (track.GetHitArray().size() > 0)
SetTrackInitialParameters(track);
//retEvent->AddTrack(std::move(track));
}

bool kMergeTracks = false;

std::vector<AtTrack> mergedTracks;
if(tracks.size() > 2){

//const double tolerance = 2.0;
std::vector<bool> processed(tracks.size(), false);

for(Int_t numtr = 0; numtr < tracks.size(); numtr++){
std::cout << "Theta " << tracks.at(numtr).GetGeoTheta() << std::endl;
if (processed[numtr]) continue;

auto track0 = tracks.at(numtr);
auto hitArray0 = track0.GetHitArrayObject();
auto theta0 = track0.GetGeoTheta();

AtTrack newTrack;

for(auto &hit : hitArray0){
newTrack.AddHit(hit);

}

if (numtr + 1 < tracks.size()) {

for (size_t tr = numtr + 1; tr < tracks.size(); ++tr) {
if (processed[tr]) continue;

auto track = tracks.at(tr);
auto hitArray = track.GetHitArrayObject();
auto theta = track.GetGeoTheta();

if (std::abs((theta0 * TMath::RadToDeg()) - (theta * TMath::RadToDeg())) <= tolerance) {
for(auto &hit : hitArray){
newTrack.AddHit(hit);

}
processed[tr] = true;
}

}
}

processed[numtr] = true;
fTrackTransformer->ClusterizeSmooth3D(newTrack, fClusterRadius, fClusterDistance);
mergedTracks.push_back(newTrack);

}

kMergeTracks = true;
}

if(kMergeTracks){
std::swap(tracks, mergedTracks);
}

Comment on lines +181 to +242
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track merging should be controlled by a run-time flag. Changes to core classes like this should retain the old behavior by default (or it could break code for others)

for (auto &track : tracks) {
if (track.GetHitArray().size() > 0)
SetTrackInitialParameters(track);
retEvent->AddTrack(std::move(track));
}



return retEvent;
}





//First try of merging tracks
/* bool kMergeTracks = false;

if(tracks.size() > 2){

const double tolerance = 2.0;
std::vector<bool> processed(tracks.size(), false);

for(Int_t numtr = 0; numtr < tracks.size(); numtr++){
std::cout << "Theta " << tracks.at(numtr).GetGeoTheta() << std::endl;
if (processed[numtr]) continue;

auto track0 = tracks.at(numtr);
auto hitArray0 = track0.GetHitArrayObject();
auto theta0 = track0.GetGeoTheta();

AtTrack newTrack;

for(auto &hit : hitArray0){
newTrack.AddHit(hit);

}

if (numtr + 1 < tracks.size()) {

for (size_t tr = numtr + 1; tr < tracks.size(); ++tr) {
if (processed[tr]) continue;

auto track = tracks.at(tr);
auto hitArray = track.GetHitArrayObject();
auto theta = track.GetGeoTheta();

if (std::abs((theta0 * TMath::RadToDeg()) - (theta * TMath::RadToDeg())) <= tolerance) {
for(auto &hit : hitArray){
newTrack.AddHit(hit);

}
processed[tr] = true;
}

}
}

processed[numtr] = true;
//fTrackTransformer->ClusterizeSmooth3D(newTrack, fClusterRadius, fClusterDistance);
mergedTracks.push_back(newTrack);

}

kMergeTracks = true;
}

if(kMergeTracks){
std::swap(tracks, mergedTracks);
}
*/

/*
auto sp = std::unique_ptr<AtTrack[]>(new AtTrack[tracks.size()]);


for (auto iTrack = 0; iTrack < tracks.size(); ++iTrack) {
sp[iTrack] = tracks.at(iTrack);
candTrackPool.push_back(std::move(&sp[iTrack]));

}

std::vector<AtTrack *> candToMergePool;
AtTrackFinder merger;
for (auto itA = candTrackPool.begin(); itA != candTrackPool.end(); ++itA) {
if(candTrackPool.size() == 0) break;
AtTrack *trA = *(itA);
if(candTrackPool.size() == 1){
mergedTrackPool.push_back(*trA);
break;
}
candToMergePool.clear();

auto itB = std::copy_if(itA + 1, candTrackPool.end(), std::back_inserter(candToMergePool),
[&trA, this](AtTrack *track) { return SameTrack(trA, track); });

std::cout << "candToMergePool size after copy_if: " << candToMergePool.size() << std::endl;

if (candToMergePool.size() > 0) { // Merge if matches are found
candToMergePool.push_back(trA);
Bool_t merged = merger.MergeTracks(&candToMergePool, &mergedTrackPool, fEnableSingleVertexTrack, fClusterRadius,
fClusterSize);

std::cout << "Merged: " << merged << std::endl;
std::cout << "candTrackPool size before erase: " << candTrackPool.size() << std::endl;

itA = candTrackPool.erase(std::remove_if(itA, candTrackPool.end(),
[&trA, this](AtTrack *track) { return SameTrack(trA, track); }),
candTrackPool.end());

} else {
mergedTrackPool.push_back(*trA);
itA = candTrackPool.erase(itA); // Erase the track from the pool
}

}

std::swap(tracks, mergedTrackPool);

candToMergePool.clear();
candTrackPool.clear();
//mergedTrackPool.clear();

/* for (auto &track : tracks) {
if (track.GetHitArray().size() > 0)
SetTrackInitialParameters(track);
retEvent->AddTrack(std::move(track));
}*/
//std::cout << "Number of tracks: " << tracks.size() << std::endl;
Comment on lines +258 to +371
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code (should live in commit history, not in source file)




Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/** @file */

#include "directedgraph.h"
#include "orthogonallsq.h"
#include "pointcloud.h"

#include "util.h"
#include <assert.h> /* assert */
Expand Down Expand Up @@ -41,17 +43,17 @@ Graph::Graph(PointCloud &cloud, std::vector<size_t> _indices)
assert(std::set<size_t>(_indices.begin(), _indices.end()).size() == _indices.size()); // indices are unique
assert((indices.back() < cloud.size())); // checks range of indices

this->indices = indices;

this->indices = _indices;
// insert Nodes without Edges. Nodes have x,y,z Coordinates and the corresponding index
for (unsigned int i = 0; i < indices.size(); i++) {
graph.insert(std::pair<size_t, Node>(
indices[i], Node(indices[i], cloud[indices[i]].x, cloud[indices[i]].y, cloud[indices[i]].z)));
}

// Add first subtree: the first Point by time and the last Point by Index
this->subtree_roots.push_back(&graph.at(indices[indices.size() - 1]));

// construct MST by adding Edges
constructMST();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "pointcloud.h"

class PointCloud;

Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary to forward declare since the class is defined in the included header?

//
// orthogonal least squares fit with libeigen
// pc: points
Expand Down
Loading