Back to index

CMultDetector.C

 
//----------------------------------------------------------------------------- 
//  $Header: /tmp_mnt/asis/offline/ceres/cool/project/RCS/CMultDetector.C,v 2.1 1996/10/04 08:45:58 voigt Exp $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Implementation of class CMultDetector. 
// 
//----------------------------------------------------------------------------- 
#include <iostream.h> 
#include <math.h> 
#include "cool.h"  
#include "CMultDetector.h"  
#include "CLabel.h"  
#include "CEventServer.h"  
 
CMultDetector::CMultDetector() 
{ 
   // 
   //  Read the default pedestals and mips 
   // 
   CString calFile = CString(C_DEFAULT_SETUP_PATH) + CString(C_CALFILE_MD); 
   CString pedFile = CString(C_DEFAULT_SETUP_PATH) + CString(C_PEDFILE_MD); 
   readCalibrationConstantsFromFile(calFile.data(), pedFile.data());    
} 
 
CMultDetector::~CMultDetector() {} 
 
CBoolean CMultDetector::unpack(CEventServer& es)  
{ 
   static int oldRunNumber = 0; 
   int newRunNumber = 0; 
   static CBoolean calibrationRead = False; 
   const double errscal = 0.441;		         // don't ask 
    
   const CLabel *badc = es.getLabel(BADC);      // get pointer to BADC label 
   if ( badc == 0 ) { 
     cerr << "CMultDetector::unpack():\n"; 
     cerr << "\tWARNING\n"; 
     cerr << "\tLabel BADC not found. Aborting unpack.\n"; 
     return False; 
   } 
    
   if (badc->getLength() < SizeOfBADC) { 
      cerr << "CMultDetector::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; 
 
   // 
   // Read ADC data, skipping the 4 status words at the beginning of 
   // each (8 short words long) ADC block. 
   //  
   int ipaddle = 0; 
   for (int k=0; k<MaxPaddles+4; k++) { 
      if (k%9 != 0) 
	 paddles[ipaddle++].amp = data[k]; 
   } 
    
   // 
   //  Calculate <Nch> using the calibration constants 
   //  for each individual paddle; the pedestals as well 
   //  as the calibration values are read from file. 
   // 
   multiplicity.counts = multiplicity.realCounts = 0; 
   multiplicity.xmips  = multiplicity.dxmips     = 0.; 
    
   float dx; 
    
   for (k=0; k<MaxPaddles; k++) { 
      multiplicity.realCounts += paddles[k].amp; 
       
      double amp = paddles[k].amp-paddles[k].ped; 
      if (amp < 0) amp = 0; 
      multiplicity.counts += amp; 
       
      paddles[k].xmip = amp/paddles[k].mip; 
      if (paddles[k].xmip > 0 && paddles[k].xmip < 1) paddles[k].xmip = 1; 
      dx = errscal*sqrt(paddles[k].xmip); 
       
      multiplicity.xmips  += paddles[k].xmip; 
      multiplicity.dxmips += (dx*dx); 
   } 
    
   multiplicity.dxmips = sqrt(multiplicity.dxmips); 
    
   return True; 
} 
 
CBoolean CMultDetector::readCalibrationConstantsFromFile(const char* calfile, const char* pedfile) 
{ 
   // 
   // Open files. 
   // 
   ifstream ifsCal(calfile);    
   if (!ifsCal) { 
      cerr << "CMultDetector::readCalibrationConstantsFromFile():\n"; 
      cerr << "\tERROR\n"; 
      cerr << "\tError opening calibration file '" << calfile << endl; 
      cerr << "\tWill use fallback values.\n"; 
      return False; 
   } 
    
   ifstream ifsPed(pedfile);    
   if (!ifsPed) { 
      cerr << "CMultDetector::readCalibrationConstantsFromFile():\n"; 
      cerr << "\tERROR\n"; 
      cerr << "\tError opening pedestal file '" << pedfile << endl; 
      cerr << "\tWill use fallback values.\n"; 
      return False; 
   } 
    
   // 
   // Fill pedestals and calibration data from files. 
   // 
   int    paddleNumber; 
   double mipFromFile, pedFromFile, sigmaFromFile; 
   for (int i=0; i<MaxPaddles; i++) { 
      ifsCal >> paddleNumber >> mipFromFile; 
      paddles[i].mip = mipFromFile; 
      ifsPed >> pedFromFile >> sigmaFromFile; 
      paddles[i].ped = pedFromFile; 
   } 
 
   ifsCal.close(); 
   ifsPed.close(); 
 
   return True; 
} 
 

Back to index