#include "PndTorinoDetectorMCTrackAssociator.h" #include "PndTrack.h" #include "PndTrackID.h" #include "FairRunAna.h" #include "PndTorinoDetectorPoint.h" #include "PndTorinoDetectorHit.h" #include "PndMCTrack.h" #include "FairMCApplication.h" #include "FairRootManager.h" #include "FairTask.h" #include #include using namespace std; //_________________________________________________________________ PndTorinoDetectorMCTrackAssociator::PndTorinoDetectorMCTrackAssociator() { //--- //fTrackArray = new TClonesArray("PndTrack"); fTrackIDArray = new TClonesArray("PndTrackID"); fTrackInBranchName = ""; fTrackOutBranchName = ""; fPersistence = kTRUE; fVerbose = kFALSE; } //_________________________________________________________________ PndTorinoDetectorMCTrackAssociator::PndTorinoDetectorMCTrackAssociator(const char *name, const char *title):FairTask(name) { //--- //fTrackArray = new TClonesArray("PndTrack"); fTrackIDArray = new TClonesArray("PndTrackID"); fTrackInBranchName = ""; fTrackOutBranchName = ""; fPersistence = kTRUE; fVerbose = kFALSE; } //_________________________________________________________________ PndTorinoDetectorMCTrackAssociator::~PndTorinoDetectorMCTrackAssociator() { } //_________________________________________________________________ InitStatus PndTorinoDetectorMCTrackAssociator::Init() { // cout << "InitStatus PndTorinoDetectorMCTrackAssociator::Init\n\n"; cout << "-I- PndTorinoDetectorMCTrackAssociator::Init" << endl; FairRootManager *fManager =FairRootManager::Instance(); fTrackArray = (TClonesArray *)fManager->GetObject(fTrackInBranchName); if ( ! fTrackArray ) { cout << "-I- PndTorinoDetectorMCTrackAssociator::Init: No PndTrack array!" << endl; return kERROR; } // ---------------------- fTorinoPointArray = (TClonesArray*) fManager->GetObject("PndTorinoDetectorPoint"); if (!fTorinoPointArray) { cout << "-W- PndTorinoDetectorMCTrackAssociator::Init: No TorinoPoint array" << endl; } fTorinoHitArray = (TClonesArray*) fManager->GetObject("PndTorinoDetectorHit"); if(!fTorinoHitArray) { cout << "-W- PndTorinoDetectorMCTrackAssociator::Init: No TorinoHit array" << endl; } // ---------------------- if (fVerbose) cout << "-I- PndTorinoDetectorMCTrackAssociator::Init: Verbose Mode ON" << endl; Register(); return kSUCCESS; } //_________________________________________________________________ Int_t PndTorinoDetectorMCTrackAssociator::GetTorinoHits(Int_t index) { // Taking points from PndTorinoDetectorHit PndTorinoDetectorHit* hit = (PndTorinoDetectorHit*) fTorinoHitArray->At(index); if (!hit) { cout << "-E- PndTorinoDetectorMCTrackAssociator::GetTorinoHits: PndTorinoDetectorHit #" << index << " does not exist!!!" << endl; return -1; } if (hit->GetRefIndex()>-1) { PndTorinoDetectorPoint* myPoint = (PndTorinoDetectorPoint*)(fTorinoPointArray->At(hit->GetRefIndex())); if (!myPoint) { cout << "-E- PndTorinoDetectorMCTrackAssociator::GetTorinoHits: PndTorinoDetectorPoint #" << hit->GetRefIndex() << " does not exist!!!" << endl; return -1; } return (myPoint->GetTrackID()); } else { if (fVerbose) cout << "-E- PndTorinoDetectorMCTrackAssociator::GetTorinoHits: GetTorinoDetectorHit #" << index << " has GetRefIndex()<0 -> noise hit" << endl; return -1; } } //________________ //_________________________________________________________________ void PndTorinoDetectorMCTrackAssociator::Exec(Option_t * option) { //FIXME: Here we should call Clear() to save time. For // really large events we could call Delete() to save Memory fTrackIDArray->Delete(); for (Int_t tt=0; ttGetEntriesFast(); tt++) { map fMCTrackList; // MC TrackId, multiplicity map::iterator iter; PndTrack *pndTrack = (PndTrack*)fTrackArray->At(tt); PndTrackCand trackCand = pndTrack->GetTrackCand(); for (Int_t ii=0; iiGetBranchId("PndTorinoDetectorHit")) && fTorinoPointArray && fTorinoHitArray) trackID = GetTorinoHits(candHit.GetHitId()); } fMCTrackList[trackID]++; } // end of PndTrackCand loop multimap fMCRevertedList; // multiplicity, MC TrackId Int_t count = 0; for (iter=fMCTrackList.begin(); iter!=fMCTrackList.end(); ++iter) { fMCRevertedList.insert(pair(-(*iter).second, (*iter).first)); count++; } TArrayI trackID(count); TArrayI multID(count); count = 0; for (iter=fMCRevertedList.begin(); iter!=fMCRevertedList.end(); ++iter) { trackID[count] = (*iter).second; multID[count] = -(*iter).first; count++; } TClonesArray &pndtrackids = *fTrackIDArray; Int_t size = pndtrackids.GetEntriesFast(); PndTrackID* pndTrackId = new(pndtrackids[size]) PndTrackID(size ,trackID, multID); } // end of PndTrack loop } //_________________________________________________________________ void PndTorinoDetectorMCTrackAssociator::Register() { //--- FairRootManager::Instance()-> Register(fTrackOutBranchName,"Gen", fTrackIDArray, fPersistence); } ClassImp(PndTorinoDetectorMCTrackAssociator)