diff --git a/etc/bankdefs/hipo4/cvtnn.json b/etc/bankdefs/hipo4/cvtnn.json new file mode 100644 index 0000000000..6d71f044ea --- /dev/null +++ b/etc/bankdefs/hipo4/cvtnn.json @@ -0,0 +1,104 @@ +[ + { + "name": "CVTRec::MLHit", + "group": 20500, + "item" : 51, + "info": "reconstructed hits (1st pass tracking)", + "entries": [ + {"name":"id", "type":"S", "info":"id of the hit"}, + {"name":"sidx", "type":"S", "info":"row in the MLSeed bank"}, + {"name":"tidx", "type":"S", "info":"row in the MLTrack bank"}, + {"name":"rectid", "type":"S", "info":"reconstructed track id associated with the hit"}, + {"name":"recsid", "type":"S", "info":"reconstructed seed id associated with the hit"}, + {"name":"mctid", "type":"S", "info":"MC track id associated with the hit"}, + {"name":"sector", "type":"B", "info":"sector"}, + {"name":"layer", "type":"B", "info":"layer (1...6)=SVT; (7...12)=BMT"}, + {"name":"type", "type":"B", "info":"detector type: 0=SVT; 1=BMT-Z; 2=BMT-C"}, + {"name":"strip", "type":"S", "info":"strip number"}, + {"name":"order", "type":"B", "info":"order 0=MC hit-on-track; 1=noise hit"}, + {"name":"cid", "type":"S", "info":"associated cluster id"}, + {"name":"cweight", "type":"F", "info":"1/1+|difference to associated cluster centroid|"}, + {"name":"sweight", "type":"F", "info":"1/1+|normalized difference to associated cluster seed|"}, + {"name":"x1", "type":"F", "info":"geometric strip first end-point x-coordinate"}, + {"name":"y1", "type":"F", "info":"geometric strip first end-point y-coordinate"}, + {"name":"z1", "type":"F", "info":"geometric strip first end-point z-coordinate"}, + {"name":"x2", "type":"F", "info":"geometric strip second end-point x-coordinate"}, + {"name":"y2", "type":"F", "info":"geometric strip second end-point y-coordinate"}, + {"name":"z2", "type":"F", "info":"geometric strip second end-point z-coordinate"} + ] + }, + { + "name": "CVT::MLHit", + "group": 20500, + "item" : 52, + "info": "reconstructed hits (2nd pass tracking)", + "entries": [ + {"name":"id", "type":"S", "info":"id of the hit"}, + {"name":"sidx", "type":"S", "info":"row in the MLSeed bank"}, + {"name":"tidx", "type":"S", "info":"row in the MLTrack bank"}, + {"name":"rectid", "type":"S", "info":"reconstructed track id associated with the hit"}, + {"name":"recsid", "type":"S", "info":"reconstructed seed id associated with the hit"}, + {"name":"mctid", "type":"S", "info":"MC track id associated with the hit"}, + {"name":"sector", "type":"B", "info":"sector"}, + {"name":"layer", "type":"B", "info":"layer (1...6)=SVT; (7...12)=BMT"}, + {"name":"type", "type":"B", "info":"detector type: 0=SVT; 1=BMT-Z; 2=BMT-C"}, + {"name":"strip", "type":"S", "info":"strip number"}, + {"name":"order", "type":"B", "info":"order 0=MC hit-on-track; 1=noise hit"}, + {"name":"cid", "type":"S", "info":"associated cluster id"}, + {"name":"cweight", "type":"F", "info":"1/1+|normalized difference to associated cluster centroid|"}, + {"name":"sweight", "type":"F", "info":"1/1+|normalized difference to associated cluster seed|"}, + {"name":"x1", "type":"F", "info":"geometric strip first end-point x-coordinate"}, + {"name":"y1", "type":"F", "info":"geometric strip first end-point y-coordinate"}, + {"name":"z1", "type":"F", "info":"geometric strip first end-point z-coordinate"}, + {"name":"x2", "type":"F", "info":"geometric strip second end-point x-coordinate"}, + {"name":"y2", "type":"F", "info":"geometric strip second end-point y-coordinate"}, + {"name":"z2", "type":"F", "info":"geometric strip second end-point z-coordinate"} + ] + }, + { + "name": "CVTRec::MLSeed", + "group": 20500, + "item" : 61, + "info": "reconstructed seeds (1st pass tracking)", + "entries": [ + {"name":"id", "type":"S", "info":"id of the seed"}, + {"name":"purity", "type":"F", "info":"seed purity: Nb of reconstructed true hits in seed / total hits on seed"}, + {"name":"efficiency", "type":"F", "info":"seed purity: Nb of reconstructed true hits in seed / MC hits in gemerated track"} + ] + }, + { + "name": "CVTRec::MLTrack", + "group": 20500, + "item" : 62, + "info": "reconstructed seeds (1st pass tracking)", + "entries": [ + {"name":"id", "type":"S", "info":"id of the seed"}, + {"name":"purity", "type":"F", "info":"seed purity: Nb of reconstructed true hits in track / total hits on track"}, + {"name":"efficiency", "type":"F", "info":"seed purity: Nb of reconstructed true hits in track / MC hits in gemerated track"} + ] + }, + { + "name": "CVT::MLSeed", + "group": 20500, + "item" : 63, + "info": "reconstructed seeds (2nd pass tracking)", + "entries": [ + {"name":"id", "type":"S", "info":"id of the track"}, + {"name":"purity", "type":"F", "info":"seed purity: Nb of reconstructed true hits in seed / total hits on seed"}, + {"name":"efficiency", "type":"F", "info":"seed purity: Nb of reconstructed true hits in seed / MC hits in gemerated track"} + ] + }, + { + "name": "CVT::MLTrack", + "group": 20500, + "item" : 64, + "info": "reconstructed seeds (2nd pass tracking)", + "entries": [ + {"name":"id", "type":"S", "info":"id of the track"}, + {"name":"purity", "type":"F", "info":"seed purity: Nb of reconstructed true hits in track / total hits on track"}, + {"name":"efficiency", "type":"F", "info":"seed purity: Nb of reconstructed true hits in track / MC hits in gemerated track"} + ] + } + + +] diff --git a/etc/services/mc-mlcvt.yaml b/etc/services/mc-mlcvt.yaml new file mode 100644 index 0000000000..744a9d596c --- /dev/null +++ b/etc/services/mc-mlcvt.yaml @@ -0,0 +1,27 @@ +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.ml.SampleMaker + name: CVTFP +configuration: + global: + variation: rga_fall2018_bg +# dcMinistagger: "NOTONREFWIRE" +# dcFeedthroughs: "OFF" +# io-services: +# writer: +# schema_dir: "absolute-path-to-schema-folder" + services: + MAGFIELDS: + magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat + magfieldTorusMap: Symm_torus_r2501_phi16_z251_24Apr2018.dat + +mime-types: + - binary/data-hipo diff --git a/etc/services/mc-mlcvtfilter.yaml b/etc/services/mc-mlcvtfilter.yaml new file mode 100644 index 0000000000..0c3cfc7b3f --- /dev/null +++ b/etc/services/mc-mlcvtfilter.yaml @@ -0,0 +1,27 @@ +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.ml.CVTFilter + name: CVTFP +configuration: + global: + variation: rga_fall2018_bg +# dcMinistagger: "NOTONREFWIRE" +# dcFeedthroughs: "OFF" +# io-services: +# writer: +# schema_dir: "absolute-path-to-schema-folder" + services: + MAGFIELDS: + magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat + magfieldTorusMap: Symm_torus_r2501_phi16_z251_24Apr2018.dat + +mime-types: + - binary/data-hipo diff --git a/reconstruction/cvt/pom.xml b/reconstruction/cvt/pom.xml index 2516e9eb29..4ab19b4992 100644 --- a/reconstruction/cvt/pom.xml +++ b/reconstruction/cvt/pom.xml @@ -95,6 +95,10 @@ junit junit + + org.jlab.jnp + jnp-hipo4 + diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/BankOutput.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/BankOutput.java new file mode 100644 index 0000000000..1693dd51e7 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/BankOutput.java @@ -0,0 +1,122 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package org.jlab.rec.cvt.ml; + +import java.util.ArrayList; +import java.util.List; +import org.jlab.detector.base.DetectorType; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.track.Seed; +import org.jlab.rec.cvt.track.Track; + +/** + * + * @author ziegler + */ +public class BankOutput { + public static DataBank fillHitsBank(DataEvent event, List>hits, String bankName) { + if (hits == null || hits.isEmpty()) return null; + DataBank bank = event.createBank(bankName, hits.get(0).size()+hits.get(1).size()); + int index=0; + for(int i = 0; i < hits.size(); i++) { + for(int j = 0; j < hits.get(i).size(); j++) { + bank.setShort("id", index, (short) hits.get(i).get(j).getId()); + bank.setShort("sidx", index, (short) hits.get(i).get(j).getSeedBankRow()); + bank.setShort("tidx", index, (short) hits.get(i).get(j).getTrackBankRow()); + bank.setShort("recsid", index, (short) hits.get(i).get(j).getAssociatedSeedID()); + bank.setShort("rectid", index, (short) hits.get(i).get(j).getAssociatedTrackID()); + bank.setShort("mctid", index, (short) hits.get(i).get(j).getAssociateMCTrkId()); + bank.setByte("sector", index, (byte) hits.get(i).get(j).getSector()); + int layer = hits.get(i).get(j).getLayer(); + if(i>0) layer+=6; + bank.setByte("layer", index, (byte) layer); + bank.setByte("type", index, getType(hits.get(i).get(j))); + bank.setShort("strip", index, (short) hits.get(i).get(j).getStrip().getStrip()); + bank.setByte("order", index, (byte) hits.get(i).get(j).MCstatus); + bank.setShort("cid", index, (short) hits.get(i).get(j).getAssociatedClusterID()); + bank.setFloat("cweight", index, (float) hits.get(i).get(j).getCweight()); + bank.setFloat("sweight", index, (float) hits.get(i).get(j).getSweight()); + if(hits.get(i).get(j).getDetector()==DetectorType.BST || + (hits.get(i).get(j).getDetector()==DetectorType.BMT + && hits.get(i).get(j).getType()==BMTType.Z)) { + bank.setFloat("x1", index, (float) hits.get(i).get(j).getStrip().getLine().origin().x()/10); + bank.setFloat("y1", index, (float) hits.get(i).get(j).getStrip().getLine().origin().y()/10); + bank.setFloat("z1", index, (float) hits.get(i).get(j).getStrip().getLine().origin().z()/10); + bank.setFloat("x2", index, (float) hits.get(i).get(j).getStrip().getLine().end().x()/10); + bank.setFloat("y2", index, (float) hits.get(i).get(j).getStrip().getLine().end().y()/10); + bank.setFloat("z2", index, (float) hits.get(i).get(j).getStrip().getLine().end().z()/10); + + } + if(hits.get(i).get(j).getDetector()==DetectorType.BMT + && hits.get(i).get(j).getType()==BMTType.C) { + bank.setFloat("x1", index, (float) hits.get(i).get(j).getStrip().getArc().origin().x()/10); + bank.setFloat("y1", index, (float) hits.get(i).get(j).getStrip().getArc().origin().y()/10); + bank.setFloat("z1", index, (float) hits.get(i).get(j).getStrip().getArc().origin().z()/10); + bank.setFloat("x2", index, (float) hits.get(i).get(j).getStrip().getArc().end().x()/10); + bank.setFloat("y2", index, (float) hits.get(i).get(j).getStrip().getArc().end().y()/10); + bank.setFloat("z2", index, (float) hits.get(i).get(j).getStrip().getArc().end().z()/10); + + } + + index++; + } + } + return bank; + } + + public static DataBank fillSeedsBank(DataEvent event, List seeds, String bankName) { + if (seeds == null || seeds.isEmpty()) return null; + + DataBank bank = event.createBank(bankName, seeds.size()); + + for (int i = 0; i < seeds.size(); i++) { + if(seeds.get(i)==null) + continue; + bank.setShort("id", i, (short) seeds.get(i).getId()); + bank.setFloat("purity", i, (float) seeds.get(i).getPurity()); + bank.setFloat("efficiency", i, (float) seeds.get(i).getEffs()[2]); + } + return bank; + } + + public static DataBank fillTracksBank(DataEvent event, List tracks, String bankName) { + if (tracks == null || tracks.isEmpty()) return null; + + DataBank bank = event.createBank(bankName, tracks.size()); + + for (int i = 0; i < tracks.size(); i++) { + if(tracks.get(i)==null) + continue; + bank.setShort("id", i, (short) tracks.get(i).getId()); + bank.setFloat("purity", i, (float) tracks.get(i).getPurity()); + bank.setFloat("efficiency", i, (float) tracks.get(i).getEffs()[2]); + } + return bank; + } + + + private static byte getType(Hit h) { + DetectorType detector = h.getDetector(); + + if (detector == DetectorType.BST) { + return 0; + } + + if (detector == DetectorType.BMT) { + BMTType type = h.getType(); + switch (type) { + case Z: return 1; + case C: return 2; + default: return -1; + } + } + + return -1; +} + +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/CVTFilter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/CVTFilter.java new file mode 100644 index 0000000000..f7068085e3 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/CVTFilter.java @@ -0,0 +1,616 @@ +package org.jlab.rec.cvt.ml; + +import org.jlab.rec.cvt.services.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.clas.swimtools.Swim; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataEvent; +import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.Geometry; +import org.jlab.rec.cvt.banks.RecoBankWriter; +import org.jlab.rec.cvt.cluster.Cluster; +import org.jlab.rec.cvt.cross.Cross; +import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.track.Seed; +import org.jlab.rec.cvt.track.StraightTrack; +import org.jlab.rec.cvt.track.Track; +import org.jlab.utils.groups.IndexedTable; + +/** + * Service to return reconstructed TRACKS + * format + * + * @author ziegler + * + */ +public class CVTFilter extends ReconstructionEngine { + + @Override + public void detectorChanged(int run) {} + + /** + * @param docacutsum the docacutsum to set + */ + public void setDocacutsum(double docacutsum) { + this.docacutsum = docacutsum; + } + + private String svtHitBank; + private String svtClusterBank; + private String svtCrossBank; + private String bmtHitBank; + private String bmtClusterBank; + private String bmtCrossBank; + private String cvtSeedBank; + private String cvtSeedClusBank; + private String cvtTrackBank; + private String cvtUTrackBank; + private String cvtTrajectoryBank; + private String cvtKFTrajectoryBank; + private String cvtCovMatBank; + private String bankPrefix = ""; + + // run-time options + private int pid = 0; + private int kfIterations = 5; + private boolean kfFilterOn = true; + private boolean initFromMc = false; + + // yaml setting passed to Constants class + private boolean isCosmics = false; + private boolean svtOnly = false; + private String excludeLayers = null; + private String excludeBMTLayers = null; + private int removeRegion = 0; + private int beamSpotConstraint = 2; + private double beamSpotRadius = 0.3; + private String targetMaterial = ""; + private boolean elossPrecorrection = true; + private boolean svtSeeding = true; + private boolean timeCuts = true; + private boolean hvCuts = true; + public boolean useSVTTimingCuts = false; + public boolean removeOverlappingSeeds = true; + public boolean flagSeeds = true; + public boolean gemcIgnBMT0ADC = false; + public boolean KFfailRecovery = true; + public boolean KFfailRecovMisCls = true; + private String matrixLibrary = "EJML"; + private boolean useOnlyTruth = false; + private boolean useSVTLinkerSeeder = true; + private double docacut = 0.75; + private double docacutsum = 1.15; + private int svtmaxclussize = 100; + private int bmtcmaxclussize = 100; + private int bmtzmaxclussize = 100; + private double rcut = 120.0; + private double z0cut = 10; + + public CVTFilter(String name) { + super(name, "ziegler", "6.0"); + } + + public CVTFilter() { + super("CVTEngine", "ziegler", "6.0"); + } + + + @Override + public boolean init() { + this.loadConfiguration(); + Constants.getInstance().initialize(this.getName(), + isCosmics, + svtOnly, + excludeLayers, + excludeBMTLayers, + removeRegion, + beamSpotConstraint, + beamSpotRadius, + targetMaterial, + elossPrecorrection, + svtSeeding, + timeCuts, + hvCuts, + useSVTTimingCuts, + removeOverlappingSeeds, + flagSeeds, + gemcIgnBMT0ADC, + KFfailRecovery, + KFfailRecovMisCls, + matrixLibrary, + useOnlyTruth, + useSVTLinkerSeeder, + docacut, + docacutsum, + svtmaxclussize, + bmtcmaxclussize, + bmtzmaxclussize, + rcut, + z0cut); + + this.initConstantsTables(); + this.registerBanks(); + this.printConfiguration(); + return true; + } + + public final void setOutputBankPrefix(String prefix) { + this.bankPrefix = prefix; + } + + public void registerBanks() { + String prefix = bankPrefix; + if(Constants.getInstance().isCosmics) prefix = "Rec"; + this.setBmtHitBank("BMT" + prefix + "::Hits"); + this.setBmtClusterBank("BMT" + prefix + "::Clusters"); + this.setBmtCrossBank("BMT" + prefix + "::Crosses"); + this.setSvtHitBank("BST" + prefix + "::Hits"); + this.setSvtClusterBank("BST" + prefix + "::Clusters"); + this.setSvtCrossBank("BST" + prefix + "::Crosses"); + this.setSeedBank("CVT" + prefix + "::Seeds"); + this.setSeedClusBank("CVT" + prefix + "::SeedClusters"); + this.setTrackBank("CVT" + prefix + "::Tracks"); + this.setUTrackBank("CVT" + prefix + "::UTracks"); + this.setCovMatBank("CVT" + prefix + "::TrackCovMat"); + this.setTrajectoryBank("CVT" + prefix + "::Trajectory"); + this.setKFTrajectoryBank("CVT" + prefix + "::KFTrajectory"); + super.registerOutputBank(this.bmtHitBank); + super.registerOutputBank(this.bmtClusterBank); + super.registerOutputBank(this.bmtCrossBank); + super.registerOutputBank(this.svtHitBank); + super.registerOutputBank(this.svtClusterBank); + super.registerOutputBank(this.svtCrossBank); + super.registerOutputBank(this.cvtSeedBank); + super.registerOutputBank(this.cvtSeedClusBank); + super.registerOutputBank(this.cvtTrackBank); + super.registerOutputBank(this.cvtUTrackBank); + super.registerOutputBank(this.cvtCovMatBank); + super.registerOutputBank(this.cvtTrajectoryBank); + super.registerOutputBank(this.cvtKFTrajectoryBank); + } + + public int getRun(DataEvent event) { + + if (event.hasBank("RUN::config") == false) { + System.err.println("RUN CONDITIONS NOT READ!"); + return 0; + } + + DataBank bank = event.getBank("RUN::config"); + int run = bank.getInt("run", 0); + if(Constants.getInstance().seedingDebugMode) { + System.out.println("EVENT "+bank.getInt("event", 0)); + } + return run; + } + + public int getPid() { + return pid; + } + + public int getKfIterations() { + return kfIterations; + } + + public boolean isKfFilterOn() { + return kfFilterOn; + } + + public boolean isInitFromMc() { + return initFromMc; + } + + public boolean seedBeamSpot() { + return this.beamSpotConstraint>0; + } + + 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 processDataEventUser(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); + reco.filterHits=true; + + List> hits = reco.readHits(event, svtStatus, bmtStatus, bmtTime, + bmtStripVoltage, bmtStripThreshold, + adcStatus); + + List> clusters = reco.findClusters(); + List> crosses = reco.findCrosses(); + + + List banks = new ArrayList<>(); + + if(crosses != null) { + if(Constants.getInstance().isCosmics) { + CosmicTracksRec trackFinder = new CosmicTracksRec(); + List seeds = trackFinder.getSeeds(event, clusters.get(0), clusters.get(1), crosses); + List tracks = trackFinder.getTracks(event, this.isInitFromMc(), + this.isKfFilterOn(), + this.getKfIterations()); + if(seeds!=null) banks.add(RecoBankWriter.fillStraightSeedsBank(event, seeds, "CVTRec::CosmicSeeds")); + if(tracks!=null) { + banks.add(RecoBankWriter.fillStraightTracksBank(event, tracks, "CVTRec::Cosmics")); + banks.add(RecoBankWriter.fillStraightTracksTrajectoryBank(event, tracks, "CVTRec::Trajectory")); + banks.add(RecoBankWriter.fillStraightTrackKFTrajectoryBank(event, tracks, "CVTRec::KFTrajectory")); + } + } + else { + double[] xyBeam = CVTReconstruction.getBeamSpot(event, beamPos); + TracksFromTargetRec trackFinder = new TracksFromTargetRec(swimmer, xyBeam); + trackFinder.totTruthHits = reco.getTotalNbTruHits(); + List seeds = trackFinder.getSeeds(clusters, crosses); + + + List tracks = trackFinder.getTracks(event, this.isInitFromMc(), + this.isKfFilterOn(), + this.getKfIterations(), + true, this.getPid()); + +// if(seeds!=null) { +// banks.add(RecoBankWriter.fillSeedBank(event, seeds, this.getSeedBank())); +// banks.add(RecoBankWriter.fillSeedClusBank(event, seeds, this.getSeedClusBank())); +// } + if(tracks!=null) { + ((HipoDataEvent) event).getHipoEvent().reset(); +// banks.add(RecoBankWriter.fillTrackBank(event, tracks, this.getTrackBank())); +// // banks.add(RecoBankWriter.fillTrackCovMatBank(event, tracks, this.getCovMat())); +// banks.add(RecoBankWriter.fillTrajectoryBank(event, tracks, this.getTrajectoryBank())); +// banks.add(RecoBankWriter.fillKFTrajectoryBank(event, tracks, this.getKFTrajectoryBank())); + } + } + } +// banks.add(RecoBankWriter.fillSVTHitBank(event, hits.get(0), this.getSvtHitBank())); +// banks.add(RecoBankWriter.fillBMTHitBank(event, hits.get(1), this.getBmtHitBank())); +// banks.add(RecoBankWriter.fillSVTClusterBank(event, clusters.get(0), this.getSvtClusterBank())); +// banks.add(RecoBankWriter.fillBMTClusterBank(event, clusters.get(1), this.getBmtClusterBank())); +// banks.add(RecoBankWriter.fillSVTCrossBank(event, crosses.get(0), this.getSvtCrossBank())); +// banks.add(RecoBankWriter.fillBMTCrossBank(event, crosses.get(1), this.getBmtCrossBank())); +// +// 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 setSvtClusterBank(String bstClusterBank) { + this.svtClusterBank = bstClusterBank; + } + + public void setSvtCrossBank(String bstCrossBank) { + this.svtCrossBank = bstCrossBank; + } + + public void setBmtHitBank(String bmtHitBank) { + this.bmtHitBank = bmtHitBank; + } + + public void setBmtClusterBank(String bmtClusterBank) { + this.bmtClusterBank = bmtClusterBank; + } + + public void setBmtCrossBank(String bmtCrossBank) { + this.bmtCrossBank = bmtCrossBank; + } + + public void setSeedBank(String cvtSeedBank) { + this.cvtSeedBank = cvtSeedBank; + } + + public void setSeedClusBank(String cvtSeedClusBank) { + this.cvtSeedClusBank = cvtSeedClusBank; + } + + public void setTrackBank(String cvtTrackBank) { + this.cvtTrackBank = cvtTrackBank; + } + + public void setUTrackBank(String cvtTrack0Bank) { + this.cvtUTrackBank = cvtTrack0Bank; + } + + public void setTrajectoryBank(String cvtTrajectoryBank) { + this.cvtTrajectoryBank = cvtTrajectoryBank; + } + + public void setCovMatBank(String cvtTrackCovMat) { + this.cvtCovMatBank = cvtTrackCovMat; + } + + public void setKFTrajectoryBank(String cvtKFTrajectoryBank) { + this.cvtKFTrajectoryBank = cvtKFTrajectoryBank; + } + + public String getSvtHitBank() { + return svtHitBank; + } + + public String getSvtClusterBank() { + return svtClusterBank; + } + + public String getSvtCrossBank() { + return svtCrossBank; + } + + public String getBmtHitBank() { + return bmtHitBank; + } + + public String getBmtClusterBank() { + return bmtClusterBank; + } + + public String getBmtCrossBank() { + return bmtCrossBank; + } + + public String getSeedBank() { + return cvtSeedBank; + } + + public String getSeedClusBank() { + return cvtSeedClusBank; + } + public String getTrackBank() { + return cvtTrackBank; + } + + public String getUTrackBank() { + return cvtUTrackBank; + } + + public String getTrajectoryBank() { + return cvtTrajectoryBank; + } + + public String getKFTrajectoryBank() { + return cvtKFTrajectoryBank; + } + + public String getCovMat() { + return cvtCovMatBank; + } + + 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); + } + +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/SampleMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/SampleMaker.java new file mode 100644 index 0000000000..391c0392e7 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/ml/SampleMaker.java @@ -0,0 +1,697 @@ +package org.jlab.rec.cvt.ml; + +import org.jlab.rec.cvt.services.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.clas.swimtools.Swim; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.Geometry; +import org.jlab.rec.cvt.banks.RecoBankWriter; +import org.jlab.rec.cvt.cluster.Cluster; +import org.jlab.rec.cvt.cross.Cross; +import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.track.Seed; +import org.jlab.rec.cvt.track.StraightTrack; +import org.jlab.rec.cvt.track.Track; +import org.jlab.utils.groups.IndexedTable; + +/** + * Service to return reconstructed TRACKS + * format + * + * @author ziegler + * + */ +public class SampleMaker extends ReconstructionEngine { + + @Override + public void detectorChanged(int run) {} + + /** + * @param docacutsum the docacutsum to set + */ + public void setDocacutsum(double docacutsum) { + this.docacutsum = docacutsum; + } + + private int Run = -1; + + private String svtHitBank; + private String svtClusterBank; + private String svtCrossBank; + private String bmtHitBank; + private String mlHitBank; + private String mlSeedBank; + private String mlTrackBank; + private String bmtClusterBank; + private String bmtCrossBank; + private String cvtSeedBank; + private String cvtSeedClusBank; + private String cvtTrackBank; + private String cvtUTrackBank; + private String cvtTrajectoryBank; + private String cvtKFTrajectoryBank; + private String cvtCovMatBank; + private String bankPrefix = ""; + + // run-time options + private int pid = 0; + private int kfIterations = 5; + private boolean kfFilterOn = true; + private boolean initFromMc = false; + + // yaml setting passed to Constants class + private boolean isCosmics = false; + private boolean svtOnly = false; + private String excludeLayers = null; + private String excludeBMTLayers = null; + private int removeRegion = 0; + private int beamSpotConstraint = 2; + private double beamSpotRadius = 0.3; + private String targetMaterial = ""; + private boolean elossPrecorrection = true; + private boolean svtSeeding = true; + private boolean timeCuts = true; + private boolean hvCuts = true; + public boolean useSVTTimingCuts = false; + public boolean removeOverlappingSeeds = true; + public boolean flagSeeds = true; + public boolean gemcIgnBMT0ADC = false; + public boolean KFfailRecovery = true; + public boolean KFfailRecovMisCls = true; + private String matrixLibrary = "EJML"; + private boolean useOnlyTruth = false; + private boolean useSVTLinkerSeeder = true; + private double docacut = 0.75; + private double docacutsum = 1.15; + private int svtmaxclussize = 100; + private int bmtcmaxclussize = 100; + private int bmtzmaxclussize = 100; + private double rcut = 120.0; + private double z0cut = 10; + + public SampleMaker(String name) { + super(name, "ziegler", "6.0"); + } + + public SampleMaker() { + super("CVTEngine", "ziegler", "6.0"); + } + + @Override + public boolean init() { + this.loadConfiguration(); + Constants.getInstance().initialize(this.getName(), + isCosmics, + svtOnly, + excludeLayers, + excludeBMTLayers, + removeRegion, + beamSpotConstraint, + beamSpotRadius, + targetMaterial, + elossPrecorrection, + svtSeeding, + timeCuts, + hvCuts, + useSVTTimingCuts, + removeOverlappingSeeds, + flagSeeds, + gemcIgnBMT0ADC, + KFfailRecovery, + KFfailRecovMisCls, + matrixLibrary, + useOnlyTruth, + useSVTLinkerSeeder, + docacut, + docacutsum, + svtmaxclussize, + bmtcmaxclussize, + bmtzmaxclussize, + rcut, + z0cut); + + this.initConstantsTables(); + this.registerBanks(); + this.printConfiguration(); + return true; + } + + public final void setOutputBankPrefix(String prefix) { + this.bankPrefix = prefix; + } + + public void registerBanks() { + String prefix = bankPrefix; + if(Constants.getInstance().isCosmics) prefix = "Rec"; + this.setMlHitBank("CVT" + prefix + "::MLHit"); + this.setMlSeedBank("CVT" + prefix + "::MLSeed"); + this.setMlTrackBank("CVT" + prefix + "::MLTrack"); + this.setBmtHitBank("BMT" + prefix + "::Hits"); + this.setBmtClusterBank("BMT" + prefix + "::Clusters"); + this.setBmtCrossBank("BMT" + prefix + "::Crosses"); + this.setSvtHitBank("BST" + prefix + "::Hits"); + this.setSvtClusterBank("BST" + prefix + "::Clusters"); + this.setSvtCrossBank("BST" + prefix + "::Crosses"); + this.setSeedBank("CVT" + prefix + "::Seeds"); + this.setSeedClusBank("CVT" + prefix + "::SeedClusters"); + this.setTrackBank("CVT" + prefix + "::Tracks"); + this.setUTrackBank("CVT" + prefix + "::UTracks"); + this.setCovMatBank("CVT" + prefix + "::TrackCovMat"); + this.setTrajectoryBank("CVT" + prefix + "::Trajectory"); + this.setKFTrajectoryBank("CVT" + prefix + "::KFTrajectory"); + super.registerOutputBank(this.bmtHitBank); + super.registerOutputBank(this.mlSeedBank); + super.registerOutputBank(this.mlTrackBank); + super.registerOutputBank(this.mlHitBank); + super.registerOutputBank(this.bmtClusterBank); + super.registerOutputBank(this.bmtCrossBank); + super.registerOutputBank(this.svtHitBank); + super.registerOutputBank(this.svtClusterBank); + super.registerOutputBank(this.svtCrossBank); + super.registerOutputBank(this.cvtSeedBank); + super.registerOutputBank(this.cvtSeedClusBank); + super.registerOutputBank(this.cvtTrackBank); + super.registerOutputBank(this.cvtUTrackBank); + super.registerOutputBank(this.cvtCovMatBank); + super.registerOutputBank(this.cvtTrajectoryBank); + super.registerOutputBank(this.cvtKFTrajectoryBank); + } + + public int getRun(DataEvent event) { + + if (event.hasBank("RUN::config") == false) { + System.err.println("RUN CONDITIONS NOT READ!"); + return 0; + } + + DataBank bank = event.getBank("RUN::config"); + int run = bank.getInt("run", 0); + if(Constants.getInstance().seedingDebugMode) { + System.out.println("EVENT "+bank.getInt("event", 0)); + } + return run; + } + + public int getPid() { + return pid; + } + + public int getKfIterations() { + return kfIterations; + } + + public boolean isKfFilterOn() { + return kfFilterOn; + } + + public boolean isInitFromMc() { + return initFromMc; + } + + public boolean seedBeamSpot() { + return this.beamSpotConstraint>0; + } + + 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 processDataEventUser(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> clusters = reco.findClusters(); + for(int i = 0; i < clusters.size(); i++) { + for(int j = 0; j < clusters.get(i).size(); j++) { + double clsSize = clusters.get(i).get(j).size(); + double centroid = clusters.get(i).get(j).getCentroid(); + double seed = (double) clusters.get(i).get(j).getSeed().getStrip().getStrip(); + for(Hit h : clusters.get(i).get(j)) { + double strip = h.getStrip().getStrip(); + double cweight = 1/(1+Math.abs(strip-centroid)); + double sweight = 1/(1+Math.abs(strip-seed)); + h.setCweight(cweight); + h.setSweight(sweight); + } + } + } + List> crosses = reco.findCrosses(); + + + List banks = new ArrayList<>(); + List seeds = null; + List tracks = null; + if(crosses != null) { + if(Constants.getInstance().isCosmics) { + CosmicTracksRec trackFinder = new CosmicTracksRec(); + List seedsSt = trackFinder.getSeeds(event, clusters.get(0), clusters.get(1), crosses); + List tracksSt = trackFinder.getTracks(event, this.isInitFromMc(), + this.isKfFilterOn(), + this.getKfIterations()); + if(seedsSt!=null) banks.add(RecoBankWriter.fillStraightSeedsBank(event, seedsSt, "CVTRec::CosmicSeeds")); + if(tracksSt!=null) { + banks.add(RecoBankWriter.fillStraightTracksBank(event, tracksSt, "CVTRec::Cosmics")); + banks.add(RecoBankWriter.fillStraightTracksTrajectoryBank(event, tracksSt, "CVTRec::Trajectory")); + banks.add(RecoBankWriter.fillStraightTrackKFTrajectoryBank(event, tracksSt, "CVTRec::KFTrajectory")); + } + } + else { + double[] xyBeam = CVTReconstruction.getBeamSpot(event, beamPos); + TracksFromTargetRec trackFinder = new TracksFromTargetRec(swimmer, xyBeam); + trackFinder.totTruthHits = reco.getTotalNbTruHits(); + seeds = trackFinder.getSeeds(clusters, crosses); + + + tracks = trackFinder.getTracks(event, this.isInitFromMc(), + this.isKfFilterOn(), + this.getKfIterations(), + true, this.getPid()); + + if(seeds!=null) { + banks.add(RecoBankWriter.fillSeedBank(event, seeds, this.getSeedBank())); + banks.add(RecoBankWriter.fillSeedClusBank(event, seeds, this.getSeedClusBank())); + int bankrow=0; + for(Seed s : seeds) { + for(Cluster c: s.getClusters()) { + for(Hit h : c) { + h.setAssociatedSeedID(s.getId()); + h.setSeedBankRow(bankrow); + } + } + bankrow++; + } + } + if(tracks!=null) { + banks.add(RecoBankWriter.fillTrackBank(event, tracks, this.getTrackBank())); + // banks.add(RecoBankWriter.fillTrackCovMatBank(event, tracksSt, this.getCovMat())); + banks.add(RecoBankWriter.fillTrajectoryBank(event, tracks, this.getTrajectoryBank())); + banks.add(RecoBankWriter.fillKFTrajectoryBank(event, tracks, this.getKFTrajectoryBank())); + int bankrow2=0; + for(Track t : tracks) { + for(Cluster c: t.getSeed().getClusters()) { + for(Hit h : c) { + h.setAssociatedTrackID(t.getId()); + h.setTrackBankRow(bankrow2); + } + } + bankrow2++; + } + } + } + } + + banks.add(RecoBankWriter.fillSVTHitBank(event, hits.get(0), this.getSvtHitBank())); + banks.add(RecoBankWriter.fillBMTHitBank(event, hits.get(1), this.getBmtHitBank())); + banks.add(RecoBankWriter.fillSVTClusterBank(event, clusters.get(0), this.getSvtClusterBank())); + banks.add(RecoBankWriter.fillBMTClusterBank(event, clusters.get(1), this.getBmtClusterBank())); + banks.add(RecoBankWriter.fillSVTCrossBank(event, crosses.get(0), this.getSvtCrossBank())); + banks.add(RecoBankWriter.fillBMTCrossBank(event, crosses.get(1), this.getBmtCrossBank())); + + //ML banks + TrackingPerformance.TrackingPerformance(event, hits, seeds, tracks); + if(hits!=null) { + banks.add(BankOutput.fillHitsBank(event, hits, this.getMlHitBank())); + } + if(seeds!=null) { + banks.add(BankOutput.fillSeedsBank(event, seeds, this.getMlSeedBank())); + } + if(tracks!=null) { + banks.add(BankOutput.fillTracksBank(event, tracks, this.getMlTrackBank())); + } + + 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 setSvtClusterBank(String bstClusterBank) { + this.svtClusterBank = bstClusterBank; + } + + public void setSvtCrossBank(String bstCrossBank) { + this.svtCrossBank = bstCrossBank; + } + + public void setBmtHitBank(String bmtHitBank) { + this.bmtHitBank = bmtHitBank; + } + + public void setMlHitBank(String mlHitBank) { + this.mlHitBank = mlHitBank; + } + + public void setMlSeedBank(String mlSeedBank) { + this.mlSeedBank = mlSeedBank; + } + + public void setMlTrackBank(String mlTrackBank) { + this.mlTrackBank = mlTrackBank; + } + + public void setBmtClusterBank(String bmtClusterBank) { + this.bmtClusterBank = bmtClusterBank; + } + + public void setBmtCrossBank(String bmtCrossBank) { + this.bmtCrossBank = bmtCrossBank; + } + + public void setSeedBank(String cvtSeedBank) { + this.cvtSeedBank = cvtSeedBank; + } + + public void setSeedClusBank(String cvtSeedClusBank) { + this.cvtSeedClusBank = cvtSeedClusBank; + } + + public void setTrackBank(String cvtTrackBank) { + this.cvtTrackBank = cvtTrackBank; + } + + public void setUTrackBank(String cvtTrack0Bank) { + this.cvtUTrackBank = cvtTrack0Bank; + } + + public void setTrajectoryBank(String cvtTrajectoryBank) { + this.cvtTrajectoryBank = cvtTrajectoryBank; + } + + public void setCovMatBank(String cvtTrackCovMat) { + this.cvtCovMatBank = cvtTrackCovMat; + } + + public void setKFTrajectoryBank(String cvtKFTrajectoryBank) { + this.cvtKFTrajectoryBank = cvtKFTrajectoryBank; + } + + public String getSvtHitBank() { + return svtHitBank; + } + + public String getSvtClusterBank() { + return svtClusterBank; + } + + public String getSvtCrossBank() { + return svtCrossBank; + } + + public String getBmtHitBank() { + return bmtHitBank; + } + + public String getMlHitBank() { + return this.mlHitBank; + } + + public String getMlSeedBank() { + return this.mlSeedBank; + } + + public String getMlTrackBank() { + return this.mlTrackBank; + } + public String getBmtClusterBank() { + return bmtClusterBank; + } + + public String getBmtCrossBank() { + return bmtCrossBank; + } + + public String getSeedBank() { + return cvtSeedBank; + } + + public String getSeedClusBank() { + return cvtSeedClusBank; + } + public String getTrackBank() { + return cvtTrackBank; + } + + public String getUTrackBank() { + return cvtUTrackBank; + } + + public String getTrajectoryBank() { + return cvtTrajectoryBank; + } + + public String getKFTrajectoryBank() { + return cvtKFTrajectoryBank; + } + + public String getCovMat() { + return cvtCovMatBank; + } + + + 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); + + + } + +}