00001 #include "StrobeDelayAlgorithm.h"
00002 #include "AnalysisAlgorithmMap.h"
00003 #include "SctData/StrobeDelayTestResult.h"
00004 #include "SctData/FitScanResult.h"
00005 #include "SctData/FitObject.h"
00006 #include "SctData/TopHatFitObject.h"
00007 #include "SctData/DefectList.h"
00008 #include "SctData/StandardDefects.h"
00009 #include <string>
00010
00011 using namespace std;
00012 using namespace boost;
00013 using namespace SctData;
00014 using namespace Sct;
00015
00016 namespace SctAnalysis {
00017
00018 bool StrobeDelayAlgorithm::inMap = AnalysisAlgorithmMap::instance().setAlgorithm("StrobeDelayTest", auto_ptr<AnalysisAlgorithm>(new StrobeDelayAlgorithm()));
00019
00020 shared_ptr<AnalysisAlgorithm> StrobeDelayAlgorithm::clone(const TestData& testData, const string& moduleName) const throw(){
00021 return shared_ptr<AnalysisAlgorithm>(new StrobeDelayAlgorithm(testData, moduleName, *this));
00022 }
00023
00024 shared_ptr<TestResult> StrobeDelayAlgorithm::createTestResult() const {
00025 return shared_ptr<StrobeDelayTestResult> (new StrobeDelayTestResult()) ;
00026 }
00027
00028 void StrobeDelayAlgorithm::loadData() {
00029 loadAllFits();
00030 }
00031
00032 bool StrobeDelayAlgorithm::canAnalyze() const {
00033 return hasAllFits();
00034 }
00035
00036 void StrobeDelayAlgorithm::analyze() {
00037 const double fraction=0.25;
00038
00039 StrobeDelayTestResult& result = *dynamic_pointer_cast<StrobeDelayTestResult>(getTestResult());
00040 const FitScanResult& fitted = *getFit(0);
00041 result.setScanVariable(fitted.getHeader().getVariable());
00042
00043 bool pass = true;
00044 result.setNOptima(nChipModule);
00045 for (short unsigned int ichip=0; ichip<nChipModule; ++ichip ) {
00046 const DefectSeverity& severity = result.getDefects().defectSeverityAffectingElement(ModuleElement::Chip(ichip));
00047 if (severity>=SERIOUS) pass=false;
00048 FitObject& fit = fitted.getChipFit(ichip);
00049 try {
00050 dynamic_cast<TopHatFitObject&> (fit);
00051 } catch(std::exception& e) {
00052 throw InvariantViolatedError("StrobeDelayAlgorithm::optimize ERROR not a TopHat function", __FILE__, __LINE__);
00053 }
00054 double rise=fit.getParameter(1), fall=fit.getParameter(3);
00055 result.setOptimum(ichip, rise + fraction*(fall-rise));
00056 if (rise < 0 || fall < StandardDefects::SD_LO.getParameter()) {
00057 result.getDefects().addDefect(Defect(StandardDefects::SD_LO, ModuleElement::Chip(ichip)));
00058 pass = false;
00059 }
00060 if (rise > StandardDefects::SD_HI.getParameter() || fall > 63) {
00061 result.getDefects().addDefect(Defect(StandardDefects::SD_HI, ModuleElement::Chip(ichip)));
00062 pass = false;
00063 }
00064 }
00065 result.setPassed(pass);
00066 }
00067
00068
00069 }