118 lines
2.4 KiB
C++
118 lines
2.4 KiB
C++
//
|
|
// TrackFinder.cpp
|
|
// TrackReconstruction
|
|
//
|
|
// Created by Baranyai David on 2018. 06. 07..
|
|
//
|
|
|
|
#include "TrackFinder.hpp"
|
|
#include <iostream>
|
|
|
|
std::istream& operator >> (std::istream& is, Hit& h)
|
|
{
|
|
is >> h.ch_id >> h.fine_ts >> h.coarse_ts >> h.ts >> h.width;
|
|
if(h.ch_id < 64)
|
|
{
|
|
h.which_chamber = 0;
|
|
if(h.ch_id < 32)
|
|
{
|
|
h.direction = "x";
|
|
}
|
|
else
|
|
{
|
|
h.direction = "y";
|
|
h.ch_id = h.ch_id - 32;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
h.which_chamber = 1;
|
|
if(h.ch_id - 64 < 32)
|
|
{
|
|
h.direction = "x";
|
|
h.ch_id = h.ch_id - 64;
|
|
}
|
|
else
|
|
{
|
|
h.direction = "y";
|
|
h.ch_id = h.ch_id - 64 - 32;
|
|
}
|
|
}
|
|
return is;
|
|
}
|
|
|
|
TrackFinder::TrackFinder()
|
|
{
|
|
try
|
|
{
|
|
file.open("data.txt");
|
|
if(!file.is_open())
|
|
{
|
|
throw "File opening error";
|
|
}
|
|
SortFile();
|
|
}
|
|
catch(char param)
|
|
{
|
|
std::cout << param << std::endl;
|
|
}
|
|
}
|
|
|
|
void TrackFinder::SortFile()
|
|
{
|
|
std::cout << "Sorting data..." << std::endl;
|
|
while (file >> h)
|
|
{
|
|
hits.push_back(h);
|
|
}
|
|
std::sort(hits.begin(), hits.end(), [](const Hit& h1, const Hit& h2) {return h1.ts < h2.ts;});
|
|
std::cout << "Sorting finished!" << std::endl;
|
|
}
|
|
|
|
TrackFinder::~TrackFinder()
|
|
{
|
|
file.close();
|
|
}
|
|
|
|
bool TrackFinder::FindTrack()
|
|
{
|
|
std::cout << "Finding track..." << std::endl;
|
|
track.erase(track.begin(), track.end());
|
|
|
|
while(iterator < hits.size() - 1)
|
|
{
|
|
if(hits[iterator+1].ts - hits[iterator].ts < interval)
|
|
{
|
|
track.push_back(hits[iterator]);
|
|
}
|
|
else
|
|
{
|
|
track.push_back(hits[iterator]);
|
|
iterator++;
|
|
if(track.size() > 4)
|
|
{
|
|
istrackavailable = true;
|
|
std::cout << "Track found!" << std::endl;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
track.erase(track.begin(), track.end());
|
|
}
|
|
}
|
|
iterator++;
|
|
}
|
|
std::cout << "End reached, no more tracks found!" << std::endl;
|
|
return false;
|
|
}
|
|
|
|
void TrackFinder::GetTrack(std::vector<Hit> &h)
|
|
{
|
|
if(istrackavailable)
|
|
{
|
|
h = track;
|
|
std::cout << "Getting track..." << std::endl;
|
|
istrackavailable = false;
|
|
}
|
|
}
|