lcsim/src/org/lcsim/contrib/uiowa/MuonFinder
diff -u -r1.3 -r1.4
--- MuonFinder.java 3 Oct 2008 19:05:47 -0000 1.3
+++ MuonFinder.java 4 Oct 2008 01:05:33 -0000 1.4
@@ -104,24 +104,37 @@
//In endcap, track curves so it will bring wrong direction if we use first and last hit.
//First two layers will give better direction.
if(_useFirstTwoLayer){
- CalorimeterHit muonhit0 = mumip.getCalorimeterHits().get(0);
- Hep3Vector muonpos0 = new BasicHep3Vector(muonhit0.getPosition());
- Hep3Vector muonpos1 = new BasicHep3Vector();
- System.out.println("muonhit0= " + muonpos0.magnitude());
+ SortedMap<Integer, Set<CalorimeterHit>> exam = new TreeMap();
int prelayer = -1 ;
+ int i = -1;
+ String predetName = null;
for(CalorimeterHit h : mumip.getCalorimeterHits()){
IDDecoder id = h.getIDDecoder();
id.setID(h.getCellID());
int layer = id.getLayer();
- System.out.println("layer = " + layer);
- if(prelayer != layer && prelayer != -1){
- muonpos1 = new BasicHep3Vector(h.getPosition());
- System.out.println("muonhit1= " + muonpos1.magnitude());
- trackMuon = VecOp.sub(muonpos1, muonpos0);
- break;
+ if(prelayer != layer || prelayer == -1){
+ predetName = h.getSubdetector().getName();
+ i++;
+ if(i==2) break;
}
+
+ Set<CalorimeterHit> hits = exam.get(layer);
+ if(hits == null){
+ hits = new HashSet<CalorimeterHit>();
+ exam.put(layer,hits);
+ }
+ String subdetName = h.getSubdetector().getName();
+ if(predetName.contains(subdetName)) hits.add(h);
prelayer = layer;
}
+
+ Collection<CalorimeterHit> hits0 = exam.get(exam.firstKey());
+ Collection<CalorimeterHit> hits1 = exam.get(exam.lastKey());
+ Hep3Vector muonpos0 = getHitMeanPosition(hits0);
+ Hep3Vector muonpos1 = getHitMeanPosition(hits1);
+ trackMuon = VecOp.sub(muonpos1, muonpos0);
+
+
}else{
CalorimeterHit muonhit1 = mumip.getCalorimeterHits().get(mumip.getCalorimeterHits().size()-1);
CalorimeterHit muonhit0 = mumip.getCalorimeterHits().get(0);
@@ -227,5 +240,17 @@
event.put("MuonList", muonTracks);
}
}
+
+ public Hep3Vector getHitMeanPosition(Collection<CalorimeterHit> hits){
+ Hep3Vector hitPosition = new BasicHep3Vector();
+ double size = hits.size();
+ double norm = 1/size;
+ for(CalorimeterHit hit : hits) {
+ hitPosition = VecOp.add(hitPosition, new BasicHep3Vector(hit.getPosition()));
+ }
+ Hep3Vector meanPosition = VecOp.mult(norm, hitPosition);
+
+ return meanPosition;
+ }
}