Print

Print


Commit in lcsim/src/org/lcsim/util on MAIN
OverlayDriver.java+24-381.1 -> 1.2
Changed debug output to use histogram level instead of a debug flag

lcsim/src/org/lcsim/util
OverlayDriver.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- OverlayDriver.java	15 Feb 2011 23:21:42 -0000	1.1
+++ OverlayDriver.java	26 Feb 2011 11:57:41 -0000	1.2
@@ -33,20 +33,18 @@
 import org.lcsim.util.loop.LCIOEventSource;
 
 /**
- * Driver to overlay one or more events from another slcio source over the current event.
+ * Driver to overlay one or more events from another <i>SLCIO</i> source over the current event.
  * A bunch train can be modeled by setting the number of bunch crossings and the time between
- * those bunch crossings. The number of events overlayed per bunch crossing is drawn from a
+ * those bunch crossings. The number of events overlaid per bunch crossing is drawn from a
  * Poisson distribution and its mpv is set by the weight. Time windows can be set for each
  * collection to model a realistic readout. They control which hits to keep and are applied
  * relative to the time of the original event plus a time of flight correction. A separate
- * collection of McParticles is created only for the particles from the overlayed events.
+ * collection of <b>McParticles</b> is created only for the particles from the overlaid events.
  * 
- * @version 1.0 (Feb 15, 2011)
  * @author <a href="mailto:[log in to unmask]">Christian Grefe</a>
  */
 public class OverlayDriver extends Driver {
 
-	protected boolean debug = false;
 	protected double c = 299.792458; // speed of light in mm/ns
 	protected SpacePoint interactionPoint = new SpacePoint(); // assuming 0 0 0 as IP
 	protected DistributionFactory df;
@@ -90,7 +88,7 @@
 	// -------------------- Steering Parameters --------------------
 	/**
 	 * Sets the number of bunch crossings in a train. This is the maximum number
-	 * of bunch crossings overlayed, independent of readout times.
+	 * of bunch crossings overlaid, independent of readout times.
 	 * @param n the number of bunch crossings in a bunch train, default is 1
 	 */
 	public void setBunchCrossings(int n) {
@@ -131,7 +129,7 @@
 	}
 	
 	/**
-	 * Sets a name as an identifier for the overlayed events.
+	 * Sets a name as an identifier for the overlaid events.
 	 * The name is used in an LCRelation to identify McParticles from the overlay.
 	 * @param name identifier for the overlay events
 	 */
@@ -141,7 +139,7 @@
 	
 	/**
 	 * Sets the number of overlay event used per bunch crossing.
-	 * The actual number per event is drawn from a poisson distribution with the
+	 * The actual number per event is drawn from a Poisson distribution with the
 	 * weight being the most probable value of the distribution.
 	 * A weight of 0 will instead add one overlay event per bunch crossing.
 	 * @param weight the most probable number of overlay events added per bunch crossing
@@ -171,7 +169,7 @@
 	 */
 	public void setReadoutTime(String[] collection) {
 		if (collection.length != 2) {
-			throw new RuntimeException("Needs exactly two strings");
+			throw new RuntimeException("setReadoutTime takes a list of exactly two strings");
 		}
 		readoutTimes.put(collection[0], Double.valueOf(collection[1]));
 	}
@@ -195,7 +193,7 @@
 	}
 	
 	/**
-	 * Selects if the overlay events are randomly overlayed on the event instead of
+	 * Selects if the overlay events are randomly overlaid on the event instead of
 	 * in a serial way
 	 * @param shuffleOverlay shuffle the overlay events (default true)
 	 */
@@ -213,14 +211,6 @@
 		this.signalAtZero = signalAtZero;
 	}
 	
-	/**
-	 * Switches on additional messages
-	 * @param debug
-	 */
-	public void setDebug(boolean debug) {
-		this.debug = debug;
-	}
-	
 	// -------------------- Driver Interface --------------------
 	@Override
 	protected void startOfData() {
@@ -246,7 +236,7 @@
 		}
 		double signalTime = 0;
 		if (!signalAtZero) signalTime = signalBunchCrossing * bunchSpacing;
-		if (debug) System.out.println("Move 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
@@ -271,27 +261,23 @@
 		
 		System.out.println("signal event mc particles: "+event.getMCParticles().size());
 		for (int bX : overlayList) {
-			if (debug) System.out.println("Overlaying BX "+bX);
+			if (this.getHistogramLevel() > HLEVEL_OFF) System.out.println("Overlaying BX "+bX);
 			
 			double overlayTime = (bX - signalBunchCrossing) * bunchSpacing;
 			if (!signalAtZero) overlayTime = bX * bunchSpacing;
 			
 			EventHeader overlayEvent = this.getNextEvent(overlayEvents);
-			if (debug) System.out.println("Memory free: "+100*Runtime.getRuntime().freeMemory()/Runtime.getRuntime().totalMemory()+(" %"));
+			if (this.getHistogramLevel() > HLEVEL_NORMAL) System.out.println("Memory free: "+100*Runtime.getRuntime().freeMemory()/Runtime.getRuntime().totalMemory()+(" %"));
 			if (overlayEvent != null) {
 				if (event.getDetector().equals(overlayEvent.getDetector())) {
 					this.mergeEvents(event, overlayEvent, overlayTime);
 				} else {
-					if (debug) System.err.println("Unable to merge events simulated in different detectors");
+					System.err.println("Unable to merge events simulated in different detectors");
 				}
 			} else {
-				if (debug) System.err.println("Error reading from overlay event list");
+				System.err.println("Error reading from overlay event list");
 			}
 		}
-		if (debug) {
-			System.out.println("Mc particles after merging: "+event.getMCParticles().size());
-			System.out.println("Mc particles from background: "+event.get(MCParticle.class, mcOverlayName).size());
-		}
 	}
 	
 	@Override
@@ -306,7 +292,7 @@
 	
 	// -------------------- Protected Methods --------------------
 	/**
-	 * Goes to the next event in the LCIOEventSource and returns it.
+	 * Goes to the next event in the <b>LCIOEventSource</b> and returns it.
 	 * If the end of the source is reached, the source is rewound and
 	 * the first event will be returned. If any other error occurs,
 	 * i.e. the source does not exist, null is returned instead.
@@ -355,7 +341,7 @@
 		} else {
 			event.put(collection.getName(), entries, collection.getType(), collection.getFlags());
 		}
-		if (debug) System.out.println("Put collection: "+collection.getName());
+		if (this.getHistogramLevel() > HLEVEL_NORMAL) System.out.println("Putting collection "+collection.getName()+" into event.");
 	}
 	
 	/**
@@ -390,7 +376,7 @@
 		String collectionName = collection.getName();
 		Class collectionType = collection.getType();
 		int flags = collection.getFlags();
-		if (debug) System.out.println("Moving collection: "+collectionName+" of type "+collectionType);
+		if (this.getHistogramLevel() > HLEVEL_NORMAL) System.out.println("Moving collection: "+collectionName+" of type "+collectionType+" to "+time+"ns");
 		
 		double timeWindow = 0;
 		if (readoutTimes.get(collectionName) != null) {
@@ -499,17 +485,17 @@
 					movedHit.shiftTime(time);
 				}
 				movedCollection.add(movedHit);
-				if (debug && nHitsMoved%100 == 0) System.out.print("Moved "+nHitsMoved+" / "+nSimCaloHits+" hits\r");
+				if (this.getHistogramLevel() > HLEVEL_HIGH && nHitsMoved%100 == 0) System.out.print("Moved "+nHitsMoved+" / "+nSimCaloHits+" hits\r");
 			}
-			if (debug) System.out.print("\n");
+			if (this.getHistogramLevel() > HLEVEL_HIGH) System.out.print("\n");
 		} else if (collectionType.isAssignableFrom(GenericObject.class)) {
 			// nothing to do for GenericObjects
 			return event.get(GenericObject.class, collectionName);
 		} else {
-			if (debug) System.err.println("Unable to move collection: "+collectionName+" of type "+collectionType);
+			System.err.println("Unable to move collection: "+collectionName+" of type "+collectionType);
 			return null;
 		}
-		if (debug) System.out.println("Moved collection: "+collectionName+" of type "+collectionType+" to "+time+"ns");
+		if (this.getHistogramLevel() > HLEVEL_NORMAL) System.out.println("Moved collection: "+collectionName+" of type "+collectionType+" to "+time+"ns");
 		return movedCollection;
 	}
 	
@@ -517,7 +503,7 @@
 	 * Merges all collections from the given events and applies a time offset
 	 * to all entries in all collections of the overlay event.
 	 * @param event the event where everything is merged into
-	 * @param overlayEvent the event overlayed
+	 * @param overlayEvent the event overlaid
 	 * @param overlayTime the time offset for the overlay event
 	 */
 	protected void mergeEvents(EventHeader event, EventHeader overlayEvent, double overlayTime) {
@@ -564,7 +550,7 @@
 	 * Merges two collections and applies a time offset to all entries in
 	 * the overlay collection.
 	 * @param collection the collection where the overlay collection is merged into
-	 * @param overlayCollection the collection overlayed
+	 * @param overlayCollection the collection overlaid
 	 * @param overlayTime the time offset for the overlay collection
 	 * @return returns <c>false</c> if unable to merge collections, otherwise <c>true</c>
 	 */
@@ -573,7 +559,7 @@
 		Class collectionType = collection.getType();
 		Class overlayCollectionType = overlayCollection.getType();
 		if (!collectionType.equals(overlayCollectionType)) {
-			if (debug) System.err.println("Can not merge collections: "+collectionName
+			System.err.println("Can not merge collections: "+collectionName
 					+" of type "+collectionType+" and "+overlayCollectionType);
 			return false;
 		}
@@ -684,7 +670,7 @@
 				//event.get(GenericObject.class, collectionName).addAll(overlayEntries);
 				//event.remove("MCParticleEndPointEnergy");
 			} else {
-				if (debug) System.err.println("Can not merge collection "+collectionName
+				System.err.println("Can not merge collection "+collectionName
 						+" of type "+collectionType+". Unhandled type.");
 				return false;
 			}
CVSspam 0.2.8