Timeanalysis
Timeanalysis
#include <vector>
#include <TH1D.h>
#include <TFile.h>
#include <TTree.h>
#include <TGraph.h>
#include <TF1.h>
// Function to fit rising edge and compute TOA at the baseline level
double computeTOA(const vector<double>& voltage, const vector<double>& time) {
double baseline = computeBaseline(voltage);
auto [start, end] = findRisingEdge(voltage, baseline);
TGraph graph;
for (int i = start; i < end; i++) {
graph.SetPoint(graph.GetN(), time[i], voltage[i]);
}
return (baseline - a) / b; // Time at which the fit crosses the baseline level
}
double time;
vector<double> channel1, channel2;
tree->SetBranchAddress("Time", &time);
tree->SetBranchAddress("CH1", &channel1);
tree->SetBranchAddress("CH2", &channel2);
if (isValidValue(channel1[i])) ch1Waveform.push_back(channel1[i]);
if (isValidValue(channel2[i])) ch2Waveform.push_back(channel2[i]);
}
file->Close();
if (ch1Waveform.empty() || ch2Waveform.empty()) {
cerr << "❌ Skipping file due to empty waveform data!" << endl;
continue;
}
double toaCh1 = computeTOA(ch1Waveform, timeValues);
double toaCh2 = computeTOA(ch2Waveform, timeValues);
cout << "✅ Time difference histogram computed successfully!" << endl;
}