|
| 1 | +package org.jlab.calibration.detectors; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | +import org.jlab.detector.base.DetectorType; |
| 6 | +import org.jlab.io.base.DataBank; |
| 7 | +import org.jlab.io.base.DataEvent; |
| 8 | + |
| 9 | +/** |
| 10 | + * |
| 11 | + * @author devita |
| 12 | + */ |
| 13 | +public class CTOFCalibrator extends DetectorCalibrator { |
| 14 | + |
| 15 | + public CTOFCalibrator() { |
| 16 | + super(DetectorType.CTOF); |
| 17 | + super.init("CTOF::adc", "CTOF::tdc", "CTOF::hits", "CVTRec::Tracks", |
| 18 | + "REC::Track", "REC::Scintillator", "REC::Particle"); |
| 19 | + } |
| 20 | + @Override |
| 21 | + public boolean isGoodEvent(DataEvent event) { |
| 22 | + |
| 23 | + DataBank part = event.getBank("REC::Particle"); |
| 24 | + if(part.rows()<2 || |
| 25 | + part.getInt("pid", 0)!=11 || |
| 26 | + ((int) (Math.abs(part.getShort("status", 0))/1000))!=2) |
| 27 | + return false; |
| 28 | + else { |
| 29 | + for(int i=1; i<part.rows(); i++) { |
| 30 | + if(part.getByte("charge", i)<0 && |
| 31 | + part.getShort("status", i)>4000) |
| 32 | + return true; |
| 33 | + } |
| 34 | + } |
| 35 | + return false; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public DataBank buildCalibBank(DataEvent event) { |
| 40 | + DataBank part = event.getBank("REC::Particle"); |
| 41 | + DataBank scin = event.getBank("REC::Scintillator"); |
| 42 | + DataBank trac = event.getBank("REC::Track"); |
| 43 | + DataBank cvts = event.getBank("CVTRec::Tracks"); |
| 44 | + DataBank hits = event.getBank("CTOF::hits"); |
| 45 | + DataBank adcs = event.getBank("CTOF::adc"); |
| 46 | + DataBank tdcs = event.getBank("CTOF::tdc"); |
| 47 | + |
| 48 | + Map<Integer,Integer> sinds = new HashMap<>(); |
| 49 | + for(int is=0; is<scin.rows(); is++) { |
| 50 | + int detector = scin.getByte("detector", is); |
| 51 | + if(DetectorType.getType(detector)==DetectorType.CTOF) { |
| 52 | + int pindex = scin.getShort("pindex", is); |
| 53 | + sinds.put(pindex, is); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + Map<Integer,Integer> tinds = new HashMap<>(); |
| 59 | + for(int it=0; it<trac.rows(); it++) { |
| 60 | + int detector = trac.getByte("detector", it); |
| 61 | + if(DetectorType.getType(detector)==DetectorType.CVT) { |
| 62 | + int index = trac.getShort("index", it); |
| 63 | + tinds.put((int) cvts.getShort("ID", index), it); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + int ngood = 0; |
| 68 | + for(int i=0; i<hits.rows(); i++) { |
| 69 | + int tid = hits.getShort("trkID", i); |
| 70 | + if(tid>0 && tinds.containsKey(tid)) { |
| 71 | + int tindex = tinds.get(tid); |
| 72 | + int pindex = trac.getShort("pindex", tindex); |
| 73 | + if(sinds.containsKey(pindex)) |
| 74 | + ngood++; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + if(ngood>0) { |
| 79 | + DataBank calib = event.createBank("CTOF::calib", ngood); |
| 80 | + |
| 81 | + int row =0; |
| 82 | + for(int i=0; i<hits.rows(); i++) { |
| 83 | + int tid = hits.getShort("trkID", i); |
| 84 | + if(tid>0 && tinds.containsKey(tid)) { |
| 85 | + int tindex = tinds.get(tid); |
| 86 | + int pindex = trac.getShort("pindex", tindex); |
| 87 | + if(sinds.containsKey(pindex)) { |
| 88 | + int sindex = sinds.get(pindex); |
| 89 | + calib.setShort("id", row, hits.getShort("id", i)); |
| 90 | + calib.setShort("status", row, hits.getShort("status", i)); |
| 91 | + calib.setShort("trackid", row, hits.getShort("trkID", i)); |
| 92 | + calib.setShort("pindex", row, (short) pindex); |
| 93 | + calib.setShort("component", row, hits.getShort("component", i)); |
| 94 | + calib.setFloat("energy", row, hits.getFloat("energy", i)); |
| 95 | + calib.setFloat("time", row, hits.getFloat("time", i)); |
| 96 | + calib.setFloat("x", row, hits.getFloat("x", i)); |
| 97 | + calib.setFloat("y", row, hits.getFloat("y", i)); |
| 98 | + calib.setFloat("z", row, hits.getFloat("z", i)); |
| 99 | + calib.setFloat("tx", row, scin.getFloat("hx", sindex)); |
| 100 | + calib.setFloat("ty", row, scin.getFloat("hy", sindex)); |
| 101 | + calib.setFloat("tz", row, scin.getFloat("hz", sindex)); |
| 102 | + calib.setInt("pid", row, part.getInt("pid", pindex)); |
| 103 | + calib.setByte("charge", row, part.getByte("charge", pindex)); |
| 104 | + calib.setFloat("px", row, part.getFloat("px", pindex)); |
| 105 | + calib.setFloat("py", row, part.getFloat("py", pindex)); |
| 106 | + calib.setFloat("pz", row, part.getFloat("pz", pindex)); |
| 107 | + calib.setFloat("vx", row, part.getFloat("vx", pindex)); |
| 108 | + calib.setFloat("vy", row, part.getFloat("vy", pindex)); |
| 109 | + calib.setFloat("vz", row, part.getFloat("vz", pindex)); |
| 110 | + calib.setFloat("vt", row, part.getFloat("vt", pindex)); |
| 111 | + calib.setFloat("pathLength", row, scin.getFloat("path", sindex)); |
| 112 | + calib.setFloat("pathLengthThruBar", row, hits.getFloat("pathLengthThruBar", i)); |
| 113 | + calib.setFloat("chi2", row, trac.getFloat("chi2", tindex)); |
| 114 | + calib.setShort("NDF", row, trac.getShort("NDF", tindex)); |
| 115 | + calib.setInt("adc1", row, adcs.getInt("ADC", hits.getShort("adc_idx1", i))); |
| 116 | + calib.setInt("adc2", row, adcs.getInt("ADC", hits.getShort("adc_idx2", i))); |
| 117 | + calib.setInt("tdc1", row, tdcs.getInt("TDC", hits.getShort("tdc_idx1", i))); |
| 118 | + calib.setInt("tdc2", row, tdcs.getInt("TDC", hits.getShort("tdc_idx2", i))); |
| 119 | + row++; |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + return calib; |
| 124 | + } |
| 125 | + return null; |
| 126 | + } |
| 127 | +} |
0 commit comments