BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
//
// Calbration data object for scintilator sis in the multiplicity
// array 
//

//____________________________________________________________________
//
// $Id: BrSiCalibration.cxx,v 1.22 2002/04/23 15:32:25 videbaek Exp $
// $Author: videbaek $
// $Date: 2002/04/23 15:32:25 $
// $Copyright: 2001 BRAHMS Collaboration 
#ifndef WIN32
#include <iostream>
#include <iomanip>
#include <cfloat>
#include <fstream>
#else
#include <iostream.h>
#include <iomanip.h>
#include <float.h>
#include <fstream>
#endif 
#include <TString.h>
#include <TSystem.h>
#ifndef BRAT_BrDataObject
#include "BrDataObject.h"
#endif
#ifndef BRAT_BrSiCalibration
#include "BrSiCalibration.h"
#endif
#ifndef BRAT_BrPathManager
#include "BrPathManager.h"
#endif

//____________________________________________________________________
ClassImp(BrSiCalibration);
 
//____________________________________________________________________
BrSiCalibration::BrSiCalibration() 
{
  // Default CTOR
}

//____________________________________________________________________
BrSiCalibration::BrSiCalibration(const Char_t* name, 
				 const Char_t* title) 
  : BrMultCalibration(name, title) 
{
  // Standard CTOR 
  // The name hould be that of the associated detector e.g. "Si" 
  AddParameterData("pulser",           &fPulserFunc);
  //fRingRadius         =  5.31;
}

//====================================================================
//
// Pulser calibrations
//
//____________________________________________________________________
Int_t BrSiCalibration::GetPulserFuncOrder() const 
{
  // return the order of the pulser calibrations 
  if (!fPulserFunc.fAccessMode || !fPulserFunc.fRevision) 
    return -1;

  Float_t* array = (Float_t*)fPulserFunc.fRevision->GetArray();
  if (!array) 
    return -1;

  return Int_t(array[0]);

}

//____________________________________________________________________
Float_t BrSiCalibration::GetPulserFuncPar(Int_t siNo, Int_t parNo) const
{
  // return the parNo'th parameter of the pulser calibration for strip
  // number siNo
  // Return FLT_MAX in case of errors 
  if (!fPulserFunc.fAccessMode || !fPulserFunc.fRevision)
    return FLT_MAX;
  
  Float_t* array = (Float_t*)fPulserFunc.fRevision->GetArray();
  if (!array)
    return FLT_MAX;
  
  Int_t norder = Int_t(array[0]);
  
  // Offset of function in array:
  //   i * (number of parameters) + 1 reserved places
  Int_t offset = 1 + siNo * (norder + 1); 
  if (offset + parNo > fPulserFunc.fRevision->GetEntries())
    return FLT_MAX;
  return array[offset + parNo];
}


//____________________________________________________________________
Float_t BrSiCalibration::GetConversionFuncPar(Int_t ringno, Int_t i) const 
{
  // Returns the ith parameter of the energy to multiplicity
  // conversion function. Note that the ring argument isn't used in
  // the SMA code. 
  return BrMultCalibration::GetConversionFuncPar(0, i);
}


//====================================================================
//
// Pulser calibrations
//
//____________________________________________________________________
void BrSiCalibration::SetPulserFuncOrder(Int_t order)
{
  // Set the order of the pulser correction 
  if (!fPulserFunc.fAccessMode || !fPulserFunc.fRevision) 
    return;
  Float_t* array = (Float_t*)fPulserFunc.fRevision->GetArray();
  if (!array) 
    return;
  array[0] = order;
}

//____________________________________________________________________
void BrSiCalibration::SetPulserFunc(Int_t stripNo, Float_t* func)
{
  // Sets the pulser calibration for strip number stripNo, to the
  // array in the second argument. That array MUST be the order
  // (SetPulserFuncOrder) + 1 long, or, you'll get a SIGSEGV!
  if (!fPulserFunc.fAccessMode || !fPulserFunc.fRevision) 
    return;
  Float_t* array = (Float_t*)fPulserFunc.fRevision->GetArray();
  if (!array) 
    return;  

  Int_t norder = Int_t(array[0]);

  // one reserved + i * (# parameters)
  // Where (# parameters) = order + 1 constant
  Int_t offset = 1 + stripNo * (norder + 1); 

  if (fPulserFunc.fRevision->GetEntries() < offset + norder)
    return;

  for (Int_t i = 0; i < norder + 1; i++)
    array[offset + i] = func[i];
}


//====================================================================
//
// Eta dependent conversion from E to M 
//

//____________________________________________________________________
void BrSiCalibration::SetConversionFunc(Int_t ringno, Float_t* func) 
{
  // Set the number of functions to store in calibration
  BrMultCalibration::SetConversionFunc(0, func);
}

  
#ifdef BR_MULT_CAL_TMP

//____________________________________________________________________
ClassImp(BrSiTmpCalibration);

//____________________________________________________________________
BrSiTmpCalibration* BrSiTmpCalibration::fgInstance = 0;

//____________________________________________________________________
 BrSiTmpCalibration::BrSiTmpCalibration()
{
  Defaults();
}

//____________________________________________________________________
 BrSiTmpCalibration::BrSiTmpCalibration(const Char_t* name, 
				       const Char_t* title) 
  : BrMultTmpCalibration(name, title)
{
  Defaults();
}
    
//____________________________________________________________________
 BrSiTmpCalibration::~BrSiTmpCalibration()
{}
    
//____________________________________________________________________
 BrSiTmpCalibration* BrSiTmpCalibration::Instance() 
{
  // 
  if (!fgInstance) 
    fgInstance = new BrSiTmpCalibration("MultSi", 
					"Temporary si calib");
  
  return fgInstance;
}


//____________________________________________________________________
 void  BrSiTmpCalibration::Defaults() 
{
  fPulserOrder     = 3;

  //Function parameters for converting energy to segment multiplicity
  //for Si elements
  fConversionOrder = 8;
  fConversionFunc[0]  =5112.23;
  fConversionFunc[1]  =-55.3237;
  fConversionFunc[2]  =-1433.13;
  fConversionFunc[3]  =24.1965;
  fConversionFunc[4]  =201.839;
  fConversionFunc[5]  =-3.25217;
  fConversionFunc[6]  =-14.3608;
  fConversionFunc[7]  =0.139099;
  fConversionFunc[8]  =0.404336;

  //Function parameters for correcting sum multiplicity for the vertex
  //location.
  fCorrectionOrder = 9;
  fCorrectionCut   = 45;
  fCorrectionFunc[0]  = 9.96850e-01;
  fCorrectionFunc[1]  = -3.66567e-03;
  fCorrectionFunc[2]  = -1.09277e-04;
  fCorrectionFunc[3]  = -2.41127e-07;
  fCorrectionFunc[4]  = -9.35841e-07;
  fCorrectionFunc[5]  = -6.23173e-04;
  fCorrectionFunc[6]  = -1.52285e-05;
  fCorrectionFunc[7]  = -9.99293e-03;
  fCorrectionFunc[8]  =  2.26745e-04;
  fCorrectionFunc[9]  = -1.73901e-06;

  // Centrality functions; 
  fCentralityOrder = 4;
  fCentralityN     = 14;
  for (Int_t i = 0; i < 84; i++) 
    fCentralityFunc[i]  = 0;
  Int_t i;
  Int_t j;

  // Maps 
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    fPedestal[i]      = 0;
    fPedestalWidth[i] = 0;
    fAdcGain[i]       = .0117; // 0.097 / ;
    for (j = 0; j < fPulserOrder  + 1; j++)
      fPulserFunc[i * (fPulserOrder + 1) + j] = 0.;

    fRingMap[i]       = -1;
    fRowMap[i]        = -1;
    fTilt[i]          = 0;  
  }
  
  // Geometry
  fRingPosition[3]    = -19.10;
  fRingPosition[10]    = -11.46;
  fRingPosition[17]   =  -3.82;
  fRingPosition[24]   =   3.82;
  fRingPosition[31]   =  11.46;
  fRingPosition[38]   =  19.10;
  for (i = 0; i < 6; i++) {
    fRingPosition[(i * 7 + 3) - 3] = fRingPosition[(i * 7 + 3)] - 2.58;
    fRingPosition[(i * 7 + 3) - 2] = fRingPosition[(i * 7 + 3)] - 1.72;
    fRingPosition[(i * 7 + 3) - 1] = fRingPosition[(i * 7 + 3)] -  .86;
    fRingPosition[(i * 7 + 3) + 1] = fRingPosition[(i * 7 + 3)] +  .86;
    fRingPosition[(i * 7 + 3) + 2] = fRingPosition[(i * 7 + 3)] + 1.72;
    fRingPosition[(i * 7 + 3) + 3] = fRingPosition[(i * 7 + 3)] + 2.58;
  }
  
  fRingRadius         =  5.31;
  fRingDetectorFront = 5.3;
  fRingDetectorDepth = 0.03;
  fRingDetectorWidth = 0.86;
  fRingDetectorHeight = 4.0;

}

//____________________________________________________________________
 void BrSiTmpCalibration::Clear() 
{
}

//____________________________________________________________________
 void BrSiTmpCalibration::ReadASCIIFile(Int_t runNo) 
{
  const Int_t lineSize = 256;
  char line[lineSize];

  BrPathManager* pathMan = BrPathManager::Instance();
  //
  // Set run specific calibration parameters
  SetRunNo(runNo);
  for(Int_t i = 0; i< BR_SI_RING_MAX; i++) fRingCnt[i]=0;

  if (DebugLevel() > 5) 
    cout << ClassName() << "::ReadASCIIFile: for runNo: " << runNo 
	 << endl; 
  if (runNo < 1761) {
    //
    // calibrations for early runs. Only a ADC to row, ring map is
    // avaliable. For everything else, use the default parameters. 
    // 
    TString fileName("ActiveMultDet");

    // Append to file name 
    if (runNo < 0) 
      fileName += ".dat";
    else 
      fileName += "_0.dat";

    // Try to open in current directory 
    ifstream file(fileName.Data());
    if (file.fail()) {
      file.close();
      file.clear();
      // If that fails try in BRATSYS/params
      fileName.Prepend(Form("%s/params/",
			    pathMan->GetDataDir()));
      file.open(fileName.Data());

      if (!file) {
	// If that also fails, give up
	Fatal("ReadASCIIFile", "couldn't find file");
	return;
      }
    }
    // Read the file 
    while (kTRUE) {
      // Peek to see what comes next 
      char c = file.peek();
      // if line starts with a 's', we've got a si line 
      if (c == 's') {
	// Some variables we need 
	char si[3];
	char underscore[2];
	int ring, row, ch;
	
	// First read the si name 
	file.get(si,3); 
	// Then the row number
	file >> row;
	// and then the underscore in the name
	file.get(underscore,2);
	// then the ring number 
	file >> ring;
	// and finally the ADC channel 
	file >> ch;

	// Set the ring and row maps 
	fRingMap[ch] = ring - 1;
	++fRingCnt[ring - 1];

	fRowMap[ch]  = row;
	if (DebugLevel() > 10)
	  cout << setw(3) << ch << " " << row << " " << ring << endl;
      }
      // Read the reminder of the line 
      file.getline(line, lineSize);

      // If we met EOF, break the loop 
      if (file.eof()) 
	break;

      // If some read fialed, stop the whole thing
      if (file.fail()) {
	Fatal("ReadASCIIFile", "failure while reading file");
	return;
      }
      
    } // while(kTRUE)
    file.close();
    return;
  }
  else {
    Char_t fname[120];
    // Later runs, for which we got full calibrations. 
    
    sprintf(fname, Form("%s/params/mult/BrCalibrMult_%d.dat", 
			  pathMan->GetDataDir(), runNo));
    ifstream file(fname);
    if (file.fail()) {
      file.close();
      file.clear();
      // If we couldn't open a specific file for the requested run,
      // fall back to runNo = 0 if Yr 1 run, runNo = 1 if Yr 2 run 
      if (runNo >= 5702) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5702.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 5685) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5685.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 5684) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5684.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 5682) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5682.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 5681) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5681.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 5680) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5680.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 5677) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_5677.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 4713) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_4713.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 4640) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_4640.dat", 
		      pathMan->GetDataDir());
      else if (runNo >= 3700) 
	sprintf(fname,"%s/params/mult/BrCalibrMult_1.dat", 
		      pathMan->GetDataDir());
      else
	sprintf(fname,"%s/params/mult/BrCalibrMult_0.dat", 
		      pathMan->GetDataDir());

      file.open(fname);
      
      if (!file) {
	// If that also fails, give up
	Fatal("ReadASCIIFile", "couldn't find file %s", fname);
	return;
      }

    }
    if (DebugLevel() > 5) 
      cout << ClassName() 
	   << "::ReadASCIIFile: Reading Si Calibrations from file " 
	   << fname << endl;
    
    
    // First thing in the file is a number
    Int_t lineno=0;
    Int_t fileRunNo = 0;
    file >> fileRunNo;
    file.getline(line, lineSize);
    lineno++;
    if (fileRunNo != runNo)
      Warning("ReadASCIIFile", 
	      "you requsted run %d, but file %s is for %d", 
	       runNo, fname, fileRunNo);
      
    // Second thing is just a comment line, telling us what the
    // entries are. 
    file.getline(line, lineSize);
    lineno++;
    if (file.fail()) {
      Fatal("ReadASCIIFile", "Failure while scanning file %s", 
	    fname);
      return;
    }
            
    Int_t adcChannel     = -1;
    Int_t row            = -1;
    Int_t ring           = -1;
    Int_t status         = 0;
    float pedestal       = 0;
    float pedestalWidth  = 0;
    float param0         = 0;
    float param1         = 0;
    float param2         = 0;
    float param3         = 0;
    float tilt           = 0;
    float gain           = 0;
    if (DebugLevel() > 10)
      cout << "Ch:  " 
	   << "Row " 
	   << "Ring "
	   << "Pedestal "
	   << "PedWidth "
	   << "Param0    "
	   << "Param1    "
	   << "Param2    "
	   << "Param3    "
	   << "Tilt      "
	   << "Gain      " << endl;
    // Start reading the entries 


    while(kTRUE) {
      Char_t c = file.peek();
      if (c != 'A') {
	// Read reminder of the line 
	file.getline(line, lineSize);
	lineno++;
      } 
      else {
	file.getline(line, lineSize);
	lineno++;
	//Beginning of Si section
	break;
      }
    }

    // if(DebugLevel() > 5) 
    //   cout<< "Starting Si parameter scan..." << endl;
    while(kTRUE) {
      Char_t c = file.peek();
      // Break on EOF
      if (file.eof()) {
	if (DebugLevel() > 5)
	  cout << "Found EOF" << endl;
	break;
      }
      if(c=='#') { //we have a comment line
	file.getline(line, lineSize);
	lineno++;
	// if (DebugLevel() > 10) 
	//   cout << "Comment line: " << line << endl;
	continue;
      }
      // Read the ADC channel number. 
      file >> adcChannel;

      // Read the name 
      Int_t n = 0;
      while (n < 2) {
	file.get(c); 
	if      (n == 0 && c == 's') n++;
	else if (n == 1 && c == 'i') n++;
	else if (c == 't' || c == ' ') 
	  // ignore white space 
	  ;
	else {
	  Error("ReadASCIIFile", 
		"Ill formed strip line %d in file %s (c = '%c')", 
		lineno, fname, c);
	  return;
	}
      }

      // read the row number
      file >> row;
	
      // read seperating underscore 
      file.get(c);
      if (c != '_') {
	Error("ReadASCIIFile", 
	      "Ill formed strip line in file %si ('%c' != '_')", 
	      fname, c);
	return;
      }
	
      // read the ring 
      file >> ring;

      // read the segment
      file.get(c);
      switch(c) {
      case 'a':
      case 'b':
      case 'c':
      case 'd':
      case 'e':
      case 'f':
      case 'g':
      case 't':
	break;
      default:
	Error("ReadASCIIFile", "bad segment letter %c", c);
	return;
      }
      
      // read the status 
      file >> status;

      // read the pedestal and pedestal width 
      file >> pedestal;
      file >> pedestalWidth;
	
      // read the pulser calibration
      file >> param0;
      file >> param1;
      file >> param2;
      file >> param3;

      // read the tilt of the detector 
      file >> tilt;

      // read the gain 
      file >> gain;

      // Break on EOF
      if (file.eof()) {
	if (DebugLevel() > 5) 
	  cout << ClassName() << "::ReadASCIIFile: Found EOF" << endl;
	break;
      }
      
      // Return on failure 
      if (file.fail()) {
	Fatal("ReadASCIIFile", "Failure while reading file %s", 
	      fname);
	return;
      }
	  
      // Read reminder of the line 
      file.getline(line, lineSize);
      lineno++;
      --ring;
      if(c != 't') 
	// The paranthesis maps (a, b, c, d, e, f, g) into 
	// (0, 1, 2, 3, 4, 5) so we get a proper number 
	ring =  7 * ring  + (c - 'a');
      // If si is not flaged as good or if temp, add 100 to ring as flag
      if (status < 1&& c!= 't') ring+=100;
      if (c=='t') ring+=200;


      fPedestal[adcChannel]                            = pedestal;
      fPedestalWidth[adcChannel]                       = pedestalWidth;
      fPulserFunc[adcChannel * (fPulserOrder + 1)]     = param0;
      fPulserFunc[adcChannel * (fPulserOrder + 1) + 1] = param1;
      fPulserFunc[adcChannel * (fPulserOrder + 1) + 2] = param2;
      fPulserFunc[adcChannel * (fPulserOrder + 1) + 3] = param3;
      fTilt[adcChannel]                                = tilt;
      fAdcGain[adcChannel]                             = gain;
      fRowMap[adcChannel]                              = row;
      fRingMap[adcChannel]                             = ring;

      if(ring < BR_SI_RING_MAX) ++fRingCnt[ring];

      if (DebugLevel() > 10)
	cout << setw(3) << adcChannel << ": " 
	     << setw(3) << fRowMap[adcChannel] << " " 
	     << setw(3) << fRingMap[adcChannel] << " "
	     << setw(8) << fPedestal[adcChannel] << " "
	     << setw(8) << fPedestalWidth[adcChannel] << " " 
	     << setw(8) << fPulserFunc[adcChannel * (fPulserOrder+1)] 
	     << " " 
	     << setw(8) << fPulserFunc[adcChannel * 
				      (fPulserOrder + 1) + 1] << " " 
	     << setw(8) << fPulserFunc[adcChannel * 
				      (fPulserOrder + 1) + 2] << " " 
	     << setw(8) << fPulserFunc[adcChannel * 
				      (fPulserOrder + 1) + 3] << " " 
	     << setw(8) << fTilt[adcChannel] << " "
	     << setw(8) << fAdcGain[adcChannel] << endl; 
      

    } // while (kTRUE)
  
    file.close();
  } // if (runNo < 1761) ... else


  TString name;
  if (runNo < 3700) 
    name = Form("%s/params/mult/smacent.dat", 
		pathMan->GetDataDir());
  else if (runNo < 5677)
    name = Form("%s/params/mult/smacent004640.dat", 
		pathMan->GetDataDir());
  else 
    name = Form("%s/params/mult/smacent005677.dat", 
		pathMan->GetDataDir());
  if (DebugLevel() > 5) 
    cout << ClassName() 
	 << ": Reading Si Centrality Calibrations from file "
	 << name << endl;

  ifstream file(name.Data());
  
  if (file.fail()) {
    // If that also fails, give up
    Fatal("ReadASCIIFile", "couldn't find file '%s'", name.Data());
    return;
  }

  fCentralityN = 0;
  fCentralityOrder = 0;
  // Read the file 
  while (kTRUE) {
    // Peek to see what comes next 
    char c = file.peek();
    // if line starts with a '#', we've got a comment line  
    if (c == '#') {
      file.getline(line, lineSize);
      continue;
    }

    // Read the first word on the line
    TString token;
    file >> token;
    token.ToLower();

    // If the first word is "order", then we read that
    if (!token.CompareTo("order")) {
      file >> token;
      if (!token.CompareTo("="))
	file >> fCentralityOrder;
    } 
    // If the first word is "ncuts", then we read that
    else if (!token.CompareTo("ncuts")) {
      file >> token;
      if (!token.CompareTo("="))
	file >> fCentralityN;
    }
    // Read the rest of the line 
    file.getline(line, lineSize);

    // Break out of this state if we got all we need for  now. 
    if (fCentralityOrder > 0 && fCentralityN > 0) 
      break;

    // Return if we got some error. 
    if (file.eof() || file.fail()) {
      Error("ReadASCIIFile", 
	    "Incomplete read of centrality parameters"); 
      file.close();
      fCentralityN = 0;
      fCentralityOrder = 0;
      return;
    }
  }
  
  if (fCentralityN * (fCentralityOrder+2) > lineSize) {
    Warning("ReadASCIIFile", 
	    "Insufficient memory to store cuts");
    return;
  }
    

  Int_t cut = 0;
  while(true) {
    // Peek to see what comes next 
    char c = file.peek();
    // if line starts with a '#', we've got a comment line 
    if (c == '#') {
      file.getline(line, lineSize);
      continue;
    }
    
    // Read the cut value;
    file >> fCentralityFunc[cut * (fCentralityOrder + 2)];
    if (DebugLevel() > 10)
      cout << " Cut: " 
	   << fCentralityFunc[cut * (fCentralityOrder + 2)] 
	   << flush;

    // Read the parameters 
    for (Int_t i = 0; i < fCentralityOrder + 1; i++) {
      file >> fCentralityFunc[cut * (fCentralityOrder + 2) + i + 1];
      if (DebugLevel() > 10)
	cout << " + " 
	     << fCentralityFunc[cut * (fCentralityOrder + 2) + i + 1] 
	     << "x^" << i << flush;
    }
    if (DebugLevel() > 10)
      cout << endl;

    // Increment the cut counter, and see if we are at the last one. 
    if (++cut >= fCentralityN) {
      file.close();
      break;
    }
    
    // Return if we got some error. 
    if (file.eof() || file.fail()) {
      Error("ReadASCIIFile", 
	    "Incomplete read of centrality parameters"); 
      fCentralityN = cut;
      file.close();
      return;
    }
  }
}

// ADC calibration 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetPedestal(Int_t siNo) const
{ 
  // Returnt the ADC pedestal 
  if (siNo >= BR_SI_CHAN_MAX || !fPedestal)
    return 0;
  return fPedestal[siNo];
}
 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetPedestalWidth(Int_t siNo) const
{ 
  // Returnt the ADC pedestal Widht
  if (siNo >= BR_SI_CHAN_MAX || !fPedestalWidth)
    return 0;
  return fPedestalWidth[siNo];
}
 
 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetAdcGain(Int_t siNo) const
{ 
  // Returnt the ADC gain
  if (siNo >= BR_SI_CHAN_MAX || !fAdcGain)
    return 0;
  return fAdcGain[siNo];
}
 
// For the pulser calibrations 
//____________________________________________________________________
 Int_t BrSiTmpCalibration::GetPulserFuncOrder() const
{ 
  // Return the order of the centrlity functions.
  if (!fPulserFunc)
    return 0;
  return fPulserOrder;
}

//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetPulserFuncPar(Int_t stripNo, 
					     Int_t parno) const
{ 
  // return the parno parameter of the funcno centrality function
  if (!fPulserFunc || 
      parno > fPulserOrder || 
      stripNo > BR_SI_CHAN_MAX) 
    return 0;
  return fPulserFunc[stripNo * (fPulserOrder + 1) + parno];
}

//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetConversionFuncPar(Int_t i, Int_t parno) const
{ 
  // return the parNo conversion parameter
  if (!fConversionFunc || parno > fConversionOrder) 
    return 0;
  return fConversionFunc[parno];
}

// For the correction function 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetCorrectionFuncPar(Int_t parno) const 
{ 
  // Return the max vertex Z for whichthe correction function is
  // valid. 
  if (!fCorrectionFunc || parno > fCorrectionOrder)
    return 0;
  return fCorrectionFunc[parno];
}

// For the centrality cuts 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetCentralityFuncCut(Int_t funcno) const
{ 
  // return the centrality cut of the funcno centrality function
  if (!fCentralityFunc || 
      funcno > fCentralityN) 
    return 0;
  return fCentralityFunc[funcno * (fCentralityOrder + 2)];
}

//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetCentralityFuncPar(Int_t funcno, 
                                                 Int_t parno) const
{ 
  // return the parno parameter of the funcno centrality function
  if (!fCentralityFunc || 
      parno > fCentralityOrder || 
      funcno > fCentralityN) 
    return 0;
  return fCentralityFunc[funcno * (fCentralityOrder + 2) + parno + 1];
}


// Geometry - shoud be in geometry database
//____________________________________________________________________
 Short_t BrSiTmpCalibration::GetRingMap(Int_t siNo) const
{ 
  // Return the ring # corresponding til ADC channel # sino
  if (!fRingMap || siNo >= BR_SI_CHAN_MAX){
    Warning("GetRingMap", "either no ringmap, or %d >= %d", 
	    siNo, BR_SI_CHAN_MAX);
    return 0;
  }
  
  return fRingMap[siNo];
}
 
//____________________________________________________________________
 Short_t BrSiTmpCalibration::GetRowMap(Int_t siNo) const
{ 
  // Return the row # corresponding til ADC channel # sino
  if (!fRowMap || siNo >= BR_SI_CHAN_MAX) {
    Warning("GetRowMap", "either no rowmap, or %d >= %d", 
	    siNo, BR_SI_CHAN_MAX);
    return 0;
  }
  
  return fRowMap[siNo];
}
 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetRingPosition(Int_t ringNo) const
{ 
  // 
  if (ringNo >= BR_SI_RING_MAX || !fRingPosition)
    return 0;
  return fRingPosition[ringNo];
}
 
//____________________________________________________________________
 Float_t BrSiTmpCalibration::GetTilt(Int_t siNo) const
{ 
  // 
  if (!fTilt || siNo >= BR_SI_CHAN_MAX)
    return 0;
  return fTilt[siNo];
}

//____________________________________________________________________
 void BrSiTmpCalibration::SetRunNo(const Int_t runno)
{
  fRunNo = runno;
  //Function parameters for correcting sum multiplicity for the vertex
  //location.
  fCorrectionOrder = 9;
  fCorrectionCut   = 45;
  if(runno < 3700)
    {
      fCorrectionFunc[0]  = 9.96850e-01;
      fCorrectionFunc[1]  = -3.66567e-03;
      fCorrectionFunc[2]  = -1.09277e-04;
      fCorrectionFunc[3]  = -2.41127e-07;
      fCorrectionFunc[4]  = -9.35841e-07;
      fCorrectionFunc[5]  = -6.23173e-04;
      fCorrectionFunc[6]  = -1.52285e-05;
      fCorrectionFunc[7]  = -9.99293e-03;
      fCorrectionFunc[8]  =  2.26745e-04;
      fCorrectionFunc[9]  = -1.73901e-06;
    }
  else
    {
      fCorrectionFunc[0]  =  9.95032e-01;
      fCorrectionFunc[1]  =  1.25181e-03;
      fCorrectionFunc[2]  = -4.26750e-04;
      fCorrectionFunc[3]  = -2.09483e-05;
      fCorrectionFunc[4]  = -1.02240e-06;
      fCorrectionFunc[5]  = -1.43219e-03;
      fCorrectionFunc[6]  = -2.32207e-05;
      fCorrectionFunc[7]  = -3.15259e-03;
      fCorrectionFunc[8]  =  7.79627e-05;
      fCorrectionFunc[9]  = -6.14410e-07;
    }

}

//____________________________________________________________________
 void BrSiTmpCalibration::Print(Option_t* option) const 
{
  Int_t i = 0;
  cout << "BrSiTmpCalibration: " << endl; 

  // Pedestal of ADCs
  cout << "  Pedesal:" << flush;
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fPedestal[i] << " " << flush;
  }
  cout << endl;

  // Pedestal width of ADCs
  cout << "  Pedestal width: " << flush;
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fPedestalWidth[i] << " " << flush;
  }
  cout << endl;
  
  // Pedestal width of ADCs
  cout << "  Pulser: " << flush;
  for (i = 0; i < 4 * BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fPulserFunc[i] << " " << flush;
  }
  cout << endl;

  // Pedestal width of ADCs
  cout << "  ADC Gain: " << flush;
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fAdcGain[i] << " " << flush;
  }
  cout << endl;

  // Pedestal width of ADCs
  cout << "  Conversion func: " << flush;
  for (i = 0; i < 9; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fConversionFunc[i] << " " << flush;
  }
  cout << endl;

  // Pedestal width of ADCs
  cout << "  Correction func: " << flush;
  for (i = 0; i < 10; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fCorrectionFunc[i] << " " << flush;
  }
  cout << endl;

  // Centrality 
  cout << "  Centrality:  Order=" << fCentralityOrder 
       << " Number=" << fCentralityN << flush;
  for (i = 0; i < 70; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fCentralityFunc[i] << " " << flush;
  }
  cout << endl;

  // Tilt
  cout << "  tilt: " << flush;
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fTilt[i] << " " << flush;
  }
  cout << endl;

  // Ring map
  cout << "  Ring map: " << flush;
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fRingMap[i] << " " << flush;
  }
  cout << endl;

  // Row map
   cout << "  Row map: " << flush;
  for (i = 0; i < BR_SI_CHAN_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fRowMap[i] << " " << flush;
  }
  cout << endl;

  // Row map
  cout << "  Ring position: " << flush;
  for (i = 0; i < BR_SI_RING_MAX; i++) {
    if (i % 8 == 0) cout << endl;
    cout << setw(8) << fRingPosition[i] << " " << flush;
  }
  cout << endl;
}

#endif 



//
// $Log: BrSiCalibration.cxx,v $
// Revision 1.22  2002/04/23 15:32:25  videbaek
// Removed ios::in. Added close + clear in cases where you want to re-open another file
// (The error flags are not cleared on an open in C++ standard, was in gcc 2.91 but not in g++3
// Added lineno counter for error ouput.
//
// Revision 1.21  2002/03/14 10:02:27  cholm
// minor fixes to output
//
// Revision 1.20  2002/03/12 13:50:59  cholm
// Took out a debug print put in previously be myself.
//
// Revision 1.19  2002/03/12 13:30:19  cholm
// Increased size of `line' local variable to 256, since some of the
// calibration files by Steve contains comment lines longer than 128 (the
// old size).
//
// Revision 1.18  2002/03/12 13:25:20  cholm
// Added some more debug stuff
//
// Revision 1.17  2002/03/12 13:03:07  cholm
// Some better debug messages
//
// Revision 1.16  2002/03/02 15:33:23  cholm
// Expanded arrays for more centrality cuts
//
// Revision 1.15  2002/03/02 14:45:44  cholm
// Added more cases for reading calibrations
//
// Revision 1.14  2002/02/19 23:25:48  sanders
// fixed bad initialization of fRingCnt array
//
// Revision 1.13  2002/02/17 18:04:08  sanders
// Added code to allow comments at end of ascii calibration files
//
// Revision 1.12  2002/02/04 23:51:03  sanders
// Add setter for detector gains
//
// Revision 1.11  2002/01/05 08:52:25  sanders
// Changed how detectors with bad status are handled when reading
// ascii file.  Before the status was checked and if found bad the
// detector was skipped.  Now the ring number is incremented by 100
// to flag the status situation.
//
// Revision 1.10  2001/12/06 00:32:53  sanders
// Fixed calibrations to obtain average pseudorapidity and geometric
// scaling factor for si and tile elements.
//
// Revision 1.9  2001/11/24 15:42:56  sanders
// Added si and tile calibrations for:
// 1) converting from detector multiplicities to ring dNdEta values
// 2) finding the HIJING weighted ring eta value for a given vertex position
// Both of these calibrations were found doing 8th order polynomial fits
// to functions obtained by taking HIJING particle distributions starting
// from vertex locations between -46cm and +46 cm, in 2 cm steps, and
// checking if the corresponding particles "hit" any of the si or tile
// detectors in the array.
//
// Revision 1.8  2001/11/21 19:12:08  cholm
// Added code for reading SDE centrality calibrations for run 4640
// (and forward?).  See also http://www4.rhic.bnl.gov/~cholm/mult.html. Took
// out the default numbers since they were invalid and not used.
//
// Revision 1.7  2001/11/19 04:09:36  sanders
// Revised calibration modules for 200 GeV (yr 2001) si/tile calibrations.
//
// Revision 1.6  2001/11/15 00:33:34  sanders
// fix premature submission
//
// Revision 1.5  2001/11/15 00:08:59  sanders
// Print name of ascii calibration file if Verbose() >=3
//
// Revision 1.4  2001/10/27 23:01:39  sanders
// Added code for yr 2 calibration in tmpCalibration.  The yr 2
// default ascii file is BrCalibrMult_1.dat
//
// Revision 1.3  2001/09/20 13:10:58  cholm
// Various fixes
//
// Revision 1.2  2001/09/12 15:05:39  cholm
// Varius fixes that was needed for the thing to work properly.  Mistakes on
// my part.  Stupid ones too.
//
// Revision 1.1.1.1  2001/06/21 14:54:59  hagel
// Initial revision of brat2
//
// Revision 1.12  2001/06/05 18:42:47  cholm
// Removed BrDbInc.h an all references to it
//
// Revision 1.11  2001/06/04 13:37:03  cholm
// Changes to use BrPathManager, BrVersion, and perpare to use BrFileTag.
//
// Revision 1.10  2001/06/02 15:23:53  sanders
// Modified parameters for E-to-N conversions.  Also modified parameters
// for converting the average Si+Tile sum multiplicity to centrality.  The
// new parameters result from an analysis where GEANT simulations are used
// to correct for the excessive number of low multiplicity events arising from
// pedestal tails being counted as particle hits.  Events with tile multiplicities
// between 4 and 200 are compared to the corresponding GBRAHMS (Hijing input)
// simulations to estimate the number of expected events with tile multiplicity
// below 4.
//
// Revision 1.9  2001/06/01 15:49:23  cholm
// Fix of some default values from -1 to zero (gave bad results)
// BrSiCalibration had a bug in returning the correction function.
// Tile|Rdo modules had some minor bugs, and I did some improvments
// Mult Rdo module had some serious bugs, but should be ok now.
// BrMultRdo is fixed a lot too.
//
// Revision 1.8  2001/05/31 01:46:16  cholm
// Second rewamp of this directory.  All RDO modules use the common
// BrMultRdoModule, and they both write BrMultRdo Objects.  Also introduced
// ABC for Br[Tile|Si][Parameters|Calibration] since they have a lot in common,
// and the code can be made more efficient this way.
//
// A possible further thing to do, is to make an ABC for the CentModules, and
// the corresponding calibration modules, since they are very VERY similar.
// However, the current module BrMultCentModule is in the way.  Need to talk
// to Steve about that.
//
// Revision 1.7  2001/05/23 12:27:25  cholm
// Important bug fixes in returning centrality function
//
// Revision 1.6  2001/05/17 11:12:47  cholm
// Added support for reading ASCII calibration files for centrality cuts
// in classes BrTileTmpCalibration and BrSiTmpCalibration.
// Added some preliminary work for using the energy signal rather than the
// multiplicity signal for the centrality determination in classses
// BrTileCentCalModule and BrSiCentCalModule.
//
// Revision 1.5  2001/04/11 14:05:19  cholm
// Fixed a few bugs
//
// Revision 1.4  2001/04/06 19:56:13  cholm
// This class is now done. All data members are there. Maybe some
// minor bug fixes in the future, but hopefully not too many.
//
// Revision 1.3  2001/04/05 03:04:16  sanders
// Restored "brat complience" to Si and Tile Rdo, BrRdoModuleMult still not complient.
//
// Revision 1.2  2001/04/02 01:17:37  sanders
// BrRdoMult and BrRdoModuleMult reinstated.  These files develop the joint
// Si+Tile multiplicity.  BrRdoModuleMult now gets it parameters from the
// BrTileRdoModule and BrSiRdoModule classes and is a friend of these classes.
//
// Revision 1.1  2001/01/29 20:49:30  cholm
// Added a claibration module for silicon pedestals, plus a calibration
// class for use with the calibrations database. Both classes havent been
// tested yet.
//
//

 

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS