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

#include "THiRAPixel.h"
#include "THiRA.h"
#include "TTarget.h"

#include <TClonesArray.h>
#include <TTree.h>
#include <TVector3.h>


ClassImp(THiRAPixel);
ClassImp(TTele);

////////////////////////////////////////////////////////////////////////////////
/* BEGIN_HTML
<p> The THiRAPixel class is analogous to a particle track in high-energy physics.  
In the case of HiRA the basic data analysis element we want to deal with is a pixel.  

</p>

<h3><a name="phil">I. Philosophy</a></h3>

<h3><a name="vars">II. Important Data Members</a></h3>

<h3><a name="examples">III. Examples</a></h3>

END_HTML */
////////////////////////////////////////////////////////////////////////////////


//______________________________________________________________________________
THiRAPixel *THiRAPixel::AddHit(TCrange *p,Int_t *materials,TTele *tele,
			       Int_t stripEF,Int_t stripEB,UShort_t segCsI,
			       Int_t hit,UShort_t nCsIHits)
{
  // -- Add a "good" pixel to the TClonesArray.
  //

  Clear();

  TClonesArray &fHits = *tele->parent->fPixel;
  THiRAPixel   *pHit  = new(fHits[hit]) THiRAPixel();

  pHit->Clear();

  TVector3 vtmp(tele->pixelMatrix[stripEB][stripEF]);
  pHit->pixVec.SetXYZ(vtmp.X(),vtmp.Y(),vtmp.Z());

  pHit->fTeleID  = tele->GetTeleID();
  pHit->EFstrip  = (UShort_t)stripEF;
  pHit->EBstrip  = (UShort_t)stripEB;
  pHit->CsISeg   = (UShort_t)segCsI;

  pHit->E_EF  = tele->EF.E[stripEF];
  pHit->E_EB  = tele->EB.E[stripEB];
  pHit->E_CsI = tele->CsI.E[segCsI];

  pHit->ETot = pHit->E_EF+pHit->E_CsI;
  pHit->fCsIHits = nCsIHits;

  //   Double_t tmpEtot;
  //   Double_t CsIEAll = tele->CsI.E[0]+tele->CsI.E[1]+tele->CsI.E[2]+tele->CsI.E[3];
  //   for(Int_t i=0; i<5; i++){
  // //     tmpEtot = p->range(CsIEAll,i,materials[1]);
  // //     tmpEtot = p->renergy(0,tmpEtot+tele->GetCsIMylarThickness(),i,materials[1]);
  // //     tmpEtot = tmpEtot + tele->EF.E[stripEF];
  // //     tmpEtot = p->range(tmpEtot,i,materials[0]);
  // //     tmpEtot = tmpEtot + tele->GetSiThickness("E");
  // //     tmpEtot = p->renergy(0,tmpEtot,i,materials[0]);
  // //     tmpEtot = p->range(tmpEtot,i,materials[2]);
  // //     tmpEtot = tmpEtot + tele->parent->GetTarget()->GetThickness();
  // //     tmpEtot = p->renergy(0,tmpEtot,i,materials[2]);
  //     //tmpEtot = CsIEAll + pHit->E_EF;    
  
  //     if(i==0) pHit->pETot   = tmpEtot;
  //     if(i==1) pHit->dETot   = tmpEtot;
  //     if(i==2) pHit->tETot   = tmpEtot;
  //     if(i==3) pHit->He3ETot = tmpEtot;
  //     if(i==4) pHit->He4ETot = tmpEtot;
  
  //   }

  return pHit;
}


//______________________________________________________________________________
void THiRAPixel::Clear(Option_t *)
{
  // -- Clears all relavent THiRAPixel data members.
  //

  pixVec.SetXYZ(0,0,0);
  pETot   = 0;
  dETot   = 0;
  tETot   = 0;
  He3ETot = 0;
  He4ETot = 0;
  
  fTeleID  = 99;
  DEstrip  = 35;
  EFstrip  = 35;
  EBstrip  = 35;
  CsISeg   = 99;
  fMult    = 0;

  E_DE  = 0;
  E_EF  = 0;
  E_EB  = 0;
  E_CsI = 0;
  T_DE  = 0;
  T_EF  = 0;
  T_EB  = 0;
  T_CsI = 0;
}


//______________________________________________________________________________
void THiRAPixel::Calibrate()
{
  // --
  //


}


//______________________________________________________________________________
void THiRAPixel::Calculate()
{
  // --
  //

}


//______________________________________________________________________________
void THiRAPixel::Fill()
{
  // --
  //

  

}


//______________________________________________________________________________
Int_t THiRAPixel::GetTower(THiRA *hira,Int_t face)
{
  // --
  //
  
  if(face==0 || face==1 || face==2) return kTowerMap[hira->GetTeleIndex(fTeleID)][face];
  return -1;
}


//______________________________________________________________________________
Bool_t THiRAPixel::IsBad(THiRA *hira)
{
  // -- Check if any element defining a pixel OF THE CURRENT ENTRY is marked as bad.
  // This method easily allows the user to exclude pixels that may contain faulty 
  // data.  Bad elements are specified in an input file and loaded with the 
  // THiRA::LoadBadElements() method (see documentation of this method for input 
  // file formating).
  //
  // Not only can this method be used in scripts but it can also be used with the
  // Draw() command.
  //   Ex:  hira->LoadBadElements("HiRABadElements.dat");
  //        tree->Draw("E_EF:E_CsI","!IsBad(ex->hira)","colz");
  //
  // This will draw a 2D histo for all pixels EXCEPT those containing a bad element
  // set in the HiRABadElements.dat file.
  //
  

  if(hira->tele[hira->GetTeleIndex(fTeleID)].DE.IsBad(DEstrip)) return kTRUE;
  if(hira->tele[hira->GetTeleIndex(fTeleID)].EF.IsBad(EFstrip)) return kTRUE;
  if(hira->tele[hira->GetTeleIndex(fTeleID)].EB.IsBad(EBstrip)) return kTRUE;
  if(hira->tele[hira->GetTeleIndex(fTeleID)].CsI.IsBad(CsISeg)) return kTRUE;
  return kFALSE;
}


//______________________________________________________________________________
Bool_t THiRAPixel::IsBad(THiRA *hira, Int_t id, Char_t *face, Int_t element)
{
  // -- Check if a specific element is marked as bad.
  //

  if(strcmp(face,"DE")==0)  return hira->tele[hira->GetTeleIndex(id)].DE.IsBad(element);
  if(strcmp(face,"EF")==0)  return hira->tele[hira->GetTeleIndex(id)].EF.IsBad(element);
  if(strcmp(face,"EB")==0)  return hira->tele[hira->GetTeleIndex(id)].EB.IsBad(element);
  if(strcmp(face,"CsI")==0) return hira->tele[hira->GetTeleIndex(id)].CsI.IsBad(element);
  return kFALSE;
}


//______________________________________________________________________________
void THiRAPixel::InitClass(TString name)
{
  // -- Initialze the defaults for the THiRAPixel class.
  //

  SetName(name);

}

//______________________________________________________________________________
void THiRAPixel::InitTree(TTree *tree)
{
  // -- Initialize the pixel TTree and set the branch addresses.
  //

  fChain   = tree;
  fCurrent = -1;

  b_fTeleID   = fChain->GetBranch(fName+".fTeleID");
  b_DEstrip   = fChain->GetBranch(fName+".DEstrip");
  b_EFstrip   = fChain->GetBranch(fName+".EFstrip");
  b_EBstrip   = fChain->GetBranch(fName+".EBstrip");
  b_CsISeg    = fChain->GetBranch(fName+".CsISeg");
  b_fCsIHits  = fChain->GetBranch(fName+".fCsIHits");
  b_fMult     = fChain->GetBranch(fName+".fMult");

  b_pETot   = fChain->GetBranch(fName+".pETot");
  b_dETot   = fChain->GetBranch(fName+".dETot");
  b_tETot   = fChain->GetBranch(fName+".tETot");
  b_He3ETot = fChain->GetBranch(fName+".He3ETot");
  b_He4ETot = fChain->GetBranch(fName+".He4ETot");
  b_E_DE    = fChain->GetBranch(fName+".E_DE");
  b_E_EF    = fChain->GetBranch(fName+".E_EF");
  b_E_EB    = fChain->GetBranch(fName+".E_EB");
  b_E_CsI   = fChain->GetBranch(fName+".E_CsI");
  b_T_DE    = fChain->GetBranch(fName+".T_DE");
  b_T_EF    = fChain->GetBranch(fName+".T_EF");
  b_T_EB    = fChain->GetBranch(fName+".T_EB");
  b_T_CsI   = fChain->GetBranch(fName+".T_CsI");
}


//______________________________________________________________________________
void THiRAPixel::SetName(const Char_t *name)
{
  // -- Change (i.e. set) the name of the THiRAPixel.
  //

  fName = name;
}


//______________________________________________________________________________
void THiRAPixel::SetNameTitle(const Char_t *name, const Char_t *title)
{
  // -- Change (i.e. set) all the THiRAPixel parameters (name and title).
  //

  fName  = name;
  fTitle = title;
}


//______________________________________________________________________________
void THiRAPixel::SetTitle(const Char_t *title)
{
  // -- Change (i.e. set) the title of the THiRAPixel.
  //

  fTitle = title;
}

Last change: Sun Dec 21 12:38:48 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.