Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
999c3ba
add more helpful helper method
baltzell Aug 12, 2026
8c39661
simplify
baltzell Aug 12, 2026
c9f1720
add occupancy table
baltzell Aug 10, 2026
e169100
complete OccupancyTable class
baltzell Aug 11, 2026
7f454cb
cleanup
baltzell Aug 11, 2026
2455b18
cleanup
baltzell Aug 11, 2026
239b819
add missing method
baltzell Aug 11, 2026
763864c
add bank
baltzell Aug 11, 2026
46e99c6
make it work
baltzell Aug 12, 2026
5dbac4f
cleanup
baltzell Aug 12, 2026
145a026
cleanup
baltzell Aug 12, 2026
51ec338
more
baltzell Aug 13, 2026
cbbd245
claraify it
baltzell Aug 13, 2026
48b1d7e
untagged periodic instead
baltzell Aug 13, 2026
9c18bb1
cleanup
baltzell Aug 13, 2026
3f59013
go long
baltzell Aug 13, 2026
a2e8955
cleanup
baltzell Aug 13, 2026
d207b54
cleanup
baltzell Aug 13, 2026
404139a
cleanup
baltzell Aug 13, 2026
fbaee82
cleanup
baltzell Aug 13, 2026
8ac7df8
cleanup
baltzell Aug 13, 2026
0ae575e
doc
baltzell Aug 13, 2026
2401d63
cleanup
baltzell Aug 14, 2026
592aeca
rename
baltzell Aug 14, 2026
283540a
cleanup
baltzell Aug 14, 2026
79c713a
add more detectors
baltzell Aug 14, 2026
a21a23e
update
baltzell Aug 14, 2026
c427728
revert unrelated changes
baltzell Aug 14, 2026
52be0a5
new schema directory for each file
baltzell Aug 14, 2026
92ba832
add occupancy banks to dst (all) schema
baltzell Aug 14, 2026
12ad126
debug
baltzell Aug 14, 2026
8199bbf
fix bank name
baltzell Aug 14, 2026
e5eaf4a
remove printouts
baltzell Aug 14, 2026
8b07906
debug
baltzell Aug 14, 2026
fb55fa9
ignore negative indices (BMT?)
baltzell Aug 14, 2026
cbb58bc
cleanup
baltzell Aug 14, 2026
0423018
add column-index accessors
baltzell Aug 15, 2026
d5516e0
extension class too
baltzell Aug 15, 2026
d0d19e9
Merge branch 'development' into occupancy
baltzell Aug 15, 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
Expand Up @@ -135,6 +135,51 @@ public float getFloat(String varName, int index ){
return bank.getFloat(varName, indexList.get(index));
}

/**
* @param column
* @param index filtered index to retrieve
* @return value for the filtered index
*/
public int getByte(int column, int index ){
return bank.getByte(column, indexList.get(index));
}

/**
* @param column
* @param index filtered index to retrieve
* @return value for the filtered index
*/
public int getShort(int column, int index ){
return bank.getShort(column, indexList.get(index));
}

/**
* @param column
* @param index filtered index to retrieve
* @return value for the filtered index
*/
public int getInt(int column, int index ){
return bank.getInt(column, indexList.get(index));
}

/**
* @param column
* @param index filtered index to retrieve
* @return value for the filtered index
*/
public long getLong(int column, int index ){
return bank.getLong(column, indexList.get(index));
}

/**
* @param column
* @param index filtered index to retrieve
* @return value for the filtered index
*/
public float getFloat(int column , int index ){
return bank.getFloat(column, indexList.get(index));
}

/**
* @param index filtered index to retrieve
* @return true bank row index corresponding to the filtered index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,51 @@ public float getFloat(String varName, int index ){
return dataBank.getFloat(varName, indexList.get(index));
}

/**
* @param index filtered index to retrieve
* @return value for the filtered index
*/
@Override
public int getByte(int column, int index ){
return dataBank.getByte(column, indexList.get(index));
}

/**
* @param index filtered index to retrieve
* @return value for the filtered index
*/
@Override
public int getShort(int column, int index ){
return dataBank.getShort(column, indexList.get(index));
}

/**
* @param index filtered index to retrieve
* @return value for the filtered index
*/
@Override
public int getInt(int column, int index ){
return dataBank.getInt(column, indexList.get(index));
}

/**
* @param index filtered index to retrieve
* @return value for the filtered index
*/
@Override
public long getLong(int column, int index ){
return dataBank.getLong(column, indexList.get(index));
}

/**
* @param index filtered index to retrieve
* @return value for the filtered index
*/
@Override
public float getFloat(int column, int index ){
return dataBank.getFloat(column, indexList.get(index));
}

public static void main(String[] args){

RawDataBank ftof = new RawDataBank("FTOF::adc");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
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.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 {

protected Bank hitBank;
protected Bank occBank;
protected IndexedTable table;
protected String[] valueNames = {"occ/F"};
protected int[] indices = {0,1,2};

public OccupanceTable(SchemaFactory schema, String hits, String occupancy, int... index) {
indices = index;
hitBank = schema.getBank(hits);
occBank = schema.getBank(occupancy);
reset();
}

public OccupanceTable(SchemaFactory schema, String hits, String occupancy) {
hitBank = schema.getBank(hits);
occBank = schema.getBank(occupancy);
reset();
}

/**
* Reset occupancy table.
*/
public final void reset() {
table = new IndexedTable(indices.length, valueNames);
}

/**
* Get number of rows for the occupancy table/bank.
* @return rows
*/
public final int getRows() {
return table.getRowCount();
}

/**
* Get the raw occupancy table.
* @return
*/
public final IndexedTable getOccupancy() {
return table;
}

/**
* Get the normalized occupancy table.
* @param events
* @return
*/
public final IndexedTable getOccupancy(long events) {
IndexedTable t = new IndexedTable(indices.length, valueNames);
for (long hash : ((Map<Long,IndexedEntry>)table.getList().getMap()).keySet()) {
t.addEntry(IndexedTable.DEFAULT_GENERATOR.getIndices(hash, indices.length));
t.setDoubleValueByHash((table.getDoubleValueByHash(0, hash))/events, 0, hash);
}
return t;
}

/**
* Fill occupancy table with a weight.
* @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.setIntValueByHash(0, 0, hash);
}
table.setDoubleValueByHash(table.getDoubleValueByHash(0, hash) + weight, 0, hash);
}

/**
* Fill occupancy table.
* @param index
*/
public final void fill(int... index) {
fill(1.0f, index);
}

/**
* Fill occupancy table from a user-defined bank.
* @param bank
* @param weighted
*/
public void fill(Bank bank, boolean weighted) {
int rows = bank.getRows();
int[] idx = new int[indices.length];
for (int i=0; i<rows; i++) {
for (int j=0; j<indices.length; j++) {
if (j==2) idx[j] = bank.getShort(j,i);
else idx[j] = bank.getByte(j,i);
}
if (weighted) fill(bank.getFloat(indices.length,i), idx);
else fill(idx);
}
}

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

/**
* Fill occupancy table from a user-defined bank, unweighted.
* @param bank
*/
public void fill(DataBank bank) {
if (bank != null) {
final int rows = bank.rows();
int[] idx = new int[indices.length];
for (int i=0; i<rows; i++) {
for (int j=0; j<indices.length; j++) {
if (j==2) idx[j] = bank.getShort(j,i);
else idx[j] = bank.getByte(j,i);
}
fill(idx);
}
}
}

/**
* Fill occupancy table from the hit bank, unweighted.
* @param event
*/
public void fill(DataEvent event) {
fill(event.getBank(hitBank.getSchema().getName()));
}

/**
* Create an occupancy bank.
* @param events
* @param event
* @return
*/
public final DataBank create(long events, DataEvent event) {
DataBank b = event.createBank(occBank.getSchema().getName(), getRows());
int i = 0;
Map<Long,IndexedEntry> m = table.getList().getMap();
for (long hash : m.keySet()) {
int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices(hash, indices.length);
for (int j=0; j<indices.length; j++) {
if (j == 2) b.setShort(j, i, (short)idx[j]);
else b.setByte(j, i, (byte)idx[j]);
}
b.setFloat(indices.length, i, ((float)m.get(hash).getValue(0).intValue())/events);
i++;
}
return b;
}

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

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","DC::occ"),
new OccupanceTable(schema,"ECAL::adc","ECAL::aocc"),
new OccupanceTable(schema,"ECAL::tdc","ECAL::tocc"),
new OccupanceTable(schema,"FTOF::adc","FTOF::aocc"),
new OccupanceTable(schema,"FTOF::tdc","FTOF::tocc"),
new OccupanceTable(schema,"CTOF::adc","CTOF::aocc"),
new OccupanceTable(schema,"CTOF::tdc","CTOF::tocc"),
new OccupanceTable(schema,"HTCC::adc","HTCC::aocc"),
new OccupanceTable(schema,"HTCC::tdc","HTCC::tocc"),
new OccupanceTable(schema,"LTCC::adc","LTCC::aocc"),
new OccupanceTable(schema,"LTCC::tdc","LTCC::tocc"),
new OccupanceTable(schema,"SVT::adc","SVT::occ"),
new OccupanceTable(schema,"BMT::adc","BMT::occ"),
new OccupanceTable(schema,"FTC::adc","FTC::occ"),
new OccupanceTable(schema,"FTH::adc","FTH::occ"),
new OccupanceTable(schema,"FTT::adc","FTT::occ"),
new OccupanceTable(schema,"RICH::tdc","RICH::occ"),
new OccupanceTable(schema,"BAND::tdc","BAND::occ"),
};
}
public void process(Event event) {
for (OccupanceTable t : tables) t.fill(event);
if (events++ % prescale == 0) {
for (OccupanceTable t : tables) {
if (t.getRows() > 0) event.write(t.create(events));
t.reset();
}
events = 0;
}
}
public void process(DataEvent event) {
for (OccupanceTable t : tables) t.fill(event);
if (events++ % prescale == 0) {
for (OccupanceTable t : tables) {
if (t.getRows() > 0) event.appendBank(t.create(events, event));
t.reset();
}
events = 0;
}
}
public void reset() {
for (OccupanceTable t : tables) 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