change: .gitignore;add: csvReader, CHANNEL_NUMBER

This commit is contained in:
liuyihui 2022-07-05 16:55:06 +08:00
parent 1425683fc8
commit a3531e6663
5 changed files with 98 additions and 17 deletions

6
.gitignore vendored
View File

@ -1,14 +1,16 @@
# data file # data file
*.root *.root
*.log *.log
*.csv
*.json
2016Q3D/
# build cache # build cache
build/ build/
2016Q3D/
# config # config
.vscode .vscode
.vs .vs
*.json
*.code-workspace *.code-workspace
*.exe

BIN
Q3D.exe

Binary file not shown.

74
include/csvReader.h Normal file
View File

@ -0,0 +1,74 @@
#pragma once
#ifndef csv_reader_h
#define csv_reader_h
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using std::string;
using std::vector;
class csvReader {
public:
csvReader(string);
~csvReader();
public:
string file;
vector<vector<string>> 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<string> lineArray;
while (std::getline(ss, str, ',')) lineArray.push_back(str);
strArray.push_back(lineArray);
}
}
string& csvReader::operator()(int i, int j) const {
vector<string> 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<string> 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

View File

@ -3,11 +3,13 @@
#include <iostream> #include <iostream>
#define CHANNEL_NUMBER 4096
double getADC(TH1F *hist) { double getADC(TH1F *hist) {
int n, cnt = 0; int n, cnt = 0;
double *parma = new double[3]; double *parma = new double[3];
GaussFit *GF = new GaussFit(); GaussFit *GF = new GaussFit();
for (int k = 0; k < 300; k++) { for (int k = 0; k < CHANNEL_NUMBER; k++) {
n = hist->GetBinContent(k); n = hist->GetBinContent(k);
if (n == 0) continue; if (n == 0) continue;
GF->addData(k, n); GF->addData(k, n);

View File

@ -1,4 +1,5 @@
#include "getADC.h" #include "csvReader.h"
// #include "getADC.h"
#include <TFile.h> #include <TFile.h>
#include <TH1F.h> #include <TH1F.h>
#include <TTree.h> #include <TTree.h>
@ -122,21 +123,23 @@ void readData(const char *fin, TH1F Left[5][8], TH1F Right[5][8]) {
} }
int main() { int main() {
TH1F Left[5][8]; // TH1F Left[5][8];
TH1F Right[5][8]; // TH1F Right[5][8];
string L, R; // string L, R;
for (int i = 0; i < 5; i++) // for (int i = 0; i < 5; i++)
for (int j = 0; j < 8; j++) { // for (int j = 0; j < 8; j++) {
L = "Left" + to_string(i) + to_string(j); // L = "Left" + to_string(i) + to_string(j);
R = "Right" + 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); // 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(), 300, 0, 300); // 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); // readData("F:/NuclearAstroPhy/Q3D-Calibration/2016Q3D/root/raw/201609Q3D1002.root", Left,
double x = getADC(&Left[0][0]); // Right); double x = getADC(&Left[0][0]); cout << x << endl;
cout << x << endl;
csvReader cR("config.csv");
cR.readData();
return 0; return 0;
} }