1
2
3
4
5
6
7
8
9
10 package org.lcsim.recon.tracking.digitization.sisim;
11
12 import java.util.ArrayList;
13 import java.util.EnumMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Set;
17 import java.util.SortedMap;
18 import org.lcsim.detector.IDetectorElement;
19 import org.lcsim.detector.IReadout;
20 import org.lcsim.detector.tracker.silicon.ChargeCarrier;
21 import org.lcsim.detector.tracker.silicon.SiSensor;
22 import org.lcsim.event.RawTrackerHit;
23 import org.lcsim.event.SimTrackerHit;
24 import org.lcsim.event.base.BaseRawTrackerHit;
25
26
27
28
29
30 public class RawTrackerHitMaker implements SiDigitizer
31 {
32 private static String _NAME = "RawTrackerHitMaker";
33
34 private SiSensorSim _si_simulation;
35 private ReadoutChip _readout_chip;
36
37 Class _input_type = SimTrackerHit.class;
38 Class _output_type = RawTrackerHit.class;
39
40
41
42
43 public RawTrackerHitMaker(SiSensorSim si_simulation, ReadoutChip readout_chip)
44 {
45 _si_simulation = si_simulation;
46 _readout_chip = readout_chip;
47 }
48
49 public String getName()
50 {
51 return _NAME;
52 }
53
54 public List<RawTrackerHit> makeHits(IDetectorElement detector)
55 {
56 List<RawTrackerHit> raw_hits = new ArrayList<RawTrackerHit>();
57 List<SiSensor> sensors = detector.findDescendants(SiSensor.class);
58
59
60 for (SiSensor sensor : sensors)
61 {
62 raw_hits.addAll(makeHits(sensor));
63 }
64
65
66 return raw_hits;
67 }
68
69
70 public List<RawTrackerHit> makeHits(SiSensor sensor)
71 {
72
73 List<RawTrackerHit> raw_hits = new ArrayList<RawTrackerHit>();
74
75
76 IReadout ro = sensor.getReadout();
77 List<SimTrackerHit> sim_hits = ro.getHits(SimTrackerHit.class);
78
79
80
81
82
83
84
85 _si_simulation.setSensor(sensor);
86 Map<ChargeCarrier,SiElectrodeDataCollection> electrode_data = _si_simulation.computeElectrodeData();
87
88
89 for (ChargeCarrier carrier : ChargeCarrier.values())
90 {
91 if (sensor.hasElectrodesOnSide(carrier))
92 {
93 SortedMap<Integer,List<Integer>> digitized_hits = _readout_chip.readout(electrode_data.get(carrier),sensor.getReadoutElectrodes(carrier));
94
95
96 for (Integer readout_cell : digitized_hits.keySet())
97 {
98 int time = 0;
99 long cell_id = sensor.makeStripId(readout_cell,carrier.charge()).getValue();
100
101
102 List<Integer> readout_data = digitized_hits.get(readout_cell);
103 short[] adc_values = new short[readout_data.size()];
104 for (int i=0; i<readout_data.size(); i++) {
105 adc_values[i] = readout_data.get(i).shortValue();
106 }
107
108 Set<SimTrackerHit> simulated_hits = electrode_data.get(carrier).get(readout_cell).getSimulatedHits();
109 IDetectorElement detector_element = sensor;
110
111 RawTrackerHit raw_hit = new BaseRawTrackerHit(time,cell_id,adc_values,new ArrayList<SimTrackerHit>(simulated_hits),detector_element);
112
113
114 ro.addHit(raw_hit);
115 raw_hits.add(raw_hit);
116 }
117 }
118
119 }
120
121 _si_simulation.clearReadout();
122
123
124
125
126
127
128 return raw_hits;
129 }
130
131
132 }
133