Back to index

CBeamCounter.C

 
//----------------------------------------------------------------------------- 
//  $Header: /nfs/ceres1/asis/offline/ceres/cool/project/RCS/CBeamCounter.C,v 1.1 1996/12/10 13:33:07 messer Exp $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Implementation of class CBeamCounter. 
// 
//----------------------------------------------------------------------------- 
#include <iostream.h> 
#include <math.h> 
#include "cool.h"  
#include "CEventServer.h"  
#include "CTriggerServer.h"  
#include "CBeamCounter.h"  
#include "CMCGeantTrack.h"  
 
CBeamCounter::CBeamCounter() {} 
 
CBeamCounter::~CBeamCounter() {} 
 
CBoolean CBeamCounter::unpack(CEventServer& es)  
{ 
   static int oldRunNumber = 0; 
   int newRunNumber = 0; 
   static CBoolean calibrationRead = False; 
    
   // 
   //  Get calibration constants. 
   //  Read in at startup or if the run number has changed. 
   // 
   const CRawSoR *sor = es.getSoR(); 
   if ( sor == 0 ) { 
      cerr << "CBeamCounter::unpack():\n"; 
      cerr << "\tWARNING\n"; 
      cerr << "\tLabel SoR not found. Aborting unpack.\n"; 
      return False; 
   }  
    
   if (!calibrationRead || oldRunNumber != sor->getRunNumber()) { 
      const CLabel *cal = es.getLabel(TRPD); 
      if ( cal == 0 ) { 
	 cerr << "CBeamCounter::unpack():\n"; 
	 cerr << "\tWARNING\n"; 
	 cerr << "\tCalibration constants not available. Will use fallback values.\n"; 
      } 
      else  
	 getCalibrationConstants(cal); 
      calibrationRead = True; 
      oldRunNumber = sor->getRunNumber(); 
   } 
    
    
   const CLabel *badc = es.getLabel(BADC);      // get pointer to BADC label 
   if ( badc == 0 ) { 
     cerr << "CBeamCounter::unpack():\n"; 
     cerr << "\tWARNING\n"; 
     cerr << "\tLabel BADC not found. Aborting unpack.\n"; 
     return False; 
   } 
    
   if (badc->getLength() < SizeOfBADC) { 
      cerr << "CBeamCounter::unpack():\n"; 
      cerr << "\tWARNING\n"; 
      cerr << "\tIllegal size of BADC label: " << badc->getLength() << endl; 
      cerr << "\tAborting unpack.\n"; 
      return False; 
   } 
    
   const CWord *ldata = badc->getData(); 
   short *data = (short *) ldata; 
    
   int offset = 29;				// skip 4 status words & MD information 
   for (int k=0; k<MaxCounters; k++)   
      counters[k].rawAmp = data[k+offset]; 
 
   return True; 
} 
 
 
    
void CBeamCounter::getCalibrationConstants(const CLabel *calib) 
{    
   const CWord *ldata = calib->getData(); 
    
   short *data = (short *) ldata; 
 
   int offset =  57;                                    // skip MD mips & pedestals 
   for (int i=0; i<MaxCounters; i++)                    // read pedestals 
      counters[i].ped = double(data[i+offset])/100.;   
} 
 
 
void CBeamCounter::pedestalSubtract() 
{    
 
   for (int i=0; i<MaxCounters; i++)  
      counters[i].amp = counters[i].rawAmp - counters[i].ped;   
} 

Back to index