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

#ifndef __THIRA_H
#define __THIRA_H

#include <iostream>

#include <TROOT.h>
#include <TBranch.h>
#include <TCanvas.h>
#include <TClonesArray.h>
#include <TMath.h>
#include <TObjArray.h>
#include <TPolyMarker3D.h>
#include <TTree.h>
#include <TObject.h>
#include <TFolder.h>

#ifndef  __ROOTDEFINE_H
#include "rootDefine.h"
#define  __ROOTDEFINE_H
#endif
#ifndef  __PACKETID_H
#include "packetID.h"
#define  __PACKETID_H
#endif
#ifndef  __THIRAASIC_H
#include "THiRAAsic.h"
#define  __THIRAASIC_H
#endif
#ifndef  __TTELE_H
#include "TTele.h"
#define  __TTELE_H
#endif
#ifndef  __TCRANGE_H
#include "TCrange.h"
  //#include "REcomplex.hh"
#define  __TCRANGE_H
#endif
#ifndef  __TTARGET_H
#include "TTarget.h"
#define  __TTARGET_H
#endif


class TTarget;
class TTele;


using namespace std;
using namespace TMath;


class THiRA : public TObject{
 protected:
  TString   fName;                                             //! Object identifier
  TString   fTitle;                                            //! Object title
  Int_t     fAnalysisState;                                    //! Current analysis state of fChain.
  
  TTarget   *fTarget;                                          //! Current target.

 private:
  TVector3  fPixVec;
  Int_t     fChipErr[THIRA_NMBS][THIRA_MB_SLOTS*2];                  //! Errors related to chip addressing.
  Int_t     fChanErr[THIRA_NMBS][THIRA_MB_SLOTS][THIRA_SI_CHANNELS]; //! Errors related to channel addressing.

  TCanvas   *fHiRACanvas;                                      //!
  Int_t     fTeleIndexMap[THIRA_NTELES];                       //!

 private:
  Char_t     *chipMapFile;                                     //! ASIC chip mapping filename.
  Char_t     *csiMapFile;                                      //! CsI mapping filename.
  Char_t     *csiMapPath;                                      //! CsI mapping file path.
  Char_t     *fReadoutShiftPath;                               //! Readout shift file path.
  Short_t    adcTeleMap[21][32];                               //! ADC VME slot and channel mapping.
  Short_t    CsIMap[21][32];                                   //! ADC VME slot and channel mapping.

  vector<Short_t> adcList;                                     //!
 public:
  TCrange       *fCRange;                                      //! Range-Energy range calculator.
  TPolyMarker3D *fPixelView;                                   //! Marker graph of loaded pixels. (OpenGL)

 public:
  Bool_t     fAddRndm;                                         //! Add random number to convert from short data types to double.
  Bool_t     fCorrectReadout;                                  //! Apply readout order correction.

  UShort_t   fNwords;                                          //  Number of HiRA words in an event.
  Short_t    fRawMult;                                         //  Total HiRA multiplicity
  Short_t    fHits[THIRA_NMBS];                                //  Number of hits in each tower.

  TClonesArray *fPixel;                                        //  Collection of hit telescope pixels. 
  static TClonesArray *fgPixel;                                //  Collection of hit telescope pixels. 

  Double_t   SiRawThresh;                                      //! Si multiplicity threshold.
  Double_t   CsIRawThresh;                                     //! CsI multiplicity threshold.
  Double_t   fEulerPhi;                                        //! Phi Euler angle.
  Double_t   fEulerTheta;                                      //! Theata Euler angle.
  Double_t   fEulerPsi;                                        //! Psi Euler angle.

  THiRAAsic  asic;                                             //! ASIC class to hold unpacking data.
  TTele      tele[THIRA_NTELES];                               //! A HiRA Telescope array.
  TList      teleTList;                                        //  A HiRA Telescope collection.
  TTele     *fTele[THIRA_NTELES];                              //!

  TBranch    *b_tele[THIRA_NTELES];                            //! Telescope branch.
  TBranch    *b_fPixel;                                        //!
  TBranch    *b_fNwords;                                       //! Words count branch.
  TBranch    *b_fRawMult;                                      //! Raw multiplicity branch.
  TBranch    *b_fHits;                                         //!


  TFolder    *f_HiRA;                                          //! HiRA folder. 
  TFolder    *f_pixelMatrix;                                   //! Pixel position folder.
  TFolder    *f_parameters;                                    //! Parameters folder.
  TFolder    *f_input;                                         //! Input-files folder.

  TTree      *fChain;                  //! pointer to the analyzed TTree or TChain
  TTree      *fClone;                  //! pointer to a cloned TTree or TChain
  Int_t      fCurrent;                 //! current Tree number in a TChain

 public:
  THiRA(): fName(), fTitle() {}
  ~THiRA() {}
  THiRA(const THiRA &);                // The copy constructor.



  const Char_t  *GetName() const { return fName; }
  const Char_t  *GetTitle() const { return fTitle; }
  void           SetName(const Char_t *name);
  void           SetNameTitle(const Char_t *name, const Char_t *title);
  void           SetTitle(const Char_t *title=""); 

  void           Clear(Option_t *option="");                    // Clear and reset all class members to defaults.
  void           ClearErr();                                    // Clear error counters.
  void           Copy(TObject &hira) const;                     // The copy method.

  virtual void     Draw(Option_t* option="") { Draw(option,"","","all");}
  virtual Long64_t Draw(const Char_t* varexp,                
			const Char_t* selection,               // Draw varexp for all telescopes.
			Option_t* option="",
			Option_t* drawType="all");

  const Char_t *GetChipMapFile() const {return chipMapFile;}   //
  const Char_t *GetCsIMapFile() const {return csiMapFile;}     //
  const Char_t *GetCsIMapPath() const {return csiMapPath;}     //
  const Char_t *GetReadoutFile() const {return fReadoutShiftPath;} //
  Int_t         GetCsIQuadIndex(Int_t xStrip, Int_t yStrip);   // Get the index of the CsI located behind a pixel.      
  Int_t         GetPadIndex(Int_t index);                      // Get pad index for formated drawing.
  TTarget      *GetTarget(){return fTarget;}                   //
  Int_t         GetTeleIndex(Int_t id);                        // Get the array index of a telescope.
  TVector3      GetPixVec(THiRA *hira);

  Bool_t        InitClass();                                   // Initialize any default properties of the class.
  void          InitTree(TTree *tree);                         // Initialize the tree.
  void          InitBranch(TTree *tree,Option_t *stage);       // Initialize the branch structure of the tree.
  void          ResetCalibBranches();
  void          SetAddRndm(Bool_t *AddRndm){fAddRndm=AddRndm;} //
  Bool_t        SetChipMapFile(Char_t *filePath);              // Location of the ASIC chip to telescope mapping file.
  Bool_t        SetCsIMapFile(Char_t *filePath);               // Location of the ADC CsI mapping file.
  Bool_t        SetReadoutShiftPath(Char_t *filePath);         // Location of the readout shift file.

  void          SetEuler(Double_t phi,Double_t theta, Double_t psi){fEulerPhi  =phi*DegToRad(); 
                                                                    fEulerTheta=theta*DegToRad(); 
                                                                    fEulerPsi  =psi*DegToRad();}
  void          SetTarget(TTarget *target){fTarget = target;}  // Set the current target.


  Int_t         Calibrate(Option_t *prefix="",Option_t *path="",
			  Option_t *treeName="",
			  Option_t *option="RECREATE");        // Calibrate detector array.
  void          Calculate();                                   // Calculate detector array data.
  void          CreateFolders();                               // Create default HiRA folders.
  Bool_t        Fill(Short_t energy, Short_t time,
		     Short_t teleNum, Short_t faceNum,         // Fill branches with data.
		     Short_t stripNum,Short_t cbSeq,
		     Short_t chSeq, UInt_t hitSeq);                           
  Bool_t        FillCsI(Short_t energy, Short_t teleNum, 
			Short_t csiNum);                       // Fill CsI branches.
  Int_t         GenPrime(Option_t *prefix="",Option_t *path="",
			 Option_t *treeName="",
			 Option_t *option="RECREATE");             // Generate Primay data.
  Bool_t        LoadAdcMap();                                      // Load ADC mapping.
  Bool_t        LoadBadElements(Char_t *filePath);                 // Load bad elements file.
  Bool_t        LoadCsICalibration(Char_t *filePath,Int_t nCal=0); // Load CsI calibration file.
  Bool_t        LoadCsIVCalibration(Char_t *filePath);             // Load CsI Volatge calibration file.
  Bool_t        LoadCsISegVec(Char_t *filePath);                   // Load CsI crystal segment position vectors.
  Bool_t        LoadPixelMatrix(Char_t *filePath);                 // Load the DESIGN pixel matrix.
  Bool_t        LoadReadoutShifts(Char_t *filePath);               // Load the readout shifts.
  Bool_t        LoadSiCalibration(Char_t *filePath);               // Load Si calibration file.

  void          PrintBad(Option_t*);                               // Print bad elements.
 
  virtual Bool_t  Unpack(UShort_t *p);                         // Unpack an Event.
  Bool_t          UnpackCsI(UShort_t *p);                      // Unpack CsI data.
  UShort_t*       UnpackCsIEnergy(UShort_t *p);                // Unpack CsI energy data.

  ClassDef(THiRA,15)     // The High Resolution Array (HiRA).
  
};

#endif

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