物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

Read track text file

Read track files

Track struct has 6 members. four double members and two int members. The double members include position x, position y, angle x, angle y. The int members include pulse height and pulse height volume.

Q1. Make track class.

class track {
public:
    //insert here.
    //insert here.
};

The track data files is as follows. Lines that start with # are comments.

#pos_x[mm] pos_y[mm] angle_x angle_y ph phv
-58.5483 156.9036   -0.0039 -0.0358    16.0 1430.8
-58.5148 156.8275   0.0016 -0.0544    16.0 6449.2
-58.5998 156.8236   -0.0370 -0.0273    16.0 6325.0
-58.5134 156.8441   -0.0415 -0.0422    16.0 1698.3
-58.5704 156.8770   -0.0004 -0.0117    16.0 454.6
-58.5388 156.8782   0.0233 -0.0309    16.0 759.4
-58.4927 156.8461   0.0506 -0.0412    16.0 1826.0
-58.5128 156.8928   0.0409 -0.0024    16.0 1784.3
-58.5469 156.8413   0.0558 -0.0208    16.0 2264.7

Q2. Make read function.

#include <string>
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>

void read_txt(std::string filepath, std::vector<track> &vin)
{
    std::ifstream ifs(filepath);
    if (!ifs) {
        throw std::exception(("cannot open " + filepath).c_str());
    }
    std::string str;
    while (getline(ifs, str))
    {
        if (str.size() == 0) { continue; } //to ignore null lines
        if (str[0] == '#') { continue; } //to ignore comment lines
        stringstream ss(str);
        //insert here
        //insert here
        //insert here
    }
}

Download these files.

https://1drv.ms/t/s!Ap9xAxIuzM0xlLlaOr2g5qaKpYqF2w

https://1drv.ms/t/s!Ap9xAxIuzM0xlLlbUgqNsGvbe4Eq6w

Q3. Make main function to check the size of the tracks each file.

int main() {
    string path1 = "beam_4372-0_u.txt";
    string path2 = "beam_4372-0_d.txt";
    vector<track> vtrack1, vtrack2;
    //insert here
    //insert here
    //insert here
    //insert here
}