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(shared_ptr<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 stuckcells=0, deadcells=0, cellmask=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.95) deadcells += 1<<delay;   // cell is dead val=0
00078             if(valb>0.05) stuckcells += 1<<delay;  // cell is stuck val >0
00079             cellmask += 1<<delay;
00080         }
00081 
00082         if (stuckcells==cellmask){                 // channel stuck
00083           defects.addDefect(Defect(StandardDefects::STUCKON, 
00084                        ModuleElement::Channel(ichannel)));
00085           
00086         } else if (stuckcells!=0) {                // cell stuck
00087             defects.addDefect(Defect(StandardDefects::STUCK_CELL, 
00088                          ModuleElement::Channel(ichannel),
00089                          boost::optional<double>(stuckcells)));
00090             pass = false;
00091         }
00092         
00093         if (deadcells==cellmask){                 // channel dead
00094           defects.addDefect(Defect(StandardDefects::DEAD,
00095                        ModuleElement::Channel(ichannel)));
00096 
00097             dead[ichInChip]=true;
00098         } else  if (deadcells!=0) {               // cell dead
00099             defects.addDefect(Defect(StandardDefects::DEAD_CELL, 
00100                          ModuleElement::Channel(ichannel),
00101                          boost::optional<double>(deadcells)));
00102             pass = false;
00103         }
00104         } // end of first loop over channels in chip
00105 
00106     } // end of loop over chips
00107     
00108     // Fails if there are any defects...
00109     result->setPassed( defects.defectSeverityAffectingElement(ModuleElement::Module())==NONE );
00110     }
00111 } // end of namespace SctAnalysis

Generated on Mon Feb 6 14:01:24 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6