lcsim/src/org/lcsim/contrib/CosminDeaconu
diff -u -r1.2 -r1.3
--- TrackerHitTrackFinder.java 20 Jul 2007 17:48:44 -0000 1.2
+++ TrackerHitTrackFinder.java 25 Jul 2007 00:24:17 -0000 1.3
@@ -56,50 +56,58 @@
//===============================================================================//
// Driver to find helical tracks from a collection of TrackerHits
public class TrackerHitTrackFinder extends Driver{
-
- private ArrayList<TrackerHit> _input_hit_collection = null;
-
- private ArrayList<String> event_input = new ArrayList<String>();
- private ArrayList<String> sim_event_input = new ArrayList<String>();
-
+
+ private ArrayList<TrackerHit> _input_hit_collection = null;
+ private ArrayList<String> _event_input = new ArrayList<String>();
+ private ArrayList<String> _sim_event_input = new ArrayList<String>();
private HashMap<TrackerHit,Double> _hit_separation = new HashMap<TrackerHit,Double>();
private ArrayList<TrackerHit> _hitset = new ArrayList<TrackerHit>();
private ArrayList<StandaloneOuterTrack> _tracks = new ArrayList<StandaloneOuterTrack>();
private ArrayList<TrackerHit> _used = new ArrayList<TrackerHit>();
-
-
private HelicalTrackFitter _fitter = new HelicalTrackFitter();
private HelicalTrackFit _fit = null;
- double chisq_l = 10;
- double chisq_c = 10;
+ private String _outputSimTrackerHitCollection = "";
+ private String _outputTrackerHitCollection = "";
- int min_hits = 4;
- int max_hits = 20;
+ private double _chisq_l = 10; //chisq cutoff for the linear fit portion of the helical tracker
+ private double _chisq_c = 10; //chisq cutoff for the circular fit portion of the helical tracker
+
+ private int _min_hits = 4; //minimum number of hits for a track
+ private int _max_hits = 200; // max number of hits for a track
private AIDA _aida = AIDA.defaultInstance();
private boolean _make_histograms = true;
private String _id = "";
- double required_distance = 0.3;
- double required_separation = 0.5;
+ private double _required_distance = 0.3; //how close hits need to be to the seed helix to be considered candidates
+ private double _required_separation = 1; //how well separated the hits must be to be considered candidates
+
+ private double _required_distance_second_pass = 1;
- boolean require_different_layers = false;
+ private boolean _require_different_layers = false; //require all hits to be from different layers on a track
- double drphi = 0.03;
- double dz = 100;
+ private double _drphi = 0.03; //drphi for circle fit portion of helical fit
+ private double _dz = 100; //dz for linear fit portion of helical fit
- double[] origin = {0.,0.,0.};
+ private double[] _origin = {0.,0.,0.}; //the ip
+ private boolean _use_all_layers=true;
+ private HashMap<String,ArrayList> _unused_layers = new HashMap<String,ArrayList>();
/** Creates a new instance of TrackerHitTrackFinder */
public TrackerHitTrackFinder() {
+ //uncomment the following lines to add input (or, you can do it via a driver since the relevant method is public)
+// addSimTrackerInputCollection("TkrBarrHits");
+// addSimTrackerInputCollection("TkrForwardHits");
+// addSimTrackerInputCollection("TkrEndcapHits");
}
protected void process(EventHeader event) {
- updateEventInput(event);
+ updateEventInput(event); // grab new data from event
+
if (_input_hit_collection==null)
{
@@ -107,29 +115,34 @@
return;
}
-
- DistanceCompare<TrackerHit> c = new DistanceCompare<TrackerHit>();
- Collections.sort(_input_hit_collection,c); // sort from outside in... yeah this may take a while if there are a lot of hits
+ if (!_use_all_layers) purgeHitsFromUnusedLayers();
+
+ DistanceCompare<TrackerHit> comp = new DistanceCompare<TrackerHit>(); //DistanceCompare is a comparator for tracker hits
+ Collections.sort(_input_hit_collection,comp); // sort hits from outside in
+
generateHistogram("Number of Input Hits in collection",_input_hit_collection.size());
+ ArrayList<Double> purities = new ArrayList<Double>(); //for plotting purposes
+
// get hit separation
for (TrackerHit hit : _input_hit_collection)
{
_hit_separation.put(hit,findNearest(hit,_input_hit_collection));
}
-
+
+ //loop through all combinations of hits
for (TrackerHit hit1 : _input_hit_collection)
{
for (TrackerHit hit2 : _input_hit_collection)
{
if (hit1==hit2) continue;
- if (require_different_layers && sameLayer(hit1,hit2)) continue;
+ if (_require_different_layers && sameLayer(hit1,hit2)) continue;
for (TrackerHit hit3 : _input_hit_collection)
{
if (hit1==hit3 || hit2==hit3) continue;
- if (require_different_layers && (sameLayer(hit1,hit3) || sameLayer(hit2,hit3))) continue;
- if (_used.contains(hit1)||_used.contains(hit2)||_used.contains(hit3)) continue; //don't reuse hits that already have a home'
+ if (_require_different_layers && (sameLayer(hit1,hit3) || sameLayer(hit2,hit3))) continue;
+ if (_used.contains(hit1)||_used.contains(hit2)||_used.contains(hit3)) continue; //don't reuse hits
_hitset.clear();
_hitset.add(hit1);
@@ -139,8 +152,9 @@
_fit = doFit(_hitset);
generateHistogram("chisql_1",_fit.chisq()[1]);
+
//check line chisquare to see if it's reasonable'
- if (_fit.chisq()[1]/3.0>chisq_l) continue;
+ if (_fit.chisq()[1]/3.0>_chisq_l) continue;
generateHistogram("chisql_2",_fit.chisq()[1]);
ArrayList<TrackerHit> candidates = new ArrayList<TrackerHit>();
@@ -148,27 +162,31 @@
//look for well separated new hits that are candidates to attach
for (TrackerHit new_hit : _input_hit_collection)
{
+ if (_used.contains(new_hit)) continue;
if (_hitset.contains(new_hit)) continue; //make sure not already used
//check separation/distance
- if (Math.abs(_fit.getHelix().getSignedClosestDifferenceToPoint(new SpacePoint(new BasicHep3Vector(new_hit.getPosition())))) > required_distance &&
- _hit_separation.get(new_hit)<required_separation) continue;
-
+
+ double distance = Math.abs(_fit.getHelix().getSignedClosestDifferenceToPoint(new SpacePoint(new BasicHep3Vector(new_hit.getPosition()))));
+
+ if ( distance> _required_distance || _hit_separation.get(new_hit)<_required_separation) continue;
+
+
//try adding it to hitset and assess chisq
_hitset.add(new_hit);
_fit = doFit(_hitset);
//check new chisq's and see if they're reasonable'
- if (_fit.chisq()[1]/((double)_hitset.size())>chisq_l || _fit.chisq()[0]/((double)_hitset.size())>chisq_c)
+ if (_fit.chisq()[1]/((double)_hitset.size())>_chisq_l || _fit.chisq()[0]/((double)_hitset.size())>_chisq_c)
{
_hitset.remove(new_hit);
continue;
}
//if requiring different layers, don't add anything in a layer already used... this is probably not the best way to do this
- if (require_different_layers)
+ if (_require_different_layers)
{
boolean fail = false;
if (sameLayer(new_hit,hit1) || sameLayer(new_hit,hit2) || sameLayer(new_hit,hit3)) fail=true;
@@ -185,34 +203,31 @@
_hitset.remove(new_hit);
}
- generateHistogram("candidates_size",candidates.size());
-
+ generateHistogram("candidates_size",candidates.size());
////first, try adding all candidates
_hitset.addAll(candidates);
- if (_hitset.size() < min_hits || _hitset.size() > max_hits) continue; //if too many or too few hits, skip
+ if (_hitset.size() < _min_hits || _hitset.size() > _max_hits) continue; //if too many or too few hits, skip
_fit = doFit(_hitset);
generateHistogram("chisql_3",_fit.chisq()[1]);
generateHistogram("chisqc_1",_fit.chisq()[0]);
- int while_loop_iterations = 0;
-
//if chisquared is too high, remove hits farthest from helix until chisquared is acceptable
- while (_fit.chisq()[1]/((double)_hitset.size())>chisq_l || _fit.chisq()[0]/((double)_hitset.size())>chisq_c)
+ while (_fit.chisq()[1]/((double)_hitset.size())>_chisq_l || _fit.chisq()[0]/((double)_hitset.size())>_chisq_c)
{
- if (_hitset.size()<min_hits) break;
+ if (_hitset.size()<_min_hits) break;
int size = _hitset.size();
double farthest_distance = -1;
- int removeMe=-1;
+ TrackerHit removeMe=null;
- for (int i = 0; i<candidates.size(); i++)
+ for (TrackerHit i : candidates)
{
- double distance = Math.abs(_fit.getHelix().getSignedClosestDifferenceToPoint(new SpacePoint(new BasicHep3Vector(candidates.get(i).getPosition()))));
+ double distance = Math.abs(_fit.getHelix().getSignedClosestDifferenceToPoint(new SpacePoint(new BasicHep3Vector(i.getPosition()))));
if (distance > farthest_distance)
{
@@ -221,46 +236,131 @@
}
}
- if(!_hitset.remove(candidates.get(removeMe))) System.out.println("Infinite Loop! Diagnostic information: "+removeMe+" "+candidates.size());
+ if(!_hitset.remove(removeMe)) System.out.println("Infinite Loop! Diagnostic information: "+removeMe+" "+candidates.size());
candidates.remove(removeMe);
- while_loop_iterations++;
-
//fit again
_fit = doFit(_hitset);
}
- generateHistogram("while loop iter",while_loop_iterations);
+ //now check if any candidate hits are too far and remove them if they are, refitting after each removal...
+
+ boolean keepgoing = true;
+
+ while(keepgoing) //while loop so that we start over whenever we remove a candidate
+ {
+ keepgoing = false; //assume all candidates fall within critical distance
+ ArrayList<TrackerHit> removeFromCandidates = new ArrayList<TrackerHit>(); //since java won't let you remove an element from a List you're looping over...'
+
+ for (TrackerHit i : candidates)
+ {
+ double distance = Math.abs(_fit.getHelix().getSignedClosestDifferenceToPoint(new SpacePoint(new BasicHep3Vector(i.getPosition()))));
+
+ if(distance>_required_distance_second_pass) //check distance to make sure it's reasonable'
+ {
+ _hitset.remove(i);
+ _fit = doFit(_hitset); //refit
+ removeFromCandidates.add(i);
+ keepgoing = true;
+ break;
+ }
+ }
+ candidates.removeAll(removeFromCandidates);
+ }
//now, I think we have a track
- if (_hitset.size()>=min_hits)
+ if (_hitset.size()>=_min_hits)
{
MCParticle majority_particle = findMajorityParticle(_hitset);
double purity = findPurity(_hitset,majority_particle);
- double b_field = event.getDetector().getFieldMap().getField(origin)[2];
+ double b_field = event.getDetector().getFieldMap().getField(_origin)[2];
StandaloneOuterTrack track = new StandaloneOuterTrack(b_field,_fit,_hitset,majority_particle,purity);
_tracks.add(track);
_used.addAll(_hitset);
+ purities.add(purity);
+ //We love plots!
generateHistogram("Number of hits per track",_hitset.size());
generateHistogram("purity",purity);
+ generateScatterPlot("purity vs. hits per track",purity,_hitset.size());
+ generateScatterPlot("purity vs. chisql per nhits",purity,_fit.chisq()[1]/_hitset.size());
+ generateScatterPlot("purity vs. chisqc per nhits",purity,_fit.chisq()[0]/_hitset.size());
+ generateScatterPlot("purity vs. majority_particle momentum",purity,majority_particle.getMomentum().magnitude());
+ generateScatterPlot("purity vs. z momentum",purity,majority_particle.getMomentum().z());
+ generateScatterPlot("purity vs. theta",purity,Math.atan(_fit.parameters()[4]));
+ generateScatterPlot("purity vs. phi",purity,_fit.parameters()[1]);
+ generateScatterPlot("purity vs. z",purity,_fit.parameters()[3]);
+ generateScatterPlot("purity vs. curvature",purity,_fit.parameters()[2]);
+ generateScatterPlot("purity vs. dca",purity,_fit.parameters()[0]);
+
+ HashMap<String,Integer> det_hits = new HashMap<String,Integer>();
+
+
+ double max_distance = -1; //this will store the distance of the point farthest from the track.
+ double total_distance = 0;
+ double min_sep = 100000000;
+ double total_sep = 0;
+
+ for (TrackerHit i : _hitset) //calculate some info for plotting purposes
+ {
+ double distance = Math.abs(_fit.getHelix().getSignedClosestDifferenceToPoint(new SpacePoint(new BasicHep3Vector(i.getPosition()))));
+ total_distance = total_distance + distance;
+ if (distance>max_distance) max_distance=distance;
+
+ double separation = _hit_separation.get(i).doubleValue();
+ if (separation<min_sep) min_sep = separation;
+ total_sep = total_sep + separation;
+
+ String detector = ((BaseTrackerHitMC)i).getSimHits().get(0).getSubdetector().getName();
+ if (!det_hits.containsKey(i))
+ {
+ det_hits.put(detector,1);
+ }
+
+ else
+ {
+ Integer already = det_hits.get(detector);
+ det_hits.put(detector,already+1);
+ }
+ }
+
+ generateScatterPlot("purity vs. number of subdetectors",purity,det_hits.keySet().size());
+ generateScatterPlot("purity vs. max distance",purity,max_distance);
+ generateScatterPlot("purity vs. average distance",purity,total_distance/((double)_hitset.size()));
+ generateScatterPlot("purity vs. min seperation",purity,min_sep);
+ generateScatterPlot("purity vs. average separation",purity,total_sep/((double)_hitset.size()));
}
}
}
}
- event.put(EventHeader.TRACKS, _tracks, Track.class, 0); //put tracks into event
+
+ event.put(EventHeader.TRACKS, new ArrayList<StandaloneOuterTrack>(_tracks), Track.class, 0); //put tracks into event
+
+ //make some more plots!
+ generateHistogram("hits left",_input_hit_collection.size());
generateHistogram("ntracks",_tracks.size());
+ for (Double i : purities)
+ {
+ generateScatterPlot("purity vs. NTracks",i.doubleValue(),_tracks.size());
+ }
+
+ outputHits(event); //output any unused hits to be outputted
+
purgeLists(); //do some cleanup
}
//-------------------------Public Controller Methods--------------------------------------------------------------
+ //TODO: Finish writing javadoc
- //TODO: write javadoc...
-
+ /**
+ * Adds a list of tracker hits to be processed. Note that this needs to be called once for each time this driver processes.
+ *
+ * @param hits An arraylist of tracker hits to be processed
+ */
public void addInput(ArrayList<TrackerHit> hits)
{
if (_input_hit_collection==null)
@@ -274,57 +374,168 @@
}
}
+ /**
+ * Sets whether or not hits must be on a different layer for a track
+ *
+ * @param b boolean value to set _require_different_layers to
+ */
public void requireDifferentLayers(boolean b)
- {require_different_layers=b;}
+ {_require_different_layers=b;}
+ /**
+ * Sets the chisq cutoff / number of points for the linear fitter portion of the helical fitter
+ *
+ * @param chisql new value for chisql
+ */
public void setChisqL(double chisql)
- {chisq_l=chisql;}
+ {_chisq_l=chisql;}
+ /**
+ * Sets the chisq cutoff / number of points for the circle fitter portion of the helical fitter
+ *
+ * @param chisqc new value for chisqc
+ */
public void setChisqC(double chisqc)
- {chisq_c=chisqc;}
+ {_chisq_c=chisqc;}
+ /**
+ * Sets the dz value for helical fitter
+ *
+ * @param dz new value for dz
+ */
public void set_dz(double newdz)
- {dz = newdz;}
+ {_dz = newdz;}
+ /**
+ * Sets the drphi value for the helical fitter
+ *
+ * @param drphi new value for drphi
+ */
public void set_drphi(double newdrphi)
- {dz = newdrphi;}
+ {_dz = newdrphi;}
+ /**
+ * Sets the maximum distance to the seed helix for hits to be considered candidates
+ *
+ * @param d double value for new required distance
+ */
public void setRequiredDistance(double d)
- {required_distance=d;}
+ {_required_distance=d;}
+ public void setRequiredDistanceSecondPass(double d)
+ {_required_distance_second_pass=d;}
+
+ /**
+ * Sets the minimum separation for a hit to be considered a candidate
+ *
+ * @param s double value for new separation
+ */
public void setRequiredSeparation(double s)
- {required_separation=s;}
+ {_required_separation=s;}
+ /**
+ * Sets the minimum number of hits to form a track
+ *
+ * @param minhits integer value for minimum number of hits
+ */
public void setMinHits(int minhits)
- {min_hits = minhits;}
+ {_min_hits = minhits;}
+ /**
+ * Sets the maximum number of hits to form a track
+ *
+ * @param maxhits integer value for minimum number of maxhits
+ */
public void setMaxHits(int maxhits)
- {max_hits = maxhits;}
+ {_max_hits = maxhits;}
+ /**
+ * Turns histograms on*/
public void make_histograms()
{_make_histograms = true;}
+ /**
+ * Turns histograms on or off
+ *
+ * @param histograms boolean value for histograms being on
+ */
public void make_histograms(boolean histograms)
{_make_histograms = histograms;}
+ /**
+ * Adds a list of simtrackerhits to be processed. Note that this needs to be called once for each time this driver processes. The simtrackerhits are converted to tracker hits using TrackerHitCheater
+ *
+ * @param hits An arraylist of simtrackerhits to be processed
+ */
public void addSimTrackerHitInput(ArrayList<SimTrackerHit> hits)
{
TrackerHitCheater _cheat = new TrackerHitCheater();
addInput ((ArrayList<TrackerHit>) _cheat.makeTrackerHits(hits));
}
+ /**
+ * Adds a collection of SimTrackerHits from the event which will be updated with each call to process(). Converted to TrackerHits.
+ *
+ * @param sim_tracker_hit_collection_name The name of the collection (e.g. "TkrBarrHits")
+ */
public void addSimTrackerInputCollection(String sim_tracker_hit_collection_name)
{
- sim_event_input.add(sim_tracker_hit_collection_name);
+ _sim_event_input.add(sim_tracker_hit_collection_name);
}
+ /**
+ * Adds a collection of TrackerHits from the event which will be updated with each call to process().
+ *
+ * @param tracker_hit_collection_name The name of the collection (e.g. "TkrBarrHits")
+ */
public void addInputCollection(String tracker_hit_collection_name)
{
- event_input.add(tracker_hit_collection_name);
+ _event_input.add(tracker_hit_collection_name);
+ }
+
+ public void ignoreLayer (String subdetector, int layer)
+ {
+ if (!_unused_layers.containsKey(subdetector))
+ {
+ _unused_layers.put(subdetector,new ArrayList(Arrays.asList(new int[]{layer})));
+ }
+ else
+ {
+ ArrayList arr = _unused_layers.get(subdetector);
+ arr.add(layer);
+ _unused_layers.put(subdetector,arr);
+ }
+ }
+
+ public void useAllLayers(boolean usealllayers)
+ {_use_all_layers=usealllayers;}
+
+ public void ignoreEveryOtherForwardLayer()
+ {
+ _use_all_layers=false;
+ ignoreLayer("TrackerForward",1);
+ ignoreLayer("TrackerForward",3);
+ ignoreLayer("TrackerForward",5);
+ ignoreLayer("TrackerEndcap",1);
+ ignoreLayer("TrackerEndcap",3);
+ ignoreLayer("TrackerEndcap",5);
+ ignoreLayer("TrackerEndcap",7);
}
- public void setID(String s)
- {_id = s;}
+ public void setOutputSimTrackerHitCollection(String str)
+ {_outputSimTrackerHitCollection=str;}
+
+ public void setOutputTrackerHitCollection(String str)
+ {_outputTrackerHitCollection=str;}
+
+ /**
+ * Set a string to be appended to the names of output collections and histograms. This allows one to distinguish different track finder subdrivers from each other.
+ *
+ * @param str Appended string
+ *
+ */
+ public void setID(String str)
+ {_id = str;}
//--------------------------Private Helper Methods-----------------------------------------------------
@@ -334,6 +545,7 @@
for (TrackerHit i : hits)
{
+ if (i==hit) continue;
double d = distance(((BaseTrackerHitMC)hit).getPosition(),((BaseTrackerHitMC)i).getPosition());
if (d < returnme)
{
@@ -365,7 +577,7 @@
{
double[] returnme = new double[nhits];
for (int i = 0; i<nhits;i++)
- {returnme[i]=drphi;}
+ {returnme[i]=_drphi;}
return returnme;
}
@@ -373,7 +585,7 @@
{
double[] returnme = new double[nhits];
for (int i = 0; i<nhits;i++)
- {returnme[i]=dz;}
+ {returnme[i]=_dz;}
return returnme;
}
@@ -419,7 +631,6 @@
MCParticle currentMax = null;
int max_value = -1;
-
for (MCParticle i : particles.keySet())
{
if (particles.get(i).intValue()>max_value)
@@ -454,13 +665,20 @@
{
_aida.cloud1D(name+_id).fill(value);
}
-
+ }
+
+ private void generateScatterPlot(String name, double value1, double value2)
+ {
+ if (_make_histograms)
+ {
+ _aida.cloud2D(name+_id).fill(value1,value2);
+ }
}
private void purgeLists()
{
_input_hit_collection.clear();
- _hitset.clear();
+ _hitset.clear();
_hit_separation.clear();
_used.clear();
_tracks.clear();
@@ -468,18 +686,18 @@
private void updateEventInput(final EventHeader event) {
- if (event_input.size()>0) //get any input from the event
+ if (_event_input.size()>0) //get any input from the event
{
- for (String s : event_input)
+ for (String s : _event_input)
{
ArrayList<TrackerHit> eventhits = (ArrayList) event.get(TrackerHit.class,s);
if (eventhits!=null) addInput(eventhits);
}
}
- if (sim_event_input.size()>0) // get any simtracker input from the event
+ if (_sim_event_input.size()>0) // get any simtracker input from the event
{
- for (String s : sim_event_input)
+ for (String s : _sim_event_input)
{
ArrayList<SimTrackerHit> simeventhits = (ArrayList) event.get(SimTrackerHit.class,s);
if (simeventhits!=null) addSimTrackerHitInput(simeventhits);
@@ -487,6 +705,54 @@
}
}
+ private void purgeHitsFromUnusedLayers()
+ {
+
+ ArrayList<TrackerHit> removeMe = new ArrayList<TrackerHit>();
+
+ for (TrackerHit i : _input_hit_collection)
+ {
+ String subdetector = ((BaseTrackerHitMC) i).getSimHits().get(0).getSubdetector().getName();
+ int layer = ((BaseTrackerHitMC) i).getSimHits().get(0).getLayer();
+
+ if (_unused_layers.containsKey(subdetector) && _unused_layers.get(subdetector).contains(Integer.valueOf(layer))) removeMe.add(i);
+ }
+
+ for (TrackerHit i: removeMe)
+ {
+ _input_hit_collection.remove(i);
+ }
+
+ }
+
+ private void outputHits(EventHeader event)
+ {
+ if (_outputSimTrackerHitCollection!="")
+ {
+ List<SimTrackerHit> outputMe = new ArrayList<SimTrackerHit>();
+ for (TrackerHit i : _input_hit_collection)
+ {
+ if (!_used.contains(i))
+ {
+ outputMe.addAll(((BaseTrackerHitMC)i).getSimHits());
+ }
+ }
+ event.put(_outputSimTrackerHitCollection,outputMe,SimTrackerHit.class, 0); //put tracks into event
+ }
+
+ if (_outputTrackerHitCollection!="")
+ {
+ List<TrackerHit> outputMe = new ArrayList<TrackerHit>();
+ for (TrackerHit i : _input_hit_collection)
+ {
+ if (!_used.contains(i))
+ {
+ outputMe.add(i);
+ }
+ }
+ event.put(_outputTrackerHitCollection,outputMe,TrackerHit.class,0);
+ }
+ }
} //end TrackerHitTrackFinder class
lcsim/src/org/lcsim/contrib/CosminDeaconu
diff -u -r1.4 -r1.5
--- OuterTrackFinder.java 20 Jul 2007 17:48:44 -0000 1.4
+++ OuterTrackFinder.java 25 Jul 2007 00:24:17 -0000 1.5
@@ -82,7 +82,8 @@
//private String[] _subdetectors_arr = {"TrackerForward","TrackerEndcap","TrackerBarrel"};
private ArrayList<String> _subdetectors = null;
- private String _output_hit_collection = "";
+ private String _output_trackerhit_collection = "";
+ private String _output_simhit_collection = "";
private double _module_length = 300.0;
private double _seedhit_isolation = 0.5; //0; //0.5;
@@ -91,7 +92,7 @@
private double _pass1_hit_isolation = 1.0; //0; //1.0;
private double _pass2_hit_dca = 0.25; //900000; //0.25;
private double _chisq_dof = 10; //1.0E20; //10.0;
- private boolean _make_histograms = true;
+ private boolean _make_histograms = false;
private int nAssocMin = 4;
private double _min_seed_pt = 0.5; //*Tyler
private double _max_phi_sep = (Math.PI)/2; //*Tyler
@@ -136,7 +137,7 @@
private int [][] _combinedLayers_arr={{4,6}};
private ArrayList<ArrayList<Integer>> _combinedLayers = null;
- private boolean _phi_cut = false; //whether or not to use the phicut
+ private boolean _phi_cut = true; //whether or not to use the phicut
private boolean _zseg = false; //whether or not to use z segmentation (Lori's Code)
@@ -211,79 +212,7 @@
//------------------------------------------------------------------------------//
if (!_useAllLayers)
{
- for (int i = 0; i<nlayers; i++) //by default, map each layer to itself
- {
- layer_converter.add(i);
- }
-
- Set used = new TreeSet();
-
- for (Integer j : _usedLayers)
- {
- int i = j.intValue();
- used.add(i);
- if (i>nlayers)
- {
- System.out.println("ERROR: THE USED LAYERS ARRAY CONTAINS NON-EXISTING LAYERS");
- throw (new NullPointerException()); //throw exception if _usedLayers specifies layers that don't exist
- }
- }
-
- //skip layers not in _usedLayers if not using all layers and then map other layers to them
- Set available_spots = new TreeSet();
-
- for (int i =0;i<layer_converter.size();i++)
- {
- if (!used.contains(i))
- {
- layer_converter.set(i,-1); //set unused layers to -1 so we know to skip them
- available_spots.add(i);
- }
- }
-
- if (_combinedLayers.size()>0) //free up locations held by layers to be combined
- {
- for (ArrayList i : _combinedLayers)
- {
- for (int j = 1; j<i.size();j++)
- {
- used.remove(i.get(j));
- available_spots.add(i.get(j));
- }
- }
- }
-
- for (int i = 0; i<layer_converter.size();i++) //map used layers to lowest possible index
- {
- if (used.contains(i) && available_spots.size()>0)
- {
- for (int j = 0; j<i;j++)
- {
- if (available_spots.contains(j))
- {
- layer_converter.set(i,j);
- available_spots.remove(j);
- available_spots.add(i);
- break;
- }
- }
- }
- }
-
- if (_combinedLayers.size()>0) //combine any layers to be combined
- {
- for (ArrayList i : _combinedLayers)
- {
- for (int j = 1; j<i.size();j++)
- {
- layer_converter.set(((Integer)i.get(j)).intValue(),layer_converter.get(((Integer)(i.get(0))).intValue())); //yuck... why must ArrayLists not work with primitives?
-
- }
- }
- }
-
- //System.out.println(layer_converter.toString());
- nlayers = used.size(); //set nlayers to the number of layers actually used
+ nlayers = figureOutLayers(layer_converter, nlayers); //set nlayers to the number of layers actually used
}
gotHere(0);
@@ -295,7 +224,7 @@
_hits = new ArrayList<TrackerHit>();
for (String i : _input_hit_collections)
{
- _hits.addAll((List<TrackerHit>)_cheat.makeTrackerHits(event.getSimTrackerHits(i)));
+ _hits.addAll((List<TrackerHit>)_cheat.makeTrackerHits(event.getSimTrackerHits(i)));
}
// Print out number of hits
@@ -326,20 +255,7 @@
if (_multiple_collections) //Stack layers if multiple hit collections so we don't have a bunch of layer 0's and such'
{
- for (int i = 1; i<_subdetectors.size();i++)
- {
- if (((BaseTrackerHitMC)hit).getSimHits().get(0).getSubdetector().getName().equals(_subdetectors.get(i)))
- {
- int offset = 0;
- for (int j = i-1; j>-1;j--)
- {
- int this_offset = ((Integer)subdetector_lengths.get(j)).intValue();
- offset=offset+this_offset;
- }
-// System.out.println("offset:"+offset);
- layer = layer+offset;
- }
- }
+ layer = stackLayers(layer, hit, subdetector_lengths);
}
if (!_useAllLayers) //if not using all layers, go through the necessary hoopla
@@ -389,20 +305,7 @@
if (_multiple_collections) //Stack layers if multiple hit collections so we don't have a bunch of layer 0's and such'
{
- for (int i = 1; i<_subdetectors.size();i++)
- {
- if (((BaseTrackerHitMC)hit).getSimHits().get(0).getSubdetector().getName().equals(_subdetectors.get(i)))
- {
- int offset = 0;
- for (int j = i-1; j>-1;j--)
- {
- int this_offset = ((Integer)subdetector_lengths.get(j)).intValue();
- offset=offset+this_offset;
- }
- // System.out.println("offset:"+offset);
- layer = layer+offset;
- }
- }
+ layer = stackLayers(layer, hit, subdetector_lengths);
}
if (!_useAllLayers) //if not using all layers, go through the necessary hoopla
@@ -794,7 +697,7 @@
for(int ts2=0; ts2<nlayers; ts2++)
{
double phidifference2 = Math.abs(phivalues2[ps2]-phivalues2[ts2]);
- _aida.cloud1D("PhiDifference").fill(phidifference2);
+ if (_make_histograms) _aida.cloud1D("PhiDifference").fill(phidifference2);
if( (phidifference2 > _max_phi_sep) && (phidifference2 < 2*(Math.PI )-_max_phi_sep))
{
b2 = 1;
@@ -808,8 +711,6 @@
// If fit is good enough, fill final histograms
//if (_fit.chisq()/nhits < _chisq_dof)
- _aida.cloud1D("ChisqL before check").fill(_hfit.chisq()[1]);
- _aida.cloud1D("ChisqC before check").fill(_hfit.chisq()[0]);
if (_hfit.chisq()[0]/nhits < _h_chisq_dof[0] && _hfit.chisq()[1]/nhits < _h_chisq_dof[1])
{
// Mark hits as used - find all MCParticles that contribute
@@ -880,6 +781,7 @@
_aida.cloud1D("dca_pass"+_id).fill(_hfit.parameters()[0]);
_aida.cloud1D("nhits_pass"+_id).fill(used_layers.size());
_aida.cloud1D("purity"+_id).fill((double)nhits_max/(double)nhits);
+ _aida.cloud2D("purity vs. chisql"+_id).fill(((double)nhits_max)/((double)nhits),_hfit.chisq()[1]);
}
// Create StandaloneAxialBarrelTrack1
@@ -914,7 +816,7 @@
event.put(EventHeader.TRACKS, tracklist, Track.class, 0);
// If requested, put unused hits into event
- if (_output_hit_collection != "")
+ if (_output_trackerhit_collection != "")
{
List<TrackerHit> unused_hits = _hits;
int i = 0;
@@ -924,7 +826,27 @@
unused_hits.remove(hit);
}
- event.put(_output_hit_collection, unused_hits, TrackerHit.class, 0);
+ event.put(_output_trackerhit_collection, unused_hits, TrackerHit.class, 0);
+ }
+
+ if (_output_simhit_collection != "")
+ {
+ List<TrackerHit> unused_hits = _hits;
+ int i = 0;
+ for (TrackerHit hit : _used_hits)
+ {
+ i++;
+ unused_hits.remove(hit);
+ }
+
+ List<SimTrackerHit> putme = new ArrayList<SimTrackerHit>();
+ for (TrackerHit j : unused_hits)
+ {
+ putme.addAll(((BaseTrackerHitMC)j).getSimHits());
+ }
+
+ event.put(_output_simhit_collection, putme, SimTrackerHit.class, 0);
+
}
}
@@ -1042,11 +964,22 @@
/**
* Set name of SimTrackerHit collection for unused hits (default = "" == not written out)
*
- * @param output_hit_collection Name of output collection for unused SimTrackerHits
- *if (ntracks_all_layers > 0)
+ * @param output_hit_collection Name of output collection for unused TrackerHits
+
*/
- public void setOutputHits(String output_hit_collection)
- {_output_hit_collection = output_hit_collection;}
+ public void setTrackerOutputHits(String output_hit_collection)
+ {_output_trackerhit_collection = output_hit_collection;}
+
+
+ /**
+ * Set name of SimTrackerHit collection for unused hits (default = "" == not written out)
+ *
+ * @param output_hit_collection Name of output collection for unused SimTrackerHits (converted from TrackerHits)
+
+ */
+ public void setSimOutputHits(String output_hit_collection)
+ {_output_simhit_collection= output_hit_collection;}
+
/**
* Set length of modules in z (default = 100.0)
*
@@ -1133,7 +1066,7 @@
/**
- * Use the default forward tracking settings
+ * Use the default forward tracking settings. Note that this is for sid01 detector models and will result in a NullPointerException with sid00 (since sid00 doesn't have the TrackerForward piece)
*/
public void useDefaultForwardSettings()//~Cosmin
{
@@ -1161,6 +1094,19 @@
_zseg=true;
}
+ public void useDefaultBothSettings()
+ {
+ _useAllLayers=false;
+ _multiple_collections=true;
+ setUsedLayers(new int[]{0,2,4,6,8,10,12,14,15,16,17,18});
+ setCombinedLayers(new int[][]{{4,6}});
+ setInputHits(new String[]{"TkrForwardHits","TkrEndcapHits","TkrBarrHits"});
+ setSubdetectors(new String[]{"TrackerForward","TrackerEndcap","TrackerBarrel"});
+ _phi_cut=false;
+ _zseg=false;
+
+ }
+
/**
* Enable/Disable using the phi cut
*
@@ -1264,5 +1210,101 @@
}
return returnme;
}
+
+ private int figureOutLayers(final ArrayList layer_converter, int nlayers) throws NullPointerException {
+ for (int i = 0; i<nlayers; i++) //by default, map each layer to itself
+ {
+ layer_converter.add(i);
+ }
+
+ Set used = new TreeSet();
+
+ for (Integer j : _usedLayers)
+ {
+ int i = j.intValue();
+ used.add(i);
+ if (i>nlayers)
+ {
+ System.out.println("ERROR: THE USED LAYERS ARRAY CONTAINS NON-EXISTING LAYERS");
+ throw (new NullPointerException()); //throw exception if _usedLayers specifies layers that don't exist
+ }
+ }
+
+ //skip layers not in _usedLayers if not using all layers and then map other layers to them
+ Set available_spots = new TreeSet();
+
+ for (int i =0;i<layer_converter.size();i++)
+ {
+ if (!used.contains(i))
+ {
+ layer_converter.set(i,-1); //set unused layers to -1 so we know to skip them
+ available_spots.add(i);
+ }
+ }
+
+ if (_combinedLayers.size()>0) //free up locations held by layers to be combined
+ {
+ for (ArrayList i : _combinedLayers)
+ {
+ for (int j = 1; j<i.size();j++)
+ {
+ used.remove(i.get(j));
+ available_spots.add(i.get(j));
+ }
+ }
+ }
+
+ for (int i = 0; i<layer_converter.size();i++) //map used layers to lowest possible index
+ {
+ if (used.contains(i) && available_spots.size()>0)
+ {
+ for (int j = 0; j<i;j++)
+ {
+ if (available_spots.contains(j))
+ {
+ layer_converter.set(i,j);
+ available_spots.remove(j);
+ available_spots.add(i);
+ break;
+ }
+ }
+ }
+ }
+
+ if (_combinedLayers.size()>0) //combine any layers to be combined
+ {
+ for (ArrayList i : _combinedLayers)
+ {
+ for (int j = 1; j<i.size();j++)
+ {
+ layer_converter.set(((Integer)i.get(j)).intValue(),layer_converter.get(((Integer)(i.get(0))).intValue())); //yuck... why must ArrayLists not work with primitives?
+
+ }
+ }
+ }
+
+ //System.out.println(layer_converter.toString()+_id);
+ nlayers = used.size(); //set nlayers to the number of layers actually used
+ return nlayers;
+ }
+
+ private int stackLayers(int layer, final TrackerHit hit, final ArrayList subdetector_lengths) {
+ for (int i = 1; i<_subdetectors.size();i++)
+ {
+ if (((BaseTrackerHitMC)hit).getSimHits().get(0).getSubdetector().getName().equals(_subdetectors.get(i)))
+ {
+ int offset = 0;
+ for (int j = i-1; j>-1;j--)
+ {
+ int this_offset = ((Integer)subdetector_lengths.get(j)).intValue();
+ offset=offset+this_offset;
+ }
+// System.out.println("offset:"+offset);
+ layer = layer+offset;
+ }
+ }
+ return layer;
+ }
+
}