1 package org.lcsim.recon.tracking.digitization.sisim.config;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.HashSet;
6 import java.util.List;
7 import java.util.Set;
8
9 import org.lcsim.detector.tracker.silicon.SiSensor;
10 import org.lcsim.event.EventHeader;
11 import org.lcsim.geometry.Detector;
12 import org.lcsim.recon.tracking.digitization.sisim.CDFSiSensorSim;
13 import org.lcsim.recon.tracking.digitization.sisim.GenericReadoutChip;
14 import org.lcsim.recon.tracking.digitization.sisim.Kpix;
15 import org.lcsim.recon.tracking.digitization.sisim.NearestNeighbor;
16 import org.lcsim.recon.tracking.digitization.sisim.PixelHitMaker;
17 import org.lcsim.recon.tracking.digitization.sisim.RawTrackerHitMaker;
18 import org.lcsim.recon.tracking.digitization.sisim.ReadoutChip;
19 import org.lcsim.recon.tracking.digitization.sisim.SiDigitizer;
20 import org.lcsim.recon.tracking.digitization.sisim.SiSensorSim;
21 import org.lcsim.util.Driver;
22
23
24
25
26
27
28
29
30 public class PixelDigiSetupDriver extends Driver
31 {
32
33 private String rawHitsCollectionName;
34 private String trackerHitsCollectionName;
35
36
37 private List<String> subdetectorNames = new ArrayList<String>();
38
39
40 String readoutChipType = "generic";
41 private double noiseIntercept;
42 private double noiseSlope;
43 private double noiseThreshold;
44 private double readoutNeighborThreshold;
45
46
47 private double seedThreshold;
48 private double neighborThreshold;
49
50
51 private int maxClusterSize = 10;
52
53 double oneClusterErr = 1 / Math.sqrt(12);
54 double twoClusterErr = 1 / 5;
55 double threeClusterErr = 1 / 3;
56 double fourClusterErr = 1 / 2;
57 double fiveClusterErr = 1;
58
59 private SimTrackerHitReadoutDriver readoutDriver;
60
61
62 Set<SiSensor> sensorsToProcess = new HashSet<SiSensor>();
63
64
65 SiSensorSim sisim = new CDFSiSensorSim();
66 ReadoutChip readout;
67 SiDigitizer digitizer;
68 PixelHitMaker clusterer;
69
70
71 private boolean wasSetup = false;
72
73 public PixelDigiSetupDriver()
74 {
75 readoutDriver = new SimTrackerHitReadoutDriver();
76 add(readoutDriver);
77 }
78
79 public void setReadoutChipType(String readoutChipType)
80 {
81 this.readoutChipType = readoutChipType;
82 }
83
84 public void setSubdetectorName(String name)
85 {
86 if (!subdetectorNames.contains(name))
87 subdetectorNames.add(name);
88 }
89
90 public void setSubdetectorNames(String names[])
91 {
92 subdetectorNames.addAll(Arrays.asList(names));
93 }
94
95 public void setNoiseIntercept(double noiseIntercept)
96 {
97 this.noiseIntercept = noiseIntercept;
98 }
99
100 public void setNoiseSlope(double noiseSlope)
101 {
102 this.noiseSlope = noiseSlope;
103 }
104
105 public void setNoiseThreshold(double noiseThreshold)
106 {
107 this.noiseThreshold = noiseThreshold;
108 }
109
110 public void setReadoutNeighborThreshold(double readoutNeighborThreshold)
111 {
112 this.readoutNeighborThreshold = readoutNeighborThreshold;
113 }
114
115 public void setSeedThreshold(double seedThreshold)
116 {
117 this.seedThreshold = seedThreshold;
118 }
119
120 public void setNeighborThreshold(double neighborThreshold)
121 {
122 this.neighborThreshold = neighborThreshold;
123 }
124
125 public void setMaxClusterSize(int maxClusterSize)
126 {
127 this.maxClusterSize = maxClusterSize;
128 }
129
130 public void setOneClusterErr(double oneClusterErr)
131 {
132 this.oneClusterErr = oneClusterErr;
133 }
134
135 public void setTwoClusterErr(double twoClusterErr)
136 {
137 this.twoClusterErr = twoClusterErr;
138 }
139
140 public void setThreeClusterErr(double threeClusterErr)
141 {
142 this.threeClusterErr = threeClusterErr;
143 }
144
145 public void setFourClusterErr(double fourClusterErr)
146 {
147 this.fourClusterErr = fourClusterErr;
148 }
149
150 public void setFiveClusterErr(double fiveClusterErr)
151 {
152 this.fiveClusterErr = fiveClusterErr;
153 }
154
155 public void setRawHitsCollectionName(String rawHitsCollectionName)
156 {
157 this.rawHitsCollectionName = rawHitsCollectionName;
158 }
159
160 public void setTrackerHitsCollectionName(String trackerHitsCollectionName)
161 {
162 this.trackerHitsCollectionName = trackerHitsCollectionName;
163 }
164
165 public String getRawHitsCollectionName()
166 {
167 return rawHitsCollectionName;
168 }
169
170 public String getTrackerHitsCollectionName()
171 {
172 return trackerHitsCollectionName;
173 }
174
175 public void detectorChanged(Detector detector)
176 {
177 setupReadoutDriver(detector);
178 setupDigi();
179 super.detectorChanged(detector);
180 }
181
182 private void setupReadoutDriver(Detector detector)
183 {
184 List<String> readouts = new ArrayList<String>();
185 for (String subdetectorName : subdetectorNames)
186 {
187 readouts.add(detector.getSubdetector(subdetectorName).getReadout().getName());
188 }
189 readoutDriver.setCollections(readouts.toArray(new String[] {}));
190 }
191
192 public void setupDigi()
193 {
194 if (wasSetup)
195 return;
196
197
198 if (readoutChipType.toLowerCase().equals("kpix"))
199 {
200 Kpix chip = new Kpix();
201 chip.setNoiseThreshold(noiseThreshold);
202 chip.setNeighborThreshold(readoutNeighborThreshold);
203 }
204 else if (readoutChipType.toLowerCase().equals("generic"))
205 {
206 GenericReadoutChip chip = new GenericReadoutChip();
207 chip.setNoiseIntercept(noiseIntercept);
208 chip.setNoiseSlope(noiseSlope);
209 chip.setNoiseThreshold(noiseThreshold);
210 chip.setNeighborThreshold(readoutNeighborThreshold);
211 this.readout = chip;
212 }
213 else
214 {
215 throw new RuntimeException(readoutChipType + " is not a valid reaodut chip type.");
216 }
217
218 digitizer = new RawTrackerHitMaker(sisim, readout);
219
220 NearestNeighbor clustering = new NearestNeighbor();
221 clustering.setSeedThreshold(seedThreshold);
222 clustering.setNeighborThreshold(neighborThreshold);
223
224 clusterer = new PixelHitMaker(sisim, readout, clustering);
225 clusterer.setMaxClusterSize(maxClusterSize);
226 clusterer.SetOneClusterErr(oneClusterErr);
227 clusterer.SetTwoClusterErr(twoClusterErr);
228 clusterer.SetThreeClusterErr(threeClusterErr);
229 clusterer.SetFourClusterErr(fourClusterErr);
230 clusterer.SetFiveClusterErr(fiveClusterErr);
231
232
233 add(new DigiDriver(
234 digitizer,
235 clusterer,
236 getRawHitsCollectionName(),
237 getTrackerHitsCollectionName(),
238 subdetectorNames));
239
240 wasSetup = true;
241 }
242
243 public void startOfData()
244 {
245 super.startOfData();
246 }
247
248 public void process(EventHeader event)
249 {
250 super.process(event);
251 }
252 }