00001 #include "Sct/SctParameters.h"
00002 #include "../ScanResultWriter/dataTypes.h"
00003 #include "OccupancyProjector.h"
00004 #include "DefectList.h"
00005 #include "TH1.h"
00006 #include "TH2.h"
00007
00008 namespace SctData{
00009 using namespace Sct;
00010
00011 OccupancyProjector::OccupancyProjector() throw() : raw(0) {
00012 unsetVetos();
00013 }
00014
00015 OccupancyProjector::OccupancyProjector(const RawScanResult& r) throw() : raw(&r) {
00016 unsetVetos();
00017 }
00018
00019 OccupancyProjector::~OccupancyProjector() throw() {;}
00020
00021 void OccupancyProjector::vetoAllDefects(const DefectList& l) throw(){
00022 defects=&l; m_vetoAllDefects=true;
00023 }
00024 void OccupancyProjector::vetoSeriousDefects(const DefectList& l) throw(){
00025 defects=&l;
00026 }
00027
00028
00029
00030 void OccupancyProjector::vetoMaskedChannels(const ModuleConfiguration& c) throw(){
00031 config=&c;
00032 }
00033 void OccupancyProjector::unsetVetos() throw(){
00034 config=0; defects=0; m_vetoAllDefects = false;
00035 }
00036
00037 auto_ptr<TH1> OccupancyProjector::getOccupancy(const char* name, const ModuleElement& element) const throw (LogicError) {
00038 if (!raw) throw IllegalStateError("OccupancyProjector::getOccupancy no raw result", __FILE__, __LINE__);
00039
00041 if ( raw->getDataType() == SR_DT_RAWHIST) throw IllegalStateError("Occupany project data in SR_DT_RAWHIST format????", __FILE__, __LINE__);
00042
00043 double* bins = raw->getPoints().getEdgesAscending();
00044 auto_ptr<TH1> occ ( new TH1D(name, "Raw data projection", raw->getPoints().getNPoints(), bins) );
00045 delete[] bins;
00046
00047
00048 bool ascending=raw->getPoints().ascending();
00049
00050
00051 for (unsigned int j=0; j<raw->getPoints().getNPoints(); ++j){
00052 unsigned ipt=ascending ? j : raw->getPoints().getNPoints()-1-j;
00053 Stat_t n=raw->getPoints().getNEvents(ipt);
00054 double z=0;
00055 unsigned int nChans = 0;
00056
00057
00058 for (unsigned int i=element.getFirst(); i<=element.getLast(); ++i) {
00059 if (config && config->channelIsMasked(i)) {
00060
00061 continue;
00062 }
00063 if (defects) {
00064 DefectSeverity s = defects->defectSeverityAffectingElement(ModuleElement::Channel(i));
00065 if (m_vetoAllDefects && s != NONE ) continue;
00066 else if (s >= SERIOUS) {
00067
00068
00069 continue;
00070 }
00071 }
00072
00073 z += raw->getScanData(i/nChannelLink).GetBinContent(i%nChannelLink+1, j+1);
00074 nChans++;
00075 }
00076
00077 if (n==0 || nChans==0) {
00078
00079
00080 occ->SetBinContent(j+1, z);
00081 occ->SetBinError(j+1, 0);
00082 continue;
00083 }
00084 n*=nChans;
00085
00086 double err2=(z+1)*(n-z+1)/(n*n*n);
00087 double occupancy=z/n;
00088
00089
00090
00091 occ->SetBinContent(j+1, occupancy);
00092 occ->SetBinError(j+1,sqrt(err2));
00093 }
00094 return occ;
00095 }
00096
00097 }