change: .gitignore;add: csvReader, CHANNEL_NUMBER
This commit is contained in:
parent
1425683fc8
commit
a3531e6663
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,14 +1,16 @@
|
||||
# data file
|
||||
*.root
|
||||
*.log
|
||||
*.csv
|
||||
*.json
|
||||
2016Q3D/
|
||||
|
||||
# build cache
|
||||
build/
|
||||
2016Q3D/
|
||||
|
||||
# config
|
||||
.vscode
|
||||
.vs
|
||||
*.json
|
||||
|
||||
*.code-workspace
|
||||
*.exe
|
||||
|
74
include/csvReader.h
Normal file
74
include/csvReader.h
Normal 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
|
@ -3,11 +3,13 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#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);
|
||||
|
31
main.cpp
31
main.cpp
@ -1,4 +1,5 @@
|
||||
#include "getADC.h"
|
||||
#include "csvReader.h"
|
||||
// #include "getADC.h"
|
||||
#include <TFile.h>
|
||||
#include <TH1F.h>
|
||||
#include <TTree.h>
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user