//////////////////////////////////////////////////////////// // $Id: IMultiHit.cxx,v 1.8.22.2 2013/01/11 16:58:09 mcgrew Exp $ // #include #include #include #include #include #include "HEPUnits.hxx" #include "IMultiHit.hxx" #include "IOADatabase.hxx" ClassImp(COMET::IMultiHit); COMET::IMultiHit::IMultiHit() : fInitialized(false), fGeomID(0), fCharge(0), fTime(0), fPosition(0,0,0), fIsXHit(false), fIsYHit(false), fIsZHit(false), fSpread(100*unit::meter,100*unit::meter,100*unit::meter), fUncertainty(100*unit::meter,100*unit::meter,100*unit::meter), fTimeUncertainty(1*unit::ns) { SetBit(kCanDelete,false); } COMET::IMultiHit::IMultiHit(const COMET::IMultiHit& h) : COMET::IHit(h), fHits(h.fHits), fInitialized(false), fGeomID(h.fGeomID), fCharge(h.fCharge), fTime(h.fTime), fPosition(h.fPosition), fIsXHit(h.fIsXHit), fIsYHit(h.fIsYHit), fIsZHit(h.fIsZHit), fSpread(h.fSpread), fUncertainty(h.fUncertainty), fTimeUncertainty(h.fTimeUncertainty) { SetBit(kCanDelete,false); } COMET::IMultiHit::IMultiHit(iterator f, iterator l) : fInitialized(false), fGeomID(0), fCharge(0), fTime(0), fPosition(0,0,0), fIsXHit(false), fIsYHit(false), fIsZHit(false), fSpread(100*unit::meter,100*unit::meter,100*unit::meter), fUncertainty(100*unit::meter,100*unit::meter,100*unit::meter) { SetBit(kCanDelete,false); fHits.clear(); fHits.insert(fHits.end(),f,l); Initialize(); } COMET::IMultiHit::~IMultiHit() {} ////////////////////////////////////////////////// // Getter methods for COMET::IMultiHit ////////////////////////////////////////////////// COMET::IGeometryId COMET::IMultiHit::GetGeomID(void) const { if (!fInitialized) const_cast(this)->Initialize(); return fGeomID; } const TVector3& COMET::IMultiHit::GetPosition(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->GetPosition(); } double COMET::IMultiHit::GetCharge(void) const { if (!fInitialized) const_cast(this)->Initialize(); return fCharge; } double COMET::IMultiHit::GetTime(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->GetTime(); } const TVector3& COMET::IMultiHit::GetSpread(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->GetSpread(); } const TVector3& COMET::IMultiHit::GetUncertainty(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->GetUncertainty(); } double COMET::IMultiHit::GetTimeUncertainty(void) const { return 1.0*unit::ns; } COMET::IChannelId COMET::IMultiHit::GetChannelID(int i) const { if (!fInitialized) const_cast(this)->Initialize(); if (i<0 || (int) size()<=i) throw COMET::EHitOutOfRange(); return fHits[i]->GetChannelID(); } int COMET::IMultiHit::GetChannelIDCount() const { if (!fInitialized) const_cast(this)->Initialize(); return size(); } bool COMET::IMultiHit::IsXHit(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->IsXHit(); } bool COMET::IMultiHit::IsYHit(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->IsYHit(); } bool COMET::IMultiHit::IsZHit(void) const { if (!fInitialized) const_cast(this)->Initialize(); if (size()<1) throw EMultiHitIllegal(); return fHits.front()->IsZHit(); } COMET::IMultiHit::iterator COMET::IMultiHit::begin() const { return fHits.begin(); } COMET::IMultiHit::iterator COMET::IMultiHit::end() const { return fHits.end(); } const COMET::IHandle& COMET::IMultiHit::operator [](int index) const { return fHits[index]; } unsigned int COMET::IMultiHit::size() const { return fHits.size(); } namespace { bool fHitsCompare(const COMET::IHandle& a, const COMET::IHandle& b) { return (a->GetTime() < b->GetTime()); } } void COMET::IMultiHit::Initialize() { fInitialized = true; if (size()<1) throw EMultiHitIllegal(); std::sort(fHits.begin(),fHits.end(), fHitsCompare); fGeomID = fHits.front()->GetGeomID(); fCharge = 0.0; for (iterator h = begin(); h != end(); ++h) { if (fGeomID != (*h)->GetGeomID()) throw EMultiHitIllegal(); fCharge += (*h)->GetCharge(); } } void COMET::IMultiHit::ls(Option_t *opt) const { COMET::IHit::ls(opt); std::string option(opt); if (option.find("dump") != std::string::npos) { TROOT::IncreaseDirLevel(); for (iterator v = begin(); v != end(); ++v) { (*v)->ls(opt); } TROOT::DecreaseDirLevel(); } }