Commit in hps-java/src/main/java/org/lcsim/hps/users/omoreno on MAIN
SvtPerformance.java+147-2881.5 -> 1.6
Added some plots; cleaned up some old code

hps-java/src/main/java/org/lcsim/hps/users/omoreno
SvtPerformance.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- SvtPerformance.java	30 Jul 2012 06:29:32 -0000	1.5
+++ SvtPerformance.java	24 May 2013 01:54:16 -0000	1.6
@@ -9,19 +9,27 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.lcsim.detector.tracker.silicon.SiSensor;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.Track;
 import org.lcsim.event.TrackerHit;
+import org.lcsim.fit.helicaltrack.HelicalTrackCross;
 import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.fit.helicaltrack.HelicalTrackStrip;
 import org.lcsim.geometry.Detector;
 import org.lcsim.hps.monitoring.AIDAFrame;
 import org.lcsim.hps.recon.ecal.HPSEcalCluster;
+import org.lcsim.hps.recon.tracking.HPSSVTCalibrationConstants;
+import org.lcsim.hps.recon.tracking.HPSSVTCalibrationConstants.ChannelConstants;
+import org.lcsim.hps.recon.tracking.HPSShapeFitParameters;
+import org.lcsim.hps.recon.tracking.HPSShaperAnalyticFitAlgorithm;
 import org.lcsim.hps.recon.tracking.SvtTrackExtrapolator;
 import org.lcsim.hps.recon.tracking.SvtUtils;
 import org.lcsim.hps.recon.tracking.TrackUtils;
+import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHitStrip1D;
 import org.lcsim.recon.tracking.seedtracker.SeedTrack;
 import org.lcsim.util.Driver;
 import org.lcsim.util.aida.AIDA;
@@ -30,50 +38,34 @@
  * Svt Performance Plots
  * 
  * @author Omar Moreno <[log in to unmask]>
- * @version $Id: SvtPerformance.java,v 1.5 2012/07/30 06:29:32 omoreno Exp $
+ * @version $Id: SvtPerformance.java,v 1.6 2013/05/24 01:54:16 omoreno Exp $
  */
 public class SvtPerformance extends Driver {
 
     private AIDA aida;
-    private List<AIDAFrame> frames = new ArrayList<AIDAFrame>();
-    private List<IHistogram1D> histos1D = new ArrayList<IHistogram1D>();
-    private List<IHistogram2D> histos2D = new ArrayList<IHistogram2D>();
     private List<IPlotter> plotters = new ArrayList<IPlotter>();
     TrackUtils trkUtil = new TrackUtils();
     SvtTrackExtrapolator extrapolator = new SvtTrackExtrapolator();
+    HPSShaperAnalyticFitAlgorithm shaperFitter = new HPSShaperAnalyticFitAlgorithm();
 
-    double totalTracksFound = 0;
-    double totalTopTracksFound = 0;
-    double totalBottomTracksFound = 0;
-    double totalNumberEvents = 0;
-    double totalNumberSingleTrkEvents = 0;
-    double possibleTracks = 0;
-    double possibleTopTracks = 0;
-    double possibleBottomTracks = 0;
-    double totalFourHitTracks = 0;
-    double totalTracksWith5LayersHit = 0;
+    String sensorName = null;
+    
     int plotterIndex = 0;
 
+    double totalNumberOfEvents = 0;
     double totalTracks = 0;
     double totalTwoTrackEvents = 0;
-
+    double idealNoise = 886; // e-
+    
     double[] topLayers;
     double[] bottomLayers;
-    Map<Integer, List<HelicalTrackHit>> topLayerMap = new HashMap<Integer, List<HelicalTrackHit>>();
-    Map<Integer, List<HelicalTrackHit>> bottomLayerMap = new HashMap<Integer, List<HelicalTrackHit>>();
     
-    boolean debug = true;
-    boolean enableHitPositionPlots = false;
-
-    // Plot flags
+    boolean debug = false;
 
     // Collection Names
-    private String stereoHitCollectionName = "HelicalTrackHits";
     private String trackCollectionName = "MatchedTracks";
-    private String ecalClustersCollectionName = "EcalClusters";
 
-    public SvtPerformance() {
-    }
+    public SvtPerformance() {}
 
     // --- Setters ---//
     // ---------------//
@@ -85,295 +77,162 @@
         this.debug = debug;
     }
 
-    public void setEnableHitPositionPlots(boolean enableHitPositionPlots) {
-        this.enableHitPositionPlots = enableHitPositionPlots;
+    /**
+     * 
+     */
+    public void setSensorName(String sensorName){
+    	this.sensorName = sensorName;
     }
 
     protected void detectorChanged(Detector detector) {
-
-        // Initialize all maps
-        for(int layer = 1; layer < 6; layer++){
-            topLayerMap.put(layer, new ArrayList<HelicalTrackHit>());
-            bottomLayerMap.put(layer, new ArrayList<HelicalTrackHit>());
-        }
-        
+ 
         // setup AIDA
         aida = AIDA.defaultInstance();
         aida.tree().cd("/");
 
-        // Create AIDA Frames
-        for (int index = 0; index < 2; index++)
-            frames.add(new AIDAFrame());
-
-        // Set frame titles
-        frames.get(0).setTitle("Stereo Hit Positions");
-
+        Set<SiSensor> sensors = SvtUtils.getInstance().getSensors();
+        
         String title = null;
         IHistogram2D histo2D = null;
         IHistogram1D histo1D = null;
-
-        // --- Hit Positions ---//
-        // ---------------------//
-        if (enableHitPositionPlots) {
-            plotters.add(PlotUtils.setupPlotter("Hit Positions", 1, 2));
-            title = "Hit Positions - XZ";
-            histo2D = aida.histogram2D(title, 5, 1, 6, 200, -100, 100);
-            histos2D.add(histo2D);
-            PlotUtils.setup2DRegion(plotters.get(plotterIndex), title, 0, "Layer #", "x [mm]", histo2D);
-            title = "Hit Positions - YZ";
-            histo2D = aida.histogram2D(title, 5, 1, 6, 200, -100, 100);
-            PlotUtils.setup2DRegion(plotters.get(plotterIndex), title, 1, "Layer #", "y [mm]", histo2D);
-
-            frames.get(0).addPlotter(plotters.get(plotterIndex));
-            plotterIndex++;
-            plotters.add(PlotUtils.setupPlotter("Chi Squared", 0, 0));
-            title = "ChiSquared";
-            histo1D = aida.histogram1D("ChiSquared", 50, 0, 50);
-            PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 0, "Chi Squared", histo1D);
-            frames.get(0).addPlotter(plotters.get(plotterIndex));
-        }
-
-        for (AIDAFrame frame : frames) {
-            frame.pack();
-            frame.setVisible(true);
+ 
+        //--- MIP Plots ---//
+        //-----------------//
+        plotters.add(PlotUtils.setupPlotter("Cluster Charge", 5, 4));
+        for(SiSensor sensor : sensors){
+        	title = SvtUtils.getInstance().getDescription(sensor) + " - Cluster Charge";
+        	histo1D = aida.histogram1D(title, 500, 0, 50000);
+        	PlotUtils.setup1DRegion(plotters.get(plotterIndex), title,	PlotUtils.getPlotterRegion(sensor), "Cluster Charge [e-]", histo1D);
         }
-    }
-
-    public void process(EventHeader event) {
-        totalNumberEvents++;
-
-        // Get the list of tracks in the event
-        List<SeedTrack> tracks = event.get(SeedTrack.class, trackCollectionName);
-
-        totalTracks += tracks.size();
-
-        if (tracks.size() == 2) totalTwoTrackEvents++;
-
-        // For now, only look at event which have less than a single track
-        if (tracks.size() >= 2) {
-            if (debug)
-                System.out.println(this.getClass().getSimpleName() + ": Two track event found! Skipping ...!");
-            return;
-        }
-
-        // Increment the event number
-        totalNumberSingleTrkEvents++;
-        this.clearLayers();
+        plotterIndex++;
         
-        // Loop through all HelicalTrackHits and arrange them by layer
-        if (!event.hasCollection(HelicalTrackHit.class, stereoHitCollectionName)){
-            if(tracks.size() != 0) System.out.println("This event has a track but the HelicalTrackHit collection is empty");
-            return;        
-        }
-
-        // Get the list of HelicalTrackHits
-        List<HelicalTrackHit> stereoHits = event.get(HelicalTrackHit.class, stereoHitCollectionName);
-
-        for (HelicalTrackHit stereoHit : stereoHits) {
-            if (debug)
-                System.out.println(this.getClass().getSimpleName() + " : Stereo Hit position = " + stereoHit.getCorrectedPosition().toString());
-
-                // Get the layer associated with the stereoHit
-                int layer = stereoHit.Layer();
-                int mapPosition = ((layer - 1)/2) + 1;
-
-                // Find the detector volume the hit corresponds to - Top or Bottom.
-                // Then "add" the hit to the corresponding layer
-                if (stereoHit.getCorrectedPosition().y() > 0) {
-                    topLayerMap.get(mapPosition).add(stereoHit);
-                    if (debug){
-                        System.out.println(this.getClass().getSimpleName() + " :  Found Top Hit!");
-                        System.out.println(this.getClass().getSimpleName() + " : Layer " + stereoHit.Layer());
-                    }
-                    
-                } else if (stereoHit.getCorrectedPosition().y() < 0) {
-                    bottomLayerMap.get(mapPosition).add(stereoHit);
-                    if (debug){
-                        System.out.println(this.getClass().getSimpleName() + " :  Found Bottom Hit!");
-                        System.out.println(this.getClass().getSimpleName() + " : Layer " + stereoHit.Layer());
-                        System.out.println(this.getClass().getSimpleName() + " : Layer Size: " + bottomLayerMap.get(mapPosition).size());
-                    }
-                } else throw new RuntimeException("Invalid hit position - y = " + stereoHit.y());
-        }
-
-        // Get the list of Ecal Clusters
-        List<HPSEcalCluster> ecalClusters = event.get(HPSEcalCluster.class, ecalClustersCollectionName);
-
-        // Check if there are four consencutive hits on either volume and
-        // that there is an Ecal cluster in the same volume
-        if(!ecalClusters.isEmpty()){
-            if(debug) System.out.println(this.getClass().getSimpleName() + " Ecal Cluster size: " + ecalClusters.size());
-            for(HPSEcalCluster ecalCluster : ecalClusters){
-                if(debug) System.out.println(this.getClass().getSimpleName() + " Cluster Position: [" + ecalCluster.getPosition()[0] + ", " + ecalCluster.getPosition()[1] + ", " + ecalCluster.getPosition()[2]);
-                if(ecalCluster.getPosition()[1] > 0 && this.topHasConsecutiveHits()){
-                    if(debug) System.out.println(this.getClass().getSimpleName() + " : Found Possible Top Track!");
-                    possibleTopTracks++;
-                    possibleTracks++;
-                    break;
-                } else if(ecalCluster.getPosition()[1] < 0 && this.bottomHasConsecutiveHits()){
-                    if(debug) System.out.println(this.getClass().getSimpleName() + " : Found Possible Bottom Track!");
-                    possibleBottomTracks++;
-                    possibleTracks++;
-                    break;
-                } else if(ecalCluster.getPosition()[1] < 0 && this.topHasConsecutiveHits()){
-                    return;
-                }
-                else if(ecalCluster.getPosition()[1] > 0 && this.bottomHasConsecutiveHits()){
-                    return;
-                }
-            }
-        } else if(ecalClusters.isEmpty()){
-            if(debug) System.out.println(this.getClass().getName() + " : No Ecal Clusters Found!");
+        if(sensorName != null){
+        	plotters.add(PlotUtils.setupPlotter("Cluster Charge", 0, 0));	
+        	title = sensorName + " - Cluster Charge";
+        	PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 0, "Cluster Charge [e-]", aida.histogram1D(title));
         }
-
-        // Only continue if an event has a track
-        if (tracks.isEmpty()) {
-            if (debug) System.out.println(this.getClass().getSimpleName() + ": No Tracks Were Found!");
-            return;
+        plotterIndex++; 
+       
+        
+        //-------------------//
+        
+        plotters.add(PlotUtils.setupPlotter("Cluster Charge vs Seed Strip", 5, 4));
+        for(SiSensor sensor : sensors){
+        	title = SvtUtils.getInstance().getDescription(sensor) + " - Cluster Charge vs Seed Strip";
+        	histo2D = aida.histogram2D(title, 640, 0, 639, 500, 0, 50000);
+        	PlotUtils.setup2DRegion(plotters.get(plotterIndex), title, PlotUtils.getPlotterRegion(sensor), "Physical Channel Number", "Cluster Charge [e-]", histo2D);
         }
-
-        if (debug) System.out.println(this.getClass().getSimpleName() + ": Number of Tracks: " + tracks.size());
-
-        if(this.topHasConsecutiveHits() || this.bottomHasConsecutiveHits()){
-            totalTracksFound += tracks.size();
-        } else {
-            if(debug) System.out.println(this.getClass().getName() + ": Track has no helical track associated with it!");
+        plotterIndex++;
+        
+        if(sensorName != null){
+        	plotters.add(PlotUtils.setupPlotter("Cluster Charge vs Seed Strip", 0, 0));
+        	title = sensorName + " - Cluster Charge vs Seed Strip";
+        	PlotUtils.setup2DRegion(plotters.get(plotterIndex), title, 0, "Physical Channel Number", "Cluster Charge [e-]", aida.histogram2D(title));
+        }
+        plotterIndex++;
+         
+        //--- Signal to Noise ---//
+        //-----------------------//
+        plotters.add(PlotUtils.setupPlotter("Signal to Noise", 5, 4));
+        for(SiSensor sensor : sensors){
+        	title = SvtUtils.getInstance().getDescription(sensor) + " - Signal to Noise";
+        	histo1D = aida.histogram1D(title, 25, 0, 50);
+        	PlotUtils.setup1DRegion(plotters.get(plotterIndex), title,	PlotUtils.getPlotterRegion(sensor), "Signal To Noise", histo1D);
         }
-
-        for (SeedTrack track : tracks) {
-            trkUtil.setTrack(track);
-            extrapolator.setTrack(track);
-
-            // Check which volume the track corresponds to
-            if (trkUtil.getZ0() > 0 ) {
-                totalTopTracksFound++;
-                if (debug) System.out.println(this.getClass().getSimpleName() + " : Found Top Track!");
-            } else if (trkUtil.getZ0() < 0 ) {
-                totalBottomTracksFound++;
-                if (debug) System.out.println(this.getClass().getSimpleName() + " : Found Bottom Track!");
-            }
-
-            // Check if the track has four hits associated with it. This should
-            // be the case when
-            // only four hits are used to fit the track
-            
-            if (track.getTrackerHits().size() == 4 && !ecalClusters.isEmpty()) {
-
-                // Get the position of the track at the last Layer
-                Hep3Vector trkPositionAtLayer5 = extrapolator.extrapolateTrack(696.1715 /* mm */);
-
-                if (debug)
-                    System.out.println(this.getClass().getSimpleName() + ": Track Position at Layer 5: "
-                            + trkPositionAtLayer5.toString());
-
-                if (trkPositionAtLayer5.y() < 67/* 69.89656 */&& trkPositionAtLayer5.y() > -27/*-28.73156*/
-                        && trkPositionAtLayer5.z() > 11/* 12.59405 */&& trkPositionAtLayer5.z() < 47/* 50.93395 */) {
-                    
-                    if (trkUtil.getZ0() > 0 && track.getChi2() < 10) {
-                        for (HPSEcalCluster ecalCluster : ecalClusters) {
-                            if (ecalCluster.getPosition()[1] > 0) {
-                                totalFourHitTracks++;
-                        //        if (topLayers[4] > 0)
-                        //            totalTracksWith5LayersHit++;
-                        //        break;
-                            }
-                        }
-                    }
-                    /*
-                     * if(trkUtil.getZ0() > 0 && topLayers[4] > 0 &&
-                     * track.getChi2() < 10){ for(HPSEcalCluster ecalCluster :
-                     * ecalClusters){ if(ecalCluster.getPosition()[1] > 0){
-                     * totalTracksWith5LayersHit++; break; } } }
-                     */
-//                    else if (trkUtil.getZ0() > 0 && topLayers[4] == 0) {
-//                        for (TrackerHit hit : track.getTrackerHits()) {
-//                            HelicalTrackHit hth = (HelicalTrackHit) hit;
-//                            int arrayPosition = (hth.Layer() - 1) / 2;
-                            // String title = "Hit Positions - Layer " +
-                            // String.valueOf(arrayPosition+1);
-                            // String title = "Hit Positions - XZ";
-                            // System.out.println(title);
-                            // aida.histogram2D(title).fill(arrayPosition + 1,
-                            // hth.getCorrectedPosition().y());
-                            // title = "Hit Positions - YZ";
-                            // aida.histogram2D(title).fill(arrayPosition + 1,
-                            // hth.getCorrectedPosition().z());
-//                        }
-//                        aida.histogram1D("ChiSquared").fill(track.getChi2());
-//                    } else if (trkUtil.getZ0() < 0 && bottomLayers[4] > 0) {
-//                        for (HPSEcalCluster ecalCluster : ecalClusters) {
-//                            if (ecalCluster.getPosition()[1] < 0) {
-                                // totalTracksWith5LayersHit++;
-//                                break;
-//                            }
-//                        }
-//                    }
-                }
-            }
+        plotterIndex++;
+        
+        if(sensorName != null){
+        	plotters.add(PlotUtils.setupPlotter("Signal to Noise", 0, 0));
+        	title = sensorName + " - Signal to Noise";
+        	PlotUtils.setup1DRegion(plotters.get(plotterIndex), title, 0, "Signal to Noise", aida.histogram1D(title));
         }
+        plotterIndex++; 
+        
+        // Show the plotters
+        for(IPlotter plotter : plotters) plotter.show();
     }
 
-    private boolean hasConsecutiveHits(double[] layers) {
-        for (int index = 0; index < 2; index++) {
-            if (layers[index] > 0 && layers[index + 1] > 0 && layers[index + 2] > 0 && layers[index + 3] > 0) {
-                return true;
-            }
-        }
+    public void process(EventHeader event) {
+        totalNumberOfEvents++;
 
-        return false;
-    }
-    
-    private boolean topHasConsecutiveHits(){
-        for(int index = 1; index < 3; index++){
-            if(this.getNumberTopLayerHits(index) > 0 &&
-                    this.getNumberTopLayerHits(index + 1) > 0 &&
-                    this.getNumberTopLayerHits(index + 2) > 0 &&
-                    this.getNumberTopLayerHits(index + 3) > 0 ){
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    private boolean bottomHasConsecutiveHits(){
-        for(int index = 1; index < 3; index++){
-            if(this.getNumberBottomLayerHits(index) > 0 &&
-                    this.getNumberBottomLayerHits(index + 1) > 0 &&
-                    this.getNumberBottomLayerHits(index + 2) > 0 &&
-                    this.getNumberBottomLayerHits(index + 3) > 0){
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    private void clearLayers(){
-        for(int layer = 1; layer < 6; layer++){
-            topLayerMap.get(layer).clear();
-            bottomLayerMap.get(layer).clear();
-        }
+        // If the event doesn't have tracks, skip the event
+        if(!event.hasCollection(Track.class, trackCollectionName)) return;
+        List<Track> tracks = event.get(Track.class, trackCollectionName);
+        
+        totalTracks += tracks.size(); 
+        if(tracks.size() == 2) totalTwoTrackEvents++; 
+        
+        String title = null;
+        SiSensor sensor = null;
+        RawTrackerHit rawHit = null;
+        double hitCharge = 0;
+        double totalAdc = 0;
+        double noise = 0; 
+        double ston = 0; 
+        int channel = 0;
+        int maxChannel = 0; 
+        double maxAdc = 0; 
+        double gain = 0; 
+        ChannelConstants constants = null;
+        HPSShapeFitParameters fit = null;
+        
+        // Loop over all tracks in an event
+        for(Track track : tracks){
+        	// Loop over all stereo hits associated with a track
+        	for(TrackerHit trackHit : track.getTrackerHits()){
+        		// Loop over the strip hits used to crate the stereo hit
+        		for(HelicalTrackStrip stripHit : ((HelicalTrackCross) trackHit).getStrips()){
+        			// Loop over all the raw hits used to create the cluster
+        			hitCharge = 0;
+        			totalAdc = 0;
+        			maxAdc = 0; 
+        			for(Object hit : stripHit.rawhits()){
+        				rawHit = (RawTrackerHit) hit; 
+        				sensor = (SiSensor) rawHit.getDetectorElement(); 
+        				channel = rawHit.getIdentifierFieldValue("strip");
+        				constants = HPSSVTCalibrationConstants.getChannelConstants(sensor, channel);
+        				fit = shaperFitter.fitShape(rawHit, constants);
+        				if(fit.getAmp() > maxAdc){
+        					maxChannel = channel; 
+        					maxAdc = fit.getAmp(); 
+        				}
+        				gain = constants.getNoise()/idealNoise;
+        				totalAdc += fit.getAmp();
+        				noise += Math.pow(constants.getNoise(),2);
+        				//hitCharge += fit.getAmp()/HPSSVTCalibrationConstants.getGain(sensor, channel);
+        				hitCharge += fit.getAmp()/gain; 
+        			}
+        			
+        			title = SvtUtils.getInstance().getDescription(sensor) + " - Cluster Charge";
+        			aida.histogram1D(title).fill(hitCharge);
+
+        			title = SvtUtils.getInstance().getDescription(sensor) + " - Cluster Charge vs Seed Strip";
+        			aida.histogram2D(title).fill(maxChannel, hitCharge); 
+        			
+        			noise = Math.sqrt(noise/stripHit.rawhits().size()); 
+        			ston = totalAdc/noise; 
+        			title = SvtUtils.getInstance().getDescription(sensor) + " - Signal to Noise";
+        			aida.histogram1D(title).fill(ston);
+        		}
+        	}
+        } 
     }
+
     
-    private int getNumberTopLayerHits(int layer){
-        return topLayerMap.get(layer).size();
+    /**
+     * print debug statements
+     */
+    public void printDebug(String debugStatement){
+        if(!debug) return;
+        System.out.println(this.getClass().getSimpleName() + ": " + debugStatement);     
     }
     
-    private int getNumberBottomLayerHits(int layer){
-        return bottomLayerMap.get(layer).size();
-    }
-
     @Override
     public void endOfData() {
         System.out.println("%===================================================================% \n");
-        System.out.println("Number of tracks per event: " + (totalTracks/ totalNumberEvents));
-        System.out.println("Number of events with two tracks per event: " + (totalTwoTrackEvents/totalNumberEvents));
-        System.out.println("Total Track Reconstruction Efficiency: " + totalTracksFound + " / " + possibleTracks + " = " + (totalTracksFound / possibleTracks) * 100 + "%");
-        System.out.println("Total Top Track Reconstruction Efficiency: " + totalTopTracksFound + " / " + possibleTopTracks + " = " + (totalTopTracksFound / possibleTopTracks)* 100 + "%");
-        System.out.println("Total Bottom Track Reconstruction Efficiency: " + totalBottomTracksFound + " / " + possibleBottomTracks + " = " + (totalBottomTracksFound / possibleBottomTracks) * 100 + "%");
-        System.out.println("Percentage of 4 hit tracks: " + (totalFourHitTracks / totalTracksFound) * 100 + "%");
-        System.out.println("Hit Efficiency: " + (totalTracksWith5LayersHit / totalFourHitTracks) * 100 + "%");
-//        System.out.println("Percentage of Two Track Events: " + (totalTwoTrackEvents / totalEvents) * 100 + "%");
-        System.out.println("%===================================================================% \n");
+        System.out.println("Number of tracks per event: " + (totalTracks/ totalNumberOfEvents));
+        System.out.println("Number of events with two tracks per event: " + (totalTwoTrackEvents/totalNumberOfEvents));
+        System.out.println("\n%===================================================================% \n");
 
     }
 }
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