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
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
00073
00074 auto_ptr<TH1> occ = opr.getOccupancy("temp", ModuleElement::Chip(ichip)) ;
00075 float peak=0;
00076 float peakbin=0;
00077 float peakerr=0;
00078 float av=0;
00079 float peakratio=0;
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;
00090
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
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 }