REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawFeminosRootToSignalProcess.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
78
79#include "TRestRawFeminosRootToSignalProcess.h"
80
81using namespace std;
82
84
85TRestRawFeminosRootToSignalProcess::TRestRawFeminosRootToSignalProcess() { Initialize(); }
86
87TRestRawFeminosRootToSignalProcess::TRestRawFeminosRootToSignalProcess(const char* configFilename) {
88 Initialize();
89}
90
91TRestRawFeminosRootToSignalProcess::~TRestRawFeminosRootToSignalProcess() {}
92
94 delete fSignalEvent;
95 fSignalEvent = new TRestRawSignalEvent();
96
97 fIsExternal = true; // We need this in order to prevent error since we are not reading a rest root file
98 fSingleThreadOnly = true;
99}
100
102 // print input aqs file
103 const auto inputFilename = fRunInfo->GetInputFileName(0);
104
105 // verify it is a root file reading the last 5 characters
106 if (inputFilename.substr(inputFilename.size() - 5) != ".root") {
107 cerr << "TRestRawFeminosRootToSignalProcess::InitProcess: Input file is not a root file" << endl;
108 exit(1);
109 }
110
111 fInputFile = TFile::Open(inputFilename.c_str(), "READ");
112 if (!fInputFile) {
113 cerr << "TRestRawFeminosRootToSignalProcess::InitProcess: Error opening input file" << endl;
114 exit(1);
115 }
116 fInputFile->cd();
117
118 fInputRunTree = fInputFile->Get<TTree>("run");
119 fInputEventTree = fInputFile->Get<TTree>("events");
120
121 if (!fInputRunTree || !fInputEventTree) {
122 cerr << "TRestRawFeminosRootToSignalProcess::InitProcess: Error opening input trees" << endl;
123 exit(1);
124 }
125
126 if (fUseFeminosDaqRunInfo) {
127 ULong64_t startTimeStampMilliseconds = 0;
128 ULong64_t runNumber = 0;
129 std::string* runTag = new std::string();
130 std::string* runDescription = new std::string();
131 fInputRunTree->SetBranchAddress("timestamp", &startTimeStampMilliseconds);
132 fInputRunTree->SetBranchAddress("number", &runNumber);
133 fInputRunTree->SetBranchAddress("tag", &runTag);
134 fInputRunTree->SetBranchAddress("comments", &runDescription);
135
136 /* // Unused because they cannot be set in the run info
137 std::string* runComment = new std::string();
138 fInputRunTree->SetBranchAddress("comments", &runComment);
139 std::string* runDetector = new std::string();
140 fInputRunTree->SetBranchAddress("detector", &runDetector);
141 Float_t driftField = 0;
142 fInputRunTree->SetBranchAddress("drift_field_V_cm_bar", &driftField);
143 Float_t meshVoltage = 0;
144 fInputRunTree->SetBranchAddress("mesh_voltage_V", &meshVoltage);
145 Float_t detectorPressure = 0;
146 fInputRunTree->SetBranchAddress("detector_pressure_bar", &detectorPressure);
147 */
148
149 // retrieve row 0
150 fInputRunTree->GetEntry(0);
151
152 // set run info
153 Double_t startTimeStamp = startTimeStampMilliseconds / 1000.0; // convert ms to seconds
154 fRunInfo->SetStartTimeStamp(startTimeStamp);
155 fRunInfo->SetRunNumber(runNumber);
156 // mclient sets the run tag and description to "\n" if they are empty
157 if (*runTag == "\n") {
158 runTag->clear();
159 }
160 if (*runDescription == "\n") {
161 runDescription->clear();
162 }
163 fRunInfo->SetRunTag(*runTag);
164 fRunInfo->SetRunDescription(*runDescription);
165 fRunInfo->SetFeminosDaqTotalEvents(fInputEventTree->GetEntries());
166 }
167
168 fInputEventTree->SetBranchAddress("timestamp", &fInputEventTreeTimestamp);
169 fInputEventTree->SetBranchAddress("signal_ids", &fInputEventTreeSignalIds);
170 fInputEventTree->SetBranchAddress("signal_values", &fInputEventTreeSignalValues);
171}
172
174 fSignalEvent->Initialize();
175
176 fInputEventTree->GetEntry(fInputTreeEntry);
177
178 fSignalEvent->SetID(fInputTreeEntry);
179
180 // fInputEventTreeTimestamp is in milliseconds and TRestEvent::SetTime(seconds, nanoseconds)
181 fSignalEvent->SetTime(fInputEventTreeTimestamp / 1000, fInputEventTreeTimestamp % 1000 * 1000000);
182
183 // get the first event timestamp (if we are not using FeminosDaq run info where this is set from the run
184 // tree)
185 if (!fUseFeminosDaqRunInfo && fInputEventTreeTimestamp < fStartTimestamp) {
186 fStartTimestamp = fInputEventTreeTimestamp;
187 }
188 // get the last event timestamp
189 if (fInputEventTreeTimestamp > fEndTimestamp) {
190 fEndTimestamp = fInputEventTreeTimestamp;
191 }
192
193 for (size_t i = 0; i < fInputEventTreeSignalIds->size(); i++) {
194 auto signal = TRestRawSignal();
195 signal.Initialize();
196
197 const auto id = fInputEventTreeSignalIds->at(i);
198 signal.SetID(id);
199
200 for (int j = 0; j < 512; j++) {
201 signal.AddPoint(short(fInputEventTreeSignalValues->at(i * 512 + j)));
202 }
203
204 fSignalEvent->AddSignal(signal);
205 }
206
207 fInputTreeEntry += 1;
208
209 if (fInputTreeEntry >= fInputEventTree->GetEntries()) {
210 return nullptr;
211 }
212
213 return fSignalEvent;
214}
215
217 // use first event timestamp as start of run if we are not using FeminosDaq run info
218 if (!fUseFeminosDaqRunInfo) {
219 fRunInfo->SetStartTimeStamp(fStartTimestamp / 1000.0); // convert from ms to s
220 }
221 // use last event timestamp as end of run
222 fRunInfo->SetEndTimeStamp(fEndTimestamp / 1000.0); // convert from ms to s
223}
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.