PreTriggerNoiseAlgorithm.cpp

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

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