lcsim/src/org/lcsim/digisim
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;
- }
}