DoubleTriggerNoiseAlgorithm.cpp

00001 #include "DoubleTriggerNoiseAlgorithm.h"
00002 #include "AnalysisAlgorithmMap.h"
00003 #include "AnalysisService.h"
00004 #include "SctData/DoubleTriggerNoiseTestResult.h"
00005 #include "SctData/StandardDefects.h"
00006 #include "SctData/RawScanResult.h"
00007 #include "SctData/ConfigurationVariable.h"
00008 #include "Sct/UnsupportedOperationError.h"
00009 #include "SctData/OccupancyProjector.h"
00010 #include <Sct/AbcdScans.h>
00011 #include <TH1.h>
00012 #include <TH2.h>
00013 
00014 using namespace std;
00015 using namespace boost;
00016 using namespace SctData;
00017 using namespace Sct;
00018 
00019 namespace SctAnalysis {
00020     
00021     DoubleTriggerNoiseAlgorithm::~DoubleTriggerNoiseAlgorithm() throw() {}
00022 
00023      shared_ptr<AnalysisAlgorithm> DoubleTriggerNoiseAlgorithm::clone(shared_ptr<const TestData> testData, const string& moduleName) const throw() {
00024     return shared_ptr<AnalysisAlgorithm>(new DoubleTriggerNoiseAlgorithm(testData, moduleName, *this));
00025     }
00026 
00027     bool DoubleTriggerNoiseAlgorithm::inMap = AnalysisAlgorithmMap::instance().setAlgorithm("DoubleTriggerNoiseTest", auto_ptr<AnalysisAlgorithm>(new DoubleTriggerNoiseAlgorithm()));
00028 
00029     //----------------------------------------------------------------------
00030     
00031     void DoubleTriggerNoiseAlgorithm::loadData() {
00032     loadAllRaws();
00033     }
00034     
00035     bool DoubleTriggerNoiseAlgorithm::canAnalyze() const {
00036     return hasAllRaws();
00037     }
00038     
00039     shared_ptr<SctData::TestResult> DoubleTriggerNoiseAlgorithm::createTestResult() const {
00040     return shared_ptr<TestResult>(new DoubleTriggerNoiseTestResult());
00041     }
00042 
00043     void DoubleTriggerNoiseAlgorithm::analyze() {
00044     shared_ptr<DoubleTriggerNoiseTestResult> result = dynamic_pointer_cast<DoubleTriggerNoiseTestResult>(getTestResult());
00045     const SctData::ConfigurationVariable& scanVariable = getRaw(0)->getHeader().getVariable();
00046     result->setScanVariable(scanVariable);
00047     const ModuleConfiguration config=getRaw(0)->getConfiguration();
00048     
00049     m_scanVariable = SctData::ConfigurationVariableIOHelper::getTypeRep(scanVariable);
00050     
00051     result->setPassed(true);
00052 
00053     for (unsigned ilink=0; ilink<nLinkModule; ++ilink){
00054       if (getRaw(0)->getScanData(ilink).GetMaximum()<1.) result->setProblem(true);
00055       std::ostringstream comment;
00056       comment << "Problem: no data in link " << ilink << std::endl;
00057       result->addComment(comment.str());
00058     }
00059 
00060 
00061     OccupancyProjector opr(*getRaw(0) );
00062     for (unsigned int ichip=0; ichip<nChipModule; ++ichip) {
00063       //const ChipConfiguration& chipconfig=config.getChipConfiguration(ichip);
00064       //DefectList& defects = result->getDefects();
00065       auto_ptr<TH1> occ = opr.getOccupancy("temp", ModuleElement::Chip(ichip)) ;
00066       float peak=0; // maximum occupancy over time bins
00067       float peakbin=0; // bin where the maximum occupancy occurs
00068       float peakerr=0; // the errorbar on the peak. 
00069       float av=0;   // average occupancy over time bins
00070       float peakratio=0; // ratio of peak to pedestal
00071       for (unsigned ibin=1; ibin<=occ->GetNbinsX(); ++ibin){
00072         const float value = occ->GetBinContent(ibin);
00073         if (value>peak) {
00074           peak = value;
00075           peakerr = occ->GetBinError(ibin);
00076           peakbin = occ->GetBinCenter(ibin);
00077         }
00078         av+=value;
00079       }
00080       av -= peak; //subtract the peak out of the sum of all
00081       // Find the average: using N-1, since one bin, namely the peak isn't part of the sum
00082       if (occ->GetNbinsX()>0) av/=((static_cast<float>(occ->GetNbinsX()))-1); 
00083       result->setPeakOccupancy(ichip, peak);
00084       result->setPeakOccupancyBin(ichip, peakbin);
00085       result->setPedestalOccupancy(ichip, av);
00086       if (av>0) {
00087         peakratio = peak/av;
00088       } else {
00089         peakratio = 0;
00090       }
00091       result->setPeakRatio(ichip, peakratio);
00092       // Set passed false if the peak is 5 sigma away from the average
00093       if (peak > 5E-4 || peak > (av+peakerr*5.)){
00094         result->setPassed(false);
00095         result->getDefects().addDefect(Defect(StandardDefects::DOUBTR_HI, ModuleElement::Chip(ichip)));
00096       }
00097     }
00098     }
00099 } // end of namespace SctAnalysis

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