1919#include <TGraphErrors.h>
2020#include <TCanvas.h>
2121
22+ //LOCAL INCLUDES
23+ #include "Aux.hh"
24+
25+ // NetScope INCLUDES
2226#include "common.h"
2327#include "hdf5io.h"
2428
@@ -44,6 +48,13 @@ std::string ParseCommandLine( int argc, char* argv[], std::string opt )
4448int main (int argc , char * * argv ) {
4549 size_t i , j , iCh , iEvent = 0 , nEvents = 0 , frameSize , nEventsInFile ;
4650 char * inFileName ;
51+
52+ // hardcoded number of time samples for pulses
53+ int NSAMPLES = 1000 ;
54+
55+ // need to do a reverse ADC to use same
56+ // code as DRS, then reverse
57+ float ADC = (1.0 / 4096.0 );
4758
4859 struct hdf5io_waveform_file * waveformFile ;
4960 struct waveform_attribute waveformAttr ;
@@ -106,8 +117,8 @@ int main(int argc, char **argv) {
106117
107118 // initialization of variables for TTree output
108119 int event ;
109- float time [2 ][1000 ]; // calibrated time
110- float channel [4 ][1000 ]; // input (in V)
120+ float time [2 ][NSAMPLES ]; // calibrated time
121+ float channel [4 ][NSAMPLES ]; // input (in V)
111122 float xmin [4 ]; // location of peak
112123 float base [4 ]; // baseline voltage
113124 float amp [4 ]; // pulse amplitude
@@ -126,6 +137,24 @@ int main(int argc, char **argv) {
126137 float constantThresholdTime [4 ];
127138 bool _isRinging [4 ];
128139
140+ for (iCh = 0 ; iCh < 4 ; iCh ++ ) {
141+ xmin [iCh ] = 0. ;
142+ amp [iCh ] = 0. ;
143+ base [iCh ] = 0. ;
144+ integral [iCh ] = 0. ;
145+ integralFull [iCh ] = 0. ;
146+ gauspeak [iCh ] = 0. ;
147+ sigmoidTime [iCh ] = 0. ;
148+ linearTime0 [iCh ] = 0. ;
149+ linearTime15 [iCh ] = 0. ;
150+ linearTime30 [iCh ] = 0. ;
151+ linearTime45 [iCh ] = 0. ;
152+ linearTime60 [iCh ] = 0. ;
153+ risetime [iCh ] = 0. ;
154+ constantThresholdTime [iCh ] = 0. ;
155+ _isRinging [iCh ] = false;
156+ }
157+
129158 tree -> Branch ("event" , & event , "event/I" );
130159 tree -> Branch ("channel" , channel , "channel[4][1000]/F" );
131160 tree -> Branch ("time" , time , "time[2][1000]/F" );
@@ -162,7 +191,7 @@ int main(int argc, char **argv) {
162191
163192 event = waveformEvent .eventId ;
164193
165- for (i = 0 ; i < 1000 ; i ++ ) {
194+ for (i = 0 ; i < NSAMPLES ; i ++ ) {
166195 if (i < waveformFile -> nPt )
167196 time [0 ][i ] = waveformAttr .dt * (i %frameSize );
168197 else
@@ -172,10 +201,10 @@ int main(int argc, char **argv) {
172201 for (iCh = 0 ; iCh < SCOPE_NCH ; iCh ++ ) {
173202 if ((1 <<iCh ) & waveformAttr .chMask ) {
174203 if (i < waveformFile -> nPt ){
175- channel [iCh ][i ] = (waveformBuf [j * waveformFile -> nPt + i ]
204+ channel [iCh ][i ] = (( waveformBuf [j * waveformFile -> nPt + i ]
176205 - waveformAttr .yoff [iCh ])
177206 * waveformAttr .ymult [iCh ]
178- + waveformAttr .yzero [iCh ];
207+ + waveformAttr .yzero [iCh ]) / ADC ;
179208 } else {
180209 channel [iCh ][i ] = 0. ;
181210 }
@@ -191,6 +220,103 @@ int main(int argc, char **argv) {
191220 // printf("\n");
192221 }
193222 // printf("\n");
223+
224+ // loop over channels for pulse processing
225+ for (iCh = 0 ; iCh < SCOPE_NCH ; iCh ++ ) {
226+ if ((1 <<iCh ) & waveformAttr .chMask ) {
227+ xmin [iCh ] = 0. ;
228+ amp [iCh ] = 0. ;
229+ base [iCh ] = 0. ;
230+ integral [iCh ] = 0. ;
231+ integralFull [iCh ] = 0. ;
232+ gauspeak [iCh ] = 0. ;
233+ sigmoidTime [iCh ] = 0. ;
234+ linearTime0 [iCh ] = 0. ;
235+ linearTime15 [iCh ] = 0. ;
236+ linearTime30 [iCh ] = 0. ;
237+ linearTime45 [iCh ] = 0. ;
238+ linearTime60 [iCh ] = 0. ;
239+ risetime [iCh ] = 0. ;
240+ constantThresholdTime [iCh ] = 0. ;
241+
242+ // Make pulse shape graph
243+ TString pulseName = Form ("pulse_event%d_ch%d" , event , iCh );
244+ TGraphErrors * pulse = GetTGraph ( channel [iCh ], time [0 ] );
245+
246+ // Estimate baseline
247+ float baseline ;
248+ baseline = GetBaseline ( pulse , 5 ,150 , pulseName );
249+ base [iCh ] = baseline ;
250+
251+ // Correct pulse shape for baseline offset + amp/att
252+ for (int j = 0 ; j < NSAMPLES ; j ++ ) {
253+ channel [iCh ][j ] = channel [iCh ][j ] + baseline ;
254+ }
255+
256+ int index_min = FindMinAbsolute (NSAMPLES , channel [iCh ]);
257+
258+ // Recreate the pulse TGraph using baseline-subtracted channel data
259+ delete pulse ;
260+ pulse = GetTGraph ( channel [iCh ], time [0 ] );
261+
262+ xmin [iCh ] = index_min ;
263+
264+ Double_t tmpAmp = 0.0 ;
265+ Double_t tmpMin = 0.0 ;
266+ pulse -> GetPoint (index_min , tmpMin , tmpAmp );
267+ amp [iCh ] = tmpAmp * ADC ;
268+
269+ // Get pulse integral
270+ if ( xmin [iCh ] != 0 ) {
271+ integral [iCh ] = GetPulseIntegral ( index_min , 20 , channel [iCh ], time [0 ] );
272+ integralFull [iCh ] = GetPulseIntegral ( index_min , channel [iCh ], "full" );
273+ }
274+ else {
275+ integral [iCh ] = 0.0 ;
276+ integralFull [iCh ] = 0.0 ;
277+ }
278+
279+ // Gaussian time stamp and constant-fraction fit
280+ Double_t min = 0. ; Double_t low_edge = 0. ; Double_t high_edge = 0. ; Double_t y = 0. ;
281+ pulse -> GetPoint (index_min , min , y );
282+ pulse -> GetPoint (index_min - 4 , low_edge , y ); // time of the low edge of the fit range
283+ pulse -> GetPoint (index_min + 4 , high_edge , y ); // time of the upper edge of the fit range
284+
285+ float timepeak = 0 ;
286+ float fs [6 ]; // constant-fraction fit output
287+ float fs_falling [6 ]; // falling exp timestapms
288+ float cft_low_range = 0.03 ;
289+ float cft_high_range = 0.20 ;
290+
291+ if (xmin [iCh ] != 0.0 ) {
292+ timepeak = GausFit_MeanTime (pulse , low_edge , high_edge );
293+ RisingEdgeFitTime ( pulse , index_min , cft_low_range , cft_high_range , fs , event , "linearFit_" + pulseName , false );
294+ }
295+
296+ _isRinging [iCh ] = isRinging ( index_min , channel [iCh ] );
297+ // for output tree
298+ gauspeak [iCh ] = timepeak ;
299+ risetime [iCh ] = fs [0 ];
300+ linearTime0 [iCh ] = fs [1 ];
301+ linearTime15 [iCh ] = fs [2 ];
302+ linearTime30 [iCh ] = fs [3 ];
303+ linearTime45 [iCh ] = fs [4 ];
304+ linearTime60 [iCh ] = fs [5 ];
305+ fallingTime [iCh ] = fs_falling [0 ];
306+ constantThresholdTime [iCh ] = ConstantThresholdTime ( pulse , 75 );
307+
308+ // reconvert to "mV" with ADC factor
309+ for (int s = 0 ; s < NSAMPLES ; s ++ )
310+ channel [iCh ][s ] *= ADC ;
311+
312+ delete pulse ;
313+
314+
315+
316+ }
317+ }
318+
319+
194320 tree -> Fill ();
195321 }
196322
0 commit comments