Subversion Repositories f9daq

Rev

Rev 180 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
180 f9daq 1
 
2
// Simple macro showing capabilities of triple slider
3
//Authors: Bertrand Bellenot, Ilka Antcheva
4
 
5
#include "TGButton.h"
6
#include "TRootEmbeddedCanvas.h"
7
#include "TGLayout.h"
8
#include "TF1.h"
9
#include "TMath.h"
10
#include "TCanvas.h"
11
#include "TGTextEntry.h"
12
#include "TGNumberEntry.h"
13
#include "TGLabel.h"
14
#include "TGTripleSlider.h"
15
#include "TGFrame.h"
16
#include "TGTab.h"
17
#include "TGButton.h"
18
#include "TGSlider.h"
19
#include "TGComboBox.h"
20
#include <TGFileDialog.h>
21
#include "DrsChannel.h"
22
#include "drs.h"
23
 
24
enum ETestCommandIdentifiers {
25
        HId1,
26
        HId2,
27
        HId3,
28
 
29
        VId1,
30
        VId2,
31
        VId3,
32
 
33
        CFId1,
34
 
35
        HCId1,
36
        HCId2,
37
 
38
 
39
        HSId1,
40
 
41
        VSId1,
42
        StartId
43
};
44
 
45
const char *filetypesdat[] = {
46
        "data files",    "*.dat",
47
        "Text files",    "*.[tT][xX][tT]",
48
        0,               0
49
};
50
 
51
const char *filetypesini[] = {
52
        "configuration files",    "*.ini",
53
        0,               0
54
};
55
 
56
TRootEmbeddedCanvas *fCanvas;
57
 
58
class TChannel {
59
private:
60
 
61
 
62
        TGTripleHSlider     *fTimingSlider;
63
        TGTripleHSlider     *fThresholdSlider;
64
 
65
        TGLayoutHints       *fBly, *fBfly1, *fBfly2, *fBfly3;
66
public:
67
        TChannel( TGCompositeFrame *p, int ch);
68
        ~TChannel();
69
 
70
        TGTextEntry         *fTeh[7];
71
        TGTextBuffer        *fTbh[7];
72
        TGCheckButton       *fEdge;
73
 
74
        void DoText(const char *text);
75
        void DoSlider();
76
        void HandleButtons();
77
 
78
        ClassDef(TChannel, 0)
79
 
80
};
81
 
82
 
83
 
84
TChannel::~TChannel(){
85
 
86
 
87
 
88
}
89
 
90
TChannel::TChannel( TGCompositeFrame *p, int ch){
91
 
92
        //--- layout for the frame: place at bottom, right aligned
93
        fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5);
94
        fBfly2 = new TGLayoutHints(kLHintsTop | kLHintsLeft,    5, 5, 5, 5);
95
        fBfly3 = new TGLayoutHints(kLHintsTop | kLHintsRight,   5, 5, 5, 5);
96
        fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
97
 
98
 
99
        TGVerticalFrame *fHframe1 = new TGVerticalFrame(p, 0, 0, 0);
100
 
101
 
102
 
103
        TGHorizontalFrame * fThresholdFrame = new TGHorizontalFrame(fHframe1, 0, 0, 0);
104
 
105
        //TGLabel *fLChannel = new TGLabel(fThresholdFrame, tmp);
106
        TGLabel *fLThreshold = new TGLabel(fThresholdFrame, "Threshold:");
107
 
108
        fThresholdSlider = new TGTripleHSlider(fThresholdFrame, 190, kDoubleScaleBoth, VSId1,
109
                                               kHorizontalFrame,
110
                                               p->GetDefaultFrameBackground(),
111
                                               kFALSE, kFALSE, kFALSE, kFALSE);
112
        fThresholdSlider->Connect("PointerPositionChanged()", "TChannel",  this, "DoSlider()");
113
        fThresholdSlider->Connect("PositionChanged()", "TChannel", this, "DoSlider()");
114
        fThresholdSlider->SetRange(-1,1);
115
 
116
        //fThresholdFrame->AddFrame(fLChannel, fBfly2);
117
        fThresholdFrame->AddFrame(fLThreshold, fBfly2);
118
        fThresholdFrame->AddFrame(fThresholdSlider, fBly);
119
 
120
        TGHorizontalFrame * fTimeWinFrame = new TGHorizontalFrame(fHframe1, 0, 0, 0);
121
        fEdge = new TGCheckButton(fTimeWinFrame, "&Positive Edge", HCId2);
122
        fEdge->SetState(kButtonUp);
123
        fEdge->SetToolTipText("Pointer position relative to slider position");
124
 
125
        TGLabel *fLTiming = new TGLabel(fTimeWinFrame, "Time Window:");
126
 
127
        fTimingSlider = new TGTripleHSlider(fTimeWinFrame, 190, kDoubleScaleBoth, HSId1,
128
                                            kHorizontalFrame,
129
                                            p->GetDefaultFrameBackground(),
130
                                            kFALSE, kFALSE, kFALSE, kFALSE);
131
        fTimingSlider->Connect("PointerPositionChanged()", "TChannel",  this, "DoSlider()");
132
        fTimingSlider->Connect("PositionChanged()", "TChannel", this, "DoSlider()");
133
        fTimingSlider->SetRange(0,200);
134
 
135
 
136
 
137
        fHframe1->Resize(200, 25);
138
 
139
        fEdge->Connect("Clicked()", "TChannel", this,
140
                       "HandleButtons()");
141
 
142
        fTimeWinFrame->AddFrame(fEdge, fBfly2);
143
        fTimeWinFrame->AddFrame(fLTiming, fBfly2);
144
        fTimeWinFrame->AddFrame(fTimingSlider, fBly);
145
 
146
        fHframe1->AddFrame(fThresholdFrame, fBly);
147
        fHframe1->AddFrame(fTimeWinFrame, fBly);
148
 
149
 
150
 
151
 
152
        TGHorizontalFrame *fNumbersFrame = new TGHorizontalFrame(fHframe1, 0, 0, 0);
153
 
154
        for (int i=0; i<7; i++)
155
                fTeh[i] = new TGTextEntry(fNumbersFrame, fTbh[i] = new TGTextBuffer(5), HId1+i);
156
 
157
        fTeh[0]->SetToolTipText("Minimum (left) Value of Slider");
158
        fTeh[1]->SetToolTipText("Pointer Position Value");
159
        fTeh[2]->SetToolTipText("Maximum (right) Value of Slider");
160
        fTeh[3]->SetToolTipText("Signal Cut 0");
161
        fTeh[4]->SetToolTipText("Signal Threshold");
162
        fTeh[5]->SetToolTipText("Signal Cut 1");
163
 
164
        fTeh[6]->SetToolTipText("Constant Fraction Ratio");
165
 
166
        for (int i=0; i<7; i++) {
167
                fTbh[i]->AddText(0, "0.0");
168
                fTeh[i]->Connect("TextChanged(char*)", "TChannel", this,
169
                                 "DoText(char*)");
170
        }
171
 
172
        fNumbersFrame->Resize(100, 25);
173
 
174
 
175
 
176
        for (int i=0; i<7; i++) { fNumbersFrame->AddFrame(fTeh[i], fBfly2); }
177
 
178
 
179
        fHframe1->AddFrame(fNumbersFrame, fBly);
180
        p->AddFrame(fHframe1, fBly);
181
 
182
 
183
 
184
 
185
        fTimingSlider->SetPosition(60,120);
186
        fTimingSlider->SetPointerPosition(65);
187
        fThresholdSlider->SetPosition(-0.5,0.5);
188
        fThresholdSlider->SetPointerPosition(0.25);
189
 
190
        char buf[32];
191
        sprintf(buf, "%.3f", fTimingSlider->GetMinPosition());
192
        fTbh[0]->Clear();
193
        fTbh[0]->AddText(0, buf);
194
        sprintf(buf, "%.3f", fTimingSlider->GetPointerPosition());
195
        fTbh[1]->Clear();
196
        fTbh[1]->AddText(0, buf);
197
        sprintf(buf, "%.3f", fTimingSlider->GetMaxPosition());
198
        fTbh[2]->Clear();
199
        fTbh[2]->AddText(0, buf);
200
        sprintf(buf, "%.3f", fThresholdSlider->GetMinPosition());
201
        fTbh[3]->Clear();
202
        fTbh[3]->AddText(0, buf);
203
        sprintf(buf, "%.3f", fThresholdSlider->GetPointerPosition());
204
        fTbh[4]->Clear();
205
        fTbh[4]->AddText(0, buf);
206
        sprintf(buf, "%.3f", fThresholdSlider->GetMaxPosition());
207
        fTbh[5]->Clear();
208
        fTbh[5]->AddText(0, buf);
209
 
210
        sprintf(buf, "0.25");
211
        fTbh[6]->Clear();
212
        fTbh[6]->AddText(0, buf);
213
 
214
 
215
}
216
 
217
 
218
class TDrsGui: public TGMainFrame {
219
 
220
private:
221
 
222
        TGLayoutHints       *fLcan;
223
        TGComboBox *fTrgch;
224
        TGVerticalFrame   *fHframe0;
225
        TGTextButton *fStart;
226
        TGTextButton *fSelect;
227
        TGTextEntry *fFile;
208 f9daq 228
        TGNumberEntry *fFirst;
180 f9daq 229
        TGNumberEntry *fNeve;
230
        TGNumberEntry *fUpdFrq;
231
        TGTextBuffer        *fFileText;
232
 
233
        TChannel * fChannel[4];
234
        TGLayoutHints       *fBly;
235
public:
236
        TDrsGui();
237
        virtual ~TDrsGui();
238
 
239
        void CloseWindow();
240
        void StartAnalysis();
241
        void HandleAction();
242
        void LoadIni();
243
        ClassDef(TDrsGui, 0)
244
};
245
 
246
void TDrsGui::StartAnalysis(){
247
        const int nch=4;
248
        DrsChannel c[nch];
249
 
250
        for (int i=0; i<nch; i++) {
251
 
252
 
253
                c[i].cfrac = atof(fChannel[i]->fTbh[6]->GetString());
254
                c[i].threshold = atof( fChannel[i]->fTbh[4]->GetString());
255
                c[i].twin[0] = atof( fChannel[i]->fTbh[0]->GetString());
256
                c[i].twin[1] = atof( fChannel[i]->fTbh[2]->GetString());
257
 
258
                c[i].adcgate[0] = atof( fChannel[i]->fTbh[1]->GetString());;
259
                c[i].adcgate[1] = c[i].adcgate[0] + c[i].twin[1]-c[i].twin[0];
260
 
261
                c[i].vcut[0] = atof( fChannel[i]->fTbh[3]->GetString());
262
                c[i].vcut[1] = atof( fChannel[i]->fTbh[5]->GetString());
263
 
264
                c[i].edge = fChannel[i]->fEdge->GetState();
265
 
266
 
267
 
268
                printf("Ch.%d :",i);
269
                for (int j=0; j<7; j++) printf("\t%f", atof( fChannel[i]->fTbh[j]->GetString()));
270
                printf("%d\n", fChannel[i]->fEdge->GetState() );
271
 
272
        }
273
        printf("File: %s\n", fFileText->GetString()  );
274
 
275
 
276
 
277
 
278
 
279
        int nev=fNeve->GetIntNumber();
208 f9daq 280
		int first=fFirst->GetIntNumber();
180 f9daq 281
        int updfrq=fUpdFrq->GetIntNumber();;
282
 
283
        int trgch=fTrgch->GetSelected();
208 f9daq 284
        drs * d = new drs(fFileText->GetString(), nch, c, trgch,first, nev, updfrq  );
180 f9daq 285
 
286
 
287
}
288
void TDrsGui::LoadIni(){
289
        static TString dir(".");
290
        TGFileInfo fi;
291
        fi.fFileTypes = filetypesini;
292
        fi.fIniDir    = StrDup(dir);
293
        printf("fIniDir = %s\n", fi.fIniDir);
294
        new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
295
        printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
296
        dir = fi.fIniDir;
297
        FILE *fp= fopen(fi.fFilename,"r");
298
        float f[10];
299
        int j=0;
300
        const int ndim=400;
301
        char line[ndim];
302
        int edge=0;
303
        int ch=0;
304
        float cfrac=1;
305
        while (fgets(line,ndim,fp)!=NULL) {
306
                if (line[0]=='#' ) continue;
307
                printf("%d***********\n",j++);
308
                sscanf(line,"%d%d%f%f%f%f%f%f%f",&ch,&edge,&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6]);
309
                printf("%d\t%d\t",ch, edge);
310
                for (int i=0; i<7; i++) {
311
 
312
                        char buf[20];
313
                        sprintf(buf, "%.3f", f[i]);
314
                        fChannel[ch]->fTbh[i]->Clear();
315
                        fChannel[ch]->fTbh[i]->AddText(0, buf);
316
                        fChannel[ch]->fTeh[i]->SetCursorPosition(fChannel[ch]->fTeh[i]->GetCursorPosition());
317
                        fChannel[ch]->fTeh[i]->Deselect();
318
                        gClient->NeedRedraw(fChannel[ch]->fTeh[i]);
319
                        printf("%2.2f\t",f[i]);
320
 
321
                }
322
                if (!edge) fChannel[ch]->fEdge->SetState(kButtonUp);
323
                else fChannel[ch]->fEdge->SetState(kButtonDown);
324
 
325
                printf("\n");
326
        }
327
 
328
        fclose(fp);
329
 
330
 
331
}
332
 
333
 
334
void TDrsGui::HandleAction(){
335
        static TString dir(".");
336
        TGFileInfo fi;
337
        fi.fFileTypes = filetypesdat;
338
        fi.fIniDir    = StrDup(dir);
339
        printf("fIniDir = %s\n", fi.fIniDir);
340
        new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
341
        printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
342
        dir = fi.fIniDir;
343
        //char buf[32];
344
        //sprintf(buf, "%.3f", fTimingSlider->GetMinPosition());
345
        fFileText->Clear();
346
        fFileText->AddText(0,fi.fFilename);
347
        /*
348
           fCanvas->GetCanvas()->Modified();
349
              fCanvas->GetCanvas()->Update();
350
         */
351
        fFile->SetCursorPosition(fFile->GetCursorPosition());
352
        fFile->Deselect();
353
        gClient->NeedRedraw(fFile);
354
}
355
//______________________________________________________________________________
356
TDrsGui::TDrsGui() : TGMainFrame(gClient->GetRoot(), 100, 100)
357
{
358
        SetCleanup(kDeepCleanup);
359
        // Create an embedded canvas and add to the main frame, centered in x and y
360
        // and with 30 pixel margins all around
361
        /*
362
           fCanvas = new TRootEmbeddedCanvas("Canvas", this, 600, 400);
363
           fLcan = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10);
364
           //AddFrame(fCanvas, fLcan);
365
           fCanvas->GetCanvas()->SetFillColor(33);
366
           fCanvas->GetCanvas()->SetFrameFillColor(41);
367
           fCanvas->GetCanvas()->SetBorderMode(0);
368
           fCanvas->GetCanvas()->SetGrid();
369
           fCanvas->GetCanvas()->SetLogy();
370
         */
371
        fHframe0 = new TGVerticalFrame(this, 0, 0, 0);
372
        fHframe0->Resize(200, 50);
373
        //--- layout for buttons: top align, equally expand horizontally
374
        fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
375
 
376
        TGHorizontalFrame *fStartFrame = new TGHorizontalFrame(fHframe0, 0, 0, 0);
377
 
378
        char tmp[20];
379
        // combo box widget
380
        fTrgch = new TGComboBox(fStartFrame,50);
381
        for (int i = 0; i < 4; i++) {
382
                sprintf(tmp, "Ch %i", i);
383
                fTrgch->AddEntry(tmp, i);
384
        }
385
        fTrgch->Resize(50, 20);
386
        fTrgch->Select(0);
208 f9daq 387
        TGLabel *fLTrgch = new TGLabel(fStartFrame, "Trg Chan:");
180 f9daq 388
        fNeve = new TGNumberEntry(fStartFrame,  5000, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
208 f9daq 389
        TGLabel *fLNeve = new TGLabel(fStartFrame, "Number of ev.:");
390
 
391
		fFirst = new TGNumberEntry(fStartFrame,  0, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
392
        TGLabel *fLFirst = new TGLabel(fStartFrame, "First ev.:");
180 f9daq 393
 
394
        fUpdFrq = new TGNumberEntry(fStartFrame,  50, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
208 f9daq 395
        TGLabel *fLUpdFrq = new TGLabel(fStartFrame, "Update Freq.:");
180 f9daq 396
 
397
        fStartFrame->AddFrame(fLTrgch, fBly);
398
        fStartFrame->AddFrame(fTrgch, fBly);
399
        fStartFrame->AddFrame(fLNeve, fBly);
400
        fStartFrame->AddFrame(fNeve, fBly);
208 f9daq 401
		fStartFrame->AddFrame(fLFirst, fBly);
402
        fStartFrame->AddFrame(fFirst, fBly);
180 f9daq 403
        fStartFrame->AddFrame(fLUpdFrq, fBly);
404
        fStartFrame->AddFrame(fUpdFrq, fBly);
405
 
406
        fHframe0->AddFrame(fStartFrame, fBly);
407
 
408
 
409
        TGHorizontalFrame *fH = new TGHorizontalFrame(fHframe0, 0, 0, 0);
410
 
411
 
412
        fStart =  new TGTextButton(fH, "Start");
413
        fStart->Connect("Clicked()", "TDrsGui", this, "StartAnalysis()");
414
 
415
        fSelect =  new TGTextButton(fH, "Select Analysis File");
416
        fSelect->Connect("Clicked()", "TDrsGui", this, "HandleAction()");
417
 
418
        fFile = new TGTextEntry(fH, fFileText = new TGTextBuffer(5), 1);
419
 
420
        TGTextButton * fLoadIni =  new TGTextButton(fH, "Load Ini File");
421
        fLoadIni->Connect("Clicked()", "TDrsGui", this, "LoadIni()");
422
 
423
 
424
        fH->AddFrame(fSelect, fBly);
425
        fH->AddFrame(fFile, fBly);
426
        fH->AddFrame(fLoadIni, fBly);
427
        fH->AddFrame(fStart, fBly);
428
 
429
        fHframe0->AddFrame(fH, fBly);
430
        AddFrame(fHframe0, fBly);
431
 
432
        //--------- create the Tab widget
433
        TGTab *fTab = new TGTab(fHframe0, 300, 300);
434
        TGLayoutHints *fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
435
 
436
        for (int ich=0; ich<4; ich++) {
437
                char tmp[255];
438
                sprintf(tmp,"Channel %d:",ich);
439
                TGCompositeFrame *tf = fTab->AddTab(tmp);
440
                fChannel[ich]= new TChannel( tf, ich);
441
 
442
        }
443
        fHframe0->AddFrame(fTab, fBly);
444
 
445
        // Set main frame name, map sub windows (buttons), initialize layout
446
        // algorithm via Resize() and map main frame
447
        SetWindowName("DRS Analysis");
448
        MapSubwindows();
449
        Resize(GetDefaultSize());
450
        MapWindow();
451
 
452
}
453
 
454
//______________________________________________________________________________
455
TDrsGui::~TDrsGui()
456
{
457
        // Clean up
458
 
459
        Cleanup();
460
}
461
 
462
//______________________________________________________________________________
463
void TDrsGui::CloseWindow()
464
{
465
        // Called when window is closed via the window manager.
466
 
467
        delete this;
468
}
469
 
470
//______________________________________________________________________________
471
void TChannel::DoText(const char * /*text*/)
472
{
473
        // Handle text entry widgets.
474
 
475
        TGTextEntry *te = (TGTextEntry *) gTQSender;
476
        Int_t id = te->WidgetId();
477
 
478
        switch (id) {
479
        case HId1:
480
                fTimingSlider->SetPosition(atof(fTbh[0]->GetString()),
481
                                           fTimingSlider->GetMaxPosition());
482
                break;
483
        case HId2:
484
                fTimingSlider->SetPointerPosition(atof(fTbh[1]->GetString()));
485
                break;
486
        case HId3:
487
                fTimingSlider->SetPosition(fTimingSlider->GetMinPosition(),
488
                                           atof(fTbh[2]->GetString()));
489
                break;
490
 
491
        case VId1:
492
                fThresholdSlider->SetPosition(atof(fTbh[3]->GetString()),
493
                                              fThresholdSlider->GetMaxPosition());
494
                break;
495
        case VId2:
496
                fThresholdSlider->SetPointerPosition(atof(fTbh[4]->GetString()));
497
                break;
498
        case VId3:
499
                fThresholdSlider->SetPosition(fThresholdSlider->GetMinPosition(),
500
                                              atof(fTbh[5]->GetString()));
501
                break;
502
 
503
        default:
504
                break;
505
        }
506
        /*
507
 
508
 
509
           fCanvas->GetCanvas()->Modified();
510
           fCanvas->GetCanvas()->Update();
511
 
512
         */
513
}
514
 
515
//______________________________________________________________________________
516
void TChannel::DoSlider()
517
{
518
        // Handle slider widgets.
519
 
520
        char buf[32];
521
 
522
        float values[6]={
523
                fTimingSlider->GetMinPosition(),fTimingSlider->GetPointerPosition(),fTimingSlider->GetMaxPosition(),
524
                fThresholdSlider->GetMinPosition(),fThresholdSlider->GetPointerPosition(),fThresholdSlider->GetMaxPosition()
525
        };
526
 
527
        for (int i=0; i<6; i++) {
528
                sprintf(buf, "%.3f", values[i]);
529
                fTbh[i]->Clear();
530
                fTbh[i]->AddText(0, buf);
531
                fTeh[i]->SetCursorPosition(fTeh[i]->GetCursorPosition());
532
                fTeh[i]->Deselect();
533
                gClient->NeedRedraw(fTeh[i]);
534
        }
535
 
536
 
537
        /*
538
 
539
           fCanvas->GetCanvas()->Modified();
540
           fCanvas->GetCanvas()->Update();
541
         */
542
}
543
 
544
//______________________________________________________________________________
545
void TChannel::HandleButtons()
546
{
547
        // Handle different buttons.
548
 
549
        TGButton *btn = (TGButton *) gTQSender;
550
        Int_t id = btn->WidgetId();
551
 
552
        switch (id) {
553
        case HCId1:
554
                // fTimingSlider->SetConstrained(fTrigger->GetState());
555
                break;
556
        case HCId2:
557
                fTimingSlider->SetRelative(fEdge->GetState());
558
                break;
559
        default:
560
                break;
561
        }
562
}
563
 
564
 
565
void drsgui()
566
{
567
        new TDrsGui();
568
}