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

ThresholdFitAlgorithm2.cpp

00001 #include "ThresholdFitAlgorithm2.h"
00002 #include "FitAlgorithmMap.h"
00003 #include "FitterMode.h"
00004 #include "SctData/mVThresholdVariable.h"
00005 #include "SctData/mVfromTrimTargetThresholdVariable.h"
00006 #include "SctData/ErfcFitObject.h"
00007 #include "SctData/StandardDefects.h"
00008 #include <TH1.h>
00009 
00010 using namespace SctData;
00011 
00012 namespace SctFitter {
00013     
00014     
00015 ThresholdFitAlgorithm2::ThresholdFitAlgorithm2() throw() {
00016     FitterMode mode = getMode();
00017     mode.fitNone(); 
00018     mode.fitChips(); 
00019     mode.fitChannels() ; 
00020     mode.doSummary(false);     
00021     setMode(mode);
00022 }
00023 
00024 bool ThresholdFitAlgorithm2::putInMap() throw() {    
00025     inMap = FitAlgorithmMap::instance().setAlgorithm(mVThresholdVariable::instance().getVariableName(), auto_ptr<FitAlgorithm>(new ThresholdFitAlgorithm2));
00026     inMap |= FitAlgorithmMap::instance().setAlgorithm(mVfromTrimTargetThresholdVariable::instance().getVariableName(), auto_ptr<FitAlgorithm>(new ThresholdFitAlgorithm2));
00027     inMap |= FitAlgorithmMap::instance().setAlgorithm("Default Variable", auto_ptr<FitAlgorithm>(new ThresholdFitAlgorithm2));
00028     return inMap;
00029 }
00030     
00031 bool ThresholdFitAlgorithm2::inMap = false;
00032 
00033 void ThresholdFitAlgorithm2::doFit(const TH1& hist, FitObject& fitObject,
00034                    const ModuleElement& element, DefectList& defects) const throw (LogicError) {
00035     
00036     double amp = hist.GetBinContent(1);
00037     unsigned int ampCount = 1;
00038     double mean = 0;
00039     double meanx2 = 0;
00040     double norm = 0;
00041     double last = hist.GetBinContent(1);
00042     bool flatTop = true;
00043     
00044     for (unsigned int i=2; i<=hist.GetNbinsX(); ++i) {
00045     double bin = hist.GetBinContent(i);
00046     double bincentre = hist.GetBinLowEdge(i);
00047     double error = hist.GetBinError(i);
00048     double diff = bin-last;
00049     norm += diff;
00050     if (flatTop && error < (amp/ampCount - bin)) {
00051         //cout << "diff>error: " << amp << " error: " << error << " last: "<< last << " bin: " << i << " bincentre" << bincentre << endl; 
00052         flatTop = false;
00053     }
00054     if (flatTop) {
00055         amp += bin;
00056         ++ampCount;
00057     }
00058     mean += diff * bincentre;
00059     meanx2 += diff*bincentre* bincentre;
00060     last = bin;
00061     }
00062  
00063     //cout << "amp: " << amp << " ampCount: " << ampCount << " mean: " << mean << " meanx2 " << meanx2 << endl;
00064     
00065     amp /= ampCount;
00066     //mean /= 1-hist.GetNbinsX();
00067     mean /= norm;
00068     //double sigma = sqrt(meanx2 /(1-hist.GetNbinsX()) - mean * mean);
00069     double sigma = sqrt(meanx2/norm - mean * mean);
00070     
00071     //cout << "amp: " << amp << " mean: " << mean << " sigma: " << sigma << endl;;
00072     
00073     
00074     fitObject.setParameter(0, amp);
00075     fitObject.setParameter(1, mean);
00076     fitObject.setParameter(2, sigma);
00077     fitObject.setParError(0, 0);
00078     fitObject.setParError(1, 0);
00079     fitObject.setParError(2, 0);    
00080 }
00081 
00082     
00083 auto_ptr<FitObject> ThresholdFitAlgorithm2::getPrototype() const throw() {
00084     return auto_ptr<FitObject> (new ErfcFitObject());
00085 }
00086     
00087 void ThresholdFitAlgorithm2::guessParameters(const TH1& hist, FitObject& fitOb) const throw (LogicError, MathsError) {
00088 }
00089 
00090 
00091 void ThresholdFitAlgorithm2::checkForDefects(const FitObject& fo, const ModuleElement& element, 
00092                          DefectList& defects) const {
00093   if (fo.getNDF() &&  fo.getChiSquared()/fo.getNDF() > StandardDefects::BADFIT.getParameter() ) {
00094     cout << "Chi-squared: " << fo.getChiSquared() << " NDF: " << fo.getNDF() << endl;
00095       defects.addDefect(Defect(StandardDefects::BADFIT,element));
00096   }
00097      
00098 }
00099 
00100 void ThresholdFitAlgorithm2::checkForDefects(const TH1& hist, const ModuleElement& element, 
00101                          DefectList& defects) const throw (LogicError) {
00102 }
00103 
00104 void ThresholdFitAlgorithm2::createSummaryHistograms(FitScanResult& fits) const throw() {
00105 }
00106 }

Generated on Fri Sep 16 18:02:02 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5