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

ThresholdFitAlgorithm.cpp

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     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     return (first && second);
00021 }
00022     
00023 bool ThresholdFitAlgorithm::inMap = putInMap();
00024 
00025 ThresholdFitAlgorithm::ThresholdFitAlgorithm() throw() {
00026     FitterMode mode = getMode();
00027     mode.fitNone(); 
00028     mode.fitChips(); 
00029     mode.fitChannels() ; 
00030     mode.doSummary(false); 
00031     setMode(mode);
00032 }
00033 
00034 auto_ptr<FitObject> ThresholdFitAlgorithm::getPrototype() const throw() {
00035     return auto_ptr<FitObject> (new ErfcFitObject());
00036 }
00037 
00038 void ThresholdFitAlgorithm::guessParameters(const TH1& hist, FitObject& fitOb) const throw (LogicError, MathsError) {
00039     fitOb.setParameter(0, hist.GetMaximum() ) ;
00040     fitOb.fixParameter(0, true);
00041     fitOb.setParameter(1, findLevel(hist,0.5,false)) ;                 // 50% level
00042     double p2 = findLevel(hist, 0.82, false) - fitOb.getParameter(1);    // level 1-sigma away from 50%
00043     if (p2<0.) p2=-p2;  
00044     fitOb.setParameter(2, p2 ) ;
00045 
00046     int lbin=findBin(hist, 0.99, false); if ((lbin-1)>=1) lbin--;
00047     int ubin=findBin(hist, 0.01, false); if ((ubin+1)<hist.GetNbinsX()) ubin++;
00048     fitOb.setVarMin(0 , hist.GetBinLowEdge( lbin ) );    // Lower edge of bin before first bin < 99%
00049     fitOb.setVarMax(0 , hist.GetBinLowEdge( ubin+1 ) );    // Upper edge of bin after first bin <1% 
00050 }
00051 
00052 void ThresholdFitAlgorithm::checkForDefects(const FitObject& fo, const ModuleElement& element, DefectList& defects) const {
00053   if (fo.getNDF() &&  fo.getChiSquared()/fo.getNDF() > 5000 ) {
00055       cout << "Chi-squared: " << fo.getChiSquared() << " NDF: " << fo.getNDF() << " so claiming is DEAD" << endl;
00056       //defects.addDefect(Defect(StandardDefects::DEAD,element));
00057   }
00058 }
00059 
00060 void ThresholdFitAlgorithm::checkForDefects(const TH1& hist, const ModuleElement& element, DefectList& defects) const throw (LogicError) {
00061     double maxVal = hist.GetMaximum();
00062     double minVal = hist.GetMinimum();
00063     
00064     //Prevent ROOT calculating this millions of times!
00065     TH1* h_nonconst = const_cast<TH1*>(&hist);
00066     h_nonconst->SetMaximum(maxVal);
00067     h_nonconst->SetMinimum(minVal);
00068 
00069     if ( maxVal < StandardDefects::DEAD.getParameter() ){
00070     defects.addDefect(Defect(StandardDefects::DEAD, element));
00071     } else if( maxVal < StandardDefects::UNDER.getParameter() ){
00072     defects.addDefect(Defect(StandardDefects::UNDER,element));
00073     } else if( maxVal > StandardDefects::OVER.getParameter() ){
00074     defects.addDefect(Defect(StandardDefects::OVER,element));
00075     }
00076     if( minVal > StandardDefects::STUCKON.getParameter() ){
00077     defects.addDefect(Defect(StandardDefects::STUCKON, element));
00078     } 
00079     
00080 }
00081 
00082 void ThresholdFitAlgorithm::createSummaryHistograms(FitScanResult& fits) const throw() {
00083     /*
00084     string name = getUniqueID() + "Mean";
00085     string title = getClassName() + "." + getUniqueID() + " Mean";
00087     TH1D* rooth = new TH1D(name.c_str(), title.c_str(), 30, 0, 20);
00088     if (!rooth) throw InvalidArgument("FitScanResult::createSummaryHistograms() couldn't make histogram");
00089     for (vector<FitObject*>::iterator is = m_channelFits.begin(); is!= m_channelFits.end(); ++is ) {
00090     rooth->Fill( (*is)->getParameter(1) );
00091     }
00092 */
00093 }
00094     
00095 }

Generated on Thu Jul 8 11:41:21 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5