diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java index 84ec0a6cf4..3fb4c7eb75 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java @@ -4,8 +4,10 @@ import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.jlab.detector.banks.RawBank.OrderType; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.ConstantsManager; @@ -22,27 +24,22 @@ public class DetectorEventDecoder { ConstantsManager fitterManager = new ConstantsManager(); ConstantsManager scalerManager = new ConstantsManager(); - List tablesTrans = null; - List tablesFitter = null; + HashSet keysFilter; + HashSet keysMicromega; - List keysTrans = null; - List keysFitter = null; - List keysFilter = null; - List keysMicromega= null; + HashMap tableTrans; + HashMap tableFitter; - private int runNumber = 10; + HashMap tablesFitter; + TranslationTable translator; - private ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter(); - private MVTFitter mvtFitter = new MVTFitter(); - - private TranslationTable translator = new TranslationTable(); + ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter(); + MVTFitter mvtFitter = new MVTFitter(); + int runNumber = 10; + public DetectorEventDecoder(boolean development){ - if(development==true){ - this.initDecoderDev(); - } else { - this.initDecoder(); - } + this.initDecoder(); } public void setTimestamp(String timestamp) { @@ -60,8 +57,11 @@ public void setVariation(String variation) { public void setRunNumber(int run){ if (run != this.runNumber) { translator = new TranslationTable(); - for (int i=0; i(); + for (DetectorType t : tableTrans.keySet()) + translator.add(t, translationManager.getConstants(run, tableTrans.get(t))); + for (DetectorType t: tableFitter.keySet()) + tablesFitter.put(t, fitterManager.getConstants(run, tableFitter.get(t))); } this.runNumber = run; } @@ -84,68 +84,79 @@ public DetectorEventDecoder(){ this.initDecoder(); } - public final void initDecoderDev(){ - keysTrans = Arrays.asList(new DetectorType[]{ DetectorType.HTCC,DetectorType.BST,DetectorType.RTPC} ); - tablesTrans = Arrays.asList(new String[]{ "/daq/tt/clasdev/htcc","/daq/tt/clasdev/svt","/daq/tt/clasdev/rtpc" }); - keysFitter = Arrays.asList(new DetectorType[]{DetectorType.HTCC}); - tablesFitter = Arrays.asList(new String[]{"/daq/fadc/clasdev/htcc"}); - translationManager.init(tablesTrans); - fitterManager.init(tablesFitter); - scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp", - "/runcontrol/helicity","/daq/config/scalers/dsc1"})); - } - public final void initDecoder(){ - // Detector translation table - keysTrans = Arrays.asList(new DetectorType[]{DetectorType.FTCAL,DetectorType.FTHODO,DetectorType.FTTRK,DetectorType.LTCC,DetectorType.ECAL,DetectorType.FTOF, - DetectorType.HTCC,DetectorType.DC,DetectorType.CTOF,DetectorType.CND,DetectorType.BST,DetectorType.RF,DetectorType.BMT,DetectorType.FMT, - DetectorType.RICH,DetectorType.HEL,DetectorType.BAND,DetectorType.RTPC, - DetectorType.RASTER,DetectorType.ATOF,DetectorType.AHDC - }); - tablesTrans = Arrays.asList(new String[]{ - "/daq/tt/ftcal","/daq/tt/fthodo","/daq/tt/fttrk","/daq/tt/ltcc", - "/daq/tt/ec","/daq/tt/ftof","/daq/tt/htcc","/daq/tt/dc","/daq/tt/ctof","/daq/tt/cnd","/daq/tt/svt", - "/daq/tt/rf","/daq/tt/bmt","/daq/tt/fmt","/daq/tt/rich2","/daq/tt/hel","/daq/tt/band","/daq/tt/rtpc", - "/daq/tt/raster","/daq/tt/atof","/daq/tt/ahdc" - }); - translationManager.init(tablesTrans); + keysFilter = new HashSet<>(); + keysMicromega= new HashSet<>(); + tableTrans = new HashMap<>(); + tableFitter = new HashMap<>(); + + keysFilter.add(DetectorType.DC); - // ADC waveform fitter translation table - keysFitter = Arrays.asList(new DetectorType[]{DetectorType.FTCAL,DetectorType.FTHODO,DetectorType.FTTRK,DetectorType.FTOF,DetectorType.LTCC, - DetectorType.ECAL,DetectorType.HTCC,DetectorType.CTOF,DetectorType.CND,DetectorType.BMT, - DetectorType.FMT,DetectorType.HEL,DetectorType.RF,DetectorType.BAND,DetectorType.RASTER, - DetectorType.AHDC}); - tablesFitter = Arrays.asList(new String[]{ - "/daq/fadc/ftcal","/daq/fadc/fthodo","/daq/config/fttrk","/daq/fadc/ftof","/daq/fadc/ltcc", - "/daq/fadc/ec", "/daq/fadc/htcc","/daq/fadc/ctof","/daq/fadc/cnd","/daq/config/bmt", - "/daq/config/fmt","/daq/fadc/hel","/daq/fadc/rf","/daq/fadc/band","/daq/fadc/raster", - "/daq/config/ahdc" - }); - fitterManager.init(tablesFitter); - - // Data filter list - keysFilter = Arrays.asList(new DetectorType[]{DetectorType.DC}); - - scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp", - "/runcontrol/helicity","/daq/config/scalers/dsc1"})); - - keysMicromega = Arrays.asList(new DetectorType[]{DetectorType.BMT,DetectorType.FMT,DetectorType.FTTRK}); + keysMicromega.add(DetectorType.BMT); + keysMicromega.add(DetectorType.FMT); + keysMicromega.add(DetectorType.FTTRK); + + tableTrans.put(DetectorType.FTCAL, "/daq/tt/ftcal"); + tableTrans.put(DetectorType.FTHODO, "/daq/tt/fthodo"); + tableTrans.put(DetectorType.FTTRK, "/daq/tt/fttrk"); + tableTrans.put(DetectorType.LTCC, "/daq/tt/ltcc"); + tableTrans.put(DetectorType.ECAL, "/daq/tt/ec"); + tableTrans.put(DetectorType.FTOF, "/daq/tt/ftof"); + tableTrans.put(DetectorType.HTCC, "/daq/tt/htcc"); + tableTrans.put(DetectorType.DC, "/daq/tt/dc"); + tableTrans.put(DetectorType.CTOF, "/daq/tt/ctof"); + tableTrans.put(DetectorType.CND, "/daq/tt/cnd"); + tableTrans.put(DetectorType.BST, "/daq/tt/svt"); + tableTrans.put(DetectorType.RF, "/daq/tt/rf"); + tableTrans.put(DetectorType.BMT, "/daq/tt/bmt"); + tableTrans.put(DetectorType.FMT, "/daq/tt/fmt"); + tableTrans.put(DetectorType.RICH, "/daq/tt/rich2"); + tableTrans.put(DetectorType.HEL, "/daq/tt/hel"); + tableTrans.put(DetectorType.BAND, "/daq/tt/band"); + tableTrans.put(DetectorType.RTPC, "/daq/tt/rtpc"); + tableTrans.put(DetectorType.RASTER, "/daq/tt/raster"); + tableTrans.put(DetectorType.ATOF, "/daq/tt/atof"); + tableTrans.put(DetectorType.AHDC, "/daq/tt/ahdc"); + translationManager.init(tableTrans.values().stream().collect(Collectors.toList())); + + tableFitter.put(DetectorType.FTCAL, "/daq/fadc/ftcal"); + tableFitter.put(DetectorType.FTHODO, "/daq/fadc/fthodo"); + tableFitter.put(DetectorType.FTTRK, "/daq/fadc/fttrk"); + tableFitter.put(DetectorType.FTOF, "/daq/fadc/ftof"); + tableFitter.put(DetectorType.LTCC, "/daq/fadc/ltcc"); + tableFitter.put(DetectorType.ECAL, "/daq/fadc/ec"); + tableFitter.put(DetectorType.HTCC, "/daq/fadc/htcc"); + tableFitter.put(DetectorType.CTOF, "/daq/fadc/ctof"); + tableFitter.put(DetectorType.CND, "/daq/fadc/cnd"); + tableFitter.put(DetectorType.BMT, "/daq/fadc/bmt"); + tableFitter.put(DetectorType.FMT, "/daq/fadc/fmt"); + tableFitter.put(DetectorType.HEL, "/daq/fadc/hel"); + tableFitter.put(DetectorType.RF, "/daq/fadc/rf"); + tableFitter.put(DetectorType.BAND, "/daq/fadc/band"); + tableFitter.put(DetectorType.RASTER, "/daq/fadc/raster"); + tableFitter.put(DetectorType.AHDC, "/daq/fadc/ahdc"); + fitterManager.init(tableFitter.values().stream().collect(Collectors.toList())); + + scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup", + "/runcontrol/slm","/runcontrol/hwp","/runcontrol/helicity","/daq/config/scalers/dsc1"})); checkTables(); } - public void checkTables() { - for (int i=0; i tables = (List)tableTrans.values().stream().collect(Collectors.toList()); + for (int i=0; i detectorData){ @@ -169,57 +180,59 @@ public void translate(List detectorData){ } } - public void fitPulses(List detectorData){ + /** + * Use CCDB /daq/fadc tables to convert waveforms to pulses. + * + * @param detectorData + */ + public void fitPulses(List detectorData) { - // preload CCDB tables once: - ArrayList tables = new ArrayList<>(); - for (String name : tablesFitter) { - tables.add(fitterManager.getConstants(runNumber, name)); - } + final long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0); + + for (DetectorDataDgtz data : detectorData) { - for(DetectorDataDgtz data : detectorData){ if (data.getADCSize() == 0) continue; - int crate = data.getDescriptor().getCrate(); - int slot = data.getDescriptor().getSlot(); - int channel = data.getDescriptor().getChannel(); - long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel); - long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0); - boolean ismm = keysMicromega.contains(data.getDescriptor().getType()); - - for (int j=0; j0){ try { extendedFitter.fit(nsa, nsb, tet, ped, adc.getPulseArray()); } catch (Exception e) { - System.out.println(">>>> error : fitting pulse " - + crate + " / " + slot + " / " + channel); + System.err.println(">>>> error : fitting pulse "+data.getDescriptor().getCrate()+ + " / "+data.getDescriptor().getSlot()+" / "+data.getDescriptor().getChannel()); } int adc_corrected = extendedFitter.adc + extendedFitter.ped*(nsa+nsb); adc.setHeight((short) this.extendedFitter.pulsePeakValue); @@ -229,14 +242,12 @@ else if(daq.hasEntryByHash(hash)==true){ } data.getADCData(i).setADC(nsa, nsb); } - // first one wins: - break; } } } } - public void filterTDCs(List detectorData){ + void filterTDCs(List detectorData){ int maxMultiplicity = 1; for(DetectorType type : keysFilter){ Map> filteredData = new HashMap<>();