Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1cdac41
add more helpful helper method
baltzell Aug 12, 2026
5bd9f5d
simplify
baltzell Aug 12, 2026
1184d38
add occupancy table
baltzell Aug 10, 2026
009022e
complete OccupancyTable class
baltzell Aug 11, 2026
c9b19ef
cleanup
baltzell Aug 11, 2026
e13dc5e
cleanup
baltzell Aug 11, 2026
eb17eb0
add bank
baltzell Aug 11, 2026
b090f34
make it work
baltzell Aug 12, 2026
fa5e2a6
cleanup
baltzell Aug 12, 2026
120cf99
cleanup
baltzell Aug 12, 2026
25c4537
more
baltzell Aug 13, 2026
66ca129
claraify it
baltzell Aug 13, 2026
0bfec15
untagged periodic instead
baltzell Aug 13, 2026
f403636
cleanup
baltzell Aug 13, 2026
4bc362f
go long
baltzell Aug 13, 2026
9369074
cleanup
baltzell Aug 13, 2026
ba71f19
cleanup
baltzell Aug 13, 2026
f0177fc
cleanup
baltzell Aug 13, 2026
0fb0c34
cleanup
baltzell Aug 13, 2026
220976b
cleanup
baltzell Aug 13, 2026
625cbc6
doc
baltzell Aug 13, 2026
f168f4d
cleanup
baltzell Aug 14, 2026
2e55ae2
rename
baltzell Aug 14, 2026
9734728
cleanup
baltzell Aug 14, 2026
f2e0333
add more detectors
baltzell Aug 14, 2026
fa32785
update
baltzell Aug 14, 2026
1b7fca1
revert unrelated changes
baltzell Aug 14, 2026
8daa797
add occupancy banks to dst (all) schema
baltzell Aug 14, 2026
ac533a5
debug
baltzell Aug 14, 2026
b049034
fix bank name
baltzell Aug 14, 2026
93449dc
remove printouts
baltzell Aug 14, 2026
3d7d7fe
debug
baltzell Aug 14, 2026
1649c24
ignore negative indices (BMT?)
baltzell Aug 14, 2026
83ba059
cleanup
baltzell Aug 14, 2026
2162b57
fix counter, add DC::tdc
baltzell Aug 16, 2026
996ec1d
change default occupancy prescale to 100
baltzell Aug 16, 2026
44ec2d2
cleanup
baltzell Aug 16, 2026
f0fcc86
cleanup
baltzell Aug 16, 2026
020af89
rename occupancy banks
baltzell Aug 17, 2026
7f1c0f2
this should be final
baltzell Aug 17, 2026
4b22bd1
fix bank name
baltzell Aug 17, 2026
9c22fee
cleanup
baltzell Aug 17, 2026
0606cab
use filtered banks
baltzell Aug 17, 2026
d54cfaf
fix bank names
baltzell Aug 17, 2026
154f472
add occupancy to uber engine
baltzell Aug 22, 2026
44173cb
change yaml variable name
baltzell Aug 25, 2026
6ac884f
cleanup, make it thread-safe
baltzell Aug 25, 2026
4b8398c
fix build
baltzell Aug 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package org.jlab.detector.calib.utils;

import java.util.Map;
import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.utils.groups.IndexedTable.IndexedEntry;
import org.jlab.detector.banks.RawDataBank;
import org.jlab.detector.banks.RawBank.OrderGroups;

/**
* Occupancy bookkeeper based on IndexedTable, with I/O helpers for indexed banks.
*
* @author baltzell
*/
public class OccupanceTable {

String hitBank;
String occBank;
IndexedTable table;

/**
* A 3-index table, e.g., sector/layer/component.
* @param hitBank name of the hit bank
*/
public OccupanceTable(String hitBank) {
this.hitBank = hitBank;
occBank = "OCC::" + hitBank;
table = new IndexedTable(3, new String[]{"occ/F"});
}

/**
* An N-index table.
* @param hitBank name of the hit bank
* @param indexCount number of inidices in the hit bank
*/
public OccupanceTable(String hitBank, int indexCount) {
this.hitBank = hitBank;
occBank = "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<Long,IndexedEntry>)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;
}

public final IndexedTable getTable() {
return table;
}

/**
* Fill the occupancy table.
* @param weight
* @param index
*/
public synchronized final void fill(float weight, int... index) {
for (int i=0; i<index.length; i++) if (index[i] < 0) return;
final long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(index);
if (!table.hasEntryByHash(hash)) {
table.addEntry(index);
table.setDoubleValueByHash(0.0d, 0, hash);
}
table.setDoubleValueByHash(table.getDoubleValueByHash(0, hash) + weight, 0, hash);
}

/**
* Fill occupancy table from a user-defined bank.
* @param bank
* @param weighted
*/
public void fill(RawDataBank bank, boolean weighted) {
if (bank != null) {
final int rows = bank.rows();
int[] idx = new int[table.getList().getIndexSize()];
for (int i=0; i<rows; i++) {
for (int j=0; j<table.getList().getIndexSize(); j++) {
if (j==2) idx[j] = bank.getShort(j,i);
else idx[j] = bank.getByte(j,i);
}
if (weighted) fill(bank.getFloat(table.getList().getIndexSize(),i),idx);
else fill(1.0f, idx);
}
}
}

/**
* Fill occupancy table from the hit bank, unweighted.
* @param event
*/
public void fill(DataEvent event) {
RawDataBank b = new RawDataBank(hitBank, 1000, OrderGroups.NOMINAL);
b.read(event);
fill(b, false);
}

/**
* Get an occupancy bank, normalized by number of events.
* @param events
* @param event
* @return
*/
public DataBank create(long events, DataEvent event) {
DataBank b = event.createBank(occBank, table.getRowCount());
int i = 0;
Map<Long,IndexedEntry> 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().getIndexSize(); j++) {
if (j == 2) b.setShort(j, i, (short)idx[j]);
else b.setByte(j, i, (byte)idx[j]);
}
b.setFloat(table.getList().getIndexSize(), i, ((float)m.get(hash).getValue(0).intValue())/events);
i++;
}
return b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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[]{
Expand All @@ -144,7 +144,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++){
Expand All @@ -160,7 +160,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[]{
Expand Down Expand Up @@ -193,7 +193,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... ");
Expand Down
Loading
Loading