Author: [log in to unmask]
Date: Tue Feb 3 13:04:17 2015
New Revision: 2031
Log:
Changed from array of pedestals to Map<RawCalorimeterHit,pedestal>
Modified:
java/trunk/users/src/main/java/org/hps/users/baltzell/ECalRunningPedestalDriver.java
java/trunk/users/src/main/java/org/hps/users/baltzell/EcalRawConverter_RunPed.java
Modified: java/trunk/users/src/main/java/org/hps/users/baltzell/ECalRunningPedestalDriver.java
=============================================================================
--- java/trunk/users/src/main/java/org/hps/users/baltzell/ECalRunningPedestalDriver.java (original)
+++ java/trunk/users/src/main/java/org/hps/users/baltzell/ECalRunningPedestalDriver.java Tue Feb 3 13:04:17 2015
@@ -1,7 +1,9 @@
package org.hps.users.baltzell;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hps.conditions.database.TableConstants;
import org.hps.conditions.ecal.EcalChannel;
@@ -18,6 +20,7 @@
/**
* Calculate a running pedestal average for every channel from Mode7 FADCs.
+ *
* @version $Id: ECalRunningPedestalDriver.java,v 0.0 2015/01/31 00:00:00
* @author <[log in to unmask]>
*/
@@ -25,15 +28,15 @@
// limit array lengths:
private final int limitLookbackEvents = 1000;
-
+
// minimum number of readouts for running averages:
// (if not satisfied, use pedestals from database)
private int minLookbackEvents = 10;
-
+
// maximum number of readouts for running averages:
// (if too many, discard the oldest ones)
private int maxLookbackEvents = 100;
-
+
// oldest allowed time for running averages:
// (discard older readouts ; negative = no time limit)
private long maxLookbackTime = -1; // units = ms
@@ -47,7 +50,7 @@
// running pedestal averages, one for each channel:
private List<Double> runningPedestals = new ArrayList<Double>(nChannels);
-
+
// FIXME:
// recent event-by-event pedestals and timestamps:
private List<Integer>[] eventPedestals = (ArrayList<Integer>[]) new ArrayList[nChannels];
@@ -56,8 +59,6 @@
private boolean debug = false;
private EcalConditions ecalConditions = null;
-
-
public ECalRunningPedestalDriver() {
for (int ii = 0; ii < nChannels; ii++) {
eventPedestals[ii] = new ArrayList<>();
@@ -65,6 +66,7 @@
runningPedestals.add(-1.);
}
}
+
@Override
protected void startOfData() {
}
@@ -74,30 +76,34 @@
ecalConditions = ConditionsManager.defaultInstance()
.getCachedConditions(EcalConditions.class,TableConstants.ECAL_CONDITIONS)
.getCachedData();
- for (int ii=0; ii<nChannels; ii++) {
- runningPedestals.set(ii,getStaticPedestal(ii+1));
- }
- if (debug){
+ for (int ii = 0; ii < nChannels; ii++) {
+ runningPedestals.set(ii,getStaticPedestal(ii + 1));
+ }
+ if (debug) {
+ System.out.println("Running and static pedestals better match here:");
printPedestals();
}
}
+
public void setMinLookbackEvents(int nev) {
- if (nev<1){
- System.err.println(
- "ECalRunningPedestalDriver: MinLookbackEvents too small. Setting to 1.");
- nev=1;
+ if (nev < 1) {
+ System.err
+ .println("ECalRunningPedestalDriver: MinLookbackEvents too small. Setting to 1.");
+ nev = 1;
}
minLookbackEvents = nev;
}
+
public void setMaxLookbackEvents(int nev) {
- if (nev>limitLookbackEvents){
- System.err.println(
- "ECalRunningPedestalDriver: MaxLookbackEvents too big. Setting to "
- +limitLookbackEvents+".");
- nev=limitLookbackEvents;
+ if (nev > limitLookbackEvents) {
+ System.err
+ .println("ECalRunningPedestalDriver: MaxLookbackEvents too big. Setting to "
+ + limitLookbackEvents + ".");
+ nev = limitLookbackEvents;
}
maxLookbackEvents = nev;
}
+
public void setMaxLookbackTime(int time) {
maxLookbackTime = time;
}
@@ -112,31 +118,28 @@
@Override
protected void process(EventHeader event) {
+
if (!event.hasCollection(RawCalorimeterHit.class,rawCollectionName))
return;
if (!event.hasCollection(LCRelation.class,extraDataRelationsName))
return;
+
+ Map<RawCalorimeterHit, Double> pedMap = new HashMap<RawCalorimeterHit, Double>();
+
for (LCRelation rel : event.get(LCRelation.class,extraDataRelationsName)) {
RawCalorimeterHit hit = (RawCalorimeterHit) rel.getFrom();
GenericObject extraData = (GenericObject) rel.getTo();
updatePedestal(event,hit,extraData);
- }
-
- //
- // Don't care right now whether this persists in output slcio,
- // just that it is accessible during reconstruction (and it is)
- //
- // Another option would be to put hits' running pedestals into HitExtraData.Mode7Data
- // Or create another LCRelation. Either would also remove the need for indexing later.
- //
- event.put(runningPedestalsName,runningPedestals,Double.class,1,"dog");
-
+ if (!pedMap.containsKey(hit))
+ pedMap.put(hit,getPedestal(hit));
+ }
+ event.put(runningPedestalsName,pedMap);
if (debug) {
printPedestals();
}
}
- public void updatePedestal(EventHeader event, RawCalorimeterHit hit, GenericObject mode7data) {
+ private void updatePedestal(EventHeader event, RawCalorimeterHit hit, GenericObject mode7data) {
final int ii = getChannelID(hit) - 1;
if (ii < 0 || ii >= nChannels) {
System.err.println(String.format("Event #%d, Invalid id: %d/%d ",
@@ -148,7 +151,8 @@
final int max = ((HitExtraData.Mode7Data) mode7data).getAmplHigh();
// ignore if pulse at beginning of window:
- if (max <= 0) return;
+ if (max <= 0)
+ return;
// If new timestamp is older than previous one, restart pedestals.
// This should never happen unless firmware counter cycles back to zero,
@@ -176,7 +180,7 @@
// remove old pedestals surpassing limit on lookback time:
if (maxLookbackTime > 0) {
while (eventTimestamps[ii].size() > 0) {
- if (eventTimestamps[ii].get(0) < timestamp - maxLookbackTime*1e6) {
+ if (eventTimestamps[ii].get(0) < timestamp - maxLookbackTime * 1e6) {
eventTimestamps[ii].remove(0);
eventPedestals[ii].remove(0);
} else {
@@ -194,29 +198,34 @@
}
runningPedestals.set(ii,avg / eventPedestals[ii].size());
} else {
- runningPedestals.set(ii,getStaticPedestal(ii+1));
+ runningPedestals.set(ii,getStaticPedestal(ii + 1));
}
}
public double getPedestal(int channel_id) {
- return runningPedestals.get(channel_id-1);
-// final int nped = eventPedestals[channel_id - 1].size();
-// if (nped < minLookbackEvents) return getStaticPedestal(channel_id);
-// else return runningPedestals.get(channel_id - 1);
- }
+ return runningPedestals.get(channel_id - 1);
+ // final int nped = eventPedestals[channel_id - 1].size();
+ // if (nped < minLookbackEvents) return getStaticPedestal(channel_id);
+ // else return runningPedestals.get(channel_id - 1);
+ }
+
public double getPedestal(RawCalorimeterHit hit) {
return getPedestal(getChannelID(hit));
}
+
private double getStaticPedestal(int channel_id) {
EcalChannel cc = ecalConditions.getChannelCollection().findChannel(channel_id);
return ecalConditions.getChannelConstants(cc).getCalibration().getPedestal();
}
+
private double getStaticPedestal(RawCalorimeterHit hit) {
return getStaticPedestal(getChannelID(hit));
}
+
public int getChannelID(RawCalorimeterHit hit) {
return findChannel(hit.getCellID()).getCalibration().getChannelId();
}
+
public EcalChannelConstants findChannel(long cellID) {
return ecalConditions.getChannelConstants(ecalConditions.getChannelCollection()
.findGeometric(cellID));
Modified: java/trunk/users/src/main/java/org/hps/users/baltzell/EcalRawConverter_RunPed.java
=============================================================================
--- java/trunk/users/src/main/java/org/hps/users/baltzell/EcalRawConverter_RunPed.java (original)
+++ java/trunk/users/src/main/java/org/hps/users/baltzell/EcalRawConverter_RunPed.java Tue Feb 3 13:04:17 2015
@@ -1,6 +1,7 @@
package org.hps.users.baltzell;
import java.util.List;
+import java.util.Map;
import org.hps.conditions.database.TableConstants;
import org.hps.conditions.ecal.EcalCalibration;
@@ -56,24 +57,21 @@
// NAB January 2015
// Choose whether to use static pedestal from database or running pedestal:
- public double getPedestal(EventHeader event, long cellID) {
- EcalCalibration calib = findChannel(cellID).getCalibration();
+ public double getPedestal(EventHeader event,RawCalorimeterHit hit)
+ {
if (useRunningPedestal) {
- // works, but remove indexing by using LCRelation or adding to Mode7Data
if (event.hasCollection(Double.class,"EcalRunningPedestals")) {
- List<Double> peds = event.get(Double.class,"EcalRunningPedestals");
- final int cid = calib.getChannelId()-1;
- if (cid < 0 || cid>=peds.size()) {
- // logger, or throw exception, ...
- System.err.println("EcalRawConverter::getPedestal Bad Channel_id: "+cid);
+ Map<RawCalorimeterHit, Double> runningPedMap=
+ (Map<RawCalorimeterHit, Double>)
+ event.get("EcalRunningPedestals");
+ if (!runningPedMap.containsKey(hit)){
+ System.err.println("Missing Key Dog");
} else {
- // System.out.println(String.format("%d - %.2f",channel_id-1,peds.get(cid)));
- return peds.get(cid);
+ return runningPedMap.get(hit);
}
}
}
- // pedestal from database:
- return calib.getPedestal();
+ return findChannel(hit.getCellID()).getCalibration().getPedestal();
}
public short sumADC(RawTrackerHit hit) {
@@ -112,11 +110,7 @@
public CalorimeterHit HitDtoA(EventHeader event,RawCalorimeterHit hit, GenericObject mode7Data, int window, double timeOffset) {
double time = hit.getTimeStamp() / 16.0; //timestamps use the full 62.5 ps resolution
long id = hit.getCellID();
-// // Get the channel data.
- EcalChannelConstants channelData = findChannel(id);
-// double adcSum = hit.getAmplitude() - window * channelData.getCalibration().getPedestal();
-// double adcSum = hit.getAmplitude() - window * Mode7Data.getAmplLow(mode7Data); //A.C. is this the proper way to pedestal subtract in mode 7?
- double adcSum = hit.getAmplitude() - window * getPedestal(event,id);
+ double adcSum = hit.getAmplitude() - window * getPedestal(event,hit);
double rawEnergy = adcToEnergy(adcSum, id);
return CalorimeterHitUtilities.create(rawEnergy, time + timeOffset, id);
|