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