// ESAF : Euso Simulation and Analysis Framework
// $Id: EDetector.cc,v 1.10 2005/03/21 17:13:45 thea Exp $
// M. Pallavicini created Mar, 13 2002
#include "EDetector.hh"
#include "Etypes.hh"
#include "EDetPhoton.hh"
#include "EMacroCellHit.hh"
#include "EMacroCell.hh"
#include "EFee.hh"
#include "EAFee.hh"
ClassImp(EDetector)
TClonesArray* EDetector::fgPhotons = NULL;
TClonesArray* EDetector::fgMacroCellHits = NULL;
TClonesArray* EDetector::fgFee = NULL;
TClonesArray* EDetector::fgAFee = NULL;
TClonesArray* EDetector::fgMacroCell = NULL;
EDetector* EDetector::fgCurrent = NULL;
// class EDetector
//______________________________________________________________________________
EDetector::EDetector() : TObject() {
// ctor
if ( fgPhotons == NULL )
fgPhotons = new TClonesArray("EDetPhoton",20000);
if ( fgMacroCellHits == NULL )
fgMacroCellHits = new TClonesArray("EMacroCellHit",20000);
if ( fgFee == NULL )
fgFee = new TClonesArray("EFee",20000);
if ( fgAFee == NULL )
fgAFee = new TClonesArray("EAFee",20000);
if ( fgMacroCell == NULL )
fgMacroCell = new TClonesArray("EMacroCell",20000);
fMacroCellHits = fgMacroCellHits;
fFee = fgFee;
fAFee = fgAFee;
fPhotons = fgPhotons;
fMacroCell = fgMacroCell;
fPhotonFillable = kTRUE;
fCopy = kFALSE;
fNumPhotons = 0;
fNumFee = 0;
fNumAFee = 0;
fNumCells = 0;
fNumCellHits = 0;
fFirstTime = kHuge;
fLastTime = -kHuge;
}
//______________________________________________________________________________
EDetector::EDetector(const EDetector& other) : TObject() {
// copy ctor
other.Copy ( *this );
}
//______________________________________________________________________________
EDetector::~EDetector() {
// destructor
Clear();
// copied events have different TClonesArray and need additional cleaning
if ( IsCopy() )
ClearCopy();
if ( GetCurrent() == this ) SetCurrent( 0 );
}
//______________________________________________________________________________
void EDetector::Copy( TObject& other) const {
// copy
TObject::Copy(other);
EDetector& det = (EDetector&)other;
// copy det variables
det.fNumPhotons = fNumPhotons;
det.fNumFee = fNumFee;
det.fNumAFee = fNumAFee;
det.fNumCells = fNumCells;
det.fNumCellHits = fNumCellHits;
det.fFirstTime = fFirstTime;
det.fLastTime = fLastTime;
// clear tclonesarrays
if ( det.IsCopy() ) {
SafeDelete(det.fMacroCellHits);
SafeDelete(det.fPhotons);
SafeDelete(det.fFee);
SafeDelete(det.fAFee);
SafeDelete(det.fMacroCell);
}
// create TClonesArray; for copied objects, the static buffer is not used
det.fMacroCellHits = (TClonesArray*)fMacroCellHits->Clone();
det.fPhotons = (TClonesArray*)fPhotons->Clone();
det.fFee = (TClonesArray*)fFee->Clone();
det.fAFee = (TClonesArray*)fAFee->Clone();
det.fMacroCell = (TClonesArray*)fMacroCell->Clone();
// copy objects
fElectronics.Copy( det.fElectronics );
det.fRunPars = fRunPars;
det.SetCopy();
}
//______________________________________________________________________________
void EDetector::Clear( Option_t* ) {
// build header
if ( fMacroCellHits )
fMacroCellHits->Delete();
if ( fPhotons )
fPhotons->Delete();
if ( fFee )
fFee->Delete();
if ( fAFee )
fAFee->Delete();
if ( fMacroCell )
fMacroCell->Delete();
fNumPhotons = 0;
fNumFee = 0;
fNumAFee = 0;
fNumCells = 0;
fFirstTime = kHuge;
fLastTime = -kHuge;
fElectronics.Clear();
TRef dummy;
fRunPars = dummy;
}
//______________________________________________________________________________
void EDetector::ClearCopy() {
// delete TClonesArray in case of copied events
SafeDelete(fMacroCellHits);
SafeDelete(fFee);
SafeDelete(fPhotons);
SafeDelete(fAFee);
SafeDelete(fMacroCell);
}