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

PipelineAlgorithm.cpp

00001 #include "PipelineAlgorithm.h"
00002 #include "AnalysisAlgorithmMap.h"
00003 #include "SctData/PipelineTestResult.h"
00004 #include "SctData/StandardDefects.h"
00005 #include "SctData/OccupancyProjector.h"
00006 #include <TH1.h>
00007 #include <TH2.h>
00008 
00009 using namespace std;
00010 using namespace boost;
00011 using namespace SctData;
00012 using namespace Sct;
00013 
00014 namespace SctAnalysis {
00015     
00016     bool PipelineAlgorithm::inMap = AnalysisAlgorithmMap::instance().setAlgorithm("PipelineTest", auto_ptr<AnalysisAlgorithm>(new PipelineAlgorithm()));
00017     
00018     shared_ptr<AnalysisAlgorithm> PipelineAlgorithm::clone(const TestData& testData, const string& moduleName) const throw() {
00019     return shared_ptr<AnalysisAlgorithm>(new PipelineAlgorithm(testData, moduleName, *this));
00020     }
00021 
00022     shared_ptr<TestResult> PipelineAlgorithm::createTestResult() const {
00023     return shared_ptr<TestResult>(new PipelineTestResult());
00024     }
00025     
00026     void PipelineAlgorithm::loadData() {
00027     loadAllRaws();
00028     }
00029     
00030     bool PipelineAlgorithm::canAnalyze() const {
00031     return PipelineAlgorithm::hasAllRaws();
00032     }
00033     
00034     void PipelineAlgorithm::analyze() {
00035     shared_ptr<PipelineTestResult> result = dynamic_pointer_cast<PipelineTestResult>(getTestResult());
00036     result->setScanVariable(getRaw(0)->getHeader().getVariable());  
00037     shared_ptr<const RawScanResult> rawa=getRaw(0);
00038     shared_ptr<const RawScanResult> rawb=getRaw(1);
00039     
00040     bool pass = true;
00041 
00042     // quick check:
00043     if (rawa->getScanData(0).GetNbinsY() != rawb->getScanData(0).GetNbinsY() ||
00044         rawa->getScanData(1).GetNbinsY() != rawb->getScanData(1).GetNbinsY() ){
00045         ostringstream os;
00046         os << "PipelineAlgorithm different y-extent of scans " << rawa->getHeader().getScanNumber()
00047            << " and " << rawb->getHeader().getScanNumber() <<ends;
00048         throw IllegalStateError(os.str(), __FILE__, __LINE__);
00049     }
00050 
00051     DefectList& defects=result->getDefects();
00052 
00054     for (unsigned ichip=0; ichip<nChipModule; ++ichip){
00055 
00056         bool stuck[nChannelChip], dead[nChannelChip];
00057 
00058         // loop to find stuck and dead channels and report stuck and dead cells
00059         for (unsigned ichInChip=0; ichInChip<nChannelChip; ++ichInChip){
00060         // initialise
00061         stuck[ichInChip]=false;
00062         dead[ichInChip]=false;
00063 
00064         // find the real channel number
00065         unsigned ichannel=ichip*nChannelChip+ichInChip;
00066 
00067         TH2& hista = rawa->getScanData(ichip/nChipLink);
00068         TH2& histb = rawb->getScanData(ichip/nChipLink);
00069         unsigned nstuckcell=0, ndeadcell=0;
00070 
00071         unsigned nPipeline=hista.GetNbinsY();
00072         
00073         // find number of stuck and dead cells for this channel
00074         for ( unsigned delay=0; delay < nPipeline; ++delay){
00075             double vala = hista.GetBinContent(ichannel%nChannelLink+1, delay+1);
00076             double valb = histb.GetBinContent(ichannel%nChannelLink+1, delay+1);
00077             if(vala<0.5) ++ndeadcell;   // cell is dead val=0
00078             if(valb>0.5) ++nstuckcell;  // cell is stuck val >0
00079         }
00080 
00081         if (nstuckcell==nPipeline){                 // channel stuck
00082             stuck[ichInChip]=true;
00083         } else if (nstuckcell!=0) {                // cell stuck
00084             defects.addDefect(Defect(StandardDefects::STUCK_CELL, ModuleElement::Channel(ichannel)));
00085             pass = false;
00086         }
00087         
00088         if (ndeadcell==nPipeline){                 // channel dead
00089             dead[ichInChip]=true;
00090         } else  if (ndeadcell!=0) {               // cell dead
00091             defects.addDefect(Defect(StandardDefects::DEAD_CELL, ModuleElement::Channel(ichannel)));
00092             pass = false;
00093         }
00094         } // end of first loop over channels in chip
00095 
00096         //loop to report contiguous stuck and dead channels within this chip
00097         int firstDeadChannel =-1, lastDeadChannel=-1;
00098         int firstStuckChannel=-1, lastStuckChannel=-1;      
00099         for (unsigned ichInChip=0; ichInChip<nChipModule; ++ichInChip){
00100         // find the real channel number
00101         unsigned ichannel=ichip*nChannelChip+ichInChip;
00102 
00103         // first dead
00104         if (dead[ichInChip]) {
00105             if (firstDeadChannel==-1) firstDeadChannel=ichannel;
00106             lastDeadChannel=ichannel;
00107         }
00108         if (!dead[ichInChip] || ichInChip==nChannelChip){
00109             if (firstDeadChannel!=-1){
00110             defects.addDefect(Defect(StandardDefects::DEAD, 
00111                       ModuleElement(firstDeadChannel, lastDeadChannel)));
00112             pass = false;
00113             firstDeadChannel=-1;
00114             lastDeadChannel=-1;
00115             }
00116         }
00117 
00118         // Now stuck:
00119         if (stuck[ichInChip]) {
00120             if (firstStuckChannel==-1) firstStuckChannel=ichannel;
00121             lastStuckChannel=ichannel;
00122         }
00123         if (!stuck[ichInChip] || ichInChip==nChannelChip){
00124             if (firstStuckChannel!=-1){
00125             defects.addDefect(Defect(StandardDefects::STUCKON, 
00126                       ModuleElement(firstStuckChannel, lastStuckChannel)));
00127             pass = false;
00128             firstStuckChannel=-1;
00129             lastStuckChannel=-1;
00130             }
00131         }
00132         } // end of second loop over channels in chip
00133     } // end of loop over chips
00134     
00135     result->setPassed(pass);
00136     }
00137 } // end of namespace SctAnalysis

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