Print

Print


Author: [log in to unmask]
Date: Wed Nov  5 15:05:58 2014
New Revision: 1444

Log:
First working version of Eng Run EVIO to LCIO conversion for ECAL data.

Modified:
    java/trunk/evio/src/main/java/org/hps/evio/LCSimEngRunEventBuilder.java
    java/trunk/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java

Modified: java/trunk/evio/src/main/java/org/hps/evio/LCSimEngRunEventBuilder.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/LCSimEngRunEventBuilder.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/LCSimEngRunEventBuilder.java	Wed Nov  5 15:05:58 2014
@@ -1,7 +1,12 @@
 package org.hps.evio;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.hps.readout.ecal.SSPData;
 import org.hps.readout.ecal.TriggerData;
+import org.jlab.coda.jevio.EvioEvent;
+import org.lcsim.event.EventHeader;
 
 /**
  * Build LCSim events from EVIO data.
@@ -9,24 +14,52 @@
  * @author Sho Uemura <[log in to unmask]>
  * @author Jeremy McCormick <[log in to unmask]>
  * @version $Id: LCSimTestRunEventBuilder.java,v 1.24 2013/03/01 01:30:25 meeg
- * Exp $
+ *          Exp $
  */
 public class LCSimEngRunEventBuilder extends LCSimTestRunEventBuilder {
 
-    public LCSimEngRunEventBuilder() {
-        ecalReader.setTopBankTag(0x25);
-        ecalReader.setBotBankTag(0x27);
-        sspCrateBankTag = 0x25;
-        sspBankTag = 0xe10c;
-//        ecalReader = new ECalEvioReader(0x25, 0x27);
-//        svtReader = new SVTEvioReader();
-    }
+	public LCSimEngRunEventBuilder() {
+		ecalReader.setTopBankTag(0x25);
+		ecalReader.setBotBankTag(0x27);
+		sspCrateBankTag = 0x25;
+		sspBankTag = 0xe10c;
+		// ecalReader = new ECalEvioReader(0x25, 0x27);
+		// svtReader = new SVTEvioReader();
+	}
 
-    protected TriggerData makeTriggerData(int[] data) {
-        TriggerData triggerData = new SSPData(data);
-        time = ((long) triggerData.getTime()) * 4;
-        return triggerData;
-    }
+	protected TriggerData makeTriggerData(int[] data) {
+		TriggerData triggerData = new SSPData(data);
+		time = ((long) triggerData.getTime()) * 4;
+		return triggerData;
+	}
 
+	@Override
+	public EventHeader makeLCSimEvent(EvioEvent evioEvent) {
+		if (!isPhysicsEvent(evioEvent)) {
+			throw new RuntimeException("Not a physics event: event tag " + evioEvent.getHeader().getTag());
+		}
+
+		// Create a new LCSimEvent.
+		EventHeader lcsimEvent = getEventData(evioEvent);
+
+		// Make RawCalorimeterHit collection, combining top and bottom section
+		// of ECal into one list.
+		try {
+			ecalReader.makeHits(evioEvent, lcsimEvent);
+		} catch (Exception e) {
+			Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error making ECal hits", e);
+		}
+
+		// Commented out for now while SVT is not implemented.  --JM
+		// Make SVT RawTrackerHits
+		// try {
+		// svtReader.makeHits(evioEvent, lcsimEvent);
+		// } catch (Exception e) {
+		// Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
+		// "Error making SVT hits", e);
+		// }
+
+		return lcsimEvent;
+	}
 
 }

Modified: java/trunk/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java
 =============================================================================
--- java/trunk/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java	(original)
+++ java/trunk/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java	Wed Nov  5 15:05:58 2014
@@ -15,62 +15,67 @@
 import org.lcsim.util.test.TestUtil.TestOutputFile;
 
 /**
- * Test conversion of EVIO to LCIO for Engineering Run EVIO data.
- * This is ECAL data only for now.
+ * Test conversion of EVIO to LCIO for Engineering Run EVIO data. This is ECAL
+ * data only for now.
+ * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class LCSimEngRunEventBuilderTest extends TestCase {
-		
+
 	public void testLCSimEngRunEventBuilder() throws Exception {
-	
+
 		// Setup database conditions.
 		DatabaseConditionsManager conditionsManager = new DatabaseConditionsManager();
 		conditionsManager.setConnectionResource("/org/hps/conditions/config/conditions_dev.properties");
 		conditionsManager.configure("/org/hps/conditions/config/conditions_dev.xml");
 		conditionsManager.register();
-		conditionsManager.setDetector("HPS-Proposal2014-v8-6pt6", 0);
-		
+		conditionsManager.setDetector("HPS-Proposal2014-v8-6pt6", 2000);
+
 		// Configure LCIO writer.
 		new TestOutputFile(getClass().getSimpleName()).mkdirs();
 		File lcioFile = new TestOutputFile(getClass().getSimpleName() + File.separator + getClass().getSimpleName() + "_output.slcio");
-        LCIOWriter writer;
+		LCIOWriter writer;
 		try {
-            writer = new LCIOWriter(lcioFile);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-		
+			writer = new LCIOWriter(lcioFile);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+
 		// Create event builder.
 		LCSimEventBuilder builder = new LCSimEngRunEventBuilder();
 		builder.setDetectorName("HPS-Proposal2014-v8-6pt6");
-		
+
 		// Get remote test file.
 		FileCache cache = new FileCache();
 		File evioFile = cache.getCachedFile(new URL("http://www.lcsim.org/test/hps-java/LCSimEngRunEventBuilderTest/hps_002744.evio.0"));
 
 		// Open the EVIO reader.
-        System.out.println("Opening file " + evioFile);
-        EvioReader reader = null;
-        try {
-            reader = new EvioReader(evioFile);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-        
-        // Run the event builder on the EVIO.
-        EvioEvent evioEvent = null;
-        while ((evioEvent = reader.nextEvent()) != null) {
-        	reader.parseEvent(evioEvent);
-    		builder.readEvioEvent(evioEvent);
-        	if (builder.isPhysicsEvent(evioEvent)) {
-        		EventHeader lcsimEvent = builder.makeLCSimEvent(evioEvent);
-        		System.out.println("created LCSim event #" + lcsimEvent.getEventNumber());
-        		writer.write(lcsimEvent);
-        	}
-        }
-        
-        // Close the LCIO writer.
-        writer.flush();
-        writer.close();
+		System.out.println("Opening file " + evioFile);
+		EvioReader reader = null;
+		try {
+			reader = new EvioReader(evioFile);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+
+		// Run the event builder on the EVIO.
+		EvioEvent evioEvent = null;
+		while ((evioEvent = reader.nextEvent()) != null) {
+			reader.parseEvent(evioEvent);
+			builder.readEvioEvent(evioEvent);
+			if (EventConstants.isPhysicsEvent(evioEvent)) {
+				try {
+					EventHeader lcsimEvent = builder.makeLCSimEvent(evioEvent);
+					System.out.println("created LCSim event #" + lcsimEvent.getEventNumber());
+					writer.write(lcsimEvent);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+		}
+
+		// Close the LCIO writer.
+		writer.flush();
+		writer.close();
 	}
 }