diff --git a/etc/bankdefs/hipo4/bmt.json b/etc/bankdefs/hipo4/bmt.json index 616793bd1f..d46630c226 100644 --- a/etc/bankdefs/hipo4/bmt.json +++ b/etc/bankdefs/hipo4/bmt.json @@ -129,7 +129,8 @@ {"name":"trkingStat", "type":"B", "info":"tracking status"}, {"name":"clusterID", "type":"S", "info":"associated cluster ID"}, {"name":"trkID", "type":"S", "info":"associated track ID"}, - {"name":"status", "type":"B", "info":"status (0=good)"} + {"name":"status", "type":"B", "info":"status (0=good)"}, + {"name":"ai", "type":"B", "info":"bits [0-2] : noise flags for sections 1-3 (1 = noise, 0 = signal); bits [3-5] : hit presence for sections 1-3 (1 = hit present, 0 = no hit)"} ] }, { diff --git a/etc/bankdefs/hipo4/bst.json b/etc/bankdefs/hipo4/bst.json index 8d9c6c46ba..7b8acb882c 100644 --- a/etc/bankdefs/hipo4/bst.json +++ b/etc/bankdefs/hipo4/bst.json @@ -120,7 +120,8 @@ {"name":"trkingStat", "type":"B", "info":"tracking status"}, {"name":"clusterID", "type":"S", "info":"associated cluster ID"}, {"name":"trkID", "type":"S", "info":"associated track ID"}, - {"name":"status", "type":"B", "info":"status (0=good)"} + {"name":"status", "type":"B", "info":"status (0=good)"}, + {"name":"ai", "type":"B", "info":"bits [0-2] : noise flags for sections 1-3 (1 = noise, 0 = signal); bits [3-5] : hit presence for sections 1-3 (1 = hit present, 0 = no hit)"} ] }, { diff --git a/etc/services/data-cvthits.yaml b/etc/services/data-cvthits.yaml new file mode 100644 index 0000000000..90d59aaa45 --- /dev/null +++ b/etc/services/data-cvthits.yaml @@ -0,0 +1,30 @@ +io-services: + reader: + class: org.jlab.io.clara.HipoToHipoReader + name: HipoToHipoReader + writer: + class: org.jlab.io.clara.HipoToHipoWriter + name: HipoToHipoWriter +services: + - class: org.jlab.clas.swimtools.MagFieldsEngine + name: MAGFIELDS + - class: org.jlab.rec.cvt.services.CVTHitEngine + name: CVTH +configuration: + global: + variation: rga_fall2018_bg +# timestamp: 12/31/2020-00:00:00 +# triggerMask: "0x1" +## uncomment the following two lines for compatibility with alignments before the DC fixes +# dcMinistagger: "NOTONREFWIRE" +# dcFeedthroughs: "OFF" +# io-services: +# writer: +# schema_dir: dst + services: + MAGFIELDS: + magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat + magfieldTorusMap: Full_torus_r251_phi181_z251_25Jan2021.dat + +mime-types: + - binary/data-hipo diff --git a/reconstruction/cvt/pom.xml b/reconstruction/cvt/pom.xml index 50e7eecd3a..168707823d 100644 --- a/reconstruction/cvt/pom.xml +++ b/reconstruction/cvt/pom.xml @@ -79,6 +79,11 @@ clas-geometry 14.1.2-SNAPSHOT + + org.jlab.clas12.detector + clas12detector-ai + 14.1.2-SNAPSHOT + org.jlab.clas12.detector clas12detector-eb @@ -95,6 +100,10 @@ junit junit + + ai.djl + api + diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTDenoiseEngine.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTDenoiseEngine.java new file mode 100644 index 0000000000..29030ca589 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTDenoiseEngine.java @@ -0,0 +1,515 @@ +package org.jlab.rec.cvt.services; + +import ai.djl.MalformedModelException; +import java.nio.file.Paths; +import ai.djl.ndarray.NDArray; +import ai.djl.ndarray.NDList; +import ai.djl.ndarray.NDManager; +import ai.djl.ndarray.types.Shape; +import ai.djl.repository.zoo.Criteria; +import ai.djl.repository.zoo.ZooModel; +import ai.djl.training.util.ProgressBar; +import ai.djl.translate.Translator; +import ai.djl.translate.TranslatorContext; +import ai.djl.translate.Batchifier; +import ai.djl.inference.Predictor; +import ai.djl.repository.zoo.ModelNotFoundException; +import ai.djl.translate.TranslateException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.utils.system.ClasUtilsFile; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.Geometry; +import org.jlab.clas.swimtools.Swim; +import org.jlab.rec.cvt.Constants; +import org.jlab.service.ai.PredictorPool; +import org.jlab.utils.groups.IndexedTable; + +/* ----------------------------------------------- + Input class + ----------------------------------------------- */ +class CVTInput { + + float[][] data; // [450][9] + float[] mask; // [450] + + public CVTInput(float[][] data, float[] mask) { + this.data = data; + this.mask = mask; + } +} + +/* ----------------------------------------------- + DJL Translator + ----------------------------------------------- */ +class CVTTranslator implements Translator { + + @Override + public NDList processInput(TranslatorContext ctx, CVTInput input) { + + NDManager manager = ctx.getNDManager(); + + NDArray x = manager.create(input.data).reshape(1, 450, 9); + NDArray mask = manager.create(input.mask).reshape(1, 450); + + return new NDList(x, mask); + } + + @Override + public float[][] processOutput(TranslatorContext ctx, NDList list) { + + NDArray output = list.singletonOrThrow(); // shape: (1, 450, C) or (1, 450) + output = output.squeeze(0); // remove batch dim -> (450, C) + + float[] flat = output.toFloatArray(); + long[] shape = output.getShape().getShape(); + + int dim0 = (int) shape[0]; + int dim1 = shape.length > 1 ? (int) shape[1] : 1; + + float[][] result = new float[dim0][dim1]; + + for(int i=0;i[] criterias; + private ZooModel[] model; + private PredictorPool[] predictors; + + public CVTDenoiseEngine() { + super("CVTDenoiseEngine","Tongtong","1.0"); + } + + + @Override + public boolean init() { + this.initConstantsTables(); + + criterias = new Criteria[NSECTIONS]; + model = new ZooModel[NSECTIONS]; + predictors = new PredictorPool[NSECTIONS]; + + initScaling(); // Initial minVals and maxVals + + System.setProperty("ai.djl.pytorch.num_interop_threads", "1"); + System.setProperty("ai.djl.pytorch.num_threads", "1"); + System.setProperty("ai.djl.pytorch.graph_optimizer", "false"); + + + // Load models and set predictor pools + for(int i = 0; i < NSECTIONS; i++){ + if (getEngineConfigString(CONF_THRESHOLDS[i]) != null) + thresholds[i] = Float.parseFloat(getEngineConfigString(CONF_THRESHOLDS[i])); + if (getEngineConfigString(CONF_MODEL_FILES[i]) != null) + modelFiles[i] = getEngineConfigString(CONF_MODEL_FILES[i]); + + try { + String modelPath = ClasUtilsFile.getResourceDir("CLAS12DIR", "etc/data/nnet/cvtdn/" + modelFiles[i]); + + CVTTranslator translator = new CVTTranslator(); + criterias[i] = Criteria.builder() + .setTypes(CVTInput.class, float[][].class) + .optModelPath(Paths.get(modelPath)) + .optEngine("PyTorch") + .optTranslator(translator) + .optProgress(new ProgressBar()) + .build(); + + model[i] = criterias[i].loadModel(); + + int threads = Integer.parseInt(getEngineConfigString(CONF_THREADS,"16")); + predictors[i] = new PredictorPool(threads, model[i]); + } catch (NullPointerException | MalformedModelException | IOException | ModelNotFoundException ex) { + Logger.getLogger(CVTDenoiseEngine.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + } + + return true; + } + + @Override + public boolean processDataEvent(DataEvent event) { + + Swim swimmer = new Swim(); + + int run = this.getRun(event); + + IndexedTable svtLorentz = this.getConstantsManager().getConstants(run, "/calibration/svt/lorentz_angle"); + IndexedTable bmtVoltage = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_voltage"); + + Geometry.getInstance().initialize(this.getConstantsManager().getVariation(), run, svtLorentz, bmtVoltage); + + if (!event.hasBank(BST_BANK)) return true; + if (!event.hasBank(BMT_BANK)) return true; + + DataBank bst_bank = event.getBank(BST_BANK); + DataBank bmt_bank = event.getBank(BMT_BANK); + + float[][][] x = new float[NSECTIONS][MAX_HITS][NFEATURES]; + float[][] mask = new float[NSECTIONS][MAX_HITS]; + + int[] nHits = {0, 0, 0}; + + Map[] maps = new HashMap[NSECTIONS]; + for (int i = 0; i < NSECTIONS; i++) { + maps[i] = new HashMap<>(); + } + + // Read BST bank and set input for models + int[][][] nHitsLayerSectorStrip_BST = new int[6][18][256]; // Number of hits in a strip + for(int i = 0; i < bst_bank.rows(); i++){ + int sector = bst_bank.getByte("sector", i); + int layer = bst_bank.getByte("layer", i); + int strip = bst_bank.getShort("strip",i); + + Hit hit = new Hit(layer, sector, strip, nHitsLayerSectorStrip_BST[layer-1][sector-1][strip-1]++); + + Line3D line = Geometry.getInstance().getSVT().getStrip(layer, sector, strip); + float[] features = {strip, (float)(line.origin().x()/10.), (float)(line.end().x()/10.), (float)(line.origin().y()/10.), + (float)(line.end().y()/10.), (float)(line.origin().z()/10.), (float)(line.end().z()/10.), sector, layer}; // unit conversion from mm to cm for end points + + for(int f = 0; f < NFEATURES - 1; f++){ + float min = minVals[f][layer-1]; + float max = maxVals[f][layer-1]; + features[f] = (features[f] - min) / (max-min); + } + features[NFEATURES-1] = (features[NFEATURES-1] - 1) / (NLAYERS - 1); + + List sectionList = getSectionList(layer, sector); + for(int section : sectionList){ + for(int f = 0; f < NFEATURES; f++){ + x[section - 1][nHits[section - 1]][f] = features[f]; + } + + mask[section - 1][nHits[section - 1]] = 1.0f; + + maps[section - 1].put(nHits[section - 1], hit); + + nHits[section - 1]++; + if(nHits[section - 1] == MAX_HITS) { + Logger.getLogger(CVTDenoiseEngine.class.getName()).log(Level.SEVERE, "Number of hits is over maximum limit!"); + return true; + } + } + } + + // Read BMT bank and set input for models + int[][][] nHitsLayerSectorStrip_BMT = new int[6][3][1152]; // Number of hits in a strip + for(int i = 0; i < bmt_bank.rows(); i++){ + int sector = bmt_bank.getByte("sector", i); + int layer = bmt_bank.getByte("layer", i); + int strip = bmt_bank.getShort("strip",i); + + Hit hit = new Hit(layer+6, sector, strip, nHitsLayerSectorStrip_BMT[layer-1][sector-1][strip-1]++); + + Point3D originPoint, endPoint; + int region = (layer + 1) / 2; // Get region number for a BMT layer; layers 1, 4, 6 for BMT-C layers, and layers 2, 3, 5 for BMT-Z + if(layer == 2 || layer ==3 || layer == 5) { + Line3D line = Geometry.getInstance().getBMT().getLCZstrip(region, sector, strip, swimmer); + originPoint = line.origin(); + endPoint = line.origin(); + } + else { + Arc3D arcLine = Geometry.getInstance().getBMT().getCstrip(region, sector, strip); + originPoint = arcLine.origin(); + endPoint = arcLine.end(); + } + + layer += 6; + float[] features = {strip, (float)(originPoint.x()/10.), (float)(endPoint.x()/10.), (float)(originPoint.y()/10.), + (float)(endPoint.y()/10.), (float)(originPoint.z()/10.), (float)(endPoint.z()/10.), sector, layer}; // unit conversion from mm to cm for end points + + for(int f = 0; f < NFEATURES - 1; f++){ + float min = minVals[f][layer-1]; + float max = maxVals[f][layer-1]; + features[f] = (features[f] - min) / (max-min); + } + features[NFEATURES-1] = (features[NFEATURES-1] - 1) / (NLAYERS - 1); + + List sectionList = getSectionList(layer, sector); + for(int section : sectionList){ + for(int f = 0; f < NFEATURES; f++){ + x[section - 1][nHits[section - 1]][f] = features[f]; + } + + mask[section - 1][nHits[section - 1]] = 1.0f; + + maps[section - 1].put(nHits[section - 1], hit); + + nHits[section - 1]++; + if(nHits[section - 1] == MAX_HITS) { + Logger.getLogger(CVTDenoiseEngine.class.getName()).log(Level.SEVERE, "Number of hits is over maximum limit!"); + return true; + } + } + } + + int maxIndex_BST = Integer.MIN_VALUE; + for (int i = 0; i < nHitsLayerSectorStrip_BST.length; i++) { + for (int j = 0; j < nHitsLayerSectorStrip_BST[i].length; j++) { + for (int k = 0; k < nHitsLayerSectorStrip_BST[i][j].length; k++) { + if (nHitsLayerSectorStrip_BST[i][j][k] > maxIndex_BST) { + maxIndex_BST = nHitsLayerSectorStrip_BST[i][j][k]; + } + } + } + } + int maxIndex_BMT = Integer.MIN_VALUE; + for (int i = 0; i < nHitsLayerSectorStrip_BMT.length; i++) { + for (int j = 0; j < nHitsLayerSectorStrip_BMT[i].length; j++) { + for (int k = 0; k < nHitsLayerSectorStrip_BMT[i][j].length; k++) { + if (nHitsLayerSectorStrip_BMT[i][j][k] > maxIndex_BMT) { + maxIndex_BMT = nHitsLayerSectorStrip_BMT[i][j][k]; + } + } + } + } + int maxIndex = Math.max(maxIndex_BST, maxIndex_BMT); + + // AI-based hit classification. + // Hit status is encoded in a single byte: + // bits [0–2] : noise flags for sections 1–3 (1 = noise, 0 = signal) + // bits [3–5] : hit presence for sections 1–3 (1 = hit present, 0 = no hit) + byte[][][][] statuses = new byte[NLAYERS][18][1152][maxIndex+1]; + for(int s = 0; s < NSECTIONS; s++){ + CVTInput input = new CVTInput(x[s],mask[s]); + try{ + Predictor predictor = predictors[s].take(); + + try{ + float[][] preds = predictor.predict(input); + for(int i = 0; i < nHits[s]; i++){ + Hit hit = maps[s].get(i); + statuses[hit.getLayer()-1][hit.getSector()-1][hit.getStrip() - 1][hit.getIndex()] |= (byte) (1 << (s+3)); + if(preds[i][0] < thresholds[s]) statuses[hit.getLayer()-1][hit.getSector()-1][hit.getStrip() - 1][hit.getIndex()] |= (byte) (1 << s); + } + } finally { + predictors[s].put(predictor); + } + + } catch (TranslateException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + // Update BST and BMT banks to record predictions + updateBanks(bst_bank, bmt_bank, statuses); + event.removeBank(BST_BANK); + event.appendBank(bst_bank); + event.removeBank(BMT_BANK); + event.appendBank(bmt_bank); + + return true; + } + + // Scaling per layer + private void initScaling(){ + + for(int l=0;l<12;l++) minVals[0][l]=1f; + + int[] stripMax={256,256,256,256,256,256,896,640,640,1024,768,1152}; + for(int l=0;l<12;l++) maxVals[0][l]=stripMax[l]; + + float[] xyMin={-7,-8,-10,-10,-15,-15,-15,-18,-18,-23,-23,-23}; + float[] xyMax={7,8,10,10,15,15,15,18,18,23,23,23}; + + for(int f=1;f<=4;f++){ + for(int l=0;l<12;l++){ + minVals[f][l]=xyMin[l]; + maxVals[f][l]=xyMax[l]; + } + } + + float[] zMin={-25,-25,-22,-22,-18,-18,-18,-21,-21,-21,-21,-21}; + float[] zMax={25,25,22,22,18,18,21,21,21,25,25,25}; + + for(int f=5;f<=6;f++){ + for(int l=0;l<12;l++){ + minVals[f][l]=zMin[l]; + maxVals[f][l]=zMax[l]; + } + } + + float[] sectorMax={11,11,15,15,19,19,3,3,3,3,3,3}; + + for(int l=0;l<12;l++){ + minVals[7][l]=1f; + maxVals[7][l]=sectorMax[l]; + } + + /* + float[] timeMin={0,0,0,0,0,0,4,4,4,4,4,4}; + float[] timeMax={511,511,511,511,511,511,436,436,436,436,436,436}; + + for(int l=0;l<12;l++){ + minVals[8][l]=timeMin[l]; + maxVals[8][l]=timeMax[l]; + } + */ + } + + // Set sections based on layer and sector of hits + // Some SVT hits are shared by sections1&2 or sections2&3 + private List getSectionList(int layer, int sector) { + List sectionList = new ArrayList<>(); + + if (layer >= 1 && layer <= 2) { + if (sector >= 1 && sector <= 4) sectionList.add(1); + if (sector >= 4 && sector <= 8) sectionList.add(2); + if (sector >= 8 && sector <= 10) sectionList.add(3); + } + else if (layer >= 3 && layer <= 4) { + if (sector >= 1 && sector <= 6) sectionList.add(1); + if (sector >= 6 && sector <= 10) sectionList.add(2); + if (sector >= 10 && sector <= 14) sectionList.add(3); + } + else if (layer >= 5 && layer <= 6) { + if (sector >= 1 && sector <= 7) sectionList.add(1); + if (sector >= 7 && sector <= 13) sectionList.add(2); + if (sector >= 14 && sector <= 18) sectionList.add(3); + } + else { + if (sector == 1) sectionList.add(1); + if (sector == 2) sectionList.add(2); + if (sector == 3) sectionList.add(3); + } + + return sectionList; + } + + // -------- Update BST & BMT banks -------- + private void updateBanks(DataBank bst_bank, DataBank bmt_bank, byte[][][][] statuses) { + int[][][] nHitsLayerSectorStrip_BST = new int[6][18][256]; // Number of hits in a strip + for (int row=0; row0; + } + + public boolean kfBeamSpot() { + return this.beamSpotConstraint==2; + } + + /** + * @return the docacut + */ + public double getDocacut() { + return docacut; + } + + /** + * @param docacut the docacut to set + */ + public void setDocacut(double docacut) { + this.docacut = docacut; + } + + /** + * @return the docacutsum + */ + public double getDocacutsum() { + return docacutsum; + } + + /** + * @return the svtmaxclussize + */ + public int getSvtmaxclussize() { + return svtmaxclussize; + } + + /** + * @param svtmaxclussize the svtmaxclussize to set + */ + public void setSvtmaxclussize(int svtmaxclussize) { + this.svtmaxclussize = svtmaxclussize; + } + + /** + * @return the bmtcmaxclussize + */ + public int getBmtcmaxclussize() { + return bmtcmaxclussize; + } + + /** + * @param bmtcmaxclussize the bmtcmaxclussize to set + */ + public void setBmtcmaxclussize(int bmtcmaxclussize) { + this.bmtcmaxclussize = bmtcmaxclussize; + } + + /** + * @return the bmtzmaxclussize + */ + public int getBmtzmaxclussize() { + return bmtzmaxclussize; + } + + /** + * @param bmtzmaxclussize the bmtzmaxclussize to set + */ + public void setBmtzmaxclussize(int bmtzmaxclussize) { + this.bmtzmaxclussize = bmtzmaxclussize; + } + + @Override + public boolean processDataEvent(DataEvent event) { + + Swim swimmer = new Swim(); + + int run = this.getRun(event); + + IndexedTable svtStatus = this.getConstantsManager().getConstants(run, "/calibration/svt/status"); + IndexedTable svtLorentz = this.getConstantsManager().getConstants(run, "/calibration/svt/lorentz_angle"); + IndexedTable bmtStatus = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_status"); + IndexedTable bmtTime = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_time"); + IndexedTable bmtVoltage = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_voltage"); + IndexedTable bmtStripVoltage = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_strip_voltage"); + IndexedTable bmtStripThreshold = this.getConstantsManager().getConstants(run, "/calibration/mvt/bmt_strip_voltage_thresholds"); + IndexedTable beamPos = this.getConstantsManager().getConstants(run, "/geometry/beam/position"); + IndexedTable adcStatus = this.getConstantsManager().getConstants(run, "/calibration/svt/adcstatus"); + + Geometry.getInstance().initialize(this.getConstantsManager().getVariation(), run, svtLorentz, bmtVoltage); + + CVTReconstruction reco = new CVTReconstruction(swimmer); + + List> hits = reco.readHits(event, svtStatus, bmtStatus, bmtTime, + bmtStripVoltage, bmtStripThreshold, + adcStatus); + + + List banks = new ArrayList<>(); + + banks.add(RecoBankWriter.fillSVTHitBank(event, hits.get(0), this.getSvtHitBank())); + banks.add(RecoBankWriter.fillBMTHitBank(event, hits.get(1), this.getBmtHitBank())); + + event.appendBanks(banks.toArray(new DataBank[0])); + + + return true; + } + + + public void loadConfiguration() { + + // general (pass-independent) settings + if (this.getEngineConfigString("cosmics")!=null) + this.isCosmics = Boolean.valueOf(this.getEngineConfigString("cosmics")); + + if (this.getEngineConfigString("svtOnly")!=null) + this.svtOnly = Boolean.valueOf(this.getEngineConfigString("svtOnly")); + + if (this.getEngineConfigString("excludeLayers")!=null) + this.excludeLayers = this.getEngineConfigString("excludeLayers"); + + if (this.getEngineConfigString("excludeBMTLayers")!=null) + this.excludeBMTLayers = this.getEngineConfigString("excludeBMTLayers"); + + if (this.getEngineConfigString("removeRegion")!=null) + this.removeRegion = Integer.valueOf(this.getEngineConfigString("removeRegion")); + + if (this.getEngineConfigString("beamSpotConst")!=null) + this.beamSpotConstraint = Integer.valueOf(this.getEngineConfigString("beamSpotConst")); + + if (this.getEngineConfigString("beamSpotRadius")!=null) + this.beamSpotRadius = Double.valueOf(this.getEngineConfigString("beamSpotRadius")); + + if(this.getEngineConfigString("targetMat")!=null) + this.targetMaterial = this.getEngineConfigString("targetMat"); + + if(this.getEngineConfigString("elossPreCorrection")!=null) + this.elossPrecorrection = Boolean.parseBoolean(this.getEngineConfigString("elossPreCorrection")); + + if(this.getEngineConfigString("svtSeeding")!=null) + this.svtSeeding = Boolean.parseBoolean(this.getEngineConfigString("svtSeeding")); + + if(this.getEngineConfigString("timeCuts")!=null) + this.timeCuts = Boolean.parseBoolean(this.getEngineConfigString("timeCuts")); + + if(this.getEngineConfigString("hvCuts")!=null) + this.hvCuts = Boolean.parseBoolean(this.getEngineConfigString("hvCuts")); + + if(this.getEngineConfigString("useSVTTimingCuts")!=null) + this.useSVTTimingCuts = Boolean.parseBoolean(this.getEngineConfigString("useSVTTimingCuts")); + + if(this.getEngineConfigString("removeOverlappingSeeds")!=null) + this.removeOverlappingSeeds = Boolean.parseBoolean(this.getEngineConfigString("removeOverlappingSeeds")); + + if(this.getEngineConfigString("flagSeeds")!=null) + this.flagSeeds = Boolean.parseBoolean(this.getEngineConfigString("flagSeeds")); + + if(this.getEngineConfigString("gemcIgnBMT0ADC")!=null) + this.gemcIgnBMT0ADC = Boolean.parseBoolean(this.getEngineConfigString("gemcIgnBMT0ADC")); + + if(this.getEngineConfigString("KFfailRecovery")!=null) + this.KFfailRecovery = Boolean.parseBoolean(this.getEngineConfigString("KFfailRecovery")); + + if(this.getEngineConfigString("KFfailRecovMisCls")!=null) + this.KFfailRecovMisCls = Boolean.parseBoolean(this.getEngineConfigString("KFfailRecovMisCls")); + + if (this.getEngineConfigString("matLib")!=null) + this.matrixLibrary = this.getEngineConfigString("matLib"); + + // service dependent configuration settings + if(this.getEngineConfigString("elossPid")!=null) + this.pid = Integer.parseInt(this.getEngineConfigString("elossPid")); + + if (this.getEngineConfigString("kfFilterOn")!=null) + this.kfFilterOn = Boolean.valueOf(this.getEngineConfigString("kfFilterOn")); + + if (this.getEngineConfigString("initFromMC")!=null) + this.initFromMc = Boolean.valueOf(this.getEngineConfigString("initFromMC")); + + if (this.getEngineConfigString("useOnlyTruthHits")!=null) + this.useOnlyTruth = Boolean.valueOf(this.getEngineConfigString("useOnlyTruthHits")); + + if (this.getEngineConfigString("useSVTLinkerSeeder")!=null) + this.useSVTLinkerSeeder = Boolean.valueOf(this.getEngineConfigString("useSVTLinkerSeeder")); + + if (this.getEngineConfigString("kfIterations")!=null) + this.kfIterations = Integer.valueOf(this.getEngineConfigString("kfIterations")); + + if (this.getEngineConfigString("docacut")!=null) + this.setDocacut((double) Double.valueOf(this.getEngineConfigString("docacut"))); + + if (this.getEngineConfigString("docacutsum")!=null) + this.setDocacutsum((double) Double.valueOf(this.getEngineConfigString("docacutsum"))); + + if (this.getEngineConfigString("svtmaxclussize")!=null) + this.setSvtmaxclussize((int) Integer.valueOf(this.getEngineConfigString("svtmaxclussize"))); + + if (this.getEngineConfigString("bmtcmaxclussize")!=null) + this.setBmtcmaxclussize((int) Integer.valueOf(this.getEngineConfigString("bmtcmaxclussize"))); + + if (this.getEngineConfigString("bmtzmaxclussize")!=null) + this.setBmtzmaxclussize((int) Integer.valueOf(this.getEngineConfigString("bmtzmaxclussize"))); + + if (this.getEngineConfigString("rcut")!=null) + this.rcut = Double.valueOf(this.getEngineConfigString("rcut")); + + if (this.getEngineConfigString("z0cut")!=null) + this.z0cut = Double.valueOf(this.getEngineConfigString("z0cut")); + + } + + + public void initConstantsTables() { + String[] tables = new String[]{ + "/calibration/svt/status", + "/calibration/svt/lorentz_angle", + "/calibration/mvt/bmt_time", + "/calibration/mvt/bmt_status", + "/calibration/mvt/bmt_voltage", + "/calibration/mvt/bmt_strip_voltage", + "/calibration/mvt/bmt_strip_voltage_thresholds", + "/geometry/beam/position", + "/calibration/svt/adcstatus" + }; + requireConstants(Arrays.asList(tables)); + this.getConstantsManager().setVariation("default"); + } + + public void setSvtHitBank(String bstHitBank) { + this.svtHitBank = bstHitBank; + } + + public void setBmtHitBank(String bmtHitBank) { + this.bmtHitBank = bmtHitBank; + } + + public String getSvtHitBank() { + return svtHitBank; + } + + public String getBmtHitBank() { + return bmtHitBank; + } + + + public void printConfiguration() { + + System.out.println("["+this.getName()+"] run with cosmics setting set to "+Constants.getInstance().isCosmics); + System.out.println("["+this.getName()+"] run with SVT only set to "+Constants.getInstance().svtOnly); + if(this.excludeLayers!=null) + System.out.println("["+this.getName()+"] run with layers "+this.excludeLayers+" excluded in fit, based on yaml"); + if(this.excludeBMTLayers!=null) + System.out.println("["+this.getName()+"] run with BMT layers "+this.getEngineConfigString("excludeBMTLayers")+" excluded"); + if(this.removeRegion>0) + System.out.println("["+this.getName()+"] run with region "+this.getEngineConfigString("removeRegion")+" removed"); + System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.getInstance().beamSpotConstraint+ " (0=no-constraint, 1=seed only, 2=seed and KF)"); + System.out.println("["+this.getName()+"] run with beam spot size set to "+Constants.getInstance().getBeamRadius()); + System.out.println("["+this.getName()+"] Target material set to "+ Constants.getInstance().getTargetType()); + System.out.println("["+this.getName()+"] Pre-Eloss correction set to " + Constants.getInstance().preElossCorrection); + System.out.println("["+this.getName()+"] run SVT-based seeding set to "+ Constants.getInstance().svtSeeding); + System.out.println("["+this.getName()+"] run BMT timing cuts set to "+ Constants.getInstance().timeCuts); + System.out.println("["+this.getName()+"] run BMT HV masks "+ Constants.getInstance().bmtHVCuts); + System.out.println("["+this.getName()+"] run with matLib "+ Constants.getInstance().KFMatrixLibrary.toString() + " library"); + System.out.println("["+this.getName()+"] ELoss mass set for particle "+ pid); + System.out.println("["+this.getName()+"] run with Kalman-Filter status set to "+this.kfFilterOn); + System.out.println("["+this.getName()+"] initialize KF from true MC information "+this.initFromMc); + System.out.println("["+this.getName()+"] number of KF iterations set to "+this.kfIterations); + System.out.println("["+this.getName()+"] SLA doca cut "+this.docacut); + System.out.println("["+this.getName()+"] SLA docasum cut "+this.docacutsum); + System.out.println("["+this.getName()+"] max svt cluster size "+this.getSvtmaxclussize()); + System.out.println("["+this.getName()+"] max bmt-c cluster size "+this.getBmtcmaxclussize()); + System.out.println("["+this.getName()+"] max btm-z cluster size "+this.getBmtzmaxclussize()); + System.out.println("["+this.getName()+"] helix radius cut (mm) "+this.rcut); + System.out.println("["+this.getName()+"] z0 cut (mm from target edges) "+this.z0cut); + + + } + + + +}