Print

Print


Commit in lcsim/src/org/lcsim/recon/calorimetry on MAIN
ResetCalorimeterHitEnergy.java+85added 1.1
Driver to re-calculate total energy of SimCalorimeterHits from the sum of all contributions

lcsim/src/org/lcsim/recon/calorimetry
ResetCalorimeterHitEnergy.java added at 1.1
diff -N ResetCalorimeterHitEnergy.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ResetCalorimeterHitEnergy.java	15 Aug 2012 08:16:48 -0000	1.1
@@ -0,0 +1,85 @@
+package org.lcsim.recon.calorimetry;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.base.BaseSimCalorimeterHit;
+import org.lcsim.util.Driver;
+import org.lcsim.util.lcio.LCIOConstants;
+import org.lcsim.util.lcio.LCIOUtil;
+
+
+
+/**
+ * Driver to re-calculate the raw energy of all SimCalorimeterHits from the sum of their energy contributions. 
+ * 
+ * @author <a href="mailto:[log in to unmask]">Christian Grefe</a>
+ */
+public class ResetCalorimeterHitEnergy extends Driver {
+	
+	protected List<String> ignoreCollections;
+	
+	public ResetCalorimeterHitEnergy() {
+		ignoreCollections = new ArrayList<String>();
+	}
+	
+	public void setIgnoreCollection(String collectionName) {
+		ignoreCollections.add(collectionName);
+	}
+	
+	public void setIgnoreCollcetions(String[] collectionNames) {
+		ignoreCollections.addAll(Arrays.asList(collectionNames));
+	}
+	
+	@Override
+	protected void process(EventHeader event) {
+		
+		List<List<SimCalorimeterHit>> caloHitCollections = event.get(SimCalorimeterHit.class);
+		
+		for (List<SimCalorimeterHit> caloHitCollection : caloHitCollections) {
+			LCMetaData metaData = event.getMetaData(caloHitCollection);
+			String collectionName = metaData.getName();
+			if (ignoreCollections.contains(collectionName)) {
+				continue;
+			}
+			boolean hasPDG = LCIOUtil.bitTest(metaData.getFlags(),LCIOConstants.CHBIT_PDG);
+			List<SimCalorimeterHit> resetHits = new ArrayList<SimCalorimeterHit>();
+			for (SimCalorimeterHit caloHit : caloHitCollection) {
+				long id = caloHit.getCellID();
+				double totalEnergy = caloHit.getRawEnergy();
+				double time = caloHit.getTime();
+				int nMCP = caloHit.getMCParticleCount();
+				Object[] mcparts = new Object[nMCP];
+				float[] energies = new float[nMCP];
+				float[] times = new float[nMCP];
+				int[] pdgs = null;
+				List<float[]> steps = new ArrayList<float[]>();
+				if (hasPDG) pdgs = new int[nMCP];
+				// fill arrays with values from hit
+				for (int i = 0; i != nMCP; i++) {
+					mcparts[i] = caloHit.getMCParticle(i);
+					energies[i] = (float) caloHit.getContributedEnergy(i);
+					totalEnergy += energies[i];
+					times[i] = (float) caloHit.getContributedTime(i);
+					if (hasPDG){
+						pdgs[i] = caloHit.getPDG(i);
+						steps.add(caloHit.getStepPosition(i));
+					}
+				}
+				
+				BaseSimCalorimeterHit resetHit = new BaseSimCalorimeterHit(id, totalEnergy, time, mcparts, energies, times, pdgs, steps);
+				//resetHit.setDetectorElement(hit.getDetectorElement());
+				resetHit.setMetaData(metaData);
+				resetHits.add(resetHit);
+			}
+			caloHitCollection.clear();
+			caloHitCollection.addAll(resetHits);
+		}
+		
+	}
+
+}
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1