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

ChipCounterAlgorithm.cpp

00001 #include "ChipCounterAlgorithm.h"
00002 #include "AnalysisAlgorithmMap.h"
00003 #include "SctData/ChipCounterTestResult.h"
00004 #include "SctData/StandardDefects.h"
00005 //#include "SctData/FitObject.h"
00006 #include "SctData/RawScanResult.h"
00007 #include <cfloat>
00008 #include "TH2.h"
00009 #include "Sct/SctNames.h"
00010 
00011 // gcc296 needs a declaration of fabs
00012 #include <cmath>
00013 #include <set>
00014 
00015 using namespace std;
00016 using namespace boost;
00017 using namespace SctData;
00018 using namespace Sct;
00019 
00020 namespace SctAnalysis {
00021     
00022     bool ChipCounterAlgorithm::inMap = AnalysisAlgorithmMap::instance().setAlgorithm("ChipCounterTest", auto_ptr<AnalysisAlgorithm>(new ChipCounterAlgorithm()));
00023     
00024     shared_ptr<AnalysisAlgorithm> ChipCounterAlgorithm::clone(const TestData& testData, const string& moduleName) const throw() {
00025     return shared_ptr<AnalysisAlgorithm>(new ChipCounterAlgorithm(testData, moduleName, *this));
00026     }
00027 
00028     void ChipCounterAlgorithm::loadData() {
00029     loadAllRaws();
00030     }
00031     
00032     bool ChipCounterAlgorithm::canAnalyze() const{
00033     return hasAllRaws();
00034     }
00035     
00036     shared_ptr<TestResult> ChipCounterAlgorithm::createTestResult() const {
00037     return shared_ptr<ChipCounterTestResult> (new ChipCounterTestResult());
00038     }
00039        
00040     void ChipCounterAlgorithm::analyze() {
00041       ChipCounterTestResult & result =  *dynamic_pointer_cast<ChipCounterTestResult> ( getTestResult() );
00042       
00043       const RawScanResult& raw = *getRaw(0);
00044       result.setScanVariable(raw.getHeader().getVariable());    
00045 
00046       const SctData::ScanPoints& points=raw.getPoints();
00047       const unsigned int numberOfScanPoints = points.getNPoints();
00048  
00049       const TH2& data0 = raw.getScanData(0);
00050       const TH2& data1 = raw.getScanData(1);
00051 
00052       const unsigned nx0 = data0.GetNbinsX();
00053       const unsigned ny0 = data0.GetNbinsY();
00054       const unsigned nx1 = data1.GetNbinsX();
00055       const unsigned ny1 = data1.GetNbinsY();
00056       if((!(ny0==numberOfScanPoints)) || (!(ny1==numberOfScanPoints))) { 
00057     throw IllegalStateError("This should not be!",__FILE__,__LINE__);
00058       };
00059       if((ny0<=0) || (ny1<=0) ||  (!(ny0==ny1))) {
00060     throw IllegalStateError("This should not be!",__FILE__,__LINE__);
00061       };
00062 
00063       // Find where the header bit starts 
00064       
00065       unsigned int i = 1;
00066       unsigned int nstart0 = 0;
00067       while ( i <= nx0 ) {
00068     if (data0.GetBinContent(i,1) == 0)  ++i;        
00069     if (data0.GetBinContent(i,1) == 1)  {
00070       nstart0=i;
00071       i=nx0+1;
00072     }        
00073       }
00074 
00075       i = 1;
00076       unsigned int nstart1 = 0;
00077       while ( i <= nx1 ) {
00078     if (data1.GetBinContent(i,1) == 0)  ++i;        
00079     if (data1.GetBinContent(i,1) == 1)  {
00080       nstart1=i;
00081       i=nx1+1;
00082     }        
00083       }
00084       
00085       // In this case, one of the links returned all 0's. How to deal with this?!?
00086       if ((nstart0 ==0) || (nstart1 ==0)) {
00087     throw IllegalStateError("This should not be!",__FILE__,__LINE__);
00088       }
00089       
00090       //      header: 111010 LLLL BBBBBBBB 101 = 21 bit header
00091       
00092       bool problemInBit[NBC+NL1];
00093       for (unsigned ibit=0; ibit<NBC+NL1; ++ibit){
00094     problemInBit[ibit]=false;
00095       }
00096 
00097       // Check the L1 and BC counters now
00098       for (int ibin=NHEADER; ibin<(NHEADER+NBC+NL1); ++ibin) { 
00099     unsigned int allzeros=1; //check that both counters have not failed to be all 0s
00100     
00101     for (unsigned int j=0; j< numberOfScanPoints; ++j) { 
00102       if (!(data0.GetBinContent(nstart0+ibin, j+1) == data1.GetBinContent(nstart1+ibin, j+1))) {
00103         // then the two counters are different. Report defect. 
00104         problemInBit[ibin-NHEADER]=true;
00105       }
00106       if ((data0.GetBinContent(nstart0+ibin, j+1) == 1)) allzeros =0;
00107     }
00108     
00109     // also a defect if all zeros in that bin (need at least 15 triggers for this to be true!)
00110     if (allzeros == 1) problemInBit[ibin-NHEADER]=true;
00111 
00112       }
00113       
00114       bool setpassed=true;
00115 
00116       for (int ibit=0; ibit<NBC+NL1; ++ibit){
00117     if ( problemInBit[ibit] == true ) {
00118       if (ibit < (NL1)) {
00119         result.getDefects().addDefect(Defect(StandardDefects::L1_COUNTER, ModuleElement::Module()));
00120         ostringstream oss;
00121         oss << "Counter error in L1 bit (LSB=0) " << NL1-1-(ibit);  
00122         result.addComment(oss.str());
00123         setpassed=false;
00124       } else {
00125         result.getDefects().addDefect(Defect(StandardDefects::BC_COUNTER, ModuleElement::Module()));
00126         ostringstream oss;
00127         oss << "Counter error in BC bit (LSB=0) " << NBC-1-(ibit-NL1);  
00128         result.addComment(oss.str());
00129         setpassed=false;
00130       }
00131     }
00132       }
00133       
00134       result.setPassed(setpassed);
00135       result.setProblem(!setpassed);
00136       
00137     }
00138 } // end of namespace SctAnalysis

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