2022-07-05 19:02:59 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef file_handler_h
|
|
|
|
#define file_handler_h
|
|
|
|
|
|
|
|
#include "GaussFit.h"
|
|
|
|
#include <TH1F.h>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::to_string;
|
|
|
|
|
|
|
|
class FileHandler {
|
|
|
|
public:
|
|
|
|
FileHandler();
|
2022-07-06 23:33:12 +08:00
|
|
|
FileHandler(string, int n_ = 6, int thMin_ = 800, int thMax_ = 4000);
|
2022-07-05 19:02:59 +08:00
|
|
|
~FileHandler();
|
|
|
|
|
|
|
|
public:
|
2022-07-06 23:33:12 +08:00
|
|
|
int n = 6, m = 8;
|
|
|
|
int thMin, thMax, pX;
|
2022-07-05 19:02:59 +08:00
|
|
|
string file;
|
|
|
|
double adcValue[6][8][2];
|
|
|
|
TH1F Left[6][8];
|
|
|
|
TH1F Right[6][8];
|
|
|
|
|
|
|
|
public:
|
|
|
|
double getADC(TH1F hist);
|
|
|
|
void solve();
|
|
|
|
void save();
|
|
|
|
void save(string);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
};
|
|
|
|
|
|
|
|
FileHandler::FileHandler() {}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
FileHandler::FileHandler(string file_, int n_, int thMin_, int thMax_) {
|
2022-07-05 19:02:59 +08:00
|
|
|
file = file_;
|
|
|
|
n = n_;
|
2022-07-06 23:33:12 +08:00
|
|
|
thMin = thMin_;
|
|
|
|
thMax = thMax_;
|
2022-07-05 19:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FileHandler::~FileHandler() {}
|
|
|
|
|
|
|
|
void FileHandler::init() {
|
|
|
|
string L, R;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
for (int j = 0; j < m; 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double FileHandler::getADC(TH1F hist) {
|
|
|
|
int n, cnt = 0;
|
|
|
|
double *parma = new double[3];
|
2022-07-06 23:33:12 +08:00
|
|
|
GaussFit GF = GaussFit();
|
2022-07-05 19:02:59 +08:00
|
|
|
for (int k = 10; k < CHANNEL_NUMBER; k++) {
|
|
|
|
n = hist.GetBinContent(k);
|
|
|
|
if (n == 0) continue;
|
2022-07-06 23:33:12 +08:00
|
|
|
GF.addData(hist.GetBinCenter(k), n);
|
2022-07-05 19:02:59 +08:00
|
|
|
}
|
2022-07-06 23:33:12 +08:00
|
|
|
parma = GF.fit();
|
|
|
|
if (DEBUG) GF.draw();
|
2022-07-05 19:02:59 +08:00
|
|
|
|
|
|
|
return parma[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileHandler::solve() {
|
|
|
|
init();
|
2022-07-06 23:33:12 +08:00
|
|
|
readROOTData(file.c_str(), Left, Right, n, m, thMin, thMax);
|
|
|
|
if (DEBUG)
|
|
|
|
std::cout << getADC(Left[3][2]) << std::endl;
|
|
|
|
else
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
for (int j = 0; j < m; j++) {
|
|
|
|
adcValue[i][j][0] = getADC(Left[i][j]);
|
|
|
|
adcValue[i][j][1] = getADC(Right[i][j]);
|
|
|
|
}
|
2022-07-05 19:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileHandler::save() {
|
|
|
|
string path = rmString(file, ".root") + ".csv";
|
|
|
|
save(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileHandler::save(string path) {
|
|
|
|
std::ofstream ofs(path);
|
|
|
|
|
|
|
|
ofs << "pX,X4,Bind,Left,Right" << std::endl;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
for (int j = 0; j < m; j++)
|
2022-07-06 23:33:12 +08:00
|
|
|
ofs << pX << "," << i << "," << j << "," << adcValue[i][j][0] << ","
|
|
|
|
<< adcValue[i][j][1] << std::endl;
|
2022-07-05 19:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|