00001 #include "ThresholdFitAlgorithm.h"
00002 #include "FitAlgorithmMap.h"
00003 #include "FitterMode.h"
00004 #include "SctData/mVThresholdVariable.h"
00005 #include "SctData/ModuleDefect.h"
00006 #include "SctData/ErfcFitObject.h"
00007 #include <TH1.h>
00008
00009 using namespace SctData;
00010
00011 namespace SctFitter {
00012
00013 bool ThresholdFitAlgorithm::putInMap() throw() {
00014 return FitAlgorithmMap::instance().setAlgorithm(mVThresholdVariable::instance().getVariableName(), auto_ptr<FitAlgorithm>(new ThresholdFitAlgorithm));
00015 }
00016
00017 bool ThresholdFitAlgorithm::inMap = putInMap();
00018
00019 ThresholdFitAlgorithm::ThresholdFitAlgorithm() throw() {
00020 FitterMode& mode = getMode();
00021 mode.fitNone();
00022 mode.fitChips();
00023 mode.fitChannels() ;
00024 mode.doSummary(false);
00025 }
00026
00027 auto_ptr<FitObject> ThresholdFitAlgorithm::getPrototype() const throw() {
00028 return auto_ptr<FitObject> (new ErfcFitObject());
00029 }
00030
00031 void ThresholdFitAlgorithm::guessParameters(const TH1& hist, FitObject& fitOb) const throw (LogicError, MathsError) {
00032 fitOb.setParameter(0, hist.GetMaximum() ) ;
00033 fitOb.fixParameter(0, true);
00034 fitOb.setParameter(1, findLevel(hist,0.5,false)) ;
00035 double p2 = findLevel(hist, 0.82, false) - fitOb.getParameter(1);
00036 if (p2<0.) p2=-p2;
00037 fitOb.setParameter(2, p2 ) ;
00038
00039 int lbin=findBin(hist, 0.99, false); if ((lbin-1)>=1) lbin--;
00040 int ubin=findBin(hist, 0.01, false); if ((ubin+1)<hist.GetNbinsX()) ubin++;
00041 fitOb.setVarMin(0 , hist.GetBinLowEdge( lbin ) );
00042 fitOb.setVarMax(0 , hist.GetBinLowEdge( ubin+1 ) );
00043 }
00044
00045 void ThresholdFitAlgorithm::checkForDefects(const TH1& hist, const ModuleElement& element, ModuleDefectList& defects) const throw (LogicError) {
00046 double maxVal = hist.GetMaximum();
00047 double minVal = hist.GetMinimum();
00048
00049
00050 TH1* h_nonconst = const_cast<TH1*>(&hist);
00051 h_nonconst->SetMaximum(maxVal);
00052 h_nonconst->SetMinimum(minVal);
00053
00054 if ( maxVal < ModuleDefect::DEAD.getParameter() ){
00055 defects.addDefect(ModuleDefect::DEAD, element);
00056 } else if( maxVal < ModuleDefect::UNDER.getParameter() ){
00057 defects.addDefect(ModuleDefect::UNDER,element);
00058 } else if( maxVal > ModuleDefect::OVER.getParameter() ){
00059 defects.addDefect(ModuleDefect::OVER,element);
00060 }
00061 if( minVal > ModuleDefect::STUCKON.getParameter() ){
00062 defects.addDefect(ModuleDefect::STUCKON, element);
00063 }
00064
00065 }
00066
00067 void ThresholdFitAlgorithm::createSummaryHistograms(FitScanResult& fits) const throw() {
00068
00069
00070
00072
00073
00074
00075
00076
00077
00078 }
00079
00080 }