diff --git a/.gitignore b/.gitignore index eaac86d..e3021eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,16 @@ # data file *.root *.log +*.csv +*.json +2016Q3D/ # build cache build/ -2016Q3D/ # config .vscode .vs -*.json *.code-workspace +*.exe diff --git a/Q3D.exe b/Q3D.exe deleted file mode 100644 index 29f843b..0000000 Binary files a/Q3D.exe and /dev/null differ diff --git a/include/csvReader.h b/include/csvReader.h new file mode 100644 index 0000000..1a5f5cb --- /dev/null +++ b/include/csvReader.h @@ -0,0 +1,74 @@ +#pragma once + +#ifndef csv_reader_h +#define csv_reader_h + +#include +#include +#include +#include +#include + +using std::string; +using std::vector; + +class csvReader { +public: + csvReader(string); + ~csvReader(); + +public: + string file; + vector> strArray; + +public: + int rows(); + void readData(); + string& operator()(int i, int j) const; +}; + +csvReader::csvReader(string file_) { file = file_; } + +csvReader::~csvReader() {} + +int csvReader::rows() { return strArray.size(); } + +void csvReader::readData() { + std::ifstream inFile(file); + string lineStr; + while (std::getline(inFile, lineStr)) { + std::stringstream ss(lineStr); + string str; + vector lineArray; + while (std::getline(ss, str, ',')) lineArray.push_back(str); + strArray.push_back(lineArray); + } +} + +string& csvReader::operator()(int i, int j) const { + vector lineArray; + int n = strArray.size(), m; + + if (i < 0 || i > n - 1) std::cout << "Row Index Out Of Bounds " << std::endl; + lineArray = strArray.at(i); + m = lineArray.size(); + if (j < 0 || j > m - 1) std::cout << "Column Index Out Of Bounds " << std::endl; + + return lineArray.at(j); +} + +std::ostream& operator<<(std::ostream& cout, csvReader& cR) { + vector lineArray; + int n = cR.strArray.size(), m; + + for (int i = 0; i < n; i++) { + lineArray = cR.strArray.at(i); + m = lineArray.size(); + for (int j = 0; j < m; j++) cout << lineArray.at(j) << " "; + if (i < n - 1) cout << std::endl; + } + + return cout; +} + +#endif diff --git a/include/getADC.h b/include/getADC.h index 2633e83..620daee 100644 --- a/include/getADC.h +++ b/include/getADC.h @@ -3,11 +3,13 @@ #include +#define CHANNEL_NUMBER 4096 + double getADC(TH1F *hist) { int n, cnt = 0; double *parma = new double[3]; GaussFit *GF = new GaussFit(); - for (int k = 0; k < 300; k++) { + for (int k = 0; k < CHANNEL_NUMBER; k++) { n = hist->GetBinContent(k); if (n == 0) continue; GF->addData(k, n); diff --git a/main.cpp b/main.cpp index 81210e2..9dc9730 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ -#include "getADC.h" +#include "csvReader.h" +// #include "getADC.h" #include #include #include @@ -122,21 +123,23 @@ void readData(const char *fin, TH1F Left[5][8], TH1F Right[5][8]) { } int main() { - TH1F Left[5][8]; - TH1F Right[5][8]; + // TH1F Left[5][8]; + // TH1F Right[5][8]; - string L, R; - for (int i = 0; i < 5; i++) - for (int j = 0; j < 8; j++) { - L = "Left" + to_string(i) + to_string(j); - R = "Right" + to_string(i) + to_string(j); - Left[i][j] = TH1F(L.c_str(), L.c_str(), 300, 0, 300); - Right[i][j] = TH1F(R.c_str(), R.c_str(), 300, 0, 300); - } + // string L, R; + // for (int i = 0; i < 5; i++) + // for (int j = 0; j < 8; j++) { + // L = "Left" + to_string(i) + to_string(j); + // R = "Right" + to_string(i) + to_string(j); + // Left[i][j] = TH1F(L.c_str(), L.c_str(), CHANNEL_NUMBER, 0, CHANNEL_NUMBER); + // Right[i][j] = TH1F(R.c_str(), R.c_str(), CHANNEL_NUMBER, 0, CHANNEL_NUMBER); + // } - readData("F:/NuclearAstroPhy/Q3D-Calibration/2016Q3D/root/raw/201609Q3D1002.root", Left, Right); - double x = getADC(&Left[0][0]); - cout << x << endl; + // readData("F:/NuclearAstroPhy/Q3D-Calibration/2016Q3D/root/raw/201609Q3D1002.root", Left, + // Right); double x = getADC(&Left[0][0]); cout << x << endl; + + csvReader cR("config.csv"); + cR.readData(); return 0; }