694def PatRec(firsttwo,zlayer,zlayerv2,StrawRaw,StrawRawLink,ReconstructibleMCTracks):
695 global reconstructiblehorizontalidsfound12,reconstructiblestereoidsfound12,reconstructiblehorizontalidsfound34,reconstructiblestereoidsfound34
696 global reconstructibleidsfound12,reconstructibleidsfound34,rawhits,totalaftermatching
697
698 hits={}
699 rawhits={}
700 stereohits={}
701 hitids={}
702 ytan={}
703 ycst={}
704 horpx={}
705 horpy={}
706 horpz={}
707 stereomom={}
708 stereotan={}
709 stereocst={}
710 fraction={}
711 trackid={}
712 duplicates=[]
713 j=0
714 resolution=ShipGeo.strawtubes.sigma_spatial
715
716 for item in StrawRaw:
717
718 rawhits[j]=copy.deepcopy(((StrawRaw[item][1]+StrawRaw[item][4])/2,(StrawRaw[item][2]+StrawRaw[item][5])/2,StrawRaw[item][6]))
719 if firsttwo==True:
720 if global_variables.debug:
721 print(
722 "rawhits[", j, "]=", rawhits[j],
723 "trackid", StrawRawLink[item][0].GetTrackID(),
724 "strawname", StrawRawLink[item][0].GetDetectorID(),
725 "true x", StrawRawLink[item][0].GetX(),
726 "true y", StrawRawLink[item][0].GetY(),
727 "true z", StrawRawLink[item][0].GetZ()
728 )
729 j=j+1
730
731 sortedrawhits=OrderedDict(sorted(rawhits.items(),key=lambda t:t[1][1]))
732 if global_variables.debug:
733 print(" ")
734 print("horizontal view (y) hits ordered by plane: plane nr, zlayer, hits")
735
736 y2=[]
737 y3=[]
738 yother=[]
739 ymin2=[]
740 z2=[]
741 z3=[]
742 zother=[]
743 zmin2=[]
744 for i in range(i1,i2+1):
745 a=[]
746 c=[]
747 d=[]
748 for item in sortedrawhits:
749 if (float(sortedrawhits[item][1])==float(zlayer[i][0])) :
750
751 if sortedrawhits[item][0] not in a:
752 a.append(float(sortedrawhits[item][0]))
753 else:
754
755 if global_variables.debug:
756 print(" wire hit again", sortedrawhits[item], "strawname=", StrawRawLink[item][0].GetDetectorID())
757 a.append(float(sortedrawhits[item][0]))
758 duplicates.append(float(zlayer[i][0]))
759 a.sort()
760
761 for value in a:
762 for item in sortedrawhits:
763 if ((float(sortedrawhits[item][0])==value) & (float(sortedrawhits[item][1])==float(zlayer[i][0]))) :
764 if item not in c :
765 c.append(item)
766 d.append(float(sortedrawhits[item][2]))
767 else :
768 continue
769 break
770
771 b=len(a)*[0]
772 hits[i]=[a,b,c,d]
773 if global_variables.debug:
774 print(i, zlayer[i], hits[i])
775
776
777
778 for item in range(len(hits[i][0])):
779 if StrawRawLink[hits[i][2][item]][0].GetTrackID() == 3:
780 y3.append(float(hits[i][0][item]))
781 z3.append(float(zlayer[i][0]))
782 else:
783 if StrawRawLink[hits[i][2][item]][0].GetTrackID() == 2:
784 y2.append(float(hits[i][0][item]))
785 z2.append(float(zlayer[i][0]))
786 else:
787 if StrawRawLink[hits[i][2][item]][0].GetTrackID() == -2:
788 ymin2.append(float(hits[i][0][item]))
789 zmin2.append(float(zlayer[i][0]))
790 else:
791 yother.append(float(hits[i][0][item]))
792 zother.append(float(zlayer[i][0]))
793
794 if cheated==True :
795 if threeprong==1 : nrtrcandv1,trcandv1=ptrack(zlayer,hits,6,0.6)
796 else : nrtrcandv1,trcandv1=ptrack(zlayer,hits,7,0.5)
797 else :
798 if threeprong==1 : nrtrcandv1,trcandv1=ptrack(zlayer,hits,6,0.6)
799 else: nrtrcandv1,trcandv1=ptrack(zlayer,hits,7,0.7)
800
801 foundhorizontaltrackids=[]
802 horizontaltrackids=[]
803 removetrackids=[]
804 for t in trcandv1:
805 trackids=[]
806 if global_variables.debug:
807 print(' ')
808 print('track found in Y view:',t,' indices of hits in planes',trcandv1[t])
809 for ipl in range(len(trcandv1[t])):
810 indx= trcandv1[t][ipl]
811 if indx>-1:
812 if global_variables.debug:
813 print(
814 ' plane nr, z-position, y of hit, trackid:',
815 ipl, zlayer[ipl], hits[ipl][0][indx],
816 StrawRawLink[hits[ipl][2][indx]][0].GetTrackID()
817 )
818 trackids.append(StrawRawLink[hits[ipl][2][indx]][0].GetTrackID())
819 if global_variables.debug:
820 print(
821 " Largest fraction of hits in Y view:", fracMCsame(trackids)[0],
822 "on MC track with id",fracMCsame(trackids)[1]
823 )
824 if firsttwo==True:
825 h['fracsame12-y'].Fill(fracMCsame(trackids)[0])
826 else:
827 h['fracsame34-y'].Fill(fracMCsame(trackids)[0])
828 if monitor==1:
829 if fracMCsame(trackids)[1] in ReconstructibleMCTracks:
830 horizontaltrackids.append(fracMCsame(trackids)[1])
831 if fracMCsame(trackids)[1] not in foundhorizontaltrackids:
832 foundhorizontaltrackids.append(fracMCsame(trackids)[1])
833 else:
834
835 if global_variables.debug:
836 print("Y view track with trackid", fracMCsame(trackids)[1], "is not reconstructible. Removing it.")
837 removetrackids.append(t)
838
839 if (len(foundhorizontaltrackids) == 0 or len(horizontaltrackids)==0 ):
840 if global_variables.debug:
841 print("No reconstructible Y view tracks found.")
842 if monitor==True : return 0,[],[],[],[],[],[],{},{},{},{},{}
843
844 for i in range(0,len(removetrackids)):
845 del trcandv1[removetrackids[i]]
846 nrtrcandv1=nrtrcandv1-1
847
848
849 if len(removetrackids)>0:
850 j=0
851 for key in trcandv1:
852 j=j+1
853 if key!=j:
854 trcandv1[j]=trcandv1[key]
855 del trcandv1[key]
856
857 if monitor==1:
858 if len(ReconstructibleMCTracks)>0:
859 if firsttwo==True:
860 if len(foundhorizontaltrackids)>=len(ReconstructibleMCTracks) : reconstructiblehorizontalidsfound12+=1
861 else :
862 if global_variables.debug:
863 print("!!!!!!!!!!!!!!!! Difference between Y-view tracks found and reconstructible tracks (station 1&2). Quitting patrec.")
864 debugevent(iEvent,False,y2,y3,ymin2,yother,z2,z3,zmin2,zother,foundhorizontaltrackids)
865 return 0,[],[],[],[],[],[],{},{},{},{},{}
866 else:
867 if len(foundhorizontaltrackids)>=len(ReconstructibleMCTracks) : reconstructiblehorizontalidsfound34+=1
868 else :
869 if global_variables.debug:
870 print("!!!!!!!!!!!!!!!! Difference between Y-view tracks found and reconstructible tracks (station 3&4). Quitting patrec.")
871 debugevent(iEvent,False,y2,y3,ymin2,yother,z2,z3,zmin2,zother,foundhorizontaltrackids)
872 return 0,[],[],[],[],[],[],{},{},{},{},{}
873
874 if len(foundhorizontaltrackids) != reconstructiblerequired :
875 if global_variables.debug:
876 print(len(foundhorizontaltrackids), "Y view tracks found, but ", reconstructiblerequired, "required.")
877 return 0,[],[],[],[],[],[],{},{},{},{},{}
878 else:
879 if firsttwo==True: reconstructiblehorizontalidsfound12+=1
880 else: reconstructiblehorizontalidsfound34+=1
881
882
883 if nrtrcandv1==0 :
884 if global_variables.debug:
885 print("0 tracks found in Y view. Reconstructible:", len(ReconstructibleMCTracks))
886 if monitor==True: return 0,[],[],[],[],[],[],{},{},{},{},{}
887 else :
888 if global_variables.debug:
889 print(nrtrcandv1, "tracks found in Y view. Reconstructible:", len(ReconstructibleMCTracks))
890
891 if global_variables.debug:
892 print("***************** Start of Stereo PatRec **************************")
893
894 v2hits={}
895 v2hitsMC={}
896
897 uvview={}
898 j=0
899 rawxhits={}
900 for item in StrawRaw:
901 rawxhits[j]=copy.deepcopy((StrawRaw[item][0],StrawRaw[item][1],StrawRaw[item][3],StrawRaw[item][4],StrawRaw[item][2],StrawRaw[item][6]))
902 if firsttwo==True:
903 if global_variables.debug:
904 print(
905 "rawxhits[", j, "]=", rawxhits[j],
906 "trackid", StrawRawLink[item][0].GetTrackID(),
907 "true x", StrawRawLink[item][0].GetX(),
908 "true y",StrawRawLink[item][0].GetY()
909 )
910 j=j+1
911
912 sortedrawxhits=OrderedDict(sorted(rawxhits.items(),key=lambda t:t[1][4]))
913
914 if global_variables.debug:
915 print("stereo view hits ordered by plane:")
916 for i in range(i1,i2+1):
917 xb=[]
918 yb=[]
919 xt=[]
920 yt=[]
921 c=[]
922 d=[]
923 for item in sortedrawxhits:
924 if (float(sortedrawxhits[item][4])==float(zlayerv2[i][0])) :
925 xt.append(float(sortedrawxhits[item][0]))
926 yt.append(float(sortedrawxhits[item][1]))
927 xb.append(float(sortedrawxhits[item][2]))
928 yb.append(float(sortedrawxhits[item][3]))
929
930 c.append(item)
931
932 d.append(float(sortedrawxhits[item][5]))
933 uvview[i]=[xb,yb,xt,yt,c,d]
934
935 if global_variables.debug:
936 print(
937 ' uv hits, z,xb,yb,xt,yt,dist ',
938 i, zlayerv2[i], uvview[i][0], uvview[i][1], uvview[i][2],
939 uvview[i][3], uvview[i][4], uvview[i][5]
940 )
941
942
943
944
945
946
947 ntracks=0
948 trackkey=0
949 tracks={}
950 if global_variables.debug:
951 if (firsttwo==True) :
952 print('Loop over tracks found in Y view, stations 1&2')
953 else :
954 print('Loop over tracks found in Y view, stations 3&4')
955
956 foundstereotrackids=[]
957 foundtrackids=[]
958
959 for t in trcandv1:
960 alltrackids=[]
961 y11trackids=[]
962 y12trackids=[]
963 y21trackids=[]
964 y22trackids=[]
965 y11hitids=[]
966 y12hitids=[]
967 y21hitids=[]
968 y22hitids=[]
969 trackkey+=1
970
971
972
973 fitt,fitc=fitline(trcandv1[t],hits,zlayer,resolution)
974 if global_variables.debug:
975 print(' Track nr', t, 'in Y view: tangent, constant=', fitt, fitc)
976
977 tan=0.
978 cst=0.
979 px=0.
980 py=0.
981 pz=0.
982 m=0
983 if firsttwo==True: looplist=reversed(list(range(len(trcandv1[t]))))
984 else: looplist=list(range(len(trcandv1[t])))
985 for ipl in looplist:
986 indx= trcandv1[t][ipl]
987 if indx>-1:
988 if global_variables.debug:
989 print(' Plane nr, z-position, y of hit:', ipl, zlayer[ipl], hits[ipl][0][indx])
990 hitpoint=[zlayer[ipl],hits[ipl][0][indx]]
991 rc=h['disthittoYviewtrack'].Fill(dist2line(fitt,fitc,hitpoint))
992
993
994
995 px=StrawRawLink[hits[ipl][2][indx]][0].GetPx()
996 py=StrawRawLink[hits[ipl][2][indx]][0].GetPy()
997 pz=StrawRawLink[hits[ipl][2][indx]][0].GetPz()
998 ptmp=math.sqrt(px**2+py**2+pz**2)
999 if global_variables.debug:
1000 print(" p",ptmp,"px",px,"py",py,"pz",pz)
1001 if tan==0. : tan=py/pz
1002 if cst==0. : cst=StrawRawLink[hits[ipl][2][indx]][0].GetY()-tan*zlayer[ipl][0]
1003 rc=h['disthittoYviewMCtrack'].Fill(dist2line(tan,cst,hitpoint))
1004
1005 if global_variables.debug:
1006 print(' Track nr', t, 'in Y view: MC tangent, MC constant=', tan, cst)
1007
1008 for ipl in range(len(trcandv1[t])):
1009 indx= trcandv1[t][ipl]
1010 if indx>-1:
1011 diffy=hits[ipl][0][indx]-StrawRawLink[hits[ipl][2][indx]][0].GetY()
1012 h['digi-truevstruey'].Fill(diffy)
1013 if ipl<5:
1014 y11trackids.append(StrawRawLink[hits[ipl][2][indx]][0].GetTrackID())
1015 y11hitids.append([hits[ipl][2][indx]][0])
1016 if (ipl>4 and ipl<9):
1017 y12trackids.append(StrawRawLink[hits[ipl][2][indx]][0].GetTrackID())
1018 y12hitids.append([hits[ipl][2][indx]][0])
1019 if (ipl>9 and ipl<13):
1020 y21trackids.append(StrawRawLink[hits[ipl][2][indx]][0].GetTrackID())
1021 y21hitids.append([hits[ipl][2][indx]][0])
1022 if ipl>12:
1023 y22trackids.append(StrawRawLink[hits[ipl][2][indx]][0].GetTrackID())
1024 y22hitids.append([hits[ipl][2][indx]][0])
1025 else:
1026 if ipl<5:
1027 y11trackids.append(999)
1028 y11hitids.append(999)
1029 if (ipl>4 and ipl<9):
1030 y12trackids.append(999)
1031 y12hitids.append(999)
1032 if (ipl>9 and ipl<13):
1033 y21trackids.append(999)
1034 y21hitids.append(999)
1035 if ipl>12:
1036 y22trackids.append(999)
1037 y22hitids.append(999)
1038
1039
1040
1041 v2y2=[]
1042 v2y3=[]
1043 v2yother=[]
1044 v2ymin2=[]
1045 v2z2=[]
1046 v2z3=[]
1047 v2zother=[]
1048 v2zmin2=[]
1049 for ipl in range(1,len(zlayerv2)+1):
1050 items=[]
1051 xclean=[]
1052 distances=[]
1053 if cheated==False:
1054 xclean,items=line2plane(fitt,fitc,uvview[ipl],zlayerv2[ipl][0])
1055
1056 else:
1057 xclean=copy.deepcopy(uvview[ipl][0])
1058 items=copy.deepcopy(uvview[ipl][4])
1059
1060 distances=copy.deepcopy(uvview[ipl][5])
1061 xcleanunsorted=[]
1062 xcleanunsorted=list(xclean)
1063
1064 xclean.sort()
1065 b=len(xclean)*[0]
1066 d=[]
1067 e=[]
1068 for item in xclean:
1069 d.append(items[xcleanunsorted.index(item)])
1070 e.append(distances[xcleanunsorted.index(item)])
1071
1072 v2hits[ipl]=[xclean,b,d,e]
1073 if global_variables.debug:
1074 print(' Plane,z, projected hits:', ipl , zlayerv2[ipl], v2hits[ipl])
1075
1076 for item in range(len(v2hits[ipl][0])):
1077 if StrawRawLink[v2hits[ipl][2][item]][0].GetTrackID() == 3:
1078 v2y3.append(float(v2hits[ipl][0][item]))
1079 v2z3.append(float(zlayerv2[ipl][0]))
1080 else:
1081 if StrawRawLink[v2hits[ipl][2][item]][0].GetTrackID() == 2:
1082 v2y2.append(float(v2hits[ipl][0][item]))
1083 v2z2.append(float(zlayerv2[ipl][0]))
1084 else:
1085 if StrawRawLink[v2hits[ipl][2][item]][0].GetTrackID() == -2:
1086 v2ymin2.append(float(v2hits[ipl][0][item]))
1087 v2zmin2.append(float(zlayerv2[ipl][0]))
1088 else:
1089 v2yother.append(float(v2hits[ipl][0][item]))
1090 v2zother.append(float(zlayerv2[ipl][0]))
1091
1092
1093
1094
1095 if cheated==True:
1096 nrtrcandv2,trcandv2=ptrack(zlayerv2,v2hits,7,0.7)
1097 else:
1098 nrtrcandv2,trcandv2=ptrack(zlayerv2,v2hits,6,15.)
1099 if len(trcandv2)>1:
1100 if global_variables.debug:
1101 print(" len(trcandv2) in stereo", len(trcandv2))
1102
1103 nstereotracks=0
1104 if nrtrcandv2==0 :
1105 if global_variables.debug:
1106 print(" 0 tracks found in stereo view, for Y-view track nr", t)
1107
1108
1109
1110
1111
1112 for t1 in trcandv2:
1113 if global_variables.debug:
1114 print(' Track belonging to Y-view view track', t, 'found in stereo view:', t1, trcandv2[t1])
1115
1116 stereofitt,stereofitc=fitline(trcandv2[t1],v2hits,zlayerv2,resolution)
1117
1118 pxMC=0.
1119 pzMC=0.
1120 stereotanMCv=0.
1121 stereocstMCv=0.
1122 if firsttwo==True: looplist=reversed(list(range(len(trcandv2[t1]))))
1123 else: looplist=list(range(len(trcandv2[t1])))
1124 for ipl in looplist:
1125 indx= trcandv2[t1][ipl]
1126 if indx>-1:
1127 hitpointx=[zlayerv2[ipl],v2hits[ipl][0][indx]]
1128 rc=h['disthittostereotrack'].Fill(dist2line(stereofitt,stereofitc,hitpointx))
1129 if pxMC==0. : pxMC=StrawRawLink[v2hits[ipl][2][indx]][0].GetPx()
1130 if pzMC ==0. : pzMC=StrawRawLink[v2hits[ipl][2][indx]][0].GetPz()
1131 if stereotanMCv==0. : stereotanMCv=pxMC/pzMC
1132 if stereocstMCv==0. : stereocstMCv=StrawRawLink[v2hits[ipl][2][indx]][0].GetX()-stereotanMCv*zlayerv2[ipl][0]
1133 rc=h['disthittostereoMCtrack'].Fill(dist2line(stereotanMCv,stereocstMCv,hitpointx))
1134
1135
1136 stereotrackids=[]
1137
1138 stereo11trackids=[]
1139 stereo12trackids=[]
1140 stereo21trackids=[]
1141 stereo22trackids=[]
1142 stereo11hitids=[]
1143 stereo12hitids=[]
1144 stereo21hitids=[]
1145 stereo22hitids=[]
1146 nstereotracks+=1
1147
1148
1149 for ipl in range(len(trcandv2[t1])):
1150 indx= trcandv2[t1][ipl]
1151 if indx>-1:
1152 stereotrackids.append(StrawRawLink[v2hits[ipl][2][indx]][0].GetTrackID())
1153 if global_variables.debug:
1154 print(
1155 " plane nr, zpos, x of hit, hitid, trackid",
1156 ipl, zlayerv2[ipl], v2hits[ipl][0][indx], v2hits[ipl][2][indx],
1157 StrawRawLink[v2hits[ipl][2][indx]][0].GetTrackID()
1158 )
1159 xdiff=v2hits[ipl][0][indx]-StrawRawLink[v2hits[ipl][2][indx]][0].GetX()
1160 h['digi-truevstruex'].Fill(xdiff)
1161 if ipl<5:
1162 if indx>-1:
1163 stereo11trackids.append(StrawRawLink[v2hits[ipl][2][indx]][0].GetTrackID())
1164 stereo11hitids.append(v2hits[ipl][2][indx])
1165 else:
1166 stereo11trackids.append(999)
1167 stereo11hitids.append(999)
1168 if (ipl>4 and ipl<9):
1169 if indx>-1:
1170 stereo12trackids.append(StrawRawLink[v2hits[ipl][2][indx]][0].GetTrackID())
1171 stereo12hitids.append(v2hits[ipl][2][indx])
1172 else:
1173 stereo12trackids.append(999)
1174 stereo12hitids.append(999)
1175 if (ipl>9 and ipl<13):
1176 if indx>-1:
1177 stereo21trackids.append(StrawRawLink[v2hits[ipl][2][indx]][0].GetTrackID())
1178 stereo21hitids.append(v2hits[ipl][2][indx])
1179 else:
1180 stereo21trackids.append(999)
1181 stereo21hitids.append(999)
1182 if ipl>12:
1183 if indx>-1:
1184 stereo22trackids.append(StrawRawLink[v2hits[ipl][2][indx]][0].GetTrackID())
1185 stereo22hitids.append(v2hits[ipl][2][indx])
1186 else:
1187 stereo22trackids.append(999)
1188 stereo22hitids.append(999)
1189
1190 if firsttwo==True: h['fracsame12-stereo'].Fill(fracMCsame(stereotrackids)[0])
1191 else: h['fracsame34-stereo'].Fill(fracMCsame(stereotrackids)[0])
1192
1193 if global_variables.debug:
1194 print(" Largest fraction of hits in stereo view:",fracMCsame(stereotrackids)[0],"on MC track with id",fracMCsame(stereotrackids)[1])
1195
1196 if monitor==True: print(" fracMCsame(stereotrackids)[1]", fracMCsame(stereotrackids)[1],"foundhorizontaltrackids[",t-1,"]",foundhorizontaltrackids[t-1])
1197
1198 if monitor==True:
1199 if fracMCsame(stereotrackids)[1] != horizontaltrackids[t-1] :
1200 if global_variables.debug:
1201 print(
1202 " Stereo track with trackid",
1203 fracMCsame(stereotrackids)[1],
1204 "does not belong to the Y-view track with id=",
1205 horizontaltrackids[t-1]
1206 )
1207 continue
1208
1209
1210 if fracMCsame(stereotrackids)[1] in ReconstructibleMCTracks:
1211 if fracMCsame(stereotrackids)[1] not in foundstereotrackids:
1212 foundstereotrackids.append(fracMCsame(stereotrackids)[1])
1213 else:
1214 if global_variables.debug:
1215 print(
1216 " Stereo track with trackid",
1217 fracMCsame(stereotrackids)[1],
1218 "is not reconstructible. Removing it."
1219 )
1220 continue
1221 else:
1222 if fracMCsame(stereotrackids)[1] not in foundstereotrackids:
1223 foundstereotrackids.append(fracMCsame(stereotrackids)[1])
1224
1225 ntracks=ntracks+1
1226 alltrackids=y11trackids+stereo11trackids+stereo12trackids+y12trackids+y21trackids+stereo21trackids+stereo22trackids+y22trackids
1227 if firsttwo==True: h['fracsame12'].Fill(fracMCsame(alltrackids)[0])
1228 else: h['fracsame34'].Fill(fracMCsame(alltrackids)[0])
1229 if global_variables.debug:
1230 print(
1231 " Largest fraction of hits in horizontal and stereo view:", fracMCsame(alltrackids)[0],
1232 "on MC track with id", fracMCsame(alltrackids)[1]
1233 )
1234
1235
1236 if monitor==True:
1237 if fracMCsame(alltrackids)[1] in ReconstructibleMCTracks:
1238 if fracMCsame(alltrackids)[1] not in foundtrackids:
1239 foundtrackids.append(fracMCsame(alltrackids)[1])
1240
1241 tracks[trackkey*1000+nstereotracks]=alltrackids
1242 hitids[trackkey*1000+nstereotracks]=y11hitids+stereo11hitids+stereo12hitids+y12hitids+y21hitids+stereo21hitids+stereo22hitids+y22hitids
1243 if cheated==False :
1244 ytan[trackkey*1000+nstereotracks]=fitt
1245 ycst[trackkey*1000+nstereotracks]=fitc
1246 else:
1247 ytan[trackkey*1000+nstereotracks]=tan
1248 ycst[trackkey*1000+nstereotracks]=cst
1249
1250
1251 fraction[trackkey*1000+nstereotracks]=fracMCsame(alltrackids)[0]
1252 trackid[trackkey*1000+nstereotracks]=fracMCsame(alltrackids)[1]
1253
1254
1255 horpx[trackkey*1000+nstereotracks]=px
1256 horpy[trackkey*1000+nstereotracks]=py
1257 horpz[trackkey*1000+nstereotracks]=pz
1258
1259 if cheated==False:
1260 stereotan[trackkey*1000+nstereotracks]=stereofitt
1261 stereocst[trackkey*1000+nstereotracks]=stereofitc
1262 else:
1263 stereotan[trackkey*1000+nstereotracks]=stereotanMCv
1264 stereocst[trackkey*1000+nstereotracks]=stereocstMCv
1265 else:
1266 if global_variables.debug:
1267 print("Track with trackid", fracMCsame(alltrackids)[1], "is not reconstructible. Removing it.")
1268 continue
1269 else:
1270 if fracMCsame(alltrackids)[1] not in foundtrackids:
1271 foundtrackids.append(fracMCsame(alltrackids)[1])
1272
1273 tracks[trackkey*1000+nstereotracks]=alltrackids
1274 hitids[trackkey*1000+nstereotracks]=y11hitids+stereo11hitids+stereo12hitids+y12hitids+y21hitids+stereo21hitids+stereo22hitids+y22hitids
1275 if cheated==False :
1276 ytan[trackkey*1000+nstereotracks]=fitt
1277 ycst[trackkey*1000+nstereotracks]=fitc
1278 else:
1279 ytan[trackkey*1000+nstereotracks]=tan
1280 ycst[trackkey*1000+nstereotracks]=cst
1281
1282
1283 fraction[trackkey*1000+nstereotracks]=fracMCsame(alltrackids)[0]
1284 trackid[trackkey*1000+nstereotracks]=fracMCsame(alltrackids)[1]
1285
1286
1287 horpx[trackkey*1000+nstereotracks]=px
1288 horpy[trackkey*1000+nstereotracks]=py
1289 horpz[trackkey*1000+nstereotracks]=pz
1290
1291 if cheated==False:
1292 stereotan[trackkey*1000+nstereotracks]=stereofitt
1293 stereocst[trackkey*1000+nstereotracks]=stereofitc
1294 else:
1295 stereotan[trackkey*1000+nstereotracks]=stereotanMCv
1296 stereocst[trackkey*1000+nstereotracks]=stereocstMCv
1297
1298 if monitor==True:
1299 if len(foundstereotrackids)>=len(ReconstructibleMCTracks) :
1300 if firsttwo==True: reconstructiblestereoidsfound12+=1
1301 else: reconstructiblestereoidsfound34+=1
1302 else:
1303 if global_variables.debug:
1304 debugevent(iEvent,True,v2y2,v2y3,v2ymin2,v2yother,v2z2,v2z3,v2zmin2,v2zother,foundstereotrackids)
1305 print("Nbr of reconstructible tracks after stereo",len(foundstereotrackids)," but ",len(ReconstructibleMCTracks)," reconstructible tracks in this event. Quitting.")
1306 return 0,[],[],[],[],[],[],{},{},{},{},{}
1307
1308 if len(foundtrackids)>=len(ReconstructibleMCTracks):
1309 if firsttwo==True: reconstructibleidsfound12+=1
1310 else: reconstructibleidsfound34+=1
1311 else:
1312 if global_variables.debug:
1313 debugevent(iEvent,True,v2y2,v2y3,v2ymin2,v2yother,v2z2,v2z3,v2zmin2,v2zother,foundstereotrackids)
1314 print("Nbr of reconstructed tracks ",len(foundtrackids)," but",len(ReconstructibleMCTracks)," reconstructible tracks in this event. Quitting.")
1315 return 0,[],[],[],[],[],[],{},{},{},{},{}
1316 else:
1317 if firsttwo==True: reconstructiblestereoidsfound12+=1
1318 else: reconstructiblestereoidsfound34+=1
1319 if firsttwo==True: reconstructibleidsfound12+=1
1320 else: reconstructibleidsfound34+=1
1321
1322
1323 return ntracks,tracks,hitids,ytan,ycst,stereotan,stereocst,horpx,horpy,horpz,fraction,trackid
1324