View Javadoc

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.RawTrackerHitMaker;
17  import org.lcsim.recon.tracking.digitization.sisim.ReadoutChip;
18  import org.lcsim.recon.tracking.digitization.sisim.SiDigitizer;
19  import org.lcsim.recon.tracking.digitization.sisim.SiSensorSim;
20  import org.lcsim.recon.tracking.digitization.sisim.StripHitMaker;
21  import org.lcsim.util.Driver;
22  
23  /**
24   * Driver for configuring and running the tracking digitization for strip detectors.
25   * Accepts a number of parameters related to clustering and readout chip, as well
26   * as a list of subdetectors and the name of the output digit collections. 
27   * 
28   * @author jeremym
29   */
30  public class StripDigiSetupDriver extends Driver
31  {	
32  	// Output collection names.
33  	private String rawHitsCollectionName;
34  	private String trackerHitsCollectionName;
35  	
36  	// Subdetector names.
37  	private List<String> subdetectorNames = new ArrayList<String>();
38  
39  	// Readout chip parameters.
40  	String readoutChipType = "generic";
41  	private double noiseIntercept;
42  	private double noiseSlope;
43  	private double noiseThreshold;
44  	private double readoutNeighborThreshold;
45  	
46  	// NN clustering algorithm parameters.
47  	private double seedThreshold;
48  	private double neighborThreshold;
49  	
50  	// Clustering parameters.	
51  	private int maxClusterSize;
52  	private int centralStripAveragingThreshold;
53  	private double oneClusterErr;
54  	private double twoClusterErr;
55  	private double threeClusterErr;
56  	private double fourClusterErr;
57  	private double fiveClusterErr;
58  	
59  	private SimTrackerHitReadoutDriver readoutDriver;
60  	
61  	// List of sensors to process.
62  	Set<SiSensor> sensorsToProcess = new HashSet<SiSensor>();	
63  	
64  	// Objects for running the digitization. These are setup in the detectorChanged() method.
65  	SiSensorSim sisim = new CDFSiSensorSim();
66  	ReadoutChip readout;	
67  	SiDigitizer digitizer;
68  	StripHitMaker clusterer;
69  			
70  	// Setup flag.
71  	private boolean wasSetup = false;
72  	
73  	public StripDigiSetupDriver()
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[] collectionNames)
91      {
92      	subdetectorNames.addAll(Arrays.asList(collectionNames));
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 setCentralStripAveragingThreshold(int centralStripAveragingThreshold)
131 	{
132 		this.centralStripAveragingThreshold = centralStripAveragingThreshold;
133 	}
134 	
135 	public void setOneClusterErr(double oneClusterErr)
136 	{
137 		this.oneClusterErr = oneClusterErr;
138 	}
139 	
140 	public void setTwoClusterErr(double twoClusterErr)
141 	{
142 		this.twoClusterErr = twoClusterErr;
143 	}
144 	
145 	public void setThreeClusterErr(double threeClusterErr)
146 	{
147 		this.threeClusterErr = threeClusterErr;
148 	}
149 	
150 	public void setFourClusterErr(double fourClusterErr)
151 	{
152 		this.fourClusterErr = fourClusterErr;
153 	}
154 	
155 	public void setFiveClusterErr(double fiveClusterErr)
156 	{
157 		this.fiveClusterErr = fiveClusterErr;
158 	}
159 	
160 	public void setRawHitsCollectionName(String rawHitsCollectionName)
161 	{
162 		this.rawHitsCollectionName = rawHitsCollectionName;
163 	}
164 	
165 	public void setTrackerHitsCollectionName(String trackerHitsCollectionName)
166 	{
167 		this.trackerHitsCollectionName = trackerHitsCollectionName;
168 	}
169 	
170 	public String getRawHitsCollectionName()
171 	{
172 		return rawHitsCollectionName;
173 	}
174 	
175 	public String getTrackerHitsCollectionName()
176 	{
177 		return trackerHitsCollectionName;
178 	}
179 	
180 	public void detectorChanged(Detector detector)
181 	{			
182 		setupReadoutDriver(detector);
183 		setupDigi();
184 		super.detectorChanged(detector);
185 	}
186 	
187 	private void setupReadoutDriver(Detector detector)
188 	{
189 		List<String> readouts = new ArrayList<String>();
190 		for (String subdetectorName : subdetectorNames)
191 		{
192 			readouts.add(detector.getSubdetector(subdetectorName).getReadout().getName());
193 		}
194 //		readoutDriver.setCollections(readouts.toArray(new String[] {}));
195                 add(new SimTrackerHitReadoutDriver(readouts));
196 	}
197 		
198 	public void setupDigi()
199 	{
200 		if (wasSetup)
201 			return;
202 		
203 		// Setup Kpix or Generic readout chip.
204 		if (readoutChipType.toLowerCase().equals("kpix"))
205 		{
206 			Kpix chip = new Kpix();
207 			chip.setNoiseThreshold(noiseThreshold);
208 			chip.setNeighborThreshold(readoutNeighborThreshold);
209 		}
210 		else if (readoutChipType.toLowerCase().equals("generic"))
211 		{
212 			GenericReadoutChip chip = new GenericReadoutChip();
213 			chip.setNoiseIntercept(noiseIntercept);
214 			chip.setNoiseSlope(noiseSlope);
215 			chip.setNoiseThreshold(noiseThreshold);
216 			chip.setNeighborThreshold(readoutNeighborThreshold);
217 			this.readout = chip;
218 		}
219 		else
220 		{
221 			throw new RuntimeException(readoutChipType + " is not a valid reaodut chip type.");
222 		}
223 				
224 		digitizer = new RawTrackerHitMaker(sisim, readout);
225 		
226 		NearestNeighbor clustering = new NearestNeighbor();
227 		clustering.setSeedThreshold(seedThreshold);
228 		clustering.setNeighborThreshold(neighborThreshold);
229 		  
230 		clusterer = new StripHitMaker(sisim, readout, clustering);
231 		clusterer.setMaxClusterSize(maxClusterSize);
232 		clusterer.setCentralStripAveragingThreshold(centralStripAveragingThreshold);
233 		clusterer.SetOneClusterErr(oneClusterErr);
234 		clusterer.SetTwoClusterErr(twoClusterErr);
235 		clusterer.SetThreeClusterErr(threeClusterErr);
236 		clusterer.SetFourClusterErr(fourClusterErr);
237 		clusterer.SetFiveClusterErr(fiveClusterErr);
238 		
239 		// Add driver to run the digitization.
240 		add(new DigiDriver(
241 				digitizer,
242 				clusterer,
243 				getRawHitsCollectionName(),
244 				getTrackerHitsCollectionName(),
245 				subdetectorNames));
246 		
247 		wasSetup = true;
248 	}
249 		
250 	public void process(EventHeader event)
251 	{
252 		super.process(event);		
253 	}	
254 }