2022-07-05 19:02:59 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef utils_h
|
|
|
|
#define utils_h
|
|
|
|
|
|
|
|
#include <TFile.h>
|
|
|
|
#include <TH1F.h>
|
|
|
|
#include <TTree.h>
|
|
|
|
|
|
|
|
#include <Eigen/Dense>
|
2022-07-06 23:33:12 +08:00
|
|
|
#include <ios>
|
2022-07-05 19:02:59 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
#define DEBUG 0
|
2022-07-05 19:02:59 +08:00
|
|
|
#define INF 1e9
|
|
|
|
#define CHANNEL_NUMBER 4096
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
using namespace std;
|
2022-07-05 19:02:59 +08:00
|
|
|
using std::string;
|
|
|
|
using std::to_string;
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataMax(std::vector<double> data) {
|
|
|
|
double x, m = -INF;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
x = data.at(i);
|
|
|
|
m = std::max(m, x);
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataAvg(std::vector<double> data) {
|
|
|
|
double m = 0;
|
|
|
|
for (int i = 0; i < data.size(); i++) m += data.at(i);
|
|
|
|
return m / data.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataStd(std::vector<double> data) {
|
|
|
|
double m = 0;
|
|
|
|
double mu = dataAvg(data);
|
|
|
|
for (int i = 0; i < data.size(); i++) m += std::pow(data.at(i) - mu, 2);
|
|
|
|
return m / (data.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataMax2D(std::vector<Eigen::Vector2d> data) {
|
2022-07-05 19:02:59 +08:00
|
|
|
double m = -INF;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
m = std::max(m, point(1));
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataAvg2D(std::vector<Eigen::Vector2d> data) {
|
2022-07-05 19:02:59 +08:00
|
|
|
int n = 0;
|
|
|
|
double m = 0;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
n += point(1);
|
|
|
|
m += point(0) * point(1);
|
|
|
|
}
|
|
|
|
return m / n;
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataStd2D(std::vector<Eigen::Vector2d> data) {
|
2022-07-05 19:02:59 +08:00
|
|
|
int n = 0;
|
|
|
|
double m = 0;
|
2022-07-06 23:33:12 +08:00
|
|
|
double mu = dataAvg2D(data);
|
2022-07-05 19:02:59 +08:00
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
n += point(1);
|
|
|
|
m += std::pow(point(0) - mu, 2) * point(1);
|
|
|
|
}
|
|
|
|
return std::sqrt(m / (n - 1));
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataMax2DInd(std::vector<Eigen::Vector2d> data) {
|
|
|
|
double x = 0, m = -INF;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
if (point(1) > m) {
|
|
|
|
x = point(0);
|
|
|
|
m = point(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataStd2DSQRT(std::vector<Eigen::Vector2d> data) { return std::sqrt(dataMax2D(data)); }
|
|
|
|
|
2022-07-06 23:42:52 +08:00
|
|
|
void readROOTData(const char *fin, std::vector<int> adcValue[6][8][2], int n = 6, int m = 8,
|
2022-07-06 23:33:12 +08:00
|
|
|
int thMin = 800, int thMax = 4000) {
|
2022-07-05 19:02:59 +08:00
|
|
|
// read file
|
|
|
|
TFile *fRun = new TFile(fin);
|
|
|
|
TTree *t = (TTree *)fRun->Get("Tree1");
|
|
|
|
|
|
|
|
// data numbers
|
|
|
|
Long64_t ntot = t->GetEntriesFast();
|
|
|
|
|
|
|
|
// five X-4 block
|
|
|
|
UInt_t dataArray[6][16];
|
|
|
|
|
|
|
|
// read adc data
|
|
|
|
int na, nc;
|
2022-07-06 23:33:12 +08:00
|
|
|
double x1, x2;
|
2022-07-05 19:02:59 +08:00
|
|
|
string adc;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
for (int j = 0; j < m; j++) {
|
|
|
|
na = i / 2;
|
|
|
|
nc = j + 2 * m * (i % 2);
|
|
|
|
adc = "adc" + to_string(na) + "ch" + to_string(nc);
|
|
|
|
t->SetBranchAddress(adc.c_str(), &dataArray[i][j]);
|
|
|
|
adc = "adc" + to_string(na) + "ch" + to_string(nc + m);
|
|
|
|
t->SetBranchAddress(adc.c_str(), &dataArray[i][j + m]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < ntot; i++) {
|
|
|
|
t->GetEntry(i);
|
|
|
|
for (int j = 0; j < n; j++)
|
|
|
|
for (int k = 0; k < m; k++) {
|
2022-07-06 23:33:12 +08:00
|
|
|
x1 = dataArray[j][k];
|
|
|
|
x2 = dataArray[j][k + m];
|
|
|
|
if ((x1 + x2) < thMin || (x1 + x2) > thMax) continue;
|
2022-07-06 23:42:52 +08:00
|
|
|
adcValue[j][k][0].push_back(dataArray[j][k]);
|
|
|
|
adcValue[j][k][1].push_back(dataArray[j][k]);
|
2022-07-05 19:02:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string rmString(string str, string substr) {
|
|
|
|
int pos;
|
|
|
|
int len = substr.length();
|
|
|
|
while (true) {
|
|
|
|
pos = str.find(substr);
|
|
|
|
if (pos < 0) break;
|
|
|
|
str.erase(pos, len);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|