-
Notifications
You must be signed in to change notification settings - Fork 1
/
vertex.C
1807 lines (1627 loc) · 55.7 KB
/
vertex.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
#include<fstream>
#include <string>
#include "math.h"
#include <TClonesArray.h>
#include <TObjArray.h>
#include <TChain.h>
#include <TH1D.h>
#include <TH2D.h>
#include <vector>
using namespace std;
//=====================================================================================================================================================//
//s509 Position Variables
//
#define TRIG(i) (1 << (i - 1))
/*
On-spill + FOOT.
TRIG_LMU_OUT( 1) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu;
TRIG_LMU_OUT( 2) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu and in_tofd;
TRIG_LMU_OUT( 3) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu and in_califa_and;
TRIG_LMU_OUT( 4) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu and in_califa_and and not in_califa_veto;
TRIG_LMU_OUT( 5) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu and in_califa_or;
TRIG_LMU_OUT( 6) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu and in_califa_or and not in_califa_veto;
TRIG_LMU_OUT( 6) = BEAM_GATE_AUX and not FOOT_DEAD_AUX and in_los_nrolu and in_neuland;
On-spill - FOOT.
TRIG_LMU_OUT( 7) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu;
TRIG_LMU_OUT( 8) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu and in_tofd;
TRIG_LMU_OUT( 9) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu and in_califa_and;
TRIG_LMU_OUT(10) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu and in_califa_and and not in_califa_veto;
TRIG_LMU_OUT(11) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu and in_califa_or;
TRIG_LMU_OUT(12) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu and in_califa_or and not in_califa_veto;
TRIG_LMU_OUT(12) = BEAM_GATE_AUX and NONFOOT_BONUS_AUX and in_los_nrolu and in_neuland;
Off-spill.
TRIG_LMU_OUT(13) = not BEAM_GATE_AUX and in_califa_or;
TRIG_LMU_OUT(14) = not BEAM_GATE_AUX and in_neuland;
TRIG_LMU_OUT(15) = not BEAM_GATE_AUX and in_tofd;
TRIG_LMU_OUT(16) = not BEAM_GATE_AUX and in_rpc;
*/
double mm = pow(10,3);
double mwz_0 = 0.83*mm;
double mwz_1 = 1.250*mm;
double mwz_t = 2.773*mm;
double fib_ang = 14;//deg
double fib32_z = 4.862*mm;// from bending
double fib30_z = 5.148*mm;// from bending//yy
double fib33_z = 6.462*mm;// from bending
double fib31_z = 6.5939*mm;// from bending
double tofd_z = 11.394*mm;// from bending
double tofd_bar = 27;//mm
//=====================================================================================================================================================//
//FRS varibales
double FRSZ=0;
double FRSAQ=0;
double FRSB=0;
double FRSG=0;
double FRSBR=0;
double FRST=0;
double FRSX=0;
double FRSM=0;
double FRSZ_G = 7;
//=====================================================================================================================================================//
//Hist Init
//Int_t Energy_sup = 3500;//s509
Int_t Energy_sup = 2100;//S522
//=====================================================================================================================================================//
//R3BRoot Variables
int setPoint;
Int_t TPAT;
//=====================================================================================================================================================//
//To make More Pretty Plots
void Hist(){
}
double recon(Double_t dep_e, Double_t theta)
{
double mp = 938.; // MeV
TF1 *f1 = new TF1("f1","[0]/(x*x)+[1]*log(x)/(x*x)+[2]",0.65,0.95);
Double_t theta_deg = theta * TMath::RadToDeg();
if (theta_deg<55.5) {
if (dep_e <125. || dep_e > 270.)
return -1000.;
f1->SetParameter(0,-377.139);
f1->SetParameter(1,-677.695);
f1->SetParameter(2,508.23);
double beta = f1->GetX(dep_e);
if (beta <= 0. || beta >= 1.)
return -1000.;
double gamma = 1./TMath::Sqrt(1.-beta*beta);
double Ekin = (gamma-1) * mp;
return Ekin;
}
else if (theta_deg < 70.4)
{
if (dep_e <103. || dep_e > 230.)
return -1000.;
f1->SetParameter(0,-167.502);
f1->SetParameter(1,-343.602);
f1->SetParameter(2,269.559);
double beta = f1->GetX(dep_e);
if (beta <= 0. || beta >= 1.)
return -1000.;
double gamma = 1./TMath::Sqrt(1.-beta*beta);
double Ekin = (gamma-1) * mp;
return Ekin;
}
else
{
if (dep_e <97. || dep_e > 210.)
return -1000.;
f1->SetParameter(0,-132.962);
f1->SetParameter(1,-285.584);
f1->SetParameter(2,228.287);
double beta = f1->GetX(dep_e);
if (beta <= 0. || beta >= 1.)
return -1000.;
double gamma = 1./TMath::Sqrt(1.-beta*beta);
double Ekin = (gamma-1) * mp;
return Ekin;
}
}
/*double recon(Double_t dep_e, Double_t theta)
{
Double_t theta_deg = theta * TMath::RadToDeg();
if (theta_deg<55.5) { // iphos
if (dep_e<135 || dep_e > 265)
return -1000;
return 12369.8 - 194.693 * dep_e +1.20531 * pow(dep_e,2) - 0.00335935 * pow(dep_e,3) +0.00000353193 * pow(dep_e,4);
} else if (theta_deg < 70.4) { // barrel 1
if (dep_e<105 || dep_e > 215)
return -1000;
return 5381.41 - 69.8561*dep_e + 0.288122*pow(dep_e,2) - 0.000135574*pow(dep_e,3) - 0.000000950755*pow(dep_e,4);
} else { // barrel 2
if (dep_e<100 || dep_e > 205)
return -1000;
return 3321.43 - 19.5399*dep_e - 0.19495*pow(dep_e,2) + 0.00196785*pow(dep_e,3) - 0.00000440662*pow(dep_e,4);
}
}
*/
void MinDist(double ax_right, double bx_right, double ay_right, double by_right, double ax_left, double bx_left, double ay_left, double by_left, double &xv, double &yv, double &zv, double &distmin)
{
double a1, a2, b1, b2, ap1, ap2, bp1, bp2;
a1 = bx_left;
a2 = by_left;
b1 = ax_left;
b2 = ay_left;
ap1 = bx_right;
ap2 = by_right;
bp1 = ax_right;
bp2 = ay_right;
double alpha, beta, A, B, C;
alpha = (bp1*(a1-ap1)+bp2*(a2-ap2))/(bp1*bp1 + bp2*bp2 + 1);
beta = (bp1*b1+bp2*b2+1)/(bp1*bp1 + bp2*bp2 + 1);
A = beta*(bp1*bp1 + bp2*bp2 + 1) - (bp1*b1 + bp2*b2 + 1);
B = (b1*b1 + b2*b2 + 1) - beta*(bp1*b1+bp2*b2+1);
C = beta*(bp1*(ap1-a1) + bp2*(ap2-a2)) - (b1*(ap1-a1) + b2*(ap2-a2));
double sol1, solf1;
double x1,y1,z1,xp,yp,zp;
sol1 = -(A*alpha + C)/(A*beta + B);
solf1 = alpha + beta* sol1;
x1 = a1 + b1*sol1;
y1 = a2 + b2*sol1;
z1 = sol1;
xp = ap1 + bp1*solf1;
yp = ap2 + bp2*solf1;
zp = solf1;
xv = (x1+xp)/2.;
yv = (y1+yp)/2.;
zv = (z1+zp)/2.;
distmin = TMath::Sqrt((x1-xp)*(x1-xp) + (y1-yp)*(y1-yp) + (z1-zp)*(z1-zp));
}
//=====================================================================================================================================================//
//Main()
void vertex(){
TStopwatch timer;
timer.Start();
Hist();
TFile*in = new TFile("../unpacked/131_mdf_2.root","READ");
if(in){std::cout<<"File Found" << std::endl;}
if(!in){std::cout<<"File Not Found" << std::endl;}
TTree*tree = (TTree*)in->Get("evt");
if(tree){std::cout<< "Tree Found"<<std::endl;}
if(!tree){std::cout<< "Tree Not Found"<<std::endl;}
int nevents = tree->GetEntries();
std::cout << "Number Of Raw Events: "<< nevents << std::endl;
R3BEventHeader*DataCA = new R3BEventHeader();
TBranch*branchData = tree->GetBranch("EventHeader.");
if(branchData){std::cout<< "EventHeader Loaded"<<std::endl;}
if(!branchData){std::cout<< "EventHeader Not Loaded"<<std::endl;}
branchData->SetAddress(&DataCA);
TClonesArray*hitDataFRS = new TClonesArray("R3BFrsData",10);
TBranch*branchFRSHitData = tree->GetBranch("FrsData");
if(branchFRSHitData){std::cout<<"FrsData Loaded"<<std::endl;}
if(!branchFRSHitData){std::cout<<"FrsData Not Loaded"<<std::endl;}
branchFRSHitData->SetAddress(&hitDataFRS);
TClonesArray*hitDataMWPC0 = new TClonesArray("R3BMwpcHitData",2);
TBranch*branchMWPC0HitData = tree->GetBranch("Mwpc0HitData");
if(branchMWPC0HitData){std::cout<< "Mwpc0HitData Loaded"<<std::endl;}
if(!branchMWPC0HitData){std::cout<< "Mwpc0HitData Not Loaded"<<std::endl;}
branchMWPC0HitData->SetAddress(&hitDataMWPC0);
TClonesArray*hitDataMWPC1 = new TClonesArray("R3BMwpcHitData",2);
TBranch*branchMWPC1HitData = tree->GetBranch("Mwpc1HitData");
if(branchMWPC1HitData){std::cout<< "MwpC1HitData Loaded"<<std::endl;}
if(!branchMWPC1HitData){std::cout<< "MwpC1HitData Not Loaded"<<std::endl;}
branchMWPC1HitData->SetAddress(&hitDataMWPC1);
TClonesArray*LosTCalData = new TClonesArray("R3BLosTCalData");
TBranch*branchLosTCalData = tree->GetBranch("LosTCal");
if(branchLosTCalData){std::cout<< "LosTCalData Loaded"<<std::endl;}
if(!branchLosTCalData){std::cout<< "LosTCalData Not Loaded"<<std::endl;}
branchLosTCalData->SetAddress(&LosTCalData);
TClonesArray *CalifaClusterData = new TClonesArray("R3BCalifaClusterData");
tree->GetBranch("CalifaClusterData")->SetAutoDelete(kFALSE);
if(CalifaClusterData){std::cout<<"CalifaHitData Loaded"<<std::endl;}
if(!CalifaClusterData){std::cout<<"CalifaHitData Not Loaded"<<std::endl;}
tree->SetBranchAddress("CalifaClusterData", &CalifaClusterData);
TClonesArray* TofdHitData = new TClonesArray("R3BTofdHitData",10);
TBranch* branchTofdHit = tree->GetBranch("TofdHit");
if(branchTofdHit){std::cout<<"TofdHitData Loaded"<<std::endl;}
if(!branchTofdHit){std::cout<<"TofdHitData Not Loaded"<<std::endl;}
branchTofdHit->SetAddress(&TofdHitData);
TClonesArray *FootHitData = new TClonesArray("R3BFootHitData");
tree->GetBranch("FootHitData")->SetAutoDelete(kFALSE);
if(FootHitData){std::cout<< "FootHitData Loaded"<<std::endl;}
if(!FootHitData){std::cout<< "FootHitData Not Loaded"<<std::endl;}
tree->SetBranchAddress("FootHitData", &FootHitData);
//cut normali
TCutG *cutg3 = new TCutG("cut103f",7);
cutg3->SetVarX("FOOT10_X");
cutg3->SetVarY("FOOT3_X");
cutg3->SetTitle("Graph");
cutg3->SetFillStyle(1000);
cutg3->SetPoint(0,70.8277,57.3048);
cutg3->SetPoint(1,44.7736,35.7081);
cutg3->SetPoint(2,44.84,31.7815);
cutg3->SetPoint(3,47.8309,31.536);
cutg3->SetPoint(4,71.3594,51.5375);
cutg3->SetPoint(5,71.0271,54.1144);
cutg3->SetPoint(6,70.8277,57.3048);
TCutG *cutg5 = new TCutG("CUTG5",6);
cutg5->SetVarX("FOOT5_Y");
cutg5->SetVarY("FOOT12_Y");
cutg5->SetTitle("Graph");
cutg5->SetFillStyle(1000);
cutg5->SetPoint(0,55.0653,41.3125);
cutg5->SetPoint(1,-50.0653,-27.2083);
cutg5->SetPoint(2,-49.7971,-39.1875);
cutg5->SetPoint(3,55.0653,29.3333);
cutg5->SetPoint(4,55.0653,37);
cutg5->SetPoint(5,55.0653,41.3125);
TCutG *cutg6 = new TCutG("CUTG6",6);
cutg6->SetVarX("FOOT9_Y");
cutg6->SetVarY("FOOT6_Y");
cutg6->SetTitle("Graph");
cutg6->SetFillStyle(1000);
cutg6->SetPoint(0,52.3834,34.6042);
cutg6->SetPoint(1,-49.5289,-19.0625);
cutg6->SetPoint(2,-48.7243,-33.9167);
cutg6->SetPoint(3,53.188,22.1458);
cutg6->SetPoint(4,53.188,25.9792);
cutg6->SetPoint(5,52.3834,34.6042);
TCutG *cutg8 = new TCutG("CUTG8",8);
cutg8->SetVarX("FOOT8_X");
cutg8->SetVarY("FOOT11_X");
cutg8->SetTitle("Graph");
cutg8->SetFillStyle(1000);
cutg8->SetPoint(0,-49.6979,-32.6667);
cutg8->SetPoint(1,-71.6711,-52.4);
cutg8->SetPoint(2,-71.4141,-58.4);
cutg8->SetPoint(3,-68.1374,-58.6667);
cutg8->SetPoint(4,-45.2647,-37.6);
cutg8->SetPoint(5,-45.3289,-31.8667);
cutg8->SetPoint(6,-47.9632,-32.4);
cutg8->SetPoint(7,-49.6979,-32.6667);
double sx =0.;//4.26095;
double sy = 0.;
double angley=0.;//1.08506; //0.08506;
double x5=63.395+sx;
double x12=38.323+sx;
double x9=-63.935+sx;
double x6=-39.354+sx;
double z5=527.848;
double z12=490.752;
double z9=527.136;
double z6=490.413;
double px5=20*TMath::Cos(-74.64723447*TMath::DegToRad());
double px12=20*TMath::Cos(-74.67117924*TMath::DegToRad());
double px6=20*TMath::Cos(75.09256426426*TMath::DegToRad());
double px9=20*TMath::Cos(75.09398359*TMath::DegToRad());
double pz5=20*TMath::Sin(-74.64723447*TMath::DegToRad());
double pz12=20*TMath::Sin(-74.67117924*TMath::DegToRad());
double pz6=20*TMath::Sin(75.09256426426*TMath::DegToRad());
double pz9=20*TMath::Sin(75.09398359*TMath::DegToRad());
//cout<<"px12"<<px12<<endl;
//cout<<"pz12"<<pz12<<endl;
double s1x5=63.395+sx-px5;
double s1x12=38.323+sx-px12;
double s1x9=-63.935+sx+px9;
double s1x6=-39.354+sx+px6;
double s1z5=527.848-pz5;
double s1z12=490.752-pz12;
double s1z9=527.136+pz9;
double s1z6=490.413+pz6;
double c5;
double c12;
double c6;
double c9;
TVector3 pos5(x5,0,z5);
TVector3 pos12(x12,0,z12);
TVector3 pos6(x6,0,z6);
TVector3 pos9(x9,0,z9);
TVector3 pos5_1(s1x5,0,s1z5);
TVector3 pos12_1(s1x12,0,s1z12);
TVector3 pos6_1(s1x6,0,s1z6);
TVector3 pos9_1(s1x9,0,s1z9);
pos5.RotateY(TMath::DegToRad()*angley);
pos12.RotateY(TMath::DegToRad()*angley);
pos9.RotateY(TMath::DegToRad()*angley);
pos6.RotateY(TMath::DegToRad()*angley);
pos5_1.RotateY(TMath::DegToRad()*angley);
pos12_1.RotateY(TMath::DegToRad()*angley);
pos9_1.RotateY(TMath::DegToRad()*angley);
pos6_1.RotateY(TMath::DegToRad()*angley);
c5= ((pos5.X()-pos5_1.X())/(pos5.Z()-pos5_1.Z()));
c12= ((pos12.X()-pos12_1.X())/(pos12.Z()-pos12_1.Z()));
c6= ((pos6.X()-pos6_1.X())/(pos6.Z()-pos6_1.Z()));
c9= ((pos9.X()-pos9_1.X())/(pos9.Z()-pos9_1.Z()));
double td=439.338211;
double angley_r=0.89515684;
double fADet_old[20]={0.,0.,0.,0.,0.,-0.2563176063,0.2506446273,0.,0.,0.2506316425, 0.,0.,-0.2563132822,0.,0.,0.,0.,0.,0.,0 };
double fADet[20]={0.,0.,0.,0.,0.,c5,c6,0.,0.,c9, 0.,0.,c12,0.,0.,0.,0.,0.,0.,0 };
double fBDet[20]={0.,0.,0.,0.,0.,pos5.X()-c5*(pos5.Z()),pos6.X()-c6*(pos6.Z()),0.,0.,pos9.X()-c9*(pos9.Z()),0.,0.,pos12.X()-c12*(pos12.Z()),0.,0.,0.,0.,0.,0.,0.};
//cout<<"x5"<< pos5.X()<<endl;
//cout<<"z5"<< pos5.Z()<<endl;
//cout<<"x6"<< pos6.X()<<endl;
//cout<<"z6"<< pos6.Z()<<endl;
//cout<<"x9"<< pos9.X()<<endl;
//cout<<"z9"<< pos9.Z()<<endl;
//cout<<"x12"<< pos12.X()<<endl;
//cout<<"z12"<< pos12.Z()<<endl;
//cout<<"x5"<< pos5.X<<endl;
//cout<<"c5"<< c5<<endl;
//cout<<"c12"<< c12<<endl;
//cout<<"c6"<< c6<<endl;
//cout<<"c9"<< c9<<endl;
//cout<<"b5: "<<pos5.X()-c5*(pos5.Z())<<endl;
//cout<<"b12: "<<pos12.X()-c12*(pos12.Z())<<endl;
//cout<<"b6: "<<pos6.X()-c6*(pos6.Z())<<endl;
//cout<<"b9: "<<pos9.X()-c9*(pos9.Z())<<endl;
int goodmwevents=0; int goodfootevents=0;
double S_aX_mwpc=0; double S_aX_beam=0;
double A_aX_mwpc=0; double A_aX_beam=0;
double SNum_p=0; double SDen1=0; double SDen2=0;
double P=0; double P_t=0; double SNum_p_t=0;
double SDen2_t=0; int goodfootevents_t=0;
double S_aX_beam_t=0; double A_aX_beam_t=0;
double bX_mwpco=-999.;
Double_t aX_beam = -999; Double_t bX_beam = -999;
Double_t aY_beam = -999; Double_t bY_beam = -999;
Double_t aX_right = -999; Double_t bX_right = -999;
Double_t aY_right = -999; Double_t bY_right = -999;
Double_t aX_left = -999; Double_t bX_left = -999;
Double_t aY_left = -999; Double_t bY_left = -999;
double Foot6_Z=999.;
double Foot13_Z=999.;
double Foot10_Z=999.;
double Foot7_Z=999.;
Double_t mw0x = -500.; Double_t mw0y = -500.; Double_t mw1x = -500.; Double_t mw1y = -500.;
Double_t mw0z = -1083.661789-24; Double_t mw1z = -2250.661789-24;
Double_t aX_mwpc = -999; Double_t bX_mwpc = -999;
Double_t aY_mwpc = -999; Double_t bY_mwpc = -999;
Double_t Q = -999 , Q_ = -999;
bool p2pt=false;
bool t1=false;
Double_t M_x = -999;
Double_t M_y = -999;
Double_t x_0 = -999; Double_t y_1 = -999; Double_t y_15 = -999; Double_t x_14 = -999;
Double_t dist_min1=-999999;
Double_t dist_min15=-99999;
//Double_t mw0z = -1523; Double_t mw1z = -2690;
int count_v=0;
int detId;
int stripId;
double energy;
int i_init = 0;
int Mult1t=0;
int Mult2t=0;
int Mult3t=0;
int Mult4t=0;
int Det_Id=0;
int Bar_Id=0;
double EH=0;
int Califa_mult;
vector <double> ts;
vector <double> Et0;
vector <double> Zt0;
vector <double> xt0;
vector <double> yt0;
vector <double> etat0;
vector <double> Multt0;
vector <double> Nst0;
vector <double> Et1;
vector <double> xt1;
vector <double> yt1;
vector <double> etat1;
vector <double> Multt1;
vector <double> Nst1;
vector <double> Et14;
vector <double> xt14;
vector <double> yt14;
vector <double> etat14;
vector <double> Multt14;
vector <double> Nst14;
vector <double> Et15;
vector <double> xt15;
vector <double> yt15;
vector <double> etat15;
vector <double> Multt15;
vector <double> Nst15;
vector <double> Et10;
vector <double> zt10;
vector <double> xt10;
vector <double> etat10;
vector <double> Multt10;
vector <double> Nst10;
vector <double> Et5;
vector <double> yt5;
vector <double> etat5;
vector <double> Multt5;
vector <double> Nst5;
vector <double> Et3;
vector <double> xt3;
vector <double> zt3;
vector <double> etat3;
vector <double> Multt3;
vector <double> Nst3;
vector <double> Et12;
vector <double> yt12;
vector <double> etat12;
vector <double> Multt12;
vector <double> Nst12;
vector <double> Et8;
vector <double> zt8;
vector <double> xt8;
vector <double> etat8;
vector <double> Multt8;
vector <double> Nst8;
vector <double> Et11;
vector <double> xt11;
vector <double> zt11;
vector <double> etat11;
vector <double> Multt11;
vector <double> Nst11;
vector <double> Et9;
vector <double> yt9;
vector <double> etat9;
vector <double> Multt9;
vector <double> Nst9;
vector <double> Et6;
vector <double> yt6;
vector <double> etat6;
vector <double> Multt6;
vector <double> Nst6;
vector <double> lost;
vector <int> Multe0;
vector <int> Multe1;
vector <int> Multe14;
vector <int> Multe15;
vector <double> Et0r;
vector <double> Et1r;
vector <double> zt0;
vector <double> zt1;
vector <double> zt14;
vector <double> zt15;
vector <int> S_id;
vector <int> D_id;
vector <double> hit_energy;
vector <double> hit_theta;
vector <double> hit_phi;
vector <int> nbofcrystalhits;
int multhits;
vector <double> frs_aq;
vector <double> frs_z;
vector <double> frs_b;
vector <double> ns;
vector <double> nf;
vector <int> c_id;
vector <int> c_t;
vector <double> Zt;
vector <double> mw0xt;
vector <double> mw0yt;
vector <double> mw1xt;
vector <double> mw1yt;
vector <int> Bar_Idt;
vector <int> Det_Idt;
vector <int> Mult1;
vector <int> Mult2;
vector <int> Mult3;
vector <int> Mult4;
vector <double> theta1;
vector <double> theta2;
vector <double> phi1;
vector <double> phi2;
vector <double> opa_c;
vector <double> opa_f;
vector <double> opa_f_t;
vector <double> e1c;
vector <double> e2c;
vector <double> dphi_f;
vector <double> phi_fl;
vector <double> phi_fr;
vector <double> phi_fps;
vector <double> foot8_x;
vector <double> foot11_x;
vector <double> Et0n;
vector <double> Et1n;
vector <double> Et14n;
vector <double> Et15n;
vector <double> pro01;
vector <double> pro45;
vector <double> Et0new;
vector <double> Et1new;
vector <double> Et14new;
vector <double> Et15new;
vector <double> AX_MW;
vector <double> BX_MW;
vector <double> AY_MW;
vector <double> BY_MW;
vector <double> AX_beam;
vector <double> AY_beam;
vector <double> BX_beam;
vector <double> BY_beam;
vector <double> z_v;
vector <double> x_v;
vector <double> y_v;
vector <double> z_vm_l;
vector <double> x_vm_l;
vector <double> y_vm_l;
vector <double> z_vm_lb;
vector <double> x_vm_lb;
vector <double> y_vm_lb;
vector <double> d;
vector <double> dm_l;
vector <double> t_pl;
vector <double> t_pr;
vector <double> t_ps;
vector <double> AX_right;
vector <double> AY_right;
vector <double> BX_right;
vector <double> BY_right;
vector <double> AX_left;
vector <double> AY_left;
vector <double> BX_left;
vector <double> BY_left;
vector <double> zt5;
vector <double> zt12;
vector <double> zt6;
vector <double> zt9;
vector <double> zv_t;
vector <double> yv_t;
vector <double> xv_t;
vector <double> z_vm_r;
vector <double> x_vm_r;
vector <double> y_vm_r;
vector <double> dm_r;
vector <double> theta_rv;
vector <double> theta_lv;
vector <double> phi_rv;
vector <double> phi_lv;
vector <double> z_vm_t;
vector <double> x_vm_t;
vector <double> y_vm_t;
vector <double> dm_t;
vector <double> z_vm_tt;
vector <double> x_vm_tt;
vector <double> y_vm_tt;
vector <double> dm_tt;
//Starting new variables
vector <double> ml;
vector <double> mr;
vector <int> eventn;
vector <double> theta_p_l;
vector <double> theta_p_r;
vector <double> phi_p_l;
vector <double> phi_p_r;
vector <double> theta_p_l_m;
vector <double> theta_p_r_m;
vector <double> phi_p_l_m;
vector <double> phi_p_r_m;
vector <double> theta_p_l_m_t;
vector <double> theta_p_r_m_t;
vector <double> phi_p_l_m_t;
vector <double> phi_p_r_m_t;
vector <double> theta_rn;
vector <double> theta_ln;
vector <double> phi_ln;
vector <double> phi_rn;
vector <double> opa_rl;
vector <double> opa_lr;
vector <double> opa_t;
vector <double>x_extt;
vector <double> dpl;
vector <double> dpr;
vector <double> dtl;
vector <double> dtr;
vector <double> Mm;
vector <double> Pmt;
vector <double> Pmtf;
vector <double> Pmx;
vector <double> Pmy;
vector <double> Pmz;
vector <double> Em;
vector <double> Erc;
vector <double> Elc;
vector <double> Mmf;
vector <double> Pmxf;
vector <double> Pmyf;
vector <double> Pmzf;
vector <double> Emf;
TLorentzVector p3f, p4f,pmissf;
TLorentzVector p3, p4, ptg, pmiss, pbeam;
double Emiss, mmiss, Emissf, mmissf;
bool p2pt_n=false;
int mult0n=0;
int mult1n=0;
int mult14n=0;
int mult15n=0;
int mult0n_n=0;
int mult1n_n=0;
int mult14n_n=0;
int mult15n_n=0;
bool t2=false;
bool t7 = false;
bool t8 = false;
bool t13 = false;
bool t14 = false;
bool t15 = false;
bool t16 = false;
bool t3 = false;
bool t4=false;
Int_t TPATn;
//New File definition
TFile *q = new TFile("vertex_big_ts_strict_2.root","RECREATE");
TTree *vertex = new TTree ("vertex","vertex");
vertex->Branch("FRS_Aq",&frs_aq);
vertex->Branch("FRS_Z",&frs_z);
vertex->Branch("FRS_B",&frs_b);
vertex->Branch("FOOT3_E",&Et3);
vertex->Branch("Nf",&nf);
vertex->Branch("Ns",&ns);
vertex->Branch("Crystal_ID",&c_id);
vertex->Branch("p2p",&p2pt_n);
vertex->Branch("TPAT",&TPATn);
vertex->Branch("T1",&t1);
vertex->Branch("T2",&t2);
vertex->Branch("T3",&t3);
vertex->Branch("T4",&t4);
vertex->Branch("Strip_Id",&S_id);
vertex->Branch("Det_Id",&D_id);
vertex->Branch("TOFD_Z",&Zt);
vertex->Branch("TOFD_Mult1",&Mult1);
vertex->Branch("TOFD_Mult2",&Mult2);
vertex->Branch("TOFD_Mult3",&Mult3);
vertex->Branch("TOFD_Mult4",&Mult4);
vertex->Branch("TOFD_DetId",&Det_Idt);
vertex->Branch("TOFD_BarId",&Bar_Idt);
vertex->Branch("Z_vertex_m_t",&z_vm_t);
vertex->Branch("Y_vertex_m_t",&y_vm_t);
vertex->Branch("X_vertex_m_t",&x_vm_t);
vertex->Branch("Dist_m_t",&dm_t);
vertex->Branch("Theta_Califa_r",&theta_rv);
vertex->Branch("Theta_Califa_l",&theta_lv);
vertex->Branch("Phi_c_r",&phi_rv);
vertex->Branch("Phi_c_l",&phi_lv);
vertex->Branch("Energy_Califa_r",&Erc);
vertex->Branch("Energy_Califa_l",&Elc);
vertex->Branch("Opening_angle_Califa",&opa_c);
vertex->Branch("Opening_angle_Foot_t",&opa_f_t);
vertex->Branch("E_loss_p",&hit_energy);
vertex->Branch("NbOfCrystalHits",&nbofcrystalhits);
vertex->Branch("NbHits",&multhits);
vertex->Branch("Theta_proton_left",&t_pl);
vertex->Branch("Theta_proton_right",&t_pr);
vertex->Branch("Theta_protons",&t_ps);
vertex->Branch("Mult_left",&ml);
vertex->Branch("Mult_right",&mr);
vertex->Branch("Event",&eventn);
vertex->Branch("Theta_p_l",&theta_p_l_m_t);
vertex->Branch("Theta_p_r",&theta_p_r_m_t);
vertex->Branch("Phi_p_l",&phi_p_l_m_t);
vertex->Branch("Phi_p_r",&phi_p_r_m_t);
vertex->Branch("Opening_angle_t",&opa_t);
vertex->Branch("Dpl",&dpl);
vertex->Branch("Dpr",&dpr);
vertex->Branch("Dtr",&dtr);
vertex->Branch("Dtl",&dtl);
vertex->Branch("Pt",&Pmt);
vertex->Branch("Ptf",&Pmtf);
vertex->Branch("Mmiss",&Mm);
vertex->Branch("Emiss",&Em);
vertex->Branch("Px",&Pmx);
vertex->Branch("Py",&Pmy);
vertex->Branch("Pz",&Pmz);
vertex->Branch("Mmissf",&Mmf);
vertex->Branch("Emissf",&Emf);
vertex->Branch("Pxf",&Pmxf);
vertex->Branch("Pyf",&Pmyf);
vertex->Branch("Pzf",&Pmzf);
vertex->Branch("TimeStamp",&ts);
//nevents=100000;
for(int i = 0; i<nevents ; i++){
//cout<<"i-> "<<i<<endl;
TPATn=TPAT;
p2pt_n=p2pt;
eventn.clear();
eventn.push_back(i);
//bool p2pt=false;
bool p2pt_n=false;
int mult0n=0;
int mult1n=0;
int mult14n=0;
int mult15n=0;
int mult0n_n=0;
int mult1n_n=0;
int mult14n_n=0;
int mult15n_n=0;
std::clog << "Analysis Info : " << (i-i_init)*100/(nevents-i_init) << " % of events treated, " << count_v << " Good vertex found " << "\r";
//std::clog << "Analysis Info : " << count_v << " Good vertex found" << "\r";
//cout<<"TPAT--> "<<TPAT<<endl;
t4=false;
t1 = (TRIG(1)) & TPAT;
t2 = (TRIG(2)) & TPAT;
t3 = (TRIG(3)) & TPAT;
t4 = (TRIG(4)) & TPAT;
t7 = (TRIG(7)) & TPAT;
t8 = (TRIG(8)) & TPAT;
t13 = (TRIG(13)) & TPAT;
t14 = (TRIG(14)) & TPAT;
t15 = (TRIG(15)) & TPAT;
t16 = (TRIG(16)) & TPAT;
//clear variables inside code
Mult1.clear();
Mult2.clear();
Mult3.clear();
Mult4.clear();
Zt.clear();
c_t.clear();
Bar_Idt.clear();
Det_Idt.clear();
mw0xt.clear();
mw0yt.clear();
mw1xt.clear();
mw1yt.clear();
Et0.clear();
xt0.clear();
yt0.clear();
zt0.clear();
zt1.clear();
zt14.clear();
zt15.clear();
etat0.clear();
Multt0.clear();
Nst0.clear();
Et1.clear();
xt1.clear();
yt1.clear();
etat1.clear();
Multt1.clear();
Nst1.clear();
Et14.clear();
xt14.clear();
yt14.clear();
etat14.clear();
Multt14.clear();
Nst14.clear();
Et15.clear();
xt15.clear();
yt15.clear();
etat15.clear();
Multt15.clear();
Nst15.clear();
Multe0.clear();
Multe1.clear();
Multe14.clear();
Multe15.clear();
p2pt=false;
Et0r.clear();
Et1r.clear();
Zt0.clear();
S_id.clear();
D_id.clear();
frs_b.clear();
frs_aq.clear();
frs_z.clear();
Et8.clear();
xt8.clear();
zt8.clear();
zt11.clear();
zt3.clear();
zt10.clear();
etat8.clear();
Multt8.clear();
Et11.clear();
xt11.clear();
etat11.clear();
Multt11.clear();
Et9.clear();
yt9.clear();
etat9.clear();
Multt9.clear();
Et6.clear();
yt6.clear();
etat6.clear();
Multt6.clear();
Et10.clear();
xt10.clear();
etat10.clear();
Multt10.clear();
Et3.clear();
xt3.clear();
etat3.clear();
Multt3.clear();
Et12.clear();
yt12.clear();
etat12.clear();
Multt12.clear();
Et5.clear();
yt5.clear();
etat5.clear();
Multt5.clear();
lost.clear();
ns.clear();
nf.clear();
c_id.clear();
hit_energy.clear();
hit_theta.clear();
hit_phi.clear();
nbofcrystalhits.clear();
multhits=-1;
Nst5.clear();
Nst12.clear();
Nst3.clear();
Nst10.clear();
Nst11.clear();
Nst8.clear();
Nst6.clear();
Nst9.clear();
ts.clear();
// Clear of new variables
phi_rv.clear();
phi_lv.clear();
theta_rv.clear();
theta_lv.clear();
theta_p_l_m_t.clear();
theta_p_r_m_t.clear();
phi_p_l_m_t.clear();
phi_p_r_m_t.clear();
theta_p_l.clear();
theta_p_r.clear();
phi_p_l.clear();
phi_p_r.clear();
opa_t.clear();
AX_MW.clear();
AY_MW.clear();
BX_MW.clear();
BY_MW.clear();
AX_beam.clear();
AY_beam.clear();
BX_beam.clear();
BY_beam.clear();
phi1.clear();
phi2.clear();
theta1.clear();
theta2.clear();
opa_c.clear();
z_vm_t.clear();
x_vm_t.clear();
y_vm_t.clear();
dm_t.clear();
t_pl.clear();
t_pr.clear();
t_ps.clear();
AX_right.clear();
AY_right.clear();
BX_right.clear();
BY_right.clear();
AX_left.clear();
AY_left.clear();
BX_left.clear();
BY_left.clear();
zt5.clear();
zt12.clear();
zt6.clear();
zt9.clear();
ml.clear();
mr.clear();
opa_f.clear();
opa_f_t.clear();
dtl.clear();
dtr.clear();
dpl.clear();
dpr.clear();
Mm.clear();
Pmx.clear();
Pmy.clear();
Pmz.clear();
Em.clear();
Erc.clear();
Elc.clear();
Mmf.clear();
Pmxf.clear();
Pmyf.clear();
Pmzf.clear();
Emf.clear();
e1c.clear();
e2c.clear();
Pmt.clear();
Pmtf.clear();
hitDataFRS->Clear();
hitDataMWPC0->Clear();
hitDataMWPC1->Clear();
TofdHitData->Clear();
LosTCalData->Clear();