|
| 1 | +package org.jlab.clas.timeline.histograms; |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +// import org.jlab.clas.pdg.PhysicsConstants; |
| 5 | + |
| 6 | +import org.jlab.groot.data.H1F; |
| 7 | +// import org.jlab.groot.data.H2F; |
| 8 | +import org.jlab.groot.math.F1D; |
| 9 | +// import org.jlab.groot.fitter.DataFitter; |
| 10 | +import org.jlab.io.base.DataBank; |
| 11 | +import org.jlab.io.base.DataEvent; |
| 12 | +import org.jlab.groot.data.TDirectory; |
| 13 | +// import org.jlab.clas.physics.Particle; |
| 14 | +import org.jlab.utils.groups.IndexedTable; |
| 15 | +// import org.jlab.detector.calib.utils.CalibrationConstants; |
| 16 | +import org.jlab.detector.calib.utils.ConstantsManager; |
| 17 | +/** |
| 18 | + * |
| 19 | + * @author sangbaek |
| 20 | + */ |
| 21 | +public class ALERT { |
| 22 | + |
| 23 | + boolean userTimeBased; |
| 24 | + public int runNum, trigger; |
| 25 | + public long trigger_word; |
| 26 | + public String outputDir; |
| 27 | + |
| 28 | + public boolean hasRF; |
| 29 | + public double startTime, rfTime; |
| 30 | + |
| 31 | + public double rfPeriod; |
| 32 | + public int rf_large_integer; |
| 33 | + |
| 34 | + //Hodoscope |
| 35 | + public H1F[] TDC; |
| 36 | + private H1F bits; |
| 37 | + |
| 38 | + public IndexedTable rfTable; |
| 39 | + |
| 40 | + public ConstantsManager ccdb; |
| 41 | + private float tdc_bin_time = 0.015625f; // ns/bin |
| 42 | + |
| 43 | + public ALERT(int reqrunNum, String reqOutputDir, float reqEb, boolean reqTimeBased) { |
| 44 | + runNum = reqrunNum; |
| 45 | + outputDir = reqOutputDir; |
| 46 | + userTimeBased = reqTimeBased; |
| 47 | + |
| 48 | + startTime = -1000; |
| 49 | + rfTime = -1000; |
| 50 | + trigger = 0; |
| 51 | + |
| 52 | + rfPeriod = 4.008; |
| 53 | + ccdb = new ConstantsManager(); |
| 54 | + ccdb.init(Arrays.asList(new String[]{"/daq/tt/fthodo", "/calibration/eb/rf/config"})); |
| 55 | + rfTable = ccdb.getConstants(runNum, "/calibration/eb/rf/config"); |
| 56 | + if (rfTable.hasEntry(1, 1, 1)) { |
| 57 | + System.out.println(String.format("RF period from ccdb for run %d: %f", runNum, rfTable.getDoubleValue("clock", 1, 1, 1))); |
| 58 | + rfPeriod = rfTable.getDoubleValue("clock", 1, 1, 1); |
| 59 | + } |
| 60 | + rf_large_integer = 1000; |
| 61 | + |
| 62 | + //Hodoscope Histograms |
| 63 | + TDC = new H1F[720]; |
| 64 | + |
| 65 | + for (int index = 0; index < 720; index++) { |
| 66 | + int sector = 0; |
| 67 | + int layer = 0; |
| 68 | + int component = 0; |
| 69 | + int order = 0; |
| 70 | + |
| 71 | + sector = index / (12 * 4); |
| 72 | + layer = (index % (12 * 4)) / 12; |
| 73 | + component = index % 12; |
| 74 | + order = 0; |
| 75 | + if (component == 11){ |
| 76 | + component = 10; |
| 77 | + order = 1; |
| 78 | + } |
| 79 | + |
| 80 | + TDC[index] = new H1F(String.format("TDC_sector%d_layer%d_component%d_order%d", sector, layer, component, order), String.format("TDC sector%d layer%d component%d order%d", sector, layer, component, order), 200, 350.0, 550.0); |
| 81 | + TDC[index].setTitleX("TDC (ns)"); |
| 82 | + TDC[index].setTitleY("Counts"); |
| 83 | + TDC[index].setFillColor(4); |
| 84 | + } |
| 85 | + bits = new H1F("bits", "bits",65,0,65); |
| 86 | + bits.getDataX(0); |
| 87 | + bits.getEntries(); |
| 88 | + bits.getMaximumBin(); |
| 89 | + bits.getAxis().getNBins(); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + // public void fillAHDC(DataBank HodoHits) { |
| 94 | + // } |
| 95 | + |
| 96 | + public void fillATOF(DataBank atof_tdc) { |
| 97 | + int rows = atof_tdc.rows(); |
| 98 | + for (int loop = 0; loop < rows; loop++) { |
| 99 | + int sector = atof_tdc.getInt("sector", loop); |
| 100 | + int layer = atof_tdc.getInt("layer", loop); |
| 101 | + int component = atof_tdc.getInt("component", loop); |
| 102 | + int order = atof_tdc.getInt("order", loop); |
| 103 | + int tdc = atof_tdc.getInt("TDC", loop); |
| 104 | + int index = sector * 48 + layer * 12 + component + order; |
| 105 | + |
| 106 | + TDC[index].fill(tdc*tdc_bin_time); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + public void processEvent(DataEvent event) { |
| 111 | + |
| 112 | + DataBank recBankEB = null; |
| 113 | + DataBank recEvenEB = null; |
| 114 | + DataBank runConfig = null; |
| 115 | + DataBank atof_tdc = null; |
| 116 | + |
| 117 | + if (event.hasBank("REC::Particle")) { |
| 118 | + recBankEB = event.getBank("REC::Particle"); |
| 119 | + } |
| 120 | + if (event.hasBank("REC::Event")) { |
| 121 | + recEvenEB = event.getBank("REC::Event"); |
| 122 | + } |
| 123 | + if (event.hasBank("RUN::config")) { |
| 124 | + runConfig = event.getBank("RUN::config"); |
| 125 | + } |
| 126 | + if (event.hasBank("ATOF::tdc")) { |
| 127 | + atof_tdc = event.getBank("ATOF::tdc"); |
| 128 | + } |
| 129 | + |
| 130 | + if (runConfig!= null){ |
| 131 | + trigger_word = runConfig.getLong("trigger", 0); |
| 132 | + bits.fill(64); |
| 133 | + for (int i=0; i<64; ++i){ |
| 134 | + if ( 1 == ((trigger_word>>i)&1) ) { |
| 135 | + bits.fill(i); |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + if (recEvenEB != null) { |
| 141 | + startTime = recEvenEB.getFloat("startTime", 0); |
| 142 | + rfTime = recEvenEB.getFloat("RFTime", 0); |
| 143 | + } |
| 144 | + |
| 145 | + //Get trigger particle |
| 146 | + if (recBankEB != null) { |
| 147 | + trigger = recBankEB.getInt("pid", 0); |
| 148 | + } |
| 149 | + |
| 150 | + if (atof_tdc != null) { |
| 151 | + fillATOF(atof_tdc); |
| 152 | + } |
| 153 | + |
| 154 | + } |
| 155 | + |
| 156 | + public void write() { |
| 157 | + TDirectory dirout = new TDirectory(); |
| 158 | + dirout.mkdir("/ALERT/"); |
| 159 | + dirout.cd("/ALERT/"); |
| 160 | + for (int index = 0; index < 720; index++) { |
| 161 | + dirout.addDataSet(TDC[index]); |
| 162 | + } |
| 163 | + dirout.mkdir("/TRIGGER/"); |
| 164 | + dirout.cd("/TRIGGER/"); |
| 165 | + dirout.addDataSet(bits); |
| 166 | + if(runNum>0) dirout.writeFile(outputDir+"/out_ALERT_"+runNum+".hipo"); |
| 167 | + else dirout.writeFile(outputDir+"/out_ALERT.hipo"); |
| 168 | + } |
| 169 | + |
| 170 | +} |
0 commit comments