//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of class PndHypIdealPRTask // see PndHypIdealPRTask.hh for details // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Sebastian Neubert TUM (original author) // Alicia Sanchez HIM modified for hypernuclei // //----------------------------------------------------------- // Panda Headers ---------------------- // This Class' Header ------------------ #include "PndHypIdealPRTask.h" // C/C++ Headers ---------------------- #include #include // Collaborating Class Headers -------- #include "FairRootManager.h" #include "TClonesArray.h" #include "TArrayD.h" #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "FairField.h" //#include "../../tof/PndTofPoint.h" #include "PndHypPoint.h" #include "PndHypHit.h" #include "PndMCTrack.h" //#include "../../recotasks/PndFieldAdaptor.h" #include "FairGeanePro.h" #include "FairTrackParP.h" #include "TRandom.h" // Class Member definitions ----------- PndHypIdealPRTask::PndHypIdealPRTask() : FairTask("Ideal Pattern Reco"), fPersistence(kFALSE),fEventNr(0) { } PndHypIdealPRTask::~PndHypIdealPRTask() { if(fPH!=NULL)delete fPH; } InitStatus PndHypIdealPRTask::ReInit() { InitStatus stat=kERROR; return stat; } InitStatus PndHypIdealPRTask::Init() { //Get ROOT Manager FairRootManager* ioman= FairRootManager::Instance(); if(ioman==0) { Error("PndHypIdealPRTask::Init","RootManager not instantiated!"); return kERROR; } // open hit arrays std::map::iterator iter=fHitBranchNameMap.begin(); while(iter!=fHitBranchNameMap.end()){ TClonesArray* ar=(TClonesArray*) ioman->GetObject(iter->second); if(ar==0){ Error("PndHypDPRTask::Init","point-array %s not found!",iter->second.Data()); } else{ fHitBranchMap[iter->first] = ar; } ++iter; }//end loops over hit types // open MCTruth array fMcArray=(TClonesArray*) ioman->GetObject("MCTrack"); if(fMcArray==0){ Error("PndHypDPRTask::Init","mctrack-array not found!"); return kERROR; } fPointArray=(TClonesArray*) ioman->GetObject("HypPoint"); if(fPointArray==0){ Error("PndHypDPRTask::Init","hyp hit-array not found!"); return kERROR; } fSdsArray=(TClonesArray*) ioman->GetObject("MVDPoint"); if(fSdsArray==0){ Error("PndHypDPRTask::Init","mvd hit-array not found!"); return kERROR; } // create and register output array fTrackArray = new TClonesArray("GFTrackCand"); ioman->Register("HypTrackCand","HYP",fTrackArray,fPersistence); // setup histograms fPH=new TH1D("pH","p",1000,0.02,0.3); std::cout << "-I- PndHypIdealPRTask: Initialisation successfull" << std::endl; return kSUCCESS; } void PndHypIdealPRTask::Exec(Option_t*) { std::cout<<"PndHypIdealPRTask::Exec"<Delete(); // use McId to distinguish data from different tracks //std::map candmap; std::cout<<"<<<<< Event "<::iterator iter=fHitBranchMap.begin(); while(iter!=fHitBranchMap.end()){ fHitArray = iter->second; //loop over points Int_t np=fHitArray->GetEntriesFast(); FairMCPoint* point; FairHit* hit; for(Int_t ip=0; ipfirst==2){ hit = (PndHypHit*)fHitArray->At(ip); point = (PndHypPoint*)fPointArray->At(hit->GetRefIndex()); } else if(iter->first==3){ hit = (PndSdsHit*)fHitArray->At(ip); point = (PndSdsMCPoint*)fSdsArray->At(hit->GetRefIndex()); } if(point==0)continue; unsigned int id=point->GetTrackID(); // cut on insane ids if(id>10000)continue; // look for track in mc map AddHitToTrack(id,iter->first,ip); /* if(candmap[id]==NULL){ // create new track //std::cout<<"Creating new track candidate with id="<addHit(iter->first,ip); */ }// end loop over cluster ++iter; } // ------------------------------------------------------------------------ // try to find some starting values // loop over tracks std::map::iterator candIter=fTrackCandMap.begin(); while(candIter!=fTrackCandMap.end()){ GFTrackCand* cand=candIter->second; if(cand->getNHits()<3){ ++candIter; continue; } TVector3 frmom; unsigned int detId, hitId; cand->getHit(0, detId, hitId); PndHypHit* myHit; myHit = (PndHypHit*)fHitArray->At(hitId); FairMCPoint* pointF; if(detId==2) pointF =(FairMCPoint*)fPointArray->At(myHit->GetRefIndex()); std::cout << "Detector no. " << detId <<": "<< *pointF; pointF->Momentum(frmom); fPH->Fill(frmom.Mag()); // create track object new((*fTrackArray)[fTrackArray->GetEntriesFast()]) GFTrackCand(*(candIter->second)); ++candIter; }// end loop over tracks std::cout<GetEntriesFast()<<" tracks created "<Delete(); fMcArray->Delete(); //return; } void PndHypIdealPRTask::AddHitToTrack(Int_t trackID, Int_t detnum, Int_t iHit){ if(fTrackCandMap[trackID]==NULL){ // create new track //std::cout<<"Creating new track candidate with id="<At(trackID); int pdg=mc->GetPdgCode(); double q; int PDG; std::cout<<" particle "<5000){ q = GetChargeIon(pdg); //std::cout<<" particle "<GetParticle(pdg)->Charge()/3.; //std::cout<<" particle "<setTrackSeed( mc->GetStartVertex(), mc->GetMomentum(), q/mc->GetMomentum().Mag() ); myTCand->setMcTrackId(trackID); myTCand->setPdgCode(pdg); fTrackCandMap[trackID]= myTCand; } // add hit to track // set detectorid=2; fTrackCandMap[trackID]->addHit(detnum,iHit); } Int_t PndHypIdealPRTask::GetChargeIon(Int_t ion) { Int_t A,Z,L; if(ion>1000000000&&(ion<1010000000)) { ion -= 1000000000; Z = ion/10000; ion -= 10000*Z; A = ion/10; cout<<" ion charge "<1010000000||ion>1020000000)) { ion -= 1000000000; L = ion/10000000; ion -= 10000000*L; Z = ion/10000; ion -= 10000*Z; A = ion/10; cout<::const_iterator ci=fTrackCandMap.begin(); ci != fTrackCandMap.end(); ci++){ delete(ci->second); } fTrackCandMap.clear(); } void PndHypIdealPRTask::WriteHistograms(){ TFile* file = FairRootManager::Instance()->GetOutFile(); file->cd(); file->mkdir("HypPrefit"); file->cd("HypPrefit"); fPH->Write(); delete fPH; fPH=NULL; file->Close(); delete file; } ClassImp(PndHypIdealPRTask)