1 package org.lcsim.recon.tracking.digitization.sisim.config;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.lcsim.event.EventHeader;
7 import org.lcsim.event.EventHeader.LCMetaData;
8 import org.lcsim.event.SimTrackerHit;
9
10
11
12
13
14
15
16 public class SimTrackerHitReadoutDriver extends CollectionHandler {
17
18 boolean needCleanupDriver = true;
19 static boolean debug = false;
20
21 public SimTrackerHitReadoutDriver() {
22 }
23
24 public SimTrackerHitReadoutDriver(List<String> collectionNames) {
25 super(collectionNames);
26 }
27
28 public SimTrackerHitReadoutDriver(String[] collectionNames) {
29 super(collectionNames);
30 }
31
32 public void setReadoutCollections(String[] collectionNames) {
33 super.setCollections(collectionNames);
34 }
35
36 public void setDebug(boolean debug) {
37 SimTrackerHitReadoutDriver.debug = debug;
38 }
39
40 public void startOfData() {
41 if (needCleanupDriver) {
42 add(new ReadoutCleanupDriver(new ArrayList<String>(collections)));
43 needCleanupDriver = false;
44 }
45 }
46
47 protected void process(EventHeader header) {
48 super.process(header);
49
50 if (debug) {
51 System.out.println(this.getClass().getSimpleName() + " - handling collections");
52
53 for (String cname : this.collections) {
54 System.out.println(" " + cname);
55 }
56 }
57
58 List<List<SimTrackerHit>> collections = header.get(SimTrackerHit.class);
59 for (List<SimTrackerHit> collection : collections) {
60 LCMetaData meta = header.getMetaData(collection);
61 if (canHandle(meta.getName())) {
62 for (SimTrackerHit hit : collection) {
63
64 hit.getDetectorElement().getReadout().addHit(hit);
65 if (debug) {
66 System.out.println("Driver assigned hit " + hit.getExpandedIdentifier().toString() + " to "
67 + hit.getDetectorElement().getName() + " with id " + hit.getDetectorElement().getExpandedIdentifier().toString()
68 + ".");
69 System.out.println(" hit raw: " + hit.getIdentifier().toHexString() + ", DE raw: "
70 + hit.getDetectorElement().getIdentifier().toHexString());
71 System.out.println(" hit pos: " + hit.getPositionVec().toString() + ", DE pos: "
72 + hit.getDetectorElement().getGeometry().getPosition().toString());
73 System.out.println();
74 if (!hit.getDetectorElement().getReadout().getHits(SimTrackerHit.class).contains(hit)) {
75 throw new RuntimeException("Readout of " + hit.getDetectorElement().getName()
76 + " is missing a SimTrackerHit that points to it.");
77 }
78 }
79 }
80 }
81 }
82 }
83 }