StrobeDelayAlgorithm.cpp

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(shared_ptr<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.4;
00038     StrobeDelayTestResult& result = *dynamic_pointer_cast<StrobeDelayTestResult>(getTestResult());
00039     const FitScanResult& fitted = *getFit(0);
00040     result.setScanVariable(fitted.getHeader().getVariable());   
00041 
00042     bool pass = true;
00043     bool problem = false;
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 
00055       double rise_value=fit.getParameter(1), fall_value=fit.getParameter(3);
00056       double rise_width=fit.getParameter(2), fall_width=fit.getParameter(4);
00057 
00058       result.setOptimum(ichip, rise_value + fraction*(fall_value-rise_value));
00059 
00060       if (rise_value < 0) {
00061     result.getDefects().addDefect(Defect(StandardDefects::SD_LO, ModuleElement::Chip(ichip)));
00062     pass = false;
00063     ostringstream msg;
00064     msg << "Chip (0-11) #" << ichip << " mid-rise is at " << rise_value;
00065     result.addComment(msg.str());
00066       } else if (rise_value-rise_width < 1){
00067     problem=true;
00068     ostringstream msg;
00069     msg << "Chip (0-11) #" << ichip << " 1-sigma before mid-rise is at " << rise_value-rise_width;
00070     result.addComment(msg.str());
00071       }
00072       if (fall_value > 63) {
00073     result.getDefects().addDefect(Defect(StandardDefects::SD_HI, ModuleElement::Chip(ichip)));
00074     pass = false;
00075     ostringstream msg;
00076     msg << "Chip (0-11) #" << ichip << " mid-fall is at " << fall_value;
00077     result.addComment(msg.str());
00078       } else if (fall_value+fall_width>62){
00079     problem=true;
00080     ostringstream msg;
00081     msg << "Chip (0-11) #" << ichip << " 1-sigma after mid-fall is at " << fall_value+fall_width;
00082     result.addComment(msg.str());
00083       }
00084     }
00085     result.setPassed(result.getDefects().nChannelsAffected()<(128*2));
00086     result.setProblem(problem);
00087 }
00088 
00089 
00090 }

Generated on Mon Feb 6 14:01:30 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6