Main Page   Modules   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

TimeWalkAlgorithm.cpp

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

Generated on Mon Dec 15 19:36:21 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3