REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawFemDAQToSignalProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
73
74#include "TRestRawFemDAQToSignalProcess.h"
75
76#include <TObjString.h>
77
78#ifndef NO_YAML_CPP
79#include <yaml-cpp/yaml.h>
80#endif
81
82using namespace std;
83
85
86TRestRawFemDAQToSignalProcess::TRestRawFemDAQToSignalProcess() { Initialize(); }
87
88TRestRawFemDAQToSignalProcess::TRestRawFemDAQToSignalProcess(const char* configFilename) { Initialize(); }
89
90TRestRawFemDAQToSignalProcess::~TRestRawFemDAQToSignalProcess() {}
91
93 delete fSignalEvent;
94 fSignalEvent = new TRestRawSignalEvent();
95
96 fIsExternal = true; // We need this in order to prevent error since we are not reading a rest root file
97 fSingleThreadOnly = true;
98}
99
101 // print input aqs file
102 const auto inputFilename = fRunInfo->GetInputFileName(0);
103
104 // verify it is a root file reading the last 5 characters
105 if (inputFilename.substr(inputFilename.size() - 5) != ".root") {
106 cerr << "TRestRawFemDAQToSignalProcess::InitProcess: Input file is not a root file" << endl;
107 exit(1);
108 }
109
110 fInputFile = TFile::Open(inputFilename.c_str(), "READ");
111 if (!fInputFile) {
112 cerr << "TRestRawFemDAQToSignalProcess::InitProcess: Error opening input file" << endl;
113 exit(1);
114 }
115 fInputFile->cd();
116
117 fInputTree = fInputFile->Get<TTree>("SignalEvent");
118 fRunInfo->SetFeminosDaqTotalEvents(fInputTree->GetEntries());
119
120 if (!fInputTree) {
121 cerr << "TRestRawFemDAQToSignalProcess::InitProcess: Error opening input trees" << endl;
122 exit(1);
123 }
124
125 TObjString* tsObj = (TObjString*)fInputFile->Get("startTime");
126 TObjString* etObj = (TObjString*)fInputFile->Get("endTime");
127 if (tsObj) {
128 Double_t startTimestamp = std::stod(tsObj->GetString().Data());
129 fRunInfo->SetStartTimeStamp(startTimestamp);
130 }
131 if (etObj) {
132 Double_t endTimestamp = std::stod(etObj->GetString().Data());
133 fRunInfo->SetEndTimeStamp(endTimestamp);
134 }
135
136#ifndef NO_YAML_CPP
137 if (fUseFeminosDaqRunInfo) {
138 TObjString* yamlConfigObj = (TObjString*)fInputFile->Get("RunConfigYAML");
139 TObjString* yamlfNameObj = (TObjString*)fInputFile->Get("yaml_fileName");
140
141 if (yamlConfigObj) {
142 std::string yamlConfig = yamlConfigObj->GetString().Data();
143 std::cout << "Config YAML: " << yamlConfig << std::endl;
144 YAML::Node config = YAML::Load(yamlConfig);
145 YAML::Node run = config["run"];
146 // std::string exp = run["experiment"].as<std::string>();
147 // fRunInfo->fExperimentName = (TString)exp;
148 std::string tag = run["tag"].as<std::string>();
149 fRunInfo->SetRunTag(tag);
150 std::string type = run["type"].as<std::string>();
151 fRunInfo->SetRunType(type);
152 // TODO Add run info?
153 }
154
155 if (yamlfNameObj) {
156 std::string fileName = yamlfNameObj->GetString().Data();
157 std::cout << "Config fileName: " << fileName << std::endl;
158 }
159 }
160#else
161 fUseFeminosDaqRunInfo = false;
162#endif
163
164 fInputTree->SetBranchAddress("timestamp", &fTimestamp);
165 fInputTree->SetBranchAddress("signalsID", &fSignalIds);
166 fInputTree->SetBranchAddress("pulses", &fSignalValues);
167 fInputTree->SetBranchAddress("eventID", &fEventID);
168}
169
171 fSignalEvent->Initialize();
172
173 fInputTree->GetEntry(fInputTreeEntry);
174
175 fSignalEvent->SetID(fEventID);
176
177 // fTimestamp is in seconds
178 fSignalEvent->SetTime(fTimestamp);
179
180 // get the first event timestamp
181 if (fTimestamp < fStartTimestamp) {
182 fStartTimestamp = fTimestamp;
183 }
184 // get the last event timestamp
185 if (fTimestamp > fEndTimestamp) {
186 fEndTimestamp = fTimestamp;
187 }
188
189 for (size_t i = 0; i < fSignalIds->size(); i++) {
190 auto signal = TRestRawSignal();
191 signal.Initialize();
192
193 const auto id = fSignalIds->at(i);
194 signal.SetID(id);
195
196 for (int j = 0; j < 512; j++) {
197 signal.AddPoint(short(fSignalValues->at(i * 512 + j)));
198 }
199
200 fSignalEvent->AddSignal(signal);
201 }
202
203 fInputTreeEntry++;
204
205 if (fInputTreeEntry >= fInputTree->GetEntries()) {
206 return nullptr;
207 }
208
209 return fSignalEvent;
210}
211
213 if (fSetRunStartEndFromEvents) {
214 fRunInfo->SetStartTimeStamp(fStartTimestamp);
215 fRunInfo->SetEndTimeStamp(fEndTimestamp);
216 }
217}
bool fIsExternal
It defines if the process reads event data from an external source.
TRestRun * fRunInfo
< Pointer to TRestRun object where to find metadata.
A base class for any REST event.
Definition: TRestEvent.h:38
void SetTime(Double_t time)
Definition: TRestEvent.cxx:85
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void Initialize() override
Making default settings.
An event container for time rawdata signals with fixed length.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.