Print

Print


Commit in lcsim/src/org/lcsim/digisim on MAIN
TimeDiscrimination.java+126added 1.1
ModifierParameters.java+8-71.4 -> 1.5
DigiSimDriver.java+30-191.13 -> 1.14
+164-26
1 added + 2 modified, total 3 files
GL: new modifier for time threshold

lcsim/src/org/lcsim/digisim
TimeDiscrimination.java added at 1.1
diff -N TimeDiscrimination.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TimeDiscrimination.java	14 Jan 2006 00:08:48 -0000	1.1
@@ -0,0 +1,126 @@
+package org.lcsim.digisim;
+
+import org.lcsim.digisim.AbstractCalHitModifier;
+import java.util.Vector;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A modifier for basic time smearing + threshold transformations
+ *
+ * @author Guilherme Lima
+ * @version $Id: TimeDiscrimination.java,v 1.1 2006/01/14 00:08:48 lima Exp $
+ */
+class TimeDiscrimination extends AbstractCalHitModifier {
+
+    /** Returns a reference to a new instance */
+    public TimeDiscrimination newInstance(Digitizer digitizer,
+					  ModifierParameters modpars) {
+	return new TimeDiscrimination(digitizer, modpars);
+    }
+
+    /** private constructor, call newInstance() instead */
+    private TimeDiscrimination(Digitizer digi, ModifierParameters modpars) {
+	super(digi, modpars);
+    }
+
+    /** default constructor is only called for global instance */
+    private TimeDiscrimination() {
+	super(null, new ModifierParameters( ModifierParameters.Type.TimeDiscrimination.toString(), ModifierParameters.Type.TimeDiscrimination, new Vector<Double>()) );
+    }
+
+    public static boolean registerMe() {
+	String type = ModifierParameters.Type.TimeDiscrimination.toString();
+ 	AbstractCalHitModifier.registerModifier(type, _me);
+	return true;
+    }
+
+    //*** Defining modifier interface ***
+
+    /** initialize parameters */
+    public void init(Vector<Double> params) {
+	_par = params;
+	if(_debug>0) {
+	    int i=0;
+	    for( Double x : params ) {
+	       System.out.println(_name+".init(): _par["+(i++)+"] = "+x);
+	    }
+	}
+    }
+
+    /**
+     * This is where real work is performed.
+     * @param hitmap map with transient hits.  Both input and output.
+     */
+    public void processHits(Map<Long,TempCalHit> hitmap) {
+      if(_debug>0) {
+	  System.out.println(" name="+_name+", debug="+_debug+", orig.hitmap.size="+hitmap.size());
+      }
+
+      double time;
+
+      Vector<Long> toBeErased = new Vector<Long>();
+      // apply threshold
+      for( Map.Entry<Long,TempCalHit> entry : hitmap.entrySet() ) {
+	TempCalHit ihit = entry.getValue();
+	long key = entry.getKey();
+	time = ihit.getPrimaryTime();
+
+	if( isAboveThreshold( time ) ) {
+	  // Tried to erase here, but got problems in C++: Docs say
+	  // that iterators are not safe to use after the erase...
+// 	    hitmap.erase(it);
+
+	  // Thus, for now, just save the keys to erase the elements later
+	  toBeErased.add( key );
+	  if(_debug>1) {
+	    System.out.println("Erased hit: time="+time);
+	  }
+	}
+      }
+
+      // Remove elements above time threshold from input collection
+      for( Long key : toBeErased ) {
+ 	  hitmap.remove( key );
+      }
+      if(_debug>0) {
+	  System.out.println(_name+": Final hitmap.size="+hitmap.size());
+      }
+    }
+
+    /** debugging printout */
+    public void print() {
+      System.out.println( this.toString() );
+      System.out.println( _name + ": a gain+threshold modifier" );
+      String ret = new String();
+      if(_par!=null) {
+ 	ret += " Parameters:";
+	for(int i=0; i<_par.size(); ++i) {
+	  ret += " "+ _par.get(i);
+	}
+      }
+      System.out.println(ret);
+    }
+
+    /** transformation functions: discrimination */
+    private boolean isAboveThreshold(double t) {
+	// assign roles to the parameters
+	final double threshNominal = _par.get(0);
+	final double threshWidth = _par.get(1);
+
+	double threshold = threshNominal;
+ 	if(threshWidth>0.0) {
+	    threshold = threshNominal + threshWidth * _random.nextGaussian();
+	}
+
+	if(t>threshold) return true;
+	else return false;
+    }
+
+    //=== FIELDS ===
+
+    /** Parameters: gain and threshold */
+    private Vector<Double> _par;
+    /** Global instance, used only for registration */
+    private static TimeDiscrimination _me = new TimeDiscrimination();
+}

lcsim/src/org/lcsim/digisim
ModifierParameters.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- ModifierParameters.java	27 Jun 2005 21:34:32 -0000	1.4
+++ ModifierParameters.java	14 Jan 2006 00:08:48 -0000	1.5
@@ -6,7 +6,7 @@
  * Encapsulates the configuration parameters for any DigiSim modifier.
  *
  * @author Guilherme Lima
- * @version $Id: ModifierParameters.java,v 1.4 2005/06/27 21:34:32 lima Exp $
+ * @version $Id: ModifierParameters.java,v 1.5 2006/01/14 00:08:48 lima Exp $
  */
 public class ModifierParameters {
     /**
@@ -25,16 +25,17 @@
 
     /** Enumerates all possible modifier types */
     public enum Type {
-	GainDiscrimination,
 	AbsValueDiscrimination,
-	SmearedGain,
-	SmearedTiming,
 	Crosstalk,
-	GaussianNoise,
+	DeadCell,
 	ExponentialNoise,
+	GainDiscrimination,
+	GaussianNoise,
 	HotCell,
-	DeadCell,
-	SiPMSaturation
+	SiPMSaturation,
+	SmearedGain,
+	SmearedTiming,
+	TimeDiscrimination
     };
 
     /** Disable default constructor */

lcsim/src/org/lcsim/digisim
DigiSimDriver.java 1.13 -> 1.14
diff -u -r1.13 -r1.14
--- DigiSimDriver.java	7 Dec 2005 18:31:26 -0000	1.13
+++ DigiSimDriver.java	14 Jan 2006 00:08:48 -0000	1.14
@@ -13,25 +13,32 @@
  * both parameters and events from the framework.
  *
  * @author Guilherme Lima
- * @version $Id: DigiSimDriver.java,v 1.13 2005/12/07 18:31:26 lima Exp $
+ * @version $Id: DigiSimDriver.java,v 1.14 2006/01/14 00:08:48 lima Exp $
  */
 public class DigiSimDriver extends Driver {
 
     /**
      * Basic constructor
      * @param name A unique name, typically contains the corresponding
-     * subdetector name.
+     * subdetector name as a substring.
      */
     public DigiSimDriver(String name) {
-      _name = name;
+      _name = new String("");
       _digitizers = new Vector<Digitizer>();
-      getConditionsManager().registerConditionsConverter(new DigiSimConditionsConverter());
+
+      // open released config file from lcsim.jar
+//       _confReader = new ConfigReader(DigiSimDriver.class.getResourceAsStream(_name+".steer"));
+      // user-provided config file (current dir or full path)
+      _confReader = new ConfigReader(name);
+      _useConditions = false;
     }
 
-    /** Private constructor, not to be used */
+    /** By default, takes the steering file from the ConditionsManager */
     public DigiSimDriver() {
+      // _name will store detector name at first process(evt) call
       _name = new String("");
       _digitizers = new Vector<Digitizer>();
+      _useConditions = true;
       getConditionsManager().registerConditionsConverter(new DigiSimConditionsConverter());
     }
 
@@ -41,20 +48,19 @@
      * information, are stored in the same configuration file
      */
     public void init() {
-	// FIXME: This should be using conditions system
-  	System.out.println("DigiSimDriver.init(): _name=<"+_name+">");
 	if(_name.equals("")) return;
 
-	// open released config file from lcsim.jar
-//    	ConfigReader file = new ConfigReader(DigiSimDriver.class.getResourceAsStream(_name+".steer"));
-	// use local config file
-// 	ConfigReader file = new ConfigReader(_name+".steer");
-
 	// read config file
-	DigiSimSetup setup = getConditionsManager().getCachedConditions(DigiSimSetup.class,
-                        "digisim/digisim.steer").getCachedData();
-
- 	Map<String,Vector<String>> sections = setup.getSections();
+	DigiSimSetup setup = null;
+	if(_useConditions) {
+	    // use conditions system
+	    setup = getConditionsManager().getCachedConditions(DigiSimSetup.class, "digisim/digisim.steer").getCachedData();
+	}
+	else {
+	    // use user-provided steering file
+	    setup = _confReader.digiSimParse();
+	}
+	Map<String,Vector<String>> sections = setup.getSections();
 
 	// find digitizers to be instantiated
 	Vector<String> active = new Vector<String>();
@@ -97,12 +103,13 @@
 
 	if(_name.equals("")) {
 	    _name = event.getDetectorName();
+	    System.out.println("Detector name: <"+_name+">");
 	    this.init();
 	}
 
-//  	System.out.println("DigiSimDriver::process()  "+ _name
-//  			   +" in event "+ event.getEventNumber()
-//  			   +" (run "+ event.getRunNumber() + ") ");
+//   	System.out.println("DigiSimDriver::process()  "+ _name
+//   			   +" in event "+ event.getEventNumber()
+//   			   +" (run "+ event.getRunNumber() + ") ");
 	++_nEvt;
 
 	//*** Call processHits method for each modifier
@@ -137,6 +144,9 @@
     private Vector<Digitizer> _digitizers;
 //     private String _digisimURL = "http://nicadd.niu.edu/digisim/config/";
 
+    private boolean _useConditions = true;
+    private ConfigReader _confReader = null;
+
     // static registration globals
     private static boolean _gaindisc = GainDiscrimination.registerMe();
     private static boolean _gaussnoise = GaussianNoise.registerMe();
@@ -148,4 +158,5 @@
     private static boolean _absdisc = AbsValueDiscrimination.registerMe();
     private static boolean _gain = SmearedGain.registerMe();
     private static boolean _timing = SmearedTiming.registerMe();
+    private static boolean _timedisc = TimeDiscrimination.registerMe();
 }
CVSspam 0.2.8