New reader script. Should work with more than 2 chambers.

This commit is contained in:
Gitea 2018-06-11 00:15:36 +02:00
parent 94bb25ef34
commit 08f0b08759
3 changed files with 46 additions and 27 deletions

View File

@ -22,7 +22,6 @@ int main(int argc, char* argv[])
std::vector<Hit> x;
std::vector<Hit> y;
TrackFinder finder;
//int iterator = 0;
canvas -> cd(0);
@ -33,14 +32,18 @@ int main(int argc, char* argv[])
{
if(std::cin.get() == '\n')
{
x.clear();
y.clear();
track.clear();
if(finder.FindTrack())
{
finder.GetTrack(track);
/*
Handling is easier if we separate the results to X and Y
*/
for(int i = 0; i < track.size(); i++)
{
if (track[i].direction == "x")
@ -51,6 +54,7 @@ int main(int argc, char* argv[])
{
y.push_back(track[i]);
}
std::cout << track[i];
}
std::cout << "X size = " << x.size() << std::endl;
@ -59,7 +63,6 @@ int main(int argc, char* argv[])
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++)
@ -68,8 +71,6 @@ int main(int argc, char* argv[])
{
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");

View File

@ -50,4 +50,6 @@ private:
std::vector<Hit> track;
};
std::ostream& operator << (std::ostream&, const Hit&);
#endif /* TrackFinder_hpp */

View File

@ -8,36 +8,37 @@
#include "TrackFinder.hpp"
#include <iostream>
std::ostream& operator << (std::ostream& os, const Hit& h)
{
os <<
"Channel ID: " << h.ch_id << std::endl <<
"Chamber ID: " << h.which_chamber << std::endl <<
"Direction: " << h.direction << std::endl;
return os;
}
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)
int ch_id_helper = 0;
h.which_chamber = h.ch_id / 64; //Determine which chamber's data is it
ch_id_helper = h.ch_id % 64; //Store the channel id from 0 - 32 in it's own direction
/*
the numbering of the channels starts from X 0 - 32 and Y 32-64
*/
if(ch_id_helper < 32)
{
h.which_chamber = 0;
if(h.ch_id < 32)
{
h.direction = "x";
}
else
{
h.direction = "y";
h.ch_id = h.ch_id - 32;
}
h.direction = "x";
h.ch_id = ch_id_helper;
}
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;
}
h.direction = "y";
h.ch_id = ch_id_helper - 32;
}
return is;
}
@ -52,6 +53,7 @@ TrackFinder::TrackFinder()
}
SortFile();
}
//Check if any errors happen when opening the file
catch(char param)
{
std::cout << param << std::endl;
@ -60,6 +62,10 @@ TrackFinder::TrackFinder()
void TrackFinder::SortFile()
{
/*
Read the file line by line and store it in the memory.
At the end of the file, sort the data by TS ascending.
*/
std::cout << "Sorting data..." << std::endl;
while (file >> h)
{
@ -79,6 +85,13 @@ bool TrackFinder::FindTrack()
std::cout << "Finding track..." << std::endl;
track.erase(track.begin(), track.end());
/*
If a new track found,
then we don't want to start from the beginning
so the iterator helps us storing the last value.
Set the Interval to the right value for better track reconstruction.
*/
while(iterator < hits.size() - 1)
{
if(hits[iterator+1].ts - hits[iterator].ts < interval)
@ -108,6 +121,9 @@ bool TrackFinder::FindTrack()
void TrackFinder::GetTrack(std::vector<Hit> &h)
{
/*
Copy the track's data into the new vector if available
*/
if(istrackavailable)
{
h = track;