1 package org.lcsim.event.base;
2
3 import hep.io.sio.SIORef;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.lcsim.event.EventHeader.LCMetaData;
9 import org.lcsim.event.MCParticle;
10 import org.lcsim.event.SimCalorimeterHit;
11
12 public class BaseSimCalorimeterHit extends BaseCalorimeterHit implements SimCalorimeterHit {
13 protected int nContributions;
14 protected Object[] particle;
15 protected float[] energyContrib;
16 protected float[] times;
17 protected int[] pdg;
18 protected List<float[]> steps;
19
20 protected BaseSimCalorimeterHit() {
21 }
22
23 public BaseSimCalorimeterHit(long id,
24 double rawEnergy,
25 double time,
26 Object[] mcparts,
27 float[] energies,
28 float[] times,
29 int[] pdgs,
30 LCMetaData meta) {
31
32 super.id = id;
33 super.rawEnergy = rawEnergy;
34 super.time = time;
35 super.positionVec = null;
36
37
38 this.nContributions = mcparts.length;
39 this.particle = mcparts;
40 this.energyContrib = energies;
41 this.times = times;
42 this.pdg = pdgs;
43 this.steps = new ArrayList(nContributions);
44
45 setMetaData(meta);
46
47
48 calculateCorrectedEnergy();
49 }
50
51
52
53
54 public BaseSimCalorimeterHit(long id,
55 double rawEnergy,
56 double time,
57 Object[] mcparts,
58 float[] energies,
59 float[] times,
60 int[] pdgs,
61 List<float[]> steps,
62 LCMetaData meta) {
63
64 super.id = id;
65 super.rawEnergy = rawEnergy;
66 super.time = time;
67 super.positionVec = null;
68
69
70 this.nContributions = mcparts.length;
71 this.particle = mcparts;
72 this.energyContrib = energies;
73 this.times = times;
74 this.pdg = pdgs;
75 this.steps = steps;
76
77 setMetaData(meta);
78 }
79
80 public void shiftTime(double time) {
81 super.time = this.getTime() + time;
82 for (int i = 0; i < times.length; i++) {
83 times[i] += time;
84 }
85 }
86
87 public double getTime() {
88
89 if (super.time != 0)
90 return super.time;
91
92
93 if (times.length == 0)
94 return 0;
95
96
97 double t = times[0];
98 for (int i = 1; i < times.length; i++) {
99 t = Math.min(t, times[i]);
100 }
101
102
103 super.time = t;
104
105 return t;
106 }
107
108 public MCParticle getMCParticle(int index) {
109 Object p = particle[index];
110 if (p instanceof SIORef)
111 p = ((SIORef) p).getObject();
112 return (MCParticle) p;
113 }
114
115 public double getContributedEnergy(int index) {
116 return energyContrib[index];
117 }
118
119 public int getPDG(int index) {
120 return pdg[index];
121 }
122
123 public double getContributedTime(int index) {
124 return times[index];
125 }
126
127 public float[] getStepPosition(int index) {
128 return steps.get(index);
129 }
130
131 public int getMCParticleCount() {
132 return particle.length;
133 }
134 }