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

ThresholdFitAlgorithm2.cpp

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

Generated on Mon Dec 15 19:36:21 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3