Print

Print


Commit in lcsim/src/org/lcsim/digisim on MAIN
HitContrib.java+56added 1.1
TempCalHit.java+48-1021.6 -> 1.7
+104-102
1 added + 1 modified, total 2 files
GL: Promote private TempCalHit.HitContrib class to a normal class

lcsim/src/org/lcsim/digisim
HitContrib.java added at 1.1
diff -N HitContrib.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitContrib.java	20 Jan 2006 23:36:34 -0000	1.1
@@ -0,0 +1,56 @@
+package org.lcsim.digisim;
+
+/**
+ * A hit contribution object, useful during digitization simulation.
+ *
+ * @author Guilherme Lima
+ * @version $Id: HitContrib.java,v 1.1 2006/01/20 23:36:34 lima Exp $
+ */
+class HitContrib {
+    /** constructor */
+    public HitContrib(double energy, double time) {
+	_contEnergy = energy;
+	_contTime = time;
+    }
+
+    /** Returns contribution energy */
+    public double energy() {
+	return _contEnergy;
+    }
+
+    /** Returns contribution timing */
+    public double time() {
+	return _contTime;
+    }
+
+    /**
+     * Scale energy contribution.  This is used to apply factors
+     * to the energy values of individual contributions
+     */
+    public void scale(double factor) {
+	_contEnergy *= factor;
+    }
+
+    /** Increment energy contribution, considering time */
+    public void increment(double energy, double time) {
+	_contEnergy += energy;
+	if( time<_contTime ) _contTime = time;
+    }
+
+    /** Increment energy contribution */
+    public void increment(double energy) {
+	_contEnergy += energy;
+    }
+
+    /** Decrement energy contribution */
+    public void decrement(double energy) {
+	_contEnergy -= energy;
+    }
+
+
+    //=== FIELDS ===
+    /** Energy contribution from simHit to tempHit */
+    private double _contEnergy;
+    /** Timing from this contribution */
+    private double _contTime;
+}

lcsim/src/org/lcsim/digisim
TempCalHit.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- TempCalHit.java	14 Jan 2006 00:10:11 -0000	1.6
+++ TempCalHit.java	20 Jan 2006 23:36:34 -0000	1.7
@@ -1,6 +1,8 @@
 package org.lcsim.digisim;
 
 import java.util.Vector;
+import java.util.Map;
+import java.util.HashMap;
 import java.util.Enumeration;
 
 /**
@@ -8,31 +10,47 @@
  * hit information between modifiers.
  *
  * @author Guilherme Lima
- * @version $Id: TempCalHit.java,v 1.6 2006/01/14 00:10:11 lima Exp $
+ * @version $Id: TempCalHit.java,v 1.7 2006/01/20 23:36:34 lima Exp $
  */
 class TempCalHit {
 
+    //===  FIELDS  ===
+
+    /** Temp hit id, supposedly the same as channel ID */
+    private long _rawID;
+    /** Total energy */
+    private double _energy;
+    /** Primary hit timing */
+    private double _time;
+    /** Cell IDs contributing to this TempCalHit object */
+    private Map<Long,HitContrib> _simHits = new HashMap<Long,HitContrib>();
+
+    /** Internal notification flag */
+    private static boolean _warned = false;
+    private static boolean _warned1 = false;
+
+    //=== METHODS ===
+
     private TempCalHit() { };
 
     /** copy constructor */
     public TempCalHit( TempCalHit oldhit ) {
 	this._rawID = oldhit._rawID;
-	this._simHits = new Vector<HitContrib>();
-	for( HitContrib contr : oldhit._simHits ) {
-	  this.addContribution( contr.id(), contr.energy(), contr.time() );
+	
+	for( Long simID : oldhit._simHits.keySet() ) {
+	    HitContrib contr = oldhit._simHits.get( simID );
+	    this.addContribution( simID, contr.energy(), contr.time() );
 	}
     }
 
     /** same-cell constructor */
     public TempCalHit(long simid, double energy, double time) {
-	_simHits = new Vector<HitContrib>();
 	_rawID = simid;
 	addContribution(simid, energy, time);
     }
 
     /** non-same-cell constructor */
     public TempCalHit(long rawid, long simid, double energy, double time) {
-	_simHits = new Vector<HitContrib>();
 	_rawID = rawid;
 	addContribution(simid, energy, time);
     }
@@ -44,10 +62,8 @@
 	}
 	// else
 	double totEnergy = 0.0;
-	Enumeration e = _simHits.elements();
-	while( e.hasMoreElements() ) {
-	    HitContrib elem = (HitContrib)e.nextElement();
-	    totEnergy += elem.energy();
+	for( HitContrib contr : _simHits.values() ) {
+	    totEnergy += contr.energy();
 	}
 	return totEnergy;
     }
@@ -57,7 +73,7 @@
      * @param factor Applied to each contribution separately
      */
     public void scaleEnergy(double factor) {
-	for( HitContrib contr : _simHits ) {
+	for( HitContrib contr : _simHits.values() ) {
 	    contr.scale(factor);
 	}
 	_energy *= factor;
@@ -82,7 +98,7 @@
 	// This should be avoided if possible, because it is better to
 	// set the timing of each contribution separately
 	if(!_warned1) {
-// 	  System.out.println("***** TempCalHit.setTime() called.  Please avoid it.");
+//  	  System.out.println("***** TempCalHit.setTime() called.  Please avoid it.");
 	  _warned1=true;
 	}
 	_time = time;
@@ -97,8 +113,7 @@
 	// else
 	double largestContribTime, primaryTime;
 	double maxEnergy=0, earliestTime=1.0e+12;
-	for(int i=0; i<_simHits.size(); ++i) {
-	    HitContrib elem = (HitContrib)_simHits.get(i);
+	for( HitContrib elem : _simHits.values() ) {
 	    double curTime = elem.time();
 	    if( curTime<earliestTime ) earliestTime = curTime;
 
@@ -114,44 +129,37 @@
 	return _time;
     }
 
-    /** Adds contribution from a simulated hit */
+    /** Adds contribution from a simulated hit (usually from crosstalk) */
     public void addContribution(long id, double energy, double time) {
-	int index = findContribution(id);
-	if( index<_simHits.size() ) {
+	HitContrib contr = _simHits.get(id);
+	if( contr!=null ) {
 	    // contribution already exists
-	    HitContrib hit = (HitContrib)_simHits.get(index);
-	    hit.increment(energy,time);
+	    contr.increment(energy,time);
 	}
 	else {
 	    // new contribution
-	    _simHits.add( new HitContrib(id,energy,time) );
+	    _simHits.put( id, new HitContrib(energy,time) );
 	}
 	_energy += energy;
-	_time = ( time < _time ) ? time : _time ;
+	if(time<_time) _time = time;
     }
 
-    /**
-     * Finds contribution to this TempCalHit from a given simulated hit.
-     *
-     * @param cellID Cell ID of simulated hit wanted
-     * @return index to be used to retrieve the corresponding
-     * contribution
-     */
-    private int findContribution(long cellID) {
-	Enumeration e = _simHits.elements();
-	for(int i=0; i<_simHits.size(); ++i) {
-	    HitContrib elem = (HitContrib)_simHits.get(i);
-	    if(elem.id()==cellID) return i;
-	}
-	// not found... returns collection size (an invalid index!)
-	return _simHits.size();
+    /** Reduce contrib from original hit, due to crosstalk into neighbors */
+    public void reduceContribution(double energy) {
+	// this contribution must always exist!
+	HitContrib contr = _simHits.get( this.getChannelID() );
+	assert contr!=null
+	    : "***** TempCalHit.reduceContrib(): Something is wrong!";
+
+	contr.decrement(energy);
+	_energy -= energy;
     }
 
     /**
      * Returns all the contributions from simulated hits to the
      * current TempCalHit
      */
-    public Vector<HitContrib> getContributions() {
+    public Map<Long,HitContrib> getContributions() {
 	return _simHits;
     }
 
@@ -161,7 +169,7 @@
      */
     public Vector<Double> getEnergyContributions() {
 	Vector<Double> energies = new Vector<Double>();
-	for( HitContrib cont : _simHits ) {
+	for( HitContrib cont : _simHits.values() ) {
 	  energies.add( cont.energy() );
 	}
 	return energies;
@@ -173,8 +181,8 @@
      */
     public Vector<Long> getContributingIDs() {
 	Vector<Long> cellIDs = new Vector<Long>();
-	for( HitContrib cont : _simHits ) {
-	  cellIDs.add( cont.id() );
+	for( Long id : _simHits.keySet() ) {
+	    cellIDs.add( id );
 	}
 	return cellIDs;
     }
@@ -182,66 +190,4 @@
     public long getChannelID() {
 	return _rawID;
     }
-
-    //===  FIELDS  ===
-
-    /** Temp hit id, supposedly the same as channel ID */
-    private long _rawID;
-    /** Total energy */
-    private double _energy;
-    /** Primary hit timing */
-    private double _time;
-    /** Cell IDs contributing to this TempCalHit object */
-    private Vector<HitContrib> _simHits;
-
-    /** Internal notification flag */
-    private static boolean _warned = false;
-    private static boolean _warned1 = false;
-
-    //******** private class HitContrib
-    class HitContrib {
-	/** constructor */
-	public HitContrib(long id, double energy, double time) {
-	    _id = id;
-	    _energy = energy;
-	    _time = time;
-	}
-
-	/** Returns contributing simHit cellID */
-	public long id() {
-	    return _id;
-	}
-
-	/** Returns contribution energy */
-	public double energy() {
-	    return _energy;
-	}
-
-	/** Returns contribution timing */
-	public double time() {
-	    return _time;
-	}
-
-	/**
-	 * Scale energy contribution.  This is used to apply factors
-	 * to the energy values of individual contributions
-	 */
-	public void scale(double factor) {
-	    _energy *= factor;
-	}
-
-	/** Increment energy contribution */
-	public void increment(double energy, double time) {
-	    _energy += energy;
-	    if( time<_time ) _time = time;
-	}
-
-	//=== FIELDS ===
-	/** Simulated hit cellID */
-	private long _id;
-	/** Energy contribution from simHit to tempHit */
-	private double _energy;
-	/** Timing from this contribution */
-	private double _time;
-    }
 }
CVSspam 0.2.8