add: data to block and bind
This commit is contained in:
parent
abd731a5ae
commit
d7b2f6cf1e
|
@ -3,8 +3,10 @@
|
|||
#ifndef bind_handler_h
|
||||
#define bind_handler_h
|
||||
|
||||
#include "FileHandler.h"
|
||||
#include "GaussFit.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
class BindHandler {
|
||||
public:
|
||||
|
@ -12,10 +14,14 @@ public:
|
|||
~BindHandler(){};
|
||||
|
||||
public:
|
||||
std::vector<FileHandler> data;
|
||||
std::vector<Eigen::Vector2d> data;
|
||||
|
||||
public:
|
||||
void addData(FileHandler);
|
||||
void addData(std::vector<Eigen::Vector2d>);
|
||||
};
|
||||
|
||||
void BindHandler::addData(std::vector<Eigen::Vector2d> newData) {
|
||||
data.insert(data.end(), newData.begin(), newData.end());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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<FileHandler> 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<Eigen::Vector2d>().swap(FH.adcValue[n][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,9 +4,11 @@
|
|||
#define file_handler_h
|
||||
|
||||
#include "utils.h"
|
||||
#include <TFile.h>
|
||||
#include <TH1F.h>
|
||||
#include <TTree.h>
|
||||
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
#include <Eigen/Dense>
|
||||
|
||||
class FileHandler {
|
||||
public:
|
||||
|
@ -18,7 +20,7 @@ public:
|
|||
int n = 6, m = 8;
|
||||
int thMin, thMax, pX;
|
||||
string file;
|
||||
std::vector<int> adcValue[6][8][2];
|
||||
std::vector<Eigen::Vector2d> 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
|
||||
|
|
|
@ -3,12 +3,7 @@
|
|||
#ifndef utils_h
|
||||
#define utils_h
|
||||
|
||||
#include <TFile.h>
|
||||
#include <TH1F.h>
|
||||
#include <TTree.h>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
|
||||
#define DEBUG 0
|
||||
|
@ -87,45 +82,6 @@ double dataMax2DInd(std::vector<Eigen::Vector2d> data) {
|
|||
|
||||
double dataStd2DSQRT(std::vector<Eigen::Vector2d> data) { return std::sqrt(dataMax2D(data)); }
|
||||
|
||||
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);
|
||||
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();
|
||||
|
|
15
main.cpp
15
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue