-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeedingDemoWithSVD.py
1205 lines (1045 loc) · 46.3 KB
/
SeedingDemoWithSVD.py
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
#!/usr/bin/python
import os
import math
import subprocess
import array
import numpy as np
import ROOT
from ROOT import TFile, TTree, TH1D, TH2D, TH3D, TF1, TF2, TGraph, TGraph2D, TRandom, TVector2, TVector3, TLorentzVector, TPolyMarker3D, TPolyLine3D, TPolyLine, TCanvas, TView, TLatex, TLegend
import argparse
parser = argparse.ArgumentParser(description='analysis.py...')
parser.add_argument('-p', metavar='process', required=True, help='physics process [trident or bppp]')
parser.add_argument('-s', metavar='sides', required=False, help='detector side [e+, e-, e+e-]')
parser.add_argument('-e', metavar='energy', required=False, help='beam energy')
argus = parser.parse_args()
proc = argus.p
sides = "e+" if(proc=="trident") else "e+e-" ## jsut the default
if(argus.s is not None): sides = argus.s
if(proc=="trident" and "e-" in sides):
print("ERROR: do not run tracking in the electron side for trident")
quit()
print("Running with proc=%s and sides=%s" % (proc,sides))
ROOT.gROOT.SetBatch(1)
ROOT.gStyle.SetOptFit(0);
ROOT.gStyle.SetOptStat(0);
ROOT.gStyle.SetPadBottomMargin(0.15)
ROOT.gStyle.SetPadLeftMargin(0.13)
# ROOT.gErrorIgnoreLevel = ROOT.kWarning
ROOT.gErrorIgnoreLevel = ROOT.kError
#############################################
NeventsToDraw = 10
### electron mass:
me = 0.51099895/1000. ### GeV
me2 = me*me
cm2m = 1.e-2
cm2um = 1.e4
um2cm = 1.e-4
### magnetic field
B = 1.4 if(proc=="trident") else 2.0 # Tesla
LB = 1 # meters
### possible energies
Emax = 17.5 if(proc=="trident") else 16 # GeV
Emin = 1.00 if(proc=="trident") else 2 # GeV
### geometry:
zDipoleExit = 202.9
xDipoleExitMinAbs = 1.5 if(proc=="bppp") else 4 ## cm --> TODO: need tuning
xDipoleExitMaxAbs = 25 if(proc=="bppp") else 30 ## cm --> TODO: need tuning
xDipoleExitAbs = (xDipoleExitMaxAbs-xDipoleExitMinAbs)/2.
yDipoleExitMin = -0.05 ## cm --> TODO: need tuning
yDipoleExitMax = +0.05 ## cm --> TODO: need tuning
xAbsMargins = 0.025 # cm --> TODO: need tuning
yAbsMargins = 0.025 if(proc=="bppp") else 0.1 # cm --> TODO: need tuning
### stave geometry
Hstave = 1.5 # cm
Lstave = 27 if(proc=="bppp") else 50 # cm
Rbeampipe = 4 # cm
RoffsetBfield22BPPP = 7.0 # cm for BPPP in B=2.2T
RoffsetBfield20BPPP = 5.7 # cm for BPPP in B=2.0T
RoffsetBfield14BPPP = 4.0 # cm for BPPP in B=1.4T
RoffsetBfield = RoffsetBfield20BPPP if(proc=="bppp") else 14 # cm
xPsideL = -RoffsetBfield-Lstave
xPsideR = -RoffsetBfield
xEsideL = +RoffsetBfield
xEsideR = +RoffsetBfield+Lstave
yUp = +Hstave/2.
yDn = -Hstave/2.
### for the histogram
detXmin = xPsideL
detXmax = xEsideR
if(proc=="trident"): detXmax = xPsideR
if(proc=="bppp" and sides=="e+"): detXmax = xPsideR
if(proc=="bppp" and sides=="e-"): detXmin = xEsideL
### background stuff
NnoiseClusters = 200 ## uniformly distributed in x:y for each layer
layers = [1,2,3,4]
### histos
histos = {
"h_dxrel":TH1D("h_dxrel",";(x_{cls}-x_{tru})/x_{tru};Tracks",200,-0.01,+0.01),
"h_dyrel":TH1D("h_dyrel",";(y_{cls}-y_{tru})/y_{tru};Tracks",200,-0.25,+0.25),
}
#############################################
def getgeometry(dipole=False):
tfile = TFile("../data/root/"+proc+"_geometry.root","READ")
geometry = [ tfile.Get("TPolyLine3D;9"), tfile.Get("TPolyLine3D;8"),
tfile.Get("TPolyLine3D;7"), tfile.Get("TPolyLine3D;6"),
tfile.Get("TPolyLine3D;5"), tfile.Get("TPolyLine3D;4"),
tfile.Get("TPolyLine3D;3"), tfile.Get("TPolyLine3D;2")]
if(dipole): geometry.append(tfile.Get("TPolyLine3D;1"))
return geometry
# def GetFits():
# finname = "../output/root/fits_E_vs_x.root"
# tf = TFile(finname,"READ")
# fitsEx = {
# "Dipole":{"electrons":tf.Get("Ele_EofX0"), "positrons":tf.Get("Pos_EofX0")},
# "Layer1":{"electrons":tf.Get("Ele_EofX1"), "positrons":tf.Get("Pos_EofX1")},
# "Layer2":{"electrons":tf.Get("Ele_EofX2"), "positrons":tf.Get("Pos_EofX2")},
# "Layer3":{"electrons":tf.Get("Ele_EofX3"), "positrons":tf.Get("Pos_EofX3")},
# "Layer4":{"electrons":tf.Get("Ele_EofX4"), "positrons":tf.Get("Pos_EofX4")},
# }
# return fitsEx
# def PlaneStr(i):
# if (i==0): return "Dipole"
# elif(i==1): return "Layer1"
# elif(i==2): return "Layer2"
# elif(i==3): return "Layer3"
# elif(i==4): return "Layer4"
# print("ERROR: unsupported plane index:",i)
# quit()
# return ""
# def GetE(x,iplane,particles):
# if(iplane==0):
# if(abs(x)<1):
# print("ERROR: |x|<1 for iplane=0:",x)
# quit()
# if(abs(x)>30):
# print("ERROR: |x|>30 for iplane=0:",x)
# quit()
# else:
# if(abs(x)<4):
# print("ERROR: |x|<4 for iplane>0:",x)
# quit()
# if(abs(x)>75):
# print("ERROR: |x|>75 for iplane>0:",x)
# quit()
# if(particles!="electrons" and particles!="positrons"):
# print("ERROR: particles string unsuppoerted:",particles)
# quit()
# if(particles=="electrons" and x<0):
# print("ERROR: electrons muxt come at positive x")
# quit()
# if(particles=="positrons" and x>0):
# print("ERROR: positrons muxt come at negative x")
# quit()
# E = fitsEx[PlaneStr(iplane)][particles].Eval(x)
# return E
def rUnit2(r1,r2):
r = (r2-r1).Unit()
return r ## TVector2
def rUnit3(r1,r2):
r = (r2-r1).Unit()
return r ## TVector3
def p3(r1,r2,E):
r = rUnit3(r1,r2)
p = TVector3()
p.SetXYZ(E*r.X(),E*r.Y(),E*r.Z())
return p ## TVector3
def p4(r1,r2,E):
p = p3(r1,r2,E)
tlv = TLorentzVector()
tlv.SetXYZM(p.Px(),p.Py(),p.Pz(),me)
return tlv ## TLorentzVector
# def setnoiseclusters(noiseclusters,N):
# rnd = TRandom()
# rnd.SetSeed()
# for i in range(N):
# x = rnd.Uniform(4,31)
# y = rnd.Uniform(-0.75,+0.75)
# z = rnd.Integer(4)
# if(z==0): z = 300
# if(z==1): z = 310
# if(z==2): z = 320
# if(z==3): z = 330
# noiseclusters.SetNextPoint(x,y,z)
def xofz(r1,r2,z):
dz = r2[2]-r1[2]
dx = r2[0]-r1[0]
if(dx==0):
print("ERROR in xofz: dx=0 --> r1[0]=%g,r2[0]=%g, r1[1]=%g,r2[1]=%g, r1[2]=%g,r2[2]=%g" % (r1[0],r2[0],r1[1],r2[1],r1[2],r2[2]))
quit()
a = dx/dz
b = r1[0]-a*r1[2]
x = a*z+b
return x
def yofz(r1,r2,z):
dz = r2[2]-r1[2]
dy = r2[1]-r1[1]
if(dz==0):
print("ERROR in yofz: dz=0 --> r1[0]=%g,r2[0]=%g, r1[1]=%g,r2[1]=%g, r1[2]=%g,r2[2]=%g" % (r1[0],r2[0],r1[1],r2[1],r1[2],r2[2]))
quit()
a = dy/dz
b = r1[1]-a*r1[2]
y = a*z+b
return y
def zofx(r1,r2,x):
dz = r2[2]-r1[2]
dx = r2[0]-r1[0]
if(dx==0):
print("ERROR in zofx: dx=0 --> r1[0]=%g,r2[0]=%g, r1[1]=%g,r2[1]=%g, r1[2]=%g,r2[2]=%g" % (r1[0],r2[0],r1[1],r2[1],r1[2],r2[2]))
quit()
a = dz/dx
b = r1[2]-a*r1[0]
z = a*x+b
return z
def countpoints(points3d):
npoints = 0
for i in range(points3d.GetN()):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
points3d.GetPoint(i,r[0],r[1],r[2])
if(abs(r[0])<xDipoleExitMin): continue
if(r[2]<300 or r[2]>330): continue
npoints += 1
return npoints
def getpoint(pm, i):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
pm.GetPoint(i,r[0],r[1],r[2])
return r[0],r[1],r[2]
def windowline(points,isclosed=True):
line = TPolyLine3D()
arr = []
for i in range(points.GetN()):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
points.GetPoint(i,r[0],r[1],r[2])
if(r[0]==0): continue
arr.append([r[0],r[1],r[2]])
if(isclosed):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
points.GetPoint(0,r[0],r[1],r[2])
arr.append([r[0],r[1],r[2]])
for point in arr:
line.SetNextPoint(point[0],point[1],point[2])
return line
def getyzwindow(cluster,i):
x1,y1,z1 = getpoint(cluster,i)
particles = "electrons" if(x1>0) else "positrons"
y1min = y1-yAbsMargins if((y1-yAbsMargins)>-0.75) else -0.75 ## must be within stave volume
y1max = y1+yAbsMargins if((y1+yAbsMargins)<+0.75) else +0.75 ## must be within stave volume
window_pts = TPolyMarker3D()
window_pts.SetNextPoint(x1,y1min,z1)
window_pts.SetNextPoint(x1,y1max,z1)
xmiddle = +xDipoleExitMinAbs+(abs(x1)*0.99-xDipoleExitMinAbs)/2
if(particles=="electrons"):
# window_pts.SetNextPoint(xDipoleExitAbs,yDipoleExitMax,zDipoleExit)
window_pts.SetNextPoint(+xmiddle,yDipoleExitMax,zDipoleExit)
# window_pts.SetNextPoint(xDipoleExitAbs,yDipoleExitMin,zDipoleExit)
window_pts.SetNextPoint(+xmiddle,yDipoleExitMin,zDipoleExit)
else:
# window_pts.SetNextPoint(-xDipoleExitAbs,yDipoleExitMax,zDipoleExit)
window_pts.SetNextPoint(-xmiddle,yDipoleExitMax,zDipoleExit)
# window_pts.SetNextPoint(-xDipoleExitAbs,yDipoleExitMin,zDipoleExit)
window_pts.SetNextPoint(-xmiddle,yDipoleExitMin,zDipoleExit)
window_lin = windowline(window_pts)
window_lin.SetLineWidth(1)
window_lin.SetLineColor(ROOT.kBlack)
return window_pts,window_lin
def getwidewindow(cluster,i):
x1,y1,z1 = getpoint(cluster,i)
particles = "electrons" if(x1>0) else "positrons"
x1min = 0
x1max = 0
window_pts = TPolyMarker3D()
if(particles=="electrons"):
x1min = x1-xAbsMargins if((x1-xAbsMargins)>xEsideL) else xEsideL ## must be within stave volume
x1max = x1+xAbsMargins if((x1+xAbsMargins)<xEsideR) else xEsideR ## must be within stave volume
window_pts.SetNextPoint(x1min,y1,z1) ## top left
window_pts.SetNextPoint(x1max,y1,z1) ## top right
# window_pts.SetNextPoint(xDipoleExitMaxAbs,y1,zDipoleExit) ## bottom right
window_pts.SetNextPoint(x1max*0.99,y1,zDipoleExit) ## bottom right
window_pts.SetNextPoint(xDipoleExitMinAbs,y1,zDipoleExit) ## bottom left
else:
x1min = x1-xAbsMargins if((x1-xAbsMargins)>xPsideL) else xPsideL ## must be within stave volume
x1max = x1+xAbsMargins if((x1+xAbsMargins)<xPsideR) else xPsideR ## must be within stave volume
window_pts.SetNextPoint(x1min,y1,z1) ## top left
window_pts.SetNextPoint(x1max,y1,z1) ## top right
# window_pts.SetNextPoint(-xDipoleExitMinAbs,y1,zDipoleExit) ## bottom right
window_pts.SetNextPoint(-xDipoleExitMinAbs,y1,zDipoleExit) ## bottom right
window_pts.SetNextPoint(x1min*0.99,y1,zDipoleExit) ## bottom left
window_lin = windowline(window_pts)
window_lin.SetLineWidth(1)
window_lin.SetLineColor(ROOT.kBlack)
return window_pts,window_lin
def getnarrwindow(cluster1,cluster2,i1,i2):
x1,y1,z1 = getpoint(cluster1,i1)
x2,y2,z2 = getpoint(cluster2,i2)
window_pts = TPolyMarker3D()
window_pts.SetNextPoint(x1-xAbsMargins,y1,z1) ## top left
window_pts.SetNextPoint(x1+xAbsMargins,y1,z1) ## top right
window_pts.SetNextPoint(x2+xAbsMargins,y2,z2) ## bottom right
window_pts.SetNextPoint(x2-xAbsMargins,y2,z2) ## bottom left
window_lin = windowline(window_pts)
window_lin.SetLineWidth(1)
window_lin.SetLineColor(ROOT.kBlue)
return window_pts,window_lin
def getxminmax(window,zTest):
windowarr = []
for i in range(window.GetN()):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
window.GetPoint(i,r[0],r[1],r[2])
if(r[0]==0): continue
windowarr.append([r[0],r[1],r[2]])
### get the equation of the
xmin = xofz(windowarr[0],windowarr[3],zTest)
xmax = xofz(windowarr[1],windowarr[2],zTest)
return xmin,xmax
def getyminmax(window,zTest):
windowarr = []
for i in range(window.GetN()):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
window.GetPoint(i,r[0],r[1],r[2])
if(r[0]==0): continue
windowarr.append([r[0],r[1],r[2]])
### get the equation of the
ymin = yofz(windowarr[0],windowarr[3],zTest)
ymax = yofz(windowarr[1],windowarr[2],zTest)
return ymin,ymax
def isinwindowxz(points,i,window):
### get the test point
rTest = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
points.GetPoint(i,rTest[0],rTest[1],rTest[2])
if(abs(rTest[0])<1): return False
### get the window x extremes at zTest
xmin,xmax = getxminmax(window,rTest[2])
if(rTest[0]>=xmin and rTest[0]<=xmax): return True
return False
def isinwindowyz(points,i,window):
### get the test point
rTest = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
points.GetPoint(i,rTest[0],rTest[1],rTest[2])
if(abs(rTest[0])<1): return False
### get the window x extremes at zTest
ymin,ymax = getyminmax(window,rTest[2])
if(rTest[1]>=ymin and rTest[1]<=ymax): return True
return False
def trimwide(allpoints,points_wide,windowxz,windowyz,xpivot):
for layer in layers:
for i in range(allpoints["Cls"][layer].GetN()):
acceptxz = isinwindowxz(allpoints["Cls"][layer],i,windowxz)
acceptyz = isinwindowyz(allpoints["Cls"][layer],i,windowyz)
if(not acceptxz): continue
if(not acceptyz): continue
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
allpoints["Cls"][layer].GetPoint(i,r[0],r[1],r[2])
# if(isel(r[0]) and r[0]>1.001*xpivot): continue
if(isel(r[0]) and r[0]>=xpivot): continue
# if(not isel(r[0]) and r[0]<1.001*xpivot): continue
if(not isel(r[0]) and r[0]<=xpivot): continue
points_wide["Cls"][layer].SetNextPoint(r[0],r[1],r[2])
points_wide["IsSig"][layer].append(allpoints["IsSig"][layer][i])
points_wide["TrkId"][layer].append(allpoints["TrkId"][layer][i])
def trimnarr(points_wide,points_narr,window):
for layer in layers:
for i in range(points_wide["Cls"][layer].GetN()):
accept = isinwindowxz(points_wide["Cls"][layer],i,window)
if(not accept): continue
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
points_wide["Cls"][layer].GetPoint(i,r[0],r[1],r[2])
points_narr["Cls"][layer].SetNextPoint(r[0],r[1],r[2])
points_narr["IsSig"][layer].append(points_wide["IsSig"][layer][i])
points_narr["TrkId"][layer].append(points_wide["TrkId"][layer][i])
def makeseed(cluster1,cluster2,i1,i2,particles):
p = TLorentzVector()
r1 = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
r2 = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
cluster1.GetPoint(i1,r1[0],r1[1],r1[2])
cluster2.GetPoint(i2,r2[0],r2[1],r2[2])
x0 = 0
z0 = zofx(r1,r2,x0)
xExit = xofz(r1,r2,zDipoleExit)*cm2m
q = 1 if(particles=="electrons") else -1
H = (zDipoleExit-z0)*cm2m
R = H*(LB)/xExit + xExit ## look this up in my sides
P = 0.3*B*R
v1 = TVector2(r1[2],r1[1])
v2 = TVector2(r2[2],r2[1])
u = rUnit2(v2,v1)
uz = u.X()
uy = u.Y()
px = 0
py = P*uy
pz = P*uz
p.SetPxPyPzE(px,py,pz,math.sqrt(P*P+me2))
return p
def getparticlename(cluster,i):
r = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
cluster.GetPoint(i,r[0],r[1],r[2])
if (r[0]>+1): return "electrons"
elif(r[0]<-1): return "positrons"
else:
print("ERROR: x=",r[0])
print(" cannot determine particle name")
quit()
return "unknown"
#############################################
def isel(x):
if(x<0): return False
return True
### define the data structures to hold clusters and windows
def initpoints():
points = {
"IsSig" : {1:[],2:[],3:[],4:[]},
"TrkId" : {1:[],2:[],3:[],4:[]},
"Cls" : {1:TPolyMarker3D(),2:TPolyMarker3D(),3:TPolyMarker3D(),4:TPolyMarker3D()}
}
return points
def AddPoint(points,rcls,sig=False,trkid=-1):
layer = -1
if (rcls[2]==330): layer = 4
elif(rcls[2]==320): layer = 3
elif(rcls[2]==310): layer = 2
elif(rcls[2]==300): layer = 1
else:
print("ERROR: cannot add cluster at layer with z=",rcls[2])
quit()
points["Cls"][layer].SetNextPoint(rcls[0],rcls[1],rcls[2])
# if(sig): points["Cls"][layer].SetMarkerColor(ROOT.kRed)
points["IsSig"][layer].append(sig)
points["TrkId"][layer].append(trkid)
def getNnon0(clusters):
N = 0
for j1 in range(clusters.GetN()):
r = [ ROOT.Double(), ROOT.Double(), ROOT.Double() ]
clusters.GetPoint(j1,r[0],r[1],r[2]) ### the clusters
if(r[2]==0): break
N += 1
return N
def getLogicSidesArr():
sidesarr = ["Eside","Pside"]
if(proc=="trident"): sidesarr = ["Pside"]
if(proc=="bppp" and sides=="e+"): sidesarr = ["Pside"]
if(proc=="bppp" and sides=="e-"): sidesarr = ["Eside"]
return sidesarr
def drawall(name,pointsEside,pointsPside,dodraw):
if(not dodraw): return
cnv = TCanvas("","",2000,2000)
view = TView.CreateView(1)
view.ShowAxis()
# view.SetRange(-80,-50,0, +80,+50,350)
if (sides=="e-"): view.SetRange(0,-10,190, xEsideR,+10,340)
elif(sides=="e+"): view.SetRange(xPsideL,-10,190, 0,+10,340)
else: view.SetRange(xPsideL,-10,190, xEsideR,+10,340)
geom = getgeometry() ### get the geometry from the root file
for g in geom: g.Draw()
for layer in layers:
pointsEside["Cls"][layer].Draw("same")
pointsPside["Cls"][layer].Draw("same")
cnv.SaveAs(name)
def draw(name,points,dodraw,particles="",window_yz=None,window_xz=None):
if(not dodraw): return
cnv = TCanvas("","",2000,2000)
view = TView.CreateView(1)
view.ShowAxis()
# view.SetRange(-80,-50,0, +80,+50,350)
if (particles=="electrons"): view.SetRange(0,-10,190, xEsideR,+10,340)
elif(particles=="positrons"): view.SetRange(xPsideL,-10,190, 0,+10,340)
else: view.SetRange(xPsideL,-10,190, xEsideR,+10,340)
geom = getgeometry() ### get the geometry from the root file
for g in geom: g.Draw()
if(window_yz is not None): window_yz.Draw("same")
if(window_xz is not None): window_xz.Draw("same")
for layer in layers: points["Cls"][layer].Draw("same")
cnv.SaveAs(name)
def line3d(z,m_xz,c_xz,m_yz,c_yz):
# the intersection of those two planes and
# the function for the line would be:
# z = m_yz * y + c_yz
# z = m_xz * x + c_xz
# or:
x = (z - c_xz)/m_xz
y = (z - c_yz)/m_yz
return x,y
def seed3dfit(name,r1,r2,r3,r4,dodraw):
g = TGraph2D()
g.SetMarkerSize(3)
g.SetMarkerStyle(20)
g.SetMarkerColor(ROOT.kRed)
g.SetLineColor(ROOT.kRed)
g.SetPoint(0,r1[2],r1[1],r1[0])
g.SetPoint(1,r2[2],r2[1],r2[0])
g.SetPoint(2,r3[2],r3[1],r3[0])
g.SetPoint(3,r4[2],r4[1],r4[0])
g.GetXaxis().SetRangeUser(290,340)
g.GetYaxis().SetRangeUser(-0.8,+0.8)
g.GetZaxis().SetRangeUser(0 if(isel(r1[0])) else xPsideL, xEsideR if(isel(r1[0])) else 0 )
x = np.array([r1[0],r2[0],r3[0],r4[0]])
y = np.array([r1[1],r2[1],r3[1],r4[1]])
z = np.array([r1[2],r2[2],r3[2],r4[2]])
# this will find the slope and x-intercept of a plane
# parallel to the y-axis that best fits the data
A_xz = np.vstack((x, np.ones(len(x)))).T
# m_xz, c_xz = np.linalg.lstsq(A_xz, z,rcond=None)[0]
result_xz = np.linalg.lstsq(A_xz, z,rcond=None)
m_xz, c_xz = result_xz[0]
residuals_xz = result_xz[1]
# again for a plane parallel to the x-axis
A_yz = np.vstack((y, np.ones(len(y)))).T
# m_yz, c_yz = np.linalg.lstsq(A_yz, z,rcond=None)[0]
result_yz = np.linalg.lstsq(A_yz, z,rcond=None)
m_yz, c_yz = result_yz[0]
residuals_yz = result_yz[1]
if(dodraw):
zz = np.array([300,310,320,330])
xx,yy = line3d(zz, m_xz,c_xz,m_yz,c_yz)
lfit = TPolyLine3D()
for i in range(4):
lfit.SetNextPoint(zz[i],yy[i],xx[i])
lfit.SetLineColor(ROOT.kBlue)
cnv = TCanvas("","",2000,2000)
view = TView.CreateView(1)
xviewmin = 0 if(isel(r1[0])) else xPsideL
xviewmax = xEsideR if(isel(r1[0])) else 0
view.SetRange(290,-0.8, xviewmin , 340,+0.8,xviewmax)
view.ShowAxis()
g.Draw("p0")
lfit.Draw("smae")
cnv.SaveAs(name)
return residuals_xz,residuals_yz
def seed3dfitSVD(name,r1,r2,r3,r4,dodraw):
g = TGraph2D()
g.SetMarkerSize(3)
g.SetMarkerStyle(20)
g.SetMarkerColor(ROOT.kRed)
g.SetLineColor(ROOT.kRed)
g.SetPoint(0,r1[2],r1[1],r1[0])
g.SetPoint(1,r2[2],r2[1],r2[0])
g.SetPoint(2,r3[2],r3[1],r3[0])
g.SetPoint(3,r4[2],r4[1],r4[0])
g.GetXaxis().SetRangeUser(290,340)
g.GetYaxis().SetRangeUser(-0.8,+0.8)
g.GetZaxis().SetRangeUser( 0 if(isel(r1[0])) else xPsideL, xEsideR if(isel(r1[0])) else 0 )
x = np.array([r1[0],r2[0],r3[0],r4[0]])
y = np.array([r1[1],r2[1],r3[1],r4[1]])
z = np.array([r1[2],r2[2],r3[2],r4[2]])
data = np.concatenate((x[:, np.newaxis],
y[:, np.newaxis],
z[:, np.newaxis]),
axis=1)
# Calculate the mean of the points, i.e. the 'center' of the cloud
datamean = data.mean(axis=0)
# Do an SVD on the mean-centered data (Singular Value Decomposition)
uu, dd, vv = np.linalg.svd(data - datamean)
# Now vv[0] contains the first principal component, i.e. the direction
# vector of the 'best fit' line in the least squares sense.
# Now generate some points along this best fit line, for plotting.
# I use -7, 7 since the spread of the data is roughly 14
# and we want it to have mean 0 (like the points we did
# the svd on). Also, it's a straight line, so we only need 2 points.
# linepts = vv[0] * np.mgrid[-7:7:2j][:, np.newaxis]
linepts = vv[0] * np.mgrid[-50:50:2j][:, np.newaxis]
# shift by the mean to get the line in the right place
linepts += datamean
if(dodraw):
lfit = TPolyLine3D()
for point in linepts:
lfit.SetNextPoint(point[2],point[1],point[0])
lfit.SetLineColor(ROOT.kBlue)
cnv = TCanvas("","",2000,2000)
view = TView.CreateView(1)
xviewmin = 0 if(isel(r1[0])) else xPsideL
xviewmax = xEsideR if(isel(r1[0])) else 0
view.SetRange(290,-0.8, xviewmin , 340,+0.8,xviewmax)
view.ShowAxis()
g.Draw("p0")
lfit.Draw("smae")
cnv.SaveAs(name)
return linepts, dd ## dd is a 1D array of the data singular values
def seed2dfit(name,r1,r2,r3,r4,dodraw):
gxyz = TGraph2D()
gxyz.SetMarkerSize(1)
gxyz.SetMarkerStyle(24)
gxyz.SetMarkerColor(ROOT.kBlack)
gxyz.SetPoint(0,r1[2],r1[1],r1[0])
gxyz.SetPoint(1,r2[2],r2[1],r2[0])
gxyz.SetPoint(2,r3[2],r3[1],r3[0])
gxyz.SetPoint(3,r4[2],r4[1],r4[0])
gxyz.GetXaxis().SetRangeUser(290,340)
gxyz.GetYaxis().SetRangeUser(-0.8,+0.8)
gxyz.GetZaxis().SetRangeUser( 0 if(isel(r1[0])) else xPsideL, xEsideR if(isel(r1[0])) else 0 )
gxz = TGraph()
gxz.SetMarkerSize(1)
gxz.SetMarkerStyle(24)
gxz.SetMarkerColor(ROOT.kBlack)
gxz.SetPoint(0,r1[2],r1[0])
gxz.SetPoint(1,r2[2],r2[0])
gxz.SetPoint(2,r3[2],r3[0])
gxz.SetPoint(3,r4[2],r4[0])
gxz.GetXaxis().SetRangeUser(290,340)
if(isel(r1[0])): gxz.GetYaxis().SetRangeUser(0,xEsideR)
else: gxz.GetYaxis().SetRangeUser(xPsideL,0)
gyz = TGraph()
gyz.SetMarkerSize(1)
gyz.SetMarkerStyle(24)
gyz.SetMarkerColor(ROOT.kBlack)
gyz.SetLineColor(ROOT.kRed)
gyz.SetPoint(0,r1[2],r1[1])
gyz.SetPoint(1,r2[2],r2[1])
gyz.SetPoint(2,r3[2],r3[1])
gyz.SetPoint(3,r4[2],r4[1])
gyz.GetXaxis().SetRangeUser(290,340)
gyz.GetYaxis().SetRangeUser(-0.8,+0.8)
fxz = TF1("fxz","pol1",300,330)
fitr_xz = gxz.Fit(fxz,"Q")
fitf_xz = gxz.FindObject("fxz")
fyz = TF1("fyz","pol1",300,330)
fitr_yz = gyz.Fit(fyz,"Q")
fitf_yz = gyz.FindObject("fyz")
if(dodraw):
lfit = TPolyLine3D()
for z in [300,310,320,330]:
x = fitf_xz.Eval(z)
y = fitf_yz.Eval(z)
lfit.SetNextPoint(z,y,x)
lfit.SetLineColor(ROOT.kBlue)
cnv = TCanvas("","",1500,500)
cnv.Divide(3,1)
cnv.cd(1)
view = TView.CreateView(1)
xviewmin = 0 if(isel(r1[0])) else xPsideL
xviewmax = xEsideR if(isel(r1[0])) else 0
view.SetRange(290,-0.8, xviewmin , 340,+0.8,xviewmax)
view.ShowAxis()
gxyz.Draw("p0")
lfit.Draw("smae")
cnv.cd(2)
gxz.Draw()
cnv.cd(3)
gyz.Draw()
cnv.SaveAs(name)
chi2_xz = fitf_xz.GetChisquare()/fitf_xz.GetNDF()
chi2_yz = fitf_yz.GetChisquare()/fitf_yz.GetNDF()
prob_xz = fitf_xz.GetProb()
prob_yz = fitf_yz.GetProb()
return chi2_xz,prob_xz,chi2_yz,prob_yz
def main():
##########################################################################################
##########################################################################################
##########################################################################################
### read fits to root file
# fitsEx = GetFits()
svd0Seed = ROOT.std.vector( float )()
svd1Seed = ROOT.std.vector( float )()
svd2Seed = ROOT.std.vector( float )()
chi2xzSeed = ROOT.std.vector( float )()
chi2yzSeed = ROOT.std.vector( float )()
residxzSeed = ROOT.std.vector( float )()
residyzSeed = ROOT.std.vector( float )()
issigSeed = ROOT.std.vector( int )()
iGenMatch = ROOT.std.vector( int )()
x1Seed = ROOT.std.vector( float )()
y1Seed = ROOT.std.vector( float )()
z1Seed = ROOT.std.vector( float )()
x2Seed = ROOT.std.vector( float )()
y2Seed = ROOT.std.vector( float )()
z2Seed = ROOT.std.vector( float )()
x3Seed = ROOT.std.vector( float )()
y3Seed = ROOT.std.vector( float )()
z3Seed = ROOT.std.vector( float )()
x4Seed = ROOT.std.vector( float )()
y4Seed = ROOT.std.vector( float )()
z4Seed = ROOT.std.vector( float )()
pxSeed = ROOT.std.vector( float )()
pySeed = ROOT.std.vector( float )()
pzSeed = ROOT.std.vector( float )()
eSeed = ROOT.std.vector( float )()
pxGen = ROOT.std.vector( float )()
pyGen = ROOT.std.vector( float )()
pzGen = ROOT.std.vector( float )()
eGen = ROOT.std.vector( float )()
qGen = ROOT.std.vector( float )()
iGen = ROOT.std.vector( int )()
tF = TFile("../data/root/seeds_"+proc+".root","RECREATE")
tF.cd()
tT = TTree("seeds","seeds")
tT.Branch('svd0Seed',svd0Seed)
tT.Branch('svd1Seed',svd1Seed)
tT.Branch('svd2Seed',svd2Seed)
tT.Branch('chi2xzSeed',chi2xzSeed)
tT.Branch('chi2yzSeed',chi2yzSeed)
tT.Branch('residxzSeed',residxzSeed)
tT.Branch('residyzSeed',residyzSeed)
tT.Branch('issigSeed',issigSeed)
tT.Branch('iGenMatch',iGenMatch)
tT.Branch('x1Seed',x1Seed)
tT.Branch('y1Seed',y1Seed)
tT.Branch('z1Seed',z1Seed)
tT.Branch('x2Seed',x2Seed)
tT.Branch('y2Seed',y2Seed)
tT.Branch('z2Seed',z2Seed)
tT.Branch('x3Seed',x3Seed)
tT.Branch('y3Seed',y3Seed)
tT.Branch('z3Seed',z3Seed)
tT.Branch('x4Seed',x4Seed)
tT.Branch('y4Seed',y4Seed)
tT.Branch('z4Seed',z4Seed)
tT.Branch('pxSeed',pxSeed)
tT.Branch('pySeed',pySeed)
tT.Branch('pzSeed',pzSeed)
tT.Branch('eSeed',eSeed)
tT.Branch('pxGen',pxGen)
tT.Branch('pyGen',pyGen)
tT.Branch('pzGen',pzGen)
tT.Branch('eGen',eGen)
tT.Branch('qGen',qGen)
tT.Branch('iGen',iGen)
histos = { "h_residuals_xz_sig": TH1D("residuals_xz_sig",";residuals_{xz};Tracks", 500,0,0.5),
"h_residuals_yz_sig": TH1D("residuals_yz_sig",";residuals_{yz};Tracks", 500,0,500),
"h_residuals_xz_bkg": TH1D("residuals_xz_bkg",";residuals_{xz};Tracks", 500,0,0.5),
"h_residuals_yz_bkg": TH1D("residuals_yz_bkg",";residuals_{yz};Tracks", 500,0,500),
"h_svd_dd0_sig": TH1D("svd_dd0_sig",";svd_{dd0};Tracks", 500,21,24),
"h_svd_dd0_bkg": TH1D("svd_dd0_bkg",";svd_{dd0};Tracks", 500,21,24),
"h_svd_dd1_sig": TH1D("svd_dd1_sig",";svd_{dd1};Tracks", 500,0,0.1),
"h_svd_dd1_bkg": TH1D("svd_dd1_bkg",";svd_{dd1};Tracks", 500,0,0.1),
"h_svd_dd2_sig": TH1D("svd_dd2_sig",";svd_{dd2};Tracks", 500,0,0.05),
"h_svd_dd2_bkg": TH1D("svd_dd2_bkg",";svd_{dd2};Tracks", 500,0,0.05),
"h_prob_xz_sig": TH1D("prob_xz_sig",";prob_{xz};Tracks", 500,0,1.0),
"h_prob_yz_sig": TH1D("prob_yz_sig",";prob_{yz};Tracks", 500,0,1.0),
"h_prob_xz_bkg": TH1D("prob_xz_bkg",";prob_{xz};Tracks", 500,0,1.0),
"h_prob_yz_bkg": TH1D("prob_yz_bkg",";prob_{yz};Tracks", 500,0,1.0),
"h_chi2ndf_xz_sig": TH1D("chi2ndf_xz_sig",";chi2ndf_{xz};Tracks", 500,0,0.001),
"h_chi2ndf_yz_sig": TH1D("chi2ndf_yz_sig",";chi2ndf_{yz};Tracks", 500,0,0.001),
"h_chi2ndf_xz_bkg": TH1D("chi2ndf_xz_bkg",";chi2ndf_{xz};Tracks", 500,0,0.001),
"h_chi2ndf_yz_bkg": TH1D("chi2ndf_yz_bkg",";chi2ndf_{yz};Tracks", 500,0,0.001),
"h_seed_resE" : TH1D("seed_resE", ";(E_{seed}-E_{gen})/E_{gen};Tracks", 100,-3,+3),
"h_seed_resPz": TH1D("seed_resPz",";(Pz_{seed}-Pz_{gen})/Pz_{gen};Tracks", 100,-3,+3),
"h_seed_resPy": TH1D("seed_resPy",";(Py_{seed}-Py_{gen})/Py_{gen};Tracks", 100,-10,+10),
"h_seed_resE_vs_x" : TH2D("seed_resE_vs_x", ";x;(E_{seed}-E_{gen})/E_{gen};Tracks", 100,detXmin,detXmax, 100,-5,+5),
"h_seed_resPy_vs_x" : TH2D("seed_resPy_vs_x", ";x;(Py_{seed}-Py_{gen})/Py_{gen};Tracks", 100,detXmin,detXmax, 100,-10,+10),
"h_N_sigacc": TH1D("N_sigacc", ";Track multiplicity;Events", 40,30,190),
"h_N_all_seeds": TH1D("N_all_seeds", ";Track multiplicity;Events", 40,30,190),
"h_N_matched_seeds": TH1D("N_matched_seeds", ";Track multiplicity;Events", 40,30,190),
"h_N_good_seeds": TH1D("N_good_seeds", ";Track multiplicity;Events", 40,30,190),
"h_seeding_score": TH1D("h_seeding_score", ";N_{seeds}^{matched}/N_{signa}^{in.acc} [%];Events", 20,91,101),
"h_seeding_pool": TH1D("h_seeding_pool", ";N_{seeds}^{all}/N_{signa}^{in.acc} [%];Events", 50,90,590),
}
sidesarr = getLogicSidesArr()
pdfname = "../output/pdf/seedingdemo_"+proc+".pdf"
intfile = TFile("../data/root/rec_"+proc+".root","READ")
intree = intfile.Get("res")
nevents = intree.GetEntries()
print("with %d events" % nevents)
nmax = 100000
n=0 ### init n
for event in intree:
Nsigall = 0
Nsigacc = 0
Nseeds = 0
Nmatched = 0
Ngood = 0
## clear the output vectors
svd0Seed.clear()
svd1Seed.clear()
svd2Seed.clear()
chi2xzSeed.clear()
chi2yzSeed.clear()
residxzSeed.clear()
residyzSeed.clear()
issigSeed.clear()
iGenMatch.clear()
x1Seed.clear()
y1Seed.clear()
z1Seed.clear()
x2Seed.clear()
y2Seed.clear()
z2Seed.clear()
x3Seed.clear()
y3Seed.clear()
z3Seed.clear()
x4Seed.clear()
y4Seed.clear()
z4Seed.clear()
pxSeed.clear()
pySeed.clear()
pzSeed.clear()
eSeed.clear()
pxGen.clear()
pyGen.clear()
pzGen.clear()
eGen.clear()
qGen.clear()
iGen.clear()
### start the loop
if(n>nmax): break
### draw?
dodraw = (n<=NeventsToDraw)
### container for all clusters
allpointsEside = initpoints()
allpointsPside = initpoints()
## clusters' vectors are always written out (even if empty) for all gen tracks!
## each generated track in the vector always has 4 clusters accessed via TPolyMarker3D::GetPoint()
for i in range(event.polm_clusters.size()):
###############################################################
if(proc=="bppp"):
if(sides=="e+" and event.qgen[i]<0): continue ## only positrons
if(sides=="e-" and event.qgen[i]>0): continue ## only electrons
if(proc=="trident" and event.qgen[i]<0): continue ## only positrons
###############################################################
Nsigall += 1
wgt = event.wgtgen[i]
pgen = event.pgen[i]
### cut on acceptance
if(event.acctrkgen[i]!=1): continue
Nsigacc += 1
### write the truth track momentum and its index
pxGen.push_back(pgen.Px())
pyGen.push_back(pgen.Py())
pzGen.push_back(pgen.Pz())
eGen.push_back(pgen.E())
qGen.push_back(event.qgen[i])
iGen.push_back(i)
### loop over all clusters of the track and put in the allpoints classified by the layer
for jxy in range(event.polm_clusters[i].GetN()):
rcls = [ ROOT.Double(), ROOT.Double(), ROOT.Double() ]
event.polm_clusters[i].GetPoint(jxy,rcls[0],rcls[1],rcls[2]) ### the clusters
if(rcls[0]>0): AddPoint(allpointsEside,rcls,True,i)
if(rcls[0]<0): AddPoint(allpointsPside,rcls,True,i)
Nsig4 = getNnon0(allpointsEside["Cls"][4])+getNnon0(allpointsPside["Cls"][4])
### embed some noise clusters
rnd = TRandom()
rnd.SetSeed()
for kN in range(NnoiseClusters):
for layer in layers:
for side in sidesarr:
x = 0
if(side=="Pside"): x = rnd.Uniform(xPsideL,xPsideR)
if(side=="Eside"): x = rnd.Uniform(xEsideL,xEsideR)
y = rnd.Uniform(-0.75,+0.75)
if(layer==1): z = 300
if(layer==2): z = 310
if(layer==3): z = 320
if(layer==4): z = 330
rnoise = [x,y,z]
if(side=="Pside"): AddPoint(allpointsPside,rnoise)
if(side=="Eside"): AddPoint(allpointsEside,rnoise)
Nbkgsig4 = getNnon0(allpointsEside["Cls"][4])+getNnon0(allpointsPside["Cls"][4])
### just draw the full event
drawall(pdfname+"(",allpointsEside,allpointsPside,dodraw)
### loop on the 2 sides
for side in sidesarr:
allpoints = allpointsEside if(side=="Eside") else allpointsPside
### the initial pool for pivot clusters
Nall4 = getNnon0(allpoints["Cls"][4])
### loop over the clusters and start the seeding
for j4 in range(Nall4):
r4 = getpoint(allpoints["Cls"][4],j4)
xpivot = r4[0]
### electron / positron?
particlename = getparticlename(allpoints["Cls"][4],j4)
### get the yz window
winpts_yz,winlin_yz = getyzwindow(allpoints["Cls"][4],j4)
### set the wide window starting from cluster_seed1 (window corners must be added clockwise!)
winpts_xz_wide,winlin_xz_wide = getwidewindow(allpoints["Cls"][4],j4)
### discard all clusters which are not in the wide window
widepoints = initpoints()
trimwide(allpoints,widepoints,winpts_xz_wide,winpts_yz,xpivot)
Nwide1 = getNnon0(widepoints["Cls"][1])
# if(Nwide1<1): print("Failed Nwide1")
### draw the wide window
draw(pdfname,widepoints,dodraw,particlename,winlin_yz,winlin_xz_wide)
### choose one cluster in layer 1 as the second seed
for j1 in range(Nwide1):
### get the narrow window (window corners must be added clockwise!)
winpts_xz_narr,winlin_xz_narr = getnarrwindow(allpoints["Cls"][4],widepoints["Cls"][1],j4,j1)
### discard all clusters which are not in the narrow window
narrpoints = initpoints()
trimnarr(widepoints,narrpoints,winpts_xz_narr)
Nnarr2 = getNnon0(narrpoints["Cls"][2])
Nnarr3 = getNnon0(narrpoints["Cls"][3])
### check if there are at least 1 cluster in both layer 2 and layer 3 within the narrow window
if(Nnarr2<1 or Nnarr3<1): continue
### draw the narrow window
draw(pdfname,narrpoints,dodraw,particlename,None,winlin_xz_narr)
### get the seed - note: could be that there are several combinations but the seed momentum would be identical
pseed = makeseed(allpoints["Cls"][4],widepoints["Cls"][1],j4,j1,particlename)
# if(pseed.E()>Emax or pseed.E()<Emin): print("pseed.E()>Emax or pseed.E()<Emin")
if(pseed.E()>Emax or pseed.E()<Emin): continue
### set the cluster in layer 1
r1 = getpoint(widepoints["Cls"][1],j1)
### loop on the clusters in layer 2 and 3:
for j2 in range(Nnarr2):
# for j2 in range(narrpoints["Cls"][2].GetN()):
r2 = getpoint(narrpoints["Cls"][2],j2)
for j3 in range(Nnarr3):
# for j3 in range(narrpoints["Cls"][3].GetN()):
r3 = getpoint(narrpoints["Cls"][3],j3)
Nseeds += 1
issig1 = widepoints["IsSig"][1][j1]
issig2 = narrpoints["IsSig"][2][j2]
issig3 = narrpoints["IsSig"][3][j3]