1 package org.lcsim.lcio;
2
3 import hep.io.sio.SIOInputStream;
4 import hep.io.sio.SIOOutputStream;
5 import hep.physics.vec.BasicHep3Vector;
6
7 import java.io.IOException;
8 import java.util.ArrayList;
9
10 import org.lcsim.event.EventHeader.LCMetaData;
11 import org.lcsim.event.SimCalorimeterHit;
12 import org.lcsim.event.base.BaseSimCalorimeterHit;
13
14
15
16
17
18
19 public class SIOSimCalorimeterHit extends BaseSimCalorimeterHit
20 {
21
22 SIOSimCalorimeterHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException
23 {
24 int cellid0 = in.readInt();
25 int cellid1 = 0;
26 if (LCIOUtil.bitTest(flags,LCIOConstants.RCHBIT_ID1) || version==8) {
27 cellid1 = in.readInt();
28 }
29
30 id = ((long) cellid1)<<32 | cellid0;
31 rawEnergy = in.readFloat();
32
33 if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_LONG))
34 {
35 positionVec = new BasicHep3Vector(in.readFloat(), in.readFloat(), in.readFloat());
36 }
37 nContributions = in.readInt();
38 particle = new Object[nContributions];
39 energyContrib = new float[nContributions];
40 times = new float[nContributions];
41 steps = new ArrayList();
42
43 boolean hasPDG = LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_PDG);
44 if (hasPDG) pdg = new int[nContributions];
45 for (int i = 0; i < nContributions; i++)
46 {
47 particle[i] = in.readPntr();
48 energyContrib[i] = in.readFloat();
49 times[i] = in.readFloat();
50 if (hasPDG)
51 {
52 pdg[i] = in.readInt();
53 if(version > 1051)
54 {
55 float[] st = new float[3];
56 st[0] = in.readFloat();
57 st[1] = in.readFloat();
58 st[2] = in.readFloat();
59 steps.add(st);
60 }
61
62 }
63 }
64 if ( version > 1000 ) in.readPTag(this);
65 setMetaData(meta);
66
67
68 calculateCorrectedEnergy();
69 }
70
71 static private float emptyPos[] = new float[3];
72
73 static void write(SimCalorimeterHit hit, SIOOutputStream out, int flags) throws IOException
74 {
75 long cellID = hit.getCellID();
76 out.writeInt((int) cellID);
77 if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_ID1)) out.writeInt((int) (cellID>>32));
78 out.writeFloat((float) hit.getRawEnergy());
79
80 if ((flags & (1 << LCIOConstants.CHBIT_LONG)) != 0)
81 {
82 double[] pos = hit.getPosition();
83 out.writeFloat((float) pos[0]);
84 out.writeFloat((float) pos[1]);
85 out.writeFloat((float) pos[2]);
86 }
87
88 boolean hasPDG = LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_PDG);
89 int n = hit.getMCParticleCount();
90 out.writeInt(n);
91 for (int i = 0; i < n; i++)
92 {
93 out.writePntr(hit.getMCParticle(i));
94 out.writeFloat((float) hit.getContributedEnergy(i));
95 out.writeFloat((float) hit.getContributedTime(i));
96 if (hasPDG)
97 {
98 out.writeInt(hit.getPDG(i));
99 float[] st = hit.getStepPosition(i);
100 if (st == null) st = emptyPos;
101 out.writeFloat(st[0]);
102 out.writeFloat(st[1]);
103 out.writeFloat(st[2]);
104 }
105 }
106 out.writePTag(hit);
107 }
108 }