hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.3 -r1.4
--- HelicalTrackHitDriver.java 12 Jul 2013 20:44:43 -0000 1.3
+++ HelicalTrackHitDriver.java 30 Jul 2013 00:55:39 -0000 1.4
@@ -1,15 +1,13 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.lcsim.hps.recon.tracking;
-import hep.physics.vec.Hep3Vector;
-import hep.physics.vec.VecOp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.ITransform3D;
import org.lcsim.detector.tracker.silicon.SiSensor;
@@ -25,18 +23,27 @@
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
import org.lcsim.hps.event.HPSTransformations;
+import org.lcsim.hps.recon.tracking.StereoPair.detectorVolume;
import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHit;
import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHitStrip1D;
import org.lcsim.recon.tracking.digitization.sisim.TrackerHitType;
/**
*
- * @author phansson, mgraham
+ * @author Mathew Graham <[log in to unmask]>
+ * @author Per Hansson <[log in to unmask]>
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: HelicalTrackHitDriver.java,v 1.4 2013/07/30 00:55:39 omoreno Exp $
*/
public class HelicalTrackHitDriver extends org.lcsim.fit.helicaltrack.HelicalTrackHitDriver {
- private boolean _debug = false;
+
+ // TODO: This driver needs to be cleaned up. The classes SimpleDetectors, Layers ... need to be removed
+
+ private boolean _debug = false;
private double _clusterTimeCut = -99; // if negative, don't cut..otherwise, dt cut time in ns
- private String subdetectorName = "Tracker";
+ private String _subdetectorName = "Tracker";
+ private String _clusterCollectionName = "StripClusterer_SiTrackerHitStrip1D";
+
private Map<String, String> _stereomap = new HashMap<String, String>();
private List<String> _colnames = new ArrayList<String>();
private boolean _doTransformToTracking = true;
@@ -44,45 +51,89 @@
private SimpleDetector _det;
public enum LayerGeometryType {
Split,
- Common
+ Common
}
private LayerGeometryType _layerGeometryType = LayerGeometryType.Split;
-
+
+ /**
+ * Default Ctor
+ */
public HelicalTrackHitDriver() {
this.addCollection("StripClusterer_SiTrackerHitStrip1D");
}
+
+
+ //--- Setters ---//
+ //---------------//
+
+ /**
+ *
+ * @param geomType
+ */
public void setLayerGeometryType(String geomType) {
this._layerGeometryType = LayerGeometryType.valueOf(geomType);
}
+ /**
+ *
+ * @param dtCut
+ */
public void setClusterTimeCut(double dtCut) {
this._clusterTimeCut = dtCut;
}
+ /**
+ *
+ * @param subdetectorName
+ */
public void setSubdetectorName(String subdetectorName) {
- this.subdetectorName = subdetectorName;
+ this._subdetectorName = subdetectorName;
}
+ /**
+ *
+ * @param debug
+ */
public void setDebug(boolean debug) {
this._debug = debug;
}
+ /**
+ *
+ * @param trans
+ */
public void setTransformToTracking(boolean trans) {
this._doTransformToTracking = trans;
}
+ /**
+ *
+ * @param stripHitsCollectionName
+ */
public void setStripHitsCollectionName(String stripHitsCollectionName) {
HitRelationName(stripHitsCollectionName);
}
+ /**
+ *
+ * @param helicalTrackHitRelationsCollectionName
+ */
public void setHelicalTrackHitRelationsCollectionName(String helicalTrackHitRelationsCollectionName) {
HitRelationName(helicalTrackHitRelationsCollectionName);
}
+ /**
+ *
+ * @param helicalTrackMCRelationsCollectionName
+ */
public void setHelicalTrackMCRelationsCollectionName(String helicalTrackMCRelationsCollectionName) {
MCRelationName(helicalTrackMCRelationsCollectionName);
}
+ /**
+ *
+ * @param outputHitCollectionName
+ */
public void setOutputHitCollectionName(String outputHitCollectionName) {
OutputCollection(outputHitCollectionName);
}
@@ -91,29 +142,25 @@
public void process(EventHeader event) {
//super.process(event);
-
+ // Instantiate the list of HelicalTrackCrosses and HelicalTrackHits
+ List<HelicalTrackCross> stereoCrosses = new ArrayList<HelicalTrackCross>();
+ List<HelicalTrackHit> helhits = new ArrayList<HelicalTrackHit>();
+
+ // Create an LCRelation from a HelicalTrackHit to
+ List<LCRelation> hitrelations = new ArrayList<LCRelation>();
+
+ // Create an LCRelation from a HelicalTrackHit to an MC particle used to create it
+ List<LCRelation> mcrelations = new ArrayList<LCRelation>();
+
if(LayerGeometryType.Common==_layerGeometryType) {
-
- // Initialize the list of HelicalTrackHits
- List<HelicalTrackCross> stereoCrosses = new ArrayList<HelicalTrackCross>();
- List<HelicalTrackHit> helhits = new ArrayList<HelicalTrackHit>();
-
- // Create a List of LCRelations to relate HelicalTrackHits to the original hits
- List<LCRelation> hitrelations = new ArrayList<LCRelation>();
- // Create a List of LCRelations to relate HelicalTrackHits to the MC particle
- List<LCRelation> mcrelations = new ArrayList<LCRelation>();
-
-
-
for (String _colname : this._colnames) {
- if (!event.hasCollection(SiTrackerHit.class, _colname)) {
- continue;
- }
+ if (!event.hasCollection(SiTrackerHit.class, _colname)) continue;
// Get the list of SiTrackerHits for this collection
- List<SiTrackerHit> hitlist = (List<SiTrackerHit>) event.get(_colname);
+ List<SiTrackerHit> hitlist = event.get(SiTrackerHit.class, _colname);
+
if (_debug) {
System.out.printf("%s: found %d SiTrackerHits\n", this.getClass().getSimpleName(), hitlist.size());
}
@@ -126,17 +173,18 @@
if (hit instanceof SiTrackerHitStrip1D) {
- // Cast the hit as a 1D strip hit and find the identifier for the detector/layer combo
+ // Cast the hit as a 1D strip hit and find the identifier for the detector/layer combo
SiTrackerHitStrip1D h = (SiTrackerHitStrip1D) hit;
IDetectorElement de = h.getSensor();
String id = this.makeID(_ID.getName(de), _ID.getLayer(de));
- // This hit should be a on a stereo pair!
+ // This hit should be a on a stereo pair!
+ // With our detector setup, when is this not true?
if (!_stereomap.containsKey(id) && !_stereomap.containsValue(id)) {
throw new RuntimeException(this.getClass().getSimpleName() + ": this " + id + " was not among the stereo modules!");
}
- // Create a HelicalTrackStrip for this hit
+ // Create a HelicalTrackStrip for this hit
HelicalTrackStrip strip = makeDigiStrip(h);
// Get the list of strips for this layer - create a new list if one doesn't already exist
@@ -145,9 +193,10 @@
lyrhits = new ArrayList<HelicalTrackStrip>();
striplistmap.put(id, lyrhits);
}
+
if ((_clusterTimeCut > 0 && Math.abs(h.getTime()) < _clusterTimeCut)||_clusterTimeCut<0) {
// Add the strip to the list of strips on this sensor
- lyrhits.add(strip);
+ lyrhits.add(strip);
// Map a reference back to the hit needed to create the stereo hit LC relations
stripmap.put(strip, h);
@@ -159,8 +208,9 @@
}
} else {
- // If not a 1D strip hit, make a pixel hit
- HelicalTrackHit hit3d = this.makeDigi3DHit(hit);
+ // If not a 1D strip hit, make a pixel hit
+ // This should be removed as it is never used.
+ HelicalTrackHit hit3d = this.makeDigi3DHit(hit);
helhits.add(hit3d);
hitrelations.add(new MyLCRelation(hit3d, hit));
}
@@ -174,6 +224,7 @@
if (_debug)System.out.printf("%s: Create stereo hits from %d strips \n", this.getClass().getSimpleName(), striplistmap.size());
// Loop over the stereo layer pairs
+ // TODO: Change this so that it makes use of StereoPairs
for (String id1 : _stereomap.keySet()) {
// Get the second layer
@@ -190,7 +241,6 @@
* relations for stereo hit to SiTrackHitStrip1D object Add LC
* relation between MC particle and stereo hit
*/
-
List<HelicalTrackCross> cross_list = _crosser.MakeHits(striplistmap.get(id1), striplistmap.get(id2));
for (HelicalTrackCross cross : cross_list) {
@@ -203,17 +253,16 @@
for (HelicalTrackStrip strip : cross.getStrips()) {
hitrelations.add(new MyLCRelation(cross, stripmap.get(strip)));
}
-
}
- } // Loop over stereo pairs
+ } // End of loop over stereo pairs
if (_debug) {
System.out.printf("%s: added %d stereo hits from %s collection \n", this.getClass().getSimpleName(), stereoCrosses.size(), _colname);
}
- } // Loop over collection names
+ } // End of loop over collection names
if (_debug) {
@@ -235,25 +284,14 @@
} else if(LayerGeometryType.Split==_layerGeometryType) {
- // Initialize the list of HelicalTrackHits
- List<HelicalTrackCross> stereoCrosses = new ArrayList<HelicalTrackCross>();
- List<HelicalTrackHit> helhits = new ArrayList<HelicalTrackHit>();
-
- // Create a List of LCRelations to relate HelicalTrackHits to the original hits
- List<LCRelation> hitrelations = new ArrayList<LCRelation>();
- // Create a List of LCRelations to relate HelicalTrackHits to the MC particle
- List<LCRelation> mcrelations = new ArrayList<LCRelation>();
-
-
-
- for (String _colname : this._colnames) {
+
+ for (String _colname : this._colnames) {
- if (!event.hasCollection(SiTrackerHit.class, _colname)) {
- continue;
- }
+ if (!event.hasCollection(SiTrackerHit.class, _colname)) continue;
// Get the list of SiTrackerHits for this collection
- List<SiTrackerHit> hitlist = (List<SiTrackerHit>) event.get(_colname);
+ List<SiTrackerHit> hitlist = event.get(SiTrackerHit.class, _colname);
+
if (_debug) {
System.out.printf("%s: found %d SiTrackerHits\n", this.getClass().getSimpleName(), hitlist.size());
}
@@ -279,9 +317,10 @@
}
// This hit should be a on a stereo pair!
- if(_det.findSensor(sensor)==false) {
- throw new RuntimeException(this.getClass().getSimpleName() + ": this " +sensor.getName()+ " was not in the detector!?");
- }
+ //====> Is this check really necessary?
+ //if(_det.findSensor(sensor)==false) {
+ // throw new RuntimeException(this.getClass().getSimpleName() + ": this " +sensor.getName()+ " was not in the detector!?");
+ //}
// Create a HelicalTrackStrip for this hit
HelicalTrackStrip strip = makeDigiStrip(h);
@@ -300,29 +339,29 @@
} else {
// If not a 1D strip hit, make a pixel hit
+ // This should be removed.
HelicalTrackHit hit3d = this.makeDigi3DHit(hit);
helhits.add(hit3d);
hitrelations.add(new MyLCRelation(hit3d, hit));
}
-
} // Loop over SiTrackerHits
// Create a list of stereo hits
//List<HelicalTrackCross> stereohits = new ArrayList<HelicalTrackCross>();
+ /*
if (_debug) {
System.out.printf("%s: Create stereo hits from %d sensors being hit \n", this.getClass().getSimpleName(), striplistmap.size());
System.out.printf("%s: %d and %d stereo pairs in top and bottom resp. and %d together\n",
this.getClass().getSimpleName(), _det._top.getStereoPairs().size(),_det._bot.getStereoPairs().size(),_det.getStereoPairs().size());
- }
+ }*/
- for(StereoPair pair : _det.getStereoPairs()) {
-
-
-
- /*
+// for(StereoPair pair : _det.getStereoPairs()) {
+ for(StereoPair stereoPair : SvtUtils.getInstance().getStereoPairs()){
+
+ /*
* Form the stereo hits and add them to our hit list Add LC
* relations for stereo hit to SiTrackHitStrip1D object Add LC
* relation between MC particle and stereo hit
@@ -331,15 +370,27 @@
// this is really stupid but the cross get layer name based on the first strip in the argument
// turns out that this is the uneven one and many places depends on this e.g. seeding so we keep it
// for now. Obviously not the right way to do stuff I think, the stereo layer and sensor layer should
- // be decoupled...?
+ // be decoupled...?
+ //
+ // They should ...
+
+ // Is this check really necessary? This is guaranteed by the manner in which stereo pairs are created.
+ // If anything, this really belongs in a unit test.
+ if((SvtUtils.getInstance().getLayerNumber(stereoPair.getAxialSensor()) + SvtUtils.getInstance().getLayerNumber(stereoPair.getStereoSensor())) % 2 ==0) {
+ throw new RuntimeException(String.format("%s: axial and stereo are both even layers (%d,%d)?!",
+ this.getClass().getSimpleName(),SvtUtils.getInstance().getLayerNumber(stereoPair.getAxialSensor()),
+ SvtUtils.getInstance().getLayerNumber(stereoPair.getStereoSensor())));
+ }
- if((SvtUtils.getInstance().getLayerNumber(pair.getAxialSensor()) + SvtUtils.getInstance().getLayerNumber(pair.getStereoSensor())) % 2 ==0) {
- throw new RuntimeException(String.format("%s: axial and stereo are both even layers (%d,%d)?!",
- this.getClass().getSimpleName(),SvtUtils.getInstance().getLayerNumber(pair.getAxialSensor()),
- SvtUtils.getInstance().getLayerNumber(pair.getStereoSensor())));
+ List<HelicalTrackCross> helicalTrackCrosses = null;
+ if(stereoPair.getDetectorVolume() == detectorVolume.Top){
+ helicalTrackCrosses = _crosser.MakeHits(striplistmap.get(stereoPair.getAxialSensor()), striplistmap.get(stereoPair.getStereoSensor()));
+ } else if(stereoPair.getDetectorVolume() == detectorVolume.Bottom){
+ helicalTrackCrosses = _crosser.MakeHits(striplistmap.get(stereoPair.getStereoSensor()), striplistmap.get(stereoPair.getAxialSensor()));
}
+ /*
SiSensor s1,s2;
if(SvtUtils.getInstance().getLayerNumber(pair.getAxialSensor()) % 2 ==0) {
@@ -349,18 +400,18 @@
s1 = pair.getAxialSensor();
s2 = pair.getStereoSensor();
}
- List<HelicalTrackCross> cross_list = _crosser.MakeHits(striplistmap.get(s1), striplistmap.get(s2));
+ List<HelicalTrackCross> cross_list = _crosser.MakeHits(striplistmap.get(s1), striplistmap.get(s2)); */
if (_debug) System.out.printf("%s: Found %d stereo hits from sensors\n%s: %s : %d hits\n%s: %s with %d hits\n",
- this.getClass().getSimpleName(), cross_list.size(),
+ this.getClass().getSimpleName(), helicalTrackCrosses.size(),
this.getClass().getSimpleName(),
- pair.getAxialSensor().getName(),striplistmap.get(pair.getAxialSensor())==null?0:striplistmap.get(pair.getAxialSensor()).size(),
+ stereoPair.getAxialSensor().getName(),striplistmap.get(stereoPair.getAxialSensor())==null?0:striplistmap.get(stereoPair.getAxialSensor()).size(),
this.getClass().getSimpleName(),
- pair.getStereoSensor().getName(),striplistmap.get(pair.getStereoSensor())==null?0:striplistmap.get(pair.getStereoSensor()).size());
+ stereoPair.getStereoSensor().getName(),striplistmap.get(stereoPair.getStereoSensor())==null?0:striplistmap.get(stereoPair.getStereoSensor()).size());
- for (HelicalTrackCross cross : cross_list) {
+ for (HelicalTrackCross cross : helicalTrackCrosses) {
stereoCrosses.add(cross);
if (cross.getMCParticles() != null) {
for (MCParticle mcp : cross.getMCParticles()) {
@@ -410,9 +461,6 @@
System.exit(1);
//throw new TypeNotPresentException("This layer geometry type is not supported",null);
}
-
-
-
} //Process()
public void addCollection(String colname) {
@@ -434,32 +482,38 @@
@Override
protected void detectorChanged(Detector detector) {
- /*
+
+ /*
* Setup default pairing
*/
if (_debug) System.out.printf("%s: Setup stereo hit pair modules \n", this.getClass().getSimpleName());
- List<SiTrackerModule> modules = detector.getSubdetector(this.subdetectorName).getDetectorElement().findDescendants(SiTrackerModule.class);
+ List<SiTrackerModule> modules = detector.getSubdetector(this._subdetectorName).getDetectorElement().findDescendants(SiTrackerModule.class);
+
if (modules.isEmpty()) {
throw new RuntimeException(this.getClass().getName() + ": No SiTrackerModules found in detector.");
}
+
if (LayerGeometryType.Split==this._layerGeometryType) {
-
+ /*
+
_det = new SimpleDetector();
for(SiTrackerModule module : modules) {
+
List<SiSensor> sensors = module.findDescendants(SiSensor.class);
+
for(SiSensor sensor : sensors) {
_det.addSensor(sensor);
}
}
_det.print();
-
+ */
- } else if (LayerGeometryType.Common==this._layerGeometryType) {
+ } else if(LayerGeometryType.Common==this._layerGeometryType) {
- int nLayersTotal = detector.getSubdetector(subdetectorName).getLayering().getLayers().getNumberOfLayers();
+ int nLayersTotal = detector.getSubdetector(_subdetectorName).getLayering().getLayers().getNumberOfLayers();
if (_debug) {
System.out.printf("%s: %d layers \n", this.getClass().getSimpleName(), nLayersTotal);
}
@@ -474,7 +528,7 @@
}
for (int[] pair : pairs) {
if (_debug) System.out.printf("%s: adding stereo pair from layer %d and %d \n", this.getClass().getSimpleName(), pair[0], pair[1]);
- setStereoPair(subdetectorName, pair[0], pair[1]);
+ setStereoPair(_subdetectorName, pair[0], pair[1]);
}
} else {
@@ -581,31 +635,23 @@
}
-
+
+ @Deprecated
private static class SimpleDetector {
//private static final HelicalTrackHitDriver hthDriver = HelicalTrackHitDriver.this;
-
+
private Layers _top = new Layers();
private Layers _bot = new Layers();
private void addSensor(SiSensor sensor) {
if(SvtUtils.getInstance().isTopLayer(sensor) ) {
- //System.out.printf("Adding top sensor at tracker layer %d\n",getModuleLevelLayerNumber(sensor));
+ System.out.printf("Adding top sensor at tracker layer %d\n",getModuleLevelLayerNumber(sensor));
_top.addSensor(sensor);
- }
- else {
- //System.out.printf("Adding bot sensor at tracker layer %d\n",getModuleLevelLayerNumber(sensor));
+ } else {
+ System.out.printf("Adding bot sensor at tracker layer %d\n",getModuleLevelLayerNumber(sensor));
_bot.addSensor(sensor);
}
}
-
- private void print() {
- System.out.printf("HelicalTrackHitDriver Stereo pair setup:\n");
- System.out.printf("Top half:\n");
- _top.print();
- System.out.printf("Bottom half:\n");
- _bot.print();
- }
private void checkDetector() {
if((_top._layers.size() % 2 != 0) || (_bot._layers.size() % 2 != 0) ) {
@@ -627,11 +673,22 @@
return list;
}
+ private void print() {
+ System.out.printf("HelicalTrackHitDriver Stereo pair setup:\n");
+ System.out.printf("Top half:\n");
+ _top.print();
+ System.out.printf("Bottom half:\n");
+ _bot.print();
+ }
+
}
+
+ @Deprecated
private static int getModuleLevelLayerNumber(SiSensor sensor) {
int l = SvtUtils.getInstance().getLayerNumber(sensor);
- if(SvtUtils.getInstance().isTopLayer(sensor) ) {
+
+ if(SvtUtils.getInstance().isTopLayer(sensor)) {
if (SvtUtils.getInstance().isAxial(sensor)) {
l = (l + 1)/2;
} else {
@@ -646,25 +703,31 @@
}
return l;
}
-
+
+ @Deprecated
private static class Layers {
+
public List<StereoPair> _layers = new ArrayList<StereoPair>();
+
private StereoPair getLayer(int l) {
for(StereoPair layer : _layers) {
- if(layer.getLayerNr() == l) return layer;
+ // if(layer.getLayerNr() == l) return layer;
}
return null;
}
+
private void addLayer(StereoPair layer) {
- if(getLayer(layer.getLayerNr())!=null) throw new RuntimeException(String.format("Layer %d exists!",layer.getLayerNr()));
+ // if(getLayer(layer.getLayerNr())!=null) throw new RuntimeException(String.format("Layer %d exists!",layer.getLayerNr()));
_layers.add(layer);
}
-
+
private void addSensor(SiSensor sensor) {
+
int l = getModuleLevelLayerNumber(sensor);
+
StereoPair layer = getLayer(l);
if(layer==null) {
- layer = new StereoPair(l);
+ layer = new StereoPair(l);
_layers.add(layer);
}
boolean isAx = SvtUtils.getInstance().isAxial(sensor);
@@ -672,6 +735,7 @@
else layer.setStereoSensor(sensor);
}
+
private boolean findSensor(SiSensor sensor) {
for(StereoPair layer : _layers) {
if(layer.getAxialSensor().equals(sensor) || layer.getStereoSensor().equals(sensor)) {
@@ -683,7 +747,7 @@
private void print() {
for(StereoPair l : _layers) {
- l.print();
+// l.print();
}
}
@@ -693,52 +757,4 @@
return pairs;
}
}
-
-
-
- private static class StereoPair {
- private int _layer=-1;
- private SiSensor _axialSensor = null;
- private SiSensor _stereoSensor = null;
-
- public StereoPair(int layer) {
- this._layer = layer;
- }
-
- public void setAxialSensor(SiSensor axialSensor) {
- if(this._axialSensor!=null) throw new RuntimeException(String.format("Try to add another axial sensor to layer %d",_layer));
- this._axialSensor = axialSensor;
- }
-
- public void setStereoSensor(SiSensor stereoSensor) {
- if(this._stereoSensor!=null) throw new RuntimeException(String.format("Try to add another stereo sensor to layer %d",_layer));
- this._stereoSensor = stereoSensor;
- }
-
-
- public SiSensor getStereoSensor() {
- return this._stereoSensor;
- }
-
-
-
- public SiSensor getAxialSensor() {
- return this._axialSensor;
- }
- public void setLayerNr(int _layer) {
- this._layer = _layer;
- }
-
- public int getLayerNr() {
- return this._layer;
- }
-
- private void print() {
- String name_Ax = this.getAxialSensor()==null?"NONE":this.getAxialSensor().getName();
- String name_St = this.getStereoSensor()==null?"NONE":this.getStereoSensor().getName();
- System.out.printf("Layer %d Axial: %s StereoSensor: %s\n",getLayerNr(),name_Ax,name_St);
- }
- }
-
-
}