This class takes a block and demodulates the TOFs into each analysis channel. A lot of the code is cheezily copied and pasted from the BlockDemodulator.
Esempio n. 1
0
        // DemodulateBlockNL augments the channel values returned by DemodulateBlock
        // with several non-linear combinations of channels (E.B/DB, the correction, etc).
        // These non-linear channels are calculated point-by-point for the TOF and then
        // integrated according to the Demodulation config. This is calculated for top and
        // topNormed detectors only for speed.
        //
        public DemodulatedBlock DemodulateBlockNL(Block b, DemodulationConfig config)
        {
            // we start with the standard demodulated block
            DemodulatedBlock dblock = DemodulateBlock(b, config);
            // First do everything for the un-normalised top detector
            int tdi = dblock.DetectorIndices["top"];
            // TOF demodulate the block to get the channel wiggles
            // the BlockTOFDemodulator only demodulates the PMT detector
            BlockTOFDemodulator btdt = new BlockTOFDemodulator();
            TOFChannelSet tcst = btdt.TOFDemodulateBlock(b, tdi, false);

            // now repeat having normed the block
            // normalise the PMT signal
            b.Normalise(config.GatedDetectorExtractSpecs["norm"]);
            int tndi = dblock.DetectorIndices["topNormed"];
            // TOF demodulate the block to get the channel wiggles
            // the BlockTOFDemodulator only demodulates the PMT detector
            BlockTOFDemodulator btd = new BlockTOFDemodulator();
            TOFChannelSet tcs = btd.TOFDemodulateBlock(b, tndi, false);

            // get hold of the gating data
            GatedDetectorExtractSpec gate = config.GatedDetectorExtractSpecs["top"];

            // gate the special channels
            TOFChannel edmDB = (TOFChannel)tcs.GetChannel("EDMDB" );
            double edmDBG = edmDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDB = (TOFChannel)tcs.GetChannel( "CORRDB" );
            double corrDBG = corrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDB = (TOFChannel)tcs.GetChannel( "EDMCORRDB" );
            double edmCorrDBG = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDB_old = (TOFChannel)tcs.GetChannel( "CORRDB_OLD" );
            double corrDBG_old = corrDB_old.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDB_old = (TOFChannel)tcs.GetChannel( "EDMCORRDB_OLD" );
            double edmCorrDBG_old = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDB = (TOFChannel)tcs.GetChannel( "RF1FDB" );
            double rf1fDBG = rf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDB = (TOFChannel)tcs.GetChannel( "RF2FDB" );
            double rf2fDBG = rf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDBDB = (TOFChannel)tcs.GetChannel( "RF1FDBDB" );
            double rf1fDBDBG = rf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDBDB = (TOFChannel)tcs.GetChannel( "RF2FDBDB" );
            double rf2fDBDBG = rf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDB = (TOFChannel)tcs.GetChannel("RF1ADB");
            double rf1aDBG = rf1aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDB = (TOFChannel)tcs.GetChannel("RF2ADB");
            double rf2aDBG = rf2aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDBDB = (TOFChannel)tcs.GetChannel("RF1ADBDB");
            double rf1aDBDBG = rf1aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDBDB = (TOFChannel)tcs.GetChannel("RF2ADBDB");
            double rf2aDBDBG = rf2aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DB = (TOFChannel)tcs.GetChannel("LF1DB");
            double lf1DBG = lf1DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DBDB = (TOFChannel)tcs.GetChannel("LF1DBDB");
            double lf1DBDBG = lf1DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DB = (TOFChannel)tcs.GetChannel("LF2DB");
            double lf2DBG = lf2DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DBDB = (TOFChannel)tcs.GetChannel("LF2DBDB");
            double lf2DBDBG = lf2DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel BDB = (TOFChannel)tcs.GetChannel("BDB");
            double BDBG = BDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDB = (TOFChannel)tcs.GetChannel( "ERF1FDB" );
            double erf1fDBG = erf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDB = (TOFChannel)tcs.GetChannel( "ERF2FDB" );
            double erf2fDBG = erf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDBDB = (TOFChannel)tcs.GetChannel( "ERF1FDBDB" );
            double erf1fDBDBG = erf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDBDB = (TOFChannel)tcs.GetChannel("ERF2FDBDB" );
            double erf2fDBDBG = erf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf1fCorrDB = (TOFChannel)tcs.GetChannel( "BRF1FCORRDB" );
            double brf1fCorrDBG = brf1fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf2fCorrDB = (TOFChannel)tcs.GetChannel( "BRF2FCORRDB" );
            double brf2fCorrDBG = brf2fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);

            //Repeat for top

            TOFChannel edmDBtop = (TOFChannel)tcst.GetChannel("EDMDB");
            double edmDBGtop = edmDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDBtop = (TOFChannel)tcst.GetChannel("CORRDB");
            double corrDBGtop = corrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDBtop = (TOFChannel)tcst.GetChannel("EDMCORRDB");
            double edmCorrDBGtop = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDB_oldtop = (TOFChannel)tcst.GetChannel("CORRDB_OLD");
            double corrDBG_oldtop = corrDB_old.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDB_oldtop = (TOFChannel)tcst.GetChannel("EDMCORRDB_OLD");
            double edmCorrDBG_oldtop = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDBtop = (TOFChannel)tcst.GetChannel("RF1FDB");
            double rf1fDBGtop = rf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDBtop = (TOFChannel)tcst.GetChannel("RF2FDB");
            double rf2fDBGtop = rf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDBDBtop = (TOFChannel)tcst.GetChannel("RF1FDBDB");
            double rf1fDBDBGtop = rf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDBDBtop = (TOFChannel)tcst.GetChannel("RF2FDBDB");
            double rf2fDBDBGtop = rf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDBtop = (TOFChannel)tcst.GetChannel("RF1ADB");
            double rf1aDBGtop = rf1aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDBtop = (TOFChannel)tcst.GetChannel("RF2ADB");
            double rf2aDBGtop = rf2aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDBDBtop = (TOFChannel)tcst.GetChannel("RF1ADBDB");
            double rf1aDBDBGtop = rf1aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDBDBtop = (TOFChannel)tcst.GetChannel("RF2ADBDB");
            double rf2aDBDBGtop = rf2aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DBtop = (TOFChannel)tcst.GetChannel("LF1DB");
            double lf1DBGtop = lf1DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DBDBtop = (TOFChannel)tcst.GetChannel("LF1DBDB");
            double lf1DBDBGtop = lf1DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DBtop = (TOFChannel)tcst.GetChannel("LF2DB");
            double lf2DBGtop = lf2DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DBDBtop = (TOFChannel)tcst.GetChannel("LF2DBDB");
            double lf2DBDBGtop = lf2DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel BDBtop = (TOFChannel)tcst.GetChannel("BDB");
            double BDBGtop = BDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDBtop = (TOFChannel)tcst.GetChannel("ERF1FDB");
            double erf1fDBGtop = erf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDBtop = (TOFChannel)tcst.GetChannel("ERF2FDB");
            double erf2fDBGtop = erf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDBDBtop = (TOFChannel)tcst.GetChannel("ERF1FDBDB");
            double erf1fDBDBGtop = erf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDBDBtop = (TOFChannel)tcst.GetChannel("ERF2FDBDB");
            double erf2fDBDBGtop = erf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf1fCorrDBtop = (TOFChannel)tcst.GetChannel("BRF1FCORRDB");
            double brf1fCorrDBGtop = brf1fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf2fCorrDBtop = (TOFChannel)tcst.GetChannel("BRF2FCORRDB");
            double brf2fCorrDBGtop = brf2fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);

            // we bodge the errors, which aren't really used for much anyway
            // by just using the error from the normal dblock. I ignore the error in DB.
            // I use the simple correction error for the full correction. Doesn't much matter.
            DetectorChannelValues dcv = dblock.ChannelValues[tndi];
            double edmDBE = dcv.GetError(new string[] { "E", "B" }) / dcv.GetValue(new string[] { "DB" });
            double corrDBE = Math.Sqrt(
                Math.Pow(dcv.GetValue(new string[] { "E", "DB" }) * dcv.GetError(new string[] { "B" }), 2) +
                Math.Pow(dcv.GetValue(new string[] { "B" }) * dcv.GetError(new string[] { "E", "DB" }), 2) )
                / Math.Pow(dcv.GetValue(new string[] { "DB" }), 2);
            double edmCorrDBE = Math.Sqrt( Math.Pow(edmDBE, 2) + Math.Pow(corrDBE, 2));

            double rf1fDBE = dcv.GetError(new string[] { "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double rf2fDBE = dcv.GetError(new string[] { "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double rf1fDBDBE = dcv.GetError(new string[] { "DB", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double rf2fDBDBE = dcv.GetError(new string[] { "DB", "RF2F" }) / dcv.GetValue(new string[] { "DB" });

            double rf1aDBE = dcv.GetError(new string[] { "RF1A" }) / dcv.GetValue(new string[] { "DB" });
            double rf2aDBE = dcv.GetError(new string[] { "RF2A" }) / dcv.GetValue(new string[] { "DB" });
            double rf1aDBDBE = dcv.GetError(new string[] { "DB", "RF1A" }) / dcv.GetValue(new string[] { "DB" });
            double rf2aDBDBE = dcv.GetError(new string[] { "DB", "RF2A" }) / dcv.GetValue(new string[] { "DB" });

            double lf1DBE = dcv.GetError(new string[] { "LF1" }) / dcv.GetValue(new string[] { "DB" });
            double lf1DBDBE = dcv.GetError(new string[] { "DB", "LF1" }) / dcv.GetValue(new string[] { "DB" });
            double lf2DBE = dcv.GetError(new string[] { "LF2" }) / dcv.GetValue(new string[] { "DB" });
            double lf2DBDBE = dcv.GetError(new string[] { "DB", "LF2" }) / dcv.GetValue(new string[] { "DB" });

            double brf1fDBE = dcv.GetError(new string[] { "B", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double brf2fDBE = dcv.GetError(new string[] { "B", "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double erf1fDBE = dcv.GetError(new string[] { "E", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double erf2fDBE = dcv.GetError(new string[] { "E", "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double erf1fDBDBE = dcv.GetError(new string[] { "E", "DB", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double erf2fDBDBE = dcv.GetError(new string[] { "E", "DB", "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double BDBE = dcv.GetError(new string[] { "B" }) / dcv.GetValue(new string[] { "DB" });

            //repeat for top
            DetectorChannelValues dcvt = dblock.ChannelValues[tdi];
            double lf2DBEtop = dcvt.GetError(new string[] { "LF2" }) / dcvt.GetValue(new string[] { "DB" }); //Change the db channel back to topNormed
            double lf2DBDBEtop = dcvt.GetError(new string[] { "DB", "LF2" }) / dcvt.GetValue(new string[] { "DB" }); //Change the db channel back to topNormed

            double edmDBEtop = dcvt.GetError(new string[] { "E", "B" }) / dcvt.GetValue(new string[] { "DB" });
            double corrDBEtop = Math.Sqrt(
                Math.Pow(dcvt.GetValue(new string[] { "E", "DB" }) * dcvt.GetError(new string[] { "B" }), 2) +
                Math.Pow(dcvt.GetValue(new string[] { "B" }) * dcvt.GetError(new string[] { "E", "DB" }), 2))
                / Math.Pow(dcvt.GetValue(new string[] { "DB" }), 2);
            double edmCorrDBEtop = Math.Sqrt(Math.Pow(edmDBEtop, 2) + Math.Pow(corrDBEtop, 2));

            double rf1fDBEtop = dcvt.GetError(new string[] { "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2fDBEtop = dcvt.GetError(new string[] { "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double rf1fDBDBEtop = dcvt.GetError(new string[] { "DB", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2fDBDBEtop = dcvt.GetError(new string[] { "DB", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });

            double rf1aDBEtop = dcvt.GetError(new string[] { "RF1A" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2aDBEtop = dcvt.GetError(new string[] { "RF2A" }) / dcvt.GetValue(new string[] { "DB" });
            double rf1aDBDBEtop = dcvt.GetError(new string[] { "DB", "RF1A" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2aDBDBEtop = dcvt.GetError(new string[] { "DB", "RF2A" }) / dcvt.GetValue(new string[] { "DB" });

            double lf1DBEtop = dcvt.GetError(new string[] { "LF1" }) / dcvt.GetValue(new string[] { "DB" });
            double lf1DBDBEtop = dcvt.GetError(new string[] { "DB", "LF1" }) / dcvt.GetValue(new string[] { "DB" });

            double brf1fDBEtop = dcvt.GetError(new string[] { "B", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double brf2fDBEtop = dcvt.GetError(new string[] { "B", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf1fDBEtop = dcvt.GetError(new string[] { "E", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf2fDBEtop = dcvt.GetError(new string[] { "E", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf1fDBDBEtop = dcvt.GetError(new string[] { "E", "DB", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf2fDBDBEtop = dcvt.GetError(new string[] { "E", "DB", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double BDBEtop = dcvt.GetError(new string[] { "B" }) / dcvt.GetValue(new string[] { "DB" });

            // stuff the data into the dblock
            dblock.ChannelValues[tndi].SpecialValues["EDMDB"] = new double[] { edmDBG, edmDBE };
            dblock.ChannelValues[tndi].SpecialValues["CORRDB"] = new double[] { corrDBG, corrDBE };
            dblock.ChannelValues[tndi].SpecialValues["EDMCORRDB"] = new double[] { edmCorrDBG, edmCorrDBE };
            dblock.ChannelValues[tndi].SpecialValues["CORRDB_OLD"] = new double[] { corrDBG_old, corrDBE };
            dblock.ChannelValues[tndi].SpecialValues["EDMCORRDB_OLD"] = new double[] { edmCorrDBG_old, edmCorrDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1FDB"] = new double[] { rf1fDBG, rf1fDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2FDB"] = new double[] { rf2fDBG, rf2fDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1FDBDB"] = new double[] { rf1fDBDBG, rf1fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2FDBDB"] = new double[] { rf2fDBDBG, rf2fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1ADB"] = new double[] { rf1aDBG, rf1aDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2ADB"] = new double[] { rf2aDBG, rf2aDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1ADBDB"] = new double[] { rf1aDBDBG, rf1aDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2ADBDB"] = new double[] { rf2aDBDBG, rf2aDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["BRF1FCORRDB"] = new double[] { brf1fCorrDBG, brf1fDBE };
            dblock.ChannelValues[tndi].SpecialValues["BRF2FCORRDB"] = new double[] { brf2fCorrDBG, brf2fDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF1FDB"] = new double[] { erf1fDBG, erf1fDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF2FDB"] = new double[] { erf2fDBG, erf2fDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF1FDBDB"] = new double[] { erf1fDBDBG, erf1fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF2FDBDB"] = new double[] { erf2fDBDBG, erf2fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["LF1DB"] = new double[] { lf1DBG, lf1DBE };
            dblock.ChannelValues[tndi].SpecialValues["LF1DBDB"] = new double[] { lf1DBDBG, lf1DBDBE };
            dblock.ChannelValues[tndi].SpecialValues["LF2DB"] = new double[] { lf2DBG, lf2DBE };
            dblock.ChannelValues[tndi].SpecialValues["LF2DBDB"] = new double[] { lf2DBDBG, lf2DBDBE };
            dblock.ChannelValues[tndi].SpecialValues["BDB"] = new double[] { BDBG, BDBE };

            dblock.ChannelValues[tdi].SpecialValues["EDMDB"] = new double[] { edmDBGtop, edmDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["CORRDB"] = new double[] { corrDBGtop, corrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["EDMCORRDB"] = new double[] { edmCorrDBGtop, edmCorrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["CORRDB_OLD"] = new double[] { corrDBG_oldtop, corrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["EDMCORRDB_OLD"] = new double[] { edmCorrDBG_oldtop, edmCorrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1FDB"] = new double[] { rf1fDBGtop, rf1fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2FDB"] = new double[] { rf2fDBGtop, rf2fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1FDBDB"] = new double[] { rf1fDBDBGtop, rf1fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2FDBDB"] = new double[] { rf2fDBDBGtop, rf2fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1ADB"] = new double[] { rf1aDBGtop, rf1aDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2ADB"] = new double[] { rf2aDBGtop, rf2aDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1ADBDB"] = new double[] { rf1aDBDBGtop, rf1aDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2ADBDB"] = new double[] { rf2aDBDBGtop, rf2aDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["BRF1FCORRDB"] = new double[] { brf1fCorrDBGtop, brf1fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["BRF2FCORRDB"] = new double[] { brf2fCorrDBGtop, brf2fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF1FDB"] = new double[] { erf1fDBGtop, erf1fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF2FDB"] = new double[] { erf2fDBGtop, erf2fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF1FDBDB"] = new double[] { erf1fDBDBGtop, erf1fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF2FDBDB"] = new double[] { erf2fDBDBGtop, erf2fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF1DB"] = new double[] { lf1DBGtop, lf1DBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF1DBDB"] = new double[] { lf1DBDBGtop, lf1DBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF2DB"] = new double[] { lf2DBGtop, lf2DBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF2DBDB"] = new double[] { lf2DBDBGtop, lf2DBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["BDB"] = new double[] { BDBGtop, BDBEtop };

            return dblock;
        }
Esempio n. 2
0
        // DemodulateBlockNL augments the channel values returned by DemodulateBlock
        // with several non-linear combinations of channels (E.B/DB, the correction, etc).
        // These non-linear channels are calculated point-by-point for the TOF and then
        // integrated according to the Demodulation config. This is calculated for top and
        // topNormed detectors only for speed.
        //
        public DemodulatedBlock DemodulateBlockNL(Block b, DemodulationConfig config)
        {
            // we start with the standard demodulated block
            DemodulatedBlock dblock = DemodulateBlock(b, config);
            // First do everything for the un-normalised top detector
            int tdi = dblock.DetectorIndices["top"];
            // TOF demodulate the block to get the channel wiggles
            // the BlockTOFDemodulator only demodulates the PMT detector
            BlockTOFDemodulator btdt = new BlockTOFDemodulator();
            TOFChannelSet       tcst = btdt.TOFDemodulateBlock(b, tdi, false);

            // now repeat having normed the block
            // normalise the PMT signal
            b.Normalise(config.GatedDetectorExtractSpecs["norm"]);
            int tndi = dblock.DetectorIndices["topNormed"];
            // TOF demodulate the block to get the channel wiggles
            // the BlockTOFDemodulator only demodulates the PMT detector
            BlockTOFDemodulator btd = new BlockTOFDemodulator();
            TOFChannelSet       tcs = btd.TOFDemodulateBlock(b, tndi, false);

            // get hold of the gating data
            GatedDetectorExtractSpec gate = config.GatedDetectorExtractSpecs["top"];

            // gate the special channels
            TOFChannel edmDB          = (TOFChannel)tcs.GetChannel("EDMDB");
            double     edmDBG         = edmDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDB         = (TOFChannel)tcs.GetChannel("CORRDB");
            double     corrDBG        = corrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDB      = (TOFChannel)tcs.GetChannel("EDMCORRDB");
            double     edmCorrDBG     = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDB_old     = (TOFChannel)tcs.GetChannel("CORRDB_OLD");
            double     corrDBG_old    = corrDB_old.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDB_old  = (TOFChannel)tcs.GetChannel("EDMCORRDB_OLD");
            double     edmCorrDBG_old = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDB         = (TOFChannel)tcs.GetChannel("RF1FDB");
            double     rf1fDBG        = rf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDB         = (TOFChannel)tcs.GetChannel("RF2FDB");
            double     rf2fDBG        = rf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDBDB       = (TOFChannel)tcs.GetChannel("RF1FDBDB");
            double     rf1fDBDBG      = rf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDBDB       = (TOFChannel)tcs.GetChannel("RF2FDBDB");
            double     rf2fDBDBG      = rf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDB         = (TOFChannel)tcs.GetChannel("RF1ADB");
            double     rf1aDBG        = rf1aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDB         = (TOFChannel)tcs.GetChannel("RF2ADB");
            double     rf2aDBG        = rf2aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDBDB       = (TOFChannel)tcs.GetChannel("RF1ADBDB");
            double     rf1aDBDBG      = rf1aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDBDB       = (TOFChannel)tcs.GetChannel("RF2ADBDB");
            double     rf2aDBDBG      = rf2aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DB          = (TOFChannel)tcs.GetChannel("LF1DB");
            double     lf1DBG         = lf1DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DBDB        = (TOFChannel)tcs.GetChannel("LF1DBDB");
            double     lf1DBDBG       = lf1DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DB          = (TOFChannel)tcs.GetChannel("LF2DB");
            double     lf2DBG         = lf2DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DBDB        = (TOFChannel)tcs.GetChannel("LF2DBDB");
            double     lf2DBDBG       = lf2DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel BDB            = (TOFChannel)tcs.GetChannel("BDB");
            double     BDBG           = BDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDB        = (TOFChannel)tcs.GetChannel("ERF1FDB");
            double     erf1fDBG       = erf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDB        = (TOFChannel)tcs.GetChannel("ERF2FDB");
            double     erf2fDBG       = erf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDBDB      = (TOFChannel)tcs.GetChannel("ERF1FDBDB");
            double     erf1fDBDBG     = erf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDBDB      = (TOFChannel)tcs.GetChannel("ERF2FDBDB");
            double     erf2fDBDBG     = erf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf1fCorrDB    = (TOFChannel)tcs.GetChannel("BRF1FCORRDB");
            double     brf1fCorrDBG   = brf1fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf2fCorrDB    = (TOFChannel)tcs.GetChannel("BRF2FCORRDB");
            double     brf2fCorrDBG   = brf2fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);

            //Repeat for top


            TOFChannel edmDBtop          = (TOFChannel)tcst.GetChannel("EDMDB");
            double     edmDBGtop         = edmDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDBtop         = (TOFChannel)tcst.GetChannel("CORRDB");
            double     corrDBGtop        = corrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDBtop      = (TOFChannel)tcst.GetChannel("EDMCORRDB");
            double     edmCorrDBGtop     = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel corrDB_oldtop     = (TOFChannel)tcst.GetChannel("CORRDB_OLD");
            double     corrDBG_oldtop    = corrDB_old.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel edmCorrDB_oldtop  = (TOFChannel)tcst.GetChannel("EDMCORRDB_OLD");
            double     edmCorrDBG_oldtop = edmCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDBtop         = (TOFChannel)tcst.GetChannel("RF1FDB");
            double     rf1fDBGtop        = rf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDBtop         = (TOFChannel)tcst.GetChannel("RF2FDB");
            double     rf2fDBGtop        = rf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1fDBDBtop       = (TOFChannel)tcst.GetChannel("RF1FDBDB");
            double     rf1fDBDBGtop      = rf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2fDBDBtop       = (TOFChannel)tcst.GetChannel("RF2FDBDB");
            double     rf2fDBDBGtop      = rf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDBtop         = (TOFChannel)tcst.GetChannel("RF1ADB");
            double     rf1aDBGtop        = rf1aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDBtop         = (TOFChannel)tcst.GetChannel("RF2ADB");
            double     rf2aDBGtop        = rf2aDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf1aDBDBtop       = (TOFChannel)tcst.GetChannel("RF1ADBDB");
            double     rf1aDBDBGtop      = rf1aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel rf2aDBDBtop       = (TOFChannel)tcst.GetChannel("RF2ADBDB");
            double     rf2aDBDBGtop      = rf2aDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DBtop          = (TOFChannel)tcst.GetChannel("LF1DB");
            double     lf1DBGtop         = lf1DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf1DBDBtop        = (TOFChannel)tcst.GetChannel("LF1DBDB");
            double     lf1DBDBGtop       = lf1DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DBtop          = (TOFChannel)tcst.GetChannel("LF2DB");
            double     lf2DBGtop         = lf2DB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel lf2DBDBtop        = (TOFChannel)tcst.GetChannel("LF2DBDB");
            double     lf2DBDBGtop       = lf2DBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel BDBtop            = (TOFChannel)tcst.GetChannel("BDB");
            double     BDBGtop           = BDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDBtop        = (TOFChannel)tcst.GetChannel("ERF1FDB");
            double     erf1fDBGtop       = erf1fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDBtop        = (TOFChannel)tcst.GetChannel("ERF2FDB");
            double     erf2fDBGtop       = erf2fDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf1fDBDBtop      = (TOFChannel)tcst.GetChannel("ERF1FDBDB");
            double     erf1fDBDBGtop     = erf1fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel erf2fDBDBtop      = (TOFChannel)tcst.GetChannel("ERF2FDBDB");
            double     erf2fDBDBGtop     = erf2fDBDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf1fCorrDBtop    = (TOFChannel)tcst.GetChannel("BRF1FCORRDB");
            double     brf1fCorrDBGtop   = brf1fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);
            TOFChannel brf2fCorrDBtop    = (TOFChannel)tcst.GetChannel("BRF2FCORRDB");
            double     brf2fCorrDBGtop   = brf2fCorrDB.Difference.GatedMean(gate.GateLow, gate.GateHigh);



            // we bodge the errors, which aren't really used for much anyway
            // by just using the error from the normal dblock. I ignore the error in DB.
            // I use the simple correction error for the full correction. Doesn't much matter.
            DetectorChannelValues dcv = dblock.ChannelValues[tndi];
            double edmDBE             = dcv.GetError(new string[] { "E", "B" }) / dcv.GetValue(new string[] { "DB" });
            double corrDBE            = Math.Sqrt(
                Math.Pow(dcv.GetValue(new string[] { "E", "DB" }) * dcv.GetError(new string[] { "B" }), 2) +
                Math.Pow(dcv.GetValue(new string[] { "B" }) * dcv.GetError(new string[] { "E", "DB" }), 2))
                                        / Math.Pow(dcv.GetValue(new string[] { "DB" }), 2);
            double edmCorrDBE = Math.Sqrt(Math.Pow(edmDBE, 2) + Math.Pow(corrDBE, 2));

            double rf1fDBE   = dcv.GetError(new string[] { "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double rf2fDBE   = dcv.GetError(new string[] { "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double rf1fDBDBE = dcv.GetError(new string[] { "DB", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double rf2fDBDBE = dcv.GetError(new string[] { "DB", "RF2F" }) / dcv.GetValue(new string[] { "DB" });

            double rf1aDBE   = dcv.GetError(new string[] { "RF1A" }) / dcv.GetValue(new string[] { "DB" });
            double rf2aDBE   = dcv.GetError(new string[] { "RF2A" }) / dcv.GetValue(new string[] { "DB" });
            double rf1aDBDBE = dcv.GetError(new string[] { "DB", "RF1A" }) / dcv.GetValue(new string[] { "DB" });
            double rf2aDBDBE = dcv.GetError(new string[] { "DB", "RF2A" }) / dcv.GetValue(new string[] { "DB" });

            double lf1DBE   = dcv.GetError(new string[] { "LF1" }) / dcv.GetValue(new string[] { "DB" });
            double lf1DBDBE = dcv.GetError(new string[] { "DB", "LF1" }) / dcv.GetValue(new string[] { "DB" });
            double lf2DBE   = dcv.GetError(new string[] { "LF2" }) / dcv.GetValue(new string[] { "DB" });
            double lf2DBDBE = dcv.GetError(new string[] { "DB", "LF2" }) / dcv.GetValue(new string[] { "DB" });

            double brf1fDBE   = dcv.GetError(new string[] { "B", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double brf2fDBE   = dcv.GetError(new string[] { "B", "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double erf1fDBE   = dcv.GetError(new string[] { "E", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double erf2fDBE   = dcv.GetError(new string[] { "E", "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double erf1fDBDBE = dcv.GetError(new string[] { "E", "DB", "RF1F" }) / dcv.GetValue(new string[] { "DB" });
            double erf2fDBDBE = dcv.GetError(new string[] { "E", "DB", "RF2F" }) / dcv.GetValue(new string[] { "DB" });
            double BDBE       = dcv.GetError(new string[] { "B" }) / dcv.GetValue(new string[] { "DB" });

            //repeat for top
            DetectorChannelValues dcvt = dblock.ChannelValues[tdi];
            double lf2DBEtop           = dcvt.GetError(new string[] { "LF2" }) / dcvt.GetValue(new string[] { "DB" });       //Change the db channel back to topNormed
            double lf2DBDBEtop         = dcvt.GetError(new string[] { "DB", "LF2" }) / dcvt.GetValue(new string[] { "DB" }); //Change the db channel back to topNormed

            double edmDBEtop  = dcvt.GetError(new string[] { "E", "B" }) / dcvt.GetValue(new string[] { "DB" });
            double corrDBEtop = Math.Sqrt(
                Math.Pow(dcvt.GetValue(new string[] { "E", "DB" }) * dcvt.GetError(new string[] { "B" }), 2) +
                Math.Pow(dcvt.GetValue(new string[] { "B" }) * dcvt.GetError(new string[] { "E", "DB" }), 2))
                                / Math.Pow(dcvt.GetValue(new string[] { "DB" }), 2);
            double edmCorrDBEtop = Math.Sqrt(Math.Pow(edmDBEtop, 2) + Math.Pow(corrDBEtop, 2));

            double rf1fDBEtop   = dcvt.GetError(new string[] { "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2fDBEtop   = dcvt.GetError(new string[] { "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double rf1fDBDBEtop = dcvt.GetError(new string[] { "DB", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2fDBDBEtop = dcvt.GetError(new string[] { "DB", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });

            double rf1aDBEtop   = dcvt.GetError(new string[] { "RF1A" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2aDBEtop   = dcvt.GetError(new string[] { "RF2A" }) / dcvt.GetValue(new string[] { "DB" });
            double rf1aDBDBEtop = dcvt.GetError(new string[] { "DB", "RF1A" }) / dcvt.GetValue(new string[] { "DB" });
            double rf2aDBDBEtop = dcvt.GetError(new string[] { "DB", "RF2A" }) / dcvt.GetValue(new string[] { "DB" });

            double lf1DBEtop   = dcvt.GetError(new string[] { "LF1" }) / dcvt.GetValue(new string[] { "DB" });
            double lf1DBDBEtop = dcvt.GetError(new string[] { "DB", "LF1" }) / dcvt.GetValue(new string[] { "DB" });

            double brf1fDBEtop   = dcvt.GetError(new string[] { "B", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double brf2fDBEtop   = dcvt.GetError(new string[] { "B", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf1fDBEtop   = dcvt.GetError(new string[] { "E", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf2fDBEtop   = dcvt.GetError(new string[] { "E", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf1fDBDBEtop = dcvt.GetError(new string[] { "E", "DB", "RF1F" }) / dcvt.GetValue(new string[] { "DB" });
            double erf2fDBDBEtop = dcvt.GetError(new string[] { "E", "DB", "RF2F" }) / dcvt.GetValue(new string[] { "DB" });
            double BDBEtop       = dcvt.GetError(new string[] { "B" }) / dcvt.GetValue(new string[] { "DB" });



            // stuff the data into the dblock
            dblock.ChannelValues[tndi].SpecialValues["EDMDB"]         = new double[] { edmDBG, edmDBE };
            dblock.ChannelValues[tndi].SpecialValues["CORRDB"]        = new double[] { corrDBG, corrDBE };
            dblock.ChannelValues[tndi].SpecialValues["EDMCORRDB"]     = new double[] { edmCorrDBG, edmCorrDBE };
            dblock.ChannelValues[tndi].SpecialValues["CORRDB_OLD"]    = new double[] { corrDBG_old, corrDBE };
            dblock.ChannelValues[tndi].SpecialValues["EDMCORRDB_OLD"] = new double[] { edmCorrDBG_old, edmCorrDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1FDB"]        = new double[] { rf1fDBG, rf1fDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2FDB"]        = new double[] { rf2fDBG, rf2fDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1FDBDB"]      = new double[] { rf1fDBDBG, rf1fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2FDBDB"]      = new double[] { rf2fDBDBG, rf2fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1ADB"]        = new double[] { rf1aDBG, rf1aDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2ADB"]        = new double[] { rf2aDBG, rf2aDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF1ADBDB"]      = new double[] { rf1aDBDBG, rf1aDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["RF2ADBDB"]      = new double[] { rf2aDBDBG, rf2aDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["BRF1FCORRDB"]   = new double[] { brf1fCorrDBG, brf1fDBE };
            dblock.ChannelValues[tndi].SpecialValues["BRF2FCORRDB"]   = new double[] { brf2fCorrDBG, brf2fDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF1FDB"]       = new double[] { erf1fDBG, erf1fDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF2FDB"]       = new double[] { erf2fDBG, erf2fDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF1FDBDB"]     = new double[] { erf1fDBDBG, erf1fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["ERF2FDBDB"]     = new double[] { erf2fDBDBG, erf2fDBDBE };
            dblock.ChannelValues[tndi].SpecialValues["LF1DB"]         = new double[] { lf1DBG, lf1DBE };
            dblock.ChannelValues[tndi].SpecialValues["LF1DBDB"]       = new double[] { lf1DBDBG, lf1DBDBE };
            dblock.ChannelValues[tndi].SpecialValues["LF2DB"]         = new double[] { lf2DBG, lf2DBE };
            dblock.ChannelValues[tndi].SpecialValues["LF2DBDB"]       = new double[] { lf2DBDBG, lf2DBDBE };
            dblock.ChannelValues[tndi].SpecialValues["BDB"]           = new double[] { BDBG, BDBE };


            dblock.ChannelValues[tdi].SpecialValues["EDMDB"]         = new double[] { edmDBGtop, edmDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["CORRDB"]        = new double[] { corrDBGtop, corrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["EDMCORRDB"]     = new double[] { edmCorrDBGtop, edmCorrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["CORRDB_OLD"]    = new double[] { corrDBG_oldtop, corrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["EDMCORRDB_OLD"] = new double[] { edmCorrDBG_oldtop, edmCorrDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1FDB"]        = new double[] { rf1fDBGtop, rf1fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2FDB"]        = new double[] { rf2fDBGtop, rf2fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1FDBDB"]      = new double[] { rf1fDBDBGtop, rf1fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2FDBDB"]      = new double[] { rf2fDBDBGtop, rf2fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1ADB"]        = new double[] { rf1aDBGtop, rf1aDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2ADB"]        = new double[] { rf2aDBGtop, rf2aDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF1ADBDB"]      = new double[] { rf1aDBDBGtop, rf1aDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["RF2ADBDB"]      = new double[] { rf2aDBDBGtop, rf2aDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["BRF1FCORRDB"]   = new double[] { brf1fCorrDBGtop, brf1fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["BRF2FCORRDB"]   = new double[] { brf2fCorrDBGtop, brf2fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF1FDB"]       = new double[] { erf1fDBGtop, erf1fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF2FDB"]       = new double[] { erf2fDBGtop, erf2fDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF1FDBDB"]     = new double[] { erf1fDBDBGtop, erf1fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["ERF2FDBDB"]     = new double[] { erf2fDBDBGtop, erf2fDBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF1DB"]         = new double[] { lf1DBGtop, lf1DBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF1DBDB"]       = new double[] { lf1DBDBGtop, lf1DBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF2DB"]         = new double[] { lf2DBGtop, lf2DBEtop };
            dblock.ChannelValues[tdi].SpecialValues["LF2DBDB"]       = new double[] { lf2DBDBGtop, lf2DBDBEtop };
            dblock.ChannelValues[tdi].SpecialValues["BDB"]           = new double[] { BDBGtop, BDBEtop };


            return(dblock);
        }
Esempio n. 3
0
        private void AddBlock(string path, string normConfig)
        {
            Monitor.JobStarted();
            string fileName = path.Split('\\').Last();
            try
            {
                Controller.log("Adding block " + fileName);
                using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
                {
                    BlockSerializer bls = new BlockSerializer();
                    Block b = bls.DeserializeBlockFromZippedXML(path, "block.xml");
                    Controller.log("Loaded " + fileName);
                    // at the moment the block data is normalized by dividing each "top" TOF through
                    // by the integral of the corresponding "norm" TOF over the gate in the function below.
                    // TODO: this could be improved!
                    b.Normalise(DemodulationConfig.GetStandardDemodulationConfig(normConfig, b).GatedDetectorExtractSpecs["norm"]);
                    // add some of the single point data to the Shot TOFs so that it gets analysed
                    string[] spvsToTOFulise = new string[] { "NorthCurrent", "SouthCurrent", "MiniFlux1",
                        "MiniFlux2", "MiniFlux3", "ProbePD", "PumpPD"};
                    b.TOFuliseSinglePointData(spvsToTOFulise);

                    // extract the metadata and config into a DB object
                    DBBlock dbb = new DBBlock();
                    dbb.cluster = (string)b.Config.Settings["cluster"];
                    dbb.clusterIndex = (int)b.Config.Settings["clusterIndex"];
                    dbb.include = false;
                    dbb.eState = (bool)b.Config.Settings["eState"];
                    dbb.bState = (bool)b.Config.Settings["bState"];
                    try
                    {
                        dbb.rfState = (bool)b.Config.Settings["rfState"];
                    }
                    catch (Exception)
                    {
                        // blocks from the old days had no rfState recorded in them.
                        dbb.rfState = true;
                    }
                    dbb.ePlus = (double)b.Config.Settings["ePlus"];
                    dbb.eMinus = (double)b.Config.Settings["eMinus"];
                    dbb.blockTime = (DateTime)b.TimeStamp;

                    byte[] bts = serializeAsByteArray(b.Config);
                    dbb.configBytes = bts;

                    // extract the TOFChannelSets
                    List<string> detectorsToExtract = new List<string>
                        { "top", "norm", "magnetometer", "gnd", "battery","topNormed","NorthCurrent", "SouthCurrent",
                            "MiniFlux1", "MiniFlux2", "MiniFlux3", "ProbePD", "PumpPD" };
                    foreach (string detector in detectorsToExtract)
                    {
                        BlockTOFDemodulator demod = new BlockTOFDemodulator();
                        TOFChannelSet tcs = demod.TOFDemodulateBlock(b, b.detectors.IndexOf(detector), true);
                        byte[] tcsBytes = serializeAsByteArray(tcs);
                        DBTOFChannelSet t = new DBTOFChannelSet();
                        t.tcsData = tcsBytes;
                        t.detector = detector;
                        t.FileID = Guid.NewGuid();
                        dbb.DBTOFChannelSets.Add(t);
                    }
                    Controller.log("Demodulated " + fileName);

                    // add to the database
                    dc.DBBlocks.InsertOnSubmit(dbb);
                    dc.SubmitChanges();
                    Controller.log("Added " + fileName);
                }
            }
            catch (Exception e)
            {
                Controller.errorLog("Error adding " + fileName);
                Controller.errorLog("Error adding block " + path + "\n" + e.StackTrace);
            }
            finally
            {
                Monitor.JobFinished();
            }
        }