View Javadoc

1   package org.lcsim.recon.calorimetry;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.lcsim.event.EventHeader;
7   import org.lcsim.event.SimCalorimeterHit;
8   import org.lcsim.event.EventHeader.LCMetaData;
9   import org.lcsim.event.base.BaseLCSimEvent;
10  import org.lcsim.util.Driver;
11  
12  /**
13   * Helper class to select instrumented layers in a calorimeter collection and remove all the other hits from the collection.
14   * @author <a href="mailto:christian.grefe@cern.ch">Christian Grefe</a>
15   *
16   */
17  public class CalorimeterLayerSelector extends Driver {
18  
19  	protected String caloCollection = "";
20  	protected List<Integer> activeLayers;
21  	
22  	public CalorimeterLayerSelector() {
23  		
24  	}
25  	
26  	public void setCollectionName(String collectionName) {
27  		this.caloCollection = collectionName;
28  		this.activeLayers = new ArrayList<Integer>();
29  	}
30  	
31  	public void setActiveLayers(int[] layers) {
32  		activeLayers.clear();
33  		for (int i = 0; i != layers.length; i++) {
34  			activeLayers.add(layers[i]);
35  		}
36  	}
37  	
38  	@Override
39  	protected void process(EventHeader event) {
40  		List<SimCalorimeterHit> caloHits = new ArrayList<SimCalorimeterHit>();
41  		try {
42  			caloHits = event.get(SimCalorimeterHit.class, caloCollection);
43  		} catch (Exception e) {
44  			System.err.println("Error: Collection "+caloCollection+" does not exist.");
45  			return;
46  		}
47  		if (this.getHistogramLevel() > HLEVEL_NORMAL) {
48  			System.out.println("Removing calorimeter hits from "+caloCollection+" for all layers except:");
49  			for (int layer : activeLayers) {
50  				System.out.println("\tLayer "+layer);
51  			}
52  		}
53  		
54  		List<SimCalorimeterHit> hitsToKeep = new ArrayList<SimCalorimeterHit>();
55  		
56  		for (SimCalorimeterHit hit : caloHits) {
57  			if (activeLayers.contains(hit.getLayerNumber())) {
58  				hitsToKeep.add(hit);
59  			}
60  		}
61  		
62  		caloHits.clear();
63  		caloHits.addAll(hitsToKeep);
64  	}
65  }