|
| 1 | +package org.jlab.rec.cvt.ml.qcddat; |
| 2 | + |
| 3 | +import org.jlab.rec.cvt.ml.*; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.jlab.clas.reco.ReconstructionEngine; |
| 9 | +import org.jlab.clas.swimtools.Swim; |
| 10 | +import org.jlab.detector.base.DetectorType; |
| 11 | +import org.jlab.io.base.DataBank; |
| 12 | +import org.jlab.io.base.DataEvent; |
| 13 | +import org.jlab.rec.cvt.Constants; |
| 14 | +import org.jlab.rec.cvt.Geometry; |
| 15 | +import org.jlab.rec.cvt.bmt.BMTType; |
| 16 | +import org.jlab.rec.cvt.hit.Hit; |
| 17 | +import org.jlab.utils.groups.IndexedTable; |
| 18 | + |
| 19 | +import org.jlab.geom.prim.Line3D; |
| 20 | +import org.jlab.geom.prim.Arc3D; |
| 21 | +import org.jlab.rec.cvt.banks.HitReader; |
| 22 | + |
| 23 | +/** |
| 24 | + * Service to return reconstructed TRACKS |
| 25 | + * format |
| 26 | + * |
| 27 | + * @author ziegler |
| 28 | + * |
| 29 | + */ |
| 30 | +public class SampleMaker extends ReconstructionEngine { |
| 31 | + |
| 32 | + |
| 33 | + private int Run = -1; |
| 34 | + |
| 35 | + private String svtHitBank; |
| 36 | + |
| 37 | + public SampleMaker(String name) { |
| 38 | + super(name, "ziegler", "6.0"); |
| 39 | + } |
| 40 | + |
| 41 | + public SampleMaker() { |
| 42 | + super("CVTQCDDATEngine", "ziegler", "6.0"); |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + @Override |
| 47 | + public boolean init() { |
| 48 | + this.initConstantsTables(); |
| 49 | + this.registerBanks(); |
| 50 | + return true; |
| 51 | + } |
| 52 | + |
| 53 | + public void registerBanks() { |
| 54 | + this.setSvtHitBank("CVT::QCDDATHit"); |
| 55 | + super.registerOutputBank(this.svtHitBank); |
| 56 | + } |
| 57 | + |
| 58 | + public int getRun(DataEvent event) { |
| 59 | + |
| 60 | + if (event.hasBank("RUN::config") == false) { |
| 61 | + System.err.println("RUN CONDITIONS NOT READ!"); |
| 62 | + return 0; |
| 63 | + } |
| 64 | + |
| 65 | + DataBank bank = event.getBank("RUN::config"); |
| 66 | + int run = bank.getInt("run", 0); |
| 67 | + if(Constants.getInstance().seedingDebugMode) { |
| 68 | + System.out.println("EVENT "+bank.getInt("event", 0)); |
| 69 | + } |
| 70 | + return run; |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + @Override |
| 76 | + public boolean processDataEvent(DataEvent event) { |
| 77 | + |
| 78 | + int run = this.getRun(event); |
| 79 | + Swim swimmer = new Swim(); |
| 80 | + IndexedTable svtStatus = this.getConstantsManager().getConstants(run, "/calibration/svt/status"); |
| 81 | + IndexedTable svtLorentz = this.getConstantsManager().getConstants(run, "/calibration/svt/lorentz_angle"); |
| 82 | + IndexedTable bmtStatus = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_status"); |
| 83 | + IndexedTable bmtTime = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_time"); |
| 84 | + IndexedTable bmtVoltage = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_voltage"); |
| 85 | + IndexedTable bmtStripVoltage = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_strip_voltage"); |
| 86 | + IndexedTable bmtStripThreshold = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_strip_voltage_thresholds"); |
| 87 | + IndexedTable adcStatus = this.getConstantsManager().getConstants(run, "/calibration/svt/adcstatus"); |
| 88 | + |
| 89 | + Geometry.getInstance().initialize(this.getConstantsManager().getVariation(), run, svtLorentz, bmtVoltage); |
| 90 | + |
| 91 | + HitReader hitRead = new HitReader(); |
| 92 | + hitRead.fetch_SVTHits(event, -1, -1, svtStatus, adcStatus); |
| 93 | + hitRead.fetch_BMTHits(event, swimmer, bmtStatus, bmtTime, |
| 94 | + bmtStripVoltage, bmtStripThreshold); |
| 95 | + List<ArrayList<Hit>> hits = new ArrayList<>(); |
| 96 | + if(hitRead.getSVTHits() == null) { |
| 97 | + hits.add(new ArrayList<>()); |
| 98 | + } |
| 99 | + else { |
| 100 | + hits.add((ArrayList<Hit>) hitRead.getSVTHits()); |
| 101 | + } |
| 102 | + if(hitRead.getBMTHits() == null) { |
| 103 | + hits.add(new ArrayList<>()); |
| 104 | + } |
| 105 | + else { |
| 106 | + hits.add((ArrayList<Hit>) hitRead.getBMTHits()); |
| 107 | + } |
| 108 | + |
| 109 | + if (event.hasBank("MC::True")) { |
| 110 | + DataBank mcTrue = event.getBank("MC::True"); |
| 111 | + TrackingPerformance.MatchHitsToMC(hits, mcTrue); |
| 112 | + } |
| 113 | + |
| 114 | + if (hits.isEmpty()) |
| 115 | + return false; |
| 116 | + DataBank bank = event.createBank(this.svtHitBank, hits.get(0).size()+hits.get(1).size()); |
| 117 | + int index=0; |
| 118 | + for(int i = 0; i < hits.size(); i++) { |
| 119 | + for(int j = 0; j < hits.get(i).size(); j++) { |
| 120 | + bank.setShort("id", index, (short) hits.get(i).get(j).getId()); |
| 121 | + bank.setShort("mctid", index, (short) hits.get(i).get(j).getAssociateMCTrkId()); |
| 122 | + bank.setByte("sector", index, (byte) hits.get(i).get(j).getSector()); |
| 123 | + int layer = hits.get(i).get(j).getLayer(); |
| 124 | + if(i>0) layer+=6; |
| 125 | + bank.setByte("layer", index, (byte) layer); |
| 126 | + bank.setShort("strip", index, (short) hits.get(i).get(j).getStrip().getStrip()); |
| 127 | + bank.setFloat("energy", index, (short) hits.get(i).get(j).getStrip().getEdep()); |
| 128 | + bank.setFloat("time", index, (short) hits.get(i).get(j).getStrip().getTime()); |
| 129 | + int mctrue=-1; |
| 130 | + if(hits.get(i).get(j).MCstatus==0) { |
| 131 | + mctrue=0; |
| 132 | + } else { |
| 133 | + mctrue=1; |
| 134 | + } |
| 135 | + bank.setByte("mctrue", index, (byte) mctrue); |
| 136 | + if(hits.get(i).get(j).getDetector()==DetectorType.BST || |
| 137 | + (hits.get(i).get(j).getDetector()==DetectorType.BMT |
| 138 | + && hits.get(i).get(j).getType()==BMTType.Z)) { |
| 139 | + Line3D sline = hits.get(i).get(j).getStrip().getLine(); |
| 140 | + bank.setFloat("x1", index, (float) sline.origin().x()/10); |
| 141 | + bank.setFloat("y1", index, (float) sline.origin().y()/10); |
| 142 | + bank.setFloat("z1", index, (float) sline.origin().z()/10); |
| 143 | + bank.setFloat("x2", index, (float) sline.midpoint().x()/10); |
| 144 | + bank.setFloat("y2", index, (float) sline.midpoint().y()/10); |
| 145 | + bank.setFloat("z2", index, (float) sline.midpoint().z()/10); |
| 146 | + bank.setFloat("x3", index, (float) sline.end().x()/10); |
| 147 | + bank.setFloat("y3", index, (float) sline.end().y()/10); |
| 148 | + bank.setFloat("z3", index, (float) sline.end().z()/10); |
| 149 | + |
| 150 | + } |
| 151 | + if(hits.get(i).get(j).getDetector()==DetectorType.BMT |
| 152 | + && hits.get(i).get(j).getType()==BMTType.C) { |
| 153 | + Arc3D sarc = hits.get(i).get(j).getStrip().getArc(); |
| 154 | + bank.setFloat("x1", index, (float) sarc.origin().x()/10); |
| 155 | + bank.setFloat("y1", index, (float) sarc.origin().y()/10); |
| 156 | + bank.setFloat("z1", index, (float) sarc.origin().z()/10); |
| 157 | + bank.setFloat("x2", index, (float) sarc.point(sarc.theta()/2).x()/10); |
| 158 | + bank.setFloat("y2", index, (float) sarc.point(sarc.theta()/2).y()/10); |
| 159 | + bank.setFloat("z2", index, (float) sarc.point(sarc.theta()/2).z()/10); |
| 160 | + bank.setFloat("x3", index, (float) sarc.end().x()/10); |
| 161 | + bank.setFloat("y3", index, (float) sarc.end().y()/10); |
| 162 | + bank.setFloat("z3", index, (float) sarc.end().z()/10); |
| 163 | + } |
| 164 | + |
| 165 | + index++; |
| 166 | + } |
| 167 | + } |
| 168 | + //bank.show(); |
| 169 | + event.appendBanks(bank); |
| 170 | + |
| 171 | + return true; |
| 172 | + } |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + public void initConstantsTables() { |
| 177 | + String[] tables = new String[]{ |
| 178 | + "/calibration/svt/status", |
| 179 | + "/calibration/svt/lorentz_angle", |
| 180 | + "/calibration/mvt/bmt_time", |
| 181 | + "/calibration/mvt/bmt_status", |
| 182 | + "/calibration/mvt/bmt_voltage", |
| 183 | + "/calibration/mvt/bmt_strip_voltage", |
| 184 | + "/calibration/mvt/bmt_strip_voltage_thresholds", |
| 185 | + "/geometry/beam/position", |
| 186 | + "/calibration/svt/adcstatus" |
| 187 | + }; |
| 188 | + requireConstants(Arrays.asList(tables)); |
| 189 | + this.getConstantsManager().setVariation("default"); |
| 190 | + } |
| 191 | + |
| 192 | + public void setSvtHitBank(String bstHitBank) { |
| 193 | + this.svtHitBank = bstHitBank; |
| 194 | + } |
| 195 | + public String getSvtHitBank() { |
| 196 | + return this.svtHitBank; |
| 197 | + } |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +} |
0 commit comments