-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_and_plot.cc
More file actions
executable file
·6028 lines (5352 loc) · 180 KB
/
load_and_plot.cc
File metadata and controls
executable file
·6028 lines (5352 loc) · 180 KB
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
/*-------------------Emacs PostScript "pretty-print" page width (97 columns)-------------------*/
/* Program: load_and_plot.cc (formerly load_psd.cc)
* Created by Jon Lighthall
* Purpose:
* A set of macros for loading and analyzing data from the:
* + 2006-2007 HELIOS PSD characterization tests at WMU
* + August 2008 29Si(d,p) HELIOS commissioning experiment (including simulations)
* + 12B(d,p) experiment
* ...and plots figures for the HELIOS NIM paper and the Lighthall doctoral thesis.
* Requires:
* fit.cc (most)
* psd_analyze.cc (some)
*/
//#include <iomanip>
Bool_t bOrig=0;//Turn on/off settings for 1.91T
Bool_t bw=0;//Turn on/off black and white figures
Bool_t bThesis=1;//Turn on/off changes between thesis and NIM paper
Bool_t roman=1;
Bool_t bModern=1;
Int_t pal=11;
Float_t B0=1.91585;
Bool_t bslope=1;
Bool_t bsimQ=kTRUE;
TFile *_filename0=0;
TFile *_filename1=0;
TFile *_filename2=0;
TFile *_filename3=0;
TFile *_filename4=0;
TFile *_filename5=0;
TFile *_filename6=0;
TFile *_filename7=0;
TFile *_filename8=0;
TFile *_filename9=0;
TFile *_filename10=0;
TFile *_filename11=0;
Int_t reaction=0;
TF1 *f2,*f3;//for plotlabangle()
TF1 *f9,*f10;//for func()
TF1 *f1,*f4,*f5,*f6;//for plotbore()
TF1 *fEDiff1,*fEDiff2,*fXFXN;
Float_t pi=4.0*atan(1.0);
//Float_t e=1.602176487E-19;//NIST value
//Float_t MeV=e*1E6; //J/MeV
UInt_t width=600;
Float_t ratio1=3./4.;
Float_t ratio2=9./16.;
Float_t ratio3=11./8.5;
Float_t minE=0;
Float_t maxE=10;
Float_t plot_minZ=-880;
Float_t plot_maxZ=-80;
TString ytitle="E (MeV)";
TString xtitle="z (mm)";
Float_t ang=18.5;
Float_t ang_fan=66.5;
Float_t zmax=0;
Float_t Or=0;//origin (need to be declared globally)
Float_t aspan=342.4;
Float_t vlines[3]={-129.25,-367.25,-513.6};//"in sort" position of detectors
Float_t bshift[3]={35,25,22};//corrections for B-field
Float_t edges[3][6]={{-436.67,-377.86,-319.1,-260.47,-202.11,-144.75},
{-684.67,-625.86,-567.1,-508.47,-450.11,-392.75},
{-834.02,-775.21,-716.45,-657.82,-599.46,-542.1}};
TString fname;
/* Load data-----------------------
*
*/
//-----------------------------------------------------------------------------------------------
//Macros specific to the 28Si(d,p) experiment:---------------------------------------------------
void loadfiles(Char_t *histin="_cut")
{//the scope of these files is limited to this script, so it isn't useful.
hname="100";
hname+=histin;
hname+=".root";
printf("Input File is %s\n",hname.Data());
_filename0 = new TFile(hname.Data());
hname="350";
hname+=histin;
hname+=".root";
printf("Input File is %s\n",hname.Data());
_filename1 = new TFile(hname.Data());
hname="500";
hname+=histin;
hname+=".root";
printf("Input File is %s\n",hname.Data());
_filename2 = new TFile(hname.Data());
}
void merge(Char_t *histin="hEZg",Bool_t DoRebin=1)
{//merges histograms from three files. Adapted from addpositions.C
// if(!(gROOT->FindObject("home")))
// gROOT->ProcessLine("TDirectory *home=gDirectory");
loadfiles();
_filename0->cd();
hname=histin;
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname+="_100";
if(DoRebin)
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
hInput->Clone(hname.Data());
hOutput=(TH2F *) gROOT->FindObject(hname.Data());
hOutput->SetDirectory(home);
_filename1->cd();
hname=histin;
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname+="_350";
if(DoRebin)
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
hInput->Clone(hname.Data());
hOutput=(TH2F *) gROOT->FindObject(hname.Data());
hOutput->SetDirectory(home);
_filename2->cd();
hname=histin;
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname+="_500";
if(DoRebin)
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
hInput->Clone(hname.Data());
hOutput=(TH2F *) gROOT->FindObject(hname.Data());
hOutput->SetDirectory(home);
home->cd();
hname=histin;
hname+="_100";
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname=histin;
hname+="_all";
hInput->Clone(hname.Data());
hOutput=(TH2F *) gROOT->FindObject(hname.Data());//added
hname=histin;//omitted
add2(hname+"_100",hname+"_350",hname+"_all");
add2(hname+"_500",hname+"_all",hname+"_all");
}
void merge2(Char_t *histin="hEZg")
{//same as merge(), but only combines two files
_filename0->cd();
hname=histin;
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname+="_100";
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
hInput->Clone(hname.Data());
hOutput=(TH2F *) gROOT->FindObject(hname.Data());
hOutput->SetDirectory(home);
_filename2->cd();
hname=histin;
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname+="_500";
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
hInput->Clone(hname.Data());
hOutput=(TH2F *) gROOT->FindObject(hname.Data());
hOutput->SetDirectory(home);
home->cd();
hname=histin;
hname+="_100";
TH2F * hInput=(TH2F *) gROOT->FindObject(hname.Data());
hname=histin;
hname+="_all";
hInput->Clone(hname.Data());
hname=histin;
add2(hname+"_100",hname+"_500",hname+"_all");
}
void test(Int_t dz=12, Int_t pos=2,Char_t *names="_lineB.txt")
{//tests offset parameters (dz) against calculated E vs. z
loadfiles();
switch(pos){
case 0:
_filename0->cd();
TH2F * hInput=(TH2F *) gROOT->FindObject("hEZg");
if((hInput->GetNbinsY())>512)
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
shiftx2("hEZg",dz);
dr("hEZg_shift",vlines[0]-352.4+dz,vlines[0]+10+dz);
cFit->SetLogz();
plotvlines(vlines[0]+dz);
break;
case 1:
_filename1->cd();
TH2F * hInput=(TH2F *) gROOT->FindObject("hEZg");
if((hInput->GetNbinsY())>512)
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
shiftx2("hEZg",dz);
dr("hEZg_shift",vlines[1]-352.4+dz,vlines[1]+10+dz);
cFit->SetLogz();
plotvlines(0,vlines[1]+dz);
plotlabangle(ang_fan);
plotlabangle(ang);
break;
case 2:
_filename2->cd();
TH2F * hInput=(TH2F *) gROOT->FindObject("hEZg");
if((hInput->GetNbinsY())>512)
hInput->Rebin2D(hInput->GetNbinsX()/512,hInput->GetNbinsY()/512);
shiftx2("hEZg",dz);
dr("hEZg_shift",vlines[2]-352.4+dz,vlines[2]+10+dz);
cFit->SetLogz();
plotvlines(0,0,vlines[2]+dz);
break;
default:
printf("Position %d not recognized!\n",pos);
break;
}
plotlines(names,7);
}
//HELIOS-specific plotting utilities
void plotlabangle(Float_t angle=20, Float_t origin=0, Int_t reset=0, Float_t amu=1.007, Int_t q=1, Float_t B=1.91585, Int_t orbits=1)
{
Float_t m=amu*1.661E-27; //Ejectile mass in kg
// printf("Mass is %g kg.\n",m);
Float_t Tcyc=2*pi*m/(q*e*B)*orbits; //Cyclotron period in seconds
// printf("2 pi M is %g.\n",2*pi*m);
// printf("q*B is %g, e = %g, qeB=%g.\n",q*B,e,q*e*B);
printf("Cyclotron period is %.2f ns.\n",Tcyc*pow(10,9));
printf("Angle is %2.1f deg. Origin is %2.2f mm.\n",angle,origin);
if(reset)
if ((TF1 *) gROOT->FindObject("f3")) {
//cFit->cd();
f3->Delete();
printf("Function \"f3\" already exists. Deleting...\n");
}
Or=origin;
Float_t Zoff(Int_t x)
{
return (x-Or);
}
// f3 =new TF1("f3","([0]/2.)*pow((Zoff(x)/1000.)*(1./[1])*(1./cos([2])),2.)*(1/[3])",-1200,1200);
f3 =new TF1("f3","([0]/2.)*pow(((x-[4])/1000.)*(1./[1])*(1./cos([2])),2.)*(1/[3])",-1200,1200);
f3->SetParameter(4,origin);
f3->SetParameter(0,m);
f3->SetParameter(1,Tcyc);//Here "Tcyc" is actually the flight time
f3->SetParameter(2,(angle/180.0)*pi);
f3->SetParameter(3,MeV);
f3->SetLineColor(1);
f3->SetLineStyle(2);
f3->Draw("same");
}
void func(Float_t r0=0.895*2.54/100./2.)
{//prototype function for plotting kinematic curves
Float_t m=1.673E-27; //Ejectile mass in kg
Float_t Tcyc=34.238E-9; //Cyclotron period in seconds
Float_t Vcm=3.176E7; //Center of mass velocity in m/s
Float_t V0=5.697E7; //Ejectile velocity in center of mass in m/s
Int_t min=0,max=0,min2=0,max2=0;
Float_t slopeEcm=m*Vcm/Tcyc/MeV/1000;
f4 =new TF1("f4","acos(((x/(1000*[1]))-[2])/[3])",-1200,1200);//CoM angle over full range
f4->SetParameter(1,Tcyc);
f4->SetParameter(2,Vcm);
f4->SetParameter(3,V0);
for(int i=-1200;i<1200;i++){
if(f4(i)==f4(i)){//tests if function is valid
if(i<min)min=i;
if(i>max)max=i;
}
}
printf("minimum is %d, maximum is %d\n",min,max);
if ((TH2F *) gROOT->FindObject("h2")) {
gROOT->FindObject("h2")->Delete();
printf("Histogram \"h2\" already exists. Deleting old histogram.\n");
}
h2 = new TH2F("h2","Histogram",1000,min,max,100,0.,12);//sets valid range
if(!((TCanvas *) gROOT->FindObject("cFit"))) mkCanvas2();
h2->Draw();
//should just re-define f4 with new range!
f5 = new TF1("f5","f4",min,max);//output is center-of-mass angle in radians; works!
f5->SetLineColor(3);
f5->SetLineStyle(2);
f5->Draw("same");
f6 = new TF1("f6","pi/2+atan(((x/1000)/[1])/([3]*sin(f5)))",min,max);//output is lab angle in radians
f6->SetParameter(1,Tcyc);
f6->SetParameter(3,V0);
f6->SetLineColor(2);
f6->SetLineStyle(2);
f6->Draw("same");
// TF1 *f7 = new TF1("f7","([3]*cos(f5)+[2])*([1]-[0]/([3]*sin(f5)))",min,max);
TF1 *f7 = new TF1("f7","[3]*cos(f5)+[2]",min,max);//works! correctly produces v_para
// TF1 *f7 = new TF1("f7","([1]-[0]/([3]*sin(f5)))",min,max);//works! correctly produces time
printf("ro is %6.4f m\n",r0);
f7->SetParameter(0,r0);
f7->SetParameter(1,Tcyc);
f7->SetParameter(2,Vcm);
f7->SetParameter(3,V0);
TF1 *f8 = new TF1("f8","[3]*sin(f5)",min,max);//calculates V_perp
f8->SetParameter(3,V0);
f9 = new TF1("f9","(1/2)*[0]*(f7*f7+f8*f8)/[4]",min,max);//calculates E, plots z for r0=0
f9->SetParameter(0,m);
f9->SetParameter(4,MeV);
f9->SetLineStyle(2);
f9->Draw("same");
TF1 *f13 = new TF1("f13","[0]*x+[1]",-1200,1200);//defines f9() over larger range
f13->SetParameter(0,slopeEcm);
f13->SetParameter(1,11.676);
f13->SetLineWidth(2);
f13->SetLineStyle(9);
// TF1 *f10 = new TF1("f10","([0]/tan(f6))*1000",min,max);//offset from z
f10 = new TF1("f10","([0]/tan(f6))*1000",min,max);//offset from z. works!
f10->SetParameter(0,r0);
f10->SetLineColor(3);
f10->Draw("same");
Float_t Zoff(Int_t x)
{
return x-f10(x);
//return x-10;
}
Float_t Zpara(Int_t x)
{
return f9(Zoff(x));
}
TF1 *f11 = new TF1("f11","Zpara(x)",min,max);//-834
for(int i=min;i<max;i++){
if(f11(i)==f11(i)){//tests if function is valid
if(i<min2)min2=i;
if(i>max2)max2=i;
}
}
printf("new min is %d, new max is %d\n",min2,max2);
f11 = new TF1("f11","Zpara(x)",min2,max2);
f11->SetLineColor(9);
f11->SetLineStyle(2);
f11->SetLineWidth(1);
f11->Draw("same");
TF1 *f12 = new TF1("f12","Zpara(x)",min2,0);
f12->SetLineColor(2);
f12->SetLineStyle(1);
f12->Draw("same");
}
Float_t func4(Float_t x=0)
{//required for calling f4() at specific X. - moved to outside plotbore()
return(f4(x));
}
void plotbore(Float_t radius=36.4*2.54/100/2,Int_t amu=1.007, Int_t q=1, Float_t B=1.91585)
{//plots energy cut-off for a given bore radius
Float_t m=amu*1.661E-27; //Ejectile mass in kg
Float_t Tcyc=2*pi*m/(q*e*B); //Cyclotron period in seconds
Float_t Vcm=3.180E7; //Center of mass velocity in m/s
Float_t V0=5.701E7; //Ejectile velocity in center of mass in m/s
switch (reaction){
case 1:
//values for d(B11,p) at 81.0 MeV
Vcm=3.185E7; //Center of mass velocity in m/s
V0=4.915E7; //Ejectile velocity in center of mass in m/s
break;
case 2:
//values for d(B12,p) at 75.0 MeV
Vcm=2.972E7; //Center of mass velocity in m/s
V0=4.884E7; //Ejectile velocity in center of mass in m/s
break;
default:
break;
}
Int_t min=0,max=0,min2=0,max2=0;
printf("WARNING: This fuction requires the center-of-mass velocity Vcm and the ejectile velocity v0 to be input mannually in the code! Default calculation is for 28Si(d,p)!\n");
f4 =new TF1("f4","acos(((x/(1000*[1]))-[2])/[3])",-1200,1200);//CoM angle over full range
f4->SetParameter(1,Tcyc);
f4->SetParameter(2,Vcm);
f4->SetParameter(3,V0);
for(int i=-1200;i<1200;i++){
if(gROOT->GetVersionInt()<52400){
if(i==0)printf("Loop 1 - Deprecated ROOT Version.\n");
if(f4==f4){if(i<min)min=i;if(i>max)max=i;}
}
else{
if(i==0)printf("Loop 1 - Modern ROOT Version.\n");
if(func4(i)==func4(i)){if(i<min)min=i;if(i>max)max=i;}
}
}
printf("Center-of-mass angle is defined over %d,%d\n",min,max);
f5 = new TF1("f5","f4",min,max);//output is center-of-mass angle in radians; works!
f5->SetLineColor(3);
f5->SetLineStyle(2);
f6 = new TF1("f6","pi/2+atan(((x/1000)/[1])/([3]*sin(f5)))",min,max);//output is lab angle in radians
f6->SetParameter(1,Tcyc);
f6->SetParameter(3,V0);
f6->SetLineColor(2);
f6->SetLineStyle(2);
printf("Limiting radius is %3.2f m\n",radius);
// Float_t q=1;
//Float_t B=1.91585;
Float_t wc=q*e*B/m;//Cyclotron frequency (radians/sec)
TF1 *f1=new TF1("f1","([0]/2)*pow(([1]/2)*[2]*(1/sin(f6)),2)/[3]",min,max);
//f1=f1(f6(f5(f4))), so range should be the same as f4.
f1->FixParameter(0,m);
f1->FixParameter(1,radius);
f1->FixParameter(2,wc);
f1->FixParameter(3,MeV);
/*
for(int i=-1000;i<1000;i++){
if(gROOT->GetVersionInt()<52400){
if(i==0)printf("Loop 2 - Deprecated ROOT Version.\n");
if(f1==f1){if(i<min2)min2=i;if(i>max2)max2=i;}
} else{
if(i==0)printf("Loop 2 - Modern ROOT Version.\n");
if(f1(i)==f1(i)){if(i<min2)min2=i;if(i>max2)max2=i;}
}
}
printf("For bore function, min is %d, max is %d\n",min2,max2);
f1=new TF1("f1","([0]/2)*pow(([1]/2)*[2]*(1/sin(f6)),2)/[3]",min2,max2);
f1->FixParameter(0,m);
f1->FixParameter(1,radius);
f1->FixParameter(2,wc);
f1->FixParameter(3,MeV);
*/
f1->SetLineStyle(9);
f1->Draw("same");
}
//General plotting utilities
void plotlines(Char_t *names="_line.txt", Int_t lines=6, Int_t linestyle=1)
{//Plots a set of lines from text files. File names sequencally numbererd, starting with 0.
TString fname;
TString lname;
for(Int_t i=0;i<lines;i++){
fname="";
fname+=i;
fname+=names;
lname="g";
lname+=i;
printf("File is %s. Line name is %s: ",fname.Data(),lname.Data());
drawline(fname.Data(),lname.Data(),0,linestyle);
}
}
void tilt(Char_t * histin, Float_t tilt=0.000413, Int_t plot=1)
{//Tilts a 2D histogram by a given angle.
zmax=0;
if(plot>0) if(!((TCanvas *) gROOT->FindObject("cFit"))) mkCanvas2();
Float_t m=1*1.673E-27; //Ejectile mass in kg
Float_t Vcm=3.174E7; //Center of mass velocity in m/s
Float_t Tcyc=34.246E-9; //Cyclotron period in seconds
Float_t slopeEcm=m*Vcm/Tcyc/MeV/1000;
Float_t slope=slopeEcm+tilt;
Float_t xmin,xmax;
Float_t ymin,ymax;
Int_t xbin;
Int_t ybin,entry=0;
Float_t x,y,z;
if(gROOT->FindObject(histin))
TH2F * hInput=(TH2F *) gROOT->FindObject(histin);
else
printf("Histogram \"%s\" not recognized\n",histin);
xbin=hInput->GetXaxis()->GetNbins();
ybin=hInput->GetYaxis()->GetNbins();
xmax=hInput->GetXaxis()->GetXmax();
ymax=hInput->GetYaxis()->GetXmax();
xmin=hInput->GetXaxis()->GetXmin();
ymin=hInput->GetYaxis()->GetXmin();
ymin=floor(ymin-xmax*slope);
ymax=ceil(ymax-xmin*slope);
hname=histin;
hname+="_tilt";
Char_t *htitle = hInput->GetTitle();
if ((TH2F *) gROOT->FindObject(hname)) {
gROOT->FindObject(hname)->Delete();
//printf("Histogram \"%s\" already exists. Deleting old histogram.\n",hname.Data());
}
else
printf("Output histogram is \"%s\"\n",hname.Data());
TH2F * hOutput=new TH2F(hname,htitle,xbin,xmin,xmax,ybin,ymin,ymax);
// printf("Output histogram is constructed as:\n TH2F(\"%s\",\"%s\",%d,%1.0f,%1.0f,%d,%1.0f,%1.0f)\n",hname.Data(),htitle,xbin,xmin,xmax,ybin,ymin,ymax);
hname+="_py";
if ((TH1F *) gROOT->FindObject(hname)) {
gROOT->FindObject(hname)->Delete();
//printf("Histogram \"%s\" already exists. Deleting old histogram.\n",hname.Data());
}
else
printf("Output histogram is \"%s\"\n",hname.Data());
TH1F * hProj=new TH1F(hname,htitle,ybin,ymin,ymax);
for(int i=1;i<(xbin+1);i++){
for(int j=1;j<(ybin+1);j++){
//Note: The 0 bin contains the underflow, so the loop starts at 1;
// and the max_bin+1 contains overflow, so the loop terminates at max_bin+1
x=hInput->GetXaxis()->GetBinCenter(i);
y=hInput->GetYaxis()->GetBinCenter(j);
z=hInput->GetBinContent(i,j);
//printf("i=%2d, j=%2d, z=%2.0f \n",i,j,z);
hProj->Fill(y-slope*x,z);
hOutput->Fill(x,y-slope*x,z);
}
}
for(int j=1;j<(ybin+1);j++){
z=hProj->GetBinContent(j);
if(z>zmax)
zmax=z;//locates largest bin
}
printf("For slope = %.6f MeV/mm, Maximum peak height = %.0f counts.\n",slope,zmax);
//hProj->SetAxisRange(0,40000,"Y");
if(plot==2){
cFit->Clear();
cFit->Divide(1,2);
cFit->cd(1);
hOutput->Draw("col");
cFit->SetLogz();
cFit->cd(2);
}
if(plot==3){
cFit->Clear();
cFit->Divide(1,3);
cFit->cd(1);
hInput->Draw("col");
cFit->cd(2);
hOutput->Draw("col");
cFit->SetLogz();
cFit->cd(3);
}
if(plot>0) hProj->Draw();
/*
Float_t mu=12;
Float_t range=.700;
hProj->Fit("gaus","Q","",mu-range/2,mu+range/2);
Float_t sig=hProj->GetFunction("gaus")->GetParameter(2);
Float_t fw=2*sqrt(2*log(2))*sig;
printf("Sigma = %.3f keV, FWHM = %.3f keV\n",sig/1000,fw/1000);
*/
}
Float_t gettilt(Char_t * histin, Float_t tilt)
{
tilt(histin,tilt);
return zmax;
}
void findtilt(Char_t * histin="hEZg", Int_t steps=1)
{
for(int i=(-1*steps);i<steps;steps++;){
printf("%3d: ",i);
// gettilt(histin,i/10000.);
}
}
//Macros for generating figures the HELIOS NIM paper and Lighthall thesis.--------------
void paperplots()
{
gStyle->SetOptDate(0);
if(bOrig){
B0=1.91585;
printf("Detector positions are: %.2f, %.2f, %.2f\n",vlines[0],vlines[1],vlines[2]);
}
else{
B0=2.0020;
printf("Detector positions are: %.2f, %.2f, %.2f\n",vlines[0]+bshift[0],vlines[1]+bshift[1],vlines[2]+bshift[2]);
}
Bool_t bEx=0;//turn on/off excitation plots
loadfiles("_cut");
Float_t pttext=0.06;
TPaveText *pt;
TText *text;
//1.) Time peaks-----------------------
_filename0->cd();
hET21->ProjectionX();
if(!bOrig){
slopex("hET21_px",1.045,-0.244);//corrects for B=2.00 field
TH1F * hOutput1=(TH1F *) gROOT->FindObject("hET21_px_slope");
}
else
TH1F * hOutput1=(TH1F *) gROOT->FindObject("hET21_px");
hOutput1->SetDirectory(home);
hOutput1->SetAxisRange(0,82,"X");
hOutput1->SetYTitle("Counts per 535 ps");
hOutput1->GetYaxis()->CenterTitle(1);
hOutput1->GetYaxis()->SetTitleOffset(1.23);
hOutput1->SetXTitle("T (ns)");
hOutput1->GetXaxis()->CenterTitle(1);
hOutput1->SetStats(kFALSE);
hOutput1->SetTitle();
mkCanvas2("cTOF","cTOF");
cTOF->SetTopMargin(.02);
cTOF->SetRightMargin(.02);
cTOF->SetCanvasSize(width,(UInt_t)(width*ratio2));
hOutput1->Draw();
pt = new TPaveText(37,12677.06,45,14361.89,"br");
text = pt->AddText("A/q=1, 1 turn");
//text = pt->AddText("A/q=1 2 turns");
pt->SetTextAlign(12);//Middle, Left
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(64,5018.749,72,6754.634,"br");
text = pt->AddText("A/q=2, 1 turn");
text = pt->AddText("A/q=1, 2 turns");
//text = pt->AddText("A/q=2");
//text = pt->AddText("2 turns");
pt->SetTextAlign(20);//Middle, Middle
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
cTOF->SaveAs("cTOF_21_100.eps");
merge("hEZg");
cFit->Close();
home->cd();
/*
//2.) Energy vs. Position (all)--------
TH2F * hOutput2=(TH2F *) gROOT->FindObject("hEZg_all");
hOutput2->SetAxisRange(plot_minZ,plot_maxZ,"X");
hOutput2->SetAxisRange(minE,maxE,"Y");
hOutput2->SetYTitle(ytitle);
hOutput2->GetYaxis()->CenterTitle(1);
hOutput2->SetXTitle(xtitle);
hOutput2->GetXaxis()->CenterTitle(1);
hOutput2->SetStats(kFALSE);
hOutput2->SetTitle();
hOutput2->SetMinimum(8);
mkCanvas2("cComp","cComp");
cComp->SetTopMargin(.02);
cComp->SetRightMargin(.03);
cComp->SetCanvasSize(width,(UInt_t)(width*ratio1));
cComp->SetLogz();
hOutput2->Draw("col");
plotlabangle(ang,0);
plotbore();
//drawline("gs_line.txt","gs",0);
//gs->SetLineWidth(1);
//gs->SetLineStyle(1);
//gs->SetLineColor(1);
// gs->Draw();
plotvlines(vlines[0],vlines[1],vlines[2]);
cComp->SaveAs("cEZg_all.eps");
*/
//4.)Alternate e vs. z-------------------
home->cd();
if(bOrig){
shiftx2("hEZg_100",8);
shiftx2("hEZg_350",0);
shiftx2("hEZg_500",0);
}
else{
shiftx2("hEZg_100",bshift[0]);
shiftx2("hEZg_350",bshift[1]);
shiftx2("hEZg_500",bshift[2]);
}
add2("hEZg_100_shift","hEZg_500_shift","hEZg_shift");
add2("hEZg_100_shift","hEZg_350_shift","hEZg_ang");
add2("hEZg_350_shift","hEZg_shift","hEZg_shift");
cFit->Close();
TH2F * hOutput4=(TH2F *) gROOT->FindObject("hEZg_shift");
hOutput4->SetAxisRange(plot_minZ,plot_maxZ,"X");
hOutput4->SetAxisRange(minE,maxE,"Y");
hOutput4->SetYTitle(ytitle);
hOutput4->GetYaxis()->CenterTitle(1);
hOutput4->SetXTitle(xtitle);
hOutput4->GetXaxis()->CenterTitle(1);
hOutput4->SetStats(kFALSE);
hOutput4->SetTitle();
hOutput4->SetMinimum(8);
mkCanvas2("cShift","cShift");
cShift->SetTopMargin(.02);
cShift->SetRightMargin(.03);
cShift->SetCanvasSize(width,(UInt_t)(width*ratio1));
cShift->SetLogz();
if(bw){gStyle->SetPalette(pal);hOutput4->SetMaximum(-1111);}
// hOutput4->Rebin2D(hOutput4->GetNbinsX()/512,hOutput4->GetNbinsY()/512);
hOutput4->Draw("col");
if(bOrig){
plotlabangle(ang,0,1.007,1,B0);//ang=18.5,B=1.91
plotbore();
plotvlines(vlines[0]+8,vlines[1],vlines[2],!bOrig);
if(bslope)
plotlines("_line.txt",7,7);
}
else{
plotlabangle(ang,0,0,1.007,1,B0);
plotbore(.462,1.007,1,B0);
plotvlines(vlines[0]+bshift[0],vlines[1]+bshift[1],vlines[2]+bshift[2],1);
if(bslope)
plotlines("_lineB.txt",7,7);
}
if(bThesis){
pt = new TPaveText(-784,3,-784,3,"br");
text = pt->AddText("A");
pt->SetTextAlign(22);//Middle, Middle
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
}
if(bw)
cShift->SaveAs("cShift_bw.eps");
else
cShift->SaveAs("cShift.eps");
if(bEx){
//3.) Excitation energy(at one position)--------------------
_filename0->cd();
TH2F * hInput3=(TH2F *) gROOT->FindObject("hQTheta");
hInput3->ProjectionY();
bkgfit2("hQTheta_py");
slopex("hQTheta_py_out",1,-0.141015);
dump("hQTheta_py_out_slope","hEx_one_position.dat");
cFit->Close();
TH1F * hOutput3=(TH1F *) gROOT->FindObject("hQTheta_py_out_slope");
hOutput3->SetDirectory(home);
hOutput3->SetAxisRange(-1,10,"X");
hOutput3->SetXTitle("Excitation Energy (MeV)");
hOutput3->GetXaxis()->CenterTitle(1);
hOutput3->SetYTitle("Counts");
hOutput3->GetYaxis()->CenterTitle(1);
hOutput3->GetYaxis()->SetTitleOffset(1.25);
hOutput3->SetStats(kFALSE);
hOutput3->SetTitle();
mkCanvas2("cQy","cQy");
cQy->SetTopMargin(.02);
cQy->SetRightMargin(.02);
cQy->SetCanvasSize(width,(UInt_t)(width*ratio2));
hOutput3->Draw();
cQy->SaveAs("cExcite_100.eps");
}
//5.) Individual position E vs. Z-------
home->cd();
if(bOrig){
TH2F * hOutput5=(TH2F *) gROOT->FindObject("hEZg_350");
hOutput5->SetAxisRange(vlines[1]-352.4,vlines[1]+10,"X");
}
else{
shiftx2("hEZg_350",bshift[1],0);
TH2F * hOutput5=(TH2F *) gROOT->FindObject("hEZg_350_shift");
hOutput5->SetAxisRange(vlines[1]-352.4+bshift[1],vlines[1]+12+bshift[1],"X");
}
hOutput5->SetAxisRange(minE,maxE,"Y");
hOutput5->SetYTitle(ytitle);
hOutput5->GetYaxis()->CenterTitle(1);
hOutput5->SetXTitle(xtitle);
hOutput5->GetXaxis()->CenterTitle(1);
hOutput5->SetStats(kFALSE);
hOutput5->SetTitle();
hOutput5->SetMinimum(8);
mkCanvas2("cIndiv","cIndiv");
cIndiv->SetTopMargin(.02);
if(bOrig)
cIndiv->SetRightMargin(.2);
else
cIndiv->SetRightMargin(.03);
cIndiv->SetCanvasSize(width,(UInt_t)(width*ratio1));
cIndiv->SetLogz();
if(bw){gStyle->SetPalette(pal);hOutput5->SetMaximum(-1111);}
hOutput5->Draw("col");
if(bOrig){
plotvlines(0,vlines[1]);
plotlabangle(ang,0,0,1.007,1,B0);
plotlines("_line.txt",6,1);
plotlabangle(ang_fan);
}
else{
plotvlines(0,vlines[1]+bshift[1],0,0);
plotlabangle(ang,0,0,1.007,1,B0);
plotlines("_lineB.txt",6,7);
plotlabangle(ang_fan,0,0,1.007,1,B0);
}
if(!bOrig){
// f3->SetLineStyle(9);//set line style to match plotlabangle (upper bound)
f3->Draw("same");
Float_t left=vlines[1]+bshift[1]+1.5;
Float_t right=left+7.5;
pt = new TPaveText(left,7.8,right,8.6,"br");
text = pt->AddText("a");
pt->SetTextAlign(12);//Middle, Left
pt->SetFillColor(0);
// pt->SetFillStyle(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(left,6.6,right,7.4,"br");
text = pt->AddText("b");
pt->SetTextAlign(12);//Middle, Left
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(left,5.9,right,6.7,"br");
text = pt->AddText("c");
pt->SetTextAlign(12);//Middle, Left
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(left,4.9,right,5.7,"br");
text = pt->AddText("d");
pt->SetTextAlign(12);//Middle, Left
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(left,4.3,right,5.0,"br");
text = pt->AddText("e");
pt->SetTextAlign(12);//Middle, Left
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(left,3.0,right,3.8,"br");
text = pt->AddText("f");
pt->SetTextAlign(22);//Middle, Middle
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-525,8.8,-525,9.8,"br");
text = pt->AddText("B");
pt->SetTextAlign(22);//Middle, Middle
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-625,1.5,-625,1.5,"br");
text = pt->AddText("A");
pt->SetTextAlign(22);//Middle, Middle
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
}
else{
pt = new TPaveText(-345,7.8,-314,8.6,"br");
text = pt->AddText("g.s.");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-350.8,6.6,-253,7.4,"br");
text = pt->AddText("1.27 MeV");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-350.8,5.9,-253,6.7,"br");
text = pt->AddText("2.03 MeV");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-350.8,4.9,-253,5.7,"br");
text = pt->AddText("3.07 MeV");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-350.8,4.3,-253,5.0,"br");
text = pt->AddText("3.62 MeV");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-350.8,3.0,-253,3.8,"br");
text = pt->AddText("4.90 MeV");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-565.9,8.8,-517.2,9.8,"br");
text = pt->AddText("#theta_{lab}=66^{#circ}");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
pt = new TPaveText(-700.7022,0.8087121,-614.6112,1.667969,"br");
text = pt->AddText("#theta_{lab}=18^{#circ}");
pt->SetFillColor(0);
if(bModern)pt->SetShadowColor(0);
pt->SetLineColor(0);
pt->SetTextSize(pttext);
pt->Draw();
}
if(bw)
cIndiv->SaveAs("cEZg_350_bw.eps");
else
cIndiv->SaveAs("cEZg_350.eps");
//6. double orbit ---------------------
_filename3=new TFile("500_new.root");
hEZg2->Clone();
hEZg2->SetDirectory(home);
home->cd();
if(bOrig){
TH2F * hOutput6=(TH2F *) gROOT->FindObject("hEZg2");
hOutput6->SetAxisRange(vlines[2]-352.4,vlines[2]+10,"X");
}
else{
shiftx2("hEZg2",bshift[2],0);
TH2F * hOutput6=(TH2F *) gROOT->FindObject("hEZg2_shift");
hOutput6->SetAxisRange(vlines[2]-352.4+bshift[2],vlines[2]+10+bshift[2],"X");
}
hOutput6->Rebin2D(hOutput6->GetNbinsX()/512,hOutput6->GetNbinsY()/512);
hOutput6->SetAxisRange(minE,maxE,"Y");
hOutput6->SetYTitle(ytitle);
hOutput6->GetYaxis()->CenterTitle(1);
hOutput6->SetXTitle(xtitle);
hOutput6->GetXaxis()->CenterTitle(1);
hOutput6->SetStats(kFALSE);
hOutput6->SetTitle();
if(bOrig){
hOutput6->SetMinimum(8);
hOutput6->SetMaximum(50);
}
else
{
}
mkCanvas2("cDouble","cDouble");
cDouble->SetTopMargin(.02);
cDouble->SetRightMargin(.03);
cDouble->SetCanvasSize(width,(UInt_t)(width*ratio1));
cDouble->SetLogz();
if(bw){gStyle->SetPalette(pal);hOutput6->SetMaximum(-1111);}
hOutput6->Draw("col");