lcsim/src/org/lcsim/util
diff -u -r1.11 -r1.12
--- OverlayDriver.java 15 Jun 2012 05:24:20 -0000 1.11
+++ OverlayDriver.java 10 Jul 2012 07:31:03 -0000 1.12
@@ -57,7 +57,8 @@
protected double bunchSpacing;
protected boolean randomSignal;
protected boolean fullCaloProcessing;
- protected boolean shuffleBackground;
+ protected boolean randomizeTrainOverlay;
+ protected boolean randomizeOverlay;
protected boolean signalAtZero;
protected double signalTime;
protected int signalBunchCrossing;
@@ -93,7 +94,8 @@
caloHitMap = new HashMap<String, Map<Long,SimCalorimeterHit>>();
overlayMcParticles = new ArrayList<MCParticle>();
allMcParticles = new ArrayList<MCParticle>();
- shuffleBackground = true;
+ randomizeTrainOverlay = true;
+ randomizeOverlay = false;
mcParticleReferences = new HashMap<MCParticle, MCParticle>();
}
@@ -214,12 +216,28 @@
}
/**
- * Selects if the overlay events are randomly overlaid on the event instead of
+ * @deprecated replaced by <i>setShuffleTrainOverlay</i>
+ * @param shuffleOverlay
+ */
+ public void setShuffleOverlay(boolean shuffleOverlay) {
+ this.setRandomizeTrainOverlay(shuffleOverlay);
+ }
+
+ /**
+ * Selects if the overlay events are randomly placed within the bunch train instead of
* in a serial way
* @param shuffleOverlay shuffle the overlay events (default true)
*/
- public void setShuffleOverlay(boolean shuffleOverlay) {
- this.shuffleBackground = shuffleOverlay;
+ public void setRandomizeTrainOverlay(boolean randomizeTrainOverlay) {
+ this.randomizeTrainOverlay = randomizeTrainOverlay;
+ }
+
+ /**
+ * Selects if overlay events are read in random order from the overlay event source.
+ * @param randomizeOverlay
+ */
+ public void setRandomizeOverlay(boolean randomizeOverlay) {
+ this.randomizeOverlay = randomizeOverlay;
}
/**
@@ -235,7 +253,9 @@
// -------------------- Driver Interface --------------------
@Override
protected void startOfData() {
- backgroundDistribution = df.createPoissonDistribution(overlayWeight);
+ if (overlayWeight != 0.) {
+ backgroundDistribution = df.createPoissonDistribution(overlayWeight);
+ }
}
@Override
@@ -288,7 +308,7 @@
}
}
// shuffle the list
- if (shuffleBackground) Collections.shuffle(overlayList, this.getRandom());
+ if (randomizeTrainOverlay) Collections.shuffle(overlayList, this.getRandom());
int bxCounter = 0;
for (int bX : overlayList) {
@@ -308,7 +328,12 @@
System.out.println("Memory free: "+freeMemory/toMB+"MB / "+totalMemory/toMB+"MB ("+100*freeMemory/totalMemory+"%)");
}
- EventHeader overlayEvent = getNextEvent(overlayEvents);
+ EventHeader overlayEvent = null;
+ if (randomizeOverlay) {
+ overlayEvent = skipEvents(overlayEvents, this.getRandom().nextInt((int)overlayEvents.getEstimatedSize()));
+ } else {
+ overlayEvent = getNextEvent(overlayEvents);
+ }
if (overlayEvent != null) {
if (event.getDetector().equals(overlayEvent.getDetector())) {
// clear the mc particle references, which are only needed within one background event
@@ -371,6 +396,24 @@
}
/**
+ * Returns the event from the <b>LCIOEventSource</b> after skipping a given
+ * number of events. If the end of the source is reached, the source is rewound
+ * and the remaining events are skipped counting from the first event. If any
+ * other error occurs, i.e. the source does not exist, null is returned instead.
+ * @param lcio The LCIO source
+ * @param nEvents The number of events to skip
+ * @return
+ */
+ static protected EventHeader skipEvents(LCIOEventSource lcio, int nEvents) {
+ EventHeader event = null;
+ for (int nEvent = 0; nEvent < nEvents; nEvent++) {
+ event = getNextEvent(lcio);
+ if (event == null) break; // no need to loop further if error occurred.
+ }
+ return event;
+ }
+
+ /**
* Calculates the time of flight from the interaction point to
* the position of the given hit along a straight line.
* @param hit
@@ -444,7 +487,13 @@
// don't create new list, just move existing particles
movedCollection = event.get(MCParticle.class, collectionName);
for (MCParticle mcP : (List<MCParticle>)movedCollection) {
- ((SIOMCParticle) mcP).setTime(mcP.getProductionTime()+time);
+ if (mcP instanceof SIOMCParticle) {
+ ((SIOMCParticle) mcP).setTime(mcP.getProductionTime()+time);
+ } else if (mcP instanceof BaseMCParticle){
+ ((BaseMCParticle) mcP).setProductionTime(mcP.getProductionTime()+time);
+ } else {
+ throw new RuntimeException("Unknown type of MCParticle. Can not modify production time.");
+ }
}
} else if (collectionType.isAssignableFrom(SimTrackerHit.class)) {
// SimTrackerHits