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() > StandardDefects::BADFIT.getParameter() ) {
00054       cout << "Chi-squared: " << fo.getChiSquared() << " NDF: " << fo.getNDF() << " so claiming is DEAD" << endl;
00055       defects.addDefect(Defect(StandardDefects::BADFIT,element));
00056   }
00057 }
00058 
00059 void ThresholdFitAlgorithm::checkForDefects(const TH1& hist, const ModuleElement& element, DefectList& defects) const throw (LogicError) {
00060     double maxVal = hist.GetMaximum();
00061     double minVal = hist.GetMinimum();
00062     
00063     //Prevent ROOT calculating this millions of times!
00064     TH1* h_nonconst = const_cast<TH1*>(&hist);
00065     h_nonconst->SetMaximum(maxVal);
00066     h_nonconst->SetMinimum(minVal);
00067     
00068     //Don't check for defects where the whole chip can be affected by a single channel,
00069     //which would already be marked as defective.  Examples are UNDER and OVER, where a single
00070     //UNDER or OVER channel would cause that chip to be UNDER or OVER
00071     bool minorDefectCheck = !(element.isChip() && getMode().fittingChannels());
00072 
00073     if ( maxVal < StandardDefects::DEAD.getParameter() ){
00074     defects.addDefect(Defect(StandardDefects::DEAD, element));
00075     } else if(minorDefectCheck && maxVal < StandardDefects::UNDER.getParameter() ){
00076     defects.addDefect(Defect(StandardDefects::UNDER,element));
00077     } else if(minorDefectCheck && maxVal > StandardDefects::OVER.getParameter() ){
00078     defects.addDefect(Defect(StandardDefects::OVER,element));
00079     }
00080     if( minVal > StandardDefects::STUCKON.getParameter() ){
00081     defects.addDefect(Defect(StandardDefects::STUCKON, element));
00082     } 
00083     
00084 }
00085 
00086 void ThresholdFitAlgorithm::createSummaryHistograms(FitScanResult& fits) const throw() {
00087     /*
00088     string name = getUniqueID() + "Mean";
00089     string title = getClassName() + "." + getUniqueID() + " Mean";
00091     TH1D* rooth = new TH1D(name.c_str(), title.c_str(), 30, 0, 20);
00092     if (!rooth) throw InvalidArgument("FitScanResult::createSummaryHistograms() couldn't make histogram");
00093     for (vector<FitObject*>::iterator is = m_channelFits.begin(); is!= m_channelFits.end(); ++is ) {
00094     rooth->Fill( (*is)->getParameter(1) );
00095     }
00096 */
00097 }
00098     
00099 }

Generated on Thu Jul 15 09:51:00 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5