Print

Print


Commit in lcsim/src/org/lcsim/recon/cluster/directedtree on MAIN
DirectedTreeClusterer.java+115-481.3 -> 1.4
GL: first attempt to make it usable from template scheme

lcsim/src/org/lcsim/recon/cluster/directedtree
DirectedTreeClusterer.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- DirectedTreeClusterer.java	20 Feb 2006 22:48:12 -0000	1.3
+++ DirectedTreeClusterer.java	15 Mar 2006 12:27:43 -0000	1.4
@@ -38,40 +38,49 @@
 	// load readout map (decoders)
         _roMap = event.getDetector().getReadouts();
 
-	// load hit maps
- 	String embName = "EcalBarrDigiHits";
- 	String emeName = "EcalEndcapDigiHits";
- 	String hdbName = "HcalBarrDigiHits";
- 	String hdeName = "HcalEndcapDigiHits";
- 	embhitmap = _expert.getCollHitMap(embName);
- 	emehitmap = _expert.getCollHitMap(emeName);
- 	hdbhitmap = _expert.getCollHitMap(hdbName);
- 	hdehitmap = _expert.getCollHitMap(hdeName);
-
- 	// define densities
- 	_loader.setDensities(embName, embhitmap);
- 	_loader.setDensities(emeName, emehitmap);
- 	_loader.setDensities(hdbName, hdbhitmap);
- 	_loader.setDensities(hdeName, hdehitmap);
+	if( underUserControl() ) {
+	    // Assumes that collection is a hitmap.  Failure otherwise.
+	    Map<Long,CalorimeterHit> hitmap = new HashMap<Long,CalorimeterHit>( (Map<Long,CalorimeterHit>)event.get(_inputHitMapName) );
 
-	if(_debug>0) {
-	    System.out.println("DTree: #hits: EMB="+embhitmap.size()
-			       +", EMEC="+emehitmap.size()
-			       +", HB="+hdbhitmap.size()
-			       +", HEC="+hdehitmap.size());
+	    processCollection(event, _inputHitMapName, hitmap);
 	}
 
-        if(_rcp.ClusterSeparately()) {
-            _calType = "EM";
-	    processCollection(event, embName, embhitmap);
-  	    processCollection(event, emeName, emehitmap);
-
-            _calType = "HD";
-	    processCollection(event, hdbName, hdbhitmap);
-  	    processCollection(event, hdeName, hdehitmap);
-        }
-        else {
-	  assert false : "Sorry, single-pass clustering unavailable for now.";
+        else {  // originally, input collections were lists rather than maps
+	    // from lists...
+	    String embName = "EcalBarrDigiHits";
+	    String emeName = "EcalEndcapDigiHits";
+	    String hdbName = "HcalBarrDigiHits";
+	    String hdeName = "HcalEndcapDigiHits";
+	    // ... get hitmaps
+	    embhitmap = _expert.getCollHitMap(embName);
+	    emehitmap = _expert.getCollHitMap(emeName);
+	    hdbhitmap = _expert.getCollHitMap(hdbName);
+	    hdehitmap = _expert.getCollHitMap(hdeName);
+
+	    // define densities
+	    _loader.setDensities(embName, embhitmap);
+	    _loader.setDensities(emeName, emehitmap);
+	    _loader.setDensities(hdbName, hdbhitmap);
+	    _loader.setDensities(hdeName, hdehitmap);
+
+	    if(_debug>0) {
+		System.out.println("DTree: #hits: EMB="+embhitmap.size()
+				   +", EMEC="+emehitmap.size()
+				   +", HB="+hdbhitmap.size()
+				   +", HEC="+hdehitmap.size());
+	    }
+
+	    if(_rcp.ClusterSeparately()) {
+		_calType = "EM";
+		processCollection(event, embName, embhitmap);
+		processCollection(event, emeName, emehitmap);
+
+		_calType = "HD";
+		processCollection(event, hdbName, hdbhitmap);
+		processCollection(event, hdeName, hdehitmap);
+	    }
+	    else {
+		assert false : "Sorry, single-pass DTree clustering unavailable for now.";
 //             Vector calhit = new Vector();
 //             calhit.addAll(embhit.values());
 //             calhit.addAll(emehit.values());
@@ -88,12 +97,13 @@
 
 //             ClusterBuilder clus = new ClusterBuilder();
 //             List caClusters = clus.makeClusters(calTrees,_rcp);
-        }
+	    }
+	}
 
     }
 
     public List<List<CalorimeterHit>>
-	makeTree(Map<Long,CalorimeterHit> cahitmap, SegmentationBase segm) {
+	makeTree(Map<Long,CalorimeterHit> cahitmap, SegmentationBase segBase) {
 
 	if(_debug>0) {
 	  System.out.println("makeTree: cahitmap size="+cahitmap.size());
@@ -109,11 +119,22 @@
             long cellid = ihit.getCellID();
             double idens = _loader.getDensity( cellid );
 
+	    SegmentationBase segm = segBase;
+	    if(underUserControl()) segm = (SegmentationBase)ihit.getIDDecoder();
 	    segm.setID(cellid);
-    	    if(_debug>1) {
-		System.out.println("makeTree ihit: cellid="+MyTools.printID(cellid)
-				   +" "+idens+", rawE="+ihit.getRawEnergy());
-	    }
+     	    if(_debug>1) {
+	    double mcpE = ((org.lcsim.event.SimCalorimeterHit)ihit).getMCParticle(0).getEnergy();
+		System.out.println("DTree: hit ID="+MyTools.printID(cellid)
+				   +", dens="+idens
+				   +", rawE="+ihit.getRawEnergy()
+				   +", mcpE="+mcpE);
+ 	    }
+
+	    assert !underUserControl() : "*** DTree: need to set calType properly before proceeding";
+// 	    int sysno = segm.getSystem();
+// 	    if(sysno==) _calType = "EM";
+// 	    if(sysno==) _calType = "HD";
+// 	    System.out.println("Sysno="+sysno);
 
             double maxdensDiff = -999999.;
 	    double parDensity = -1;
@@ -178,9 +199,8 @@
 		 }
 	       }
 
-//  		System.out.println("Processing ihit: cellID="+MyTools.printID(cellid));
-	       segm.setID(cellid);
-	       long neigh[] = segm.getNeighbourIDs(_nLyr, _nZ, _nPhi);
+	       // find hit neighbors
+ 	       long neigh[] = segm.getNeighbourIDs(_nLyr, _nZ, _nPhi);
 	       for(int j=0; j<neigh.length; j++){
 		 long jid = neigh[j];
 		 CalorimeterHit jhit = cahitmap.get(jid);
@@ -192,16 +212,15 @@
 		 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);
-		 if(_debug>2) {
+  		 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;
@@ -398,11 +417,15 @@
 
       List<BasicCluster> recoClusColl = new ArrayList<BasicCluster>();
       if(trees.size()>0)
-	  recoClusColl = clusBuilder.makeClusters( trees );
-      if (recoClusColl.size() > 0) {
+	  recoClusColl = _clusBuilder.makeClusters( trees );
+
+      // Append clusters to the event
+      if( underUserControl() ) {
+	  event.put( _outputClusterListName, recoClusColl, Cluster.class, _flags);
+      }
+      else if (recoClusColl.size() > 0) {
 	  String newName = new String(colName+"DTreeClusters");
-	  int flags = 1<<31;  // store hits in clusters
-	  event.put( newName, recoClusColl, Cluster.class, flags );
+	  event.put( newName, recoClusColl, Cluster.class, _flags );
       }
 
 //       int nhits = hitmap.size();
@@ -413,6 +436,43 @@
 //       aida.cloud1D(colName+"-numCheatClusters").fill(nclusCheat);
     }
 
+    /** set name of collection of hits to be clustered */
+    public void setInputHitMap(String name) {
+	_inputHitMapName = name;
+	if(_inputHitMapName.contains("Ecal")) _calType = "EM";
+	if(_inputHitMapName.contains("EM")) _calType = "EM";
+	if(_inputHitMapName.contains("Hcal")) _calType = "HD";
+	if(_inputHitMapName.contains("HAD")) _calType = "HD";
+	if(_inputHitMapName.contains("HD")) _calType = "HD";
+	this.setUserControl();
+    }
+
+    /** set name of output hit map with left-over hits */
+    public void setOutputHitMap(String name) {
+	_outputHitMapName = name;
+	this.setUserControl();
+    }
+
+    /** set name of output collection of clusters reconstructed */
+    public void setOutputClusterList(String name) {
+	_outputClusterListName = name;
+	this.setUserControl();
+    }
+
+    private void setUserControl() {
+	if( !_outputHitMapName.equals("") &&
+	    !_outputClusterListName.equals("") &&
+	    !_outputClusterListName.equals("") ) {
+	    _userControl = true;
+	}
+    }
+
+    public boolean underUserControl() {
+	return _userControl;
+    }
+
+    // *** FIELDS ***
+
     private static Map<String,Readout> _roMap;
     private static RunControlParameters _rcp;
     private LoadMyCalorimeterHit _loader = LoadMyCalorimeterHit.getInstance();
@@ -425,5 +485,12 @@
     private int _nPhi;
     private int _evtnum;
 
-    private ClusterBuilder clusBuilder = new ClusterBuilder();
+    private ClusterBuilder _clusBuilder = new ClusterBuilder();
+    private int _flags = 1<<31; // store hits in clusters
+
+    // collection names for user steering
+    private String _inputHitMapName = "";
+    private String _outputHitMapName = "";
+    private String _outputClusterListName = "";
+    private boolean _userControl = false;
 }
CVSspam 0.2.8