LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  May 2015

HPS-SVN May 2015

Subject:

r2915 - /java/trunk/users/src/main/java/org/hps/users/omoreno/SvtHitEfficiency.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Wed, 6 May 2015 00:10:27 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (794 lines)

Author: [log in to unmask]
Date: Tue May  5 17:10:19 2015
New Revision: 2915

Log:
Updating this so it can be used with the current geometry. Work in progress.

Modified:
    java/trunk/users/src/main/java/org/hps/users/omoreno/SvtHitEfficiency.java

Modified: java/trunk/users/src/main/java/org/hps/users/omoreno/SvtHitEfficiency.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/omoreno/SvtHitEfficiency.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/omoreno/SvtHitEfficiency.java	Tue May  5 17:10:19 2015
@@ -1,23 +1,24 @@
 package org.hps.users.omoreno;
-
-
-import hep.aida.ICloud2D;
-import hep.aida.IHistogram1D;
-import hep.aida.IHistogram2D;
-import hep.aida.IPlotter;
-import hep.aida.IPlotterStyle;
-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.hps.recon.tracking.TrackUtils;
-import org.hps.recon.tracking.TrackerHitUtils;
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogramFactory;
+import hep.aida.IPlotterFactory;
+import hep.aida.IPlotter;
+import hep.aida.IHistogram1D;
+import hep.aida.ITree;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+
 import org.lcsim.detector.ITransform3D;
+import org.lcsim.detector.converter.compact.subdetector.SvtStereoLayer;
+import org.lcsim.detector.converter.compact.subdetector.HpsTracker2;
 import org.lcsim.detector.solids.Box;
 import org.lcsim.detector.solids.Point3D;
 import org.lcsim.detector.solids.Polygon3D;
@@ -31,7 +32,10 @@
 import org.lcsim.fit.helicaltrack.HelicalTrackHit;
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
-import org.lcsim.util.aida.AIDA;
+
+import org.hps.recon.tracking.TrackUtils;
+import org.hps.recon.tracking.TrackerHitUtils;
+
 
 /**
  * Analysis driver used to calculate the hit efficiency of the SVT.
@@ -41,12 +45,25 @@
  */
 public class SvtHitEfficiency extends Driver {
 
-	private AIDA aida;
-    private List<IHistogram1D> histos1D = new ArrayList<IHistogram1D>();
-    private List<IHistogram2D> histos2D = new ArrayList<IHistogram2D>();
-    private List<IPlotter> plotters = new ArrayList<IPlotter>();
-    private Map<SiSensor, Map<Integer, Hep3Vector>> stripPositions = new HashMap<SiSensor, Map<Integer, Hep3Vector>>(); 
+
+    // Use JFreeChart as the default plotting backend
+    static { 
+        hep.aida.jfree.AnalysisFactory.register();
+    }
+
+    // Plotting
+    ITree tree; 
+    IHistogramFactory histogramFactory; 
+    IPlotterFactory plotterFactory = IAnalysisFactory.create().createPlotterFactory();
+    protected Map<String, IPlotter> plotters = new HashMap<String, IPlotter>(); 
+
+    private Map<String, IHistogram1D> trackMomentumPlots = new HashMap<String, IHistogram1D>(); 
+
+    //private Map<SiSensor, Map<Integer, Hep3Vector>> stripPositions = new HashMap<SiSensor, Map<Integer, Hep3Vector>>(); 
     private List<HpsSiSensor> sensors = null;
+    private Map<Integer, SvtStereoLayer> topStereoLayers = new HashMap<Integer, SvtStereoLayer>();
+    private Map<Integer, SvtStereoLayer> bottomStereoLayers = new HashMap<Integer, SvtStereoLayer>();
+
     TrackerHitUtils trackerHitUtils = new TrackerHitUtils();
     
     boolean debug = false;
@@ -57,8 +74,6 @@
     boolean enableChiSquaredPlots = true;
     boolean enableTrackPositionPlots = true;
     boolean maskBadChannels = false;
-    
-    int plotterIndex = 0;
     
     double numberOfTopTracks = 0;
     double numberOfBottomTracks = 0;
@@ -83,10 +98,22 @@
     public static final double SENSOR_WIDTH = 38.3399; // mm
     private static final String SUBDETECTOR_NAME = "Tracker";
 
-    /**
-     * Default Ctor
+    // By default, require that all tracks have 5 hits
+    int hitsOnTrack = 5;
+
+    /**
+     * Default Constructor
      */
     public SvtHitEfficiency(){
+    }
+
+    /**
+     *  Set the number of stereo hits associated with a track fit.
+     *
+     *  @param hitsOnTrack : Number of stereo hits associated with a track fit.
+     */
+    public void setHitsOnTrack(int hitsOnTrack) { 
+        this.hitsOnTrack = hitsOnTrack;
     }
     
     /**
@@ -100,25 +127,60 @@
      * Enable/Disable masking of bad channels
      */
     public void setMaskBadChannels(boolean maskBadChannels){
-    	this.maskBadChannels = maskBadChannels; 
+        this.maskBadChannels = maskBadChannels; 
     }
     
     public void detectorChanged(Detector detector){
-    	
-    	// Get the list of sensors
-    	sensors = detector.getSubdetector(SUBDETECTOR_NAME).getDetectorElement().findDescendants(HpsSiSensor.class);
-    	
-        // setup AIDA
-        aida = AIDA.defaultInstance();
-        aida.tree().cd("/");
-        
+    
+        tree = IAnalysisFactory.create().createTreeFactory().create();
+        histogramFactory = IAnalysisFactory.create().createHistogramFactory(tree);
+        
+        // Get the HpsSiSensor objects from the tracker detector element
+        sensors = detector.getSubdetector(SUBDETECTOR_NAME)
+                          .getDetectorElement().findDescendants(HpsSiSensor.class);
+   
+        // If the detector element had no sensors associated with it, throw
+        // an exception
+        if (sensors.size() == 0) {
+            throw new RuntimeException("No sensors were found in this detector.");
+        }
+
+        // Get the stereo layers from the geometry and build the stereo
+        // layer maps
+        List<SvtStereoLayer> stereoLayers 
+            = ((HpsTracker2) detector.getSubdetector(SUBDETECTOR_NAME).getDetectorElement()).getStereoPairs();
+        for (SvtStereoLayer stereoLayer : stereoLayers) { 
+            if (stereoLayer.getAxialSensor().isTopLayer()) { 
+                topStereoLayers.put(stereoLayer.getLayerNumber(), stereoLayer);
+            } else { 
+                bottomStereoLayers.put(stereoLayer.getLayerNumber(), stereoLayer);
+            }
+        }
+    
+        /*
         String title = null;
         IHistogram2D histo2D = null;
         IHistogram1D histo1D = null;
         ICloud2D cloud2D = null;
+        */
+
+        if (enableMomentumPlots) { 
+            
+           plotters.put("Track Momentum", plotterFactory.create("Track Momentum"));
+           plotters.get("Track Momentum").createRegions(1, 2);
+
+           trackMomentumPlots.put("Track Momentum", histogramFactory.createHistogram1D("Track Momentum", 50, 0, 5));
+           plotters.get("Track Momentum").region(0).plot(trackMomentumPlots.get("Track Momentum"));
+           
+           trackMomentumPlots.put("Track Momentum - Tracks Within Acceptance",
+                   histogramFactory.createHistogram1D("Track Momentum - Tracks Within Acceptance", 50, 0, 5));
+           plotters.get("Track Momentum").region(0)
+                                         .plot(trackMomentumPlots.get("Track Momentum - Tracks Within Acceptance"));
+        }
 
         // Create a Map from sensor to bad channels and from bad channels to
         // strip position
+        /*
         for(ChargeCarrier carrier : ChargeCarrier.values()){
             for(SiSensor sensor : sensors){ 
                 if(sensor.hasElectrodesOnSide(carrier)){ 
@@ -137,49 +199,34 @@
                     }
                 }
             }
-        }
-        
-        //--- Momentum Plots ---//
-        //----------------------//
-        if(enableMomentumPlots){
-        	plotters.add(PlotUtils.setupPlotter("Track Momentum", 0, 0));
-        	title = "Track Momentum - All Tracks";
-        	histo1D = aida.histogram1D(title, 50, 0, 5);
-        	PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 0, "Momentum [GeV]", histo1D);
-        	title = "Track Momentum - Tracks Within Acceptance";
-        	histo1D = aida.histogram1D(title, 50, 0, 5);
-        	plotters.get(plotterIndex).region(0).plot(histo1D);
-        	title = "Track Momentum - Tracks With All Layers Hit";
-        	histo1D = aida.histogram1D(title, 50, 0, 5);
-        	plotters.get(plotterIndex).region(0).plot(histo1D);
-        	plotterIndex++;
-        }
+        }*/
+        
         
         //--- Track Fit Chi Squared ---//
         //-----------------------------//
-        if(enableChiSquaredPlots){
-        	plotters.add(PlotUtils.setupPlotter("Track Chi Squared", 0, 0));
-        	title = "Chi Squared - All Tracks";
-        	histo1D = aida.histogram1D(title, 50, 0, 50);
-        	PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 0, "Chi Squared", histo1D);
-        	title = "Chi Squared - Tracks Within Acceptance";
-        	histo1D = aida.histogram1D(title, 50, 0, 50);
-        	plotters.get(plotterIndex).region(0).plot(histo1D);
-        	title = "Chi Squared - Tracks With All Layers Hit";
-        	histo1D = aida.histogram1D(title, 50, 0, 50);
-        	plotters.get(plotterIndex).region(0).plot(histo1D);
+        /*if(enableChiSquaredPlots){
+            plotters.add(PlotUtils.setupPlotter("Track Chi Squared", 0, 0));
+            title = "Chi Squared - All Tracks";
+            histo1D = aida.histogram1D(title, 50, 0, 50);
+            PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 0, "Chi Squared", histo1D);
+            title = "Chi Squared - Tracks Within Acceptance";
+            histo1D = aida.histogram1D(title, 50, 0, 50);
+            plotters.get(plotterIndex).region(0).plot(histo1D);
+            title = "Chi Squared - Tracks With All Layers Hit";
+            histo1D = aida.histogram1D(title, 50, 0, 50);
+            plotters.get(plotterIndex).region(0).plot(histo1D);
             plotterIndex++;
-        }
+        }*/
                 
         //--- Track Position Plots ---//
         //----------------------------//
-        if(enableTrackPositionPlots){
-        	int layerNumber = 1; 
-        	SiSensor sensor = null;
-        	IPlotterStyle style = aida.analysisFactory().createPlotterFactory().createPlotterStyle();
+        /*if(enableTrackPositionPlots){
+            int layerNumber = 1; 
+            SiSensor sensor = null;
+            IPlotterStyle style = aida.analysisFactory().createPlotterFactory().createPlotterStyle();
             for(int index = 1; index < 6; index++){
                 plotters.add(PlotUtils.setupPlotter("Track Position - Layer " + index, 2, 3));
-            	title = "Track Position - Layer " + index + " - Tracks Within Acceptance";
+                title = "Track Position - Layer " + index + " - Tracks Within Acceptance";
                 cloud2D = aida.cloud2D(title);
                 PlotUtils.setup2DRegion(plotters.get(plotterIndex), title, 0, "x [mm]", "y [mm]", cloud2D, style);
                 title = "Track Position - Layer " + index + " - Tracks With All Layers Hit";
@@ -191,6 +238,7 @@
                 //sensor = SvtUtils.getInstance().getBottomSensor(layerNumber, 0);
                 //title = SvtUtils.getInstance().getDescription(sensor) + " - Occupancy";
                 histo1D = aida.histogram1D(title, 640, 0, 639);
+    
                 histos1D.add(histo1D);
                 PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 2, "Channel #", histo1D);
                 //sensor = SvtUtils.getInstance().getTopSensor(layerNumber, 0);
@@ -212,9 +260,9 @@
                 layerNumber++;
                 plotterIndex++;
             }
-        }
-        
-        for (IPlotter plotter : plotters) {
+        }*/
+       
+        for (IPlotter plotter : plotters.values()) { 
             plotter.show();
         }
     }
@@ -222,9 +270,9 @@
     /**
      * .
      */
-    private Hep3Vector getStripPosition(SiSensor sensor, int physicalChannel){ 
+   /* private Hep3Vector getStripPosition(SiSensor sensor, int physicalChannel){ 
         return stripPositions.get(sensor).get(physicalChannel);
-    }
+    }*/
 
     /**
      * Print a debug message if they are enabled.
@@ -251,140 +299,153 @@
         //List<Cluster> ecalClusters = event.get(Cluster.class, ecalClustersCollectionName);
 
         for(Track track : tracks){
-        	
-            ecalClusterTrackMatch = false;
-        	
+          
+            // Check that the track has the required number of hits.  The number of hits
+            // required to make a track is set in the tracking strategy.
+            if(track.getTrackerHits().size() != this.hitsOnTrack){
+                System.out.println("This track doesn't have the required number of hits.");
+                continue;
+            }
+           
+            // Calculate the momentum of the track
+            double momentum = (new BasicHep3Vector(track.getTrackStates().get(0).getMomentum())).magnitude();
+
+            if (enableMomentumPlots) {
+                trackMomentumPlots.get("Track Momentum").fill(momentum); 
+            }
+
+            // Find which of the layers isn't being used in the track fit
+            int unusedLayer = this.getUnusedSvtLayer(track.getTrackerHits());
+
+            // Extrapolate the track to the unused layer and check that it lies
+            // within the acceptance of that layer.  If it doesn't, move on
+            // to the next event
+            if(!isWithinAcceptance(track, unusedLayer)) continue;
+
+            if (enableMomentumPlots) { 
+                trackMomentumPlots.get("Track Momentum - Tracks Within Acceptance").fill(momentum); 
+            }
+            //ecalClusterTrackMatch = false;
+            
             // Check if there is an Ecal cluster in the same detector volume as the track
-        	/*for(Cluster ecalCluster : ecalClusters){
-        		if(ecalCluster.getPosition()[1] > 0 && trkUtil.getZ0() > 0){
-        			ecalClusterTrackMatch = true;
-        			break;
-        		}
-        		else if(ecalCluster.getPosition()[1] < 0 && trkUtil.getZ0() < 0){
-        			ecalClusterTrackMatch = true;
-        			break;
-        		}
-        	}*/
-        	
-        	/*
-        	if(!ecalClusterTrackMatch){
-        		if(debug) System.out.println(this.getClass().getSimpleName() + ": No matching Ecal cluster found");
-        		continue;
-        	}*/
-            
-            // Check that the track is associated with four hits only. This should
-            // be the case since the strategy is only requiring four hits to fit
-            // a track and is not requiring an extending layer
-            if(track.getTrackerHits().size() != 4){
-                System.out.println(this.getClass().getSimpleName() + ": This track is composed of " + track.getTrackerHits().size() + ". Skipping event..." );
+            /*for(Cluster ecalCluster : ecalClusters){
+                if(ecalCluster.getPosition()[1] > 0 && trkUtil.getZ0() > 0){
+                    ecalClusterTrackMatch = true;
+                    break;
+                }
+                else if(ecalCluster.getPosition()[1] < 0 && trkUtil.getZ0() < 0){
+                    ecalClusterTrackMatch = true;
+                    break;
+                }
+            }*/
+            
+            /*
+            if(!ecalClusterTrackMatch){
+                if(debug) System.out.println(this.getClass().getSimpleName() + ": No matching Ecal cluster found");
                 continue;
-            }
-            
-        	// Apply a momentum cut? Probably ...
-        	// Calculate the track momentum
-        	double momentum = Math.sqrt(track.getTrackStates().get(0).getMomentum()[0]*track.getTrackStates().get(0).getMomentum()[0] + track.getTrackStates().get(0).getMomentum()[1]*track.getTrackStates().get(0).getMomentum()[1] + track.getTrackStates().get(0).getMomentum()[2]*track.getTrackStates().get(0).getMomentum()[2]);
-        	if(momentum < 0.5 /* GeV */) continue;
-        	if(enableMomentumPlots)
-        		aida.histogram1D("Track Momentum - All Tracks").fill(momentum);
-            
-        	if(enableChiSquaredPlots)
-        		aida.histogram1D("Chi Squared - All Tracks").fill(track.getChi2());
-        	
-            // Find which layer is not being used to fit the track
-            int layer = this.findMissingFitLayer(track.getTrackerHits());
-        	int arrayPosition = (layer - 1)/2;
-            
-        	// Find if the track is within the acceptance of the layer not being used in
-            // the fit
-            if(!isWithinAcceptance(track, layer)) continue;
-            if(TrackUtils.getZ0(track) > 0){
-            	numberOfTopTracks++;
-            	topTracksPerMissingLayer[arrayPosition]++;
-            } else {
-            	numberOfBottomTracks++;
-            	bottomTracksPerMissingLayer[arrayPosition]++;
-            }
-
-            if(enableMomentumPlots)
-    			aida.histogram1D("Track Momentum - Tracks Within Acceptance").fill(momentum);
-    		if(enableChiSquaredPlots)
-    			aida.histogram1D("Chi Squared - Tracks Within Acceptance").fill(track.getChi2());
-    		
+            }*/
+            
+            
+            //int arrayPosition = (layer - 1)/2;
+            
+            //if(TrackUtils.getZ0(track) > 0){
+                //numberOfTopTracks++;
+                //topTracksPerMissingLayer[arrayPosition]++;
+            //} else {
+                //numberOfBottomTracks++;
+                //bottomTracksPerMissingLayer[arrayPosition]++;
+            //}
+
+            //if(enableChiSquaredPlots)
+            //    aida.histogram1D("Chi Squared - Tracks Within Acceptance").fill(track.getChi2());
+            
             // Find if there is a stereo hit within that layer
-            List<HelicalTrackHit> stereoHits = event.get(HelicalTrackHit.class, stereoHitCollectionName);
+            /*List<HelicalTrackHit> stereoHits = event.get(HelicalTrackHit.class, stereoHitCollectionName);
             for(HelicalTrackHit stereoHit : stereoHits){
-            	if(layer == stereoHit.Layer()){
-            		if(debug) System.out.println(this.getClass().getSimpleName() + ": Track has five layers hit");
-            		if(TrackUtils.getZ0(track) > 0){
-            			numberOfTopTracksWithHitOnMissingLayer++;
-            			topTracksWithHitOnMissingLayer[arrayPosition]++;
-            		} else {
-            			numberOfBottomTracksWithHitOnMissingLayer++;
-            			bottomTracksWithHitOnMissingLayer[arrayPosition]++;
-            		}
-            		if(enableMomentumPlots)
-            			aida.histogram1D("Track Momentum - Tracks With All Layers Hit").fill(momentum);
-            		if(enableChiSquaredPlots)
-            			aida.histogram1D("Chi Squared - Tracks With All Layers Hit").fill(track.getChi2());
-            		
-            		return;
-            	}
-            }
-            
-	      	int layerNumber = (layer - 1)/2 + 1;
-    		if(enableTrackPositionPlots){
-            	String title = "Track Position - Layer " + layerNumber + " - Difference";
-            	//aida.histogram2D(title).fill(trackPos.y(), trackPos.z());
+                if(layer == stereoHit.Layer()){
+                    if(debug) System.out.println(this.getClass().getSimpleName() + ": Track has five layers hit");
+                    if(TrackUtils.getZ0(track) > 0){
+                        numberOfTopTracksWithHitOnMissingLayer++;
+                        topTracksWithHitOnMissingLayer[arrayPosition]++;
+                    } else {
+                        numberOfBottomTracksWithHitOnMissingLayer++;
+                        bottomTracksWithHitOnMissingLayer[arrayPosition]++;
+                    }
+                    if(enableMomentumPlots)
+                        aida.histogram1D("Track Momentum - Tracks With All Layers Hit").fill(momentum);
+                    if(enableChiSquaredPlots)
+                        aida.histogram1D("Chi Squared - Tracks With All Layers Hit").fill(track.getChi2());
+                    
+                    return;
+                }
+            }*/
+            
+            /*int layerNumber = (layer - 1)/2 + 1;
+            if(enableTrackPositionPlots){
+                String title = "Track Position - Layer " + layerNumber + " - Difference";
+                //aida.histogram2D(title).fill(trackPos.y(), trackPos.z());
                 aida.cloud2D(title).fill(frontTrackPos.y(), frontTrackPos.z());
 
                 title = "Track Position - Layer " + layerNumber + " - Tracks With All Layers Hit";
                 //aida.histogram2D(title).fill(trackPos.y(), trackPos.z());
                 aida.cloud2D(title).fill(frontTrackPos.y(), frontTrackPos.z());
             }
-    		
-    		List<SiSensor> sensors = new ArrayList<SiSensor>();
-    		if(TrackUtils.getZ0(track) > 0){
-    			//sensors.add(SvtUtils.getInstance().getTopSensor(layer, 0));
-        		//sensors.add(SvtUtils.getInstance().getTopSensor(layer+1, 0));
-    		} else { 
-    			//sensors.add(SvtUtils.getInstance().getBottomSensor(layer, 0));
-        		//sensors.add(SvtUtils.getInstance().getBottomSensor(layer+1, 0));
-    		}
-    		//aida.histogram1D(SvtUtils.getInstance().getDescription(sensors.get(0)) + " - Occupancy").fill(this.findIntersectingChannel(frontTrackPos, sensors.get(0)));
+            
+            List<SiSensor> sensors = new ArrayList<SiSensor>();
+            if(TrackUtils.getZ0(track) > 0){
+                //sensors.add(SvtUtils.getInstance().getTopSensor(layer, 0));
+                //sensors.add(SvtUtils.getInstance().getTopSensor(layer+1, 0));
+            } else { 
+                //sensors.add(SvtUtils.getInstance().getBottomSensor(layer, 0));
+                //sensors.add(SvtUtils.getInstance().getBottomSensor(layer+1, 0));
+            }
+            //aida.histogram1D(SvtUtils.getInstance().getDescription(sensors.get(0)) + " - Occupancy").fill(this.findIntersectingChannel(frontTrackPos, sensors.get(0)));
             //aida.histogram1D(SvtUtils.getInstance().getDescription(sensors.get(1)) + " - Occupancy").fill(this.findIntersectingChannel(rearTrackPos, sensors.get(1)));
-    		
+            
            if(debug)
-        	   System.out.println(this.getClass().getSimpleName() + ": Stereo hit was not found.");
-        }
-    }
-    
-    private int findMissingFitLayer(List<TrackerHit> trkHits){
-        int[] layer = new int[5];
-        for(TrackerHit trkHit : trkHits){
-            HelicalTrackHit stereoHit = (HelicalTrackHit) trkHit;
-            int arrayPosition = (stereoHit.Layer() - 1)/2;
-            layer[arrayPosition]++;
-        }
-        
-        for(int index = 0; index < layer.length; index++){
-            if(layer[index] == 0) return (2*index + 1);
+               System.out.println(this.getClass().getSimpleName() + ": Stereo hit was not found.");*/
+        }
+    }
+    
+    /**
+     *  Find which of the layers is not being used in the track fit
+     *
+     *  @param hits : List of stereo hits associated with a track
+     *  @return Layer not used in the track fit
+     */
+    private int getUnusedSvtLayer(List<TrackerHit> hits) {
+        
+        int[] svtLayer = new int[6];
+        for (TrackerHit hit : hits) {
+            HelicalTrackHit stereoHit = (HelicalTrackHit) hit;
+            int  layer = (stereoHit.Layer() - 1)/2;
+            svtLayer[layer]++;
+        }
+        
+        for(int layer = 0; layer < svtLayer.length; layer++){
+            if(svtLayer[layer] == 0) return (2*layer + 1);
         }
         
         return -1;
     }
-    
-    private boolean isWithinAcceptance(Track track, int layer){
-        
-        
-        
+   
+    /**
+     *  Check if a track lies within the acceptance of a layer.
+     *
+     */
+    // TODO: Move this to a utility class 
+    private boolean isWithinAcceptance(Track track, int layer) {
+       
+        
+
         List<HpsSiSensor> sensors = new ArrayList<HpsSiSensor>();
-        if(TrackUtils.getZ0(track) > 0){
+        /*if(TrackUtils.getZ0(track) > 0){
            //sensors.add(SvtUtils.getInstance().getTopSensor(layer, 0));
            //sensors.add(SvtUtils.getInstance().getTopSensor(layer + 1, 0));
         } else {
            //sensors.add(SvtUtils.getInstance().getBottomSensor(layer, 0));
            //sensors.add(SvtUtils.getInstance().getBottomSensor(layer + 1, 0));
-        }
+        }*/
         
         Hep3Vector frontSensorPos = sensors.get(0).getGeometry().getPosition();
         Hep3Vector rearSensorPos = sensors.get(1).getGeometry().getPosition();
@@ -393,14 +454,14 @@
         this.rearTrackPos = TrackUtils.extrapolateTrack(track,rearSensorPos.z());
         
         if(this.sensorContainsTrack(frontTrackPos, sensors.get(0)) && this.sensorContainsTrack(rearTrackPos, sensors.get(1))){
-//        	if(this.sensorContainsTrack(trackPos, sensor))
-	      	if(enableTrackPositionPlots){
-	      		int layerNumber = (layer - 1)/2 + 1;
-	      		String title = "Track Position - Layer " + layerNumber + " - Tracks Within Acceptance";
-	      		//aida.histogram2D(title).fill(trackPos.y(), trackPos.z());
-	      		aida.cloud2D(title).fill(frontTrackPos.y(), frontTrackPos.z());
-	      	}
-        	return true;
+//          if(this.sensorContainsTrack(trackPos, sensor))
+            if(enableTrackPositionPlots){
+                int layerNumber = (layer - 1)/2 + 1;
+                String title = "Track Position - Layer " + layerNumber + " - Tracks Within Acceptance";
+                //aida.histogram2D(title).fill(trackPos.y(), trackPos.z());
+                //aida.cloud2D(title).fill(frontTrackPos.y(), frontTrackPos.z());
+            }
+            return true;
         } 
         
         
@@ -411,35 +472,35 @@
      * 
      */
     public int findIntersectingChannel(Hep3Vector trackPosition, SiSensor sensor){
-		
-    	//--- Check that the track doesn't pass through a region of bad channels ---//
-		//--------------------------------------------------------------------------//
-    
-		//Rotate the track position to the JLab coordinate system
-		this.printDebug("Track position in tracking frame: " + trackPosition.toString());
-		Hep3Vector trackPositionDet = VecOp.mult(VecOp.inverse(this.trackerHitUtils.detToTrackRotationMatrix()), trackPosition);
-		this.printDebug("Track position in JLab frame " + trackPositionDet.toString());
-		// Rotate the track to the sensor coordinates
-		ITransform3D globalToLocal = sensor.getReadoutElectrodes(ChargeCarrier.HOLE).getGlobalToLocal();
-		globalToLocal.transform(trackPositionDet);
-		this.printDebug("Track position in sensor electrodes frame " + trackPositionDet.toString());
-
-		// Find the closest channel to the track position
-		double deltaY = Double.MAX_VALUE;
-		int intersectingChannel = 0;
-		for(int physicalChannel= 0; physicalChannel < 639; physicalChannel++){ 
-			/*this.printDebug(SvtUtils.getInstance().getDescription(sensor) + " : Channel " + physicalChannel 
-                	+ " : Strip Position " + stripPositions.get(sensor).get(physicalChannel));
-        	this.printDebug(SvtUtils.getInstance().getDescription(sensor) + ": Channel " + physicalChannel
-                	+ " : Delta Y: " + Math.abs(trackPositionDet.x() - stripPositions.get(sensor).get(physicalChannel).x()));*/
-			if(Math.abs(trackPositionDet.x() - stripPositions.get(sensor).get(physicalChannel).x()) < deltaY ){
-				deltaY = Math.abs(trackPositionDet.x() - stripPositions.get(sensor).get(physicalChannel).x()); 
-				intersectingChannel = physicalChannel;
-			}
-		}
-    
-		
-		return intersectingChannel;
+        
+        //--- Check that the track doesn't pass through a region of bad channels ---//
+        //--------------------------------------------------------------------------//
+    
+        //Rotate the track position to the JLab coordinate system
+        this.printDebug("Track position in tracking frame: " + trackPosition.toString());
+        Hep3Vector trackPositionDet = VecOp.mult(VecOp.inverse(this.trackerHitUtils.detToTrackRotationMatrix()), trackPosition);
+        this.printDebug("Track position in JLab frame " + trackPositionDet.toString());
+        // Rotate the track to the sensor coordinates
+        ITransform3D globalToLocal = sensor.getReadoutElectrodes(ChargeCarrier.HOLE).getGlobalToLocal();
+        globalToLocal.transform(trackPositionDet);
+        this.printDebug("Track position in sensor electrodes frame " + trackPositionDet.toString());
+
+        // Find the closest channel to the track position
+        double deltaY = Double.MAX_VALUE;
+        int intersectingChannel = 0;
+        for(int physicalChannel= 0; physicalChannel < 639; physicalChannel++){ 
+            /*this.printDebug(SvtUtils.getInstance().getDescription(sensor) + " : Channel " + physicalChannel 
+                    + " : Strip Position " + stripPositions.get(sensor).get(physicalChannel));
+            this.printDebug(SvtUtils.getInstance().getDescription(sensor) + ": Channel " + physicalChannel
+                    + " : Delta Y: " + Math.abs(trackPositionDet.x() - stripPositions.get(sensor).get(physicalChannel).x()));*/
+            /*if(Math.abs(trackPositionDet.x() - stripPositions.get(sensor).get(physicalChannel).x()) < deltaY ){
+                deltaY = Math.abs(trackPositionDet.x() - stripPositions.get(sensor).get(physicalChannel).x()); 
+                intersectingChannel = physicalChannel;
+            }*/
+        }
+    
+        
+        return intersectingChannel;
     }
 
     /**
@@ -447,64 +508,64 @@
      */
     public boolean sensorContainsTrack(Hep3Vector trackPosition, HpsSiSensor sensor){
 
-    	
-    	if(maskBadChannels){
-    		int intersectingChannel = this.findIntersectingChannel(trackPosition, sensor);
-    		if(intersectingChannel == 0 || intersectingChannel == 638) return false;
-    	    
-    		if(sensor.isBadChannel(intersectingChannel) 
-    				|| sensor.isBadChannel(intersectingChannel+1) 
-    				|| sensor.isBadChannel(intersectingChannel-1)){
-    			this.printDebug("Track intersects a bad channel!");
-    			return false;
-    		}
-    	}
+        
+        if(maskBadChannels){
+            int intersectingChannel = this.findIntersectingChannel(trackPosition, sensor);
+            if(intersectingChannel == 0 || intersectingChannel == 638) return false;
+            
+            if(sensor.isBadChannel(intersectingChannel) 
+                    || sensor.isBadChannel(intersectingChannel+1) 
+                    || sensor.isBadChannel(intersectingChannel-1)){
+                this.printDebug("Track intersects a bad channel!");
+                return false;
+            }
+        }
         
         ITransform3D localToGlobal = sensor.getGeometry().getLocalToGlobal();
-    	
+        
         Hep3Vector sensorPos = sensor.getGeometry().getPosition();   
         Box sensorSolid = (Box) sensor.getGeometry().getLogicalVolume().getSolid();
         Polygon3D sensorFace = sensorSolid.getFacesNormalTo(new BasicHep3Vector(0, 0, 1)).get(0);
         
         List<Point3D> vertices = new ArrayList<Point3D>();
         for(int index = 0; index < 4; index++){
-        	vertices.add(new Point3D());
+            vertices.add(new Point3D());
         }
         for(Point3D vertex : sensorFace.getVertices()){
             if(vertex.y() < 0 && vertex.x() > 0){
-            	localToGlobal.transform(vertex);
+                localToGlobal.transform(vertex);
                 //vertices.set(0, new Point3D(vertex.y() + sensorPos.x(), vertex.x() + sensorPos.y(), vertex.z() + sensorPos.z()));
-            	vertices.set(0, new Point3D(vertex.x(), vertex.y(), vertex.z()));
+                vertices.set(0, new Point3D(vertex.x(), vertex.y(), vertex.z()));
                 if(debug){
-                	System.out.println(this.getClass().getSimpleName() + ": Vertex 1 Position: " + vertices.get(0).toString());
-                	//System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 1 Position: " + localToGlobal.transformed(vertex).toString());
+                    System.out.println(this.getClass().getSimpleName() + ": Vertex 1 Position: " + vertices.get(0).toString());
+                    //System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 1 Position: " + localToGlobal.transformed(vertex).toString());
                 }
             } 
             else if(vertex.y() > 0 && vertex.x() > 0){
-            	localToGlobal.transform(vertex);
+                localToGlobal.transform(vertex);
                 //vertices.set(1, new Point3D(vertex.y() + sensorPos.x(), vertex.x() + sensorPos.y(), vertex.z() + sensorPos.z()));
                 vertices.set(1, new Point3D(vertex.x(), vertex.y(), vertex.z()));
                 if(debug){
                 System.out.println(this.getClass().getSimpleName() + ": Vertex 2 Position: " + vertices.get(1).toString());
-            	//System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 2 Position: " + localToGlobal.transformed(vertex).toString());
+                //System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 2 Position: " + localToGlobal.transformed(vertex).toString());
                 }
             } 
             else if(vertex.y() > 0 && vertex.x() < 0){
-            	localToGlobal.transform(vertex);
+                localToGlobal.transform(vertex);
                 //vertices.set(2, new Point3D(vertex.y() + sensorPos.x(), vertex.x() + sensorPos.y(), vertex.z() + sensorPos.z()));
                 vertices.set(2, new Point3D(vertex.x(), vertex.y(), vertex.z()));
                 if(debug){
                 System.out.println(this.getClass().getSimpleName() + ": Vertex 3 Position: " + vertices.get(2).toString());
-            	//System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 3 Position: " + localToGlobal.transformed(vertex).toString());
-            	}
+                //System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 3 Position: " + localToGlobal.transformed(vertex).toString());
+                }
             }             
             else if(vertex.y() < 0 && vertex.x() < 0){
-            	localToGlobal.transform(vertex);
+                localToGlobal.transform(vertex);
                 //vertices.set(3, new Point3D(vertex.y() + sensorPos.x(), vertex.x() + sensorPos.y(), vertex.z() + sensorPos.z()));
                 vertices.set(3, new Point3D(vertex.x(), vertex.y(), vertex.z()));
                 if(debug){
                 System.out.println(this.getClass().getSimpleName() + ": Vertex 4 Position: " + vertices.get(3).toString());
-            	//System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 4 Position: " + localToGlobal.transformed(vertex).toString());
+                //System.out.println(this.getClass().getSimpleName() + ": Transformed Vertex 4 Position: " + localToGlobal.transformed(vertex).toString());
                 }
             } 
         }
@@ -531,30 +592,30 @@
         System.out.println("%======================  Hit Efficiencies ==========================%");
         System.out.println("%===================================================================% \n%");
         if(numberOfTopTracks > 0){
-        	double topEfficiency = numberOfTopTracksWithHitOnMissingLayer/numberOfTopTracks;
-        	System.out.println("% Top Hit Efficiency: " + numberOfTopTracksWithHitOnMissingLayer + "/" + 
-        						numberOfTopTracks + " = " + topEfficiency*100 + "%");
-        	System.out.println("% Top Hit Efficiency Error: sigma poisson = " 
-        						+ topEfficiency*Math.sqrt((1/numberOfTopTracksWithHitOnMissingLayer) + (1/numberOfTopTracks))*100 + "%");
-        	System.out.println("% Top Hit Efficiency Error: sigma binomial = " 
-        						+ (1/numberOfTopTracks)*Math.sqrt(numberOfTopTracksWithHitOnMissingLayer*(1-topEfficiency))*100 + "%");
+            double topEfficiency = numberOfTopTracksWithHitOnMissingLayer/numberOfTopTracks;
+            System.out.println("% Top Hit Efficiency: " + numberOfTopTracksWithHitOnMissingLayer + "/" + 
+                                numberOfTopTracks + " = " + topEfficiency*100 + "%");
+            System.out.println("% Top Hit Efficiency Error: sigma poisson = " 
+                                + topEfficiency*Math.sqrt((1/numberOfTopTracksWithHitOnMissingLayer) + (1/numberOfTopTracks))*100 + "%");
+            System.out.println("% Top Hit Efficiency Error: sigma binomial = " 
+                                + (1/numberOfTopTracks)*Math.sqrt(numberOfTopTracksWithHitOnMissingLayer*(1-topEfficiency))*100 + "%");
         }
         if(numberOfBottomTracks > 0){
-        	double bottomEfficiency = numberOfBottomTracksWithHitOnMissingLayer/numberOfBottomTracks;
-        	System.out.println("% Bottom Hit Efficiency: " + numberOfBottomTracksWithHitOnMissingLayer + "/" 
-        						+ numberOfBottomTracks + " = " + bottomEfficiency*100 + "%");
-        	System.out.println("% Bottom Hit Efficiency Error: sigma poisson= " 
-        						+ bottomEfficiency*Math.sqrt((1/numberOfBottomTracksWithHitOnMissingLayer) + (1/numberOfBottomTracks))*100 + "%");
-        	System.out.println("% Top Hit Efficiency Error: sigma binomial = " 
-								+ (1/numberOfBottomTracks)*Math.sqrt(numberOfBottomTracksWithHitOnMissingLayer*(1-bottomEfficiency))*100 + "%");
+            double bottomEfficiency = numberOfBottomTracksWithHitOnMissingLayer/numberOfBottomTracks;
+            System.out.println("% Bottom Hit Efficiency: " + numberOfBottomTracksWithHitOnMissingLayer + "/" 
+                                + numberOfBottomTracks + " = " + bottomEfficiency*100 + "%");
+            System.out.println("% Bottom Hit Efficiency Error: sigma poisson= " 
+                                + bottomEfficiency*Math.sqrt((1/numberOfBottomTracksWithHitOnMissingLayer) + (1/numberOfBottomTracks))*100 + "%");
+            System.out.println("% Top Hit Efficiency Error: sigma binomial = " 
+                                + (1/numberOfBottomTracks)*Math.sqrt(numberOfBottomTracksWithHitOnMissingLayer*(1-bottomEfficiency))*100 + "%");
         }
 /*        for(int index = 0; index < topTracksWithHitOnMissingLayer.length; index++){
-        	if(topTracksPerMissingLayer[index] > 0)
-        		System.out.println("% Top Layer " + (index+1) + ": " + (topTracksWithHitOnMissingLayer[index]/topTracksPerMissingLayer[index])*100 + "%");
+            if(topTracksPerMissingLayer[index] > 0)
+                System.out.println("% Top Layer " + (index+1) + ": " + (topTracksWithHitOnMissingLayer[index]/topTracksPerMissingLayer[index])*100 + "%");
         }
         for(int index = 0; index < bottomTracksWithHitOnMissingLayer.length; index++){
-        	if(bottomTracksPerMissingLayer[index] > 0)
-        		System.out.println("% Bottom Layer " + (index+1) + ": " + (bottomTracksWithHitOnMissingLayer[index]/bottomTracksPerMissingLayer[index])*100 + "%");
+            if(bottomTracksPerMissingLayer[index] > 0)
+                System.out.println("% Bottom Layer " + (index+1) + ": " + (bottomTracksWithHitOnMissingLayer[index]/bottomTracksPerMissingLayer[index])*100 + "%");
         }*/
         System.out.println("% \n%===================================================================%");
     }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use