00001 #ifndef THRESHOLDSCAN_H
00002 #define THRESHOLDSCAN_H
00003
00004 #include <cmath>
00005
00006 #include "../ipc/CalibrationController.hh"
00007 #include "../CalibrationControllerImpl.h"
00008 #include "../ipc/ScanRequest.h"
00009 #include "../SctApiAccessException.h"
00010 #include "../SctApiCall.h"
00011
00012
00013 #include <Sct/AbcdScans.h>
00014
00015 using namespace Sct;
00016 using namespace SctCalibrationController::Ipc;
00017 namespace SctCalibrationController {
00018 namespace Scripts {
00019
00020 class ThresholdScan : public ScanRequestImpl {
00021 public:
00022 static ScanRequestImpl& thresholdScan(unsigned long nTrigs, double calChargefC = -1, double offset=0) {
00023 static ThresholdScan request;
00024 Sct_SctApi::SctApiIPC_var api = CalibrationControllerImpl::instance()->getApi();
00025 Sct_SctApi::Scan_var s;
00026 APIRETCALL(api, s, createScan(), "Failed to create scan")
00027
00028 request.setScanNice(s);
00029
00030 APICALL(s, setNTrigs(nTrigs), "Failed to set triggers")
00031
00032 Sct_SctApi::Trigger_var t;
00033 APIRETCALL(s, t, getTrigger1(), "Failed to get Trigger1")
00034
00035 APICALL(t, calL1A(0x82), "Failed to set trigger type")
00036
00037 if (fabs(calChargefC) > 0.05) {
00038 APICALL(s, setOption(Sct_SctApi::Scan::loopCalLine, 1), "Failed to set loopCalLine")
00039 }
00040
00041 double lo = 40.0 * calChargefC + offset/2.;
00042 double hi = 150.0 + 60.0 * calChargefC + offset;
00043
00044
00045 if (calChargefC > 0 && lo < lowLimit || calChargefC < 0) lo = lowLimit;
00046 else if (lo < 0) lo = 0;
00047 if (hi > highLimit || calChargefC < 0) hi = highLimit;
00048 if (hi < lo) hi = lo + 100;
00049
00050 APICALL(s, configure(ST_VTHR, lo, hi, 5), "Failed to set Scan information")
00051 return request;
00052 }
00053
00054 private:
00055 ThresholdScan(){;}
00056
00057 static const double lowLimit = 0;
00058 static const double highLimit = 633;
00059 };
00060
00061 }
00062 }
00063
00064 #endif //THRESHOLDSCAN_H