00001 #include "Sct/SctParameters.h" 00002 #include "Sct/OutOfRangeError.h" 00003 00004 #include "ScanHeader.h" 00005 #include "RawScanResult.h" 00006 #include "ModuleConfiguration.h" 00007 #include "ModuleDefectList.h" 00008 #include "ModuleDefect.h" 00009 00010 #include <TH1.h> 00011 #include <TH2.h> 00012 #include <TROOT.h> 00013 00014 #include <sstream> 00015 00016 using namespace Sct; 00017 using namespace std; 00018 00019 00020 namespace SctData { 00021 00022 RawScanResult::RawScanResult(const ScanHeader& scan, const ModuleConfiguration& module, 00023 const ScanPoints& points, TH2D& scan_link0, TH2D& scan_link1) throw() : 00024 ScanResult(scan, module, points), scanData_link0(&scan_link0), scanData_link1(&scan_link1) {} 00025 00026 //Only for the builder: 00027 RawScanResult::RawScanResult() throw () { 00028 } 00029 00030 RawScanResult::~RawScanResult() throw() { 00031 } 00032 00033 string RawScanResult::getClassName() const throw() { 00034 return "SctData::RawScanResult"; 00035 } 00036 00037 string RawScanResult::getUniqueID() const throw() { 00038 return getHeader().getUniqueID(); 00039 } 00040 00041 00042 string RawScanResult::getUniqueID(const ScanHeader& header) throw() { 00043 return header.getUniqueID(); 00044 } 00045 00046 TH2D& RawScanResult::getScanData(unsigned ilink) const throw(LogicError) { 00047 TH2D* data=0; 00048 if (ilink == 0) { 00049 data= scanData_link0.get(); 00050 } else if ( ilink==1 ) { 00051 data= scanData_link1.get(); 00052 } else { 00053 throw OutOfRangeError<unsigned>("RawScanResult::getScanData ilink ", __FILE__, __LINE__, ilink,0,1); 00054 } 00055 if (!data) throw InvariantViolatedError("RawScanResult::getScanData no scan data", __FILE__, __LINE__) ; 00056 return *data; 00057 } 00058 00059 00060 /* 00061 TH1* RawScanResult::getLinkOccupancy (const char* name, unsigned ilink, const ModuleDefectList* defects) const throw (LogicError) { 00062 return getProjection(name, ilink, 0, nChannelLink-1, defects); 00063 } 00064 00065 TH1* RawScanResult::getChipOccupancy (const char* name, unsigned ichip, const ModuleDefectList* defects) const throw (LogicError) { 00066 return getChipOccupancy(name, ichip/nChipLink, ichip%nChipLink, defects); 00067 } 00068 00069 TH1* RawScanResult::getChipOccupancy (const char* name, unsigned ilink, unsigned ichip, const ModuleDefectList* defects) const throw (LogicError) { 00070 return getProjection(name, ilink, ichip*nChannelChip, (ichip+1)*nChannelChip-1, defects); 00071 } 00072 00073 TH1* RawScanResult::getChannelOccupancy (const char* name, unsigned istrip, const ModuleDefectList* defects) const throw (LogicError) { 00074 return getChannelOccupancy(name, istrip/nChannelLink, istrip%nChannelLink, defects); 00075 } 00076 00077 TH1* RawScanResult::getChannelOccupancy (const char* name, unsigned ilink, unsigned istrip, const ModuleDefectList* defects) const throw (LogicError) { 00078 return getProjection(name, ilink, istrip, istrip, defects); 00079 } 00080 00081 //Returns a projection from lowChan to highChan. 00082 //Inclusive and channels start from 0. 00084 TH1* RawScanResult::getProjection(const char* name, unsigned ilink, unsigned lowChan, unsigned highChan, const ModuleDefectList* defects) const throw (LogicError) { 00085 00086 if (lowChan>nChannelLink) throw OutOfRange<unsigned>("RawScanResult::getProjection lowChan ",lowChan,0,nChannelLink); 00087 if (highChan>nChannelLink) throw OutOfRange<unsigned>("RawScanResult::getProjection highChan ",highChan,0,nChannelLink); 00088 00089 TH2& data = getScanData(ilink); 00090 double* bins = points.getEdges(); 00091 TH1D* occ = new TH1D(name, "Raw data projection", points.getNPoints(), bins); 00092 delete[] bins; 00093 00094 //Explicit binomial errors. 00095 for (unsigned int j=0; j<points.getNPoints(); ++j){ 00096 Stat_t n=points.getNEvents(j); 00097 double z=0; 00098 unsigned int nChans = 0; 00099 00100 //Do projection 00101 for (unsigned int i=lowChan; i<=highChan; ++i) { 00102 if (defects) { 00103 //Note that actual channel number is i + ilink*nChannelLink! 00104 if (defects->hasSevereDefect(i+ilink*nChannelLink)) continue; 00105 } 00106 z += data.GetBinContent(i+1, j+1); 00107 nChans++; 00108 } 00109 00110 if (n==0 || nChans==0) { 00112 ostringstream text; 00113 text <<"RawScanResult::getProjection No triggers for point "<<j<<endl; 00114 throw InvalidArgument(text.str(), MRS_DIAGNOSTIC); 00115 00116 occ->SetBinContent(j+1, z); 00117 occ->SetBinError(j+1, 0); 00118 continue; 00119 } 00120 n*=nChans; // number of triggers corrected for #channels 00121 00122 double err2=(z+1)*(n-z+1)/(n*n*n); 00123 double occupancy=z/n; 00124 00125 occ->SetBinContent(j+1, occupancy); 00126 occ->SetBinError(j+1,sqrt(err2)); 00127 } 00128 return occ; 00129 } 00130 */ 00131 00132 } 00133 00134