1 package org.lcsim.recon.tracking.seedtracker.trackingdrivers.sidloi2;
2
3 import org.lcsim.recon.tracking.digitization.sisim.config.*;
4 import hep.physics.matrix.BasicMatrix;
5 import hep.physics.vec.BasicHep3Vector;
6 import hep.physics.vec.VecOp;
7
8 import java.util.List;
9
10 import org.lcsim.detector.IDetectorElement;
11 import org.lcsim.detector.IRotation3D;
12 import org.lcsim.detector.ITranslation3D;
13 import org.lcsim.detector.RotationPassiveXYZ;
14 import org.lcsim.detector.Transform3D;
15 import org.lcsim.detector.Translation3D;
16 import org.lcsim.detector.solids.Polygon3D;
17 import org.lcsim.detector.solids.Trd;
18 import org.lcsim.detector.tracker.silicon.ChargeCarrier;
19 import org.lcsim.detector.tracker.silicon.SiSensor;
20 import org.lcsim.detector.tracker.silicon.SiSensorElectrodes;
21 import org.lcsim.detector.tracker.silicon.SiStrips;
22 import org.lcsim.geometry.Detector;
23 import org.lcsim.geometry.compact.Subdetector;
24 import org.lcsim.geometry.subdetector.SiTrackerEndcap2;
25 import org.lcsim.util.Driver;
26
27 public class SiTrackerEndcap2SensorSetup extends Driver
28 {
29 String subdetectorName;
30 double readoutPitch = 0.050;
31 double sensePitch = 0.025;
32 double transferEfficiencies[] = {0.986,0.419};
33
34 public SiTrackerEndcap2SensorSetup()
35 {}
36
37 public SiTrackerEndcap2SensorSetup(String subdetectorName)
38 {
39 this.subdetectorName = subdetectorName;
40 }
41
42 public void setSubdetectorName(String subdetectorName)
43 {
44 this.subdetectorName = subdetectorName;
45 }
46
47 public void detectorChanged(Detector detector)
48 {
49 if (subdetectorName == null)
50 throw new RuntimeException("The subdetectorName was not set.");
51
52 Subdetector subdetector = detector.getSubdetector(subdetectorName);
53 if (subdetector instanceof SiTrackerEndcap2)
54 setupSensorDetectorElements(subdetector);
55 else
56 throw new RuntimeException("The subdetector " + subdetectorName + " is not an instance of SiTrackerEndcap.");
57 }
58
59 public void setReadoutPitch(double p)
60 {
61 this.readoutPitch = p;
62 }
63
64 public void setSensePitch(double p)
65 {
66 this.sensePitch = p;
67 }
68
69 public void setTransferEfficiencies(double transferEfficiencies[])
70 {
71 if (transferEfficiencies.length < 2)
72 {
73 throw new IllegalArgumentException("Not enough values in transferEfficiencies array.");
74 }
75 this.transferEfficiencies[0] = transferEfficiencies[0];
76 this.transferEfficiencies[1] = transferEfficiencies[1];
77 }
78
79 private void setupSensorDetectorElements(Subdetector subdet)
80 {
81 for ( IDetectorElement endcap : subdet.getDetectorElement().getChildren() )
82 {
83 for ( IDetectorElement layer : endcap.getChildren() )
84 {
85 for ( IDetectorElement wedge : layer.getChildren() )
86 {
87 for ( IDetectorElement module : wedge.getChildren() )
88 {
89 List<SiSensor> sensors = module.findDescendants(SiSensor.class);
90
91 if (sensors.size() == 0)
92 throw new RuntimeException("No sensors found in module.");
93
94 for (SiSensor sensor : sensors)
95 {
96 Trd sensor_solid = (Trd)sensor.getGeometry().getLogicalVolume().getSolid();
97
98 Polygon3D inside = sensor_solid.getFacesNormalTo(new BasicHep3Vector(0,-1,0)).get(0);
99 Polygon3D outside = sensor_solid.getFacesNormalTo(new BasicHep3Vector(0,1,0)).get(0);
100
101 Polygon3D n_side = inside;
102 Polygon3D p_side = outside;
103
104
105 sensor.setBiasSurface(ChargeCarrier.HOLE,p_side);
106 sensor.setBiasSurface(ChargeCarrier.ELECTRON,n_side);
107
108 double strip_angle = Math.atan2(sensor_solid.getXHalfLength2() - sensor_solid.getXHalfLength1(), sensor_solid.getZHalfLength() * 2);
109
110 ITranslation3D electrodes_position = new Translation3D(VecOp.mult(-p_side.getDistance(),new BasicHep3Vector(0,0,1)));
111 IRotation3D electrodes_rotation = new RotationPassiveXYZ(-Math.PI/2,0,strip_angle);
112 Transform3D electrodes_transform = new Transform3D(electrodes_position, electrodes_rotation);
113
114
115 SiSensorElectrodes readout_electrodes = new SiStrips(ChargeCarrier.HOLE,this.readoutPitch,sensor,electrodes_transform);
116 SiSensorElectrodes sense_electrodes = new SiStrips(ChargeCarrier.HOLE,this.sensePitch,(readout_electrodes.getNCells()*2-1),sensor,electrodes_transform);
117
118 sensor.setSenseElectrodes(sense_electrodes);
119 sensor.setReadoutElectrodes(readout_electrodes);
120
121 double[][] transfer_efficiencies = { transferEfficiencies };
122 sensor.setTransferEfficiencies(ChargeCarrier.HOLE,new BasicMatrix(transfer_efficiencies));
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130
131