From d7b2f6cf1eb5fe8eb296ba647a55b76b94aff93a Mon Sep 17 00:00:00 2001 From: YiHui Liu Date: Thu, 7 Jul 2022 01:15:19 +0800 Subject: [PATCH] add: data to block and bind --- include/BindHandler.h | 12 +++++++++--- include/BlockHandler.h | 39 +++++++++++++++++++++++++++++++++++++ include/FileHandler.h | 39 +++++++++++++++++++++++++++++++++---- include/utils.h | 44 ------------------------------------------ main.cpp | 15 +++++++++----- 5 files changed, 93 insertions(+), 56 deletions(-) create mode 100644 include/BlockHandler.h diff --git a/include/BindHandler.h b/include/BindHandler.h index 2ec132d..46bd988 100644 --- a/include/BindHandler.h +++ b/include/BindHandler.h @@ -3,8 +3,10 @@ #ifndef bind_handler_h #define bind_handler_h -#include "FileHandler.h" #include "GaussFit.h" +#include "utils.h" + +#include class BindHandler { public: @@ -12,10 +14,14 @@ public: ~BindHandler(){}; public: - std::vector data; + std::vector data; public: - void addData(FileHandler); + void addData(std::vector); }; +void BindHandler::addData(std::vector newData) { + data.insert(data.end(), newData.begin(), newData.end()); +} + #endif diff --git a/include/BlockHandler.h b/include/BlockHandler.h new file mode 100644 index 0000000..f6b7162 --- /dev/null +++ b/include/BlockHandler.h @@ -0,0 +1,39 @@ +#pragma once + +#ifndef block_handler_h +#define block_handler_h + +#include "BindHandler.h" +#include "FileHandler.h" +#include "GaussFit.h" + +class BlockHandler { +public: + BlockHandler(){}; + BlockHandler(int n_, int m_ = 8) { n = n_, m = m_; }; + ~BlockHandler(){}; + +public: + int n, m = 8; + BindHandler bind[8]; + std::vector data; + +public: + void addData(FileHandler); + void splitData(); +}; + +void BlockHandler::addData(FileHandler FH) { data.push_back(FH); } + +void BlockHandler::splitData() { + FileHandler FH; + for (int i = 0; i < data.size(); i++) { + FileHandler FH = data.at(i); + for (int j = 0; j < m; j++) { + bind[j].addData(FH.adcValue[n][j]); + std::vector().swap(FH.adcValue[n][j]); + } + } +} + +#endif diff --git a/include/FileHandler.h b/include/FileHandler.h index e26938f..d525190 100644 --- a/include/FileHandler.h +++ b/include/FileHandler.h @@ -4,9 +4,11 @@ #define file_handler_h #include "utils.h" +#include +#include +#include -using std::string; -using std::to_string; +#include class FileHandler { public: @@ -18,7 +20,7 @@ public: int n = 6, m = 8; int thMin, thMax, pX; string file; - std::vector adcValue[6][8][2]; + std::vector adcValue[6][8]; public: void readData(); @@ -31,6 +33,35 @@ FileHandler::FileHandler(string file_, int n_, int thMin_, int thMax_) { thMax = thMax_; } -void FileHandler::readData() { readROOTData(file.c_str(), adcValue, n, m, thMin, thMax); } +void FileHandler::readData() { + TFile *fRun = new TFile(file.c_str()); + TTree *t = (TTree *)fRun->Get("Tree1"); + + int na, nc, ntot = t->GetEntriesFast(); + UInt_t dataArray[6][16]; + double x1, x2; + 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++) { + x1 = dataArray[j][k]; + x2 = dataArray[j][k + m]; + if ((x1 + x2) < thMin || (x1 + x2) > thMax) continue; + adcValue[j][k].push_back(Eigen::Vector2d(x1, x2)); + } + } +} #endif diff --git a/include/utils.h b/include/utils.h index 2a46b90..b29bae6 100644 --- a/include/utils.h +++ b/include/utils.h @@ -3,12 +3,7 @@ #ifndef utils_h #define utils_h -#include -#include -#include - #include -#include #include #define DEBUG 0 @@ -87,45 +82,6 @@ double dataMax2DInd(std::vector data) { double dataStd2DSQRT(std::vector data) { return std::sqrt(dataMax2D(data)); } -void readROOTData(const char *fin, std::vector adcValue[6][8][2], int n = 6, int m = 8, - int thMin = 800, int thMax = 4000) { - // 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; - double x1, x2; - 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++) { - x1 = dataArray[j][k]; - x2 = dataArray[j][k + m]; - if ((x1 + x2) < thMin || (x1 + x2) > thMax) continue; - adcValue[j][k][0].push_back(dataArray[j][k]); - adcValue[j][k][1].push_back(dataArray[j][k]); - } - } -} - string rmString(string str, string substr) { int pos; int len = substr.length(); diff --git a/main.cpp b/main.cpp index fc9240a..d00877b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,4 @@ -#include "BindHandler.h" +#include "BlockHandler.h" #include "CsvReader.h" #include "FileHandler.h" #include "utils.h" @@ -11,6 +11,7 @@ int main() { int n; string run; FileHandler *FH; + BlockHandler *BH; CsvReader cR("config2.csv"); cR.readData(); @@ -18,14 +19,18 @@ int main() { FH = new FileHandler[n - 1]; for (int i = 1; i < n; i++) { - if (DEBUG) - run = "1250"; - else - run = cR(i, 0); + 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].readData(); } + BH = new BlockHandler[5]; + for (int i = 0; i < 5; i++) { + BH[i] = BlockHandler(4 - i); + for (int j = i * 7; j < i * 7 + 7; j++) BH[i].addData(FH[j]); + BH[i].splitData(); + } + return 0; }