2 added + 1 removed + 7 modified, total 10 files
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/cheat
diff -N RecoDefinitionCrux.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RecoDefinitionCrux.java 13 Feb 2009 20:02:18 -0000 1.1
@@ -0,0 +1,293 @@
+package org.lcsim.contrib.onoprien.crux.cheat;
+
+import java.util.*;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.SimTrackerHit;
+import org.lcsim.geometry.Subdetector;
+
+import org.lcsim.contrib.onoprien.util.NoSuchParameterException;
+import org.lcsim.contrib.onoprien.util.WeightedTable;
+import org.lcsim.contrib.onoprien.util.job.JobManager;
+
+import org.lcsim.contrib.onoprien.vsegment.geom.SegmentationManager;
+import org.lcsim.contrib.onoprien.vsegment.geom.Sensor;
+import org.lcsim.contrib.onoprien.vsegment.hit.ITrackerHit;
+import org.lcsim.contrib.onoprien.vsegment.mctruth.MCTruthVS;
+
+import org.lcsim.contrib.onoprien.crux.infrastructure.RecType;
+import org.lcsim.contrib.onoprien.crux.mctruth.MCTruthCrux;
+import org.lcsim.contrib.onoprien.crux.mctruth.MCTruthDriverCrux;
+
+/**
+ * Simple configurable implementation of {@link IRecoDefinition}.
+ * Used by track finder cheaters and tracking performance analysis classes.
+ * In addition to cuts implemented by {@link RecoDefinition}, this definition allowes
+ * cats based on Monte Carlo truth information accessible through {@link MCTruthCrux}
+ * and {@link MCTruthVS} object. Any class that uses this definition should call its
+ * <tt>startEvent(EventHeader)</tt> method to initialize event-specific data, and
+ * <tt>endEvent()</tt> to clean it up once the event is processed.
+ *
+ * @author D. Onoprienko
+ * @version $Id: RecoDefinitionCrux.java,v 1.1 2009/02/13 20:02:18 onoprien Exp $
+ */
+public class RecoDefinitionCrux extends RecoDefinition {
+
+// -- Private parts : ---------------------------------------------------------
+
+ protected EnumMap<RecType, CutSetCrux> _cutsCrux;
+ protected EnumMap<RecType, String[]> _colNames;
+
+ protected String[] _trackerHitNames;
+
+ protected EnumMap<RecType, WeightedTable<MCParticle,?>> _mcTables;
+
+ protected HashMap<MCParticle, List<ITrackerHit>> _mc2thList;
+
+ protected EventHeader _event;
+ protected MCTruthVS _mcTruthVS;
+ protected MCTruthCrux _mcTruthCrux;
+
+
+// -- Constructors : ----------------------------------------------------------
+
+ public RecoDefinitionCrux() {
+ this("");
+ }
+
+ public RecoDefinitionCrux(String name) {
+ super(name);
+ _cutsCrux = new EnumMap<RecType, CutSetCrux>(RecType.class);
+ _colNames = new EnumMap<RecType, String[]>(RecType.class);
+ _mcTables = new EnumMap<RecType, WeightedTable<MCParticle,?>>(RecType.class);
+ }
+
+
+// -- Setters : ---------------------------------------------------------------
+
+ /**
+ * Set cut parameters. Calling this method with a name of a cut but no values disables the cut.
+ * The following cuts can be configured with this method:
+ * <p><dl>
+ * <dt>"MIN_TRACK_HIT_LAYERS"</dt> <dd>Integer value: minimum number of tracker superlayers with hits.</dd>
+ * </dl>
+ * By default, all cuts are disabled.
+ *
+ * @param type Type of reconstructed object that wiil be selected using this cut.
+ * @param name Name of the cut. Case is ignored.
+ * @param values List of parameters to be used for configuring the cut.
+ * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
+ * @throws IllegalArgumentException Thrown if incorrect number of values, or a value
+ * of incorrect type is supplied.
+ */
+ public void setCut(RecType type, String name, Object... values) {
+ try {
+ super.setCut(type, name, values);
+ } catch (IllegalArgumentException x) {
+ CutSetCrux cutSet = _cutsCrux.get(type);
+ if (cutSet == null) _cutsCrux.put(type, cutSet = new CutSetCrux());
+ try {
+ if (name.equalsIgnoreCase("MIN_TRACK_HIT_LAYERS")) {
+ cutSet.cut_MinTrackerSuperLayers = (values.length == 0) ? 0 : (Integer) values[0];
+ } else {
+ throw new NoSuchParameterException();
+ }
+ } catch (ClassCastException xx) {
+ throw new IllegalArgumentException(xx);
+ }
+ }
+ }
+
+ /**
+ * Sets collection names that should be looked into when deciding whether an object of
+ * a particular type has been successfully reconstructed. If names are not set, default
+ * names supplied through {@link MCTruthDriverCrux} will be used.
+ */
+ public void setCollections(RecType type, String... collectionName) {
+ _colNames.put(type, collectionName);
+ }
+
+ /**
+ * Set parameters.
+ * The following parameters can be set with this method:
+ * <p><dl>
+ * <dt>"TRACKER_HITS"</dt> <dd>Zero or more <tt>String</tt> values specifying
+ * the names of tracker hit collections to be used by this
+ * definition for computing various parameters relevant to tracker-related cuts.
+ * The hits in the specified collections must be of type {@link ITrackerHit}. If an
+ * empty <tt>String</tt> is supplied as the first value, tracker clusters will be used.
+ * If the setter is called with no values, <tt>SimTrackerHits</tt> will be used instead of
+ * digitized hits.<br>
+ * Default: <tt>SimTrackerHits</tt> are used.</dd>
+ * </dl>
+ *
+ * @param name Name of the parameter. Case is ignored.
+ * @param values List of parameters to be used for configuring the cut.
+ * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
+ * @throws IllegalArgumentException Thrown if incorrect number of values, or a value
+ * of incorrect type is supplied.
+ */
+ public void set(String name, Object... values) {
+ try {
+ if (name.equalsIgnoreCase("TRACKER_HITS")) {
+ if (values.length == 0) {
+ _trackerHitNames = null;
+ } else if (((String)(values[0])).equals("")) {
+ _trackerHitNames = new String[0];
+ } else {
+ _trackerHitNames = new String[values.length];
+ for (int i=0; i<values.length; i++) _trackerHitNames[i] = (String) values[i];
+ }
+ } else {
+ throw new NoSuchParameterException(name);
+ }
+ } catch (ClassCastException x) {
+ throw new IllegalArgumentException(x);
+ }
+ }
+
+ /**
+ * Saves a reference to the event record to be used by this definition.
+ * If a driver calls this method, it has to call {@link #clearEvent()} once the event
+ * processing is finished.
+ */
+ public void startEvent(EventHeader event) {
+ _event = event;
+ try {
+ _mcTruthVS = (MCTruthVS) event.get(MCTruthVS.KEY);
+ } catch(IllegalArgumentException x) {
+ _mcTruthVS = null;
+ }
+ try {
+ _mcTruthCrux = (MCTruthCrux) event.get(MCTruthCrux.KEY);
+ } catch(IllegalArgumentException x) {
+ _mcTruthCrux = null;
+ }
+ }
+
+ /**
+ * Clears all references to objects that belong to a particular event.
+ */
+ public void endEvent() {
+ _event = null;
+ _mcTruthVS = null;
+ _mcTruthCrux = null;
+
+ _mc2thList = null;
+
+ _mcTables.clear();
+ }
+
+
+// -- Methods defining "reconstructable" and "reconstructed" : ----------------
+
+ public boolean isFindable(RecType type, MCParticle mcParticle) {
+
+ // Not findable if fails cuts defined in RecoDefinition
+
+ if (! super.isFindable(type, mcParticle)) return false;
+
+ // Findable if no additional cuts
+
+ CutSetCrux cutSet = _cutsCrux.get(type);
+ if (cutSet == null) return true;
+
+ // Minimum number of hit layers cut
+
+ if (cutSet.cut_MinTrackerSuperLayers > 0 &&
+ cutSet.cut_MinTrackerSuperLayers > getNumTrackerSuperLayers(mcParticle)) return false;
+
+ // Passed all cuts !
+
+ return true;
+ }
+
+
+ public boolean isReconstructed(RecType type, MCParticle mcParticle) {
+
+ // Not reconstructed if fails definition in RecoDefinition
+
+ if (! super.isReconstructed(type, mcParticle)) return false;
+
+ // Reconstructed if associated with any object of the specified type
+
+ WeightedTable<MCParticle,?> table = _mcTables.get(type);
+ if (table == null) {
+ table = _mcTruthCrux.getMCParticleTable(type, _colNames.get(type));
+ _mcTables.put(type, table);
+ }
+ return ! table.allFrom(mcParticle).isEmpty();
+ }
+
+// -- Helper methods: ---------------------------------------------------------
+
+ protected int getNumTrackerSuperLayers(MCParticle mc) {
+
+ SegmentationManager segMan = null;
+ List<? extends Object> hits;
+ if (_trackerHitNames == null) {
+ hits = _mcTruthVS.getSimTrackerHits(mc);
+ segMan = JobManager.defaultInstance().get(SegmentationManager.class);
+ } else if (_trackerHitNames.length == 0) {
+ hits = _mcTruthVS.getTrackerClusters(mc);
+ } else {
+ if (_mc2thList == null) {
+ _mc2thList = _mcTruthVS.mapByMCParticle(_trackerHitNames);
+ }
+ hits = _mc2thList.get(mc);
+ if (hits == null) return 0;
+ }
+
+ int nLayers = 0;
+ Subdetector sd = null;
+ int layer = -1;
+ for (Object ob : hits) {
+ Subdetector sd1;
+ int layer1;
+ if (ob instanceof ITrackerHit) {
+ ITrackerHit hit = (ITrackerHit) ob;
+ sd1 = hit.getSubdetector();
+ layer1 = hit.getLayer();
+ } else {
+ SimTrackerHit hit = (SimTrackerHit) ob;
+ sd1 = hit.getSubdetector();
+ layer1 = hit.getLayer();
+ }
+ if (sd != sd1 || layer != layer1) {
+ sd = sd1;
+ layer = layer1;
+ ITrackerHit.Type hitType;
+ if (ob instanceof ITrackerHit) {
+ ITrackerHit hit = (ITrackerHit) ob;
+ hitType = hit.getType();
+ } else {
+ SimTrackerHit hit = (SimTrackerHit) ob;
+ List<Sensor> sensors = segMan.getSensor(hit);
+ if (sensors.isEmpty()) {
+ hitType = ITrackerHit.Type.UNKNOWN;
+ } else {
+ hitType = sensors.get(0).getType().getHitType();
+ }
+ }
+ if (hitType.nUnmeasured() == 0) {
+ nLayers += 2;
+ } else {
+ nLayers += 1;
+ }
+ }
+ }
+ nLayers /= 2;
+ return nLayers;
+ }
+
+
+// -- Class that holds a set of cuts for a particular type of object : --------
+
+ protected class CutSetCrux {
+ protected int cut_MinTrackerSuperLayers;
+ protected CutSetCrux() {
+ cut_MinTrackerSuperLayers = 0;
+ }
+ }
+}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/cheat
diff -u -r1.5 -r1.6
--- CheatTrackFinderDriver.java 29 Jan 2009 20:35:38 -0000 1.5
+++ CheatTrackFinderDriver.java 13 Feb 2009 20:02:18 -0000 1.6
@@ -25,7 +25,7 @@
* Driver that uses MC truth info to produce a list of tracks.
*
* @author D. Onoprienko
- * @version $Id: CheatTrackFinderDriver.java,v 1.5 2009/01/29 20:35:38 onoprien Exp $
+ * @version $Id: CheatTrackFinderDriver.java,v 1.6 2009/02/13 20:02:18 onoprien Exp $
*/
public class CheatTrackFinderDriver extends Driver implements JobEventListener {
@@ -106,9 +106,7 @@
// Initialize event-specific data
_mcTruth = (MCTruthVS) event.get(MCTruthVS.KEY);
- if (_def instanceof RecoDefinitionExtended) {
- ((RecoDefinitionExtended)_def).setEvent(event);
- }
+ _def.startEvent(event);
// Create list of tracks and save it
@@ -123,7 +121,7 @@
List<MCParticle> mcList = event.getMCParticles();
for (MCParticle mc : mcList) {
- if (_def.isTrackFindable(mc)) {
+ if (_def.isFindable(RecType.TRACK, mc)) {
CruxTrack track = makeTrack(mc);
trackList.add(track);
}
@@ -134,9 +132,7 @@
trackList.trimToSize();
_mcTruth = null;
_mc2hit = null;
- if (_def instanceof RecoDefinitionExtended) {
- ((RecoDefinitionExtended)_def).clearEvent();
- }
+ _def.endEvent();
}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/cheat
diff -u -r1.3 -r1.4
--- CheatVertexFinderDriver.java 9 Feb 2009 03:57:38 -0000 1.3
+++ CheatVertexFinderDriver.java 13 Feb 2009 20:02:18 -0000 1.4
@@ -22,7 +22,7 @@
* or flies by it.
*
* @author D. Onoprienko
- * @version $Id: CheatVertexFinderDriver.java,v 1.3 2009/02/09 03:57:38 onoprien Exp $
+ * @version $Id: CheatVertexFinderDriver.java,v 1.4 2009/02/13 20:02:18 onoprien Exp $
*/
public class CheatVertexFinderDriver extends Driver {
@@ -171,7 +171,7 @@
boolean bornInFlight = mcParticle.getSimulatorStatus().vertexIsNotEndpointOfParent();
List<MCParticle> pList = mcParticle.getParents();
for (MCParticle mc : pList) {
- CruxTrack track = (CruxTrack) _mcTruth.get(MCTruthCrux.Rec.TRACK, mc).get(0);
+ CruxTrack track = (CruxTrack) _mcTruth.get(RecType.TRACK, mc).get(0);
if (bornInFlight && track != null) {
return track;
} else if (VecOp.sub(mc.getOrigin(), mc.getEndPoint()).magnitudeSquared() < _mergeDist2) {
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/cheat
diff -u -r1.1 -r1.2
--- IRecoDefinition.java 24 Jan 2009 05:11:46 -0000 1.1
+++ IRecoDefinition.java 13 Feb 2009 20:02:18 -0000 1.2
@@ -1,13 +1,21 @@
package org.lcsim.contrib.onoprien.crux.cheat;
+import org.lcsim.event.EventHeader;
import org.lcsim.event.MCParticle;
+import org.lcsim.contrib.onoprien.crux.infrastructure.RecType;
+
/**
* Interface to be implemented by classes that define reconstructable MCParticle.
* Used by cheaters and performance analysis classes.
+ * <p>
+ * An implementation of this interface that uses event-specific data (like MCTruth objects)
+ * can initialize it in the <tt>startEvent(EventHeader)</tt>, and clear any references to
+ * event-specific objects in the <tt>endEvent()</tt> method. Drivers that use such
+ * definitions and call their <tt>startEvent</tt> methods should also call <tt>endEvent()</tt>.
*
* @author D. Onoprienko
- * @version $Id: IRecoDefinition.java,v 1.1 2009/01/24 05:11:46 onoprien Exp $
+ * @version $Id: IRecoDefinition.java,v 1.2 2009/02/13 20:02:18 onoprien Exp $
*/
public interface IRecoDefinition {
@@ -17,9 +25,39 @@
String getName();
/**
- * Returns <tt>true</tt> if the specified <tt>MCParticle</tt> produced a findable
- * track, according to this definition.
+ * Returns <tt>true</tt> if the specified <tt>MCParticle</tt> should produce a
+ * findable object of the specified type, according to this definition.
+ * Throws <tt>IllegalArgumentException</tt> if this <tt>IRecoDefinition</tt> does not
+ * define whether an object of the specified type is findable.
+ */
+ boolean isFindable(RecType type, MCParticle mcParticle);
+
+ /**
+ * Returns <tt>true</tt> if the object of the specified type produced by the specified
+ * <tt>MCParticle</tt> is considered to be successfully reconstructed, according to this definition.
+ * Throws <tt>IllegalArgumentException</tt> if this <tt>IRecoDefinition</tt> does not
+ * define successful reconstruction criteria for an object of the specified type.
+ */
+ boolean isReconstructed(RecType type, MCParticle mcParticle);
+
+ /**
+ * Returns <tt>true</tt> if the specified reconstructed object is considered a fake,
+ * according to this definition.
+ * Throws <tt>IllegalArgumentException</tt> if this <tt>IRecoDefinition</tt> does not
+ * define what is considered a fake for an object of the specified type.
+ */
+ boolean isFake(RecType type, Object recObject);
+
+ /**
+ * If this <tt>IRecoDefinition</tt> uses any event-dependent data (like MCTruth object),
+ * this method should be called to initialize it.
+ */
+ void startEvent(EventHeader event);
+
+ /**
+ * If this <tt>IRecoDefinition</tt> uses any event-dependent data (like MCTruth object),
+ * this method should be called after the event is processed.
*/
- boolean isTrackFindable(MCParticle mcParticle);
+ void endEvent();
}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/cheat
diff -u -r1.2 -r1.3
--- RecoDefinition.java 1 Feb 2009 19:40:38 -0000 1.2
+++ RecoDefinition.java 13 Feb 2009 20:02:18 -0000 1.3
@@ -4,27 +4,36 @@
import hep.physics.particle.properties.ParticleType;
import hep.physics.vec.Hep3Vector;
+import org.lcsim.event.EventHeader;
import org.lcsim.event.MCParticle;
import org.lcsim.contrib.onoprien.util.NoSuchParameterException;
+import org.lcsim.contrib.onoprien.crux.infrastructure.RecType;
+
/**
* Simple configurable implementation of {@link IRecoDefinition}.
* Used by track finder cheaters and tracking performance analysis classes.
* <p>
* This definition uses only <tt>MCParticle</tt> own parameters to make selection -
- * no detector or hit information is accessible. See {@link RecoDefinitionExtended}
+ * no detector or hit information is accessible. See {@link RecoDefinitionCrux}
* if you need to cut on number of layer with hits, etc.
* <p>
* The definition can be customized either by setting parameters through the
- * {@link #setCut setCut(String,Object)} method (by default, all cuts are
+ * {@link #setCut setCut(RecType,String,Object)} method (by default, all cuts are
* disabled, so every particle is reconstructable) or by overriding some of
* the methods.
*
* @author D. Onoprienko
- * @version $Id: RecoDefinition.java,v 1.2 2009/02/01 19:40:38 onoprien Exp $
+ * @version $Id: RecoDefinition.java,v 1.3 2009/02/13 20:02:18 onoprien Exp $
*/
public class RecoDefinition implements IRecoDefinition {
+
+// -- Private parts : ---------------------------------------------------------
+
+ private String _name;
+ protected EnumMap<RecType, CutSet> _cuts;
+
// -- Constructors : ----------------------------------------------------------
@@ -33,21 +42,26 @@
}
public RecoDefinition(String name) {
-
_name = name;
-
- _cut_Charged = 0;
- _cut_Pt = 0.;
- _cut_ThetaMin = 0.;
- _cut_ThetaMax = Math.PI;
- _cut_Types = null;
+ _cuts = new EnumMap<RecType, CutSet>(RecType.class);
}
// -- Setters : ---------------------------------------------------------------
+
+ /**
+ * Defines a list of reconstructed objects types this definition can handle.
+ */
+ public void setTypes(RecType... types) {
+ for (RecType type : types) {
+ if (! _cuts.containsKey(type)) {
+ _cuts.put(type, new CutSet());
+ }
+ }
+ }
/**
- * Set cut parameters. Calling this method this a name of a cat but no values diables the cut.
+ * Set cut parameters. Calling this method with a name of a cut but no values disables the cut.
* The following cuts can be configured with this method:
* <p><dl>
* <dt>"CHARGED"</dt> <dd>Boolean value: if <tt>true</tt>, only charged particles are selected.
@@ -59,47 +73,48 @@
* of these types will be selected.</dd></dl>
*
* By default, all cuts are disabled.
- *
- * @param name Name of the cut. Case is ignored.
+ *
+ * @param type Type of reconstructed object that wiil be selected using this cut.
+ * @param name Name of the cut. Case is ignored.
* @param values List of parameters to be used for configuring the cut.
* @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
* @throws IllegalArgumentException Thrown if incorrect number of values, or a value
* of incorrect type is supplied.
*/
- public void setCut(String name, Object... values) {
- Object value = values.length == 0 ? null : values[0];
+ public void setCut(RecType type, String name, Object... values) {
+ CutSet cutSet = _cuts.get(type);
+ if (cutSet == null) _cuts.put(type, cutSet = new CutSet());
try {
if (name.equalsIgnoreCase("CHARGED")) {
if (values.length == 0) {
- _cut_Charged = 0;
+ cutSet.cut_Charged = 0;
} else {
if ((Boolean)values[0]) {
- _cut_Charged = 1;
+ cutSet.cut_Charged = 1;
} else {
- _cut_Charged = 2;
+ cutSet.cut_Charged = 2;
}
}
} else if (name.equalsIgnoreCase("PT")) {
- if (values.length == 0) _cut_Pt = 0.;
- _cut_Pt = (Double) value;
+ cutSet.cut_Pt = (values.length == 0) ? 0. : (Double) values[0];
} else if (name.equalsIgnoreCase("THETA")) {
if (values.length == 0) {
- _cut_ThetaMin = 0.;
- _cut_ThetaMax = Math.PI;
+ cutSet.cut_ThetaMin = 0.;
+ cutSet.cut_ThetaMax = Math.PI;
} else if (values.length == 1) {
- _cut_ThetaMin = (Double) values[0];
- _cut_ThetaMax = Math.PI - _cut_ThetaMin;
+ cutSet.cut_ThetaMin = (Double) values[0];
+ cutSet.cut_ThetaMax = Math.PI - cutSet.cut_ThetaMin;
} else {
- _cut_ThetaMin = (Double) values[0];
- _cut_ThetaMax = (Double) values[1];
+ cutSet.cut_ThetaMin = (Double) values[0];
+ cutSet.cut_ThetaMax = (Double) values[1];
}
} else if (name.equalsIgnoreCase("PARTICLE_TYPES")) {
if (values.length == 0) {
- _cut_Types = null;
+ cutSet.cut_Types = null;
} else {
- _cut_Types = new HashSet<ParticleType>();
+ cutSet.cut_Types = new HashSet<ParticleType>();
for (Object o : values) {
- _cut_Types.add((ParticleType)o);
+ cutSet.cut_Types.add((ParticleType)o);
}
}
} else {
@@ -111,21 +126,30 @@
}
-// -- Implementing IRecoDefinition : ------------------------------------------
+// -- Getters : ---------------------------------------------------------------
- public String getName() {return _name;}
+ public String getName() {
+ return _name;
+ }
+
+ public Set<RecType> getTypes() {
+ return _cuts.keySet();
+ }
// -- Methods defining "reconstructable" and "reconstructed" : ----------------
- public boolean isTrackFindable(MCParticle mcParticle) {
+ public boolean isFindable(RecType type, MCParticle mcParticle) {
+
+ CutSet cutSet = _cuts.get(type);
+ if (cutSet == null) throw new IllegalArgumentException();
// Charge cut
double charge = mcParticle.getCharge();
- if (_cut_Charged == 1) {
+ if (cutSet.cut_Charged == 1) {
if (Math.abs(charge) < .9) return false;
- } else if (_cut_Charged == 2) {
+ } else if (cutSet.cut_Charged == 2) {
if (Math.abs(charge) > .1) return false;
}
@@ -133,29 +157,59 @@
Hep3Vector p = mcParticle.getMomentum();
double pT = Math.hypot(p.x(), p.y());
- if (pT < _cut_Pt) return false;
+ if (pT < cutSet.cut_Pt) return false;
// Theta cut
double theta = Math.acos(p.z()/p.magnitude());
- if (theta < _cut_ThetaMin || theta > _cut_ThetaMax) return false;
+ if (theta < cutSet.cut_ThetaMin || theta > cutSet.cut_ThetaMax) return false;
// Particle type cut
- if (_cut_Types != null && (! _cut_Types.contains(mcParticle.getType()))) return false;
+ if (cutSet.cut_Types != null && (! cutSet.cut_Types.contains(mcParticle.getType()))) return false;
// Passed all cuts !
return true;
}
-
-// -- Private parts : ---------------------------------------------------------
-
- private String _name;
+ public boolean isReconstructed(RecType type, MCParticle mcParticle) {
+ if (!_cuts.containsKey(type)) throw new IllegalArgumentException();
+ return true;
+ }
- protected int _cut_Charged;
- protected double _cut_Pt;
- protected double _cut_ThetaMin, _cut_ThetaMax;
- protected Set<ParticleType> _cut_Types;
+ public boolean isFake(RecType type, Object recObject) {
+ if (!_cuts.containsKey(type)) throw new IllegalArgumentException();
+ return true;
+ }
+
+
+ /**
+ * This implementation of <tt>IRecoDefinition</tt> does not use any event-dependent
+ * data, therefore this method is implemented to do nothing.
+ */
+ public void startEvent(EventHeader event) {}
+
+ /**
+ * This implementation of <tt>IRecoDefinition</tt> does not use any event-dependent
+ * data, therefore this method is implemented to do nothing.
+ */
+ public void endEvent() {}
+
+// -- Class that holds a set of cuts for a particular type of object : --------
+
+ protected class CutSet {
+ protected int cut_Charged;
+ protected double cut_Pt;
+ protected double cut_ThetaMin, cut_ThetaMax;
+ protected Set<ParticleType> cut_Types;
+ protected CutSet() {
+ cut_Charged = 0;
+ cut_Pt = 0.;
+ cut_ThetaMin = 0.;
+ cut_ThetaMax = Math.PI;
+ cut_Types = null;
+ }
+ }
+
}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/cheat
diff -N RecoDefinitionExtended.java
--- RecoDefinitionExtended.java 1 Feb 2009 19:40:38 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,226 +0,0 @@
-package org.lcsim.contrib.onoprien.crux.cheat;
-
-import java.util.*;
-
-import org.lcsim.event.EventHeader;
-import org.lcsim.event.MCParticle;
-import org.lcsim.event.SimTrackerHit;
-import org.lcsim.geometry.Subdetector;
-
-import org.lcsim.contrib.onoprien.util.NoSuchParameterException;
-import org.lcsim.contrib.onoprien.util.job.JobManager;
-
-import org.lcsim.contrib.onoprien.vsegment.geom.SegmentationManager;
-import org.lcsim.contrib.onoprien.vsegment.geom.Sensor;
-import org.lcsim.contrib.onoprien.vsegment.hit.ITrackerHit;
-import org.lcsim.contrib.onoprien.vsegment.mctruth.MCTruthVS;
-
-/**
- * Simple configurable implementation of {@link IRecoDefinition}.
- * Used by track finder cheaters and tracking performance analysis classes.
- * The definition can be customized either by setting parameters through the
- * {@link #setCut setCut(String,Object)} method (by default, all cuts are
- * disabled, so every particle is reconstructable) or by overriding some of
- * the methods.
- *
- * @author D. Onoprienko
- * @version $Id: RecoDefinitionExtended.java,v 1.4 2009/02/01 19:40:38 onoprien Exp $
- */
-public class RecoDefinitionExtended extends RecoDefinition {
-
-// -- Constructors : ----------------------------------------------------------
-
- public RecoDefinitionExtended() {
- this("");
- }
-
- public RecoDefinitionExtended(String name) {
-
- super(name);
-
- _cut_MinTrackerSuperLayers = 0;
- }
-
-
-// -- Setters : ---------------------------------------------------------------
-
- /**
- * Set cut parameters. Calling this method this a name of a cat but no values diables the cut.
- * The following cuts can be configured with this method:
- * <p><dl>
- * <dt>"MIN_TRACK_HIT_LAYERS"</dt> <dd>Integer value: minimum number of tracker superlayers with hits.
- * {@link #getNumTrackerSuperLayers getNumTrackerSuperLayers(MCParticle)} method must be implemented.</dd>
- * </dl>
- *
- * By default, all cuts are disabled.
- *
- * @param name Name of the cut. Case is ignored.
- * @param values List of parameters to be used for configuring the cut.
- * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
- * @throws IllegalArgumentException Thrown if incorrect number of values, or a value
- * of incorrect type is supplied.
- */
- public void setCut(String name, Object... values) {
- Object value = values.length == 0 ? null : values[0];
- try {
- if (name.equalsIgnoreCase("MIN_TRACK_HIT_LAYERS")) {
- if (values.length == 0) _cut_MinTrackerSuperLayers = 0;
- _cut_MinTrackerSuperLayers = (Integer) value;
- } else {
- super.setCut(name, values);
- }
- } catch (ClassCastException x) {
- throw new IllegalArgumentException(x);
- }
- }
-
- /**
- * Set parameters.
- * The following parameters can be set with this method:
- * <p><dl>
- * <dt>"TRACKER_HIT_COLLECTIONS"</dt> <dd>Zero or more <tt>String</tt> values specifying
- * the names of tracker hit collections to be used by this
- * definition for computing various parameters relevant to tracker-related cuts.
- * The hits in the specified collections must be of type {@link ITrackerHit}. If an
- * empty <tt>String</tt> is supplied as the first value, tracker clusters will be used.
- * If the setter is called with no values, <tt>SimTrackerHits</tt> will be used instead of
- * digitized hits.<br>
- * Default: <tt>SimTrackerHits</tt> are used.</dd>
- * </dl>
- *
- * @param name Name of the parameter. Case is ignored.
- * @param values List of parameters to be used for configuring the cut.
- * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
- * @throws IllegalArgumentException Thrown if incorrect number of values, or a value
- * of incorrect type is supplied.
- */
- public void set(String name, Object... values) {
- try {
- if (name.equalsIgnoreCase("TRACKER_HIT_COLLECTIONS")) {
- if (values.length == 0) {
- _trackerHitListNames = null;
- } else if (((String)(values[0])).equals("")) {
- _trackerHitListNames = Collections.emptyList();
- } else {
- _trackerHitListNames = new ArrayList<String>(values.length);
- for (Object o : values) _trackerHitListNames.add((String)o);
- }
- } else {
- throw new NoSuchParameterException(name);
- }
- } catch (ClassCastException x) {
- throw new IllegalArgumentException(x);
- }
- }
-
- /**
- * Saves a reference to the event record to be used by this definition.
- * If a driver calls this method, it has to call {@link #clearEvent()} once the event
- * processing is finished.
- */
- public void setEvent(EventHeader event) {
- _event = event;
- try {
- _mcTruthVS = (MCTruthVS) event.get(MCTruthVS.KEY);
- } catch(IllegalArgumentException x) {
- _mcTruthVS = null;
- }
- }
-
- /**
- * Clears all references to objects that belong to a particular event.
- */
- public void clearEvent() {
- _event = null;
- _mcTruthVS = null;
- _mc2thList = null;
- }
-
-
-// -- Methods defining "reconstructable" and "reconstructed" : ----------------
-
- public boolean isTrackFindable(MCParticle mcParticle) {
-
- if (! super.isTrackFindable(mcParticle)) return false;
-
- // Minimum number of hit layers cut
-
- if (_cut_MinTrackerSuperLayers > 0 && _cut_MinTrackerSuperLayers > getNumTrackerSuperLayers(mcParticle)) return false;
-
- // Passed all cuts !
-
- return true;
- }
-
-
-// -- Helper methods: ---------------------------------------------------------
-
- protected int getNumTrackerSuperLayers(MCParticle mc) {
-
- SegmentationManager segMan = null;
- List<? extends Object> hits;
- if (_trackerHitListNames == null) {
- hits = _mcTruthVS.getSimTrackerHits(mc);
- segMan = JobManager.defaultInstance().get(SegmentationManager.class);
- } else if (_trackerHitListNames.isEmpty()) {
- hits = _mcTruthVS.getTrackerClusters(mc);
- } else {
- if (_mc2thList == null) {
- _mc2thList = _mcTruthVS.mapByMCParticle(_trackerHitListNames);
- }
- hits = _mc2thList.get(mc);
- if (hits == null) return 0;
- }
-
- int nLayers = 0;
- Subdetector sd = null;
- int layer = -1;
- for (Object ob : hits) {
- Subdetector sd1;
- int layer1;
- if (ob instanceof ITrackerHit) {
- ITrackerHit hit = (ITrackerHit) ob;
- sd1 = hit.getSubdetector();
- layer1 = hit.getLayer();
- } else {
- SimTrackerHit hit = (SimTrackerHit) ob;
- sd1 = hit.getSubdetector();
- layer1 = hit.getLayer();
- }
- if (sd != sd1 || layer != layer1) {
- sd = sd1;
- layer = layer1;
- ITrackerHit.Type hitType;
- if (ob instanceof ITrackerHit) {
- ITrackerHit hit = (ITrackerHit) ob;
- hitType = hit.getType();
- } else {
- SimTrackerHit hit = (SimTrackerHit) ob;
- List<Sensor> sensors = segMan.getSensor(hit);
- if (sensors.isEmpty()) {
- hitType = ITrackerHit.Type.UNKNOWN;
- } else {
- hitType = sensors.get(0).getType().getHitType();
- }
- }
- if (hitType.nUnmeasured() == 0) {
- nLayers += 2;
- } else {
- nLayers += 1;
- }
- }
- }
- nLayers /= 2;
- return nLayers;
- }
-
-// -- Private parts : ---------------------------------------------------------
-
- protected int _cut_MinTrackerSuperLayers;
-
- protected List<String> _trackerHitListNames;
- protected HashMap<MCParticle, List<ITrackerHit>> _mc2thList;
-
- protected EventHeader _event;
- protected MCTruthVS _mcTruthVS;
-}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/diagnostics
diff -u -r1.4 -r1.5
--- ClusteringTest.java 11 Feb 2009 23:31:40 -0000 1.4
+++ ClusteringTest.java 13 Feb 2009 20:02:19 -0000 1.5
@@ -26,7 +26,7 @@
*
*
* @author D. Onoprienko
- * @version $Id: ClusteringTest.java,v 1.4 2009/02/11 23:31:40 onoprien Exp $
+ * @version $Id: ClusteringTest.java,v 1.5 2009/02/13 20:02:19 onoprien Exp $
*/
public class ClusteringTest extends Driver implements JobEventListener {
@@ -170,7 +170,7 @@
MCTruthCrux mcTruth = (MCTruthCrux) _event.get(MCTruthCrux.KEY);
for (CruxCluster cluster : _inClusterList) {
- List<MCParticle> mcList = mcTruth.getMCParticles(MCTruthCrux.Rec.CLUSTER, cluster);
+ List<MCParticle> mcList = mcTruth.getMCParticles(RecType.CLUSTER, cluster);
CalModule module = cluster.getModule();
String name = (module == null) ? "Multiple modules" : module.getName();
_aida.cloud1D("MCParticles per cluster").fill(mcList.size());
@@ -179,7 +179,7 @@
// Cluster multiplicity:
- WeightedTable<MCParticle, Cluster> mcToClusterMap = mcTruth.<Cluster>getMCParticleTable(MCTruthCrux.Rec.CLUSTER, _inClusterList);
+ WeightedTable<MCParticle, Cluster> mcToClusterMap = mcTruth.<Cluster>getMCParticleTable(RecType.CLUSTER, _inClusterList);
for (MCParticle mc : mcToClusterMap.fromSet()) {
int nClusters = mcToClusterMap.allFrom(mc).size();
_aida.cloud1D("Clusters per MCParticle").fill(nClusters);
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/mctruth
diff -u -r1.3 -r1.4
--- MCTruthCrux.java 11 Feb 2009 23:31:40 -0000 1.3
+++ MCTruthCrux.java 13 Feb 2009 20:02:19 -0000 1.4
@@ -17,54 +17,22 @@
import org.lcsim.contrib.onoprien.crux.infrastructure.CatSeed;
import org.lcsim.contrib.onoprien.crux.infrastructure.ITrack;
+import org.lcsim.contrib.onoprien.crux.infrastructure.RecType;
/**
* Provides access to Monte Carlo truth information for reconstructed
* objects created with crux package. Relations between <tt>MCParticles</tt> and
- * reconstructed objects are weighted - See {@link Rec} for a description of how
+ * reconstructed objects are weighted - See {@link RecType} for a description of how
* weights are calculated for each type of reconstructed object.
*
* @author D. Onoprienko
- * @version $Id: MCTruthCrux.java,v 1.3 2009/02/11 23:31:40 onoprien Exp $
+ * @version $Id: MCTruthCrux.java,v 1.4 2009/02/13 20:02:19 onoprien Exp $
*/
public class MCTruthCrux {
/** Name under which this object is saved in the event record: "MCTruthCrux". */
static public final String KEY = "MCTruthCrux";
- /**
- * Enumeration of types of reconstructed objects for which Monte Carlo truth information
- * can be accessed through a {@link MCTruthCrux} object.
- */
- public enum Rec {
- /**
- * Reconstructed track. The <tt>MCParticle</tt> weight is equal to the number of hits
- * on the track to which that <tt>MCParticle</tt> has contributed.
- */
- TRACK(ITrack.class),
- /**
- * Calorimeter hit. The <tt>MCParticle</tt> weight is equal to the energy
- * contributed by that <tt>MCParticle</tt>.
- */
- CAL_HIT(CalorimeterHit.class),
- /**
- * Calorimeter cluster. The <tt>MCParticle</tt> weight is equal to the energy
- * contributed by that <tt>MCParticle</tt>.
- */
- CLUSTER(Cluster.class),
- /**
- * Calorimeter assisted tracking seed. The <tt>MCParticle</tt> weight is equal to the
- * energy contributed by the <tt>MCParticle</tt> to the MIP stub portion of the seed cluster.
- */
- CAT_SEED(CatSeed.class);
-
- Class _type;
- Rec(Class type) {_type = type;}
-
- /** Returns a common superclass of reconstructed objects of this type. */
- public Class type() {return _type;}
- }
-
// -- Private parts : ---------------------------------------------------------
private MCTruthDriverCrux _driver;
@@ -72,7 +40,7 @@
private MCTruthVS _mcTruthVS;
- private EnumMap<Rec, WeightedTable> _defMaps;
+ private EnumMap<RecType, WeightedTable> _defMaps;
// -- Constructors : ----------------------------------------------------------
@@ -88,14 +56,14 @@
/**
* Sets the default relational table between <tt>MCParticles</tt> and reconstructed objects of the specified type.
* Subsequent calls to
- * {@link #getMCParticleTable(Rec, Collection) getMCParticleTable(type)},
- * {@link #get(Rec, MCParticle) get(type, mcParticle)},
- * {@link #getMCParticles(Rec, Object) getMCParticles(type, reconstructedObject)}, and
+ * {@link #getMCParticleTable(RecType, Collection) getMCParticleTable(type)},
+ * {@link #get(RecType, MCParticle) get(type, mcParticle)},
+ * {@link #getMCParticles(RecType, Object) getMCParticles(type, reconstructedObject)}, and
* {@link #getMCParticles(Object) getMCParticles(reconstructedObject)}
* will use this map. If the map is set to <tt>null</tt>, the next call to one of these
* methods will re-create the map by calling <tt>getMCParticleTable(type)</tt>, and set it as a default.
*/
- public <T> void setMCParticleTable(Rec type, WeightedTable<MCParticle,T> map) {
+ public <T> void setMCParticleTable(RecType type, WeightedTable<MCParticle,T> map) {
_defMaps.put(type, map);
}
@@ -110,7 +78,7 @@
* set, all lists with compatible element types are used
* (as returned by {@link EventHeader#get(Class) EventHeader.get(type.type())}.
*/
- public <T> WeightedTable<MCParticle,T> getMCParticleTable(Rec type, String... collectionNames) {
+ public <T> WeightedTable<MCParticle,T> getMCParticleTable(RecType type, String... collectionNames) {
WeightedTable<MCParticle,T> out = null;
boolean needToSet = false;
@@ -159,7 +127,7 @@
* Returns a relational table between <tt>MCParticles</tt> and reconstructed objects of the
* requested type from the specified collection.
*/
- public <T> WeightedTable<MCParticle,T> getMCParticleTable(Rec type, Collection<? extends T> collection) {
+ public <T> WeightedTable<MCParticle,T> getMCParticleTable(RecType type, Collection<? extends T> collection) {
WeightedTable<MCParticle,T> table = new WeightedTable<MCParticle,T>();
LinkedHashSet<T> set = new LinkedHashSet<T>(collection);
for (T e : set) {
@@ -179,7 +147,7 @@
* <tt>MCParticle</tt> has contributed. The method uses default relational table,
* creating it if it does not already exist.
*/
- public <T> WeightedList<T> get(Rec type, MCParticle mcParticle) {
+ public <T> WeightedList<T> get(RecType type, MCParticle mcParticle) {
WeightedTable<MCParticle,T> map = _defMaps.get(type);
if (map == null) map = getMCParticleTable(type);
return map.listFrom(mcParticle);
@@ -189,15 +157,15 @@
// -- Reco object to MCParticles methods (lookup in tables) : -----------------
// public WeightedList<MCParticle> getMCParticles(Object reconstructedObject) {
-// Rec type;
+// RecType type;
// if (reconstructedObject instanceof ITrack) {
-// type = Rec.TRACK;
+// type = RecType.TRACK;
// } else if (reconstructedObject instanceof CalorimeterHit) {
-// type = Rec.CAL_HIT;
+// type = RecType.CAL_HIT;
// } else if (reconstructedObject instanceof Cluster) {
-// type = Rec.CLUSTER;
+// type = RecType.CLUSTER;
// } else if (reconstructedObject instanceof CatSeed) {
-// type = Rec.CAT_SEED;
+// type = RecType.CAT_SEED;
// } else {
// throw new IllegalArgumentException("No idea how to find MCParticles for "+ reconstructedObject.getClass());
// }
@@ -209,7 +177,7 @@
* reconstructed object. The method uses default relational table,
* creating it if it does not already exist.
*/
- public WeightedList<MCParticle> getMCParticles(Rec type, Object reconstructedObject) {
+ public WeightedList<MCParticle> getMCParticles(RecType type, Object reconstructedObject) {
WeightedTable map = _defMaps.get(type);
if (map == null) map = getMCParticleTable(type);
return map.listTo(reconstructedObject);
@@ -223,10 +191,10 @@
* specified reconstructed object. The method neither uses nor creates the default relational table.
* The returned list is in decreasing weight order.
* <p>
- * See {@link Rec} for a description of how weights are calculated for
+ * See {@link RecType} for a description of how weights are calculated for
* each type of reconstructed object.
*/
- private WeightedList<MCParticle> findMCParticles(Rec type, Object reconstructedObject) {
+ private WeightedList<MCParticle> findMCParticles(RecType type, Object reconstructedObject) {
switch (type) {
case TRACK : return findMCParticles((ITrack)reconstructedObject);
case CAL_HIT : return findMCParticles((CalorimeterHit)reconstructedObject);
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/mctruth
diff -u -r1.2 -r1.3
--- MCTruthDriverCrux.java 9 Feb 2009 03:57:38 -0000 1.2
+++ MCTruthDriverCrux.java 13 Feb 2009 20:02:19 -0000 1.3
@@ -6,18 +6,20 @@
import org.lcsim.contrib.onoprien.util.job.Driver;
+import org.lcsim.contrib.onoprien.crux.infrastructure.RecType;
+
/**
* Driver that creates {@link MCTruthCrux} object, and saves it into the event record.
*
*
* @author D. Onoprienko
- * @version $Id: MCTruthDriverCrux.java,v 1.2 2009/02/09 03:57:38 onoprien Exp $
+ * @version $Id: MCTruthDriverCrux.java,v 1.3 2009/02/13 20:02:19 onoprien Exp $
*/
public class MCTruthDriverCrux extends Driver {
// -- Private parts : ---------------------------------------------------------
- EnumMap<MCTruthCrux.Rec, String[]> _defaultNames = new EnumMap<MCTruthCrux.Rec, String[]>(MCTruthCrux.Rec.class);
+ EnumMap<RecType, String[]> _defaultNames = new EnumMap<RecType, String[]>(RecType.class);
// -- Constructors : ----------------------------------------------------------
@@ -67,7 +69,7 @@
names = new String[values.length];
for (int i=0; i<values.length; i++) names[i] = (String) values[i];
}
- _defaultNames.put(MCTruthCrux.Rec.TRACK, names);
+ _defaultNames.put(RecType.TRACK, names);
} else if (name.equalsIgnoreCase("CALORIMETER_HITS")) {
String[] names;
if (values.length == 0) {
@@ -76,7 +78,7 @@
names = new String[values.length];
for (int i=0; i<values.length; i++) names[i] = (String) values[i];
}
- _defaultNames.put(MCTruthCrux.Rec.CAL_HIT, names);
+ _defaultNames.put(RecType.CAL_HIT, names);
} else if (name.equalsIgnoreCase("CLUSTERS")) {
String[] names;
if (values.length == 0) {
@@ -85,7 +87,7 @@
names = new String[values.length];
for (int i=0; i<values.length; i++) names[i] = (String) values[i];
}
- _defaultNames.put(MCTruthCrux.Rec.CLUSTER, names);
+ _defaultNames.put(RecType.CLUSTER, names);
} else if (name.equalsIgnoreCase("CAT_SEEDS")) {
String[] names;
if (values.length == 0) {
@@ -94,7 +96,7 @@
names = new String[values.length];
for (int i=0; i<values.length; i++) names[i] = (String) values[i];
}
- _defaultNames.put(MCTruthCrux.Rec.CAT_SEED, names);
+ _defaultNames.put(RecType.CAT_SEED, names);
} else {
super.set(name, values);
}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/infrastructure
diff -N RecType.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RecType.java 13 Feb 2009 20:02:19 -0000 1.1
@@ -0,0 +1,48 @@
+package org.lcsim.contrib.onoprien.crux.infrastructure;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+
+import org.lcsim.contrib.onoprien.crux.mctruth.MCTruthCrux;
+
+/**
+ * Enumeration of types of reconstructed objects.
+ * Used to access Monte Carlo truth information through a {@link MCTruthCrux},
+ * to define findable objects for cheater and analysis classes, and other purposes.
+ */
+public enum RecType {
+
+ /**
+ * Reconstructed track. The <tt>MCParticle</tt> weight is equal to the number of hits
+ * on the track to which that <tt>MCParticle</tt> has contributed.
+ */
+ TRACK(ITrack.class),
+
+ /**
+ * Calorimeter hit. The <tt>MCParticle</tt> weight is equal to the energy
+ * contributed by that <tt>MCParticle</tt>.
+ */
+ CAL_HIT(CalorimeterHit.class),
+
+ /**
+ * Calorimeter cluster. The <tt>MCParticle</tt> weight is equal to the energy
+ * contributed by that <tt>MCParticle</tt>.
+ */
+ CLUSTER(Cluster.class),
+
+ /**
+ * Calorimeter assisted tracking seed. The <tt>MCParticle</tt> weight is equal to the
+ * energy contributed by the <tt>MCParticle</tt> to the MIP stub portion of the seed cluster.
+ */
+ CAT_SEED(CatSeed.class);
+ Class _type;
+
+ RecType(Class type) {
+ _type = type;
+ }
+
+ /** Returns a common superclass of reconstructed objects of this type. */
+ public Class type() {
+ return _type;
+ }
+}
CVSspam 0.2.8