diff --git a/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverter.java b/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverter.java index 02a591e679..5780c5a566 100644 --- a/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverter.java +++ b/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverter.java @@ -2,12 +2,15 @@ import org.lcsim.event.RawTrackerHit; import org.hps.conditions.hodoscope.HodoscopeConditions; +import org.hps.conditions.hodoscope.HodoscopeChannel.GeometryId; import org.hps.conditions.hodoscope.HodoscopeChannel; import org.hps.conditions.hodoscope.HodoscopeChannelConstants; +import org.lcsim.detector.identifier.IIdentifierHelper; import org.lcsim.event.CalorimeterHit; import org.lcsim.event.EventHeader; import java.util.ArrayList; import java.util.Map; +import org.lcsim.geometry.Subdetector; public class HodoRawConverter { @@ -20,6 +23,11 @@ public class HodoRawConverter { private boolean useUserGain = false; private double userGains = 0; private int tet = HodoConstants.TET_AllCh; + + private boolean isMC = false; + + private Subdetector subDetector; + private IIdentifierHelper helper; public ArrayList FindThresholdCrossings(RawTrackerHit hit, double ped) { @@ -70,7 +78,7 @@ public ArrayList FindThresholdCrossings(RawTrackerHit hit, double ped) public ArrayList getCaloHits(RawTrackerHit hit, ArrayList thr_crosings, double ped) { // Getting the cellID of the hit - final long cellID = hit.getCellID(); + long cellID = hit.getCellID(); // ADC values for this hit final short samples[] = hit.getADCValues(); @@ -84,6 +92,12 @@ public ArrayList getCaloHits(RawTrackerHit hit, ArrayList runningPedMap = (Map) event.get("HodoRunningPedestals"); - HodoscopeChannel chan = hodoConditions.getChannels().findGeometric(cellid); - + + HodoscopeChannel chan; + if(!isMC) + chan = hodoConditions.getChannels().findGeometric(cellid); + else + chan = hodoConditions.getChannels().findChannel((int)cellid); + return runningPedMap.get(chan); } else { return findChannel(cellid).getCalibration().getPedestal(); } } - public void setConditions(HodoscopeConditions condition) { + public void setConditions(HodoscopeConditions condition, Subdetector subDetector, IIdentifierHelper helper) { hodoConditions = condition; + this.subDetector = subDetector; + this.helper = helper; } public HodoscopeChannelConstants findChannel(long cellID) { - //System.out.println(hodoConditions.getChannels().findGeometric(cellID)); - return hodoConditions.getChannelConstants(hodoConditions.getChannels().findGeometric(cellID)); + if(!isMC) + return hodoConditions.getChannelConstants(hodoConditions.getChannels().findGeometric(cellID)); + else + return hodoConditions.getChannelConstants(hodoConditions.getChannels().findChannel((int)cellID)); } // =========== Computed Hodoscop identifiers from cellID public int[] getHodoIdentifiers(long cellID) { + HodoscopeChannel chan; + if(!isMC) + chan = hodoConditions.getChannels().findGeometric(cellID); + else + chan = hodoConditions.getChannels().findChannel((int)cellID); + int[] hodo_ids = new int[4]; - hodo_ids[0] = hodoConditions.getChannels().findGeometric(cellID).getIX(); - hodo_ids[1] = hodoConditions.getChannels().findGeometric(cellID).getIY(); - hodo_ids[2] = hodoConditions.getChannels().findGeometric(cellID).getLayer(); - hodo_ids[3] = hodoConditions.getChannels().findGeometric(cellID).getHole(); + hodo_ids[0] = chan.getIX(); + hodo_ids[1] = chan.getIY(); + hodo_ids[2] = chan.getLayer(); + hodo_ids[3] = chan.getHole(); return hodo_ids; } @@ -159,5 +188,14 @@ public void setUseUserGain(double a_usergain) { this.userGains = a_usergain; useUserGain = true; } + + /** + * Set MC mode. + * + * @param isMC + */ + public void setIsMC(final boolean isMC) { + this.isMC = isMC; + } } diff --git a/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverterDriver.java b/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverterDriver.java index 243a0885e4..dc3bf95487 100644 --- a/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverterDriver.java +++ b/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRawConverterDriver.java @@ -3,10 +3,17 @@ import org.lcsim.util.Driver; import org.hps.conditions.database.DatabaseConditionsManager; import org.hps.conditions.hodoscope.HodoscopeConditions; +import org.hps.conditions.hodoscope.HodoscopeChannel.GeometryId; +import org.lcsim.detector.IDetectorElementContainer; +//import org.hps.conditions.hodoscope.HodoscopeChannel.GeometryId; +import org.lcsim.detector.identifier.IIdentifierHelper; +import org.lcsim.detector.identifier.Identifier; +//import org.lcsim.detector.identifier.Identifier; import org.lcsim.event.CalorimeterHit; import org.lcsim.event.RawTrackerHit; import org.lcsim.event.EventHeader; import org.lcsim.geometry.Detector; +import org.lcsim.geometry.Subdetector; import org.lcsim.lcio.LCIOConstants; import java.util.List; @@ -20,11 +27,17 @@ public class HodoRawConverterDriver extends Driver { private HodoscopeConditions hodoConditions = null; private HodoRawConverter converter = null; + + private boolean isMC = false; // ===== The Mode1 Hodo hit collection name ===== private String rawCollectionName = "HodoReadoutHits"; private String hodoCollectionName = "HodoCalHits"; + + private IIdentifierHelper helper = null; + private Subdetector subDetector; + private static final String subdetectorName = "Hodoscope"; // ===== **NOTE** Seems this name can not be arbitrary, it is taken from the detector // ===== For example you can find out this by running this method of the detector @@ -42,6 +55,17 @@ public void setUseRunningPedestal(boolean useRunningPedestal) { public void setUseUserGains(double aUserGain){ converter.setUseUserGain(aUserGain); } + + + /** + * Set MC mode. + * + * @param isMC + */ + public void setIsMC(boolean isMC){ + this.isMC = isMC; + converter.setIsMC(isMC); + } public void setTETAllChannels(int arg_tet) { if (arg_tet <= 0) @@ -59,11 +83,14 @@ public void startOfData() { @Override public void detectorChanged(Detector detector) { + + subDetector = DatabaseConditionsManager.getInstance().getDetectorObject().getSubdetector(subdetectorName); + helper = subDetector.getDetectorElement().getIdentifierHelper(); // Hodo conditions object. hodoConditions = DatabaseConditionsManager.getInstance().getHodoConditions(); - converter.setConditions(hodoConditions); + converter.setConditions(hodoConditions, subDetector, helper); } @@ -95,12 +122,21 @@ public void process(EventHeader event) { ArrayList thr_crosings = converter.FindThresholdCrossings(hit, ped); // ===== For now we will calculate coarse time, which is the threshold crossing sample time. - // ===== Later will implement the mode7 time + // ===== Later will implement the mode7 time ArrayList hits_in_this_channel = converter.getCaloHits(hit, thr_crosings, ped); // Propagate the detector element information to these found_hits so it can be used later. for(CalorimeterHit found_hit: hits_in_this_channel) { - found_hit.setDetectorElement(hit.getDetectorElement()); + if(!isMC) + found_hit.setDetectorElement(hit.getDetectorElement()); + else { + // Set detector element for MC hits + int[] identifier = converter.getHodoIdentifiers(cellID); + GeometryId id_geometry = new GeometryId(helper, new int[]{subDetector.getSystemID(), identifier[0], identifier[1], identifier[2], 0}); + long id_det = id_geometry.encode(); + IDetectorElementContainer srch = subDetector.getDetectorElement().findDetectorElement(new Identifier(id_det)); + found_hit.setDetectorElement(srch.get(0)); + } } hodoHits.addAll(hits_in_this_channel); @@ -134,7 +170,7 @@ public void process(EventHeader event) { SimpleGenericObject generic_cl_time = new SimpleGenericObject(); SimpleGenericObject generic_cl_detid = new SimpleGenericObject(); ArrayList paired = new ArrayList(); - + for (int i = 0; i < hodoHits.size(); i++) { // Check if this hit is already paired, if so, then let's pass to the next hit @@ -158,11 +194,12 @@ public void process(EventHeader event) { cl_Energy = ArrayUtils.add(cl_Energy, this_hit.getRawEnergy()); cl_Time = ArrayUtils.add(cl_Time, this_hit.getTime()); cl_detid = ArrayUtils.add(cl_detid, (int)this_hit.getDetectorElement().getIdentifier().getValue()); - + continue; } boolean pair_found = false; + for (int j = i + 1; j < hodoHits.size(); j++) { @@ -240,6 +277,15 @@ public void process(EventHeader event) { } } + + /** + * Set the input collection name (source). + * + * @param inputCollectionName the input collection name + */ + public void setInputCollectionName(final String inputCollectionName) { + this.rawCollectionName = inputCollectionName; + } /** * Set to true to use a running pedestal calibration from mode diff --git a/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRunningPedestalDriver.java b/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRunningPedestalDriver.java index 6826b13b42..1ab229fd98 100644 --- a/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRunningPedestalDriver.java +++ b/ecal-recon/src/main/java/org/hps/recon/ecal/HodoRunningPedestalDriver.java @@ -36,7 +36,7 @@ public class HodoRunningPedestalDriver extends Driver { // (discard older readouts ; negative = no time limit) private long maxLookbackTime = -1; // units = ms - private static final String rawCollectionName = "HodoReadoutHits"; + private String rawCollectionName = "HodoReadoutHits"; private static final String extraDataRelationsName = "HodoReadoutExtraDataRelations"; private static final String runningPedestalsName = "HodoRunningPedestals"; @@ -55,6 +55,8 @@ public class HodoRunningPedestalDriver extends Driver { private boolean debug = false; private HodoscopeConditions hodoConditions = null; + + private boolean isMC = false; public HodoRunningPedestalDriver() { } @@ -276,12 +278,35 @@ public HodoscopeChannel findChannel(int channel_id) { return hodoConditions.getChannels().findChannel(channel_id); } - public HodoscopeChannel findChannel(RawTrackerHit hit) { - return hodoConditions.getChannels().findGeometric(hit.getCellID()); + public HodoscopeChannel findChannel(RawTrackerHit hit) { + if(!isMC) + return hodoConditions.getChannels().findGeometric(hit.getCellID()); + else + return hodoConditions.getChannels().findChannel((int)hit.getCellID()); } public HodoscopeChannel findChannel(RawCalorimeterHit hit) { - return hodoConditions.getChannels().findGeometric(hit.getCellID()); + if(!isMC) + return hodoConditions.getChannels().findGeometric(hit.getCellID()); + else + return hodoConditions.getChannels().findChannel((int)hit.getCellID()); } - + + /** + * Set the input collection name (source). + * + * @param inputCollectionName the input collection name + */ + public void setInputCollectionName(final String inputCollectionName) { + this.rawCollectionName = inputCollectionName; + } + + /** + * Set MC mode. + * + * @param isMC + */ + public void setIsMC(final boolean isMC) { + this.isMC = isMC; + } } diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon.lcsim index 9514346937..caf39f8686 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon.lcsim @@ -53,13 +53,18 @@ EcalClustersCorr - + + HodoscopeReadoutHits CONFIG + true true + HodoscopeReadoutHits 8 CONFIG + true diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon_LCIO.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon_LCIO.lcsim index 77b0cb39d2..b362685197 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon_LCIO.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2019MCRecon_LCIO.lcsim @@ -89,13 +89,17 @@ + HodoscopeReadoutHits CONFIG + true true + HodoscopeReadoutHits 8 CONFIG + true