// Author: Andrew M. Rogers, NSCL 07/01/2006
//* Copyright (C) 2006-2008 Andrew M. Rogers

#include <math.h>

#include <TTree.h>

#include "THiRASiDet.h"


ClassImp(THiRASiDet);

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// THiRASiDet                                                           //
//                                                                      //
// A THiRASiDet class derives from TObject.  This Class provides the    //
// structure for the Ef Si detectors in the HiRA device.  Raw event     //
// data is filled as branches on the tree.                              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////



//______________________________________________________________________________
THiRASiDet::THiRASiDet(const THiRASiDet &det) : TObject(det)
{
  // -- Copy constructor.

  ((THiRASiDet&)det).Copy(*this);
}


//______________________________________________________________________________
void THiRASiDet::Copy(TObject &det) const
{
  // -- Copy this method.
  
  TObject::Copy((TObject&)det);
  ((THiRASiDet&)det).fName    = fName;
  ((THiRASiDet&)det).fTitle   = fTitle ;
  ((THiRASiDet&)det).fAddRndm = fAddRndm;
  ((THiRASiDet&)det).fMb      = fMb;
  ((THiRASiDet&)det).fSlot    = fSlot;

  ((THiRASiDet&)det).Clear();
}


//______________________________________________________________________________
void THiRASiDet::Calculate()
{
  // -- General calculations.
  //

}


//______________________________________________________________________________
void THiRASiDet::Calibrate()
{
  // -- General calibrations.

}


//______________________________________________________________________________
void THiRASiDet::Clear(Option_t *)
{
  // -- Clear all event data members.
  //

  fCbSequence  = 0;
  fChSequence  = 0;
  fHitSequence = 0;

  memset(ERaw,'\0',sizeof(ERaw));
  memset(TRaw,'\0',sizeof(TRaw));
  memset(E,'\0',sizeof(E));
  memset(T,'\0',sizeof(T));

  Emax    = 0;
  Emaxch  = 99;
  rawMult = 0;
}


//______________________________________________________________________________
Int_t THiRASiDet::GetEntry(Long64_t entry,Int_t getall)
{ 
  // -- Read all branches in this class of entry and return total number of bytes read.
  //
  //     getall = 0 : get only active branches
  //     getall = 1 : get all branches
  //

  Int_t getBytes=0;
  
  getBytes += b_ERaw->GetEntry(entry,getall);
  getBytes += b_TRaw->GetEntry(entry,getall);
  getBytes += b_E->GetEntry(entry,getall);
  getBytes += b_T->GetEntry(entry,getall);
  getBytes += b_Emax->GetEntry(entry,getall);
  getBytes += b_Emaxch->GetEntry(entry,getall);
  getBytes += b_rawMult->GetEntry(entry,getall);

  return getBytes;
}


//______________________________________________________________________________
Short_t THiRASiDet::GetChReadOrder(Int_t strip)
{
  // -- Get the readout order for a hit strip on a MB.
  // The order returned is an ordianl notation, i.e. 1st, 2nd, 3rd, etc..
  // This method returns 0 if the strip was not readout.
  //

  Short_t value = GetHitReadOrder(strip);
  if(strip<0 || strip>31){ 
    return -1;
  }else if(value!=0) {
    value += fChSequence;
    return value;
  }else{
    return 0;
  }
}


//______________________________________________________________________________
Short_t THiRASiDet::GetHitReadOrder(Int_t strip)
{
  // -- Get the readout order for a hit strip on a CB.
  // The order returned is an ordianl notation, i.e. 1st, 2nd, 3rd, etc..
  // This method returns 0 if the strip was not readout.
  // 
  
  printf("FIX ME!!! \n");
  return -1;
  Short_t counter = 1;
  if(strip<0 || strip>31) return -1;
  // If strip was not hit return 0.
  if(((fHitSequence>>(strip))&0x00000001)!=0x00000001) return 0;
  // Loop over chip 0.
  for(Int_t i=0; i<strip; i=i+2) if(((fHitSequence>>(i))&0x00000001)==0x00000001) counter++;
  // Loop over chip 1 if needed.
  if((strip%2)==1){
    for(Int_t j=1; j<strip; j=j+2) if(((fHitSequence>>(j))&0x00000001)==0x00000001) counter++;
  }
  return counter;
}


//______________________________________________________________________________
void THiRASiDet::InitClass(TString name)
{
  // -- Initialize class members.
  //

  SetName(name);
  fAddRndm = kFALSE;
  Clear();
}


//______________________________________________________________________________
void THiRASiDet::InitTree(TTree *tree)
{
  // -- Set the class to use the given TTree as well as setting the class branch addresses.
  //
  
  fChain   = tree;
  fCurrent = -1;
  #ifdef TESTING
  fChain->SetMakeClass(1);
  #endif

  b_fCbSequence  = fChain->GetBranch(fName + ".fCbSequence");
  b_fChSequence  = fChain->GetBranch(fName + ".fChSequence");
  b_fHitSequence = fChain->GetBranch(fName + ".fHitSequence");

  b_ERaw = fChain->GetBranch(fName + ".ERaw[32]");
  b_TRaw = fChain->GetBranch(fName + ".TRaw[32]");
  b_E    = fChain->GetBranch(fName + ".E[32]");
  b_T    = fChain->GetBranch(fName + ".T[32]");

  b_Emax    = fChain->GetBranch(fName + ".Emax");
  b_Emaxch  = fChain->GetBranch(fName + ".Emaxch");
  b_rawMult = fChain->GetBranch(fName + ".rawMult");

//   fChain->SetBranchAddress(fName + ".fCbSequence",&fCbSequence,&b_fCbSequence);
//   fChain->SetBranchAddress(fName + ".fChSequence",&fChSequence,&b_fChSequence);
//   fChain->SetBranchAddress(fName + ".fHitSequence",&fHitSequence,&b_fHitSequence);

//   fChain->SetBranchAddress(fName + ".ERaw[32]",&ERaw,&b_ERaw);
//   fChain->SetBranchAddress(fName + ".TRaw[32]",&TRaw,&b_TRaw);
//   fChain->SetBranchAddress(fName + ".E[32]",&E,&b_E);
//   fChain->SetBranchAddress(fName + ".T[32]",&T,&b_T);

//   fChain->SetBranchAddress(fName + ".Emax",&Emax,&b_Emax);
//   fChain->SetBranchAddress(fName + ".Emaxch",&Emaxch,&b_Emaxch);
//   fChain->SetBranchAddress(fName + ".rawMult",&rawMult,&b_rawMult);
}


//______________________________________________________________________________
Bool_t THiRASiDet::IsBad(Int_t strip)
{
  // -- Check if the strip is marked as "bad".
  //

  if(fBadStrips[strip]==1) return kTRUE;
  return kFALSE;
}


//______________________________________________________________________________
void THiRASiDet::SetBad(Int_t strip, Int_t bitValue)
{
  // --
  //
  
  if((bitValue==0 || bitValue==1) && (strip>=0 && strip<THIRA_SI_CHANNELS)) fBadStrips.set(strip,bitValue);
  else if(strip==99) ; // Do nothing
  else if(strip<0 || strip>=THIRA_SI_CHANNELS) printf("* ERROR:  Invalid strip!!!\n");
  else printf("* ERROR:  Invalid bitValue!!!\n");
}


//______________________________________________________________________________
void THiRASiDet::SetName(const Char_t *name)
{
  // -- Change (i.e. set) the name of the THiRASiDet.
  fName = name;
}


//______________________________________________________________________________
void THiRASiDet::SetNameTitle(const Char_t *name, const Char_t *title)
{
  // -- Change (i.e. set) all the THiRASiDet parameters (name and title).
  fName  = name;
  fTitle = title;
}


//______________________________________________________________________________
void THiRASiDet::SetTitle(const Char_t *title)
{
  // -- Change (i.e. set) the title of the THiRASiDet.
  fTitle = title;
}

Last change: Sun Dec 21 12:38:49 2008
Last generated: 2008-12-21 12:38

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.