refactor: old method

This commit is contained in:
liuyihui 2022-07-06 23:42:52 +08:00
parent 0a8ef2e252
commit 9e63b34088
5 changed files with 8 additions and 79 deletions

View File

@ -19,18 +19,13 @@ public:
int n = 6, m = 8;
int thMin, thMax, pX;
string file;
double adcValue[6][8][2];
TH1F Left[6][8];
TH1F Right[6][8];
std::vector<int> adcValue[6][8][2];
public:
double getADC(TH1F hist);
void solve();
void readData();
void save();
void save(string);
private:
void init();
};
FileHandler::FileHandler() {}
@ -44,17 +39,6 @@ FileHandler::FileHandler(string file_, int n_, int thMin_, int thMax_) {
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];
@ -70,18 +54,7 @@ double FileHandler::getADC(TH1F hist) {
return parma[1];
}
void FileHandler::solve() {
init();
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]);
}
}
void FileHandler::readData() { readROOTData(file.c_str(), adcValue, n, m, thMin, thMax); }
void FileHandler::save() {
string path = rmString(file, ".root") + ".csv";
@ -90,12 +63,6 @@ void FileHandler::save() {
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++)
ofs << pX << "," << i << "," << j << "," << adcValue[i][j][0] << ","
<< adcValue[i][j][1] << std::endl;
}
#endif

View File

@ -51,16 +51,9 @@ void GaussFit::addData(double x, double y) { data.push_back(Eigen::Vector2d(x, y
double* GaussFit::fit(int type_) {
double x, y;
SigmaClip* SC1 = new SigmaClip(1, 5, dataMax2DInd, dataStd2DSQRT);
SigmaClip* SC2 = new SigmaClip();
data = SC1->clipN(data);
data = SC2->clip(data);
if (getTotal() <= 400) {
for (int i = 0; i < 3; i++) parma[i] = 0;
return parma;
}
parma[0] = dataMax2D(data);
parma[1] = dataAvg2D(data);
parma[2] = dataStd2D(data);
@ -89,7 +82,7 @@ double* GaussFit::fit(int type_) {
if (DEBUG) std::cout << parma[0] << " " << parma[1] << ", " << parma[2] << std::endl;
if (DEBUG) std::cout << RSquare() << std::endl;
if (RSquare() < 0.5)
if (RSquare() < 0.6)
for (int i = 0; i < 3; i++) parma[i] = 0;
return parma;

View File

@ -62,23 +62,4 @@ std::vector<Eigen::Vector2d> SigmaClip::clip(std::vector<Eigen::Vector2d> data)
return data;
}
std::vector<Eigen::Vector2d> SigmaClip::clipN(std::vector<Eigen::Vector2d> data) {
std::vector<Eigen::Vector2d> dataN;
std::vector<Eigen::Vector2d>::iterator itor;
minValue = INF, maxValue = -INF;
for (int k = 1; k <= maxiters; k++) {
computeBound(data);
for (itor = data.begin(); itor != data.end();) {
if ((*itor)(0) < minValue || (*itor)(0) > maxValue) {
dataN.push_back(Eigen::Vector2d((*itor)(0), (*itor)(1)));
data.erase(itor);
} else
itor++;
}
}
return dataN;
}
#endif

View File

@ -87,7 +87,7 @@ double dataMax2DInd(std::vector<Eigen::Vector2d> data) {
double dataStd2DSQRT(std::vector<Eigen::Vector2d> data) { return std::sqrt(dataMax2D(data)); }
void readROOTData(const char *fin, TH1F Left[6][8], TH1F Right[6][8], int n = 6, int m = 8,
void readROOTData(const char *fin, std::vector<int> adcValue[6][8][2], int n = 6, int m = 8,
int thMin = 800, int thMax = 4000) {
// read file
TFile *fRun = new TFile(fin);
@ -120,20 +120,10 @@ void readROOTData(const char *fin, TH1F Left[6][8], TH1F Right[6][8], int n = 6,
x1 = dataArray[j][k];
x2 = dataArray[j][k + m];
if ((x1 + x2) < thMin || (x1 + x2) > thMax) continue;
Left[j][k].Fill(dataArray[j][k]);
Right[j][k].Fill(dataArray[j][k + m]);
adcValue[j][k][0].push_back(dataArray[j][k]);
adcValue[j][k][1].push_back(dataArray[j][k]);
}
}
// Rebin
int nMax;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
nMax = Left[i][j].GetMaximum();
if (nMax < 50) Left[i][j] = *(TH1F *)(Left[i][j].Rebin(8));
nMax = Right[i][j].GetMaximum();
if (nMax < 50) Right[i][j] = *(TH1F *)(Right[i][j].Rebin(8));
}
}
string rmString(string str, string substr) {

View File

@ -22,9 +22,7 @@ int main() {
run = cR(i, 0);
FH[i - 1] = FileHandler("2016Q3D/root/raw/201609Q3D" + run + ".root", 5);
FH[i - 1].pX = stoi(cR(i, 5));
FH[i - 1].solve();
if (!DEBUG) FH[i - 1].save("result/adc/201609Q3D" + run + ".csv");
if (DEBUG) break;
FH[i - 1].readData();
}
return 0;