Q3D-Calibration/include/FileHandler.h

68 lines
1.6 KiB
C++

#pragma once
#ifndef file_handler_h
#define file_handler_h
#include "utils.h"
#include <TFile.h>
#include <TH1F.h>
#include <TTree.h>
#include <Eigen/Dense>
class FileHandler {
public:
FileHandler(){};
FileHandler(string, int n_ = 6, int thMin_ = 800, int thMax_ = 4000);
~FileHandler(){};
public:
int n = 6, m = 8;
int thMin, thMax, pX;
string file;
std::vector<Eigen::Vector2d> adcValue[6][8];
public:
void readData();
};
FileHandler::FileHandler(string file_, int n_, int thMin_, int thMax_) {
file = file_;
n = n_;
thMin = thMin_;
thMax = 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