Subversion Repositories f9daq

Rev

Go to most recent revision | Details | 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;
228
        TGNumberEntry *fNeve;
229
        TGNumberEntry *fUpdFrq;
230
        TGTextBuffer        *fFileText;
231
 
232
        TChannel * fChannel[4];
233
        TGLayoutHints       *fBly;
234
public:
235
        TDrsGui();
236
        virtual ~TDrsGui();
237
 
238
        void CloseWindow();
239
        void StartAnalysis();
240
        void HandleAction();
241
        void LoadIni();
242
        ClassDef(TDrsGui, 0)
243
};
244
 
245
void TDrsGui::StartAnalysis(){
246
        const int nch=4;
247
        DrsChannel c[nch];
248
 
249
        for (int i=0; i<nch; i++) {
250
 
251
 
252
                c[i].cfrac = atof(fChannel[i]->fTbh[6]->GetString());
253
                c[i].threshold = atof( fChannel[i]->fTbh[4]->GetString());
254
                c[i].twin[0] = atof( fChannel[i]->fTbh[0]->GetString());
255
                c[i].twin[1] = atof( fChannel[i]->fTbh[2]->GetString());
256
 
257
                c[i].adcgate[0] = atof( fChannel[i]->fTbh[1]->GetString());;
258
                c[i].adcgate[1] = c[i].adcgate[0] + c[i].twin[1]-c[i].twin[0];
259
 
260
                c[i].vcut[0] = atof( fChannel[i]->fTbh[3]->GetString());
261
                c[i].vcut[1] = atof( fChannel[i]->fTbh[5]->GetString());
262
 
263
                c[i].edge = fChannel[i]->fEdge->GetState();
264
 
265
 
266
 
267
                printf("Ch.%d :",i);
268
                for (int j=0; j<7; j++) printf("\t%f", atof( fChannel[i]->fTbh[j]->GetString()));
269
                printf("%d\n", fChannel[i]->fEdge->GetState() );
270
 
271
        }
272
        printf("File: %s\n", fFileText->GetString()  );
273
 
274
 
275
 
276
 
277
 
278
        int nev=fNeve->GetIntNumber();
279
        int updfrq=fUpdFrq->GetIntNumber();;
280
 
281
        int trgch=fTrgch->GetSelected();
282
        drs * d = new drs(fFileText->GetString(), nch, c, trgch, nev, updfrq  );
283
 
284
 
285
}
286
void TDrsGui::LoadIni(){
287
        static TString dir(".");
288
        TGFileInfo fi;
289
        fi.fFileTypes = filetypesini;
290
        fi.fIniDir    = StrDup(dir);
291
        printf("fIniDir = %s\n", fi.fIniDir);
292
        new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
293
        printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
294
        dir = fi.fIniDir;
295
        FILE *fp= fopen(fi.fFilename,"r");
296
        float f[10];
297
        int j=0;
298
        const int ndim=400;
299
        char line[ndim];
300
        int edge=0;
301
        int ch=0;
302
        float cfrac=1;
303
        while (fgets(line,ndim,fp)!=NULL) {
304
                if (line[0]=='#' ) continue;
305
                printf("%d***********\n",j++);
306
                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]);
307
                printf("%d\t%d\t",ch, edge);
308
                for (int i=0; i<7; i++) {
309
 
310
                        char buf[20];
311
                        sprintf(buf, "%.3f", f[i]);
312
                        fChannel[ch]->fTbh[i]->Clear();
313
                        fChannel[ch]->fTbh[i]->AddText(0, buf);
314
                        fChannel[ch]->fTeh[i]->SetCursorPosition(fChannel[ch]->fTeh[i]->GetCursorPosition());
315
                        fChannel[ch]->fTeh[i]->Deselect();
316
                        gClient->NeedRedraw(fChannel[ch]->fTeh[i]);
317
                        printf("%2.2f\t",f[i]);
318
 
319
                }
320
                if (!edge) fChannel[ch]->fEdge->SetState(kButtonUp);
321
                else fChannel[ch]->fEdge->SetState(kButtonDown);
322
 
323
                printf("\n");
324
        }
325
 
326
        fclose(fp);
327
 
328
 
329
}
330
 
331
 
332
void TDrsGui::HandleAction(){
333
        static TString dir(".");
334
        TGFileInfo fi;
335
        fi.fFileTypes = filetypesdat;
336
        fi.fIniDir    = StrDup(dir);
337
        printf("fIniDir = %s\n", fi.fIniDir);
338
        new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
339
        printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
340
        dir = fi.fIniDir;
341
        //char buf[32];
342
        //sprintf(buf, "%.3f", fTimingSlider->GetMinPosition());
343
        fFileText->Clear();
344
        fFileText->AddText(0,fi.fFilename);
345
        /*
346
           fCanvas->GetCanvas()->Modified();
347
              fCanvas->GetCanvas()->Update();
348
         */
349
        fFile->SetCursorPosition(fFile->GetCursorPosition());
350
        fFile->Deselect();
351
        gClient->NeedRedraw(fFile);
352
}
353
//______________________________________________________________________________
354
TDrsGui::TDrsGui() : TGMainFrame(gClient->GetRoot(), 100, 100)
355
{
356
        SetCleanup(kDeepCleanup);
357
        // Create an embedded canvas and add to the main frame, centered in x and y
358
        // and with 30 pixel margins all around
359
        /*
360
           fCanvas = new TRootEmbeddedCanvas("Canvas", this, 600, 400);
361
           fLcan = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10);
362
           //AddFrame(fCanvas, fLcan);
363
           fCanvas->GetCanvas()->SetFillColor(33);
364
           fCanvas->GetCanvas()->SetFrameFillColor(41);
365
           fCanvas->GetCanvas()->SetBorderMode(0);
366
           fCanvas->GetCanvas()->SetGrid();
367
           fCanvas->GetCanvas()->SetLogy();
368
         */
369
        fHframe0 = new TGVerticalFrame(this, 0, 0, 0);
370
        fHframe0->Resize(200, 50);
371
        //--- layout for buttons: top align, equally expand horizontally
372
        fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
373
 
374
        TGHorizontalFrame *fStartFrame = new TGHorizontalFrame(fHframe0, 0, 0, 0);
375
 
376
        char tmp[20];
377
        // combo box widget
378
        fTrgch = new TGComboBox(fStartFrame,50);
379
        for (int i = 0; i < 4; i++) {
380
                sprintf(tmp, "Ch %i", i);
381
                fTrgch->AddEntry(tmp, i);
382
        }
383
        fTrgch->Resize(50, 20);
384
        fTrgch->Select(0);
385
        TGLabel *fLTrgch = new TGLabel(fStartFrame, "Trg Channel:");
386
        fNeve = new TGNumberEntry(fStartFrame,  5000, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
387
        TGLabel *fLNeve = new TGLabel(fStartFrame, "Number of events:");
388
 
389
        fUpdFrq = new TGNumberEntry(fStartFrame,  50, 5,999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative );
390
        TGLabel *fLUpdFrq = new TGLabel(fStartFrame, "Update Frequency:");
391
 
392
        fStartFrame->AddFrame(fLTrgch, fBly);
393
        fStartFrame->AddFrame(fTrgch, fBly);
394
        fStartFrame->AddFrame(fLNeve, fBly);
395
        fStartFrame->AddFrame(fNeve, fBly);
396
        fStartFrame->AddFrame(fLUpdFrq, fBly);
397
        fStartFrame->AddFrame(fUpdFrq, fBly);
398
 
399
        fHframe0->AddFrame(fStartFrame, fBly);
400
 
401
 
402
        TGHorizontalFrame *fH = new TGHorizontalFrame(fHframe0, 0, 0, 0);
403
 
404
 
405
        fStart =  new TGTextButton(fH, "Start");
406
        fStart->Connect("Clicked()", "TDrsGui", this, "StartAnalysis()");
407
 
408
        fSelect =  new TGTextButton(fH, "Select Analysis File");
409
        fSelect->Connect("Clicked()", "TDrsGui", this, "HandleAction()");
410
 
411
        fFile = new TGTextEntry(fH, fFileText = new TGTextBuffer(5), 1);
412
 
413
        TGTextButton * fLoadIni =  new TGTextButton(fH, "Load Ini File");
414
        fLoadIni->Connect("Clicked()", "TDrsGui", this, "LoadIni()");
415
 
416
 
417
        fH->AddFrame(fSelect, fBly);
418
        fH->AddFrame(fFile, fBly);
419
        fH->AddFrame(fLoadIni, fBly);
420
        fH->AddFrame(fStart, fBly);
421
 
422
        fHframe0->AddFrame(fH, fBly);
423
        AddFrame(fHframe0, fBly);
424
 
425
        //--------- create the Tab widget
426
        TGTab *fTab = new TGTab(fHframe0, 300, 300);
427
        TGLayoutHints *fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
428
 
429
        for (int ich=0; ich<4; ich++) {
430
                char tmp[255];
431
                sprintf(tmp,"Channel %d:",ich);
432
                TGCompositeFrame *tf = fTab->AddTab(tmp);
433
                fChannel[ich]= new TChannel( tf, ich);
434
 
435
        }
436
        fHframe0->AddFrame(fTab, fBly);
437
 
438
        // Set main frame name, map sub windows (buttons), initialize layout
439
        // algorithm via Resize() and map main frame
440
        SetWindowName("DRS Analysis");
441
        MapSubwindows();
442
        Resize(GetDefaultSize());
443
        MapWindow();
444
 
445
}
446
 
447
//______________________________________________________________________________
448
TDrsGui::~TDrsGui()
449
{
450
        // Clean up
451
 
452
        Cleanup();
453
}
454
 
455
//______________________________________________________________________________
456
void TDrsGui::CloseWindow()
457
{
458
        // Called when window is closed via the window manager.
459
 
460
        delete this;
461
}
462
 
463
//______________________________________________________________________________
464
void TChannel::DoText(const char * /*text*/)
465
{
466
        // Handle text entry widgets.
467
 
468
        TGTextEntry *te = (TGTextEntry *) gTQSender;
469
        Int_t id = te->WidgetId();
470
 
471
        switch (id) {
472
        case HId1:
473
                fTimingSlider->SetPosition(atof(fTbh[0]->GetString()),
474
                                           fTimingSlider->GetMaxPosition());
475
                break;
476
        case HId2:
477
                fTimingSlider->SetPointerPosition(atof(fTbh[1]->GetString()));
478
                break;
479
        case HId3:
480
                fTimingSlider->SetPosition(fTimingSlider->GetMinPosition(),
481
                                           atof(fTbh[2]->GetString()));
482
                break;
483
 
484
        case VId1:
485
                fThresholdSlider->SetPosition(atof(fTbh[3]->GetString()),
486
                                              fThresholdSlider->GetMaxPosition());
487
                break;
488
        case VId2:
489
                fThresholdSlider->SetPointerPosition(atof(fTbh[4]->GetString()));
490
                break;
491
        case VId3:
492
                fThresholdSlider->SetPosition(fThresholdSlider->GetMinPosition(),
493
                                              atof(fTbh[5]->GetString()));
494
                break;
495
 
496
        default:
497
                break;
498
        }
499
        /*
500
 
501
 
502
           fCanvas->GetCanvas()->Modified();
503
           fCanvas->GetCanvas()->Update();
504
 
505
         */
506
}
507
 
508
//______________________________________________________________________________
509
void TChannel::DoSlider()
510
{
511
        // Handle slider widgets.
512
 
513
        char buf[32];
514
 
515
        float values[6]={
516
                fTimingSlider->GetMinPosition(),fTimingSlider->GetPointerPosition(),fTimingSlider->GetMaxPosition(),
517
                fThresholdSlider->GetMinPosition(),fThresholdSlider->GetPointerPosition(),fThresholdSlider->GetMaxPosition()
518
        };
519
 
520
        for (int i=0; i<6; i++) {
521
                sprintf(buf, "%.3f", values[i]);
522
                fTbh[i]->Clear();
523
                fTbh[i]->AddText(0, buf);
524
                fTeh[i]->SetCursorPosition(fTeh[i]->GetCursorPosition());
525
                fTeh[i]->Deselect();
526
                gClient->NeedRedraw(fTeh[i]);
527
        }
528
 
529
 
530
        /*
531
 
532
           fCanvas->GetCanvas()->Modified();
533
           fCanvas->GetCanvas()->Update();
534
         */
535
}
536
 
537
//______________________________________________________________________________
538
void TChannel::HandleButtons()
539
{
540
        // Handle different buttons.
541
 
542
        TGButton *btn = (TGButton *) gTQSender;
543
        Int_t id = btn->WidgetId();
544
 
545
        switch (id) {
546
        case HCId1:
547
                // fTimingSlider->SetConstrained(fTrigger->GetState());
548
                break;
549
        case HCId2:
550
                fTimingSlider->SetRelative(fEdge->GetState());
551
                break;
552
        default:
553
                break;
554
        }
555
}
556
 
557
 
558
void drsgui()
559
{
560
        new TDrsGui();
561
}