File indexing completed on 2025-01-30 09:14:58
0001 import ROOT
0002 import argparse, math
0003
0004 from ROOT import TCanvas, TFile, TTree, TLine, TArrow, gStyle
0005 from array import array
0006
0007 if "__main__" == __name__:
0008 p = argparse.ArgumentParser()
0009
0010 p.add_argument(
0011 "-i",
0012 "--input",
0013 type=str,
0014 default="",
0015 help="Input file with material tracks used from the mapping",
0016 )
0017 p.add_argument(
0018 "-o",
0019 "--output",
0020 type=str,
0021 default="",
0022 help="Output file with material mapping analysis",
0023 )
0024 p.add_argument(
0025 "-d",
0026 "--distance",
0027 type=float,
0028 default=50,
0029 help="Maximum distance to the surface",
0030 )
0031 p.add_argument(
0032 "-e",
0033 "--entries",
0034 type=int,
0035 default=10000,
0036 help="Number of draw entries",
0037 )
0038 p.add_argument(
0039 "--z-range",
0040 type=float,
0041 nargs=2,
0042 default=[-3000, 3000],
0043 help="Drawing z range",
0044 )
0045 p.add_argument(
0046 "--r-range",
0047 type=float,
0048 nargs=2,
0049 default=[0, 1200],
0050 help="Drawing z range",
0051 )
0052
0053 p.add_argument(
0054 "--arrows",
0055 action=argparse.BooleanOptionalAction,
0056 help="Draw arrows for the material projection",
0057 default=False,
0058 )
0059
0060 p.add_argument(
0061 "--eta-lines",
0062 type=float,
0063 nargs="+",
0064 default=[
0065 -3.5,
0066 -3.25,
0067 -3,
0068 -2.75,
0069 -2.5,
0070 -2.25,
0071 -2,
0072 -1.75,
0073 -1.5,
0074 -1.25,
0075 -1,
0076 -0.75,
0077 -0.5,
0078 -0.25,
0079 0,
0080 0.25,
0081 0.5,
0082 0.75,
0083 1,
0084 1.25,
0085 1.5,
0086 1.75,
0087 2,
0088 2.25,
0089 2.5,
0090 2.75,
0091 3,
0092 3.25,
0093 3.5,
0094 ],
0095 help="Drawing z range",
0096 )
0097
0098 args = p.parse_args()
0099
0100
0101 if args.input == "":
0102 print("** ERROR ** The input file must be provided")
0103 exit(1)
0104
0105
0106 gStyle.SetOptStat(0)
0107 gStyle.SetOptTitle(0)
0108
0109
0110 tfile = TFile.Open(args.input, "READ")
0111 ttree = tfile.Get("material-tracks")
0112
0113
0114 def theta_from_eta(eta):
0115 return 2 * math.atan(math.exp(-eta))
0116
0117
0118 theta_cut = math.atan2(args.r_range[1], args.z_range[1])
0119
0120
0121 def draw_eta_line(
0122 eta: float, theta_cut, z_max=args.z_range[1], r_max=args.r_range[1]
0123 ):
0124 theta = theta_from_eta(eta)
0125
0126 if theta > theta_cut and theta < math.pi - theta_cut:
0127 r_line = r_max
0128 z_line = r_line / math.tan(theta)
0129 else:
0130
0131 z_line = z_max
0132 if theta > 0.5 * math.pi:
0133 z_line = args.z_range[0]
0134 r_line = z_line * math.tan(theta)
0135
0136 line = TLine(0, 0, z_line, r_line)
0137 line.SetLineColor(ROOT.kGray)
0138 if not float(eta).is_integer():
0139 if float(eta) % 1 == 0.25 or float(eta) % 1 == 0.75:
0140 line.SetLineStyle(ROOT.kDotted)
0141 else:
0142 line.SetLineStyle(ROOT.kDashed)
0143 return line
0144
0145 c = TCanvas("CheckCanvas", "Check Material Mapping", 1200, 1200)
0146 c.Divide(1, 2)
0147
0148 lines_store = []
0149
0150
0151 c.cd(1)
0152 hcmd = f"mat_r:mat_z>>d1(100,{args.z_range[0]},{args.z_range[1]},100,{args.r_range[0]},{args.r_range[1]})"
0153 ttree.Draw(
0154 hcmd,
0155 "sur_distance>" + str(args.distance) + "; z [mm]; r [mm]",
0156 "colz",
0157 args.entries,
0158 )
0159 ttree.Draw("sur_r:sur_z", "", "same", args.entries)
0160
0161 for eta in args.eta_lines:
0162 eta_line = draw_eta_line(eta, theta_cut)
0163 if eta_line:
0164 eta_line.Draw("same")
0165 lines_store.append(eta_line)
0166 c.Update()
0167
0168
0169 c.cd(2)
0170 hcmd = f"mat_r:mat_z>>d2(100,{args.z_range[0]},{args.z_range[1]},100,{args.r_range[0]},{args.r_range[1]})"
0171 ttree.Draw(hcmd + "; z [mm]; r [mm]", "", "", args.entries)
0172
0173 for ie in range(args.entries):
0174 ttree.GetEntry(ie)
0175 steps = len(ttree.sur_distance)
0176 for si, sd in enumerate(ttree.sur_distance):
0177 if sd > args.distance:
0178 if args.arrows:
0179 line = TArrow(
0180 ttree.mat_z[si],
0181 ttree.mat_r[si],
0182 ttree.sur_z[si],
0183 ttree.sur_r[si],
0184 0.01,
0185 ">",
0186 )
0187 line.SetLineColor(ROOT.kRed)
0188 line.Draw(">")
0189 else:
0190 line = TLine(
0191 ttree.sur_z[si],
0192 ttree.sur_r[si],
0193 ttree.mat_z[si],
0194 ttree.mat_r[si],
0195 )
0196 line.SetLineColor(ROOT.kRed)
0197 line.Draw("same")
0198 lines_store.append(line)
0199
0200 for eta in args.eta_lines:
0201 eta_line = draw_eta_line(eta, theta_cut)
0202 if eta_line:
0203 eta_line.Draw("same")
0204 lines_store.append(eta_line)