00001 #include "Sct/SctParameters.h"
00002 #include "Sct/Exception.h"
00003 #include "Sct/MathsError.h"
00004 #include "../ScanResultWriter/dataTypes.h"
00005 #include "OccupancyProjector.h"
00006 #include "ConfigurationVariable.h"
00007 #include "DefectList.h"
00008 #include "TH1.h"
00009 #include "TH2.h"
00010
00011 namespace SctData{
00012 using namespace Sct;
00013
00014 OccupancyProjector::OccupancyProjector() throw() : raw(0) {
00015 unsetVetos();
00016 }
00017
00018 OccupancyProjector::OccupancyProjector(const RawScanResult& r) throw() : raw(&r) {
00019 unsetVetos();
00020 }
00021
00022 OccupancyProjector::~OccupancyProjector() throw() {;}
00023
00024 void OccupancyProjector::vetoAllDefects(const DefectList& l) throw(){
00025 defects=&l; m_vetoAllDefects=true;
00026 }
00027 void OccupancyProjector::vetoSeriousDefects(const DefectList& l) throw(){
00028 defects=&l;
00029 }
00030
00031 void OccupancyProjector::vetoMaskedChannels(const ModuleConfiguration& c) throw(){
00032 config=&c;
00033 }
00034 void OccupancyProjector::unsetVetos() throw(){
00035 config=0; defects=0; m_vetoAllDefects = false;
00036 }
00037
00038 auto_ptr<TH1> OccupancyProjector::getOccupancy(const char* name, const ModuleElement& element) const throw (LogicError) {
00039 if (!raw) throw IllegalStateError("OccupancyProjector::getOccupancy no raw result", __FILE__, __LINE__);
00040
00042 if ( raw->getDataType() == SR_DT_RAWHIST) throw IllegalStateError("Occupany project data in SR_DT_RAWHIST format????", __FILE__, __LINE__);
00043
00044 double* bins = raw->getPoints().getEdgesAscending();
00045 std::ostringstream title;
00046 if (element.isChannel()){
00047 title << "Chan " << element.getFirst();
00048 } else if (element.isChip()){
00049 title << "Chip " << element.getFirst()/nChannelChip;
00050 } else if (element.isModule()){
00051 title << "Whole Module";
00052 } else {
00053 title << "Chan " << element.getFirst() << "->" << element.getLast();
00054 }
00055
00056 auto_ptr<TH1> occ ( new TH1D(name, title.str().c_str(), raw->getPoints().getNPoints(), bins) );
00057 delete[] bins;
00058
00059 occ->SetXTitle(raw->getHeader().getVariable().getVariableName().c_str());
00060 occ->SetYTitle("Occupancy");
00061
00062
00063 bool ascending=raw->getPoints().ascending();
00064
00065
00066 for (unsigned int j=0; j<raw->getPoints().getNPoints(); ++j){
00067 unsigned ipt=ascending ? j : raw->getPoints().getNPoints()-1-j;
00068 Stat_t n=raw->getPoints().getNEvents(ipt);
00069 double z=0;
00070 unsigned int nChans = 0;
00071
00072
00073 for (unsigned int i=element.getFirst(); i<=element.getLast(); ++i) {
00074 if (config && config->channelIsMasked(i)) {
00075
00076 continue;
00077 }
00078 if (defects) {
00079 DefectSeverity s = defects->defectSeverityAffectingElement(ModuleElement::Channel(i));
00080 if (m_vetoAllDefects && s != NONE ) continue;
00081 else if (s >= SERIOUS) {
00082
00083
00084 continue;
00085 }
00086 }
00087
00088 z += raw->getScanData(i/nChannelLink).GetBinContent(i%nChannelLink+1, j+1);
00089 nChans++;
00090 }
00091
00092 if (n==0 || nChans==0) {
00093
00094
00095 occ->SetBinContent(j+1, 0);
00096 occ->SetBinError(j+1, 0);
00097 if (n==0) {
00098 std::ostringstream msg;
00099 msg << "No triggers for scan point " << j << " of " << raw->getPoints().getNPoints()
00100 << " (value=" << raw->getPoints()[j] << ")" << ends;
00101
00102 }
00103 continue;
00104 }
00105 n*=nChans;
00106
00107 double err2=(z+1)*(n-z+1)/(n*n*n);
00108 double occupancy=z/n;
00109
00110
00111
00112 occ->SetBinContent(j+1, occupancy);
00113 occ->SetBinError(j+1,sqrt(err2));
00114 }
00115 return occ;
00116 }
00117
00118 }