Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

OccupancyProjector.cpp

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     //void OccupancyProjector::setRawScanResult(const RawScanResult& r) throw(){
00028     //  raw=&r; unsetVetos();
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     // project data in ascending order in scan point.
00048     bool ascending=raw->getPoints().ascending();
00049 
00050     //Explicit binomial errors.
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         //Do projection, taking into account that we might want data on both links
00058         for (unsigned int i=element.getFirst(); i<=element.getLast(); ++i) {
00059         if (config && config->channelIsMasked(i)) {
00060             //cout << "Channel: " << i << " masked, so skipping" << endl;
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             //if (nChans>1 && j==0) 
00068             //cout << "Skipping channel " << i << endl;
00069             continue;
00070             }
00071         }
00072         // Make sure to get correct scan data TH2:
00073         z += raw->getScanData(i/nChannelLink).GetBinContent(i%nChannelLink+1, j+1);
00074         nChans++;
00075         }               
00076         
00077         if (n==0 || nChans==0) {
00078         // no triggers.
00079         //cout << "No triggers?! " << n << " Chans: " << nChans << endl;
00080         occ->SetBinContent(j+1, z);
00081         occ->SetBinError(j+1, 0);
00082         continue;
00083         }
00084         n*=nChans;                         // number of triggers corrected for #channels
00085         
00086         double err2=(z+1)*(n-z+1)/(n*n*n);
00087         double occupancy=z/n;
00088         
00089         //if (nChans>1 && j==0) cout << "Number of channels: " << nChans << " Occ: " << occupancy << " tot: " << z << endl;
00090         
00091         occ->SetBinContent(j+1, occupancy);
00092         occ->SetBinError(j+1,sqrt(err2));
00093     }       
00094     return occ;
00095     }
00096     
00097 }// end of namepace SctData

Generated on Thu Jul 15 09:50:49 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5