-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyROOTSCOPE.C
5579 lines (3695 loc) · 155 KB
/
myROOTSCOPE.C
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Author : Pei-Luan Tai
// Contact: [email protected]
// Last update: Aug 30 2019
//
// contributions list:
// ==========================
// Juan Zamora: N Gaussian fit() functionalities.
// improve Get_Sum().
//***************************************/
#include "myDialog.h"
#include "myDialog_2D.h"
#include "myUtility.h"
#include "dev.h"
#include <RVersion.h>
#include <TGaxis.h>
#include <TStyle.h>
#include <TGWindow.h>
#include <TGFrame.h>
#include <TLine.h>
#include <TH1.h>
#include <TH2.h>
#include <TF1.h>
#include <TRandom.h>
#include <TText.h>
#include <TSpectrum.h>
#include <TPolyMarker.h>
#include <vector>
#include <TVirtualPad.h>
#include <TList.h>
#include <TString.h>
#include <TObject.h>
#include <TCanvas.h>
#include <TMath.h>
#include <TCutG.h>
#include <TFile.h>
#include <TBox.h>
#include <TRootEmbeddedCanvas.h>
#include <TGTextEntry.h>
#include <TGNumberEntry.h>
#include <TGTextViewStream.h>
#include <TGMenu.h>
#include <fstream>
using namespace std;
class ROOTSCOPE : public TGMainFrame {
private:
//---------------for 1d histo----------------------------//
int fCmp; /* rebin value */
int fWhich_active_line; /* to set which line is active */
float fXrange_pick1; /* range1 set by mouse click*/
float fXrange_pick2; /* range2 set by mouse click*/
float fGeneral_pick1; /* multi-purpose */
float fGeneral_pick2; /* multi-purpose */
int fUser_generalN; /* setting from user. */
float fGeneral_pickn[NPEAKS]; /* used in N-Gaussian fit */
float fBG_const; /* bg value, const term */
float fBG_linear; /* bg value, linear term */
int fPadTotalN; /* the total pad numbers */
int fPadActive; /* the current pad number */
bool fIsSameDim; /* is display 1d histos have same dim? */
bool fIsTH2_inPad; /* a flag to show whether TH2 object in the pad */
bool fHasTH2; /* a flag check we have TH2 from input */
TH1* histo; /* the 1D histo */
TH1* histo_backup; /* the 1D histo backup*/
Int_t fSwitch_overlap; /* switch for overlap mode.*/
Int_t fOverlaph1Idx;
Int_t fOverlaph2Idx;
Bool_t fOverlapMode;
TGaxis* faxis;
TString fH1DrawOption; /* the 1D histo draw option*/
TLine* myline1; /* line marker 1 */
TLine* myline2; /* line marker 2 */
TLine* general_line1;
TLine* general_line2;
TLine* general_linen[NPEAKS]; /* used in N-Gaussian fit */
Int_t fH1_fillstyle; /* fill style */
Int_t fH1_linewidth; /* line width */
TList* fTexts; /* text labels for found peaks*/
Float_t fTextSize;
Float_t fTextPrecision;
TString fPrecisionFormat;
TPolyMarker* fPolyMarkers; /* markers for found peaks*/
TSpectrum* peakFinder;
Float_t fSigma_guess; /* parameters for finding peaks*/
Float_t fThreshold; /* parameters for finding peaks*/
//---------------for 2d histo----------------------------//
TH2* histo2d; /* the 2D histo */
TH2* histo2d_backup; /* the 2D histo backup */
Int_t fCmp_2d_X; /* rebin value fro 2d x axis */
Int_t fCmp_2d_Y; /* rebin value fro 2d x axis */
Int_t fWhich_active_2d; /* which marker set is active 1 or 2 */
TLine* fH2_marker_setA[2]; /* line marker set A */
TLine* fH2_marker_setB[2]; /* line marker set A */
float fH2_pickX[2]; /* x pick by mouse click*/
float fH2_pickY[2]; /* y pick by mouse click*/
Int_t fLogScale_style; /* switch for log scale. */
Int_t fH2_style; /* the draw style for TH2 */
Int_t fH2_marker_style; /* the marker style for TH2 */
Int_t fH2_marker_color; /* the marker color for TH2 */
static const char* styleDraw[3];
static const Int_t styleMarkersize[5];
static const Int_t styleMarkercolor[6];
//---------------for the array of histos---------------------//
vector<TH1*> histos; /* the 1D histos */
vector<TH1*> histos_backup; /* backups that used in compress/uncompress */
vector<int> fOpen_list; /* the list of idx for the diplayed histograms */
Int_t ftemp_lineN;
TLine* fTmpSet1_lines[10]; /* for temp lines */
TLine* fTmpSet2_lines[10]; /* for temp lines */
//---------------for the array of histo2ds---------------------//
vector<TH2*> histo2ds; /* the 2D histos */
vector<TH2*> histo2ds_backup; /* backups that used in compress/uncompress */
vector<int> fOpen2d_list; /* the list of idx for the diplayed histograms */
//---------------for fitting 1d histo---------------------//
TF1* fTF1_bg_const; /* bg = const */
TF1* fTF1_bg_linear; /* bg = const + linear*x */
TF1* fTF1_gaus_bg; /* y = guas(x) + a*x + c */
TF1* fTF1_gaus_bg_2;
TF1* fTF1_double_gaus_bg;
TF1* fTF1_n_gaus_bg; /* used in N-Gaussian fit */
//---------------others-----------------------------------//
TRootEmbeddedCanvas *emb_Canvas; /* Canvas container */
TCanvas *c1; /* Canvas */
TGTextViewostream *fText_viewer; /* for show user message */
TGMenuBar *fMenuBar; /* menu bar */
TGPopupMenu *fMenu_Entries[5]; /* pop-up menu entries */
bool fToUseMenuBar;
void To_backup_histos();
void To_backup_histo2ds();
void To_writeoutFile();
void To_readinFile();
//----------------------------------------- 1d histo
void SetMarker(Event_t*);
void SetMarker2(Event_t*);
void SetGeneralMarker(Event_t*); // will be replaced by SetGeneralMarkerN
void SetGeneralMarkerN(Event_t*);
void Clear_Marker();
void Set_Y_Range();
void Expand();
void Expand_dlg();
void Unexpand();
void Go_half_left();
void Go_half_right();
void Rebin_compress();
void Rebin_uncompress();
void Set_histo_title();
void To_find_peaks();
void To_show_find_peaks_dlg();
void To_show_histo_dlg();
void To_show_histo_operation_dlg( );
void To_display_histos( bool showMSG );
void To_switch_histo( bool toIncrease );
void To_delete_histo_inSelectedPad();
void To_Change_histo_x_range();
void To_overlap_histos();
void _doing_overloap( TH1* h1, TH1* h2, Int_t h1Idx, Int_t h2Idx, Bool_t ShowMsg );
void To_switch_overlap();
void To_change_linewidth();
void To_change_fillstyle();
void Fit_Gaussian();
void Fit_Double_Gaussian();
void Fit_N_Gaussian();
void Set_FitN( unsigned int input ); // set how many Gaussian to fit.
void Fit_Background(); // for bg = const
void Fit_Background_pol1(); // for bg = const + linear * x
void Set_Linear_Background(); // similar to previous one
// estimate the bg by the edges of a peak.
void Set_Background(); // manual input.
void Reset_Background(); // set const = linear = 0.
void Get_Sum( bool isTH2 ); // for both 1d and 2d
void To_show_AddSub_gate_dlg();
void Project_from_1d( bool flagXY );
//-------------------------------------- 2d histo
void To_full_xy_projection();
void Projection_2d( bool flagXY, bool toShow );
void SetMarker_2d( Event_t* );
void Clear_Marker2d( );
void Expand_2d();
void Expand_2d_dlg();
void Unexpand_2d();
void Set_Z_Range( bool toSetMax );
void Rebin_2d(bool flagXY, bool flag2 );
void To_display_histo2ds( bool showMSG );
void To_display_histo2d_quick();
void To_show_histo2d_operation_dlg();
void To_Back_to_disply_histos();
void To_change_style_2d();
void To_change_marker_size();
void To_change_marker_color();
void To_set_logscale(); //also for 1d
void To_switch_histo2d( bool toIncrease );
void To_create_profile_histo( bool _toX );
//----------------------------------------- utility
void Get_active_histo1D();
float Get_Max_range ( float, float);
float Get_Min_range ( float, float);
void Set_Xrange_pick( float );
void SetActiveLine( TLine* , float, float );
void Switch_ActiveLine(TLine*, TLine*);
void Set_Line( TLine*, float x1, float y1, float x2, float y2 );
void To_Draw_bg();
void Set_init_fit_value( double, double, double& , double& , double& );
TH1* Get_histo_by_padnum( int padnum);
void Single_pad_setting();
void Add_note(Event_t*);
void Set_CannotMove();
void Initialization();
void Create_Widgets( UInt_t w, UInt_t h );
bool Remove_default_empty_histo();
void welcome_info();
void Show_version();
void Show_command_1d();
void Show_command_2d();
public:
// constuctor: widgets are placed here.
ROOTSCOPE( const TGWindow * p, TH1* );
ROOTSCOPE( const TGWindow * p, TH2* );
ROOTSCOPE( const TGWindow * p, const char* rootFileName );
ROOTSCOPE( const TGWindow * p );
void To_response(Event_t*); // to response key press from user.
void To_response_menu( Int_t ); // to response menu bar selection.
TH2* GetTwoDHisto();
TH1* GetOneDHisto();
void SetTwoDHisto( TH2* h2d_input );
void AddOneDHisto( TH1* h_input );
template <class T>
void AddHisto(T* input);
void AddRootFile( const char* filename );
TString GetMessage(){ return fText_viewer->GetText()->AsString(); }
TCanvas* GetCanvas() { return c1; }
};
const char* ROOTSCOPE::styleDraw[3] = {"", "COL1", "COLZ1" };
const int ROOTSCOPE::styleMarkersize[5] = { 1, 6 , 7, 20 };
const int ROOTSCOPE::styleMarkercolor[6] =
{ kBlack, kRed , kGreen, kBlue, kMagenta, kOrange };
void ROOTSCOPE::To_response(Event_t* e) {
// the center for key and mouse response.
/*
Note: Event_t data type see:
https://root.cern.ch/root/html/Event_t.html
for mouse click : check EEventType
Note: for key symbols
https://root.cern.ch/doc/v608/KeySymbols_8h.html
https://root.cern.ch/doc/v606/GuiTypes_8h.html
*/
Set_CannotMove();
// to examine whether a TH1 or TH2 obj in the click-selected pad
// and then set the corresponding flags.
if ( e->fType == kButtonPress && e->fCode == kButton1Down )
{ Get_active_histo1D(); }
// key code lookup table.
const unsigned key_arrow_up = 111;
const unsigned key_arrow_down = 116;
const unsigned key_arrow_left = 113;
const unsigned key_arrow_right = 114;
// for key symbol look up.
UInt_t key_symbol;
char tmp[2];
if ( e->fType == kGKeyPress )
{ gVirtualX->LookupString( e, tmp,sizeof(tmp), key_symbol ); }
// Alt and Ctrl
bool isCtrl = false;
bool isAlt = false;
if ( e->fState & kKeyMod1Mask ) { isAlt=true; } else { isAlt = false; }
if ( e->fState & kKeyControlMask ) { isCtrl=true; } else { isCtrl = false; }
// the object in the pad is TH1.
if( !fIsTH2_inPad ) {
// for mouse button
if ( e->fType == kButtonPress && e->fCode == kButton1Down && !isCtrl && !isAlt )
{ SetMarker( e ); } // right click to set a marker.
// ctl + right click.
if ( e->fType == kButtonPress && e->fCode == kButton1Down && isCtrl && !isAlt )
{ SetGeneralMarkerN( e ); }
// { SetGeneralMarker( e ); }
// for key press test
// cout << "test e->fCode = "<< e->fCode << endl;
//_______key
if ( e->fType == kGKeyPress && !isCtrl && !isAlt ) {
if( key_symbol == kKey_m ) { SetMarker( e ); }
else if( key_symbol == kKey_n ) { Clear_Marker(); }
else if( key_symbol == kKey_e ) { Expand(); }
else if( key_symbol == kKey_E ) { Expand_dlg(); }
else if( key_symbol == kKey_o ) { Unexpand( ); }
else if( key_symbol == kKey_y ) { Set_Y_Range( ); }
else if( e->fCode == key_arrow_left ) { Go_half_left( ); }
else if( e->fCode == key_arrow_right ) { Go_half_right( ); }
else if( key_symbol == kKey_4 ) { Go_half_left(); }
else if( key_symbol == kKey_6 ) { Go_half_right(); }
else if( key_symbol == kKey_PageUp ) { To_switch_histo(1); }
else if( key_symbol == kKey_PageDown ) { To_switch_histo(0); }
else if( key_symbol == kKey_p ) { Project_from_1d( 1 ); }
else if( key_symbol == kKey_P ) { Project_from_1d( 0 ); }
else if( key_symbol == kKey_f ) { To_find_peaks(); }
else if ( key_symbol == kKey_b ) { Fit_Background(); } // fit bg by bg = const.
else if ( key_symbol == kKey_1 ) { Fit_Background_pol1(); } // fit bg by bg = const + linear* x.
else if( key_symbol == kKey_g ) { Fit_Gaussian( ); }
// else if( key_symbol == kKey_G ) { Fit_Double_Gaussian( ); } // only for 2 Gauss
else if( key_symbol == kKey_G ) { Fit_N_Gaussian( ); } // for 2, 3, .. 10 Gauss.
else if( key_symbol == kKey_s ) { Get_Sum( 0 ); }
else if( key_symbol == kKey_c ) { To_switch_overlap(); }
else if( key_symbol == kKey_x ) { Rebin_compress(); }
else if( key_symbol == kKey_X ) { Rebin_uncompress(); }
else if( key_symbol == kKey_V ) { To_show_histo_operation_dlg( ); }
else if( key_symbol == kKey_F1 ) { To_change_fillstyle(); }
else if( key_symbol == kKey_F2 ) { To_change_linewidth(); }
else if( key_symbol == kKey_F3 ) { To_set_logscale(); }
else if( key_symbol == kKey_0 ) { Reset_Background(); }
else if( key_symbol == kKey_l ) { Set_Linear_Background(); } //todo: write note in manual.
}
//_______alt + key
if ( e->fType == kGKeyPress && !isCtrl && isAlt ) {
// alt+m
if ( key_symbol == kKey_m ) { SetMarker2( e ); } //to open a dlg, let user to set value.
// alt+b
else if ( key_symbol == kKey_b ) { Set_Background(); } // open a dlg, let user to set value.
// alt+r
else if( key_symbol == kKey_r ) { To_Change_histo_x_range(); }
}
//_______ctrl + key
if ( e->fType == kGKeyPress && isCtrl && !isAlt ) {
// ctl + shift + c
if( key_symbol == kKey_C ) { To_delete_histo_inSelectedPad(); }
// ctl + d
else if( key_symbol == kKey_d ) { To_overlap_histos(); }
// ctl + w
else if( key_symbol == kKey_w ) { To_writeoutFile(); }
// ctl + r
else if( key_symbol == kKey_r ) { To_readinFile(); }
// ctl + q
else if( key_symbol == kKey_q ) { To_display_histo2d_quick(); }
// ctl + f
else if( key_symbol == kKey_f ) { To_show_find_peaks_dlg(); }
// ctl + p
else if( key_symbol == kKey_p ) { To_show_AddSub_gate_dlg(); }
else if( key_symbol == kKey_n ) { Add_note(e); }
}
} //-------------------------------------end of key reponses for TH1 obj
// the object in the pad is TH2.
if( fIsTH2_inPad ) {
// for mouse button
if ( e->fCode == kButton1Down && e->fType == kButtonPress && isCtrl && !isAlt )
{ SetMarker_2d( e ); } // ctl + right click to set a marker.
//_______key
if ( e->fType == kGKeyPress && !isCtrl && !isAlt ) {
if( key_symbol == kKey_q ) { To_Back_to_disply_histos(); }
else if( key_symbol == kKey_p ) { Projection_2d( 1, true ); }
else if( key_symbol == kKey_P ) { Projection_2d( 0, true ); }
else if( key_symbol == kKey_n ) { Clear_Marker2d( ); }
else if( key_symbol == kKey_e ) { Expand_2d( ); }
else if( key_symbol == kKey_E ) { Expand_2d_dlg( ); }
else if( key_symbol == kKey_o ) { Unexpand_2d( ); }
else if( key_symbol == kKey_F1 ) { To_change_style_2d( ); }
else if( key_symbol == kKey_F2 ) { To_change_marker_size( ); }
else if( key_symbol == kKey_F3 ) { To_set_logscale( ); }
else if( key_symbol == kKey_F4 ) { To_change_marker_color( ); }
else if( key_symbol == kKey_s ) { Get_Sum(1); }
else if( key_symbol == kKey_Z ) { Set_Z_Range(1); } // set z max
else if( key_symbol == kKey_z ) { Set_Z_Range(0); } // set z min
else if( key_symbol == kKey_x ) { Rebin_2d(1, 1); }
else if( key_symbol == kKey_X ) { Rebin_2d(1, 0); }
else if( key_symbol == kKey_y ) { Rebin_2d(0, 1); }
else if( key_symbol == kKey_Y ) { Rebin_2d(0, 0); }
else if( key_symbol == kKey_PageUp ) { To_switch_histo2d(1); }
else if( key_symbol == kKey_PageDown ) { To_switch_histo2d(0); }
}
//_______ctrl + key
if ( e->fType == kGKeyPress && isCtrl && !isAlt ) {
// ctl + w
if( key_symbol == kKey_w ) { To_writeoutFile(); }
// ctl + r
else if( key_symbol == kKey_r ) { To_readinFile(); }
// ctl + shift + p
else if( key_symbol == kKey_P ) { To_full_xy_projection(); }
}
} //--------------------------------- end of key response for TH2 obj
// for both TH1 and TH2
if( 1 ) {
//_______key
if ( e->fType == kGKeyPress && !isCtrl && !isAlt ) {
if( key_symbol == kKey_d ) { To_show_histo_operation_dlg( ); }
else if( key_symbol == kKey_A ) { To_show_histo2d_operation_dlg( ); }
}
//_______ctrl + key
if ( e->fType == kGKeyPress && isCtrl && !isAlt ) {
// ctl + t
if( key_symbol == kKey_t ) { Set_histo_title(); }
}
}
}
// this function can be replaced by SetGeneralMarkerN().
void ROOTSCOPE::SetGeneralMarker( Event_t* e) {
TVirtualPad* currentPad = c1->GetClickSelectedPad();
int px = e->fX;
float xx = currentPad->AbsPixeltoX(px);
int binx = histo->GetXaxis()-> FindBin(xx);
float x_pos = histo-> GetXaxis()-> GetBinCenter( binx );
float y_pos1 = currentPad->GetUymin();
float y_pos2 = currentPad->GetUymax();
if( currentPad->GetLogy() )
{ y_pos2 = pow(10,currentPad->GetUymax() ); } // for log scale
if ( x_pos != fGeneral_pick1 )
{
fGeneral_pick2 = fGeneral_pick1;
fGeneral_pick1 = x_pos;
currentPad->cd();
Set_Line( general_line1, x_pos, y_pos1, x_pos, y_pos2 );
Set_Line( general_line2, fGeneral_pick2, y_pos1, fGeneral_pick2, y_pos2 );
general_line1->Draw();
general_line2->Draw();
}
c1->Update();
}
void ROOTSCOPE::SetGeneralMarkerN( Event_t* e) {
TVirtualPad* currentPad = c1->GetClickSelectedPad();
int px = e->fX;
float xx = currentPad->AbsPixeltoX(px);
int binx = histo->GetXaxis()-> FindBin(xx);
float x_pos = histo-> GetXaxis()-> GetBinCenter( binx );
float y_pos1 = currentPad->GetUymin();
float y_pos2 = currentPad->GetUymax();
if( currentPad->GetLogy() )
{ y_pos2 = pow(10,currentPad->GetUymax() ); } // for log scale
// for update the lines.
if ( x_pos != fGeneral_pickn[0] && x_pos != fGeneral_pickn[1] )
{
for(int p= fUser_generalN-1; p>0; p--)
{
fGeneral_pickn[p] = fGeneral_pickn[p-1];
}
fGeneral_pickn[0] = x_pos;
currentPad->cd();
for(int p = 0; p<fUser_generalN; p++)
{
if(p==0) {
Set_Line( general_linen[p], x_pos, y_pos1, x_pos, y_pos2 );}
else{
Set_Line( general_linen[p], fGeneral_pickn[p], y_pos1,
fGeneral_pickn[p], y_pos2 );}
general_linen[p]->Draw();
}
}
c1->Update();
}
void ROOTSCOPE::SetMarker(Event_t* e){
//------------------------------------------------------------------| get x_pos, y_pos.
TVirtualPad* currentPad = c1->GetClickSelectedPad();
Int_t px = e->fX;
Float_t xx = currentPad->AbsPixeltoX(px);
Int_t binx = histo->GetXaxis()-> FindBin(xx);
Float_t x_pos = histo-> GetXaxis()-> GetBinCenter( binx );
Float_t y_pos = currentPad->GetUymax();
if( currentPad->GetLogy() )
{ y_pos = pow(10,currentPad->GetUymax() ); } // for log scale
//-------------------------------------------------| set x_pos, y_pos to active line.
Switch_ActiveLine( myline1, myline2 ); //switch between fWhich_actice_line.
if ( fWhich_active_line == 1 ) { SetActiveLine( myline1, x_pos, y_pos ); }
else if ( fWhich_active_line == 2 ) { SetActiveLine( myline2, x_pos, y_pos ); }
/* The idea here is :
Initially we have both myline1 and myline2 set black color, and fWhich_active_line = 2
so the first click will go to esle if statement, and plot the black myline2.
The second click, in the Switch_ActiveLine function, set myline2 orange, and myline1 black,
and set fWhich_active_line = 1. and hence we plot black myline1, and the previous myline2 becomes orange.
The thrird click, set myline2 black, myline1 oragne, fWhich_active_line = 2
then we plot myline2, and the previous myline1 becomes orange.
if we click on the same bin twice, it only set fWhich_active_line = 2,
and only plot black myline1.
*/
Set_Xrange_pick( x_pos ); // update fXrange_pick1 and fXrange_pick2;
// get spectrum num
Int_t specNum;
if( fPadTotalN == 1 ){ specNum = fOpen_list.at(0) + 1; }
else if ( fPadTotalN > 1 ) { specNum = fOpen_list.at( fPadActive-1) + 1; }
// show message
float y_counts = histo-> GetBinContent( binx );
*fText_viewer
<< Form("x = %6.2f (bin=%5d), y = %6.2f, spec#%02d ",
x_pos, binx, y_counts, specNum ) << endl;
fText_viewer->ShowBottom();
}
void ROOTSCOPE::SetMarker2(Event_t* e){
// we will pop up a dialog for user to set the marker
//-------------------------------------------------------| get x_pos, y_pos.
TVirtualPad* currentPad = c1->GetPad( fPadActive );
float x_pos;
float x_pos_limit1 = histo->GetXaxis()->GetXmin();
float x_pos_limit2 = histo->GetXaxis()->GetXmax();
// open a dialog for user to input marker position ( x_pos )
new Dlg_Set_Marker( gClient->GetRoot(), this,
10, 10,
&x_pos, x_pos_limit1, x_pos_limit2 );
float y_pos = currentPad->GetUymax();
// check user's input is within the boundaries.
if( x_pos < x_pos_limit1 || x_pos > x_pos_limit2 ) {
// when outside the boundaires.
*fText_viewer << "ERROR marker is out of the bounaries" << endl;
fText_viewer->ShowBottom();
}
else {
// when within the boundaires.
Switch_ActiveLine( myline1, myline2 ); //switch between fWhich_actice_line.
if ( fWhich_active_line == 1 ) { SetActiveLine( myline1, x_pos, y_pos ); }
else if ( fWhich_active_line == 2 ) { SetActiveLine( myline2, x_pos, y_pos ); }
Set_Xrange_pick( x_pos );
// show message
int binx = histo->GetXaxis()-> FindBin( x_pos );
*fText_viewer << Form("x = %6.2f\t\t(bin \t= %d) ", x_pos, binx) << endl;
fText_viewer->ShowBottom();
}
}
void ROOTSCOPE::Set_Y_Range( ) {
/* only apply for the click-selected pad.
we disable Set_Y_Range() function in the logscale mode.
*/
if ( fLogScale_style != true ) {
TVirtualPad* currentPad = c1->GetPad( fPadActive );
float y_max;
// passing by reference to get y_max from user input
new Dlg_Set_YRange(gClient->GetRoot(), this, 10, 10,
&y_max , currentPad->GetUymax() );
histo->GetYaxis()->SetRangeUser( 0, y_max );
c1->cd( fPadActive);
histo->Draw( fH1DrawOption.Data() );
c1->Update();
} else{
*fText_viewer <<
Form("In log scale mode, set y range will have an issue in display.") << endl;
fText_viewer->ShowBottom();
}
}
void ROOTSCOPE::Clear_Marker(){
// hide the line makers, and clear the fitting lines.
Set_Line( myline1, 0, 0, 0 ,0 ); myline1->Draw();
Set_Line( myline2, 0, 0, 0 ,0 ); myline2->Draw();
if ( fPadTotalN > 1 ) {
TH1* htest1;
for( int i=1; i<= fPadTotalN; i++ ) {
c1->cd(i);
Set_Line( fTmpSet1_lines[i], 0, 0, 0 ,0 );
Set_Line( fTmpSet2_lines[i], 0, 0, 0 ,0 );
fTmpSet1_lines[i]->Draw();
fTmpSet2_lines[i]->Draw();
Get_histo_by_padnum( i )->Draw();
c1->GetPad(i)->Update();
}
}
for( int p=0; p<NPEAKS; p++) { fGeneral_pickn[p] = 0; }
c1->cd( fPadActive);
histo->Draw( fH1DrawOption.Data() );
c1->Update();
}
void ROOTSCOPE::Set_Line( TLine* l, float x1, float y1, float x2, float y2 ) {
l->SetX1( x1 ); l->SetY1( y1 );
l->SetX2( x2 ); l->SetY2( y2 );
}
void ROOTSCOPE::Switch_ActiveLine(TLine* l1, TLine* l2) {
float l1_x = l1->GetX1();
float l2_x = l2->GetX1();
if ( l1_x != l2_x ) {
if ( fWhich_active_line == 1 ) {
l1->SetLineColor( kOrange );
l2->SetLineColor( kBlack );
for( int i=0; i< ftemp_lineN; i++ ) { fTmpSet1_lines[i]->SetLineColor( kOrange ); }
for( int i=0; i< ftemp_lineN; i++ ) { fTmpSet2_lines[i]->SetLineColor( kBlack ); }
fWhich_active_line = 2;
}
else if ( fWhich_active_line == 2) {
l1->SetLineColor( kBlack );
l2->SetLineColor( kOrange );
for( int i=0; i< ftemp_lineN; i++ ) { fTmpSet1_lines[i]->SetLineColor( kBlack ); }
for( int i=0; i< ftemp_lineN; i++ ) { fTmpSet2_lines[i]->SetLineColor( kOrange); }
fWhich_active_line = 1;
}
} else {
// for the case when we click on the same bin twice ( l1_x == l2_x )
// or initially l1_x =l2_x = 0
fWhich_active_line = 2;
}
}
void ROOTSCOPE::SetActiveLine( TLine* l, float x_pos, float y_pos ) {
/* (a) when we have two or more pads display in the canvas, and
(b) when all the displayed 1d histos have same x dimension.
we don't use myline1 and myline2 to plot the markers,
instead we use two sets of temp lines (fTmpSet1_lines[] and fTmpSet2_lines),
such that each pad have two lines.
the variable "l" still has to be set, since it
record where the current marker, but just not involves in the plotting.
*/
if( fPadTotalN == 1 )
{
c1->cd();
Set_Line( l, x_pos, 0, x_pos, y_pos ); l->Draw();
c1->Update();
}