Hi, Kyle.
public
class EcalCrystalExample
extends Driver {
IDetectorElementContainer
crystals;
IIdentifierHelper
helper;
int system;
public void detectorChanged(Detector
detector) {
Subdetector
subdetector = detector.getSubdetector("Ecal");
system = subdetector.getSystemID();
helper = subdetector.getDetectorElement().getIdentifierHelper();
crystals = subdetector.getDetectorElement().getChildren();
}
public void process(EventHeader
event) {
List<CalorimeterHit>
hits = event.get(CalorimeterHit.class,
"EcalCalHits");
for (CalorimeterHit hit :
hits) {
EcalCrystal
crystal;
// Find crystal from hit ID.
crystal = (EcalCrystal) crystals.find(hit.getIdentifier());
// Hit already points to crystal directly.
crystal = (EcalCrystal) hit.getDetectorElement();
// Example of making a new ID to lookup crystal.
IExpandedIdentifier
expId = new ExpandedIdentifier();
expId.addValue(system);
expId.addValue(0);
expId.addValue(helper.getValue(hit.getIdentifier(),
"ix"));
expId.addValue(helper.getValue(hit.getIdentifier(),
"iy"));
IIdentifier
crystalId = helper.pack(expId);
crystal = (EcalCrystal) crystals.find(crystalId);
System.out.println(crystal.getName() +
" @ " + crystal.getGeometry().getPosition());
}
}
}
You should look at the section commented as “Example of making a new ID” where I use the hit’s X and Y values to lookup the crystal. But these could be values coming from some other source than the hit.
You can also loop over all the crystals in the container to find what you need there but lookup by ID will be much faster.