TimeWalkAlgorithm.cpp

00001 #include "TimeWalkAlgorithm.h"
00002 #include "AnalysisAlgorithmMap.h"
00003 #include "SctData/TimeWalkTestResult.h"
00004 #include "SctData/StandardDefects.h"
00005 #include "SctData/FitObject.h"
00006 #include "SctData/FitScanResult.h"
00007 #include <cfloat>
00008 // gcc296 needs a declaration of fabs
00009 #include <cmath>
00010 
00011 using namespace std;
00012 using namespace boost;
00013 using namespace SctData;
00014 using namespace Sct;
00015 
00016 namespace SctAnalysis {
00017     
00018     bool TimeWalkAlgorithm::inMap = AnalysisAlgorithmMap::instance().setAlgorithm("TimeWalkTest", auto_ptr<AnalysisAlgorithm>(new TimeWalkAlgorithm()));
00019     
00020     shared_ptr<AnalysisAlgorithm> TimeWalkAlgorithm::clone(shared_ptr<const TestData> testData, const string& moduleName) const throw() {
00021     return shared_ptr<AnalysisAlgorithm>(new TimeWalkAlgorithm(testData, moduleName, *this));
00022     }
00023 
00024     void TimeWalkAlgorithm::loadData() {
00025     loadAllFits();
00026     }
00027 
00028     
00029     bool TimeWalkAlgorithm::canAnalyze() const{
00030     return hasAllFits();
00031     }
00032     
00033     shared_ptr<TestResult> TimeWalkAlgorithm::createTestResult() const {
00034     return shared_ptr<TimeWalkTestResult> (new TimeWalkTestResult());
00035     }
00036     
00037     void TimeWalkAlgorithm::analyze() {
00038     bool debug=false;
00039 
00040     shared_ptr<TimeWalkTestResult> result =  dynamic_pointer_cast<TimeWalkTestResult> ( getTestResult() );
00041     result->setScanVariable(getFit(0)->getHeader().getVariable());  
00042 
00043     float min_time[nChipModule];
00044     float max_time[nChipModule];
00045     for (unsigned ichip=0; ichip<nChipModule; ++ichip){
00046         min_time[ichip]=FLT_MAX;  // large positive number
00047         max_time[ichip]=-FLT_MAX; // large negative number
00048     }
00049 
00050     for (unsigned index=0; index<result->getNScans() ; ++index){
00051         shared_ptr<const FitScanResult> fit=getFit(index);
00052 
00053         if (!fit.get()) {
00054         ostringstream os;
00055         os << "TimeWalkAlgorithm: unable to get scan at index " << index <<ends;
00056         throw IllegalStateError(os.str(), __FILE__, __LINE__);
00057         }
00058         
00059         if (debug) cout << "TimeWalkAlgorithm, scan #" << index << endl;
00060 
00061         for (unsigned ichip=0; ichip<nChipModule; ++ichip){
00062         TimeWalkTestResult::ChipTWResult& cr = result->getChipResult(ichip);
00063         FitObject& fobj =fit->getChipFit(ichip);
00064         
00065         // on last point calculate calibration factor.
00066         if (debug) cout << index << "," 
00067                 << result->getNScans()-1 << endl;
00068         if (index==result->getNScans()-1){
00069             cr.calibration = // mid-rise - mid-fall
00070             fabs(fobj.getParameter(1) - fobj.getParameter(3));
00071             if (debug) {
00072             cout << "Calibration for chip "
00073                  << ichip << " = " << cr.calibration<< endl;
00074             }
00075             
00076         }
00077         if (fobj.getParameter(3) < min_time[ichip]){
00078             min_time[ichip]=fobj.getParameter(3);
00079         }
00080         if (fobj.getParameter(3) > max_time[ichip]){
00081             max_time[ichip]=fobj.getParameter(3);
00082         }
00083         }
00084     }
00085     
00086     bool pass = true;
00087 
00088     for (unsigned ichip=0; ichip<nChipModule; ++ichip){
00089         TimeWalkTestResult::ChipTWResult& cr = result->getChipResult(ichip);
00090         cr.timewalk=max_time[ichip]-min_time[ichip];
00091         if (debug) {
00092         cout << "Time-walk for chip " << ichip
00093              << " = " <<  cr.timewalk << endl;
00094         }
00095         if (cr.timewalk<StandardDefects::TW_LO.getParameter()){
00096         result->getDefects().addDefect(Defect(StandardDefects::TW_LO, ModuleElement::Chip(ichip)));
00097         pass = false;
00098         }
00099         if (cr.timewalk>StandardDefects::TW_HI.getParameter()){
00100         result->getDefects().addDefect(Defect(StandardDefects::TW_HI, ModuleElement::Chip(ichip)));
00101         pass = false;
00102         }
00103     }
00104 
00105     result->setPassed(pass);
00106     if (debug) cout << "TimeWalkAlgorithm done" << endl;
00107     }
00108 } // end of namespace SctAnalysis

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