/** @file CbmTofPoint.cxx ** @author Volker Friese ** @author Christian Simon ** @since 16.06.2014 ** @date 11.04.2017 **/ #include "CbmTofPoint.h" #include #include #include #include using std::endl; using std::string; using std::stringstream; // ----- Default constructor ------------------------------------------- CbmTofPoint::CbmTofPoint() : FairMCPoint(), fNofCells(0), fGapMask(0) { } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmTofPoint::CbmTofPoint(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss) : FairMCPoint(trackID, detID, pos, mom, tof, length, eLoss), fNofCells(0), fGapMask(0) { } // ------------------------------------------------------------------------- // ----- Copy constructor ---------------------------------------------- CbmTofPoint::CbmTofPoint(const CbmTofPoint& rhs) : FairMCPoint(rhs), fNofCells(rhs.fNofCells), fGapMask(rhs.fGapMask) { // FIXME: It was necessary to implement an explicit copy constructor here // due to a bug in the copy constructor of the ancestor class // 'FairMultiLinkedData_Interface' which - until FairRoot v-17.03 - did not // call the copy constructor of 'TObject' but its default constructor. // This prevents the unique ID that is used in 'CbmMCPointBuffer' for // preserving the 'TClonesArray' index of the MC ToF point from being // copied. SetUniqueID(rhs.GetUniqueID()); } // ------------------------------------------------------------------------- // ----- Copy assignment operator -------------------------------------- CbmTofPoint& CbmTofPoint::operator=(const CbmTofPoint& rhs) { FairMCPoint::operator=(rhs); fNofCells = rhs.fNofCells; fGapMask = rhs.fGapMask; // FIXME: It was necessary to implement an explicit copy assignment operator // here due to a bug in the explicit copy assignment operator of the ancestor // class 'FairMultiLinkedData_Interface' which does not call the copy // assignment operator of 'TObject'. Thus, the values of the member variables // inherited from 'TObject' are not copied. // In particular, this prevents the unique ID that is used in 'CbmMCPointBuffer' // for preserving the 'TClonesArray' index of the MC ToF point from being // copied. // This still needs to be fixed in FairRoot! SetUniqueID(rhs.GetUniqueID()); return *this; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmTofPoint::~CbmTofPoint() { } // ------------------------------------------------------------------------- // ----- Get the number of gaps ---------------------------------------- Int_t CbmTofPoint::GetNGaps() const { Int_t iNGaps(0); for( Int_t iGapBit = 0; iGapBit < std::numeric_limits::digits; iGapBit++ ) { if( fGapMask & ( 0x1 << iGapBit ) ) { iNGaps++; } } return iNGaps; } // ------------------------------------------------------------------------- // ----- Get the index of the first gap -------------------------------- Int_t CbmTofPoint::GetFirstGap() const { for( Int_t iGapBit = 0; iGapBit < std::numeric_limits::digits; iGapBit++ ) { if( fGapMask & ( 0x1 << iGapBit ) ) { return iGapBit; } } return -1; } // ------------------------------------------------------------------------- // ----- Get the index of the last gap --------------------------------- Int_t CbmTofPoint::GetLastGap() const { Int_t iLastGap(-1); for( Int_t iGapBit = 0; iGapBit < std::numeric_limits::digits; iGapBit++ ) { if( fGapMask & ( 0x1 << iGapBit ) ) { iLastGap = iGapBit; } } return iLastGap; } // ------------------------------------------------------------------------- // ----- Add one gap to the gap mask ----------------------------------- void CbmTofPoint::SetGap(Int_t iGap) { assert( 0 <= iGap && std::numeric_limits::digits > iGap ); fGapMask |= 0x1 << iGap; } // ------------------------------------------------------------------------- // ----- String output ------------------------------------------------- string CbmTofPoint::ToString() const { stringstream ss; ss << "STofPoint: track ID " << fTrackID << ", detector ID " << fDetectorID << "\n"; ss << " Position (" << fX << ", " << fY << ", " << fZ << ") cm \n"; ss << " Momentum (" << fPx << ", " << fPy << ", " << fPz << ") GeV \n"; ss << " Time " << fTime << " ns, Length " << fLength << " cm, Energy loss " << fELoss*1.0e06 << " keV \n"; ss << " Number of cells " << fNofCells << ", gap mask " << std::bitset::digits>(fGapMask) << endl; return ss.str(); } // ------------------------------------------------------------------------- // ----- Compare two CbmTofPoint objects w.r.t. FairMCPoint::fTime ----- Int_t CbmTofPoint::Compare(const TObject *obj) const { const CbmTofPoint* tReferencePoint = dynamic_cast(obj); assert(tReferencePoint); if(fTime < tReferencePoint->GetTime()) { return -1; } else if(fTime > tReferencePoint->GetTime()) { return 1; } else { return 0; } } // ------------------------------------------------------------------------- ClassImp(CbmTofPoint)