0% found this document useful (0 votes)
3 views1 page

Avgwave

The document contains a C++ function that computes the average waveform from a list of ROOT files. It reads data from a TTree named 'WaveformTree' and stores original waveforms in a vector. The function checks for errors in file access and tree retrieval, providing appropriate error messages if issues arise.

Uploaded by

Om
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Avgwave

The document contains a C++ function that computes the average waveform from a list of ROOT files. It reads data from a TTree named 'WaveformTree' and stores original waveforms in a vector. The function checks for errors in file access and tree retrieval, providing appropriate error messages if issues arise.

Uploaded by

Om
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include <vector>
#include <TH1D.h>
#include <TFile.h>
#include <TTree.h>

using namespace std;

// Function to compute average waveform


void computeAvgWaveform(const vector<string>& rootFiles, TH1D* avgHistOriginal,
TH1D* avgHistBaseline) {
if (rootFiles.empty()) {
cerr << "❌ Error: No ROOT files provided for averaging!" << endl;
return;
}

vector<vector<double>> allOriginalWaveforms;
vector<vector<double>> allBaselineWaveforms;
vector<double> timeValues;

for (const auto& fileName : rootFiles) {


TFile* file = TFile::Open(fileName.c_str(), "READ");
if (!file || file->IsZombie()) {
cerr << "❌ Error: Could not open ROOT file: " << fileName << endl;
continue;
}

TTree* tree = (TTree*)file->Get("WaveformTree");


if (!tree) {
cerr << "❌ Error: Could not find waveform tree in " << fileName <<
endl;
file->Close();
continue;
}

double time;
vector<double> channelValues;

tree->SetBranchAddress("Time", &time);
tree->SetBranchAddress("CH1", &channelValues);

vector<double> originalWaveform;
vector<double> baselineCorrectedWaveform;

for (int i = 0; i < tree->GetEntries(); i++) {


tree->GetEntry(i);
originalWaveform.push_back(channelValues[i]);
}

file->Close();

allOriginalWaveforms.push_back(originalWaveform);
}

cout << "✅ Average waveform computed successfully!" << endl;


}

You might also like