Print

Print


Commit in lcsim-contrib/src/main/java/org/lcsim/contrib/Partridge/DarkForces on MAIN
DarkForcesHitDriver.java+318added 1.1
Driver that allows you to specify planes to combine for stereo hits.

lcsim-contrib/src/main/java/org/lcsim/contrib/Partridge/DarkForces
DarkForcesHitDriver.java added at 1.1
diff -N DarkForcesHitDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ DarkForcesHitDriver.java	5 Jan 2010 02:30:34 -0000	1.1
@@ -0,0 +1,318 @@
+/*
+ * DarkForcesHitDriver.java
+ *
+ * Created on January 4, 2010
+ *
+ */
+package org.lcsim.contrib.Partridge.DarkForces;
+
+import hep.physics.vec.BasicHep3Vector;
+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 org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.ITransform3D;
+import org.lcsim.digisim.MyLCRelation;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.LCRelation;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.fit.helicaltrack.HelicalTrack2DHit;
+import org.lcsim.fit.helicaltrack.HelicalTrack3DHit;
+import org.lcsim.fit.helicaltrack.HelicalTrackCross;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.fit.helicaltrack.HelicalTrackStrip;
+import org.lcsim.fit.helicaltrack.HitIdentifier;
+import org.lcsim.fit.helicaltrack.StereoHitMaker;
+import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
+import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHit;
+import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHitStrip1D;
+import org.lcsim.recon.tracking.digitization.sisim.TrackerHitType.CoordinateSystem;
+import org.lcsim.recon.tracking.vsegment.hit.DigiTrackerHit;
+import org.lcsim.recon.tracking.vsegment.hit.TrackerCluster;
+import org.lcsim.util.Driver;
+
+/**
+ * Create the appropriate HelicalTrackHits for the specified TrackerHit
+ * collections.  The resulting HelicalTrackHits encapsulate the information
+ * needed to perform a helical track hit for either a segmented strip
+ * detector, a pixel detector, or cross hits from a stereo detector.
+ *
+ * This driver was developed for the Dark Forces silicon tracker, where
+ * digitized hits are in either axial or stereo layers.  The pairs of layers
+ * to be used in forming stereo hits can be specified using the setStereoPairs
+ * method.
+ *
+ * The list of hit collections to be converted must be specified
+ * before the process method is executed.
+ *
+ * @author Richard Partridge
+ * @version 1.0
+ */
+public class DarkForcesHitDriver extends Driver {
+
+    private StereoHitMaker _crosser = new StereoHitMaker(2., 10.);
+    private HitIdentifier _ID = new HitIdentifier();
+    private String _outname = "HelicalTrackHits";
+    private String _hitrelname = "HelicalTrackHitRelations";
+    private String _mcrelname = "HelicalTrackMCRelations";
+    private List<String> _colnames = new ArrayList<String>();
+    private Map<String, String> _stereomap = new HashMap<String, String>();
+    private Hep3Vector _orgloc = new BasicHep3Vector(0., 0., 0.);
+    private double _eps = 1.0e-6;
+
+    /** Creates a new instance of HelicalTrackHitDriver */
+    public DarkForcesHitDriver() {
+    }
+
+    /**
+     * Create the HelicalTrackHits for the specified hit collections.
+     * @param event EventHeader of the event to be processed
+     */
+    @Override
+    public void process(EventHeader event) {
+        super.process(event);
+
+        //  Initialize the list of HelicalTrackHits
+        List<HelicalTrackHit> helhits = new ArrayList<HelicalTrackHit>();
+
+        //  Create a List of LCRelations to relate HelicalTrackHits to the original hits
+        List<LCRelation> hitrelations = new ArrayList<LCRelation>();
+
+        for (String id1 : _stereomap.keySet()) {
+            System.out.println("Stereo layer pairs: "+id1+" / "+_stereomap.get(id1));
+        }
+        
+        for (String _colname : _colnames) {
+
+            //  Get the list of SiTrackerHits for this collection
+            List<SiTrackerHit> hitlist = (List<SiTrackerHit>) event.get(_colname);
+
+            //  Create collections for strip hits by layer and hit cross references
+            Map<String, List<HelicalTrackStrip>> striplistmap = new HashMap<String, List<HelicalTrackStrip>>();
+            Map<HelicalTrackStrip, SiTrackerHitStrip1D> stripmap = new HashMap<HelicalTrackStrip, SiTrackerHitStrip1D>();
+
+            //  Loop over the SiTrackerHits in this collection
+            for (SiTrackerHit hit : hitlist) {
+
+                //  Check if we have a 1D strip hit
+                if (hit instanceof SiTrackerHitStrip1D) {
+
+                    //  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 = makeID(_ID.getName(de), _ID.getLayer(de));
+                    System.out.println("Found hit with ID: "+id);
+
+                    //  Check if hit is on a stereo pair layer
+                    if (_stereomap.containsKey(id) || _stereomap.containsValue(id)) {
+
+                        //  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
+                        List<HelicalTrackStrip> lyrhits = striplistmap.get(id);
+                        if (lyrhits == null) {
+                            lyrhits = new ArrayList<HelicalTrackStrip>();
+                            striplistmap.put(id, lyrhits);
+                        }
+
+                        //  Add the strip to the list of strips on this sensor
+                        lyrhits.add(strip);
+
+                        //  Map a reference back to the hit needed to create the stereo hit LC relations
+                        stripmap.put(strip, h);
+
+                    } else {
+
+                        //  If not a stereo hit, create an axial strip hit and the corresponding LC Relation
+                        HelicalTrackHit dah = makeDigiAxialHit(h);
+                        helhits.add(dah);
+                        hitrelations.add(new MyLCRelation(dah, hit));
+                    }
+
+                } else {
+
+                    //  If not a 1D strip hit, make a pixel hit
+                    HelicalTrackHit hit3d = makeDigi3DHit(hit);
+                    helhits.add(hit3d);
+                    hitrelations.add(new MyLCRelation(hit3d, hit));
+                }
+            }
+
+            //  Now create the stereo hits
+            //  Create a list of stereo hits
+            List<HelicalTrackCross> stereohits = new ArrayList<HelicalTrackCross>();
+
+            //  Loop over the stereo layer pairs
+            for (String id1 : _stereomap.keySet()) {
+
+                //  Get the second layer
+                String id2 = _stereomap.get(id1);
+
+                //  Form the stereo hits and add them to our hit list
+                stereohits.addAll(_crosser.MakeHits(striplistmap.get(id1), striplistmap.get(id2)));
+            }
+
+            //  Add the stereo hits to our list of HelicalTrackHits
+            helhits.addAll(stereohits);
+
+            //add LCRelation for strip hits
+            for (HelicalTrackCross cross : stereohits) {
+                for (HelicalTrackStrip strip : cross.getStrips()) {
+                    hitrelations.add(new MyLCRelation(cross, stripmap.get(strip)));
+                }
+            }
+        }
+
+        //  Create the LCRelations between HelicalTrackHits and MC particles
+        List<LCRelation> mcrelations = new ArrayList<LCRelation>();
+        for (HelicalTrackHit hit : helhits) {
+            for (MCParticle mcp : hit.getMCParticles()) {
+                mcrelations.add(new MyLCRelation(hit, mcp));
+            }
+        }
+
+
+        //  Put the HelicalTrackHits back into the event
+        event.put(_outname, helhits, HelicalTrackHit.class, 0);
+        event.put(_hitrelname, hitrelations, LCRelation.class, 0);
+        event.put(_mcrelname, mcrelations, LCRelation.class, 0);
+        return;
+    }
+
+    /**
+     * Name of the HelicalTrackHit collection to be put back in the event.
+     * @param outname Name to use for the HelicalTrackHit collection
+     */
+    public void addCollection(String colname) {
+        _colnames.add(colname);
+    }
+
+    public void OutputCollection(String outname) {
+        _outname = outname;
+        return;
+    }
+
+    public void setOutputCollectionName(String outname) {
+        _outname = outname;
+        return;
+    }
+
+    public void HitRelationName(String hitrelname) {
+        _hitrelname = hitrelname;
+        return;
+    }
+
+    public void MCRelationName(String mcrelname) {
+        _mcrelname = mcrelname;
+        return;
+    }
+
+    public void setMaxSeperation(double maxsep) {
+        _crosser.setMaxSeparation(maxsep);
+        return;
+    }
+
+    public void setTolerance(double tolerance) {
+        _crosser.setTolerance(tolerance);
+        return;
+    }
+
+    public void setStereoPair(String detname, int lyr1, int lyr2) {
+        _stereomap.put(makeID(detname, lyr1), makeID(detname, lyr2));
+    }
+
+    private List<MCParticle> getMCParticles(TrackerCluster cluster) {
+        List<MCParticle> mcplist = new ArrayList<MCParticle>();
+        for (DigiTrackerHit dhit : cluster.getDigiHits()) {
+            //  Get the elemental hits - not sure what the dif is...
+            for (DigiTrackerHit dhit2 : dhit.getElementalHits()) {
+                //  Get the MCParticle and add it to the hit
+                MCParticle mcp = dhit2.getMCParticle();
+                if (mcp != null) {
+                    mcplist.add(mcp);
+                }
+            }
+        }
+        return mcplist;
+    }
+
+    private HelicalTrackHit makeDigi3DHit(SiTrackerHit h) {
+
+        IDetectorElement de = h.getSensor();
+        int lyr = _ID.getLayer(de);
+        BarrelEndcapFlag be = _ID.getBarrelEndcapFlag(de);
+
+        HelicalTrackHit hit = new HelicalTrack3DHit(h.getPositionAsVector(),
+                h.getCovarianceAsMatrix(), h.getdEdx(), h.getTime(),
+                h.getRawHits(), _ID.getName(de), lyr, be);
+
+        for (MCParticle p : h.getMCParticles()) {
+            hit.addMCParticle(p);
+        }
+
+        return hit;
+
+    }
+
+    private HelicalTrackHit makeDigiAxialHit(SiTrackerHitStrip1D h) {
+
+        double z1 = h.getHitSegment().getEndPoint().z();
+        double z2 = h.getHitSegment().getStartPoint().z();
+        double zmin = Math.min(z1, z2);
+        double zmax = Math.max(z1, z2);
+        IDetectorElement de = h.getSensor();
+
+        HelicalTrackHit hit = new HelicalTrack2DHit(h.getPositionAsVector(),
+                h.getCovarianceAsMatrix(), h.getdEdx(), h.getTime(),
+                h.getRawHits(), _ID.getName(de), _ID.getLayer(de),
+                _ID.getBarrelEndcapFlag(de), zmin, zmax);
+
+        for (MCParticle p : h.getMCParticles()) {
+            hit.addMCParticle(p);
+        }
+        return hit;
+    }
+
+    private HelicalTrackStrip makeDigiStrip(SiTrackerHitStrip1D h) {
+
+        SiTrackerHitStrip1D local = h.getTransformedHit(CoordinateSystem.SENSOR);
+        SiTrackerHitStrip1D global = h.getTransformedHit(CoordinateSystem.GLOBAL);
+
+        ITransform3D trans = local.getLocalToGlobal();
+        Hep3Vector org = trans.transformed(_orgloc);
+        Hep3Vector u = global.getMeasuredCoordinate();
+        Hep3Vector v = global.getUnmeasuredCoordinate();
+
+        double umeas = local.getPosition()[0];
+        double vmin = VecOp.dot(local.getUnmeasuredCoordinate(), local.getHitSegment().getStartPoint());
+        double vmax = VecOp.dot(local.getUnmeasuredCoordinate(), local.getHitSegment().getEndPoint());
+        double du = Math.sqrt(local.getCovarianceAsMatrix().diagonal(0));
+
+        IDetectorElement de = h.getSensor();
+        String det = _ID.getName(de);
+        int lyr = _ID.getLayer(de);
+        BarrelEndcapFlag be = _ID.getBarrelEndcapFlag(de);
+
+        double dEdx = h.getdEdx();
+        double time = h.getTime();
+        List<RawTrackerHit> rawhits = h.getRawHits();
+        HelicalTrackStrip strip = new HelicalTrackStrip(org, u, v, umeas, du,
+                vmin, vmax, dEdx, time, rawhits, det, lyr, be);
+
+        for (MCParticle p : h.getMCParticles()) {
+            strip.addMCParticle(p);
+        }
+        return strip;
+    }
+
+    private String makeID(String detname, int lyr) {
+        return detname + lyr;
+    }
+}
\ No newline at end of file
CVSspam 0.2.8