Working version
This commit is contained in:
parent
7f57002a7f
commit
be2bb32a4a
|
@ -0,0 +1,42 @@
|
||||||
|
# $Id: CMakeLists.txt Baranyai Dávid | 2018.06.05 18:52:01 $
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Setup the project
|
||||||
|
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
||||||
|
project(TrackReconstruction)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Find ROOT (required package)
|
||||||
|
#
|
||||||
|
find_package(ROOT REQUIRED)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Setup ROOT include directories and compile definitions
|
||||||
|
#
|
||||||
|
include(${ROOT_USE_FILE})
|
||||||
|
|
||||||
|
# Setup include directory for this project
|
||||||
|
#
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
set(ROOT_LIBRARIES -L${ROOT_LIBRARY_DIR} -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Locate sources and headers for this project
|
||||||
|
# NB: headers are included so they will show up in IDEs
|
||||||
|
#
|
||||||
|
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cpp)
|
||||||
|
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hpp)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Add the executable
|
||||||
|
#
|
||||||
|
add_executable(TrackReconstruction TrackReconstruction.cpp ${sources} ${headers})
|
||||||
|
target_link_libraries(TrackReconstruction ${ROOT_LIBRARIES} )
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
|
||||||
|
#
|
||||||
|
install(TARGETS TrackReconstruction DESTINATION bin)
|
|
@ -0,0 +1,85 @@
|
||||||
|
//
|
||||||
|
// TrackReconstruction.cpp
|
||||||
|
// DB_Track
|
||||||
|
//
|
||||||
|
// Created by Baranyai David on 2018. 06. 07..
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "TApplication.h"
|
||||||
|
#include "TrackFinder.hpp"
|
||||||
|
#include "TH3D.h"
|
||||||
|
#include "TCanvas.h"
|
||||||
|
#include "TSystem.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
TApplication App("tapp", &argc, argv);
|
||||||
|
TCanvas *canvas = new TCanvas();
|
||||||
|
TH3D *threedhisto = new TH3D("threedhisto", "threedhisto", 100, 0, 32, 100, 0, 32, 100, 0, 2);
|
||||||
|
std::vector<Hit> track;
|
||||||
|
std::vector<Hit> x;
|
||||||
|
std::vector<Hit> y;
|
||||||
|
TrackFinder finder;
|
||||||
|
//int iterator = 0;
|
||||||
|
|
||||||
|
canvas -> cd(0);
|
||||||
|
|
||||||
|
std::cout << "Press Enter for new track" << std:: endl;
|
||||||
|
std::cout << "or press Ctrl + C to exit" << std::endl;
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(std::cin.get() == '\n')
|
||||||
|
{
|
||||||
|
x.clear();
|
||||||
|
y.clear();
|
||||||
|
track.clear();
|
||||||
|
|
||||||
|
if(finder.FindTrack())
|
||||||
|
{
|
||||||
|
finder.GetTrack(track);
|
||||||
|
|
||||||
|
for(int i = 0; i < track.size(); i++)
|
||||||
|
{
|
||||||
|
if (track[i].direction == "x")
|
||||||
|
{
|
||||||
|
x.push_back(track[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
y.push_back(track[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "X size = " << x.size() << std::endl;
|
||||||
|
std::cout << "Y size = " << y.size() << std::endl;
|
||||||
|
|
||||||
|
if(x.size() > 0 && y.size() > 0)
|
||||||
|
{
|
||||||
|
threedhisto -> Reset();
|
||||||
|
//iterator = 1;
|
||||||
|
for(int x1 = 0; x1 < x.size(); x1++)
|
||||||
|
{
|
||||||
|
for(int y1 = 0; y1 < y.size(); y1++)
|
||||||
|
{
|
||||||
|
if(x[x1].which_chamber == y[y1].which_chamber)
|
||||||
|
{
|
||||||
|
threedhisto -> Fill(x[x1].ch_id, y[y1].ch_id, x[x1].which_chamber);
|
||||||
|
}
|
||||||
|
//std::cout << "Drawing " << iterator << " of " << x.size()*y.size() << std::endl;
|
||||||
|
//iterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
threedhisto -> Draw("lego2");
|
||||||
|
canvas -> Update();
|
||||||
|
gSystem -> ProcessEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
App.Run();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
//
|
||||||
|
// TrackFinder.hpp
|
||||||
|
// TrackReconstruction
|
||||||
|
//
|
||||||
|
// Created by Baranyai David on 2018. 06. 07..
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TrackFinder_hpp
|
||||||
|
#define TrackFinder_hpp
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
struct Hit
|
||||||
|
{
|
||||||
|
unsigned int ch_id;
|
||||||
|
unsigned int fine_ts;
|
||||||
|
unsigned int coarse_ts;
|
||||||
|
unsigned long ts;
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int which_chamber;
|
||||||
|
std::string direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TrackFinder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TrackFinder();
|
||||||
|
~TrackFinder();
|
||||||
|
bool FindTrack();
|
||||||
|
void GetTrack(std::vector<Hit>&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SortFile();
|
||||||
|
|
||||||
|
std::ifstream file;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
int interval = 2000;
|
||||||
|
unsigned int iterator = 0;
|
||||||
|
|
||||||
|
bool istrackavailable = false;
|
||||||
|
|
||||||
|
Hit h;
|
||||||
|
|
||||||
|
std::vector<Hit> hits;
|
||||||
|
std::vector<Hit> track;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* TrackFinder_hpp */
|
|
@ -0,0 +1,117 @@
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue