BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
// 
// 
// 

//____________________________________________________________________
//
// $Id: BrTpcAdcTable.cxx,v 1.2 2001/06/25 14:30:31 cholm Exp $
// $Author: cholm $
// $Date: 2001/06/25 14:30:31 $
// $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov>
//
#ifndef BRAT_BrTpcAdcTable
#include "BrTpcAdcTable.h"
#endif

#ifndef WIN32
#include <iostream>
#else
#include <iostream.h>
#endif

#include <iomanip>

//____________________________________________________________________

ClassImp(BrTpcAdcTable);

//____________________________________________________________________
 BrTpcAdcTable::BrTpcAdcTable()
{
  // Default constructor DO NOT USE
  fAdcs  = 0;
  fIds   = 0;
  fNPads = 0; 
  fNTimeBins = 0;
}

//____________________________________________________________________
 BrTpcAdcTable::BrTpcAdcTable(Int_t npads, Int_t ntimebins)
{
  // Default constructor
  fNPads = npads;
  fNTimeBins = ntimebins;
  fAdcs = new Short_t[fNPads * fNTimeBins];
  fIds  = new Int_t[fNPads * fNTimeBins];
  fMin  = 0;
  fMax  = fNPads * fNTimeBins - 1;
  Clear();
}

//____________________________________________________________________
 BrTpcAdcTable::~BrTpcAdcTable() 
{
  // DTOR
  if (fAdcs)
    delete [] fAdcs;
  if (fIds)
    delete [] fIds;
}

//____________________________________________________________________
 void BrTpcAdcTable::Clear(Option_t* option)
{
  //
  // Values in fAdc table is set to -1 
  // and values in fIds table is set to 0
  for (Int_t i = fMin; i < fMax+1; i++) {
    fAdcs[i] = -1;
    fIds[i] = -1;
  }
  
  // "zero" help variables
  fMax     = 0;
  fMin     = fNPads * fNTimeBins - 1;
  fMinPad  = fNPads;
  fMaxPad  = 0;
  fMinTime = fNTimeBins;
  fMaxTime = 0;

}

//____________________________________________________________________
 Bool_t BrTpcAdcTable::FindMaxPixel(Int_t &maxPad, Int_t &maxTime, 
				   Short_t adcCut)
{
  //
  // Find the max pad and time bin of the unused clusters
  // demanding that the adc value is greater than adcCut
  // Called by FindPeaks
  //
  Short_t max = 0;
  
  for(Int_t pad = fMinPad; pad < fMaxPad + 1; pad++) {
    
    for(Int_t timebin = fMinTime; timebin < fMaxTime + 1; timebin++) {
      
      // Only search the unused clusters (id == 0)
      if(GetId(pad, timebin) == 0) {
	
	if(GetAdc(pad, timebin) > max ) {
	  
	  max  = GetAdc(pad, timebin);
	  maxPad  = pad;
	  maxTime = timebin;
	}
      }
      
    }
  }
  
  // Check that the max is greater than cut
  if(max >= adcCut) 
    return kTRUE;
  
  return kFALSE;
}

//____________________________________________________________________
 Int_t BrTpcAdcTable::FindPeaks(Short_t adcCut)
{
  //
  // This method finds the pixel with the highest adc value then sets
  // the id of that pixel to 1 and continues to locate pixels with
  // less adc values locating "the mountain". It then finds the
  // pixel with the highest adc values among the rest and continues to
  // find mountains until all pixels have been used or the maximum
  // pixel is less than the adcCut
  //
  
  static const Int_t dirpad[4]  = { 1, 0, -1,  0};
  static const Int_t dirtime[4] = { 0, 1,  0, -1};
  Int_t padPeak, timebinPeak;
  const Int_t maxPixels = 
    (fMaxPad-fMinPad + 1) * fNTimeBins;
  // Make a short structure 
  struct pixellist {
    Int_t padno;
    Int_t timebinno;
  } list[maxPixels];

  Int_t nPeaks = 0;
  Int_t nPixels = 0;

  while(FindMaxPixel(padPeak, timebinPeak, adcCut)) {
    
    // increase number of peaks and fill the pixel list with the start
    // point 
    nPeaks++;
    list[nPixels].padno     = padPeak; 
    list[nPixels].timebinno = timebinPeak;
    SetId(padPeak, timebinPeak, nPeaks);
    const Int_t iStart = nPixels;
    nPixels++;
    for(Int_t i = iStart; i < nPixels; i++) {
      
      //      cout << list[i].pad << ", " << list[i].timebin << endl;

      const Short_t adc = GetAdc(list[i].padno, list[i].timebinno);
      
      for(Int_t j = 0; j < 4; j++) {

	const Int_t pad     = list[i].padno + dirpad[j];
	const Int_t timebin = list[i].timebinno + dirtime[j];
	
	//	cout << pad << " , " << timebin << endl;

	// Check that we don't get outside the array
	if(pad < 0 || timebin < 0 || 
	   pad >= fNPads || timebin >= fNTimeBins)
	  continue;
	
	// Check that pixel has not been used before
	if(GetId(pad, timebin) == 0){
	  
	  // If the adc value is less than in the current pixel add to
	  // cluster 
	  if(GetAdc(pad, timebin) <= adc) {
	    
	    list[nPixels].padno     = pad;
	    list[nPixels].timebinno = timebin;
	    SetId(pad, timebin, nPeaks);
	    nPixels++;

	    // Check that we do not exceed maxPixels
	    if(nPixels >= maxPixels) {
	      Warning("FindPeaks", 
		      "Exceeds max pixels (Should not happen)");
	      return nPeaks;
	    }
	  }
	}
      }
    }
  }
  
  return nPeaks;
}

//____________________________________________________________________
 Short_t BrTpcAdcTable::GetAdc(Int_t pad, Int_t timebin) const
{
  // 
  if (pad >= fNPads || timebin >= fNTimeBins ||
      pad < 0 || timebin < 0) {
    Warning("GetAdc", "[%d,%d] out of bounds (max [%d,%d])",
	    pad, timebin, fNPads, fNTimeBins);
    return -100;
  }
  
  return fAdcs[pad * fNTimeBins + timebin];
}

//____________________________________________________________________
 Int_t BrTpcAdcTable::GetId(Int_t pad, Int_t timebin) const
{
  // 
  if (pad >= fNPads || timebin >= fNTimeBins ||
      pad < 0 || timebin < 0) {
    Warning("GetId", "[%d,%d] out of bounds (max [%d,%d])",
	    pad, timebin, fNPads, fNTimeBins);
    return -100;
  }
  
  return fIds[pad * fNTimeBins + timebin];
}

//____________________________________________________________________
 void BrTpcAdcTable::SetAdc(Int_t pad, Int_t timebin, Short_t x)
{
  // If adc < 0 set adc to 0
  if (pad >= fNPads || timebin >= fNTimeBins ||
      pad < 0 || timebin < 0) {
    Warning("SetAdc", "[%d,%d] out of bounds (max [%d,%d])",
	    pad, timebin, fNPads, fNTimeBins);
    return;
  }

  Int_t idx = pad * fNTimeBins + timebin;
  if(x < 0)
    fAdcs[idx] = 0;
  else
    fAdcs[idx] = x;

  if (idx < fMin)
    fMin = idx;
  if (idx > fMax)
    fMax = idx;

  if (pad < fMinPad)
    fMinPad = pad;
  if (pad > fMaxPad)
    fMaxPad = pad;
  if (timebin < fMinTime)
    fMinTime = timebin;
  if (timebin > fMaxTime)
    fMaxTime = timebin;

}
 
//____________________________________________________________________
 void BrTpcAdcTable::SetId(Int_t pad, Int_t timebin, Int_t id)
{
  // 
  if (pad >= fNPads || timebin >= fNTimeBins ||
      pad < 0 || timebin < 0) {
    Warning("SetId", "[%d,%d] out of bounds (max [%d,%d])",
	    pad, timebin, fNPads, fNTimeBins);
    return;
  }
  Int_t idx = pad * fNTimeBins + timebin;
  fIds[idx] = id;
  
  if (idx < fMin)
    fMin = idx;
  if (idx > fMax)
    fMax = idx;

  if (pad < fMinPad)
    fMinPad = pad;
  if (pad > fMaxPad)
    fMaxPad = pad;
  if (timebin < fMinTime)
    fMinTime = timebin;
  if (timebin > fMaxTime)
    fMaxTime = timebin;

}
 
//____________________________________________________________________
 void BrTpcAdcTable::Print(Option_t* option="") const 
{
  // 
  cout << "# Pads: " << fNPads << " # Time bins: " << fNTimeBins << endl;
  for (Int_t i = fMinPad; i < fMaxPad + 1; i++) {

    if(i == fMinPad) {
      
      cout << "Pad\Time : " << flush;
      for (Int_t j = fMinTime; j < fMaxTime + 1; j++) 
	cout << "   " << setw(3) << j << "   " << flush;

    cout << endl;
    }
    
    cout << "   " << setw(3) << i << "    " << flush;
    for (Int_t j = fMinTime; j < fMaxTime + 1; j++) {
      if(fAdcs[i * fNPads + j] != -1) 
	cout << " " << setw(4) << fAdcs[i * fNPads + j] 
	     << "(" << setw(2) << fIds[i * fNPads + j] << ")" << flush;
      else
	cout << "         " << flush;
    }
    
    cout << endl;
  }
}


//____________________________________________________________________
//
// $Log: BrTpcAdcTable.cxx,v $
// Revision 1.2  2001/06/25 14:30:31  cholm
// Made Print conform to TObject
//
// Revision 1.1.1.1  2001/06/21 14:55:03  hagel
// Initial revision of brat2
//
// Revision 1.1  2001/05/29 14:20:11  pchristi
// Initial import of new Tpc classes
//
//

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