/** $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 DetectorTimeShift.cpp @author John Burton @creationdate Thu May 4 17:01:31 2006 @brief removes time shifts from detector signals ----------------------------------------------------------------------- Modification History: $Log$ ----------------------------------------------------------------------- */ //---------------------------------------------------------------------- // Include Files: //----------------------------------------------------------------------- // #include "ConfigFile.h" #include "EventVar.h" #include "DetectorTimeShift.h" #include "CorrectDetectorTime.h" #include "StrTools.h" #include "ValarrayConv.h" #include "InterpDetTem.h" #include "SOFIE_namespace.h" #include "FixDiffSign.h" #include #include #include using namespace std; // //----------------------------------------------------------------------- // Defines and Macros: //----------------------------------------------------------------------- // // //----------------------------------------------------------------------- // Global Variables: //----------------------------------------------------------------------- // // //----------------------------------------------------------------------- // Utility Routines: //----------------------------------------------------------------------- // int DetectorTimeShift(Event& L0, Event& L1, Event& Tmp, Event& SD, ConfigFile& cf) { const string MODULE_NAME = "DetectorTimeShift"; EventVar DetSignal; EventVarVect InEventVect; EventVarVect CorrectedEventVect; EventVar timeArray; EventVar attenArray; EventVar hskpTime; EventVarVect hskpDetTemperature; EventVarVect detectorTemperature; vector timeCorrections; valarray valVar; CorrectDetectorTime shiftTimes; FixDiffSign fixDiff; vector > inSignals; vector > outSignals; valarray time; InterpDetTem temperatureInterp; string strMsg; int retCode = 0; try { double filter_shift = cf.GetReal(MODULE_NAME, "FilterTimeShift"); fillTimeCorrections(timeCorrections); shiftTimes = CorrectDetectorTime(timeCorrections, filter_shift); L0.getEventVar("L0_DetectorTimes", timeArray); L0.getEventVar("L0_DetectorSignals", InEventVect); time.resize(timeArray.size()); time = timeArray; ConvToValarrayVec(InEventVect, inSignals); shiftTimes.correct_signal(inSignals, time, outSignals); if (bool(cf.GetInt(MODULE_NAME, "FixDiffSignals"))) { fixDiff(outSignals); } ConvToEventVect(outSignals, CorrectedEventVect); CorrectedEventVect.setName("L1_TimeShiftedSignals"); L1.addEventVar(CorrectedEventVect); timeArray.setName("L1_DetectorTimes"); L1.addEventVar(timeArray); // Put attenuator settings in the same 'box' as time and signals L0.getEventVar("L0_AttenuatorSettings",attenArray); attenArray.setName("L1_AttenuatorSettings"); L1.addEventVar(attenArray); // Interpolate Detector Temperatures to detector time grid temperatureInterp = InterpDetTem(timeArray); L0.getEventVar("L0_HousekeepingTimes", hskpTime); L0.getEventVar("L0_DetectorTemperatures", hskpDetTemperature); temperatureInterp.interpolate(hskpDetTemperature,hskpTime, detectorTemperature); detectorTemperature.setName("L1_DetectorTemperatures"); L1.addEventVar(detectorTemperature); } catch (exception &ex) { strMsg = string("Exception caught in ") + MODULE_NAME + string(": ") + ex.what(); cerr << strMsg << endl; retCode = -200; } return retCode; } void fillTimeCorrections(vector &timeCorrections) // // Temprorary function which fills the time correction array // with hard coded values. Will eventually be replaced by // a call to the database. // { timeCorrections = vector(SOFIE::tot_det_signals); vector mux_offsets (SOFIE::no_of_detectors); const double timeStampInterval = 0.05; const double offset = 0.00625; double avg_mux_offset; int i; int j; // set up time offset for detectors mux_offsets[0] = - 0.0041293787; mux_offsets[1] = - 0.0028712753; mux_offsets[2] = - 0.0028712753; mux_offsets[3] = - 0.0028333439; mux_offsets[4] = - 0.014197803; mux_offsets[5] = - 0.01140578; mux_offsets[6] = - 0.0086537903; mux_offsets[7] = - 0.0062550412; mux_offsets[8] = - 0.014480653; mux_offsets[9] = - 0.012051313; mux_offsets[10] = - 0.0051167928; mux_offsets[11] = - 0.0032423271; mux_offsets[12] = 0.00013291201; mux_offsets[13] = - 0.0017466508; mux_offsets[14] = - 0.0054042806; mux_offsets[15] = 0.00038840854; avg_mux_offset = accumulate(mux_offsets.begin(), mux_offsets.end(), 0.0)/mux_offsets.size(); // for (i = 0; i < SOFIE::no_of_detectors; i++) // timeCorrections[i] = - timeStampInterval - mux_offsets[i]; // for (i = 0; i < SOFIE::no_of_detectors; i++) // timeCorrections[i] = - timeStampInterval + mux_offsets[i]; for(i = 0; i < 4; i++) for(j = 0; j < 4; j++) { timeCorrections[j + 4*i] = - timeStampInterval + 2.*j*offset + mux_offsets[j + 4*i]; } for(i = 0; i < 4; i++) for(j = 0; j < 2; j++) { timeCorrections[j + 2*i + 16] = - timeStampInterval + (1 + 4.*j)*offset + avg_mux_offset; } }