-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathAnalysis_Profile.C
2381 lines (1877 loc) · 82.1 KB
/
Analysis_Profile.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 : Piotr Konczykowski
//*-- Date: 10/2015
//*-- Last Update: 16/05/16
//*-- Copyright: GENP (Univ. Santiago de Compostela)
//
// This macro use the information from the pads (digitization files)
// to make the energy deposit profile along the tracks (Bragg Peak)
// and the transverse diffusion profile. The method used to make the
// profiles is WeightedPadProjection where the pads are cut into
// slices and the energy deposit aken is proportional to the slice
// surface
//
// --------------------------------------------------------------
// How to run this program:
// 1 - Run the simulation
// 2 - Run the digitization
// 3 - Run this macro inside root
// .L Analysis_Profile.C;
// Run()
// --------------------------------------------------------------
//
// UPDATES :
// - The profile bining can be either fixed or scaled to the pad
// size using the command PadBin
//
//
/////////////////////////////////////////////////////////////////
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include "TBrowser.h"
#include "TH2.h"
#include "TRandom.h"
#include <TCanvas.h>
#include <iostream>
#include "TSpline.h"
#include "TVector3.h"
#include "MTrack.h"
using namespace std;
#if defined(__MAKECINT__)
#pragma link C++ class MTrack;
#endif
TSpline3* simbragRGlobal;
Double_t multiGlobal,RShiftGlobal;
const Int_t NBinsGlobal=150;
//float ProjCPUTime=0;
void Run()
{
///FLAGS///
//Event by event
Bool_t Track3DVisuFlag=0;
Bool_t TrackVisuFlag=1;
Bool_t TrackSourcePosFlag=0;
Bool_t TrackAngleFlag=0;
Bool_t TrackBragFlag=1;
Bool_t TrackRangeFlag=0;
Bool_t MultiThetaFlag=0;
Bool_t TimerFlag=1;
Bool_t AlphaBraggFitFlag=0;
Bool_t TrackAnalysis=1;
Bool_t CumulTracks=1;
Bool_t EnergyFlag=0;
Bool_t RangeFlag=0;
Bool_t ChiFlag=0;
gSystem->Load("libactar.sl");
Bool_t simuFlag;
Bool_t gasflag;
Char_t *simname;
Char_t *digname;
Char_t *gasname;
if(TimerFlag){
TStopwatch timer;
printf("Starting timer\n");
timer.Start();
}
Double_t sigma_time=3;//ns
Int_t beamOn=1;//1: no beam, 2:with beam
Int_t Run=2;//(0 : 204 mbar, 1 : 144.6 mbar, 2 : 100 mbar)
Double_t StopPoint=2.;//Stopping point will be MaxValue/StopPoint
//cout << "Reading Simulation (1) or real datas (0)? ";
//cin >> simuFlag;
simuFlag=1;
Int_t NSlices=10;
Int_t NProf=200;
Int_t NBPeaks=0;
Double_t LastPointRef=230;
Double_t LongChisq[1500];
Double_t LongChisqRange[1500];
Int_t NChisq=0;
const Double_t BraggNBin=NBinsGlobal;
//const Double_t BraggNBin=300.;
const Double_t BraggBinSize=300./BraggNBin;
//const Double_t BraggBinSize=300/(Double_t)NBinsGlobal;
//const Double_t BraggBinSize=2.;
//cout<<"BraggNBin "<<BraggNBin<<" BraggBinSize "<<BraggBinSize<<endl;
for(Int_t i=0;i<1500;i++){
LongChisq[i]=LongChisqRange[i]=0.;
}
//cout<<"digFile to use: ";
//cin >> digname;
//digname="./root_files/dig_files/digFile.root";
//digname="./root_files/dig_files/digFile_alpha7MeV.root";
//digname="./root_files/dig_files/digFile_alpha7MeV_y0.3down.root";
//digname="./root_files/dig_files/digFile_alpha7MeV_x0.1y0.3.root";
//digname="./root_files/dig_files/digFile_alpha7MeV_iC4H10_204mb.root";
//digname="./root_files/dig_files/digFile_alpha7MeV_iC4H10_144mb.root";
//digname="root_files/dig_files/digFile_alpha5MeV_iC4H10_105mbar_z1_em3.root";
//digname="root_files/dig_files/digFile_alpha7MeV_iC4H10_105mbar_z1_em3.root";
//digname="root_files/dig_files/digFile_12C_30MeV_iC4H10_105mbar_z1.root";
if(Run==0)digname="./root_files/dig_files/digFile_alpha7MeV_iC4H10_204mb_em3.root";
//if(Run==1)digname="./root_files/dig_files/digFile_alpha7MeV_iC4H10_144mb_em3.root";
if(Run==1)digname="./root_files/dig_files/digFile_alpha7MeV_iC4H10_144mbar_z1_em3.root";
//if(Run==2)digname="./root_files/dig_files/digFile.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_100mbar_VA-15_z100_D21.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_100mbar_VA15_z100_D21.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_100mbar_VA0_z100_D21.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_100mbar_VA-20to20_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA-20to20_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA-15_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA15_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA0_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA0_z100_D21.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA0_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA-15_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA15_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA-20to20_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA-20to20_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_5MeV_iC4H10_105mbar_VA0_z100_D19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-15_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-15_z100_D21.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_100mbar_VA-20to20_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_D20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_D18_75.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_D18.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_D16.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_7MeV_iC4H10_105mbar_VA-10to10_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10to10_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_D19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10_z100_D19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10to10_z100_D19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-20to20_z100_D19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_run974.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-4_z100_Radius2mm.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_2.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10_z100_Radius2mm.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt16.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt17.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10_z100_Radius2mm_Dt19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt19.5.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt19.5.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10_z100_Radius2mm_Dt19.5.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt20.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10to10_z100_D20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt20.7.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt20.7.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10_z100_Radius2mm_Dt20.7.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt21.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt21.5.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA-10_z100_Radius2mm_Dt21.5.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt22.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt22.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA0_z100_Radius2mm_Dt23.root";
//if(Run==2)digname="./root_files/dig_files/digFile_3alpha_iC4H10_105mbar_VA10_z100_Radius2mm_Dt23.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5_8MeV_iC4H10_105mbar_VA0_z100.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-10+-1.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA0+-1_Dt20.7.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-10+-1_Dt20.7.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA10+-1_Dt20.7.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA0+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA2+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA4+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA6+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA8+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA10+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-2+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-4+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-6+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-8+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-10+-1_Dt20.62.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA0+-1_Dt20.62_em4.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA0+-1_Dt20.62_ionGasModel.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA0+-1_Dt20.62_W23.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_VA-10+-1_Dt19.root";
//if(Run==2)digname="./root_files/dig_files/digFile_alpha_5.8MeV_100mbar_VA0+-1.root";
if(Run==2)digname="./root_files/dig_files/digFile_gasBox105x85x105_alpha_5.8MeV_VA0_piotrdigit.root";
//if(Run==2)digname="./root_files/dig_files/digFile_gasBox105x85x105_alpha_5.8MeV_VA0_centerdigit.root";
gROOT->ProcessLine(".L digit.h+");
//gROOT->ProcessLine(".L digit_hapol.h+");
Double_t Wvalue=30;
if(Run==0)Double_t driftVelocity=19.94E-3;//p=204mbar
if(Run==1)Double_t driftVelocity=28.63E-3;//p=144mbar
if(Run==2)Double_t driftVelocity=36.43E-3;//p=105mbar
//if(Run==2)Double_t driftVelocity=37.97E-3;//p=100mbar
//if(Run==2)Double_t driftVelocity=36.8E-3;//p=105mbar
//Double_t driftVelocity=6.865e-3;
//Double_t driftVelocity=42.26e-3;
//Double_t driftVelocity=31.03e-3;
//Double_t driftVelocity=37.97e-3;//p=100mbar
//Double_t driftVelocity=36.8e-3;//p=105mbar
//Double_t driftVelocity=19.94e-3;//p=204mbar
//Double_t driftVelocity=28.63e-3;//p=144mbar
TFile *digFile=new TFile(digname);
cout<<"Opening digitization file: "<<digname<<endl;
TTree *digiTree=(TTree*)digFile->Get("digiTree");
Int_t dentries=digiTree->GetEntries();
if(CumulTracks)dentries=NProf;
cout<<"Number of digit event : "<<dentries<<endl;
//Int_t digentries=digiTree->GetEntries();
//cout<<"Number of digit event : "<<digentries<<endl;
//ClonesArray to the signal
TClonesArray *padSignalCA=new TClonesArray("ActarPadSignal",4000);
digiTree->SetBranchAddress("padSignals",&padSignalCA);
ActarPadSignal *padSignal=new ActarPadSignal;
//const Int_t numberOfRows=32;
//const Int_t numberOfRows=64;
const Int_t numberOfRows=100;
//const Int_t numberOfColumns=64;
const Int_t numberOfColumns=100;
//const Int_t numberOfColumns=128;
//const Int_t numberOfColumns=133;
cout<<"Number of Rows "<<numberOfRows<<" Number of Columns "<<numberOfColumns<<endl;
Double_t PI=3.1415926535897932384626433;
Double_t deg=180./PI;
Double_t rad=PI/180.;
//==================================================================================//
//Canvas
if(Track3DVisuFlag){
Can_3D=new TCanvas("Can_3D","Can_3D",900,900);
}
if(TrackVisuFlag){
//Can_sil=new TCanvas("Can_sil","Can_sil",900,900);
Can_track=new TCanvas("Can_track","Can_track",900,900);
//Can_track->Divide(1,2);
//Can_track->cd(2)->Divide(2,1);
}
if(TrackSourcePosFlag){
Can_source=new TCanvas("Can_source","Can_source",900,900);
Can_source->Divide(2,2);
}
if(TrackAngleFlag){
Can_angle=new TCanvas("Can_angle","Can_angle",900,900);
Can_angle->Divide(2,1);
}
if(TrackBragFlag){
//Can_brag=new TCanvas("Can_brag","Can_brag",1800,900);
//Can_brag0=new TCanvas("Can_brag0","Can_brag0",900,600);
Can_brag=new TCanvas("Can_brag","Can_brag",900,600);
Can_brag->Divide(1,2);
}
if(TrackRangeFlag){
Can_range=new TCanvas("Can_range","Can_range",1800,900);
Can_range->Divide(1,2);
}
if(MultiThetaFlag){
TCanvas *Can_multi;
Can_multi=new TCanvas("Can_multi","Can_multi",900,900);
Can_multi->Divide(5,2);
}
///////////////////////////////////////////////////////
////////// READING ALPHA DEDX ACTARSIM FILE ///////////
///////////////////////////////////////////////////////
if(Run==0)const Int_t ActarBin=111;
if(Run==1)const Int_t ActarBin=153;
//if(Run==2)const Int_t ActarBin=213;
if(Run==2)const Int_t ActarBin=250;
if(Run==2)const Int_t ActarLatBin=150;
TGraph *hActarSimAlphadEvsR_FP=new TGraph(ActarBin);
TGraph *hActarSimAlphadEvsR2=new TGraph(ActarBin);
TGraph *gActarSimAlphadEvsR=new TGraph(ActarBin);
TGraph *gActarSimAlphaLatR=new TGraph(ActarLatBin);
TH1F *hActarSimAlphaLatR = new TH1F("hActarSimAlphaLatR","ActarSim Track Lateral Range",200, 0.,400.);
//TGraph *gActarSimAlphaLatR=new TGraph(ActarLatBin);
TH1F *hActarSimdEvsR = new TH1F("hActarSimdEvsR","ActarSim Track Bragg",400, 0.,400.);
TH2F *hActarSimAlphadEvsR = new TH2F("hActarSimAlphadEvsR","Alpha dE/dx vs Range in HeiC4H10 (ActarSim)",5000,0.,150.,5000,0.,150.);
Double_t alphaE,dE_elec,dE_nucl,Range,LongStrag,LatStrag;
Double_t LatRange;
string unit_E,unit_R,LonSunit,LatSunit;
Double_t Conv,ConvR;
Double_t ActarPreEndPointdE=0.;
Double_t ActarPreEndPoint=0.;
Double_t ActarEndPoint=0.;
//Double_t ActarSimRange=0.;
Double_t ActarSimdEMax=0.;
Double_t ActarSimdEMaxPos=0.;
Double_t ActarSimdEMaxPosBin=0.;
Double_t ActarSimdE[ActarBin],ActarSimrange[ActarBin];
Int_t ActarEndBin=0;
string ActarSimline;
//ifstream myfile ("alphadEvsR_ActarSim.txt");//L111
Char_t *simname;
Char_t *simlatname;
if(Run==0)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_7MeV_iC4H10_204mbar_ActarSim_VAngle0_HAngle0_em3.txt";//L113
if(Run==1)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_7MeV_iC4H10_144mbar_ActarSim_VAngle0_HAngle0_em3.txt";//L153
//if(Run==2)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_7MeV_iC4H10_105mbar_ActarSim_VAngle0_HAngle0_em3.txt";//L213
//if(Run==2)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_7MeV_iC4H10_100mbar_ActarSim_fixendadded.txt";//L233
//if(Run==2)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_7MeV_iC4H10_100mbar_ActarSim_fixendadded2.txt";//L233
//if(Run==2)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_5_5MeV_iC4H10_ActarSim_VA0_thr3_8_z100_D21_hapol.txt";//L250
//if(Run==2)simname="/home/piotr/workplace/analysis_macros/Profiles/alphaLongProfile/alphadEvsR_3alpha_iC4H10_105mbar_ActarSim_VA-10to10_thr3_4_z100_D19_good.txt";//L250
if(Run==2)simname="/home/piotr/workplace/analysis_macros/Profiles/NewProjAlphaLongProfile/alphadEvsR_3alpha_iC4H10_105mbar_ActarSim_VA0_thr3_4_z100_D19.txt";//L250
ifstream myfile (simname);
cout<<"Opening simulation file: "<<simname<<endl;
if (myfile.is_open())
{
for(int k=0;k<ActarBin;k++)
{
getline (myfile,ActarSimline);
stringstream ss(ActarSimline);
ss >> Range >> dE_elec;
if(dE_elec>ActarSimdEMax){ActarSimdEMax=dE_elec; ActarSimdEMaxPos=Range; ActarSimdEMaxPosBin=k;}
ActarSimdE[k]=dE_elec;
ActarSimrange[k]=Range;
hActarSimdEvsR->Fill(Range,dE_elec);
gActarSimAlphadEvsR->SetPoint(k,Range,dE_elec);
if(k>100 && dE_elec>1e-8)ActarEndBin=k;
}
myfile.close();
}
else cout << "Unable to open file";
ActarPreEndPointdE=ActarSimdE[ActarEndBin-2];
ActarPreEndPoint=ActarSimrange[ActarEndBin-2];
ActarEndPoint=ActarSimrange[ActarEndBin-1];
simbragRGlobal=new TSpline3(hActarSimdEvsR);
////////// READING LATERAL RANGE /////////////
//if(Run==2)simlatname="/home/piotr/workplace/analysis_macros/Profiles/alphaLatRvsR_7MeV_iC4H10_100mbar_ActarSim.txt";//L235
//if(Run==2)simlatname="/home/piotr/workplace/analysis_macros/Profiles/alphaLatProfile/alphaLatRvsR_5_5MeV_iC4H10_ActarSim_VA0_thr3_8_z100_D21_hapol.txt";//L250
//if(Run==2)simlatname="/home/piotr/workplace/analysis_macros/Profiles/alphaLatProfile/alphaLatRvsR_3alpha_iC4H10_105mbar_ActarSim_VA0_thr3_4_z100_D19_good.txt";//L250
//if(Run==2)simlatname="/home/piotr/workplace/analysis_macros/Profiles/NewProjAlphaLatProfile/alphaLatRvsR_3alpha_iC4H10_105mbar_ActarSim_VA0_thr3_4_z100_D19.txt";//L250
if(Run==2)simlatname="/home/piotr/workplace/analysis_macros/Profiles/LatProf/alphaLatRvsR_run974_VA-10_alpha_5.8MeV_PadBin_NoTeeth.txt";//L150
ifstream mylatfile (simlatname);
cout<<"Opening simulation lateral file: "<<simlatname<<endl;
if (mylatfile.is_open())
{
for(int k=0;k<ActarLatBin;k++)
{
getline (mylatfile,ActarSimline);
stringstream ss(ActarSimline);
ss >> Range >> LatRange;
//ActarSimLatR[k]=LatRange;
//ActarSimrange[k]=Range;
hActarSimAlphaLatR->Fill(Range+33,LatRange);
//hActarSimAlphaLatR->SetPoint(k,Range,LatRange);
}
mylatfile.close();
}
else cout << "Unable to open file";
//cout<<"ActarSim dEMax "<<ActarSimdEMax<<" dEMaxPos "<<ActarSimdEMaxPos<<endl;
//////////////////////////////////////////////////////////////
////////// END OF READING ALPHA DEDX ACTARSIM FILE ///////////
//////////////////////////////////////////////////////////////
///////////////////////////////////////////////
MTrack* Track=new MTrack();
Double_t Qtot;
TSpline3 *bragR;
TSpline3 *bragR1;
TSpline3 *bragR2;
Double_t maxZ=170.;
if(simuFlag==0)maxZ=600.;
//Double_t threshold = 1000;
//Double_t thresholdeV = threshold*30/1e9;
Double_t threshold = 0;
//Double_t threshold = 0.008;
//Double_t threshold = 0.0045;
//Double_t threshold = 0.005;
//Double_t threshold = 0.0034;
//Double_t thresholdADC = threshold*1e9/30;
Double_t thresholdADC = threshold*1e9/Wvalue;
cout<<"threshold "<<threshold<<endl;
Double_t Tthreshold = 1.;
Double_t outThresh=10000.;
//if(simuFlag==0)threshold = 200.; outThresh=1000.;
if(simuFlag==0)threshold = 0.; outThresh=1000.;
Bool_t PadBin=1;
Bool_t RowTeeth,RowHoles;
Int_t NTeeth[numberOfRows],NRHoles[numberOfRows],NC0,NCHit;
Int_t NBlock;
Bool_t MultiBlock,BCHit[numberOfRows];
Int_t CandidateTrack;
Bool_t Candidate;
Double_t range,range2,rangeX,rangeY;
Double_t Rm,Cm,Zcor,Zm;
Bool_t out_track;
Double_t PadToSilX=51.8;
Double_t PadToSilY=58.8;
Int_t Rmin=0;
Int_t Rmax=numberOfRows-1;
Int_t Cmin=0;
Int_t Cmax=numberOfColumns-1;
Double_t a,b;
Double_t RangeA[2],RangeB[2],RangeO,RangeOS;
Double_t IniPoint[2],FinPoint[2],IniFitPoint[2],FinFitPoint[2];
Double_t Start[3],Stop[3];
Double_t TStart[3],TStop[3];
Double_t PointA[3][2],PointB[3][2];
Double_t gdEdx[NBinsGlobal];
Double_t gLatRange[NBinsGlobal];
Double_t gRange[NBinsGlobal];
Double_t phi;
Double_t theta;
Double_t VAngle;
Double_t HAngle;
Double_t Angle3D;
Double_t xmaxval,xmax;
Double_t ymaxval,ymax;
Double_t zmaxval,zmax;
Double_t range_calcX;
Double_t range_calcZ;
Double_t range_calcY;
Double_t trackX,trackZ,trackY,trackZ2;
Double_t trackPadX,trackPadZ,trackPadY;
Double_t track_range,track_rangeXY,track_rangePadXY;
//3 alphas source position inside Actar
Double_t SourceX=64;
//Double_t SourceY=-43.;
Double_t SourceY=-37.43;
Int_t binshift;
Double_t RangeShift;
//Matrix for the charge map
Double_t **padCharge=new Double_t*[numberOfRows];
Double_t **padTime=new Double_t*[numberOfRows];
Double_t **padHeight=new Double_t*[numberOfRows];
for(Int_t j=0;j<numberOfRows;j++){
padCharge[j]=new Double_t[numberOfColumns];
padTime[j]=new Double_t[numberOfColumns];
padHeight[j]=new Double_t[numberOfColumns];
}
TMatrixD *padChargeTest;
TMatrixD *padTimeTest;
Double_t PadESig;
//create histograms
if(simuFlag==1){
TH2F *visu_chargeYZ=new TH2F("visu_chargeYZ","visu_chargeYZ",32,0,32,85,0,85);
TH3F *h3DTrack=new TH3F("h3DTrack","h3DTrack",64,0,64,32,0,32,85,0,85);
}
else{
TH2F *visu_chargeYZ=new TH2F("visu_chargeYZ","visu_chargeYZ",32,0,32,300,0.,300.);
TH3F *h3DTrack=new TH3F("h3DTrack","h3DTrack",64,0,64,32,0,32,300,0.,300.);
}
TH1F *h_DeltaTime=new TH1F("h_DeltaTime","Pad_Tmax - PadTmin",512,0.,512.);
TH1F *h_DeltaHeight=new TH1F("h_DeltaHeight","#Delta t * Vdrift (mm)",500,0.,500.);
TH1F *h_energy_track=new TH1F("Energy_track","Total Charge Deposited on Pads from track",500, 3.5, 7.);
////Bragg stuff////
TGraph *gLongBragg=new TGraph(NBinsGlobal);
TGraph *gLatBragg=new TGraph(NBinsGlobal);
TH1F *h_range=new TH1F("Range in mm","Range in mm",600,0.,300.);
TH1F *h_bragg=new TH1F("TrackBragg","Track Bragg",BraggNBin, 0., 300.);
TH1F *h_braggcumul=new TH1F("TrackBraggCumul","Track Bragg fixed last point and added",BraggNBin, 0., 300.);
TH1F *h_braggcumuladd=new TH1F("TrackBraggAll","Track Bragg added",BraggNBin, 0., 300.);
TH1F *h_braggcumulnorm=new TH1F("TrackBraggCumulNorm","Track Bragg fixed last point and added",BraggNBin, 0., 300.);
TH1F *h_braggres=new TH1F("TrackBraggRes","Track Bragg Fit Residual",BraggNBin, 0., 300.);
TH1F *h_latspread=new TH1F("TrackLatSpread","Track Lateral Spread",BraggNBin, 0., 300.);
TH1F *h_latspreadres=new TH1F("TrackLatSpreadRes","Track Lateral Spread Residual",BraggNBin, 0., 300.);
TH1F *h_latcumul=new TH1F("TrackLatCumul","Track Lateral Spread fixed last point and added",BraggNBin, 0., 300.);
TH1F *h_latcumulnorm=new TH1F("TrackLatCumulNorm","Track Lateral Spread fixed last point and added",BraggNBin, 0., 300.);
TH1F *h_braggcumulbin[BraggNBin];
TH1F *h_latbraggcumulbin[BraggNBin];
//TH2F *hchi2vsvangle=new TH2F("hchi2vsvangle","Longitudinal #chi^{2} vs Vertical Angle",400,-30.,30.,200,0.,0.0001);
TH2F *hchi2vsvangle=new TH2F("hchi2vsvangle","Longitudinal #chi^{2} vs Vertical Angle",400,-30.,30.,500,0.,0.03);
TH2F *hlatchi2vsvangle=new TH2F("hlatchi2vsvangle","Transverse #chi^{2} vs Vertical Angle",400,-30.,30.,200,0.,1);
for(int l=0;l<BraggNBin;l++)
{
char title[256];
sprintf(title,"Longitudinal Range bin %d",l);
h_braggcumulbin[l]=new TH1F(title,title,100, 0.,10000.);
char lattitle[256];
sprintf(lattitle,"Lateral Range bin %d",l);
h_latbraggcumulbin[l]=new TH1F(lattitle,lattitle,100, 0.,100.);
}
TH1F *h_energy=new TH1F("Energy","Total Charge Deposited",1000, 3000., 5000.);
TH2F* visu_multiplicity=new TH2F("visu_multiplicity","visu_multiplicity",numberOfColumns,0,numberOfColumns,numberOfRows,0,numberOfRows);
TH2F* visu_totcharge=new TH2F("visu_totcharge","visu_totcharge",numberOfColumns,0,numberOfColumns,numberOfRows,0,numberOfRows);
//TH2F *visu_charge=new TH2F("visu_charge","visu_charge",128,0,128,64,0,64);
//TH2F *visu_charge=new TH2F("visu_charge","visu_charge",128,0,128,32,0,32);
//TH2F *visu_charge=new TH2F("visu_charge","visu_charge",133,0,133,32,0,32);
TH2F *visu_charge=new TH2F("visu_charge","visu_charge",numberOfColumns,0,numberOfColumns,numberOfRows,0,numberOfRows);
TH2F *visu_time=new TH2F("visu_time","visu_time",numberOfColumns,0,numberOfColumns,numberOfRows,0,numberOfRows);
//TH2F *visu_time=new TH2F("visu_time","visu_time",64,0,64,64,0,64);
TH1F *hHorizAngle=new TH1F("hHorizAngle","Horizontal Angle",720,-180,180);
TH1F *hVertiAngle=new TH1F("hVertiAngle","Vertical Angle",360,-90,90);
TH1F *h3DAngle=new TH1F("h3DAngle","3D Angle",720,-180,180);
TH1F *hRange = new TH1F("hRange","Alpha range in mm",200,50.,150.);
TH1F *hRangeRest = new TH1F("hRangeRest","Alpha range in mm, |vert angle| < 10 deg",200,50.,150.);
TH2F *hRangeVsHoriz = new TH2F("hRangeVsHoriz","Range vs Horizontal angle",180,-90.,90.,200,50,150);
//*********************************************************************************************************//
//*********************************************************************************************************//
//** **//
//** Event Loop **//
//** **//
//*********************************************************************************************************//
//*********************************************************************************************************//
for (Long64_t jentry=0;jentry<dentries;jentry++) {
//for (Long64_t jentry=0;jentry<1000;jentry++) {
//for (Long64_t jentry=5000;jentry<nentries;jentry++) {
if(jentry%10==0 && jentry!=0)cout<<"."<<flush;
if(jentry%100==0)cout<<jentry<<endl;
//if(!simuFlag || (simuFlag && jentry%beamOn==0))
if(jentry%beamOn==0 && simuFlag)
{
for(Int_t u=0;u<numberOfRows;u++){
NTeeth[u]=NRHoles[u]=BCHit[u]=0;
for(Int_t k=0;k<numberOfColumns;k++){
padCharge[u][k]=0.;
padTime[u][k]=0.;
}
}
}
Candidate=0;
CandidateTrack=0;
RowTeeth=RowHoles=0;
MultiBlock=0;
NC0=NCHit=0;
Qtot=0;
visu_charge->Reset();
visu_chargeYZ->Reset();
visu_time->Reset();
h3DTrack->Reset();
h_latspread->Reset();
h_bragg->Reset();
Track->ResetLines();
//simTree->GetEvent(jentry);
padSignalCA->Clear();
digiTree->GetEvent(jentry);
Int_t numberofpads=padSignalCA->GetEntries();
//cout<<"# Pads fired "<< numberofpads<<endl;
if(numberofpads>0){
for(Int_t k=0;k<numberofpads;k++){
padSignal=(ActarPadSignal*)padSignalCA->At(k);
Double_t thisCharge = padSignal->GetChargeDeposited();
Double_t thisTime = (padSignal->GetInitTime()+padSignal->GetFinalTime())/2.;
Double_t thisSigmaTime=padSignal->GetSigmaTime();
Int_t PadRow=padSignal->GetPadRow();
Int_t PadColumn=padSignal->GetPadColumn();
//cout<<"thisSigmaTime: "<<thisSigmaTime<<endl;
//cout<<"PadRow "<<PadRow<<" PadColumn "<<PadColumn<<" thisCharge: "<<thisCharge<<endl;
if (thisCharge!=0){
//padChargeTest(padSignal->GetPadRow()-1,padSignal->GetPadColumn()-1)+= thisCharge;
//padTimeTest(padSignal->GetPadRow()-1,padSignal->GetPadColumn()-1)+= thisCharge*thisTime;
padCharge[padSignal->GetPadRow()-1][padSignal->GetPadColumn()-1]
+= thisCharge;
padTime[padSignal->GetPadRow()-1][padSignal->GetPadColumn()-1]
+= thisCharge*thisTime;
}
}//Loop on ActarPadSignals
//if(!simuFlag || (simuFlag && jentry%2==1))//To have the 2 parts of the reaction in simu
if(!simuFlag || (simuFlag && jentry%beamOn==(beamOn-1)))//To have the 2 parts of the reaction in simu
{
// Loop on rows & columns
for(Int_t c=0;c<numberOfColumns;c++){ //LOOP on Columns
for(Int_t r=0;r<numberOfRows;r++){ //LOOP on Rows
if(padCharge[r][c] > thresholdADC){
//padTimeTest(r,c)=padTimeTest(r,c)/padChargeTest(r,c);
padTime[r][c]=padTime[r][c]/padCharge[r][c];
//if(padTime[r][c]>0)cout<<padTime[r][c]<<endl;
//if(padTime[r][c]>0)cout<<"padTime[r][c] before "<<padTime[r][c];
padTime[r][c]=gRandom->Gaus(padTime[r][c],sigma_time);
//padTime[r][c]=gRandom->Gaus(padTime[r][c],thisSigmaTime);
//if(padTime[r][c]>0)cout<<" padTime[r][c] after "<<padTime[r][c]<<endl;
}
}
}//End of Loop on rows & columns
////////////////////////////////////////////////////
////////////// Loop on columns & rows //////////////
////////////////////////////////////////////////////
Double_t maxtime=0;
Double_t mintime=0;
for(Int_t r=0;r<numberOfRows;r++){ //LOOP on Rows
for(Int_t c=0;c<numberOfColumns;c++){ //LOOP on Columns
if(padCharge[r][c] > thresholdADC){
if(simuFlag){
/*
//Pad energy resolution estimation (to be measured)
if(padCharge[r][c]*30/1e6<20)PadESig=0.085;
else if(padCharge[r][c]*30/1e6>=20 && padCharge[r][c]*30/1e6<=5000)PadESig=-1.6215*1e-5*(padCharge[r][c]*30/1e6-20)+0.085;
else if(padCharge[r][c]*30/1e6>5000)PadESig=0.00425;
padCharge[r][c]=gRandom->Gaus(padCharge[r][c],PadESig*padCharge[r][c]);
*/
//cout<<"padChargeTest(r,c): "<<padChargeTest(r,c)<<" padChargeTest(r,c) (keV): "<<padChargeTest(r,c)*30/1e6<<" sigma (%): "<<PadESig*100<<" padCharge[r][c] (keV): "<<padCharge[r][c]*30/1e6<<endl;
if(c>=23)
{
if(c==23)NC0++;
if(BCHit[r]==0)NCHit++;
BCHit[r]=1;
//cout<<"C "<<c<<" R "<<r<<" padCharge[r][c] "<<padCharge[r][c]<<" thresholdADC "<<thresholdADC<<endl;
if(c>23 && c<numberOfColumns-1 && padCharge[r][c-1]<=threshold && padCharge[r][c+1]<=thresholdADC){NTeeth[r]++;}// padCharge[r][c]=0;}// cout<<"TEETH : C "<<c<<" R "<<r<<" padCharge[r][c] "<<padCharge[r][c]<<endl; }
if(c<numberOfColumns-2 && padCharge[r][c+1]<=thresholdADC && padCharge[r][c+2]>thresholdADC)NRHoles[r]++;
}
//padCharge[r][c]*=30/1e9;
padCharge[r][c]*=Wvalue/1e9;
Qtot+=padCharge[r][c];
//We left the middle pad band shadowed
//if(r>13 && r<18)padCharge[r][c]=0;
/*
else{
////////// '0' suppression simulation ////////////
//Double_t padADC=padChargeTest(r,c)*30/1e9+5+0.0537;
//Double_t padADC=padCharge[r][c]-0.0537;
Double_t padADC=padCharge[r][c];
padADC/=3.299*1e-5;
padADC+=BL[r][c]+gRandom->Gaus(0,BLSIG[r][c]);
//padADC+=BL[r][c];
//if(padADC<600)cout<<r<<" "<<c<<" padCharge "<<padCharge[r][c]<<" padADC "<<padADC<<endl;
//if(padADC<0)padCharge[r][c]=0;//just to try
if(padADC<600)padCharge[r][c]=0;
//////////END of '0' suppression simulation ////////////
}
*/
}
else if(!simuFlag){
//Pad charge to energy (MeV) convertion
//padCharge[r][c]=padChargeTest(r,c)*3.299*1e-5+0.0537;
padCharge[r][c]=padChargeTest(r,c);
padTime[r][c]=padTimeTest(r,c);
//if(r==13 && (c==0 || c==1 || c==2)){padCharge[r][c]=0; padTime[r][c]=0;} //These are noisy channels that I noticed in the end of 1st part. Check if is still the case in the run to analyse
}
//cout<<"TEST Row "<<r<<" Col "<<c<<" padCharge: "<<padCharge[r][c]<<endl;
padHeight[r][c]=padTime[r][c]*driftVelocity;
visu_charge->SetBinContent(c+1.,r+1,padCharge[r][c]);
visu_time->SetBinContent(c+1.,r+1.,padTime[r][c]);
h3DTrack->SetBinContent(c+1.,r+1.,padTime[r][c]*driftVelocity/2+1,padCharge[r][c]);
}
else{
padCharge[r][c]=-1;
padTime[r][c]=-1;
padHeight[r][c]=-1;
}
}//End of Loop on Columns
}//End of Loop on Rows
for(Int_t r=0;r<numberOfRows;r++){ //LOOP on Rows
if(NTeeth[r]>=5)RowTeeth=1;
if(NRHoles[r]>5)RowHoles=1;
NBlock=0;
for(Int_t c=23;c<numberOfColumns;c++){ //LOOP on Columns
if(padCharge[r][c]>threshold && NBlock==0 && padCharge[r][c+1]<=threshold)NBlock++;
else if(padCharge[r][c]>threshold && NBlock==1){MultiBlock=1;}// cout<<"r "<<r<<" c "<<c<<" MultiBlock "<<endl;}
}
}
h_energy_track->Fill(Qtot);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Fitting and calculating the starting and exit points as well as the energy deposit from a delta L part of the track ////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(!RowTeeth && !RowHoles)Candidate=1;
//if(!RowTeeth && !RowHoles && !MultiBlock && NC0==3 && NCHit==3)Candidate=1;
//if(TrackAnalysis)
if(TrackAnalysis && Candidate)
{
for(Int_t i=0;i<3;i++){
Start[i]=Stop[i]=0.;
TStart[i]=TStop[i]=0.;
}
Cmin=23;//corresponding to the gap between the alpha source and pad plane
FitMat(padCharge,Rmin,Rmax,Cmin,Cmax,threshold,a,b);
IniPoint[0]=0; IniPoint[1]=a*IniPoint[0]+b/2; FinPoint[0]=numberOfColumns; FinPoint[1]=FinPoint[0]*a+b/2;
Double_t chi2=FitMat3D(padCharge,padHeight,Rmin,Rmax,Cmin,Cmax,threshold,Track);
if(Track->Xm-Track->Xh!=0){
Double_t tstart=(0-Track->Xh)/(Track->Xm-Track->Xh);
Start[0]=0.;
Start[1]=tstart*(Track->Ym-Track->Yh)+Track->Yh;
Start[2]=tstart*(Track->Zm-Track->Zh)+Track->Zh;
Double_t tstop=((Double_t)numberOfColumns*2-Track->Xh)/(Track->Xm-Track->Xh);
Stop[0]=(Double_t)numberOfColumns*2;
Stop[1]=tstop*(Track->Ym-Track->Yh)+Track->Yh;
Stop[2]=tstop*(Track->Zm-Track->Zh)+Track->Zh;
Double_t trstart=(10-Track->Xh)/(Track->Xm-Track->Xh);
TStart[0]=10.;
TStart[1]=trstart*(Track->Ym-Track->Yh)+Track->Yh;
TStart[2]=trstart*(Track->Zm-Track->Zh)+Track->Zh;
}
//cout<<TStart[0]<<" "<<TStart[1]<<" "<<TStart[2]<<endl;
VAngle=TMath::ATan((Stop[2]-Start[2])/TMath::Sqrt((Stop[0]-Start[0])*(Stop[0]-Start[0])+(Stop[1]-Start[1])*(Stop[1]-Start[1])))*deg;
if(Stop[0]-Start[0]>0){
HAngle=TMath::ATan((Stop[1]-Start[1])/(Stop[0]-Start[0]))*deg;
Angle3D=TMath::ATan(TMath::Sqrt((Stop[1]-Start[1])*(Stop[1]-Start[1])+(Stop[2]-Start[2])*(Stop[2]-Start[2]))/(Stop[0]-Start[0]))*deg;
}
else{
HAngle=180.+TMath::ATan((Stop[1]-Start[1])/(Stop[0]-Start[0]))*deg;
Angle3D=180.+TMath::ATan(TMath::Sqrt((Stop[1]-Start[1])*(Stop[1]-Start[1])+(Stop[2]-Start[2])*(Stop[2]-Start[2]))/(Stop[0]-Start[0]))*deg;
}
//cout<<"VAngle :"<<VAngle<<", HAngle :"<<HAngle<<endl;
///// CORRECTING THE LATERAL RANGE //////
Double_t trans_cor;
for(int k=0;k<ActarLatBin;k++)
{
Range=hActarSimAlphaLatR->GetBinCenter(k);
LatRange=hActarSimAlphaLatR->GetBinContent(k);
/*
if(Start[2]!=0)trans_cor=Range*TMath::Tan(VAngle*rad)/Start[2];
else trans_cor=0;
LatRange*=TMath::Sqrt(1+trans_cor);
*/
gActarSimAlphaLatR->SetPoint(k,Range,LatRange);
}
///// FILLING THE CHARGE PROFILE //////
//if(h_bragg&&h_latspread)cout<<"HBRAGG & LATSPREAD"<<endl;
//if(padCharge&&padHeight)cout<<"PADCHARGE & PADHEIGHT"<<endl;
//cout<<Start[0]<<" "<<Stop[0]<<" "<<Rmin<<" "<<Rmax<<" "<<Cmin<<" "<<Cmax<<" "<<threshold<<" "<<NSlices<<endl;
Cmin=0;
//WeightedPadProjection(padCharge,padHeight,Start,Stop,Rmin,Rmax,Cmin,Cmax,threshold,gdEdx,gLatRange,gRange);
WeightedPadProjection3(padCharge,padHeight,Start,Stop,Rmin,Rmax,Cmin,Cmax,threshold,PadBin,gdEdx,gLatRange,gRange);
gLongBragg = new TGraph(NBinsGlobal,gRange,gdEdx);
gLatBragg = new TGraph(NBinsGlobal,gRange,gLatRange);
RangeO=TMath::Sqrt((Stop[0]-Start[0])*(Stop[0]-Start[0])+(Stop[1]-Start[1])*(Stop[1]-Start[1]));
bragR=new TSpline3(h_bragg);
Double_t rmaxval,rmax;
rmaxval=0;
for(Int_t n=0;n<NBinsGlobal;n++){
if(gdEdx[n]>rmaxval){rmaxval=gdEdx[n]; rmax=gRange[n];}
}
Double_t step=0.1;
Double_t value;
Double_t LastPoint=0.;
Double_t max;
Double_t posmax=0;
Double_t posmax2=0;
//for(Double_t val=rmax;val<=RangeO;val=val+step){
for(Double_t val=rmax;val<=rmax+30;val=val+step){
value=gLongBragg->Eval(val);
if(value<1e-6 && LastPoint==0.)LastPoint=val;
if(value>=rmaxval/StopPoint){
max=value;
posmax=val;
}
}
//cout<<"event "<<jentry<<" rmaxval "<<rmaxval<<" rmax "<<rmax<<" LastPoint "<<LastPoint<<endl;
RangeOS=TMath::Sqrt((TStart[0]-Start[0])*(TStart[0]-Start[0])+(TStart[1]-Start[1])*(TStart[1]-Start[1])+(TStart[2]-Start[2])*(TStart[2]-Start[2]));
h_range->Fill(posmax-RangeOS);
///////////////////////////////////////////////////////////////////
////Adjustment using MINUIT for 2 par (profile shift and hight)////
///////////////////////////////////////////////////////////////////
if(AlphaBraggFitFlag){
//NumericalMinimization("Minuit","",ActarPreEndPoint-posmax2,1948/ActarSimdEMax,1);
RShiftGlobal=ActarPreEndPoint-LastPoint;
multiGlobal=1948/ActarSimdEMax;
Double_t multi,RShift;
NumericalMinimization(gdEdx,gRange,ActarPreEndPoint-LastPoint,multiGlobal,multi,RShift);
Int_t startbin=0;
Int_t maxbin=0;
Int_t endbin=0;
Double_t valmax=0.;
Double_t simmaxrange=0.;
Double_t simrange=0.;
Double_t trans_cor;
for(int k=0;k<ActarBin;k++)
{
gActarSimAlphadEvsR->SetPoint(k,ActarSimrange[k]-RShift,ActarSimdE[k]);
if(startbin==0 && ActarSimrange[k]-RShift>=0)startbin=k;
else if(startbin!=0 && endbin==0 && ActarSimdE[k]<0.1){endbin=k; simrange=ActarSimrange[k]-RShift;}
if(ActarSimdE[k]>valmax){valmax=ActarSimdE[k]; maxbin=k; simmaxrange=ActarSimrange[k]-RShift;}
//cout<<k<<" "<<ActarSimrange[k]-RShift<<" "<<ActarSimdE[k]*multi<<" "<<startbin<<" "<<maxbin<<" "<<endbin<<endl;
///// CORRECTING THE LATERAL RANGE //////
Range=hActarSimAlphaLatR->GetBinCenter(k);
LatRange=hActarSimAlphaLatR->GetBinContent(k);
/*
if(Start[2]!=0)trans_cor=Range*TMath::Tan(VAngle*rad)/Start[2];
else trans_cor=0;
LatRange*=TMath::Sqrt(1+trans_cor);
*/
//gActarSimAlphaLatR->SetPoint(k,Range,LatRange);
gActarSimAlphaLatR->SetPoint(k,ActarSimrange[k]-RShift,LatRange);
}
Double_t Residu,LatResidu;
Double_t Realchisq=0.;
Double_t RealLatchisq=0.;