lcsim/src/org/lcsim/recon/cluster/directedtree
diff -u -r1.1 -r1.2
--- DirectedTreeClusterer.java 8 Jan 2006 14:28:22 -0000 1.1
+++ DirectedTreeClusterer.java 9 Feb 2006 21:17:59 -0000 1.2
@@ -17,6 +17,7 @@
import org.lcsim.recon.cluster.util.CalHitMapMgr;
import org.lcsim.recon.cluster.util.BasicCluster;
import org.lcsim.recon.cluster.util.SortClustersBySize;
+import org.lcsim.recon.cluster.util.CalorimeterHitESort;
import org.lcsim.event.Cluster;
public class DirectedTreeClusterer extends Driver {
@@ -36,16 +37,20 @@
System.out.println("Start DirectedTreeClusterer, event #"+_evtnum);
}
+ // load readout map (decoders)
_roMap = event.getDetector().getReadouts();
- String embName = "EcalBarrHits";
- String emeName = "EcalEndcapHits";
- String hdbName = "HcalBarrHits";
- String hdeName = "HcalEndcapHits";
+ // load hit maps
+ String embName = "EcalBarrDigiHits";
+ String emeName = "EcalEndcapDigiHits";
+ String hdbName = "HcalBarrDigiHits";
+ String hdeName = "HcalEndcapDigiHits";
embhitmap = _expert.getCollHitMap(embName, _emEcut);
emehitmap = _expert.getCollHitMap(emeName, _emEcut);
hdbhitmap = _expert.getCollHitMap(hdbName, _hdEcut);
hdehitmap = _expert.getCollHitMap(hdeName, _hdEcut);
+
+ // define densities
_loader.setDensities(embName, embhitmap);
_loader.setDensities(emeName, emehitmap);
_loader.setDensities(hdbName, hdbhitmap);
@@ -89,28 +94,33 @@
}
- public Vector<Vector<CalorimeterHit>>
+ public List<List<CalorimeterHit>>
makeTree(Map<Long,CalorimeterHit> cahitmap, SegmentationBase segm) {
if(_debug>0) {
System.out.println("makeTree: cahitmap size="+cahitmap.size());
}
_ParentMap = new HashMap<Long,Long>();
- Vector<CalorimeterHit> RootVec = new Vector<CalorimeterHit>();
+ List<CalorimeterHit> RootVec = new ArrayList<CalorimeterHit>();
+
+ // process hits according to raw energy
+ List<CalorimeterHit> sortedHits = new ArrayList<CalorimeterHit>(cahitmap.values());
+ Collections.sort( sortedHits, new CalorimeterHitESort() );
- for( CalorimeterHit ihit : cahitmap.values() ) {
+ for( CalorimeterHit ihit : sortedHits ) {
long cellid = ihit.getCellID();
double idens = _loader.getDensity( cellid );
-// if(_evtnum==81 && cellid== 1672347904) System.out.println("density="+idens);
segm.setID(cellid);
-// System.out.println("makeTree ihit: cellID="+MyTools.printID(cellid)
-// +", layer "+segm.getLayer()
-// +", dens="+idens);
+ if(_debug>1) {
+ System.out.println("makeTree ihit: cellid="+MyTools.printID(cellid)
+ +" "+idens+", rawE="+ihit.getRawEnergy());
+ }
double maxdensDiff = -999999.;
+ double parDensity = -1;
long maxdensID = -999999;
- Vector<Long> nVec = new Vector<Long>();
+ List<Long> nVec = new ArrayList<Long>();
// changed from !=0
if(idens>=0.0) {
double[] ipos = ihit.getPosition();
@@ -170,58 +180,60 @@
}
}
-// int neigh[] = segm.getNeighbors(cellid,_nLyr,_nZ,_nPhi);
-// if(_calType=="HD") System.out.println("window in directed tree "+_nLyr+" "+_nZ+" "+_nPhi);
- segm.setID(cellid);
// System.out.println("Processing ihit: cellID="+MyTools.printID(cellid));
- long neigh[] = segm.getNeighbourIDs(_nLyr, _nZ, _nPhi);
-
- for(int j=0; j<neigh.length; j++){
- long jid = neigh[j];
- CalorimeterHit jhit = cahitmap.get(jid);
- if(jhit==null) continue;
- double jdens = _loader.getDensity(jhit);
- double[] jpos = jhit.getPosition();
-
- _distType = _rcp.getDistanceType();
- CalculateDistance calcD = new CalculateDistance();
- double distance = calcD.CalculateDistance(_distType,ipos,jpos);
- double densDiff = (jdens-idens)/distance;
+ segm.setID(cellid);
+ long neigh[] = segm.getNeighbourIDs(_nLyr, _nZ, _nPhi);
+ for(int j=0; j<neigh.length; j++){
+ long jid = neigh[j];
+ CalorimeterHit jhit = cahitmap.get(jid);
+ if(jhit==null) continue;
+ double jdens = _loader.getDensity(jhit);
+ double[] jpos = jhit.getPosition();
+
+ _distType = _rcp.getDistanceType();
+ CalculateDistance calcD = new CalculateDistance();
+ double distance = calcD.CalculateDistance(_distType,ipos,jpos);
+ double densDiff = (jdens-idens)/distance;
//??? if(distance==0) densDiff=0;
- if(densDiff==0.0) nVec.add(jid);
-// System.out.println(" jhit: layer="+(jid&0x7f)
-// +", cellID="+MyTools.printID(jid)
-// +", idens="+idens
-// +", jdens="+jdens
-// +", dist="+distance
-// +", densDiff="+densDiff);
-
- if(densDiff>maxdensDiff){
- maxdensDiff = densDiff;
- maxdensID = jid;
- }
- calcD = null;
- }
+ if(densDiff==0.0) nVec.add(jid);
+ if(_debug>2) {
+ System.out.println(" jhit: cellID="+MyTools.printID(jid)
+ +", idens="+idens
+ +", jdens="+jdens
+ +", dist="+distance
+ +", densDiff="+densDiff);
+ }
+ if(densDiff>maxdensDiff){
+ maxdensDiff = densDiff;
+ maxdensID = jid;
+ parDensity = jdens;
+ }
+ calcD = null;
+ }
- if(maxdensDiff<0.0){
- RootVec.add(ihit);
-// System.out.println("Bonafide root");
- }
+ if(maxdensDiff<0.0){
+ RootVec.add(ihit);
+ if(_debug>1) System.out.println("Bonafide root");
+ }
- if(maxdensDiff>0.0){
- Long key1 = new Long(cellid);
- Long key2 = new Long(maxdensID);
- _ParentMap.put(key1,key2);
-// System.out.println(" maxdensDiff>0: "
-// +" id="+MyTools.printID(maxdensID)
-// +", parent of "+MyTools.printID(cellid));
- }
+ if(maxdensDiff>0.0){
+ Long key1 = new Long(cellid);
+ Long key2 = new Long(maxdensID);
+ _ParentMap.put(key1,key2);
+ if(_debug>1) {
+ System.out.println(" maxdensDiff>0: id="
+ +MyTools.printID(cellid)
+ +" --> parent is "
+ +MyTools.printID(maxdensID)
+ +", D="+parDensity );
+ }
+ }
if(maxdensDiff==0.0){
- Vector<Long> removeItems = new Vector<Long>();
+ List<Long> removeItems = new ArrayList<Long>();
for(Long jkey : nVec) {
- Vector<Long> temporary = new Vector<Long>();
+ List<Long> temporary = new ArrayList<Long>();
Long parent = _ParentMap.get(jkey);
while(parent!=null){
@@ -252,18 +264,18 @@
}
}
_ParentMap.put(cellid,parentKey);
-// System.out.println("Cell is matched to identical density neighbor");
+ if(_debug>1) System.out.println("Cell is matched to identical density neighbor");
}
}
}
else{
RootVec.add(ihit);
-// System.out.println("Zero density root");
+ if(_debug>1) System.out.println("Zero density root");
}
}
- Vector<CalorimeterHit> startingPoints = new Vector<CalorimeterHit>();
- for( CalorimeterHit ihit : cahitmap.values() ) {
+ List<CalorimeterHit> startingPoints = new ArrayList<CalorimeterHit>();
+ for( CalorimeterHit ihit : sortedHits ) {
long cellid = ihit.getCellID();
boolean isParent = _ParentMap.containsValue(cellid);
boolean isRoot = RootVec.contains(ihit);
@@ -271,18 +283,22 @@
startingPoints.add(ihit);
}
}
- if(_debug>0) {
- System.out.println("# starting points = "+startingPoints.size());
+ if(_debug>1) {
+ System.out.println("# starting points = "+startingPoints.size()
+ +", pars="+_ParentMap.size()
+ +", roots="+RootVec.size());
}
- Vector<Vector<CalorimeterHit>> branches = new Vector<Vector<CalorimeterHit>>();
+ List<List<CalorimeterHit>> branches = new ArrayList<List<CalorimeterHit>>();
for(int i=0;i<startingPoints.size();i++) {
- branches.add( new Vector<CalorimeterHit>() );
+ branches.add( new ArrayList<CalorimeterHit>() );
}
for(int i=0;i<startingPoints.size();i++){
CalorimeterHit ihit = startingPoints.get(i);
branches.get(i).add(ihit);
long cellid = ihit.getCellID();
+ if(_debug>1)
+ System.out.println("Starting point #"+i+": "+MyTools.printID(cellid));
Long key = new Long(cellid);
while(_ParentMap.containsKey(cellid)){
Long jkey = _ParentMap.get(cellid);
@@ -295,20 +311,21 @@
int nTrivial = 0;
int vsiz = RootVec.size();
if(_debug>0) System.out.println("no. of roots = "+vsiz);
- Vector<Vector<CalorimeterHit>> caTrees = new Vector<Vector<CalorimeterHit>>();
- for(int i=0;i<vsiz;i++){
- caTrees.add( new Vector<CalorimeterHit>() );
+ List<List<CalorimeterHit>> caTrees = new ArrayList<List<CalorimeterHit>>();
+ for(int i=0;i<vsiz;i++) {
+ caTrees.add( new ArrayList<CalorimeterHit>() );
}
- for(int i=0;i<vsiz;i++){
+ for(int i=0;i<vsiz;i++) {
CalorimeterHit ihit = RootVec.get(i);
long tmpID = ihit.getCellID();
caTrees.get(i).add(ihit);
for(int j=0;j<startingPoints.size();j++) {
- CalorimeterHit parentHit = branches.get(j).lastElement();
+ List<CalorimeterHit> jbranch = branches.get(j);
+ CalorimeterHit parentHit = jbranch.get( jbranch.size()-1 );
if(parentHit.equals(ihit)) {
- for( CalorimeterHit jhit : branches.get(j) ) {
- if(!caTrees.get(i).contains(jhit)){
+ for( CalorimeterHit jhit : jbranch ) {
+ if(!caTrees.get(i).contains(jhit)) {
caTrees.get(i).add(jhit);
long tmppID = jhit.getCellID();
// System.out.println("Branches id="+MyTools.printID(tmppID));
@@ -317,18 +334,18 @@
}
}
if(_debug>0) {
- if(caTrees.get(i).size()>1) {
+ if(caTrees.get(i).size()>0) {
System.out.println("ROOT id="+MyTools.printID(tmpID)
+", #hits="+caTrees.get(i).size());
}
- else ++nTrivial; // for single-hit clusters
+// else ++nTrivial; // for single-hit clusters
}
}
if(_debug>0) {
System.out.println("*** plus "+nTrivial+" single-hit clusters.");
}
-// for( Vector<MyCalorimeterHit> rootHits : caTrees ) {
+// for( List<MyCalorimeterHit> rootHits : caTrees ) {
// System.out.println("ROOT: #hits="+rootHits.size());
// }
@@ -361,9 +378,25 @@
+", # hits="+hitmap.size());
}
+ String roName = colName.replace("Digi","");
SegmentationBase segm
- = (SegmentationBase)_roMap.get(colName).getSegmentation();
- Vector<Vector<CalorimeterHit>> trees = makeTree(hitmap, segm);
+ = (SegmentationBase)_roMap.get(roName).getSegmentation();
+ List<List<CalorimeterHit>> trees = makeTree(hitmap, segm);
+// if(colName.contains("Ecal")) {
+// Iterator<List<CalorimeterHit>> it = trees.iterator();
+// while(it.hasNext()) {
+// List<CalorimeterHit> clus = it.next();
+// int size = clus.size();
+// if(size>10&&size<20) {
+// System.out.println("Event: "+event.getEventNumber()+", cluster size="+size+" -- List of hits:");
+// Iterator<CalorimeterHit> it2 = clus.iterator();
+// while(it2.hasNext()) {
+// CalorimeterHit hit = it2.next();
+// System.out.println("hit: "+MyTools.printID(hit.getCellID()));
+// }
+// }
+// }
+// }
List<BasicCluster> recoClusColl = new ArrayList<BasicCluster>();
if(trees.size()>0)
lcsim/src/org/lcsim/recon/cluster/directedtree
diff -u -r1.1 -r1.2
--- DTreeAnalysis.java 8 Jan 2006 14:28:22 -0000 1.1
+++ DTreeAnalysis.java 9 Feb 2006 21:17:59 -0000 1.2
@@ -17,11 +17,11 @@
import org.lcsim.recon.cluster.util.CalHitMapMgr;
import org.lcsim.recon.cluster.util.BasicCluster;
import org.lcsim.recon.cluster.util.SortClustersBySize;
-import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.util.BaseIDDecoder;
public class DTreeAnalysis extends Driver {
- private int _debug=1;
+ private int _debug=0;
public DTreeAnalysis() {
_runPar = RunControlParameters.getInstance();
@@ -46,10 +46,10 @@
}
_tree.cd("DirectedTree");
- String embName = "EcalBarrHits";
- String emeName = "EcalEndcapHits";
- String hdbName = "HcalBarrHits";
- String hdeName = "HcalEndcapHits";
+ String embName = "EcalBarrDigiHits";
+ String emeName = "EcalEndcapDigiHits";
+ String hdbName = "HcalBarrDigiHits";
+ String hdeName = "HcalEndcapDigiHits";
embhitmap = _expert.getCollHitMap(embName, _emEcut);
emehitmap = _expert.getCollHitMap(emeName, _emEcut);
hdbhitmap = _expert.getCollHitMap(hdbName, _hdEcut);
@@ -114,7 +114,7 @@
public void fillDirectedTreeNtuple(List<BasicCluster> recon,
List<BasicCluster> mctruth,
- IDDecoder decoder)
+ BaseIDDecoder decoder)
{
if(_calType=="EM"){
emClusFolder = _tupleEM.getTuple(1);
@@ -172,6 +172,7 @@
cellFolder.fill(4,(float)cdens);
cellFolder.fill(5,tag);
cellFolder.fill(6,ily);
+ if(_evtnum==223) System.out.println(_calType+", ily="+ily);
cellFolder.fill(7,iu);
cellFolder.fill(8,iv);
cellFolder.addRow();
@@ -200,6 +201,7 @@
if(_calType=="EM") tag = _nMCClusEM;
if(_calType=="HD") tag = _nMCClusHD;
for( BasicCluster clust : mctruth ) {
+ // loop over all hits on this MCcluster
for( CalorimeterHit ihit : clust.getCalorimeterHits() ) {
Integer tagObject = recTagMap.get(ihit);
@@ -231,6 +233,7 @@
SimCalorimeterHit iihit = (SimCalorimeterHit)ihit;
int npart = iihit.getMCParticleCount();
double timeStamp = 99999.;
+ // loop over contributions to this hit
for(int j=0;j<npart;j++) {
double tmpTime = (double) iihit.getContributedTime(j);
if(tmpTime<timeStamp){
@@ -328,7 +331,7 @@
Map<Long,CalorimeterHit> hitmap)
{
if(hitmap.size()==0) return;
- IDDecoder decoder = _expert.getIDDecoder(colName);
+ BaseIDDecoder decoder = _expert.getIDDecoder(colName);
// get NearestNeighbor clusters
List<BasicCluster> nnClusColl = new ArrayList<BasicCluster>();
@@ -350,7 +353,7 @@
// get MC clusters
List<BasicCluster> mcClusColl
- = event.get(BasicCluster.class, colName+"Clusters");
+ = event.get(BasicCluster.class, colName+"CheatClusters");
Collections.sort( mcClusColl, new SortClustersBySize() );
if(_debug>0) {