/* * PndOnlineSTTTriplet.cxx * * Created on: Jan 29, 2013 * Author: mertens */ #include "PndOnlineSttTriplet.h" #include #include #include "TVector3.h" #include "TVector2.h" #include "PndSttHit.h" #include "PndSttTube.h" PndOnlineSttTriplet::PndOnlineSttTriplet() : MCEventTime(0), MCEventEntryNumber(0), fTripletStatus(kUnassigned), fMinHitTime(0), fMaxHitTime(0), fHitTimeSum(0), fOldestStraw(0), fActive(kFALSE) { } PndOnlineSttTriplet::~PndOnlineSttTriplet() { } Double_t PndOnlineSttTriplet::GetMinHitTime() const { return fMinHitTime; } Double_t PndOnlineSttTriplet::GetMaxHitTime() const { return fMaxHitTime; } Double_t PndOnlineSttTriplet::GetMeanHitTime() const { return (fHitTimeSum / GetHitCount()); } Double_t PndOnlineSttTriplet::GetMinAcceptWindow() const { return fMaxHitTime - PndOnlineSTT::DriftTime; } Double_t PndOnlineSttTriplet::GetMaxAcceptWindow() const { return fMinHitTime + PndOnlineSTT::DriftTime; } Double_t PndOnlineSttTriplet::GetMinT0() const { return fMaxHitTime - PndOnlineSTT::DriftTime; } Double_t PndOnlineSttTriplet::GetMaxT0() const { return fMinHitTime; } Double_t PndOnlineSttTriplet::GetMeanT0() const { return ((GetMinT0() + GetMaxT0())/2); } void PndOnlineSttTriplet::SetPivotHit(const PndSttHit* const theHit, const PndSttTube* const theTube) { fMinHitTime = theHit->GetTimeStamp(); fMaxHitTime = theHit->GetTimeStamp(); fHitTimeSum = theHit->GetTimeStamp(); fTubes.clear(); fTubes.push_back(theHit->GetTubeID()); fTimes.push_back(theHit->GetTimeStamp()); fOldestStraw = theHit->GetTubeID(); fActive = kTRUE; fTripletStatus = kUnassigned; fMCIndex.clear(); fTrackIndex.clear(); } TVector3 PndOnlineSttTriplet::GetCMS(const TObjArray* const tubearray) const { TVector3 cmsvector(0, 0, 0); for (Int_t i = 0; i < fTubes.size(); i++) { cmsvector += ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetPosition(); } cmsvector.SetXYZ(cmsvector.x()/fTubes.size(), cmsvector.y()/fTubes.size(), cmsvector.z()/fTubes.size()); return cmsvector; } TVector3 PndOnlineSttTriplet::GetCMS3D(const TObjArray* const tubearray, TVector2* const zminmax) const { TVector3 cmsvector(0, 0, 0); Double_t zmin = 35 - 75; //((PndSttTube*)(tubearray->At(fTubes.at(0))))->GetPosition().Z();; Double_t zmax = 35 + 75; //((PndSttTube*)(tubearray->At(fTubes.at(0))))->GetPosition().Z();; for (Int_t i = 0; i < fTubes.size(); i++) { Double_t tubex = ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetPosition().X(); Double_t tubey = ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetPosition().Y(); Double_t tubez = ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetPosition().Z(); if ((tubez > 36) || (tubez < 34)) { Double_t dz = ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetWireDirection().Z(); Double_t k = (35.0 - tubez)/dz; Double_t halflen = ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetHalfLength(); if (tubez - dz*halflen > zmin) { zmin = tubez - dz*halflen; } if (tubez + dz*halflen < zmax) { zmax = tubez + dz*halflen; } tubex += k*((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetWireDirection().X(); tubey += k*((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetWireDirection().Y(); tubez += k*((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetWireDirection().Z(); } cmsvector += TVector3(tubex, tubey, tubez); //cmsvector += ((PndSttTube*)(tubearray->At(fTubes.at(i))))->GetPosition(); } if (zminmax != 0) { zminmax->Set(zmin, zmax); } cmsvector.SetXYZ(cmsvector.x()/fTubes.size(), cmsvector.y()/fTubes.size(), cmsvector.z()/fTubes.size()); return cmsvector; } Int_t PndOnlineSttTriplet::GetPivotStraw() const { return fTubes.front(); } Int_t PndOnlineSttTriplet::GetOldestStraw() const { return fOldestStraw; } Int_t PndOnlineSttTriplet::GetHitCount() const { return fTubes.size(); } Int_t PndOnlineSttTriplet::GetNeighborCount() const { return fTubes.size() - 1; } Bool_t PndOnlineSttTriplet::AddNeighbor(const PndSttHit* const theHit, const PndSttTube* const theTube, Bool_t override) { if (override == kFALSE && theHit->GetTimeStamp() < GetMinAcceptWindow()) return kFALSE; if (override == kFALSE && theHit->GetTimeStamp() > GetMaxAcceptWindow()) return kFALSE; fHitTimeSum += theHit->GetTimeStamp(); fTubes.push_back(theHit->GetTubeID()); if (theHit->GetTimeStamp() < fMinHitTime) { fMinHitTime = theHit->GetTimeStamp(); fOldestStraw = theHit->GetTubeID(); } if (theHit->GetTimeStamp() > fMaxHitTime) fMaxHitTime = theHit->GetTimeStamp(); return kTRUE; } Bool_t PndOnlineSttTriplet::CheckHit(const PndSttHit* const theHit) const { return (!( (theHit->GetTimeStamp() < GetMinAcceptWindow()) || (theHit->GetTimeStamp() > GetMaxAcceptWindow()) )); } Bool_t PndOnlineSttTriplet::HitTooRecent(const PndSttHit* const theHit) const { return (theHit->GetTimeStamp() > GetMaxAcceptWindow()); } Bool_t PndOnlineSttTriplet::HitTooOld(const PndSttHit* const theHit) const { return (theHit->GetTimeStamp() < GetMinAcceptWindow()); } Bool_t PndOnlineSttTriplet::IsActive() const { return fActive; } void PndOnlineSttTriplet::SetActive(Bool_t isActive) { fActive = isActive; } void PndOnlineSttTriplet::AddMCIndex(Int_t mcindex) { fMCIndex[mcindex]++; fMCIndexList.push_back(mcindex); } void PndOnlineSttTriplet::AddTrackIndex(Int_t trackindex) { fTrackIndex[trackindex]++; fTrackIndexList.push_back(trackindex); } Int_t PndOnlineSttTriplet::MajorMCIndex() { Int_t maxcount = 0; Int_t maxval = -2; for (std::map::iterator iter = fMCIndex.begin(); iter != fMCIndex.end(); iter++) { if (iter->second > maxcount) { maxcount = iter->second; maxval = iter->first; } } return maxval; } Int_t PndOnlineSttTriplet::MajorTrackIndex() { Int_t maxcount = 0; Int_t maxval = -2; for (std::map::iterator iter = fTrackIndex.begin(); iter != fTrackIndex.end(); iter++) { if (iter->second > maxcount) { maxcount = iter->second; maxval = iter->first; } } return maxval; } Double_t PndOnlineSttTriplet::MCIndexMajority() { Int_t maxcount = 0; Int_t totalcount = 0; for (std::map::iterator iter = fMCIndex.begin(); iter != fMCIndex.end(); iter++) { if (iter->second > maxcount) { maxcount = iter->second; totalcount += iter->second; } } return ((Double_t)maxcount)/((Double_t)totalcount); } Double_t PndOnlineSttTriplet::TrackIndexMajority() { Int_t maxcount = 0; Int_t totalcount = 0; for (std::map::iterator iter = fTrackIndex.begin(); iter != fTrackIndex.end(); iter++) { if (iter->second > maxcount) { maxcount = iter->second; totalcount += iter->second; } } return ((Double_t)maxcount)/((Double_t)totalcount); } void PndOnlineSttTriplet::AddTriplet(const PndOnlineSttTriplet& rightTriplet) { fHitTimeSum += rightTriplet.fHitTimeSum; for (int i = 0; i < rightTriplet.fTubes.size(); i++) { fTubes.push_back(rightTriplet.fTubes.at(i)); } if (rightTriplet.fMinHitTime < fMinHitTime) { fMinHitTime = rightTriplet.fMinHitTime; fOldestStraw = rightTriplet.fOldestStraw; } if (rightTriplet.fMaxHitTime > fMaxHitTime) { fMaxHitTime = rightTriplet.fMaxHitTime; } for (std::map::const_iterator iter = rightTriplet.fMCIndex.begin(); iter != rightTriplet.fMCIndex.end(); iter++) { fMCIndex[iter->first] += iter->second; } for (int i = 0; i < rightTriplet.fMCIndexList.size(); i++) { fMCIndexList.push_back(rightTriplet.fMCIndexList.at(i)); } for (std::map::const_iterator iter = rightTriplet.fTrackIndex.begin(); iter != rightTriplet.fTrackIndex.end(); iter++) { fTrackIndex[iter->first] += iter->second; } for (int i = 0; i < rightTriplet.fTrackIndexList.size(); i++) { fTrackIndexList.push_back(rightTriplet.fTrackIndexList.at(i)); } } ClassImp(PndOnlineSttTriplet);