/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.modules.statistics;

import etomica.data.AccumulatorAverageFixed;
import etomica.data.IData;
import etomica.data.IDataInfo;
import etomica.data.types.DataDouble;
import etomica.data.types.DataGroup;
import etomica.integrator.IntegratorBox;

public class AccumulatorMimicMu extends AccumulatorAverageFixed {

    protected final IntegratorBox integrator;

    public AccumulatorMimicMu(IntegratorBox integrator) {
        super();
        this.integrator = integrator;
    }

    public void putDataInfo(IDataInfo dataInfo) {
        dataSink.putDataInfo(dataInfo);
    }

    public IData processData(IData data) {
        double temperature = integrator.getTemperature();
        DataGroup g = (DataGroup) data;
        DataDouble avg = (DataDouble) g.getData(AVERAGE.index);
        DataDouble err = (DataDouble) g.getData(ERROR.index);
        DataDouble stdev = (DataDouble) g.getData(STANDARD_DEVIATION.index);
        err.x = temperature * err.x / avg.x;
        stdev.x = temperature * stdev.x / avg.x;
        avg.x = -temperature * Math.log(avg.x);
        return data;
    }
}

@@ -568,16 +568,46 @@
 egrator;
+%0A    protected DataGroup data;
 %0A%0A    pu
@@ -810,16 +810,64 @@
 aInfo);%0A
+        data = (DataGroup) dataInfo.makeData();%0A
     %7D%0A%0A 
@@ -900,17 +900,22 @@
 a(IData 
-d
+inputD
 ata) %7B%0A 
@@ -1005,17 +1005,22 @@
 aGroup) 
-d
+inputD
 ata;%0A   
@@ -1227,19 +1227,243 @@
         
-err
+DataDouble avgOut = (DataDouble) data.getData(AVERAGE.index);%0A        DataDouble errOut = (DataDouble) data.getData(ERROR.index);%0A        DataDouble stdevOut = (DataDouble) data.getData(STANDARD_DEVIATION.index);%0A        errOut
 .x = tem
@@ -1501,16 +1501,19 @@
    stdev
+Out
 .x = tem
@@ -1551,16 +1551,19 @@
      avg
+Out
 .x = -te

make our own data so we don't mess with accumulator's data