Commit in hps-java/src/main/java/org/lcsim/hps/users/omoreno on MAIN | |||
SvtPerformance.java | +209 | -137 | 1.7 -> 1.8 |
Added some plots; Output some parameters to a text file
diff -u -r1.7 -r1.8 --- SvtPerformance.java 14 Oct 2013 22:58:03 -0000 1.7 +++ SvtPerformance.java 31 Oct 2013 21:54:04 -0000 1.8 @@ -1,60 +1,70 @@
package org.lcsim.hps.users.omoreno; import hep.aida.IHistogram1D;
-import hep.aida.IHistogram2D;
import hep.aida.IPlotter;
+import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException;
import java.util.ArrayList; import java.util.List;
-import java.util.Set;
-import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.detector.tracker.silicon.HpsSiSensor;
+import org.lcsim.geometry.Detector;
+
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.HelicalTrackStrip;
-import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver; +import org.lcsim.util.aida.AIDA; +
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.SvtUtils; -import org.lcsim.hps.recon.tracking.TrackUtils; -import org.lcsim.util.Driver; -import org.lcsim.util.aida.AIDA;
/**
- * Svt Performance Plots
+ * Driver that looks at the performance of the SVT.
* * @author Omar Moreno <[log in to unmask]>
- * @version $Id: SvtPerformance.java,v 1.7 2013/10/14 22:58:03 phansson Exp $
+ * @version $Id: SvtPerformance.java,v 1.8 2013/10/31 21:54:04 omoreno Exp $
*/ public class SvtPerformance extends Driver { private AIDA aida; private List<IPlotter> plotters = new ArrayList<IPlotter>(); HPSShaperAnalyticFitAlgorithm shaperFitter = new HPSShaperAnalyticFitAlgorithm();
+ File outputFile; + BufferedWriter writer;
+ String outputFileName = "svt_performance.data";
String sensorName = null;
-
+
int plotterIndex = 0; double totalNumberOfEvents = 0; double totalTracks = 0; double totalTwoTrackEvents = 0; double idealNoise = 886; // e-
-
+
double[] topLayers; double[] bottomLayers;
-
+
boolean debug = false; // Collection Names private String trackCollectionName = "MatchedTracks";
- public SvtPerformance() {}
+ // Plot Flags + boolean plotClustersPerLayer = false; + boolean plotMIP = false; + + public SvtPerformance() { + }
// --- Setters ---// // ---------------//
@@ -69,158 +79,220 @@
/** * */
- public void setSensorName(String sensorName){ - this.sensorName = sensorName;
+ public void setSensorName(String sensorName) { + this.sensorName = sensorName; + } + + /** + * Enable/disable plotting the number of clusters per layer. Only clusters + * from stereo hits associated with a track are used. + * + * @param true or false + */ + public void setPlotClustersPerLayer(boolean plotClustersPerLayer) { + this.plotClustersPerLayer = plotClustersPerLayer; + } + + /** + * Enable/disable plotting the cluster charge. Only clusters from stereo + * hits associated with a track are used. + * + * @param true or false + */ + public void setPlotClusterCharge(boolean plotMIP) { + this.plotMIP = plotMIP; + } + + /** + * Set the name of the file to which data will be written. + * + * @param outputFileName + * : Name of the output file + */ + public void setOutputFileName(String outputFileName) { + this.outputFileName = outputFileName;
} protected void detectorChanged(Detector detector) {
-
+ + this.printDebug("Setting up plots"); +
// setup AIDA aida = AIDA.defaultInstance(); aida.tree().cd("/");
- Set<SiSensor> sensors = SvtUtils.getInstance().getSensors(); - - String title = null; - IHistogram2D histo2D = null;
+ // Get the list of sensors from the detector + List<HpsSiSensor> sensors = detector.getDetectorElement().findDescendants(HpsSiSensor.class); + + String plotTitle = null;
IHistogram1D histo1D = null;
- - //--- 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); - } - plotterIndex++; - - 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)); - } - 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); - } - 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);
+ int regionIndex = 0; + + // --- Clusters Per Layer ---// + // --------------------------// + + if (plotClustersPerLayer) { + plotters.add(PlotUtils.setupPlotter("# Clusters Per Layer", 1, 2)); + for (HpsSiSensor sensor : sensors) { + if (sensor.isTopLayer()) { + plotTitle = "Top - Layer " + sensor.getLayerNumber(); + regionIndex = 0; + } else { + plotTitle = "Bottom - Layer " + sensor.getLayerNumber(); + regionIndex = 1; + } + plotTitle += " - # Clusters"; + histo1D = aida.histogram1D(plotTitle, 9, 1, 10); + PlotUtils.setup1DRegion(plotters.get(plotterIndex), plotTitle, regionIndex, "# Clusters", histo1D); + } + plotterIndex++;
}
- 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));
+ + // --- MIP Plots ---// + // -----------------// + if (plotMIP) { + + try { + outputFile = new File(outputFileName); + if (!outputFile.exists()) { + outputFile.createNewFile(); + } + + writer = new BufferedWriter(new FileWriter(outputFile.getAbsoluteFile())); + + } catch (IOException exception) { + exception.printStackTrace(); + } + + plotters.add(PlotUtils.setupPlotter("Cluster Charge", 5, 4)); + for (HpsSiSensor sensor : sensors) { + if (sensor.isTopLayer()) { + plotTitle = "Top - Layer " + sensor.getLayerNumber(); + } else { + plotTitle = "Bottom - Layer " + sensor.getLayerNumber(); + } + plotTitle += " - Cluster Charge"; + histo1D = aida.histogram1D(plotTitle, 70, 0, 5040); + PlotUtils.setup1DRegion(plotters.get(plotterIndex), plotTitle, PlotUtils.getPlotterRegion(sensor), "Cluster Charge [e-]", histo1D); + } + plotterIndex++;
}
- plotterIndex++; -
+
// Show the plotters
- for(IPlotter plotter : plotters) plotter.show();
+ for (IPlotter plotter : plotters) + plotter.show(); +
} public void process(EventHeader event) { totalNumberOfEvents++;
- // If the event doesn't have tracks, skip the event - if(!event.hasCollection(Track.class, trackCollectionName)) return;
+ 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;
+ + HpsSiSensor sensor = null; + String plotTitle = null; + int channel; + int maxClusterChannel = 0; + int hitsPerCluster = 0;
ChannelConstants constants = null; HPSShapeFitParameters fit = null;
-
+ double clusterAmplitude, maxClusterAmplitude; + double noise = 0; +
// 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); - } - } - }
+ for (Track track : tracks) { + double[] topClusters = new double[10]; + double[] bottomClusters = new double[10]; + // Loop over all stereo hits associated with a track + for (TrackerHit trackerHit : track.getTrackerHits()) { + + // Loop over the strip hits used to crate the stereo hit + for (HelicalTrackStrip stripHit : ((HelicalTrackCross) trackerHit).getStrips()) { + + sensor = (HpsSiSensor) ((RawTrackerHit) stripHit.rawhits().get(0)).getDetectorElement(); + if (sensor.isTopLayer()) + topClusters[sensor.getLayerNumber() - 1] += 1; + else + bottomClusters[sensor.getLayerNumber() - 1] += 1; + + maxClusterAmplitude = 0; + clusterAmplitude = 0; + hitsPerCluster = stripHit.rawhits().size(); + noise = 0; + for (Object rh : stripHit.rawhits()) { + + RawTrackerHit rawHit = (RawTrackerHit) rh; + channel = rawHit.getIdentifierFieldValue("strip"); + constants = HPSSVTCalibrationConstants.getChannelConstants(sensor, channel); + fit = shaperFitter.fitShape(rawHit, constants); + if (fit.getAmp() > maxClusterAmplitude) { + maxClusterChannel = channel; + maxClusterAmplitude = fit.getAmp(); + } + noise += Math.pow(constants.getNoise(), 2); + clusterAmplitude += fit.getAmp(); + } + + noise = Math.sqrt(noise); + + if (plotMIP) { + try { + if (sensor.isTopLayer()) { + plotTitle = "Top - Layer " + sensor.getLayerNumber() + " - Cluster Charge"; + writer.write("0 " + sensor.getLayerNumber() + " " + maxClusterChannel + " " + clusterAmplitude + " "); + writer.write(noise + " " + hitsPerCluster + "\n"); + } else { + plotTitle = "Bottom - Layer " + sensor.getLayerNumber() + " - Cluster Charge"; + writer.write("1 " + sensor.getLayerNumber() + " " + maxClusterChannel + " " + clusterAmplitude + " "); + writer.write(noise + " " + hitsPerCluster + "\n"); + } + } catch (IOException exception) { + + } + aida.histogram1D(plotTitle).fill(clusterAmplitude); + } + } + + // Fill the cluster histograms + if (plotClustersPerLayer) { + for (int layerN = 1; layerN <= 10; layerN++) { + if (topClusters[layerN - 1] > 0) { + plotTitle = "Top - Layer " + layerN + " - # Clusters"; + aida.histogram1D(plotTitle).fill(topClusters[layerN - 1]); + } + if (bottomClusters[layerN - 1] > 0) { + plotTitle = "Bottom - Layer " + layerN + " - # Clusters"; + aida.histogram1D(plotTitle).fill(bottomClusters[layerN - 1]); + } + } + } + } + }
}
-
/** * print debug statements */
- public void printDebug(String debugStatement){ - if(!debug) return; - System.out.println(this.getClass().getSimpleName() + ": " + debugStatement);
+ public void printDebug(String debugStatement) { + if (!debug) + return; + System.out.println(this.getClass().getSimpleName() + ": " + debugStatement);
}
-
+
@Override public void endOfData() {
+ + try { + writer.close(); + } catch (IOException exception) { + exception.printStackTrace(); + } +
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("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"); }
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