/** $Id$ ----------------------------------------------------------------------- @copyright (©) Copyright 2006 by GATS, Inc., 11864 Canon Blvd, Suite 101, Newport News VA 23606 All Rights Reserved. No part of this software or publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without the prior written permission of GATS, Inc. ----------------------------------------------------------------------- @file SignalCorrection.cpp @author John Burton @creationdate Thu May 4 17:01:31 2006 ----------------------------------------------------------------------- Modification History: $Log$ Added thermal correction code for NO channel and moved it to occur before the drift correction so that it will arrive at a good exo V value for transmissions. ----------------------------------------------------------------------- */ //---------------------------------------------------------------------- // Include Files: //----------------------------------------------------------------------- // #include "SignalCorrection.h" #include "NonLinOutput.h" #include "NonLinearity.h" #include "NO_Thermal.h" #include "H2O_Response.h" #include "FOV_Offset.h" #include "SigCorrectInput.h" #include "SigCorrectOutput.h" #include "MultiSignal.h" #include "PerformAudit.h" #include "CheckSigInf.h" #include "AlgorithmFactory.h" #include "GenericFunctor.h" #include "DriftFunctor.h" #include "DarkFunctor.h" #include "BalanceFunctor.h" #include "PointingDriftFunctor.h" #include "SigCorrectConnEvent.h" #include "AuditEventStream.h" #include "CheckDark.h" #include "CheckDarkDiff.h" #include "SetUpDrift.h" #include "SigEarthLocParam.h" #include "SetUpDrift.h" #include "DriftParam.h" #include "SetUpPointingCor.h" #include "SOFIE_namespace.h" #include #include #include #include "GATS_DB_mysql.h" using namespace gatsDBpp; using namespace std; // //----------------------------------------------------------------------- // Defines and Macros: //----------------------------------------------------------------------- // // //----------------------------------------------------------------------- // Global Variables: //----------------------------------------------------------------------- // // //----------------------------------------------------------------------- // Utility Routines: //----------------------------------------------------------------------- // int SignalCorrection(Event& L0, Event& L1, Event& Tmp, Event& SD, ConfigFile& cf) { const string MODULE_NAME = "SignalCorrection"; bool badDataThrow; MultiSignal multiSignal; string strMsg; int retCode = 0; SigCorrectConnEvent dataConn(SD); AlgorithmFactory factory; NonLinOutput nlOutput; SigCorrectInput correctionInput(L0, L1); //SigCorrectOutput correctionOutput; // Added this module for correcting non-linearity // 5/1/2009 GJP NonLinearity nonLinCorrection(cf); CheckDark checkDarkDet; CheckDarkDiff checkDarkDrift; DarkFunctor darkCorrection(&checkDarkDet, &checkDarkDrift) ; vector darkParamVect; SigEarthLocParam earthInfo = correctionInput.getEarthLocInfo(); SetUpDrift setupParam(cf, "DriftCorrectionSetup"); SetUpDriftParam inDriftParam; DriftFunctor driftCorrection; vector driftParamVect; BalanceFunctor balCorrection; PointingDriftFunctor pointingCorrection; vector pointParmVect; SetUpPointingCor setUpPointingAlt(cf, MODULE_NAME, "PointingCutoffAlt"); AuditEventStream auditStream(L1); PerformAudit audit; double pointingCutoff; try { audit = PerformAudit(auditStream); // Added by GJP on 2/22/2011 to write out files for HU to // analyze band 3 and 4 response signals. /* EventVar timeArray; EventVarVect signals; EventVar highEl; EventVar lowEl; EventVar highAz; EventVar lowAz; EventVar balanceStart; EventVar balanceEnd; L1.getEventVar("L1_DetectorTimes", timeArray); L1.getEventVar("L1_TimeShiftedSignals", signals); L1.getEventVar("SolarHighElevationEdge", highEl); L1.getEventVar("SolarLowElevationEdge", lowEl); L1.getEventVar("SolarHighAzimuthEdge", highAz); L1.getEventVar("SolarLowAzimuthEdge", lowAz); L0.getEventVar("L0_BalanceStartTime", balanceStart); L0.getEventVar("L0_BalanceEndTime", balanceEnd); char myStr[200]; ofstream myFILE; sprintf(myStr, "AllUncorrectedData_Event%d.tsv", L0.getEventNumber()); myFILE.open(myStr); sprintf(myStr, "%f\t%f", balanceStart[0], balanceEnd[0]); myFILE << myStr << endl; myFILE.flush(); sprintf(myStr, "%d", timeArray.size()); myFILE << myStr << endl; myFILE.flush(); myFILE << "Detector_Timestamp\tBand_3\tBand_4\tHigh_El\tLow_El\tHigh_Az\tLow_Az" << endl; for (int i = 0; i < timeArray.size(); i++) { sprintf(myStr, "%f\t%f\t%f\t%f\t%f\t%f\t%f", timeArray[i], signals[2][i], signals[3][i], highEl[i], lowEl[i], highAz[i], lowAz[i]); myFILE << myStr << endl; myFILE.flush(); } myFILE.close(); */ // end section added by GJP // Initiallize function objects factory = AlgorithmFactory(dataConn); GenericFunctor GainCorr(factory.create(SigFactory::Gain)); badDataThrow = bool(cf.GetInt(MODULE_NAME, "AbortForBadData")); CheckSigInf infinityCheck(badDataThrow); // Commence Processing multiSignal = correctionInput.getMultiSignal(); // Added this section for correcting non-linearity // 5/1/2009 GJP if (bool(cf.GetInt(MODULE_NAME, "Correct_NonLinearity"))) { multiSignal = nonLinCorrection.correctAllSignals(multiSignal); } nlOutput = NonLinOutput(multiSignal); nlOutput.outputToEvent(L1); pointingCutoff = setUpPointingAlt(correctionInput.getEarthLocInfo()); pointingCorrection = PointingDriftFunctor(correctionInput.getEarthLocInfo(), correctionInput.getCalibrationTimes(), correctionInput.getBalanceTimes(), pointingCutoff); if (bool(cf.GetInt(MODULE_NAME, "Correct_Pointing_Drift"))) { multiSignal = pointingCorrection(multiSignal); pointParmVect = pointingCorrection.getParam(); } else { pointingCorrection(multiSignal); pointParmVect = pointingCorrection.getParam(); } if (bool(cf.GetInt(MODULE_NAME, "Correct_Gain"))) { multiSignal = GainCorr(multiSignal); } if (bool(cf.GetInt(MODULE_NAME, "Correct_DarkSig"))) { multiSignal = darkCorrection(multiSignal); darkParamVect = darkCorrection.getParam(); } else { darkCorrection(multiSignal); darkParamVect = darkCorrection.getParam(); } // NO Thermal correction Model EventVar E("L1_Thermal_ChiSq", 16); for(int i =0; i< E.size(); ++i) E[i] = -999.; if( bool(cf.GetInt(MODULE_NAME, "Correct_NO_Thermal"))) { double ChiSq[2]; NO_Thermal noThermal(L0,cf) ; multiSignal = noThermal.correctNO(multiSignal,earthInfo, ChiSq); E[15] = ChiSq[0]; // E[1] = ChiSq[1]; } L1.addEventVar(E); // End Thermal Model // Added by GJP on 10/15/2010 // H2O correction Model if( bool(cf.GetInt(MODULE_NAME, "Correct_H2O_Response"))) { EventVarVect EVV; EVV.setName("H2O_Parameters"); H2O_Response h2oResponse(L0,cf) ; multiSignal = h2oResponse.correctH2O(multiSignal,earthInfo, EVV); L1.addEventVar(EVV); } // End H2O correction Model inDriftParam = setupParam(correctionInput.getEarthLocInfo(), correctionInput.getBalanceTimes()); driftCorrection = DriftFunctor(inDriftParam); if (bool(cf.GetInt(MODULE_NAME, "Correct_Drift"))) { multiSignal = driftCorrection(multiSignal); driftParamVect = driftCorrection.getParam();} else { driftCorrection(multiSignal); driftParamVect = driftCorrection.getParam(); } if (bool(cf.GetInt(MODULE_NAME, "Correct_Balance"))) { balCorrection = BalanceFunctor(driftParamVect); multiSignal = balCorrection(multiSignal); } // LED Add the FOV offset correction to bands 1-16 01/14/2011 if( bool(cf.GetInt(MODULE_NAME, "Correct_FOV_Offset"))) { FOV_Offset FOVoffset(L0,cf); multiSignal = FOVoffset.correct(multiSignal, earthInfo); } if (bool(cf.GetInt(MODULE_NAME, "Check_Infinity"))) { multiSignal = infinityCheck(multiSignal); } cout << MODULE_NAME << " Processing Summary:" << endl; audit(multiSignal); //correctionOutput = SigCorrectOutput(multiSignal, darkParamVect, driftParamVect, pointParmVect, //pointingCutoff); SigCorrectOutput correctionOutput(multiSignal, darkParamVect, driftParamVect, pointParmVect, pointingCutoff); correctionOutput.outputToEvent(L1); } catch (exception &ex) { strMsg = string("Exception caught in SignalCorrection: ") + ex.what(); L1.addLogEntry(strMsg); cerr << strMsg << endl; strMsg = "processing status at time of error:"; cerr << strMsg << endl; L1.addLogEntry(strMsg); audit(multiSignal); retCode = -300; } return retCode; }