Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5dba77e
add more helpful helper method
baltzell Aug 12, 2026
fe75d01
simplify
baltzell Aug 12, 2026
ab9242f
add occupancy table
baltzell Aug 10, 2026
b39aa6d
complete OccupancyTable class
baltzell Aug 11, 2026
fdbcf36
cleanup
baltzell Aug 11, 2026
76a941b
cleanup
baltzell Aug 11, 2026
fd4bf54
add bank
baltzell Aug 11, 2026
b8c3467
make it work
baltzell Aug 12, 2026
0f94ca3
cleanup
baltzell Aug 12, 2026
b8741b9
cleanup
baltzell Aug 12, 2026
65d0bf6
more
baltzell Aug 13, 2026
76f7676
claraify it
baltzell Aug 13, 2026
08c89f3
untagged periodic instead
baltzell Aug 13, 2026
f85516a
cleanup
baltzell Aug 13, 2026
74eb33f
go long
baltzell Aug 13, 2026
9d34200
cleanup
baltzell Aug 13, 2026
2139259
cleanup
baltzell Aug 13, 2026
5910eb4
cleanup
baltzell Aug 13, 2026
dae23bc
cleanup
baltzell Aug 13, 2026
159895d
cleanup
baltzell Aug 13, 2026
70637be
doc
baltzell Aug 13, 2026
ea2149b
cleanup
baltzell Aug 14, 2026
bbb7f77
rename
baltzell Aug 14, 2026
e52e457
cleanup
baltzell Aug 14, 2026
f4e304d
add more detectors
baltzell Aug 14, 2026
d97c024
update
baltzell Aug 14, 2026
02f00e7
revert unrelated changes
baltzell Aug 14, 2026
f1c6c9e
add occupancy banks to dst (all) schema
baltzell Aug 14, 2026
2917aeb
debug
baltzell Aug 14, 2026
a1f8485
fix bank name
baltzell Aug 14, 2026
8a64ea7
remove printouts
baltzell Aug 14, 2026
3590fad
debug
baltzell Aug 14, 2026
35d4abb
ignore negative indices (BMT?)
baltzell Aug 14, 2026
c7eedef
cleanup
baltzell Aug 14, 2026
9914cc7
add column-index accessors
baltzell Aug 15, 2026
d3e6186
extension class too
baltzell Aug 15, 2026
e6651bd
fix counter, add DC::tdc
baltzell Aug 16, 2026
12f09ec
change default occupancy prescale to 100
baltzell Aug 16, 2026
3875153
cleanup
baltzell Aug 16, 2026
e214f89
cleanup
baltzell Aug 16, 2026
400beba
rename occupancy banks
baltzell Aug 17, 2026
71bc319
this should be final
baltzell Aug 17, 2026
ee92772
fix bank name
baltzell Aug 17, 2026
fa5ffe4
cleanup
baltzell Aug 17, 2026
685fa7a
use filtered banks
baltzell Aug 17, 2026
38e0b64
fix bank names
baltzell Aug 17, 2026
8550f42
Merge branch 'development' into occupancy
baltzell Aug 18, 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,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<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;
}

/**
* Fill the occupancy table.
* @param weight
* @param index
*/
public 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(RawBank bank, boolean weighted) {
int rows = bank.getRows();
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 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(Event event) {
hitBank.read(event);
fill(hitBank, false);
}

/**
* Fill occupancy table from the hit bank, unweighted.
* @param event
*/
public void fill(DataEvent event) {
hitDataBank.read(event);
fill(hitDataBank, false);
}

/**
* Get an occupancy bank, normalized by number of events.
* @param events
* @param event
* @return
*/
public final DataBank create(long events, DataEvent event) {
DataBank b = event.createBank(occBank.getSchema().getName(), 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;
}

/**
* Get an occupancy bank, normalized by number of events.
* @param events
* @return
*/
public final Bank create(long events) {
Bank b = new Bank(occBank.getSchema(), table.getRowCount());
int row = 0;
for (long hash : ((Map<Long,IndexedEntry>)table.getList().getMap()).keySet()) {
int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize());
for (int j=0; j<table.getList().getIndexSize(); j++){
if (j == 2) b.putShort(j, row, (short)idx[j]);
else b.putByte(j, row, (byte)idx[j]);
}
b.putFloat(table.getList().getIndexSize(), row, (float)table.getDoubleValueByHash(0, hash)/events);
row++;
}
return b;
}

/**
* Utility for processing a bunch of occupancies.
*/
public static final class OccupanceDriver {
int events=0,prescale;
OccupanceTable[] tables;
public OccupanceDriver(SchemaFactory schema, int prescale) {
this.prescale = prescale;
tables = new OccupanceTable[] {
new OccupanceTable(schema,"DC::tot"),
new OccupanceTable(schema,"DC::tdc"),
new OccupanceTable(schema,"ECAL::adc"),
new OccupanceTable(schema,"ECAL::tdc"),
new OccupanceTable(schema,"FTOF::adc"),
new OccupanceTable(schema,"FTOF::tdc"),
new OccupanceTable(schema,"CTOF::adc"),
new OccupanceTable(schema,"CTOF::tdc"),
new OccupanceTable(schema,"HTCC::adc"),
new OccupanceTable(schema,"HTCC::tdc"),
new OccupanceTable(schema,"LTCC::adc"),
new OccupanceTable(schema,"LTCC::tdc"),
new OccupanceTable(schema,"BST::adc"),
new OccupanceTable(schema,"BMT::adc"),
new OccupanceTable(schema,"FTCAL::adc"),
new OccupanceTable(schema,"FTHODO::adc"),
new OccupanceTable(schema,"FTTRK::adc"),
new OccupanceTable(schema,"RICH::tdc"),
new OccupanceTable(schema,"BAND::adc"),
new OccupanceTable(schema,"BAND::tdc"),
Comment on lines +195 to +214

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to avoid the DRY violation here, and read occupancy.json somehow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could surely be done.

};
}
public void process(DataEvent event) {
for (OccupanceTable t : tables) t.fill(event);
write(event);
}
public void reset() {
for (OccupanceTable t : tables) t.reset();
events = 0;
}
synchronized void write(DataEvent event) {
if (++events % prescale == 0) {
for (OccupanceTable t : tables) {
if (t.table.getRowCount() > 0) event.appendBank(t.create(events, event));
t.reset();
}
events = 0;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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[]{
Expand All @@ -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++){
Expand All @@ -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[]{
Expand Down Expand Up @@ -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... ");
Expand Down
Loading
Loading