Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN
HelicalTrackHitResidualsDriver.java+313added 1.1
Moved to tracking dir

hps-java/src/main/java/org/lcsim/hps/recon/tracking
HelicalTrackHitResidualsDriver.java added at 1.1
diff -N HelicalTrackHitResidualsDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HelicalTrackHitResidualsDriver.java	19 Nov 2012 21:53:42 -0000	1.1
@@ -0,0 +1,313 @@
+package org.lcsim.hps.recon.tracking;
+
+import hep.aida.IDataPointSet;
+import hep.aida.IDataPointSetFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.IPlotter;
+import hep.aida.ref.plotter.PlotterRegion;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.event.*;
+import org.lcsim.fit.helicaltrack.HelicalTrackFit;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.hps.monitoring.AIDAFrame;
+import org.lcsim.hps.recon.tracking.SvtUtils;
+import org.lcsim.hps.recon.tracking.TrackUtils;
+import org.lcsim.hps.users.phansson.TrigRateDriver;
+import org.lcsim.recon.tracking.seedtracker.SeedCandidate;
+import org.lcsim.recon.tracking.seedtracker.SeedTrack;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ *
+ * @author mgraham
+ */
+public class HelicalTrackHitResidualsDriver extends Driver {
+
+    private AIDA aida = AIDA.defaultInstance();
+    int totalTracks=0;
+    int totalTracksProcessed=0;
+    private String outputPlotFileName="";
+    private String trackCollectionName="MatchedTracks";
+    private boolean hideFrame = false;
+    private boolean _debug = false;
+    private TrackUtils _trackUtils = new TrackUtils();
+    
+    private AIDAFrame plotterFrame;
+//    ICloud1D[] _h_resz_track_top = new ICloud1D[5];
+//    ICloud1D[] _h_resz_track_bottom = new ICloud1D[5];
+//    ICloud1D[] _h_resy_track_top = new ICloud1D[5];
+//    ICloud1D[] _h_resy_track_bottom = new ICloud1D[5];
+    IHistogram1D[] _h_resz_track_top = new IHistogram1D[5];
+    IHistogram1D[] _h_resz_track_bottom = new IHistogram1D[5];
+    IHistogram1D[] _h_resy_track_top = new IHistogram1D[5];
+    IHistogram1D[] _h_resy_track_bottom = new IHistogram1D[5];
+    IDataPointSet dps_hth_y_b;
+    IDataPointSet dps_hth_y_t;
+    IDataPointSet dps_hth_z_b;
+    IDataPointSet dps_hth_z_t;
+    IPlotter _plotter_resz_top;
+    IPlotter _plotter_resy_top;
+    IPlotter _plotter_resz_bottom;
+    IPlotter _plotter_resy_bottom;
+    IPlotter _plotter_mean_res;
+    
+       
+    
+    
+    public void setDebug(boolean v) {
+        this._debug = v;
+    }
+    
+    public void setTrackCollectionName(String trackCollectionName) {
+        this.trackCollectionName = trackCollectionName;
+    }
+
+    public void setOutputPlotFileName(String filename) {
+        outputPlotFileName = filename;
+    }
+    
+    public void setHideFrame(boolean hide) {
+        hideFrame = hide;
+    }
+    
+    public HelicalTrackHitResidualsDriver() {
+    
+    }
+    
+
+    
+    @Override
+    public void detectorChanged(Detector detector) {
+        
+        Hep3Vector IP = new BasicHep3Vector(0., 0., 1.);
+        Hep3Vector _bfield = new BasicHep3Vector(0,0,detector.getFieldMap().getField(IP).y());
+
+        makePlots();
+       
+        
+    }
+    
+    
+    
+    @Override
+    public void process(EventHeader event) {
+
+        List<Track> tracklist = new ArrayList<Track>();
+        if(event.hasCollection(Track.class,this.trackCollectionName)) {        
+            tracklist = event.get(Track.class, this.trackCollectionName);
+             if(_debug) {
+                System.out.println(this.getClass().getSimpleName() + ": Number of Tracks = " + tracklist.size());
+             }
+        }
+        
+
+        for (Track track : tracklist) {
+            SeedTrack st = (SeedTrack) track;
+            SeedCandidate seed = st.getSeedCandidate();
+            HelicalTrackFit trk = seed.getHelix();
+            List<TrackerHit> hitsOnTrack = track.getTrackerHits();
+            for(TrackerHit hit : hitsOnTrack) {
+                HelicalTrackHit hth = (HelicalTrackHit) hit;
+                Map<String,Double> res_track = _trackUtils.calculateTrackHitResidual(hth, trk, false);
+                //Map<String,Double> res_trackgen = _trackUtils.calculateTrackHitResidual(hth, trkgen, false);
+                boolean isTop = false;
+                if(SvtUtils.getInstance().isTopLayer((SiSensor)((RawTrackerHit)hth.getRawHits().get(0)).getDetectorElement())) {
+                    isTop = true;
+                }
+                int layer = hth.Layer();
+                if(_debug) System.out.println(this.getClass().getSimpleName() + ": residual for hit at " + hth.toString() + " and layer " + layer);
+                if(layer%2==0) {
+                    System.out.println(this.getClass().getSimpleName() + ": HTH layer is not odd!" + layer);
+                    System.exit(1);
+                }
+                int layer_idx = (layer-1)/2;
+                if(isTop) {
+                    this._h_resz_track_top[layer_idx].fill(res_track.get("resz"));
+                    this._h_resy_track_top[layer_idx].fill(res_track.get("resy"));
+                } else {
+                    this._h_resz_track_bottom[layer_idx].fill(res_track.get("resz"));
+                    this._h_resy_track_bottom[layer_idx].fill(res_track.get("resy"));
+                }
+
+//                if(Math.abs(res_track.get("resy"))>0.02) {
+//                    System.out.println(this.getClass().getSimpleName() + ": this has large y res = " + res_track.get("resy"));
+//                    System.exit(1);
+//                }
+                
+            }
+            
+        }
+        totalTracks++;
+        totalTracksProcessed++;
+
+        
+
+        if(totalTracks%50==0) this.updatePlots();
+
+        
+        
+    }
+
+    public void endOfData() {
+        this.updatePlots();
+        //try {
+            System.out.println(this.getClass().getSimpleName() + ": Total Number of Tracks Found = "+totalTracks);
+            System.out.println(this.getClass().getSimpleName() + ": Total Number of Tracks Processed = "+totalTracksProcessed);
+//        } catch (IOException ex) {
+//            Logger.getLogger(CmpGenToFittedTracksDriver.class.getName()).log(Level.SEVERE, null, ex);
+//        }
+        if (!"".equals(outputPlotFileName))
+        try {
+            aida.saveAs(outputPlotFileName);
+        } catch (IOException ex) {
+            Logger.getLogger(TrigRateDriver.class.getName()).log(Level.SEVERE, "Couldn't save aida plots to file " + outputPlotFileName, ex);
+        }
+        
+    }
+    
+   
+    private void makePlots() {
+        
+        int nbins = 50;
+        double bins_resz_min = -0.2;
+        double bins_resz_max = 0.2;
+        double bins_resy_min = -0.4;
+        double bins_resy_max = 0.4;
+        
+        _plotter_resz_top = aida.analysisFactory().createPlotterFactory().create();
+        _plotter_resz_top.setTitle("res z top");
+        _plotter_resz_top.createRegions(5,1);
+        _plotter_resy_top = aida.analysisFactory().createPlotterFactory().create();
+        _plotter_resy_top.setTitle("res y top");
+        _plotter_resy_top.createRegions(5,1);
+        for(int i=1;i<6;++i) {
+//            _h_resz_track_top[i-1] = aida.cloud1D("h_resz_track_top_layer"+i);
+//            _h_resy_track_top[i-1] = aida.cloud1D("h_resy_track_top_layer"+i);
+            _h_resz_track_top[i-1] = aida.histogram1D("h_resz_track_top_layer"+i,nbins,bins_resz_min,bins_resz_max);
+            _h_resy_track_top[i-1] = aida.histogram1D("h_resy_track_top_layer"+i,nbins,bins_resy_min,bins_resy_max);
+            _plotter_resz_top.region(i-1).plot(_h_resz_track_top[i-1]);
+            _plotter_resy_top.region(i-1).plot(_h_resy_track_top[i-1]);
+        }
+        
+        _plotter_resz_bottom = aida.analysisFactory().createPlotterFactory().create();
+        _plotter_resz_bottom.setTitle("res z bottom");
+        _plotter_resz_bottom.createRegions(5,1);
+        _plotter_resy_bottom = aida.analysisFactory().createPlotterFactory().create();
+        _plotter_resy_bottom.setTitle("res y bottom");
+        _plotter_resy_bottom.createRegions(5,1);
+        for(int i=1;i<6;++i) {
+            _h_resz_track_bottom[i-1] = aida.histogram1D("h_resz_track_bottom_layer"+i,nbins,bins_resz_min,bins_resz_max);
+            _h_resy_track_bottom[i-1] = aida.histogram1D("h_resy_track_bottom_layer"+i,nbins,bins_resy_min,bins_resy_max);
+//            _h_resz_track_bottom[i-1] = aida.cloud1D("h_resz_track_bottom_layer"+i);
+//            _h_resy_track_bottom[i-1] = aida.cloud1D("h_resy_track_bottom_layer"+i);
+            _plotter_resz_bottom.region(i-1).plot(_h_resz_track_bottom[i-1]);
+            _plotter_resy_bottom.region(i-1).plot(_h_resy_track_bottom[i-1]);
+        
+        }
+        
+        _plotter_mean_res = aida.analysisFactory().createPlotterFactory().create();
+        _plotter_mean_res.setTitle("Mean res y");
+        _plotter_mean_res.createRegions(2,2);
+        
+        IDataPointSetFactory dpsf = aida.analysisFactory().createDataPointSetFactory(null);
+        
+        dps_hth_y_b = dpsf.create("dps_hth_y_b", "Mean of y residual bottom",2);
+        dps_hth_y_t = dpsf.create("dps_hth_y_t", "Mean of y residual top",2);
+        _plotter_mean_res.region(1).plot(dps_hth_y_b);
+        _plotter_mean_res.region(0).plot(dps_hth_y_t);
+
+        dps_hth_z_b = dpsf.create("dps_hth_z_b", "Mean of z residual bottom",2);
+        dps_hth_z_t = dpsf.create("dps_hth_z_t", "Mean of z residual top",2);
+        _plotter_mean_res.region(3).plot(dps_hth_z_b);
+        _plotter_mean_res.region(2).plot(dps_hth_z_t);
+
+        ((PlotterRegion)_plotter_mean_res.region(0)).getPlot().setAllowUserInteraction(true);
+        ((PlotterRegion) _plotter_mean_res.region(0)).getPlot().setAllowPopupMenus(true);
+        ((PlotterRegion)_plotter_mean_res.region(1)).getPlot().setAllowUserInteraction(true);
+        ((PlotterRegion) _plotter_mean_res.region(1)).getPlot().setAllowPopupMenus(true);
+        
+        
+        plotterFrame = new AIDAFrame();
+        plotterFrame.setTitle("HTH Residuals");
+        plotterFrame.addPlotter(_plotter_resz_top);
+        plotterFrame.addPlotter(_plotter_resz_bottom);
+        plotterFrame.addPlotter(_plotter_resy_top);
+        plotterFrame.addPlotter(_plotter_resy_bottom);
+        plotterFrame.addPlotter(_plotter_mean_res);
+        plotterFrame.pack();
+        plotterFrame.setVisible(!hideFrame);
+        
+    }
+    
+    
+    void updatePlots() {
+        dps_hth_y_t.clear();
+        dps_hth_z_t.clear();
+        dps_hth_z_b.clear();
+        dps_hth_z_t.clear();
+        
+         for(int i=1;i<6;++i) {
+                
+            double mean = this._h_resy_track_bottom[i-1].mean();
+            double stddev = this._h_resy_track_bottom[i-1].rms();
+            double N =  this._h_resy_track_bottom[i-1].entries();
+            double error = N >0 ? stddev/Math.sqrt(N) : 0; 
+            dps_hth_y_b.addPoint();
+            dps_hth_y_b.point(i-1).coordinate(1).setValue(mean);
+            dps_hth_y_b.point(i-1).coordinate(1).setErrorPlus(error);
+            dps_hth_y_b.point(i-1).coordinate(0).setValue(i);
+            dps_hth_y_b.point(i-1).coordinate(0).setErrorPlus(0);
+            
+            mean = this._h_resy_track_top[i-1].mean();
+            stddev = this._h_resy_track_top[i-1].rms();
+            N =  this._h_resy_track_top[i-1].entries();
+            error = N >0 ? stddev/Math.sqrt(N) : 0; 
+            dps_hth_y_t.addPoint();
+            dps_hth_y_t.point(i-1).coordinate(1).setValue(mean);
+            dps_hth_y_t.point(i-1).coordinate(1).setErrorPlus(error);
+            dps_hth_y_t.point(i-1).coordinate(0).setValue(i);
+            dps_hth_y_t.point(i-1).coordinate(0).setErrorPlus(0);
+            
+            mean = this._h_resz_track_top[i-1].mean();
+            stddev = this._h_resz_track_top[i-1].rms();
+            N =  this._h_resz_track_top[i-1].entries();
+            error = N >0 ? stddev/Math.sqrt(N) : 0; 
+            dps_hth_z_t.addPoint();
+            dps_hth_z_t.point(i-1).coordinate(1).setValue(mean);
+            dps_hth_z_t.point(i-1).coordinate(1).setErrorPlus(error);
+            dps_hth_z_t.point(i-1).coordinate(0).setValue(i);
+            dps_hth_z_t.point(i-1).coordinate(0).setErrorPlus(0);
+
+            mean = this._h_resz_track_bottom[i-1].mean();
+            stddev = this._h_resz_track_bottom[i-1].rms();
+            N =  this._h_resz_track_bottom[i-1].entries();
+            error = N >0 ? stddev/Math.sqrt(N) : 0; 
+            dps_hth_z_b.addPoint();
+            dps_hth_z_b.point(i-1).coordinate(1).setValue(mean);
+            dps_hth_z_b.point(i-1).coordinate(1).setErrorPlus(error);
+            dps_hth_z_b.point(i-1).coordinate(0).setValue(i);
+            dps_hth_z_b.point(i-1).coordinate(0).setErrorPlus(0);
+            
+            
+           
+            
+
+         }
+        
+        
+        
+        
+    }
+    
+    
+}
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1