LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  December 2014

HPS-SVN December 2014

Subject:

r1646 - /java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCSignalPlotsDriver.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Thu, 4 Dec 2014 00:04:46 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (188 lines)

Author: [log in to unmask]
Date: Wed Dec  3 16:04:42 2014
New Revision: 1646

Log:
Convert signal analysis to use Profile1D instead of Histogram1D.

Modified:
    java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCSignalPlotsDriver.java

Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCSignalPlotsDriver.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCSignalPlotsDriver.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCSignalPlotsDriver.java	Wed Dec  3 16:04:42 2014
@@ -1,12 +1,16 @@
 package org.hps.users.jeremym;
 
 import hep.aida.IAnalysisFactory;
-import hep.aida.IHistogram1D;
+import hep.aida.IProfile1D;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import org.hps.conditions.database.TableConstants;
 import org.hps.conditions.ecal.EcalChannel;
@@ -24,24 +28,31 @@
 /**
  * This Driver will process ECAL raw mode (window) data and extract hits 
  * that look like signal, by requiring a certain number of ADC samples
- * in a row that are above a sigma threshold.
+ * in a row that are above a sigma threshold.  For events with number
+ * of hits greater than a minimum (5 by default), it will convert
+ * the raw data into CalorimeterHits and write them to an output
+ * collection.
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalADCSignalPlotsDriver extends Driver {
 
     EcalConditions conditions = null;
     EcalChannelCollection channels = null;
-
-    Map<EcalChannel, Double[]> channelADCValues = new HashMap<EcalChannel, Double[]>();
-    Map<EcalChannel, Integer> channelEventCounts = new HashMap<EcalChannel, Integer>();
+    
+    Map<EcalChannel, IProfile1D> signalProfiles = new HashMap<EcalChannel, IProfile1D>();
+    Map<EcalChannel, IProfile1D> backgroundProfiles = new HashMap<EcalChannel, IProfile1D>();
+    
     AIDA aida = AIDA.defaultInstance();
     IAnalysisFactory analysisFactory = aida.analysisFactory();
     double sigmaThreshold = 2.5;
-    int minimumSelectedHits = 3;
+    
+    int minimumSelectedSamples = 3;
+    int minimumNumberOfHits = 3;
+    int minNeighbors = 2;
     String outputHitsCollectionName = null;
     String inputHitsCollectionName = "EcalReadoutHits";
     HPSEcal3 ecal = null;
-    String ecalName = "Ecal";
+    static String ecalName = "Ecal";
 
     /**
      * Set the sigma threshold for an ADC value.
@@ -56,8 +67,12 @@
      * saved for the event.
      * @param selectedHits The minimum number of hits above threshold.
      */
-    public void setMinimumHits(int selectedHits) {
-        this.minimumSelectedHits = selectedHits;
+    public void setMinimumSelectedSamples(int minimumSelectedSamples) {
+        this.minimumSelectedSamples = minimumSelectedSamples;
+    }
+    
+    public void setMinimumNumberOfHits(int minimumNumberOfHits) {
+        this.minimumNumberOfHits = minimumNumberOfHits;
     }
     
     public void setOutputHitsCollectionName(String outputHitsCollectionName) {
@@ -68,13 +83,9 @@
         ecal = (HPSEcal3)detector.getSubdetector(ecalName);
         conditions = ConditionsManager.defaultInstance().getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
         channels = conditions.getChannelCollection();
-        for (EcalChannel channel : conditions.getChannelCollection()) {
-            channelADCValues.put(channel, new Double[100]);
-            channelEventCounts.put(channel, new Integer(0));            
-            Double[] adcValues = channelADCValues.get(channel); 
-            for (int adcSample = 0; adcSample < adcValues.length; adcSample++) {
-                adcValues[adcSample] = new Double(0.0);                
-            }
+        for (EcalChannel channel : conditions.getChannelCollection()) {            
+            signalProfiles.put(channel, aida.profile1D("Average Signal ADC Values : " + String.format("%03d", channel.getChannelId()), 100, 0, 100));
+            backgroundProfiles.put(channel, aida.profile1D("Average Background ADC Values : " + String.format("%03d", channel.getChannelId()), 100, 0, 100));
         }
     }
 
@@ -85,10 +96,6 @@
             for (RawTrackerHit hit : hits) {
                 EcalChannel channel = channels.findGeometric(hit.getCellID());
                 if (channel != null) {
-                    Double[] adcValues = channelADCValues.get(channel);
-                    if (adcValues == null) {
-                        throw new RuntimeException("The ADC values array is null.");
-                    }
                     int nSelectedHits = 0;
                     boolean saveHit = false;
                     EcalChannelConstants channelConstants = conditions.getChannelConstants(channel);
@@ -99,7 +106,7 @@
                         short adcValue = hit.getADCValues()[adcIndex];
                         if (adcValue > threshold) {
                             ++nSelectedHits;
-                            if (nSelectedHits >= minimumSelectedHits) {
+                            if (nSelectedHits >= minimumSelectedSamples) {
                                 saveHit = true;
                                 break adcThresholdLoop;
                             }
@@ -107,41 +114,37 @@
                             nSelectedHits = 0;
                         }                        
                     }
+                    
+                    // Pick the signal or background Profile1D based on the selection.
+                    IProfile1D profile = null;
                     if (saveHit) {
-                        for (int adcIndex = 0; adcIndex < hit.getADCValues().length; adcIndex++) {
-                            adcValues[adcIndex] += hit.getADCValues()[adcIndex];
-                        }
-                        Integer nEvents = channelEventCounts.get(channel);
-                        nEvents += 1;
-                        channelEventCounts.put(channel, nEvents);
-                        
-                        // Add hit to selected hits list.
+                        profile = signalProfiles.get(channel);
                         selectedHitsList.add(hit);
+                    } else {
+                        profile = backgroundProfiles.get(channel);
                     }
+                    
+                    // Fill the Profile1D.
+                    for (int adcIndex = 0; adcIndex < hit.getADCValues().length; adcIndex++) {
+                        profile.fill(adcIndex, hit.getADCValues()[adcIndex]);
+                    }                    
                 } else {
                     System.err.println("EcalChannel not found for cell ID 0x" + String.format("%08d", Long.toHexString(hit.getCellID())));
                 }
             }
-            
-            if (outputHitsCollectionName != null) {
-                // Save selected hits list to event.
-                event.put(outputHitsCollectionName, selectedHitsList, RawTrackerHit.class, event.getMetaData(hits).getFlags(), ecal.getReadout().getName());
-            }
+                        
+            if (outputHitsCollectionName != null) {     
+                // Is number of hits above minimum?
+                if (selectedHitsList.size() >= this.minimumNumberOfHits) {
+                    // Save selected hits list to event.
+                    getLogger().info("writing " + selectedHitsList.size() + " hits into " + outputHitsCollectionName);
+                    event.put(outputHitsCollectionName, selectedHitsList, RawTrackerHit.class, event.getMetaData(hits).getFlags(), ecal.getReadout().getName());
+                } else {
+                    // Skip this event so LCIODriver does not write this event.
+                    throw new NextEventException();
+                }
+            }                        
         }
     }
 
-    public void endOfData() {
-        for (EcalChannel channel : conditions.getChannelCollection()) {
-            int nEvents = channelEventCounts.get(channel);
-            IHistogram1D channelHistogram = aida.histogram1D("Average Signal ADC Values : " + channel.getChannelId(), 100, 0, 100);
-            Double[] adcValues = channelADCValues.get(channel);
-            for (int adcIndex = 0; adcIndex < adcValues.length; adcIndex++) {
-                // Calculate the average ADC value across number of events processed for this channel.
-                double averageAdcValue = adcValues[adcIndex] / nEvents;
-                
-                // Fill the ADC sample's bin, scaling by the ADC value.
-                channelHistogram.fill(adcIndex, averageAdcValue);
-            }
-        }
-    }
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use