REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawTDSToSignalProcess.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
53
54#include "TRestRawTDSToSignalProcess.h"
55
57
62
67
73
82 ANABlockHead blockhead;
83 if (fread(&blockhead, sizeof(blockhead), 1, fInputBinFile) != 1) return;
84 totalbytesRead = sizeof(blockhead);
85 nSamples = blockhead.NEvents;
86 nChannels = blockhead.NHits / blockhead.NEvents;
87 fRate = blockhead.SRate;
88 pulseDepth = blockhead.PSize;
89 RESTDebug << "nSamples " << nSamples << " NChannels " << nChannels << RESTendl;
90 RESTDebug << "SRATE: " << (double)fRate << " PULSE DEPTH: " << pulseDepth
91 << " PRETRIGGER: " << blockhead.Pretrigger << RESTendl;
92 for (int i = 0; i < nChannels; i++) {
93 fScale[i] = blockhead.mVdiv[i];
94 negPolarity[i] = blockhead.NegPolarity[i];
95 }
96 tNow = static_cast<double>(blockhead.TimeStamp);
97 fRunInfo->SetStartTimeStamp(tNow);
98}
99
104 // TDS block and event header
105 ANABlockHead blockhead;
106 ANAEventHead eventhead;
107
108 // Initialize fSignalEvent, so it is empty if already filled in
109 fSignalEvent->Initialize();
110
111 // Read block header if any, note that we have nSamples events between 2 block headers
112 if (nEvents % nSamples == 0 && nEvents != 0) {
113 if (fread(&blockhead, sizeof(blockhead), 1, fInputBinFile) != 1) return nullptr;
114 totalbytesRead += sizeof(blockhead);
115 // Update timestamp from the blockHeader
116 tNow = static_cast<double>(blockhead.TimeStamp);
117 }
118
119 // Always read event header at the beginning of event
120 if (fread(&eventhead, sizeof(eventhead), 1, fInputBinFile) != 1) return nullptr;
121 totalbytesRead += sizeof(eventhead);
122 // This vector holds data which has a length of pulseDepth
123 std::vector<Char_t> buffer(pulseDepth);
124 fSignalEvent->SetID(nEvents);
125 fSignalEvent->SetTime(tNow + static_cast<double>(eventhead.clockTicksLT) * 1E-6);
126 // Need to initialize TRestRawSignal with the proper data length
127 TRestRawSignal sgnl(pulseDepth);
128
129 // We loop over the recorded channels, we have one data frame per channel
130 for (int i = 0; i < nChannels; i++) {
131 sgnl.SetSignalID(i);
132 fSignalEvent->AddSignal(sgnl);
133 // Read data frame and store in buffer
134 if (fread((char*)&buffer[0], pulseDepth, 1, fInputBinFile) != 1) return nullptr;
135 totalbytesRead += pulseDepth;
136 for (int j = 0; j < pulseDepth; j++) {
137 Short_t data = buffer[j];
138 if (negPolarity[i]) data *= -1; // Inversion in case pulses are negative
139 data += 128; // Add 128 since the oscilloscope range is [-128:128]
140 fSignalEvent->AddChargeToSignal(i, j, data);
141 }
142 }
143
144 // Set end time stamp for the run
145 fRunInfo->SetEndTimeStamp(tNow + static_cast<double>(eventhead.clockTicksLT) * 1E-6);
146 nEvents++;
147
148 return fSignalEvent;
149}
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
endl_t RESTendl
Termination flag object for TRestStringOutput.
void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value)
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
void SetSignalID(Int_t sID)
It sets the id number of the signal.
A process to read binary files produced with TDS (Tektronix oscilloscope) DAQ.
TRestRawTDSToSignalProcess()
Default constructor.
void Initialize() override
Function to initialize input/output event members and define the section name, calls parent TRestRawT...
~TRestRawTDSToSignalProcess()
Default destructor.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void InitProcess() override
Process initialization. Read first header block and initializes several variables such as: nSamples,...
void Initialize() override
Making default settings.