hps-java/src/main/java/org/lcsim/hps/users/omoreno
diff -u -r1.3 -r1.4
--- SvtTrackRecoEfficiency.java 25 Sep 2012 15:40:40 -0000 1.3
+++ SvtTrackRecoEfficiency.java 27 Sep 2012 06:55:57 -0000 1.4
@@ -1,6 +1,9 @@
package org.lcsim.hps.users.omoreno;
//--- java ---//
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -42,7 +45,7 @@
/**
*
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: SvtTrackRecoEfficiency.java,v 1.3 2012/09/25 15:40:40 omoreno Exp $
+ * @version $Id: SvtTrackRecoEfficiency.java,v 1.4 2012/09/27 06:55:57 omoreno Exp $
*/
public class SvtTrackRecoEfficiency extends Driver {
@@ -50,12 +53,13 @@
private List<IPlotter> plotters = new ArrayList<IPlotter>();
private List<IHistogram1D> histo1D = new ArrayList<IHistogram1D>();
private List<SimTrackerHit> simTrackerHits = new ArrayList<SimTrackerHit>();
- //private Map<Track, TrackAnalysis> trkToTrkAnalysis = new HashMap<Track, TrackAnalysis>();
TrackUtils trkUtils = new TrackUtils();
FindableTrack findable = null;
TrackAnalysis trkAnalysis = null;
RelationalTable<SimTrackerHit, MCParticle> simHitToMcParticle;
+ BufferedWriter efficiencyOutput = null;
+ BufferedWriter momentumOutput = null;
// Collection Names
String simTrackerHitCollectionName = "TrackerHits";
@@ -71,6 +75,9 @@
double topPossibleTracks, bottomPossibleTracks, possibleTracks;
double totalTopTracks, totalBottomTracks, totalTracks;
int totalLayersHit = 10;
+
+ String efficiencyOutputFile = null;
+ String momentumOutputFile = null;
boolean debug = false;
boolean trackingEfficiencyPlots = true;
@@ -86,6 +93,20 @@
}
/**
+ * Set the name of the file to output efficiency data to
+ */
+ public void setEfficiencyOutputFile(String efficiencyOutputFile){
+ this.efficiencyOutputFile = efficiencyOutputFile;
+ }
+
+ /**
+ * Set the name of the file to output momentum data to
+ */
+ public void setMomentumOutputFile(String momentumOutputFile){
+ this.momentumOutputFile = momentumOutputFile;
+ }
+
+ /**
*
*/
protected void detectorChanged(Detector detector)
@@ -96,6 +117,16 @@
aida = AIDA.defaultInstance();
aida.tree().cd("/");
+ // Open the output file stream
+ if(efficiencyOutputFile != null && momentumOutputFile != null){
+ try{
+ efficiencyOutput = new BufferedWriter(new FileWriter(efficiencyOutputFile));
+ momentumOutput = new BufferedWriter(new FileWriter(momentumOutputFile));
+ } catch(Exception e){
+ System.out.println(this.getClass().getSimpleName() + ": Error! " + e.getMessage());
+ }
+ }
+
if(trackingEfficiencyPlots){
plotters.add(PlotUtils.setupPlotter("Tracking Efficiency", 0, 0));
histo1D.add(aida.histogram1D("Tracking Efficiency", 60, 0, 6));
@@ -146,12 +177,6 @@
// Skip the event if it doesn't contain RawTrackerHits; Only interested in triggered events
if(!event.hasCollection(RawTrackerHit.class, rawTrackerHitCollectionName)) return;
-
- // If the collection of SimTrackerHits is empty, something is wrong
- //if(simTrackerHits.isEmpty()){
- // throw new RuntimeException(this.getClass().getSimpleName() + ": There are no SimTrackerHits associated with the RawTrackerHits");
- //}
-
System.out.println(this.getClass().getSimpleName() + ": Number of SimTrackerHits: " + simTrackerHits.size());
// Get the MC Particles associated with the SimTrackerHits
@@ -171,7 +196,7 @@
trackIsFindable = false;
while(mcParticleIterator.hasNext()){
MCParticle mcParticle = mcParticleIterator.next();
- if(findable.isTrackFindable(mcParticle, 8)){
+ if(findable.isTrackFindable(mcParticle, 10)){
// Check that all SimTrackerHits are within the same detector volume
Set<SimTrackerHit> trackerHits = findable.getSimTrackerHits(mcParticle);
@@ -261,7 +286,7 @@
System.out.println(this.getClass().getSimpleName() + ": Cluster and SimTrackerHit are on different volumes");
}
}
- else if(layerToSimTrackerHit.get(strip.layer()).size() > 1){
+ else if(layerToSimTrackerHit.get(strip.layer()) != null && layerToSimTrackerHit.get(strip.layer()).size() > 1){
System.out.println(this.getClass().getSimpleName() + ": Layer with multiple hits found.");
double deltaZ = Double.MAX_VALUE;
SimTrackerHit simTrackerHitMatch = null;
@@ -293,21 +318,23 @@
@Override
public void endOfData()
- {
- if(trackingEfficiencyPlots){
- double[] efficiency = new double[60];
- for(int index = 0; index < 60; index++){
- if(aida.histogram1D("Tracking Efficiency").binEntries(index) == 0) efficiency[index] = 0;
- else {
- efficiency[index] = aida.histogram1D("Tracking Efficiency").binHeight(index)/aida.histogram1D("Tracking Efficiency").binEntries(index);
- }
- System.out.println("Tracking Efficiency - Bin " + index + " " + efficiency[index]);
- }
- aida.histogram1D("Tracking Efficiency").reset();
- for(int index = 0; index < 60; index++){
- aida.histogram1D("Tracking Efficiency").fill(index, efficiency[index]);
- }
- }
+ {
+
+ if(trackingEfficiencyPlots && efficiencyOutputFile != null && momentumOutputFile != null){
+ try{
+ for(int index = 0; index < 60; index++){
+ if(aida.histogram1D("Tracking Efficiency").binEntries(index) == 0) efficiencyOutput.write(index + " " + 0 + "\n");
+ else efficiencyOutput.write(index + " " + (aida.histogram1D("Tracking Efficiency").binHeight(index)/aida.histogram1D("Tracking Efficiency").binEntries(index)) + "\n");
+
+ if(aida.histogram1D("Momentum").binEntries(index) == 0) momentumOutput.write(index + " " + 0 + "\n");
+ else momentumOutput.write(index + " " + aida.histogram1D("Momentum").binEntries(index) + "\n");
+ }
+ efficiencyOutput.close();
+ momentumOutput.close();
+ } catch(IOException e){
+ System.out.println(this.getClass().getSimpleName() + ": Error! " + e.getMessage());
+ }
+ }
System.out.println("%===============================================================%");
System.out.println("%============== Track Reconstruction Efficiencies ==============%");
@@ -315,12 +342,6 @@
if(findableTracks > 0){
System.out.println("% Total Track Reconstruction Efficiency: " + foundTracks + "/" + findableTracks + "=" + (foundTracks/findableTracks)*100 + "%");
}
- if(topPossibleTracks > 0){
- System.out.println("% Top Track Reconstruction Efficiency: " + (totalTopTracks/topPossibleTracks)*100 + "%");
- }
- if(bottomPossibleTracks > 0){
- System.out.println("% Bottom Track Reconstruction Efficiency: " + (totalBottomTracks/bottomPossibleTracks)*100 + "%");
- }
System.out.println("%\n%===============================================================%");
}
}