OccupancyProjector.cpp

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 using namespace std;
00012 
00013 namespace SctData{
00014     using namespace Sct;
00015 
00016     OccupancyProjector::OccupancyProjector() throw() : raw(0) {
00017     unsetVetos();
00018     }
00019 
00020     OccupancyProjector::OccupancyProjector(const RawScanResult& r) throw() : raw(&r) {
00021     unsetVetos();
00022     }
00023 
00024     OccupancyProjector::~OccupancyProjector() throw() {;}
00025     
00026     void OccupancyProjector::vetoAllDefects(const DefectList& l) throw(){
00027     defects=&l; m_vetoAllDefects=true;
00028     }
00029     void OccupancyProjector::vetoSeriousDefects(const DefectList& l) throw(){
00030     defects=&l;
00031     }
00032 
00033     void OccupancyProjector::vetoMaskedChannels(const ModuleConfiguration& c) throw(){
00034     config=&c;
00035     }
00036     void OccupancyProjector::unsetVetos() throw(){
00037     config=0; defects=0; m_vetoAllDefects = false;
00038     }
00039 
00040     auto_ptr<TH1> OccupancyProjector::getOccupancy(const char* name, const ModuleElement& element) const throw (LogicError) {
00041     if (!raw) throw IllegalStateError("OccupancyProjector::getOccupancy no raw result", __FILE__, __LINE__);
00042 
00044     if ( raw->getDataType() == SR_DT_RAWHIST) throw IllegalStateError("Occupany project data in SR_DT_RAWHIST format????", __FILE__, __LINE__);
00045 
00046     double* bins = raw->getPoints().getEdgesAscending();
00047     std::ostringstream title;
00048     if (element.isChannel()){
00049       title << "Chan " << element.getFirst(); 
00050     } else if (element.isChip()){
00051       title << "Chip " << element.getFirst()/nChannelChip;
00052     } else if (element.isModule()){
00053       title << "Whole Module";
00054     } else {
00055       title << "Chan " << element.getFirst() << "->" << element.getLast();
00056     }
00057 
00058     auto_ptr<TH1> occ ( new TH1D(name, title.str().c_str(), raw->getPoints().getNPoints(), bins) );
00059     delete[] bins;
00060     
00061     occ->SetXTitle(raw->getHeader().getVariable().getVariableName().c_str());
00062     occ->SetYTitle("Occupancy");
00063 
00064     // project data in ascending order in scan point.
00065     bool ascending=raw->getPoints().ascending();
00066 
00067     //Explicit binomial errors.
00068     for (unsigned int j=0; j<raw->getPoints().getNPoints(); ++j){
00069       unsigned ipt=ascending ? j : raw->getPoints().getNPoints()-1-j;
00070       Stat_t n=raw->getPoints().getNEvents(ipt); 
00071       double z=0;
00072       unsigned int nChans = 0;
00073         
00074         //Do projection, taking into account that we might want data on both links
00075         for (unsigned int i=element.getFirst(); i<=element.getLast(); ++i) {
00076         if (config && config->channelIsMasked(i)) {
00077             //cout << "Channel: " << i << " masked, so skipping" << endl;
00078             continue;
00079         }
00080         if (defects) {
00081             DefectSeverity s = defects->defectSeverityAffectingElement(ModuleElement::Channel(i));
00082             if (m_vetoAllDefects && s != NONE ) continue;
00083             else if (s >= SERIOUS) {
00084             //if (nChans>1 && j==0) 
00085             //cout << "Skipping channel " << i << endl;
00086             continue;
00087             }
00088         }
00089         // Make sure to get correct scan data TH2:
00090         z += raw->getScanData(i/nChannelLink).GetBinContent(i%nChannelLink+1, j+1);
00091         nChans++;
00092         }               
00093         
00094         if (n==0 || nChans==0) {
00095         // no triggers.
00096         //cout << "No triggers?! " << n << " Chans: " << nChans << endl;
00097         occ->SetBinContent(j+1, 0);
00098         occ->SetBinError(j+1, 0);
00099                 if (n==0) {
00100             std::ostringstream msg; 
00101             msg << "No triggers for scan point " << j << " of " << raw->getPoints().getNPoints() 
00102             << " (value=" << raw->getPoints()[j] << ")" << ends;
00103 //          Sct::MathsError(msg.str(), __FILE__, __LINE__).sendToMrs();
00104         }
00105         continue;
00106         }
00107         n*=nChans;                         // number of triggers corrected for #channels
00108         
00109         double err2=(z+1)*(n-z+1)/(n*n*n);
00110         double occupancy=z/n;
00111         
00112         //if (nChans>1 && j==0) cout << "Number of channels: " << nChans << " Occ: " << occupancy << " tot: " << z << endl;
00113         
00114         occ->SetBinContent(j+1, occupancy);
00115         occ->SetBinError(j+1,sqrt(err2));
00116     }       
00117     return occ;
00118     }
00119     
00120 }// end of namepace SctData

Generated on Mon Feb 6 14:01:24 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6