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

RxThresholdAlgorithm.cpp

00001 #include "RxThresholdAlgorithm.h"
00002 #include "AnalysisAlgorithmMap.h"
00003 #include "SctData/RxThresholdTestResult.h"
00004 #include "SctData/RawScanResult.h"
00005 #include "SctData/FitObject.h"
00006 #include "SctData/TopHatFitObject.h"
00007 #include "SctData/DefectList.h"
00008 #include "SctData/StandardDefects.h"
00009 #include <string>
00010 #include "TH2.h"
00011 
00012 using namespace std;
00013 using namespace boost;
00014 using namespace SctData;
00015 using namespace Sct;
00016 
00017 namespace SctAnalysis {
00018     
00019 bool RxThresholdAlgorithm::inMap = AnalysisAlgorithmMap::instance().setAlgorithm("RxThresholdTest", auto_ptr<AnalysisAlgorithm>(new RxThresholdAlgorithm()));
00020 
00021 shared_ptr<AnalysisAlgorithm> RxThresholdAlgorithm::clone(const TestData& testData, const string& moduleName) const throw(){
00022     return shared_ptr<AnalysisAlgorithm>(new RxThresholdAlgorithm(testData, moduleName, *this));
00023 }
00024 
00025 shared_ptr<TestResult> RxThresholdAlgorithm::createTestResult() const {
00026     return shared_ptr<RxThresholdTestResult> (new RxThresholdTestResult()) ;
00027 }
00028 
00029 void RxThresholdAlgorithm::loadData() {
00030     loadAllRaws();
00031 }
00032 
00033 bool RxThresholdAlgorithm::canAnalyze() const {
00034     return hasAllRaws();
00035 }
00036 
00037 void RxThresholdAlgorithm::analyze() {
00038     RxThresholdTestResult& result = *dynamic_pointer_cast<RxThresholdTestResult>(getTestResult());
00039     const RawScanResult& raw = *getRaw(0);
00040     result.setScanVariable(raw.getHeader().getVariable());  
00041     
00042     const SctData::ScanPoints& points=raw.getPoints();
00043     bool ascending = points.ascending();
00044     bool pass = true;
00045     result.setNOptima(nLinkModule);
00046     for (short unsigned int ilink=0; ilink<nLinkModule; ++ilink ) {
00047       const TH2& data = raw.getScanData(ilink);
00048       const unsigned nx = data.GetNbinsX();
00049       const unsigned ny = data.GetNbinsY();
00050       double* projection = new double[ny];
00051       int start=-1;
00052       int stop =-1;
00053       for (unsigned iy=0; iy<ny; ++iy){
00054     const unsigned ipt = ascending ? iy : ny-iy-1;
00055     projection[ipt]=0;
00056     for (unsigned ix=0; ix<nx; ++ix){
00057       projection[iy]+=data.GetBinContent(ix+1,ipt+1);
00058     }
00059         double compare = points.getNEvents(ipt)*nx*0.75;
00060     if (ipt>0 && projection[ipt]<compare && projection[ipt-1]>compare) {
00061       std::cout << ipt << "=" << points[ipt] << " " 
00062             << projection[ipt-1] << " -> " << projection[ipt]
00063                 << " : " << compare << std::endl;
00064       if (start!=-1) pass=false;
00065       start=ipt;
00066     }
00067         compare = points.getNEvents(ipt)*nx*0.25;
00068     if (ipt>0 && projection[ipt]<compare && projection[ipt-1]>compare) {
00069       std::cout << ipt << "=" << points[ipt] << " " 
00070             << projection[ipt-1] << " -> " << projection[ipt]
00071                 << " : " << compare << std::endl;     
00072       if (stop!=-1) pass=false;
00073       stop=ipt;
00074     }
00075       }
00076       
00077       cout << "start = " << start << ", stop = " << stop << endl;
00078 
00079       double optimum=-1;
00080       const double fraction= 0.5;
00081       const unsigned zero  = ascending ? 0 : ny-1;
00082       const unsigned end   = ascending ? ny-1 : 0;
00083       
00084       if (start==-1&&stop==-1){
00085     optimum=points[zero]+fraction*(points[end]-points[zero]);
00086       } else if (start==-1){
00087     optimum=points[zero]+fraction*(points[stop]-points[zero]);
00088       } else if (stop==-1){
00089     optimum=points[start]+fraction*(points[end]-points[start]);
00090       }else{
00091     optimum=points[start]+fraction*(points[stop]-points[start]);
00092       }
00093       cout << "optimum=" << optimum << endl;
00094       result.setOptimum(ilink, optimum);
00095     }
00096     result.setPassed(pass);
00097 }
00098 
00099 
00100 }

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