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