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