-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdrsboard3.cpp
282 lines (206 loc) · 7.17 KB
/
drsboard3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/********************************************************************\
Name: drs_exam.cpp
Created by: Stefan Ritt
Contents: Simple example application to read out a DRS4
evaluation board
$Id: drs_exam.cpp 13482 2009-05-26 06:48:58Z [email protected] $
\********************************************************************/
#include <fstream>
#include <iomanip>
#include <string>
#include <iostream>
#include <TFile.h>
#include <TTree.h>
#include <TROOT.h>
#include <TRandom.h>
#include <TApplication.h>
#include <TCanvas.h>
#include <TPostScript.h>
#include <TAxis.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TGraph.h>
#include <TLegend.h>
#include <TF1.h>
#include <TStyle.h>
#include <TProfile.h>
#include <TMapFile.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#ifdef _MSC_VER
#include <windows.h>
#elif defined(OS_LINUX)
#define O_BINARY 0
#include <unistd.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>
#define DIR_SEPARATOR '/'
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "strlcpy.h"
#include "DRS.h"
/*------------------------------------------------------------------*/
int main( int argc, char** argv)
{
char title[100]; sprintf( title, "%s_%s_%s.root", argv[1], argv[2], argv[3]);
// TFile* file = new TFile( title, "RECREATE", "MCP Test");
TFile* file = new TFile( title, "NEW", "MCP Test");
if (!file->IsOpen()) return 0;
TTree* tree = new TTree("pulse", "Wave Form");
float b1_t[1024], b1_c[4][1024];
float b2_t[1024], b2_c[4][1024];
float b3_t[1024], b3_c[4][1024];
int event, tc1, tc2, tc3;
time_t start, end;
double tdiff;
tree->Branch("event", &event, "event/I");
tree->Branch("tc1", &tc1, "tc1/I");
tree->Branch("b1_t", b1_t, "b1_t[1024]/F");
tree->Branch("b1_c", b1_c, "b1_c1[4096]/F");
tree->Branch("tc2", &tc2, "tc2/I");
tree->Branch("b2_t", b2_t, "b2_t[1024]/F");
tree->Branch("b2_c", b2_c, "b2_c1[4096]/F");
tree->Branch("tc3", &tc3, "tc3/I");
tree->Branch("b3_t", b3_t, "b3_t[1024]/F");
tree->Branch("b3_c", b3_c, "b3_c1[4096]/F");
int nBoards;
DRS *drs;
DRSBoard *b1;
DRSBoard *b2;
DRSBoard *b3;
int serial_1, serial_2, serial_3;
serial_1 = serial_2 = serial_3 = 0;
/* do initial scan */
drs = new DRS();
/* show any found board(s) */
for (int i=0 ; i<drs->GetNumberOfBoards() ; i++) {
b1 = drs->GetBoard(i);
printf("Found DRS4 evaluation board, serial #%d, firmware revision %d\n",
b1->GetBoardSerialNumber(), b1->GetFirmwareVersion());
//-- if( b1->GetBoardSerialNumber() == 2216) serial_1 = i;
//-- if( b1->GetBoardSerialNumber() == 2336) serial_2 = i;
if( b1->GetBoardSerialNumber() == 2336) serial_1 = i;
if( b1->GetBoardSerialNumber() == 2216) serial_2 = i;
if( b1->GetBoardSerialNumber() == 2204) serial_3 = i; // SCIPP board
}
if( 0) printf("Hello 0\n");
/* exit if no board found */
nBoards = drs->GetNumberOfBoards();
if (nBoards == 0) {
printf("No DRS4 evaluation board found\n");
return 0;
}
if( 0) printf("Hello 1\n");
/* continue working with first board only */
b1 = drs->GetBoard(serial_1);
b2 = drs->GetBoard(serial_2);
b3 = drs->GetBoard(serial_3);
printf("b1 : DRS4 evaluation board, serial #%d\n", b1->GetBoardSerialNumber());
printf("b2 : DRS4 evaluation board, serial #%d\n", b2->GetBoardSerialNumber());
printf("b3 : DRS4 evaluation board, serial #%d\n", b3->GetBoardSerialNumber());
if( 0) printf("Hello 2\n");
/* initialize board */
b1->Init();
b2->Init();
b3->Init();
if ( 0) printf("Hello 3\n");
/* set sampling frequency */
b1->SetFrequency(5, true);
b2->SetFrequency(5, true);
b3->SetFrequency(5, true);
if( 0)printf("Hello 4\n");
/* enable transparent mode needed for analog trigger */
b1->SetTranspMode(1);
b2->SetTranspMode(1);
b3->SetTranspMode(1);
/* set input range to -0.5V ... +0.5V */
b1->SetInputRange(0.);
b2->SetInputRange(0.);
b3->SetInputRange(0.);
/* use following line to enable external hardware trigger (Lemo) */
b1->EnableTrigger(1, 0); // lemo off, analog trigger on
// b1->SetTriggerLevel(0.050, false);
b1->SetTriggerSource(1<<4);
// b1->SetTriggerDelayNs(0);
b2->EnableTrigger(1, 0); // lemo off, analog trigger on
// b2->SetTriggerLevel(0.050, false);
b2->SetTriggerSource(1<<4);
// b2->SetTriggerDelayNs(0);
b3->EnableTrigger(1, 0); // lemo off, analog trigger on
// b3->SetTriggerLevel(0.050, false);
b3->SetTriggerSource(1<<4);
// b3->SetTriggerDelayNs(0);
time( &start);
// int c;a
// puts("Press the key . followed by Enter to stop \n");
/* repeat ten times */
for( int i =0 ; i < atoi( argv[4]) ; i++) {
/* start board (activate domino wave) */
b1->StartDomino();
b2->StartDomino();
b3->StartDomino();
/* wait for trigger */
// while (b1->IsBusy() || b2->IsBusy() || b3->IsBusy());
while (b1->IsBusy())
// {
// c = getchar();
// putchar(c);
// if(c == '.') {delete drs; return 0;}
// }
/* read all waveforms */
b1->TransferWaves(0, 8);
b2->TransferWaves(0, 8);
b3->TransferWaves(0, 8);
// tc1 = drs->GetBoard(0)->GetTriggerCell(0);a
// tc2 = drs->GetBoard(1)->GetTriggerCell(0); // why serial_2 was not used here?
// tc3 = drs->GetBoard(2)->GetTriggerCell(0); // why serial_2 was not used here?
tc1 = drs->GetBoard(serial_1)->GetTriggerCell(0);
tc2 = drs->GetBoard(serial_2)->GetTriggerCell(0); // why serial_2 was not used here?
tc3 = drs->GetBoard(serial_3)->GetTriggerCell(0); // why serial_2 was not used here?
/* read time (X) array in ns */
b1->GetTime(0, tc1, b1_t);
b2->GetTime(0, tc2, b2_t);
b3->GetTime(0, tc3, b3_t);
/* decode waveform (Y) array first channel in mV */
b1->GetWave(0, 0, b1_c[0]);
b1->GetWave(0, 2, b1_c[1]);
b1->GetWave(0, 4, b1_c[2]);
b1->GetWave(0, 6, b1_c[3]);
b2->GetWave(0, 0, b2_c[0]);
b2->GetWave(0, 2, b2_c[1]);
b2->GetWave(0, 4, b2_c[2]);
b2->GetWave(0, 6, b2_c[3]);
b3->GetWave(0, 0, b3_c[0]);
b3->GetWave(0, 2, b3_c[1]);
b3->GetWave(0, 4, b3_c[2]);
b3->GetWave(0, 6, b3_c[3]);
// if( i%100 == 99)
{
time( &end);
tdiff = difftime( end, start);
printf("Event# %5d. DAQ time = %6.2f(Second), Rate = %6.2f(Hz)\n",
i+1, tdiff, (float)(i+1)/tdiff);
}
event = i;
tree->Fill();
}
file->Write();
file->Close();
time( &end);
tdiff = difftime( end, start);
printf("DAQ time = %6.2f(Second), Rate = %6.2f(Hz)\n", tdiff, atof(argv[4])/tdiff);
/* delete DRS object -> close USB connection */
delete drs;
return 0;
}