diff --git a/scripts/rest_raw_to_feminos_daq.C b/scripts/rest_raw_to_feminos_daq.C new file mode 100644 index 0000000..67cc699 --- /dev/null +++ b/scripts/rest_raw_to_feminos_daq.C @@ -0,0 +1,57 @@ +#include +#include +#include + +#include +#include +#include + +using namespace std; + +void rest_raw_to_feminos_daq(const std::string& input_filename, const std::string& output_filename) { + std::cout << "Input file: " << input_filename << std::endl; + + auto input_file = TFile::Open(input_filename.c_str(), "READ"); + auto input_tree = input_file->Get("EventTree"); + + TRestRawSignalEvent* event = nullptr; + + input_tree->SetBranchAddress("TRestRawSignalEventBranch", &event); + + auto output_file = TFile::Open(output_filename.c_str(), "RECREATE"); + auto output_tree = TTree("events", "events"); + + unsigned long long timestamp = 0; + std::vector signal_ids; + std::vector signal_values; + + output_tree.Branch("timestamp", ×tamp); + output_tree.Branch("signal_ids", &signal_ids); + output_tree.Branch("signal_values", &signal_values); + + for (int i = 0; i < input_tree->GetEntries(); i++) { + signal_ids.clear(); + signal_values.clear(); + + input_tree->GetEntry(i); + + for (int j = 0; j < event->GetNumberOfSignals(); j++) { + TRestRawSignal* signal = event->GetSignal(j); + signal_ids.push_back(signal->GetSignalID()); + for (int k = 0; k < signal->GetNumberOfPoints(); k++) { + signal_values.push_back(signal->GetData(k)); + } + } + + // make sure the length of signal_data is 512 the length of signal_ids + if (signal_values.size() != 512 * signal_ids.size()) { + std::cerr << "Error: signal_values.size() != 512 * signal_ids.size()" << std::endl; + return; + } + + output_tree.Fill(); + } + + output_file->Write(); + output_file->Close(); +}