lcsim/src/org/lcsim/util
diff -u -r1.6 -r1.7
--- OverlayDriver.java 29 Apr 2011 17:11:15 -0000 1.6
+++ OverlayDriver.java 29 Apr 2011 20:01:34 -0000 1.7
@@ -63,6 +63,7 @@
protected double signalTime;
protected int signalBunchCrossing;
protected String mcOverlayName;
+ protected String mcSignalName;
protected LCIOEventSource overlayEvents;
protected double overlayWeight;
protected List<Integer> overlayList;
@@ -86,11 +87,13 @@
signalAtZero = true;
signalBunchCrossing = -1;
mcOverlayName = "MCParticles_overlay";
+ mcSignalName = "MCParticles_signal";
overlayWeight = 0;
overlayList = new ArrayList<Integer>();
readoutTimes = new HashMap<String, Double>();
caloHitMap = new HashMap<String, Map<Long,SimCalorimeterHit>>();
overlayMcParticles = new ArrayList<MCParticle>();
+ allMcParticles = new ArrayList<MCParticle>();
shuffleBackground = true;
mcParticleReferences = new HashMap<MCParticle, MCParticle>();
}
@@ -140,7 +143,7 @@
/**
* Sets a name as an identifier for the overlaid events.
- * The name is used in an LCRelation to identify McParticles from the overlay.
+ * It names the sub collection used to identify the overlaid McParticles.
* @param name identifier for the overlay events
*/
public void setOverlayName(String name) {
@@ -148,6 +151,15 @@
}
/**
+ * Sets a name as an identifier for the signal events.
+ * It names the sub collection used to identify the signal McParticles.
+ * @param name identifier for the overlay events
+ */
+ public void setSignalName(String name) {
+ mcSignalName = "MCParticles_"+name;
+ }
+
+ /**
* Sets the number of overlay event used per bunch crossing.
* The actual number per event is drawn from a Poisson distribution with the
* weight being the most probable value of the distribution.
@@ -235,11 +247,19 @@
@Override
protected void process(EventHeader event) {
- // reset the overlay mcParticle lists
+ // reset the mcParticle lists
overlayMcParticles.clear();
+ allMcParticles.clear();
- // always keep all mc particles from signal, no need for reset then
+ // always keep all mc particles from signal
allMcParticles = event.getMCParticles();
+ List<MCParticle> signalMcParticles = new ArrayList<MCParticle>();
+ signalMcParticles.addAll(allMcParticles);
+
+ // keep a sub collection of only signal mc particles
+ int signalFlags = event.getMetaData(event.getMCParticles()).getFlags();
+ signalFlags = LCIOUtil.bitSet(signalFlags, LCIOConstants.BITSubset, true);
+ event.put(mcSignalName, signalMcParticles, MCParticle.class, signalFlags);
// shift the signal event in time according to its BX
if (randomSignal) {
@@ -249,7 +269,7 @@
}
double signalTime = 0;
if (!signalAtZero) signalTime = signalBunchCrossing * bunchSpacing;
- if (this.getHistogramLevel() > HLEVEL_DEFAULT) System.out.println("Moving signal event to BX: "+signalBunchCrossing);
+ if (this.getHistogramLevel() > HLEVEL_OFF) System.out.println("Moving signal event to BX: "+signalBunchCrossing);
this.moveEventToTime(event, signalTime);
// building a list of all bunch crossings in this train
@@ -278,7 +298,7 @@
double overlayTime = (bX - signalBunchCrossing) * bunchSpacing;
if (!signalAtZero) overlayTime = bX * bunchSpacing;
- if (this.getHistogramLevel() > HLEVEL_DEFAULT) {
+ if (this.getHistogramLevel() > HLEVEL_OFF) {
System.out.println("Overlaying background event "+bxCounter+" / "+overlayList.size()+" at BX "+bX+" ("+overlayTime+"ns)");
}
@@ -304,9 +324,9 @@
}
// put the overlay mc particles into the event
- int flags = event.getMetaData(event.getMCParticles()).getFlags();
- flags = LCIOUtil.bitSet(flags, LCIOConstants.BITSubset, true);
- event.put(mcOverlayName, overlayMcParticles, MCParticle.class, flags);
+ int overlayFlags = event.getMetaData(event.getMCParticles()).getFlags();
+ overlayFlags = LCIOUtil.bitSet(signalFlags, LCIOConstants.BITSubset, true);
+ event.put(mcOverlayName, overlayMcParticles, MCParticle.class, overlayFlags);
// reset all lists
caloHitMap.clear();
@@ -489,12 +509,6 @@
movedHit = new BaseSimCalorimeterHit(hit.getCellID(),
rawEnergy, 0., mcArr, eneArr, timeArr, pdgArr);
movedHit.setMetaData(collection);
- // set detector elements for collections which actually implement this method
- try {
- movedHit.setDetectorElement(hit.getDetectorElement());
- } catch (Exception e) {
- // nothing to do
- }
} else {
double hitTime = hit.getTime() + time;
if (hitTime < signalTime + tofCorr + tofCaloOffset || hitTime > signalTime + tofCorr + timeWindow) continue;
@@ -538,8 +552,9 @@
}
/**
- * Adds an mc particle to the list of mc particles as well as the overlay mc particles.
- * Also adds the chain of parents.
+ * Copies an mc particle and stores it together with the copy in a map.
+ * Adds it to the list of mc particles as well as the overlay mc particles.
+ * Also copies and keeps all ancestors.
* @param event
* @param particle
*/
@@ -560,9 +575,12 @@
}
/**
- *
- * @param mcParticle
- * @return
+ * Deep copy of an mc particle. Necessary in order to be able to close an
+ * overlay event. The parent and daught relations are <b>not</b> set for the
+ * copied mc particle. Because those should most likely also point to copies
+ * this should be handled somewhere else.
+ * @param mcParticle The mc particle to be copied
+ * @return the copied mc particle
*/
static public MCParticle copyMcParticle(MCParticle mcParticle) {
Hep3Vector origin = new BasicHep3Vector(mcParticle.getOriginX(), mcParticle.getOriginY(), mcParticle.getOriginZ());
@@ -577,10 +595,11 @@
}
/**
- *
- * @param hit
- * @param meta
- * @return
+ * Deep copy of an SimTrackerHit. Necessary in order to be able to close an
+ * overlay event.
+ * @param hit The hit to be copied
+ * @param meta The meta data that will be attached to the hit
+ * @return The copied SimTrackerHit
*/
protected SimTrackerHit copySimTrackerHit(SimTrackerHit hit, LCMetaData meta) {
@@ -600,15 +619,18 @@
this.addOverlayMcParticle(hitMC);
MCParticle mcParticle = mcParticleReferences.get(hitMC);
IDetectorElement de = null;
- try {
- de = hit.getDetectorElement();
- } catch (Exception e) {
- // nothing to do
- }
return new BaseSimTrackerHit(position, dEdx, momentum, pathLength, time, cellID, mcParticle, meta, de);
}
+ /**
+ * Deep copy of an SimCalorimeterHit. Necessary in order to be able to close an
+ * overlay event.
+ * @param hit The hit to be copied
+ * @param meta The meta data that will be attached to the hit
+ * @param hasPDG Flag if the pdg code of the mc contriutions should be saved
+ * @return The copied SimCalorimeterHit
+ */
protected SimCalorimeterHit copySimCalorimeterHit(SimCalorimeterHit hit, LCMetaData meta, boolean hasPDG) {
long id = hit.getCellID();
double rawEnergy = hit.getRawEnergy();
@@ -632,11 +654,6 @@
BaseSimCalorimeterHit copyHit = new BaseSimCalorimeterHit(id, rawEnergy, time, mcparts, energies, times, pdgs);
copyHit.setMetaData(meta);
- try {
- copyHit.setDetectorElement(hit.getDetectorElement());
- } catch (Exception e) {
- // nothing to do
- }
return copyHit;
}
@@ -746,12 +763,6 @@
SimCalorimeterHit mergedHit = new BaseSimCalorimeterHit(oldHit.getCellID(),
rawEnergy, 0., mcpList, eneList, timeList, pdgList);
mergedHit.setMetaData(collection);
- // set detector elements for collections which actually implement this method
- try {
- mergedHit.setDetectorElement(oldHit.getDetectorElement());
- } catch (Exception e) {
- // nothing to do
- }
// replace old hit with merged hit
signalCaloHits.remove(oldHit);
signalCaloHits.add(mergedHit);