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 
00028     void OccupancyProjector::vetoMaskedChannels(const ModuleConfiguration& c) throw(){
00029     config=&c;
00030     }
00031     void OccupancyProjector::unsetVetos() throw(){
00032     config=0; defects=0; m_vetoAllDefects = false;
00033     }
00034 
00035     auto_ptr<TH1> OccupancyProjector::getOccupancy(const char* name, const ModuleElement& element) const throw (LogicError) {
00036     if (!raw) throw IllegalStateError("OccupancyProjector::getOccupancy no raw result", __FILE__, __LINE__);
00037 
00039     if ( raw->getDataType() == SR_DT_RAWHIST) throw IllegalStateError("Occupany project data in SR_DT_RAWHIST format????", __FILE__, __LINE__);
00040 
00041     double* bins = raw->getPoints().getEdgesAscending();
00042     auto_ptr<TH1> occ ( new TH1D(name, "Raw data projection", raw->getPoints().getNPoints(), bins) );
00043     delete[] bins;
00044     
00045     // project data in ascending order in scan point.
00046     bool ascending=raw->getPoints().ascending();
00047 
00048     //Explicit binomial errors.
00049     for (unsigned int j=0; j<raw->getPoints().getNPoints(); ++j){
00050       unsigned ipt=ascending ? j : raw->getPoints().getNPoints()-1-j;
00051       Stat_t n=raw->getPoints().getNEvents(ipt); 
00052       double z=0;
00053       unsigned int nChans = 0;
00054         
00055         //Do projection, taking into account that we might want data on both links
00056         for (unsigned int i=element.getFirst(); i<=element.getLast(); ++i) {
00057         if (config && config->channelIsMasked(i)) {
00058             //cout << "Channel: " << i << " masked, so skipping" << endl;
00059             continue;
00060         }
00061         if (defects) {
00062             DefectSeverity s = defects->defectSeverityAffectingElement(ModuleElement::Channel(i));
00063             if (m_vetoAllDefects && s != NONE ) continue;
00064             else if (s >= SERIOUS) {
00065             //if (nChans>1 && j==0) 
00066             //cout << "Skipping channel " << i << endl;
00067             continue;
00068             }
00069         }
00070         // Make sure to get correct scan data TH2:
00071         z += raw->getScanData(i/nChannelLink).GetBinContent(i%nChannelLink+1, j+1);
00072         nChans++;
00073         }               
00074         
00075         if (n==0 || nChans==0) {
00076         // no triggers.
00077         //cout << "No triggers?! " << n << " Chans: " << nChans << endl;
00078         occ->SetBinContent(j+1, z);
00079         occ->SetBinError(j+1, 0);
00080         continue;
00081         }
00082         n*=nChans;                         // number of triggers corrected for #channels
00083         
00084         double err2=(z+1)*(n-z+1)/(n*n*n);
00085         double occupancy=z/n;
00086         
00087         //if (nChans>1 && j==0) cout << "Number of channels: " << nChans << " Occ: " << occupancy << " tot: " << z << endl;
00088         
00089         occ->SetBinContent(j+1, occupancy);
00090         occ->SetBinError(j+1,sqrt(err2));
00091     }       
00092     return occ;
00093     }
00094     
00095 }// end of namepace SctData

Generated on Sat Jul 31 14:18:10 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5