Print

Print


Commit in lcsim/src/org/lcsim/recon/cluster/mipfinder/trackxtrap on MAIN
XtrapPositionDSort.java+21added 1.1
TrackXtrapThruCalDriver.java+247added 1.1
TrackXtrapCalPositions.java+35added 1.1
AttachCalorimeterHitsDriver.java+83added 1.1
TrackXtrapInfo.java+75added 1.1
+461
5 added files
Track extrapolation package for initial mip finding

lcsim/src/org/lcsim/recon/cluster/mipfinder/trackxtrap
XtrapPositionDSort.java added at 1.1
diff -N XtrapPositionDSort.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ XtrapPositionDSort.java	6 Oct 2010 19:40:42 -0000	1.1
@@ -0,0 +1,21 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.recon.cluster.mipfinder.trackxtrap;
+import java.util.*;
+
+/**
+ *
+ * @author cassell
+ */
+public class XtrapPositionDSort implements Comparator<XtrapPosition>
+{
+    public int compare(XtrapPosition x1, XtrapPosition x2)
+    {
+        if( x1.getPosition().magnitudeSquared() - x2.getPosition().magnitudeSquared() > 0 ) return 1;
+        return -1;
+    }
+
+}

lcsim/src/org/lcsim/recon/cluster/mipfinder/trackxtrap
TrackXtrapThruCalDriver.java added at 1.1
diff -N TrackXtrapThruCalDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrackXtrapThruCalDriver.java	6 Oct 2010 19:40:42 -0000	1.1
@@ -0,0 +1,247 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.recon.cluster.mipfinder.trackxtrap;
+import org.lcsim.recon.util.*;
+import org.lcsim.util.Driver;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.Track;
+import org.lcsim.geometry.Calorimeter;
+import java.util.*;
+import hep.physics.vec.*;
+import org.lcsim.recon.pfa.identifier.HelixExtrapolator;
+import org.lcsim.recon.pfa.identifier.HelixExtrapolationResult;
+import org.lcsim.util.swim.HelixSwimmer;
+
+/**
+ *
+ * @author cassell
+ */
+public class TrackXtrapThruCalDriver extends Driver
+{
+    CalorimeterInformation ci;
+    Map<Track,Map<Calorimeter.CalorimeterType,List<Hep3Vector>>> tpmap;
+    HelixExtrapolator xtrap;
+    HelixExtrapolationResult xr;
+    TrackXtrapCalPositions txcp;
+    String inputTrackList;
+    List<Hep3Vector> nulllist;
+    List<TrackXtrapInfo> txil;
+    String outputName;
+    HelixSwimmer hs;
+    double[] field;
+    public TrackXtrapThruCalDriver(HelixExtrapolator xt, String tracklist, String outName)
+    {
+        outputName = outName;
+        xtrap = xt;
+        txcp = new TrackXtrapCalPositions();
+        inputTrackList = tracklist;
+        nulllist = new ArrayList<Hep3Vector>();
+        for(int i=0;i<50;i++)
+        {
+            nulllist.add(null);
+        }
+    }
+    protected void process(EventHeader event)
+    {
+        if(ci == null)
+        {
+            ci = CalorimeterInformation.instance();
+            double[] zero = {0, 0, 0};
+            field = event.getDetector().getFieldMap().getField(zero);
+            hs = new HelixSwimmer(field[2]);
+        }
+        txil = new ArrayList<TrackXtrapInfo>();
+        tpmap = new HashMap<Track,Map<Calorimeter.CalorimeterType,List<Hep3Vector>>>();
+        List<Track> tl = event.get(Track.class,inputTrackList);
+        for(Track tt:tl)
+        {
+            int ich = tt.getCharge();
+            double pmag = (new BasicHep3Vector(tt.getMomentum())).magnitude();
+            TrackXtrapInfo txi = new TrackXtrapInfo(tt);
+            txil.add(txi);
+            Map<Calorimeter.CalorimeterType,List<Hep3Vector>> tm = new HashMap<Calorimeter.CalorimeterType,List<Hep3Vector>>();
+            tpmap.put(tt, tm);
+            xr = xtrap.performExtrapolation(tt);
+            if(xr == null)
+            {
+                System.out.println("Extrapolation to Ecal failed");
+                tm.put(Calorimeter.CalorimeterType.EM_BARREL, nulllist);
+                tm.put(Calorimeter.CalorimeterType.EM_ENDCAP, nulllist);
+                tm.put(Calorimeter.CalorimeterType.HAD_BARREL, nulllist);
+                tm.put(Calorimeter.CalorimeterType.HAD_ENDCAP, nulllist);
+                txi.setSwimmer(null);
+                continue;
+            }
+            txi.setSwimmer(xr.getSwimmer());
+            // To avoid big loopers, we need to set a maximum distance for the swimmer
+            // If the helix intercepts the max radius of the Hcal barrel, then set
+            // the max distance to that arclength. Then disallow endcap intercepts
+            // with arclength greater than that.
+            double maxs = 99999.;
+            double maxr = ci.getRMax(Calorimeter.CalorimeterType.HAD_BARREL);
+            double s = 0.;
+            if(ci.getNSides(Calorimeter.CalorimeterType.HAD_BARREL) < 3)
+                s = xr.getSwimmer().getDistanceToRadius(maxr);
+            else s = xr.getSwimmer().getDistanceToPolyhedra(maxr,ci.getNSides(Calorimeter.CalorimeterType.HAD_BARREL));
+            if(!Double.isNaN(s))maxs = s;
+            // Set the order of calorimeters
+            Hep3Vector embpos0 = xr.extendToECALBarrelLayer(0);
+            Hep3Vector emepos0 = xr.extendToECALEndcapLayer(0);
+            Hep3Vector hbpos0 = xr.extendToHCALBarrelLayer(0);
+            Hep3Vector hepos0 = xr.extendToHCALEndcapLayer(0);
+            Calorimeter.CalorimeterType[] oct = new Calorimeter.CalorimeterType[4];
+            Hep3Vector[] pos0 = new Hep3Vector[4];
+            double[] s0 = {9999.,9999.,9999.,9999.};
+            if(embpos0 == null)
+            {
+                pos0[0] = emepos0;
+                pos0[1] = embpos0;
+                oct[1] = Calorimeter.CalorimeterType.EM_BARREL;
+                oct[0] = Calorimeter.CalorimeterType.EM_ENDCAP;
+                if(emepos0 != null)s0[0] = xr.getSwimmer().getDistanceToPoint(emepos0);
+            }
+            else if(emepos0 == null)
+            {
+                pos0[1] = emepos0;
+                pos0[0] = embpos0;
+                oct[0] = Calorimeter.CalorimeterType.EM_BARREL;
+                oct[1] = Calorimeter.CalorimeterType.EM_ENDCAP;
+                if(embpos0 != null)s0[0] = xr.getSwimmer().getDistanceToPoint(embpos0);
+            }
+            else
+            {
+                s0[0] = xr.getSwimmer().getDistanceToPoint(embpos0);
+                s0[1] = xr.getSwimmer().getDistanceToPoint(emepos0);
+                if(s0[0] > s0[1])
+                {
+                    pos0[0] = emepos0;
+                    pos0[1] = embpos0;
+                    oct[1] = Calorimeter.CalorimeterType.EM_BARREL;
+                    oct[0] = Calorimeter.CalorimeterType.EM_ENDCAP;
+                    double temp = s0[0];
+                    s0[0] = s0[1];
+                    s0[1] = temp;
+                }
+                else
+                {
+                    pos0[1] = emepos0;
+                    pos0[0] = embpos0;
+                    oct[0] = Calorimeter.CalorimeterType.EM_BARREL;
+                    oct[1] = Calorimeter.CalorimeterType.EM_ENDCAP;
+                }
+            }
+            if(hbpos0 == null)
+            {
+                pos0[2] = hepos0;
+                pos0[3] = hbpos0;
+                oct[3] = Calorimeter.CalorimeterType.HAD_BARREL;
+                oct[2] = Calorimeter.CalorimeterType.HAD_ENDCAP;
+                if(hepos0 != null)s0[2] = xr.getSwimmer().getDistanceToPoint(hepos0);
+            }
+            else if(hepos0 == null)
+            {
+                pos0[3] = hepos0;
+                pos0[2] = hbpos0;
+                oct[2] = Calorimeter.CalorimeterType.HAD_BARREL;
+                oct[3] = Calorimeter.CalorimeterType.HAD_ENDCAP;
+                if(hbpos0 != null)s0[2] = xr.getSwimmer().getDistanceToPoint(hbpos0);
+            }
+            else
+            {
+                s0[2] = xr.getSwimmer().getDistanceToPoint(hbpos0);
+                s0[3] = xr.getSwimmer().getDistanceToPoint(hepos0);
+                if(s0[2] > s0[3])
+                {
+                    pos0[2] = hepos0;
+                    pos0[3] = hbpos0;
+                    oct[3] = Calorimeter.CalorimeterType.HAD_BARREL;
+                    oct[2] = Calorimeter.CalorimeterType.HAD_ENDCAP;
+                    double temp = s0[2];
+                    s0[2] = s0[3];
+                    s0[3] = temp;
+                }
+                else
+                {
+                    pos0[3] = hepos0;
+                    pos0[2] = hbpos0;
+                    oct[2] = Calorimeter.CalorimeterType.HAD_BARREL;
+                    oct[3] = Calorimeter.CalorimeterType.HAD_ENDCAP;
+                }
+            }
+            for(int it=0;it<4;it++)
+            {
+                Calorimeter.CalorimeterType ct = oct[it];
+                List<Hep3Vector> pl = new ArrayList<Hep3Vector>();
+                tm.put(ct,pl);
+                if(s0[it] > maxs)pos0[it] = null;
+                pl.add(pos0[it]);
+                XtrapPosition xp = new XtrapPosition();
+                if(pos0[it] != null)
+                {
+                    xp.setCalorimeterType(ct);
+                    xp.setLayer(0);
+                    xp.setPosition(pos0[it]);
+                    xp.setDirection(xr.getTangent(pos0[it]));
+                    txi.addPosition(xp);
+                    pmag -= adjustPmag(ct,0,pos0[it],xr.getTangent(pos0[it]));
+                }
+                Hep3Vector prevpos = pos0[it];
+                for(int lay=1;lay<ci.getNLayers(ct);lay++)
+                {
+                // extrap
+                    Hep3Vector pos = prevpos;
+                    if(pos != null)
+                    {
+                        pos = extendToLayer(oct[it],lay,prevpos,xr.getTangent(prevpos),pmag,ich);
+                        if(pos != null)
+                        {
+                            if(xr.getSwimmer().getDistanceToPoint(pos)>maxs)pos = null;
+                        }
+                    }
+                    pl.add(pos);
+                    xp = new XtrapPosition();
+                    if(pos != null)
+                    {
+                        xp.setCalorimeterType(ct);
+                        xp.setLayer(lay);
+                        xp.setPosition(pos);
+                        xp.setDirection(xr.getTangent(pos));
+                        txi.addPosition(xp);
+                        pmag -= adjustPmag(oct[it],lay,pos,xr.getTangent(pos));
+                    }
+                    prevpos = pos;
+                }
+            }
+            txi.sortPositions();
+        }
+        txcp.setMap(tpmap);
+        event.put(outputName,txil);
+    }
+    protected double adjustPmag(Calorimeter.CalorimeterType ct,int lay,Hep3Vector pos,Hep3Vector dir)
+    {
+        //TODO - calculate normals for polygonal detectors
+        Hep3Vector norm;
+        if( (ct == Calorimeter.CalorimeterType.EM_ENDCAP)||(ct == Calorimeter.CalorimeterType.HAD_ENDCAP) )
+            norm = new BasicHep3Vector(0.,0.,pos.z());
+        else norm = new BasicHep3Vector(pos.x(),pos.y(),0.);
+        norm = VecOp.unit(norm);
+        double cos = VecOp.dot(norm, dir);
+        if(cos <= 0.)return 0.;
+        double meande = ci.getMeanDe(ct, lay)/cos;
+        return meande;
+    }
+    protected Hep3Vector extendToLayer(Calorimeter.CalorimeterType ct, int lay, Hep3Vector pos, Hep3Vector dir, double pmag, int ich)
+    {
+        Hep3Vector p = VecOp.mult(pmag, dir);
+        hs.setTrack(p, pos, ich);
+        xr.setSwimmer(hs);
+        if(ct == Calorimeter.CalorimeterType.HAD_BARREL)return xr.extendToHCALBarrelLayer(lay);
+        if(ct == Calorimeter.CalorimeterType.HAD_ENDCAP)return xr.extendToHCALEndcapLayer(lay);
+        if(ct == Calorimeter.CalorimeterType.EM_BARREL)return xr.extendToECALBarrelLayer(lay);
+        if(ct == Calorimeter.CalorimeterType.EM_ENDCAP)return xr.extendToECALEndcapLayer(lay);
+        return null;
+    }
+}

lcsim/src/org/lcsim/recon/cluster/mipfinder/trackxtrap
TrackXtrapCalPositions.java added at 1.1
diff -N TrackXtrapCalPositions.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrackXtrapCalPositions.java	6 Oct 2010 19:40:42 -0000	1.1
@@ -0,0 +1,35 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.recon.cluster.mipfinder.trackxtrap;
+import java.util.*;
+import org.lcsim.event.Track;
+import org.lcsim.geometry.Calorimeter;
+import hep.physics.vec.*;
+/**
+ *
+ * @author cassell
+ */
+public class TrackXtrapCalPositions
+{
+    static TrackXtrapCalPositions theTrackXtrapCalPositions;
+    Map<Track,Map<Calorimeter.CalorimeterType,List<Hep3Vector>>> tpmap;
+    public TrackXtrapCalPositions()
+    {
+        theTrackXtrapCalPositions = this;
+    }
+    public static TrackXtrapCalPositions instance()
+    {
+        return theTrackXtrapCalPositions;
+    }
+    public void setMap(Map<Track,Map<Calorimeter.CalorimeterType,List<Hep3Vector>>> tmap)
+    {
+        tpmap = tmap;
+    }
+    public Hep3Vector getPosition(Track t,Calorimeter.CalorimeterType ct, int layer)
+    {
+        return tpmap.get(t).get(ct).get(layer);
+    }
+}

lcsim/src/org/lcsim/recon/cluster/mipfinder/trackxtrap
AttachCalorimeterHitsDriver.java added at 1.1
diff -N AttachCalorimeterHitsDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ AttachCalorimeterHitsDriver.java	6 Oct 2010 19:40:42 -0000	1.1
@@ -0,0 +1,83 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.recon.cluster.mipfinder.trackxtrap;
+import org.lcsim.recon.util.*;
+import org.lcsim.util.Driver;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.Track;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.Calorimeter;
+import java.util.*;
+import hep.physics.vec.*;
+import org.lcsim.util.hitmap.HitMap;
+import org.lcsim.geometry.IDDecoder;
+
+/**
+ *
+ * @author cassell
+ */
+public class AttachCalorimeterHitsDriver extends Driver
+{
+    String inputHitMapName;
+    double ncsq;
+    String trackListName;
+    String xtrName;
+    CalorimeterInformation ci;
+    Map<Calorimeter.CalorimeterType,Double> cellsizemap;
+    public AttachCalorimeterHitsDriver(String tracklistname,String hitmapname,String xtname, double ncellcut)
+    {
+        inputHitMapName = hitmapname;
+        ncsq = ncellcut*ncellcut;
+        trackListName = tracklistname;
+        xtrName = xtname;
+    }
+    protected void process(EventHeader event)
+    {
+        if(ci == null)
+        {
+            ci = CalorimeterInformation.instance();
+            cellsizemap = new HashMap<Calorimeter.CalorimeterType,Double>();
+            cellsizemap.put(Calorimeter.CalorimeterType.EM_BARREL, 3.5*3.5);
+            cellsizemap.put(Calorimeter.CalorimeterType.EM_ENDCAP, 3.5*3.5);
+            cellsizemap.put(Calorimeter.CalorimeterType.HAD_BARREL, 10.*10.);
+            cellsizemap.put(Calorimeter.CalorimeterType.HAD_ENDCAP, 10.*10.);
+        }
+        List<TrackXtrapInfo> txil = event.get(TrackXtrapInfo.class,xtrName);
+        TrackXtrapCalPositions txcp = TrackXtrapCalPositions.instance();
+        List<Track> tl = event.get(Track.class,trackListName);
+        HitMap hm = (HitMap) (event.get(inputHitMapName));
+        for(long id:hm.keySet())
+        {
+            IDDecoder idd = hm.get(id).getIDDecoder();
+            Hep3Vector hp = new BasicHep3Vector(hm.get(id).getPosition());
+            idd.setID(id);
+            int lay = idd.getVLayer();
+            Calorimeter.CalorimeterType ct = ((Calorimeter)(idd.getSubdetector())).getCalorimeterType();
+            if(cellsizemap.get(ct) != null)
+            {
+                double dsqcut = ncsq*cellsizemap.get(ct);
+                for(TrackXtrapInfo txi:txil)
+                {
+                    Track t = txi.getTrack();
+                    if(tl.contains(t))
+                    {
+                        Hep3Vector xp = txcp.getPosition(t, ct, lay);
+                        if(xp != null)
+                        {
+                            double dsq = (hp.x()-xp.x())*(hp.x()-xp.x()) +
+                                     (hp.y()-xp.y())*(hp.y()-xp.y()) +
+                                     (hp.z()-xp.z())*(hp.z()-xp.z());
+                            if(dsq < dsqcut)
+                            {
+                                txi.addHit(hm.get(id),ct,lay);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

lcsim/src/org/lcsim/recon/cluster/mipfinder/trackxtrap
TrackXtrapInfo.java added at 1.1
diff -N TrackXtrapInfo.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrackXtrapInfo.java	6 Oct 2010 19:40:42 -0000	1.1
@@ -0,0 +1,75 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.recon.cluster.mipfinder.trackxtrap;
+import java.util.*;
+import org.lcsim.event.Track;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.util.swim.HelixSwimmer;
+import org.lcsim.geometry.Calorimeter;
+
+/**
+ *
+ * @author cassell
+ */
+public class TrackXtrapInfo
+{
+    protected HelixSwimmer hs;
+    protected Track t;
+    protected List<XtrapPosition> xpl;
+    protected Map<XtrapPosition,List<CalorimeterHit>> posToHitsMap;
+    public TrackXtrapInfo()
+    {
+        xpl = new ArrayList<XtrapPosition>();
+    }
+    public TrackXtrapInfo(Track x)
+    {
+        t = x;
+        xpl = new ArrayList<XtrapPosition>();
+    }
+    public TrackXtrapInfo(Track x, HelixSwimmer y)
+    {
+        t = x;
+        hs = y;
+        xpl = new ArrayList<XtrapPosition>();
+    }
+    public void setTrack(Track x){t = x;}
+    public void setSwimmer(HelixSwimmer x){hs = x;}
+    public Track getTrack(){return t;}
+    public HelixSwimmer getSwimmer(){return hs;}
+    public void addPosition(XtrapPosition x){xpl.add(x);}
+    public List<XtrapPosition> getPositions(){return xpl;}
+    public XtrapPosition getPosition(int i)
+    {
+        if(i < xpl.size())return xpl.get(i);
+        return null;
+    }
+    public void sortPositions()
+    {
+        Collections.sort(xpl, new XtrapPositionDSort());
+        posToHitsMap = new HashMap<XtrapPosition,List<CalorimeterHit>>();
+        for(XtrapPosition xp:xpl)
+        {
+            posToHitsMap.put(xp, new ArrayList<CalorimeterHit>());
+        }
+    }
+    public void addHit(CalorimeterHit h, Calorimeter.CalorimeterType ct, int lay)
+    {
+        for(XtrapPosition xp:xpl)
+        {
+            if(xp.getCalorimeterType() == ct)
+            {
+                if(xp.getLayer() == lay)
+                {
+                    posToHitsMap.get(xp).add(h);
+                }
+            }
+        }
+    }
+    public List<CalorimeterHit> getHits(XtrapPosition x)
+    {
+        return posToHitsMap.get(x);
+    }
+}
CVSspam 0.2.8