diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/OccupanceTable.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/OccupanceTable.java new file mode 100644 index 0000000000..82514ea959 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/OccupanceTable.java @@ -0,0 +1,236 @@ +package org.jlab.detector.calib.utils; + +import java.util.Map; +import org.jlab.detector.banks.RawBank; +import org.jlab.detector.banks.RawBank.OrderGroups; +import org.jlab.detector.banks.RawDataBank; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.jnp.hipo4.data.Bank; +import org.jlab.jnp.hipo4.data.Event; +import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.utils.groups.IndexedTable; +import org.jlab.utils.groups.IndexedTable.IndexedEntry; + +/** + * Occupancy bookkeeper based on IndexedTable, with I/O helpers for indexed banks. + * + * @author baltzell + */ +public class OccupanceTable { + + IndexedTable table; + RawBank hitBank; + RawDataBank hitDataBank; + Bank occBank; + + /** + * A 3-index table, e.g., sector/layer/component. + * @param schema + * @param hitBank name of the hit bank + */ + public OccupanceTable(SchemaFactory schema, String hitBank) { + this.hitBank = new RawBank(schema.getSchema(hitBank), 1000, OrderGroups.NOMINAL); + hitDataBank = new RawDataBank(hitBank, 1000, OrderGroups.NOMINAL); + occBank = schema.getBank("OCC::"+hitBank); + table = new IndexedTable(3, new String[]{"occ/F"}); + } + + /** + * An N-index table. + * @param schema + * @param hitBank name of the hit bank + * @param indexCount number of inidices in the hit bank + */ + public OccupanceTable(SchemaFactory schema, String hitBank, int indexCount) { + this.hitBank = new RawBank(schema.getSchema(hitBank), 1000, OrderGroups.NOMINAL); + hitDataBank = new RawDataBank(hitBank, 1000, OrderGroups.NOMINAL); + occBank = schema.getBank("OCC::"+hitBank); + table = new IndexedTable(indexCount, new String[]{"occ/F"}); + } + + /** + * Zero the occupancy table. + */ + public final void reset() { + table = new IndexedTable(table.getList().getIndexSize(), new String[]{"occ/F"}); + } + + /** + * Get the occupancy table, normalized by number of events. + * @param events + * @return + */ + public final IndexedTable getOccupancy(long events) { + IndexedTable t = new IndexedTable(table.getList().getIndexSize(), new String[]{"occ/F"}); + for (long hash : ((Map)table.getList().getMap()).keySet()) { + t.addEntry(IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize())); + t.setDoubleValueByHash((table.getDoubleValueByHash(0, hash))/events, 0, hash); + } + return t; + } + + /** + * Fill the occupancy table. + * @param weight + * @param index + */ + public final void fill(float weight, int... index) { + for (int i=0; i m = table.getList().getMap(); + for (long hash : m.keySet()) { + int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize()); + for (int j=0; j)table.getList().getMap()).keySet()) { + int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize()); + for (int j=0; j 0) event.appendBank(t.create(events, event)); + t.reset(); + } + events = 0; + } + } + } + +} \ No newline at end of file diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java index 5f17e9b6d4..3d4923fea6 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java @@ -115,7 +115,7 @@ public void initDefault(){ String[] names = new String[]{ "MAGFIELDS", "DCCR","DCHB","FTOFHB","EC","HTCC","EBHB", - "DCTB","FTOFTB","EBTB","VTX" + "DCTB","FTOFTB","EBTB","OCC" }; String[] services = new String[]{ @@ -129,7 +129,7 @@ public void initDefault(){ "org.jlab.service.dc.DCTBEngine", "org.jlab.service.ftof.FTOFTBEngine", "org.jlab.service.eb.EBTBEngine", - "org.jlab.rec.service.vtx.VTXEngine" + "org.jlab.calibration.service.OccupanceEngine", }; for(int i = 0; i < names.length; i++){ @@ -145,7 +145,7 @@ public void initAll(){ "CVTFP","CTOF","CND","BAND", "HTCC","LTCC","EBHB", "DCTB","FMT","FTOFTB","CVT","EBTB", - "RICHEB","RTPC","AHDC","ATOF","ALERT", "MC","VTX" + "RICHEB","RTPC","AHDC","ATOF","ALERT", "MC","VTX","OCC" }; String[] services = new String[]{ @@ -178,7 +178,8 @@ public void initAll(){ "org.jlab.service.atof.ATOFEngine", "org.jlab.service.alert.ALERTEngine", "org.jlab.service.mc.TruthMatch", - "org.jlab.rec.service.vtx.VTXEngine" + "org.jlab.rec.service.vtx.VTXEngine", + "org.jlab.calibration.service.OccupanceEngine", }; if(names.length!=services.length) LOGGER.log(Level.SEVERE, "initAll : the list of services does not match the list of service names... "); diff --git a/etc/bankdefs/hipo4/occupancy.json b/etc/bankdefs/hipo4/occupancy.json new file mode 100644 index 0000000000..94b40cfe8c --- /dev/null +++ b/etc/bankdefs/hipo4/occupancy.json @@ -0,0 +1,242 @@ +[ + { + "name": "OCC::DC::tdc", + "group": 500, + "item": 10, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::DC::tot", + "group": 500, + "item": 11, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::ECAL::adc", + "group": 500, + "item": 12, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::ECAL::tdc", + "group": 500, + "item": 13, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::FTOF::adc", + "group": 500, + "item": 14, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::FTOF::tdc", + "group": 500, + "item": 15, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::CTOF::adc", + "group": 500, + "item": 16, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::CTOF::tdc", + "group": 500, + "item": 17, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::HTCC::adc", + "group": 500, + "item": 18, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::HTCC::tdc", + "group": 500, + "item": 19, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::LTCC::adc", + "group": 500, + "item": 20, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::LTCC::tdc", + "group": 500, + "item": 21, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::BST::adc", + "group": 500, + "item": 22, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::BMT::adc", + "group": 500, + "item": 23, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::FTC::adc", + "group": 500, + "item": 24, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::FTH::adc", + "group": 500, + "item": 25, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::FTT::adc", + "group": 500, + "item": 26, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::RICH::tdc", + "group": 500, + "item": 27, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::BAND::adc", + "group": 500, + "item": 28, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + }, + { + "name": "OCC::BAND::tdc", + "group": 500, + "item": 29, + "info": "Occupancy Bank", + "entries": [ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer"}, + { "name":"component" , "type":"S", "info":"component"}, + { "name":"hits" , "type":"F", "info":"number of hits"} + ] + } +] diff --git a/etc/bankdefs/util/bankSplit.py b/etc/bankdefs/util/bankSplit.py index 52b134174c..591ebad0fd 100755 --- a/etc/bankdefs/util/bankSplit.py +++ b/etc/bankdefs/util/bankSplit.py @@ -1,8 +1,9 @@ #!/usr/bin/env python -import json -import sys import os +import sys +import json +import glob # print usage if len(sys.argv)<2: @@ -54,6 +55,9 @@ def create(dirname, banklist): print("Single json files saved in " + workdirectory + singledirectory) +# occupancy banks: +occ = [os.path.basename(x)[:-5] for x in glob.glob('./singles/occupancy/*.json')] + # these should *always* be kept: mc = ["MC::Event", "MC::GenMatch", "MC::Header", "MC::Lund", "MC::Particle", "MC::RecMatch", "MC::True"] tag1 = ["RUN::config", "RAW::epics", "RAW::scaler", "RUN::scaler", "HEL::scaler", "COAT::config", "HEL::flip", "HEL::online", "HEL::decoder"] @@ -83,7 +87,7 @@ def create(dirname, banklist): trig = ["RAW::vtp","HTCC::rec","ECAL::adc","ECAL::calib","ECAL::clusters","ECAL::hits","ECAL::moments","ECAL::peaks","ECAL::tdc","ECAL::trigger"] # accumulate all the DST banks: -dst = rectbai + rectb + mc + tag1 + dets +dst = rectbai + rectb + mc + tag1 + occ + dets dsthb = dst + rechbai + rechb # generate the calib and mon schema: @@ -112,8 +116,6 @@ def create(dirname, banklist): level3 = list(dst) level3.extend(["DC::tdc", "DC::tot", "ECAL::adc", "ECAL::clusters", "FTOF::tdc", "FTOF::adc", "HitBasedTrkg::HBClusters", "HitBasedTrkg::HBTracks", "HTCC::adc", "RF::adc", "RF::tdc", "RUN::rf", "TimeBasedTrkg::TBClusters", "TimeBasedTrkg::TBTracks"]) -import glob - rgl = glob.glob('./singles/full/ALERT*.json') rgl.extend(glob.glob('./singles/full/AHDC*.json')) rgl.extend(glob.glob('./singles/full/ATOF*.json')) diff --git a/etc/services/rgd-clarode.yml b/etc/services/rgd-clarode.yml index e46daddc7e..f8147c4532 100644 --- a/etc/services/rgd-clarode.yml +++ b/etc/services/rgd-clarode.yml @@ -83,3 +83,5 @@ services: name: VTX - class: org.jlab.calibration.service.CalibBanksEngine name: CALIB + - class: org.jlab.calibration.service.OccupanceEngine + name: OCC diff --git a/reconstruction/calib/pom.xml b/reconstruction/calib/pom.xml index 77bb856b5f..21ccc45e20 100644 --- a/reconstruction/calib/pom.xml +++ b/reconstruction/calib/pom.xml @@ -34,6 +34,11 @@ clas-reco 14.1.3-SNAPSHOT + + + org.jlab.jnp + jnp-hipo4 + diff --git a/reconstruction/calib/src/main/java/org/jlab/calibration/service/OccupanceEngine.java b/reconstruction/calib/src/main/java/org/jlab/calibration/service/OccupanceEngine.java new file mode 100644 index 0000000000..63cec499d5 --- /dev/null +++ b/reconstruction/calib/src/main/java/org/jlab/calibration/service/OccupanceEngine.java @@ -0,0 +1,33 @@ +package org.jlab.calibration.service; + +import org.jlab.io.base.DataEvent; +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.detector.calib.utils.OccupanceTable.OccupanceDriver; + +public class OccupanceEngine extends ReconstructionEngine { + + OccupanceDriver occupancy; + + public OccupanceEngine() { + super("Occupance", "baltzell","0.1"); + } + + @Override + public boolean processDataEventUser(DataEvent event) { + occupancy.process(event); + return true; + } + + @Override + public boolean init() { + occupancy = new OccupanceDriver(getSchemaFactory(), + Integer.parseInt(getEngineConfigString("prescale","100"))); + return true; + } + + @Override + public void detectorChanged(int runNumber) { + occupancy.reset(); + } + +} \ No newline at end of file