-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshspe.C
4266 lines (3395 loc) · 142 KB
/
shspe.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: Jaromir Mrazek - 2008/08
// started with scripts and help of people from root team (Antcheva 1/12/2006)
//
//-- logy
// gcut - crashes...
//
#include "kibbler_fit.C" // things from here are in shspe.h
// which is unhealthly....
#include "shspe.h" // I put in front to be available to all incl
//-------- new rewrite - with sh_....
#include "sh_ver.h" // version number header created by cmake
#include "sh_menu.h"
#include "sh_cuts.C"
#include "sh_saveobj.C" // also savecanvas
#include "sh_graph.C" //graphs, also joingraph
#include "sh_tnamed.C" // TH1 GetListOfFunctions()
//------------- all previous ......
#include "TMapFile.h"
// shspe.h .... formely here ....
#include "kibbler_gdir.C"
//#include "cuts_manip.h"
#include <TPolyLine.h>
//we move to gui.h .......to have visibility...#include "kibbler_graphs.C"
#include <fstream>
#include <iostream>
#include <string>
//==== i want to look at $HOME for rt2.PID
//#include <unistd.h>
//#include <sys/types.h>
#include <pwd.h>
ClassImp(MyMainFrame) // this is a macro !!!!
void MyMainFrame::DoSelect(){ Printf("Slot DoSelect()");}
void MyMainFrame::DoExit(){ Printf("Slot DoExit()");}
int CURRENT_SLOT=1; // get_free_slot ....
//######################################################################
// Desktop setup savecanvas load configuration from a saved canvas
//######################################################################
int Desktop_setup_savecanvas(const char *filenam){
TFile *oldfile=gFile;
if (oldfile!=NULL){
printf("Veeeerrry tricky. You must be careful with two files%s\n","");
}
TDirectory *oldir=gDirectory;
if (gROOT->GetListOfCanvases()->At(0) ==NULL){printf("%d canvases\n",0);return 0;}
TCanvas *cmy=gPad->GetCanvas();
cmy->Clear();
printf("CMY %ld\n", (int64_t)cmy);
// FillWhite();
TObject *o;
/*
* OPEN file and get all pads and canvases
*/
int filexists=gSystem->AccessPathName( filenam ); // FILE EXISTS TEST
printf("DEBUG %s == %d\n",filenam, filexists );
if (filexists==0){// file for desktop setup canvas exists
TFile *f=new TFile(filenam);
gDirectory->GetObject( gDirectory->GetListOfKeys()->At(0)->GetName() ,o);
// 1st name is usually----------------------------------------------------
// - tcanvas
// - tpad
if ( strcmp("TCanvas",o->ClassName()) ==0){
cmy->cd();
printf("CMY %ld\n", (int64_t)cmy);
TPad *pads;
TCanvas *cizi = (TCanvas*)o;
int imax=cizi->GetListOfPrimitives()->GetEntries();
printf("%d entries found(Desktop_setup_savecanvas)\n", imax );
int pad_exnum=0;
for (int i=0;i<imax;i++){
printf("Primitive %d has %s class\n", i,cizi->GetListOfPrimitives()->At(i)->ClassName() );
//when it is TPad...create clone and draw it.........
if (strcmp("TPad",cizi->GetListOfPrimitives()->At(i)->ClassName())==0){
printf(" ...drawing Primitive %d %s\n", i,cizi->GetListOfPrimitives()->At(i)->GetName() );
pad_exnum++;
pads=(TPad*) cizi->GetListOfPrimitives()->At(i)->Clone();
// here I draw the clone of the original TPAD
pads->Draw();
//and now it would be good to place an analogic histogram
//
// cizi->GetListOfPrimitives()->At(i)->Draw() ;
}// is TPad
}// all entries found... i=0;i<imax;i++
//this doesnot help...
if (pad_exnum==0){
printf("NO TPADS .... you should have used 26_SaveCanv\n%s" , "");
/*
TCanvas *ccizi=(TCanvas*)cizi->GetCanvas();
ccizi->Divide(1,1);
ccizi->cd(1);
TPad *cizip=(TPad*)gPad;
for (int j=0;j<cizi->GetListOfPrimitives()->GetEntries();j++){
printf("NO Tpad: trying %s\n",cizi->GetListOfPrimitives()->At(j)->ClassName() );
if (strstr(cizi->GetListOfPrimitives()->At(j)->ClassName(),"TH")>0){
printf("NO Tpad: DRAW! %s\n",cizi->GetListOfPrimitives()->At(j)->ClassName() );
TH1*ooo=(TH1*) cizi->GetListOfPrimitives()->At(j)->Clone();
ooo->Draw();
// cmy->Modified();cmy->Update();
}
}
cmy->cd();
cizip->Draw();
*/
}//no tpads...
if (oldfile!=NULL){
// printf("Veeeerrry . You must be careful with two files%s\n","");
printf(" ..... saving oldfile ...be careful with two files%s\n","");
oldfile->cd();
}
f->Close();
cmy->Modified();cmy->Update();
// this also works when there are 2 files
oldir->cd();
printf("CMY %ld\n", (int64_t)cmy);
/*
*
*/
//------------------------- in this moment - former TPads are cleanly loaded with the original histos
imax=cmy->GetListOfPrimitives()->GetEntries();
printf("%d PAD entries found in local canvas ... parsing all...\n", imax );
int icizi; // if there is TFrame at 1st place, we must split i and icizi
for (int i=0;i<imax;i++){
icizi=i;
printf("%02d) cmy has %s class // cizi has %s class\n", i,
cmy->GetListOfPrimitives()->At(i)->ClassName(),
cizi->GetListOfPrimitives()->At(icizi)->ClassName() );
//one problem. if there is only one TPad, the first can be TFrame.... i==0 here, we try:
if (strcmp("TFrame",cizi->GetListOfPrimitives()->At(icizi)->ClassName())==0){
for (icizi=0;icizi<cizi->GetListOfPrimitives()->GetEntries();icizi++){
if (strcmp("TPad",cizi->GetListOfPrimitives()->At(icizi)->ClassName())==0){break;}
}// find icizi
}//if it is tframe ... i==0 here
if (strcmp("TPad",cizi->GetListOfPrimitives()->At(icizi)->ClassName())==0){
TString padname = cizi->GetListOfPrimitives()->At(icizi)->GetName();
printf(" ... My TPad primitive #%02d has name %s\n", i, padname.Data() );
// browse inside cizi to find the histos
TPad *p=(TPad*)cizi->GetListOfPrimitives()->At(icizi);
int jmax=p->GetListOfPrimitives()->GetEntries();
for (int ii=0;ii<jmax;ii++){
// printf(" ... My SubPrimitive %d %s class=%s\n",
// ii,p->GetListOfPrimitives()->At(ii)->GetName(),p->GetListOfPrimitives()->At(ii)->ClassName() );
if ( (strcmp("TH1F",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TH2F",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TH1D",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TH2D",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TGraph",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TGraphErrors",p->GetListOfPrimitives()->At(ii)->ClassName())==0)
){
printf(" ... class THxx ok, original histo=%s #%02d ",p->GetListOfPrimitives()->At(ii)->GetName() ,i+1 );
// find this object at my gDirectory....! and in files
// name;cycle
// Get - look into memory only (if not ;123)
// TObject *dro=gDirectory->FindObject( p->GetListOfPrimitives()->At(ii)->GetName() );
TObject *dro=gDirectory->Get( p->GetListOfPrimitives()->At(ii)->GetName() );
int classify=0;
if (dro!=NULL){ classify=1;} // TH12
if (
(strcmp("TGraph",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TGraphErrors",p->GetListOfPrimitives()->At(ii)->ClassName())==0)
){
dro=gROOT->GetListOfSpecials()->FindObject( p->GetListOfPrimitives()->At(ii)->GetName() );
if (dro!=NULL){ classify=2;} // GRAPH
}
// cd into the proper pad
//cmy->cd(i+1);
TPad *p2=(TPad*)cmy->FindObject( padname.Data() );
if (p2!=NULL){
printf("TPad %s found.\n",padname.Data());p2->cd();
}else{
printf("TPad named %s not found guess cd.\n",padname.Data()); cmy->cd(i+1);
}//p2
/*
* draw the found object:
*/
if (classify==2 ){
printf("graph found localy. ok. %s found localy as %ld. ok.\n",
p->GetListOfPrimitives()->At(ii)->GetName(),
(int64_t)gROOT->GetListOfSpecials()->FindObject(p->GetListOfPrimitives()->At(ii)->GetName() ) );
TGraphErrors *obh=(TGraphErrors*)gROOT->GetListOfSpecials()->FindObject(p->GetListOfPrimitives()->At(ii)->GetName() );
// TGraphErrors *dro2=(TGraphErrors*)dro;
obh->SetTitle( p->GetListOfPrimitives()->At(ii)->GetName() ); // We put the title == graph name
obh->Draw("pawl");
dro=NULL;
}
if ( classify==1 ){
printf("histo found localy. ok. %s found localy. ok.\n", p->GetListOfPrimitives()->At(ii)->GetName() );
/*
* // replicate ZOOM
*/
double x1,x2,y1,y2;
int ix1,ix2,iy1,iy2;
// if ( (strcmp("TH1",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ){
TH1 *obh=(TH1*)p->GetListOfPrimitives()->At(ii);
TH1 *dro2=(TH1*)dro;
printf("preparing to get X zooms : class %s\n", p->GetListOfPrimitives()->At(ii)->ClassName() );
// x1=obh->GetXaxis()->GetXmin();
// x2=obh->GetXaxis()->GetXmax();
ix1=obh->GetXaxis()->GetFirst(); //bin (1)
ix2=obh->GetXaxis()->GetLast(); //bin 8192
x1=obh->GetXaxis()->GetBinLowEdge( ix1 ); //bin (1)
x2=obh->GetXaxis()->GetBinUpEdge( ix2 ); //bin 8192
// y1=obh->GetYaxis()->GetXmin();
// y2=obh->GetYaxis()->GetXmax();
// dro2->GetYaxis()->SetRangeUser( y1,y2 );
if ( (strcmp("TH2F",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ||
(strcmp("TH2D",p->GetListOfPrimitives()->At(ii)->ClassName())==0) ){
printf("2D treatment\n");
iy1=obh->GetYaxis()->GetFirst(); //bin (1)
iy2=obh->GetYaxis()->GetLast(); //bin 8192
y1=obh->GetYaxis()->GetBinLowEdge( iy1 ); //bin (1)
y2=obh->GetYaxis()->GetBinUpEdge( iy2 ); //bin 8192
printf("2D zoom apply : X %f %f, Y %f %f\n", x1,x2, y1,y2 );
dro2->GetXaxis()->SetRangeUser( x1,x2 );
dro2->GetYaxis()->SetRangeUser( y1,y2 );
dro2->Draw("col");
dro2->GetXaxis()->SetRangeUser( x1,x2 );
dro2->GetYaxis()->SetRangeUser( y1,y2 );
}else{
printf("1D treatment\n");
printf("1D zoom apply : X %f %f, Y %f %f\n", x1,x2, y1,y2 );
dro2->GetXaxis()->SetRangeUser( x1,x2 );
dro2->Draw();
dro2->GetXaxis()->SetRangeUser( x1,x2 );
}
// }// zooms for th1f only
// else{
//dro->Draw();
// }
//
}
if ( classify==0 ){
printf("histo not found localy: %s not found localy: clear\n", p->GetListOfPrimitives()->At(ii)->GetName() );gPad->Clear();
}
}// if class TH12fd
}// for primit inside tpad
}// is TPad
}// for all entries in local canvas
}else{ // TCanvas classname ......
printf("Not Canvas..sorry%s\n","");
f->Close();
oldir->cd();
return 1; //?
}//canvas/not canvas
oldir->cd();
}//f!=NULL => file dava smysl.....
else{
return 1;// file canvas root doesnot exist
}
return 0; //ok, it exists
}// Desktop setup SAVECANCAS -----------------------------------------------------
//---------------------- BEGIN OF MOUSE CONNECT- ----------- MARKKS???
/*
* CONNECT THE MOUSE TO EVENT ......... do it more transparent....
*/
void MyMainFrame::exec3event(Int_t event, Int_t x, Int_t y, TObject *selected)
{
//UNUSED TCanvas *c = (TCanvas *) gTQSender;
//dont react on hover, pull.......
/* 1 ...left down
* 11 left up
* 2,12 middle donw, up
* 3 right down
*
* 1,11,61,11 == doubleclick left
* 2,12,62,12 == doubleclick middle
* 3,63,13 == doubleclick right
*/
if ( (event!=51)&&(event!=52)&&(event!=53)&&(event!=21) ){ // 21=pull
// printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n",
// c->GetName(), event, x, y, selected->IsA()->GetName() );
TString ss= selected->IsA()->GetName();
if (event==11){
// printf("left click (show energy)%s\n", "");
}// event 11
// When you click on a TGraphError MARKS point:
if (ss.CompareTo("TGraphErrors")==0){//======ONLY ON TGraphErrors ===
TGraphErrors *g=(TGraphErrors*)selected;// g->Print();
if (strcmp(g->GetName(),"MARKS")==0){//=====ONLY MARKS =====
// 2: sum peak
// 4: fit background around peak
if ((event==11)&&( (g->GetN()==2) || (g->GetN()==4) ) ){ // if LEFTCLICK - SUM DATA = TODO
//printf("SUMMING THE REGION OF MARKS \n");
TH1* histo; int64_t addr[MAXPRIMITIVES];addr[0]=0; int count=1;
//RecoverTH1fromGPAD( count, addr ,"TH");
RecoverTH1fromGPAD( count, addr , "TH" ,0 , "TGraph" ); // I SEARCH TH2 or ????
histo=(TH1*)addr[0];
//printf("D... recovered histo name= %s class=\n",
// histo->GetName() ,histo->ClassName() );
TGraphErrors *g=(TGraphErrors*)gPad->FindObject("MARKS");
if ((g!=NULL)&&(g->GetN()>=2)){ //======== fit BG ==== TODO
//printf(" bg fit around a peak.....%s" , "\n" );
// polynomial fit of BG to do:
}
if ((g!=NULL)&&(g->GetN()==2)){ //======== say bg and histo SUM
double xlow=g->GetX()[0]; double xhi=g->GetX()[1];
double ylow=g->GetY()[0]; double yhi=g->GetY()[1];
if (xlow>xhi){ double aa=xlow; xlow=xhi;xhi=aa;}
double bg=(xhi-xlow)*(ylow+yhi)/2.0;
double inte=histo->Integral( xlow, xhi );
double net=inte-bg;
printf(" histo== %s (%.3f, %.3f)\n SUM==%10.3f BG==%10.3f NET==%10.3f\n",
histo->GetName(),xlow,xhi, inte , bg, net);
}
//g->Print();
}//11---------LEFT CLICK
if (event==12){ // middle click => remove the point MIDDLE CLICK
Double_t xp = gPad->PadtoX(gPad->AbsPixeltoX(x));
Double_t yp = gPad->PadtoY(gPad->AbsPixeltoY(y));
int npoints=g->GetN(); int closest=0;
double clo=sqrt( pow(xp-g->GetX()[0],2)+pow(yp-g->GetY()[0],2) );
double clomax=clo; int i;
for (i=0;i<npoints;i++){
clo=sqrt( pow(xp-g->GetX()[i],2)+pow(yp-g->GetY()[i],2) );
if (clo<clomax) { clomax=clo; closest=i;}
}
printf("removing point #%d near: %f : %f\n", closest, xp,yp );
// if (closest==0){ g-}
if (g->GetN()>1){
g->RemovePoint( closest );
g->Sort(); // WE MUST SORT HERE but not when 2D!!
}else{
//--------- new delete -----
//printf("!... deleting MARKS by middle-click\n%s","");
if (gROOT->GetListOfSpecials()->FindObject("MARKS")!=NULL ){
TGraphErrors *gro=(TGraphErrors*)gROOT->GetListOfSpecials()->FindObject("MARKS") ;
gROOT->GetListOfSpecials()->Remove( gro ); // delete MARKS from gROOT
//}
delete gro;
//printf("!... not deleting MARKS\n%s","");
//g->Delete();
}//-- if MARKS !=NULL
//if (gROOT->GetListOfSpecials()->FindObject("MARKS")!=NULL){
//}
//delete g;
//g->Delete();
//printf("!... not deleting MARKS");
} // GetN >1
RefreshAll();
}//12----------MIDDLECLICK
//----- no tgraph can be after.....
}//it is MARKS tgrapherrors
}//it is TGraphErrors--------------===============================================
// NOT TGraphErrors ==> Must Want to create (new/next) MARKS...
else if(gPad->FindObject("MARKS")!=NULL ){ //
/*
* IF NOT on TGraph... but MARKS still exist
*/ // Middle12 + goodOBJECT
if ((event==12)&&( //******************* MIDDLE CLICK INSERT
(strcmp(selected->IsA()->GetName(),"TFrame")==0 )||
(strcmp(selected->IsA()->GetName(),"TH1F")==0 )||
(strcmp(selected->IsA()->GetName(),"TH1D")==0 )||
(strcmp(selected->IsA()->GetName(),"TH2F")==0 )
)
){ // LEFT CLICK - SUM DATA
//printf("D... MIDCLICK = Insert?\n","");
TGraphErrors *g=(TGraphErrors*)gPad->FindObject("MARKS");
if ( gROOT->GetListOfSpecials()->FindObject("MARKS")==NULL){
gROOT->GetListOfSpecials()->Add(g);
}// find MARKS==NULL in GetLiOSpecial => get it to GlisOSpecial
//printf("ADDING TO MARKS, GetN() will == %d \n", g->GetN()+1 );
if (g->GetN()==1){
printf("i... LEFT CLICK will count integral and bg\n%s","");
}
// Double_t xp = gPad->PadtoX(gPad->AbsPixeltoX(x));
// Double_t yp = gPad->PadtoY(gPad->AbsPixeltoY(y));
// CHCI POUZE POKUD JE TO CISLO ...... == apriori sigma
/*
TString *fentry=new TString( fEntry->GetText() ); // DEPRECIATED:---------
if ( fentry->CompareTo("")!=0 ){
if (TPRegexp("^[\\d]+$").Match(fentry->Data() )!=0){// match
defaultsigma=atoi( fentry->Data() );
}// is a number
}//fentry exists---------------possibility to change defaultsigma
*/
TString *fentry=new TString( fEntrySIG->GetText() ); // DEPRECIATED:---------
if ( fentry->CompareTo("")!=0 ){
if (TPRegexp("^[\\d]+$").Match(fentry->Data() )!=0){// match
defaultsigma=atoi( fentry->Data() );
}// is a number
}//fentry exists---------------possibility to change defaultsigma
//g->Print();
//
//--------------------- v6.12.6 crashes when InsertPoint()
//
//printf("D... inserting point \n","");
//g->InsertPoint( );
//printf("D... inserting point ok \n","");
//g->Print();
double xw[1],yw[1],xwe[1],ywe[1];
xw[0]=gPad->PadtoX(gPad->AbsPixeltoX(x));
yw[0]=gPad->PadtoY(gPad->AbsPixeltoY(y));
xwe[0]=defaultsigma;
ywe[0]=0.0;
g->SetPoint( g->GetN(), xw[0], yw[0]);
//---------------- earlier code.........
g->GetEX()[ g->GetN()-1 ] = defaultsigma;
g->GetEY()[ g->GetN()-1 ] = 0.0;
g->Draw("PL");
// g->Sort(&TGraph::CompareRadius); // Sort will be extra
// g->Sort();
//=================listpoints === =PRINTOUT====
for (int i=0; i<g->GetN(); i++){
printf("%2d %7.3f %7.3f\n",
i,
g->GetX()[i],
g->GetY()[i]
);
}
if (g->GetN()==2){ // === =PRINTOUT====
double lowy,hiy;
if (g->GetY()[0]<g->GetY()[1]){ lowy=g->GetY()[0]; hiy=g->GetY()[1];}else{
lowy=g->GetY()[1]; hiy=g->GetY()[0];
}
printf("&& (x>%10.3f) && (x<%10.3f) \n && (y>%10.3f) && (y<%10.3f) \n",
g->GetX()[0],g->GetX()[1],
lowy,hiy );
}
//=====================list
RefreshAll();
}//11---------LEFT CLICK
}//ELIF - NOT TGRAPH and "MARKS on gPad exists"
else if(gPad->FindObject("MARKS")==NULL){ // NO MARKS ON gPad=======
if ((event==12)&&( // ================= MIDDLE12 and goodOBJECT
(strcmp(selected->IsA()->GetName(),"TFrame")==0 )||
(strcmp(selected->IsA()->GetName(),"TH1F")==0 )||
(strcmp(selected->IsA()->GetName(),"TH1D")==0 )||
(strcmp(selected->IsA()->GetName(),"TH2F")==0 )
)
){ // MIDDLE CLICK -
// fSELetMarks;
//printf("D... middleclick - the first click?\n","");
// CHCI POUZE POKUD JE TO CISLO ...... == apriori sigma
TString *fentry=new TString( fEntrySIG->GetText() ); // to bylo vyse comment jako DEPR.?
if ( fentry->CompareTo("")!=0 ){
if (TPRegexp("^[\\d]+$").Match(fentry->Data() )!=0){// match
defaultsigma=atoi( fentry->Data() );
}// not a number
}//fentry exists---------------possibility to change defaultsigma
double xw[1],yw[1],xwe[1],ywe[1];
xw[0]=gPad->PadtoX(gPad->AbsPixeltoX(x));
yw[0]=gPad->PadtoY(gPad->AbsPixeltoY(y));
xwe[0]=defaultsigma; // defined in class, assigned in constructor....
ywe[0]=0.0;
TGraphErrors *m=new TGraphErrors(1,xw,yw,xwe,ywe);m->SetName("MARKS");
m->SetMarkerStyle(2); m->SetMarkerSize(4);
m->SetMarkerColor(2); m->SetLineStyle(2); m->SetLineColor(2); m->Draw("PL");
RefreshAll();
}// MIDDLE CLICK
}// ELIF - NOT TGRAPH and "MARKS on gPad NOT exist"
}// more THEN just mouse hover....
}// execute event.......... END
//---------------------- END OF MOUSE CONNECT- -----------
void MyMainFrame::FillMainMenu(){
char tmp[40];
//NOT HERE....... fListBoxOF->AddEntry("testik", 1);
if (PAGE==1){
sprintf(tmp, "%i_***Next/Page***", SELNextPage); fListBox->AddEntry(tmp, SELNextPage);
sprintf(tmp, "%i_SetMarks", SELSetMarks); fListBox->AddEntry(tmp, SELSetMarks);
sprintf(tmp, "%i_SortMarks/GCut", SELGetMarks); fListBox->AddEntry(tmp, SELGetMarks);
sprintf(tmp, "%i_DelMarks", SELDelMarks); fListBox->AddEntry(tmp, SELDelMarks);
sprintf(tmp, "%i----------",SELbar1 ); fListBox->AddEntry(tmp, SELbar1);
sprintf(tmp, "%i_FindPeaks", SELFindPks); fListBox->AddEntry(tmp, SELFindPks);
sprintf(tmp, "%i_FindBg", SELFindBg); fListBox->AddEntry(tmp, SELFindBg);
sprintf(tmp, "%i_DelPeaks", SELDelPks); fListBox->AddEntry(tmp, SELDelPks);
// sprintf(tmp, "%i_FitGaus", SELFitGaus); fListBox->AddEntry(tmp, SELFitGaus);
sprintf(tmp, "%i----------",SELbar2 ); fListBox->AddEntry(tmp, SELbar2);
sprintf(tmp, "%i_StartFIT", SELFBX); fListBox->AddEntry(tmp, SELFBX );
sprintf(tmp, "%i_UpdateMARKS", SELUpdate); fListBox->AddEntry(tmp, SELUpdate);
sprintf(tmp, "%i_SaveFit", SELSaveFit); fListBox->AddEntry(tmp, SELSaveFit);
// sprintf(tmp, "%i_", SELFit); fListBox->AddEntry(tmp, SELFit);
sprintf(tmp, "%i_HelpFit", SELDelFBX); fListBox->AddEntry(tmp, SELDelFBX);
sprintf(tmp, "%i----------",SELbar3a ); fListBox->AddEntry(tmp, SELbar3a);
sprintf(tmp, "%i_Clone2Rint", SELClone2Rint); fListBox->AddEntry(tmp, SELClone2Rint);
}// PAGE==1
if (PAGE==2){
sprintf(tmp, "%i_***Next/Page***", SELNextPage);fListBox->AddEntry(tmp, 1);
// sprintf(tmp, "%i----------",SELbar3 ); fListBox->AddEntry(tmp, 2);
sprintf(tmp, "DateTime,Calib (o)"); fListBox->AddEntry(tmp, SELDateTime -SELGrid+2);
sprintf(tmp, "Grid"); fListBox->AddEntry(tmp, SELGrid -SELGrid+2);
sprintf(tmp, "Logy"); fListBox->AddEntry(tmp, SELLogy -SELGrid+2);
sprintf(tmp, "Logz"); fListBox->AddEntry(tmp, SELLogz -SELGrid+2);
// sprintf(tmp, "%i_Div,LoadCanvas", SELDivide); fListBox->AddEntry(tmp, SELDivide -SELGrid+2);
// sprintf(tmp, "%i_LoadCanvas", SELDivide); fListBox->AddEntry(tmp, SELDivide -SELGrid+2);
sprintf(tmp, "----------" ); fListBox->AddEntry(tmp, SELbar4 -SELGrid+2 );
sprintf(tmp, "LoadCanvas (o)" ); fListBox->AddEntry(tmp, SELLoadCanvas -SELGrid+2 );
sprintf(tmp, "SaveCanvas (o)" ); fListBox->AddEntry(tmp, SELSaveCanvas -SELGrid+2 );
sprintf(tmp, "SaveAllSpectra " ); fListBox->AddEntry(tmp, SELSaveSpectra-SELGrid+2 );
//MenuItemDivCanvas
sprintf(tmp, "DivCanvas (o)"); fListBox->AddEntry(tmp, SELDivCanv-SELGrid+2 );
sprintf(tmp, "Unzoom/Rng x1-x2 (o)" ); fListBox->AddEntry(tmp, SELUnzoom -SELGrid+2 );
// sprintf(tmp, "%i----------",SELbar5 ); fListBox->AddEntry(tmp, SELbar5 -SELGrid+2 );
sprintf(tmp, "------Spectrum2Memory" ); fListBox->AddEntry(tmp, SELClone2Rint2-SELGrid+2 );
//sprintf(tmp, "RefreshAll " ); fListBox->AddEntry(tmp, SELRefresh -SELGrid+2 );
sprintf(tmp, "___________" ); fListBox->AddEntry(tmp, SELbar5 -SELGrid+2 );
sprintf(tmp, "Clear " ); fListBox->AddEntry(tmp, SELClear -SELGrid+2 );
sprintf(tmp, "ClearAll " ); fListBox->AddEntry(tmp, SELClearAll -SELGrid+2 );
// sprintf(tmp, "%i_ZoomAll " ,SELZoomAll ); fListBox->AddEntry(tmp, SELZoomAll-SELGrid+2 );
} // PAGE2
// fListBox->Resize(100,270); // 2.cislo = vyska
// 240 vyska
fListBox->Resize(100,listbox_vsize); // 2.cislo = vyska
//not def here fListBox2->Resize(100,listbox2_vsize); // 2.cislo = vyska
Layout();
}// FillMainMenu ... fills main menu pages.
/******************************************************************
******************************************************************
******************************************************************
******************************************************************
* CONSTRUCTOR
*******************************************************************
*/
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h, int page, int startstop=0) :
TGMainFrame(p, w, h)
{
// defaultsigma=5; /// ??? FIRST GUESS TO SIGMA Tbroomfit uses this
fit=0; /// there is a test ==NULL nad delete after...
flistbox_selected=-1;
// triple clikc
time_t curtime; struct tm *loctime;
curtime = time (NULL); loctime = localtime (&curtime);
lastcmd=0; lastlastcmd=0;
flistbox_selected_when=0;
lastcmdtime=(int)curtime; lastlastcmdtime=(int)curtime;
printf("linux time == %d\n", (int)curtime);
time_start=curtime; // time when shsp was started
// time_block=3600; // basic time block for TH2F's - to increase...
time_block=600; // basic time block for TH2F's - to increase...
// delay_refresh=1500;
// delay_clear=5000;
PAGE=1; // init page
PAGE=2; // init page
PAGE=page;
nfileentr=0;
primar_sigma=10.0;
MarksOn=0; // marks are not ON
fancy_rot_flag=0; // rotation of different fancy things (logz,
fancy_grid=0;fancy_logy=0;fancy_logz=0;
divide_mod_flag=0;
gStyle->SetPalette(1);
//morhac find peaks....
spe=NULL;
bg=NULL;
bgf=NULL;
// Create main frame####################################################
/*
* listbox1 .... MENU
*
*/
TGHorizontalFrame *hBframe = new TGHorizontalFrame(this);
fListBox = new TGListBox(this, 100);// TGWindow, id=89 // ?
fSelected = new TList;
fListBox2 = new TGListBox(hBframe, 101);// TGWindow, id // ? MENU?
fSelected2 = new TList;
fListBoxOF = new TGListBox(hBframe, 122);// TGWindow, id=89 // OPENFILE
// fSelectedOF = new TList;
FillMainMenu();
// fListBoxOF->Clear();
fListBoxOF->RemoveEntries( 0, fListBoxOF->GetNumberOfEntries() ); // correct way...?
//// (fListBoxOF nema expandX
hBframe->AddFrame(fListBox2 , new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
hBframe->AddFrame(fListBoxOF, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 0, 0, 0, 0));
// WORKS
fListBox->Connect("Selected(Int_t, Int_t)", "MyMainFrame", this, "ClickResponse(Int_t, Int_t)");
// copied from exec3event
// | kFixedHeight makes it all stiff...
AddFrame(fListBox, new TGLayoutHints(kLHintsLeft |
kLHintsExpandX,
5, 5, 5, 5));
// | kLHintsExpandY
// NEW - HORI FRAME =================== I PUT [inputtextbox] IN BETWEEN 2 LISTS ==========
TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 150, 20, kFixedWidth); // label
TGLabel *labelo = new TGLabel(hframe, "(o):");
hframe->AddFrame(labelo, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
//-------------------------------------------
; //textentry
fEntry = new TGTextEntry( hframe, "" ); //default text...
hframe->AddFrame(fEntry, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
fEntry->SetToolTipText("Options for MENU items. Each item with (o) has a txt option");
//---- finalize HFRAME
AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
//========================================================= #0# refresh ##
/// doesnt retur sometimes ... ? why?
TGHorizontalFrame *hframeRefresh = new TGHorizontalFrame(this, 150, 20, kFixedWidth | kFixedHeight);
//button13 -------------- refresh button
show13 = new TGTextButton(hframeRefresh, "&Refresh",13);
show13->SetToolTipText("refresh");
show13->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframeRefresh->AddFrame(show13, new TGLayoutHints(kLHintsExpandX , 0,0,0,0));
AddFrame(hframeRefresh, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
ULong_t colreafresh;
gClient->GetColorByName("lightblue", colreafresh);
show13->ChangeBackground( colreafresh );
fListBoxOF->Connect("Selected(Int_t, Int_t)", "MyMainFrame", this, "ClickResponse(Int_t, Int_t)");
AddFrame(hBframe, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY , 5, 5, 0, 5));
//--------------------------------------------------------------dalsi flistbox
/*
* listbox2 .... filey
*
*/
fListBox2->AddEntry("***OPEN File***", 1);
// for (int ii=2;ii<=19;ii++){ sprintf(tmp, "%d", ii ); fListBox2->AddEntry(tmp, ii); }
nfileentr=0; // zero histos in file
fListBox2->Resize(100 , listbox2_vsize );
fListBoxOF->Resize(1 , listbox2_vsize ); // BY DEFAULT it is very small
fListBox2->Connect("Selected(Int_t, Int_t)", "MyMainFrame", this, "ClickResponse(Int_t, Int_t)");
fListBox2->Connect("DoubleClicked(Int_t)", "MyMainFrame", this,
"ClickResponse(Int_t)");
/*
// THOS DOESNOT WORK - UNFORTUNATELY.........
//http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=10972
//
printf("box2 container: %d <%s>\n", fListBox2->GetContainer(), fListBox2->GetContainer()->ClassName() );
fListBox2->GetContainer()->Connect("DoubleClicked(TGFrame*, Int_t)", "MyMainFrame",
this, "ClickResponseDC(TGFrame*, Int_t)");
*/
// AddFrame(fListBox2, new TGLayoutHints(kLHintsTop | kLHintsLeft |
// kLHintsExpandX ,
// 5, 5, 5, 5));// padding, neexpanduj Y
// ORIGINAL HORI FRAME ====================
//========== new hframe_a .... center? ================================ #!#
TGHorizontalFrame *hframe_a = new TGHorizontalFrame(this, 150, 20, kFixedWidth);
//textentry SIGMA
TGLabel *label = new TGLabel(hframe_a, "sigma");
hframe_a->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
//-------------------------
defaultsigma=5.0; /// ??? FIRST GUESS TO SIGMA Tbroomfit uses this
char defaultsigmachar[10];
sprintf(defaultsigmachar,"%f",defaultsigma );
printf(" default sigma is %s d=%f-------!!!!!1", defaultsigmachar,defaultsigma );
sprintf(defaultsigmachar,"5%s","" ); // ????? WHY THIS ???
fEntrySIG = new TGTextEntry( hframe_a, defaultsigmachar , 555 );// id nefunguje....
fEntrySIG->SetToolTipText("sigma for gaussian fits");
fEntrySIG->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe_a->AddFrame(fEntrySIG, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
//button W up
TGTextButton *show = new TGTextButton(hframe_a, "&W(up)",1);
show->SetToolTipText("movement UP");
show->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
// hframe_a->AddFrame(show, new TGLayoutHints( kFixedWidth, 5, 5, 3, 4));
hframe_a->AddFrame(show, new TGLayoutHints( kLHintsCenterX, 0,0,0,0));
AddFrame(hframe_a, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
// TGCheckButton *
fChk1 = new TGCheckButton(hframe_a, "Multi", 71);
fChk1->SetToolTipText("common moves");
fChk1->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe_a->AddFrame(fChk1, new TGLayoutHints( kLHintsCenterX, 0,0,0,0));
//color
ULong_t colcheckb;
gClient->GetColorByName("pink", colcheckb);
fChk1->ChangeBackground(colcheckb);
//========== new hframe << >> ====================================== #2#
// Create a horizontal frame containing button(s)
TGHorizontalFrame *hframe2 = new TGHorizontalFrame(this, 150, 20, kFixedWidth);
//button2
TGTextButton *show2 = new TGTextButton(hframe2, "<<&A",2);
show2->SetToolTipText("LEFT");
show2->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe2->AddFrame(show2, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
//button3
TGTextButton *show3 = new TGTextButton(hframe2, "&S(Dn)",3);
show3->SetToolTipText("DOWN");
show3->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe2->AddFrame(show3, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
//button4
TGTextButton *show4 = new TGTextButton(hframe2, "&D>>",4);
show4->SetToolTipText("RIGHT");
show4->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe2->AddFrame(show4, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
//button5
//finalize - adding ASD buttons to object ======
AddFrame(hframe2, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
//========== new hframe ZOOM UNZOOM ============================= #3#
// Create a horizontal frame containing button(s)
TGHorizontalFrame *hframe3 = new TGHorizontalFrame(this, 150, 20, kChildFrame|kFixedWidth );
//button6
TGTextButton *show6 = new TGTextButton(hframe3, "&ZoomX",6);
show6->SetToolTipText("ZOOM");
show6->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe3->AddFrame(show6, new TGLayoutHints(kLHintsExpandX , 2,0,2,2));
/*
//button6
TGTextButton *show8 = new TGTextButton(hframe3, "ZoomY &C",8);
show8->SetToolTipText("ZOOMY");
show8->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe3->AddFrame(show8, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
*/
//button7
TGTextButton *show7 = new TGTextButton(hframe3, "UnZoom&X",7);
show7->SetToolTipText("Unzoom");
show7->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframe3->AddFrame(show7, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
//finalize
AddFrame(hframe3, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
//-----=---------------------------------- NEW FRAME SART STOP ###############
if (startstop!=0){
// Create a STARTSTOP horizontal frame containing button(s)
TGHorizontalFrame *hframeStartStop = new TGHorizontalFrame(this, 150, 20, kFixedWidth | kFixedHeight);
//TGHorizontalFrame *hframeStartStop = new TGHorizontalFrame(this, 150, 10, kFixedWidth | kFixedHeight );
//button11
show11 = new TGTextButton(hframeStartStop, "Start",11);
show11->SetToolTipText("START");
show11->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframeStartStop->AddFrame(show11, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
show12 = new TGTextButton(hframeStartStop, "Stop",12);
show12->SetToolTipText("STOP");
show12->Connect("Pressed()", "MyMainFrame", this, "ClickResponse()");
hframeStartStop->AddFrame(show12, new TGLayoutHints(kLHintsExpandX , 5, 5, 3, 4));
AddFrame(hframeStartStop, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
} // startstop !=0
//-------------------------------------------------------------------------------
// Set a name to the main frame
SetWindowName("List Box");
MapSubwindows();
// Initialize the layout algorithm via Resize()
// fListBoxOF->Resize(40 ,listbox_vsize );
Resize(GetDefaultSize());
// Map main frame
MapWindow();
fListBox->Select(1);
//=============== Prepare canvas =================
int month;// time_t curtime; struct tm *loctime;
curtime = time (NULL); loctime = localtime (&curtime);
gRandom->SetSeed( 1.1* loctime->tm_sec*loctime->tm_min );
month = int(gRandom->Uniform(22.) );
switch(month){
case 0: MyCan=new TCanvas("A","A - canvas"); break;
case 1: MyCan=new TCanvas("B","B - canvas"); break;
case 2: MyCan=new TCanvas("C","C - canvas"); break;
case 3: MyCan=new TCanvas("D","D - canvas"); break;
case 4: MyCan=new TCanvas("E","E - canvas"); break;
case 5: MyCan=new TCanvas("F","F - canvas"); break;
case 6: MyCan=new TCanvas("G","G - canvas"); break;
case 7: MyCan=new TCanvas("H","H - canvas"); break;
case 8: MyCan=new TCanvas("I","I - canvas"); break;
case 9: MyCan=new TCanvas("J","J - canvas"); break;
case 10: MyCan=new TCanvas("K","K - canvas"); break;
case 11: MyCan=new TCanvas("L","L - canvas"); break;
case 12: MyCan=new TCanvas("M","M - canvas"); break;
case 13: MyCan=new TCanvas("N","N - canvas"); break;
case 14: MyCan=new TCanvas("O","O - canvas"); break;
case 15: MyCan=new TCanvas("P","P - canvas"); break;
case 16: MyCan=new TCanvas("Q","Q - canvas"); break;
case 17: MyCan=new TCanvas("R","R - canvas"); break;
case 18: MyCan=new TCanvas("S","S - canvas"); break;
case 19: MyCan=new TCanvas("T","T - canvas"); break;
case 20: MyCan=new TCanvas("U","U - canvas"); break;
case 21: MyCan=new TCanvas("V","V - canvas"); break;
case 22: MyCan=new TCanvas("W","W - canvas"); break;
case 23: MyCan=new TCanvas("X","X - canvas"); break;
case 24: MyCan=new TCanvas("Y","Y - canvas"); break;
case 25: MyCan=new TCanvas("Z","Z - canvas"); break;
}//switch
MyCan->Draw();
MyCan->Update();
// This is from exec3.C............
GPAD=(TCanvas*)MyCan;
/*
* NAMING ALSO THE CONTROL PANEL
*/
TString sr=GPAD->GetName();
TString sr2="";
sr2.Append( sr.Data() );
sr2.Append( " shspe-ctrl" );
SetWindowName( sr2.Data() ); // CONTROL PANEL?
sr.Append("-shspe-canvas");
GPAD->SetTitle( sr.Data() );
GPAD->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", this ,
"exec3event(Int_t,Int_t,Int_t,TObject*)");
//------------------------------------------------------
// lets first openfile......
RefreshAll();
TString *fentry=new TString( fEntry->GetText() ); // normaly ""
fOpenFile(fentry,fListBox2, atoi(fEntrySIG->GetText()) ); // 1st fopenfile ---<<<<<<<<< read current directory