// ------------------------------------------------------------------------- // ----- PndLmdTrackFinderCATask ----- // ----- Created 18/05/11 by A. Karavdina ----- // ------------------------------------------------------------------------- #include #include "TClonesArray.h" #include "TArrayD.h" #include "TVectorD.h" #include "TGeoManager.h" #include "FairRootManager.h" #include "FairRun.h" #include "FairRuntimeDb.h" #include "PndLmdTrackFinderCATask.h" #include "PndSdsDigiStrip.h" #include "TStopwatch.h" // #include "PndSdsPixelCluster.h" // ----- Default constructor ------------------------------------------- PndLmdTrackFinderCATask::PndLmdTrackFinderCATask() : FairTask("LMD Track Finding Task (Cellular Automation)") { missPlAlgo = false; fHitBranchStrip = "LMDHitsStrip"; fClusterBranchStrip = "LMDStripClusterCand"; fDigiBranchStrip = "LMDStripDigis"; dXY = 0.5; // dXY = 0.01;//TEST } // ------------------------------------------------------------------------- // ----- Constructor ------------------------------------------- PndLmdTrackFinderCATask::PndLmdTrackFinderCATask(const bool missPl) : FairTask("LMD Track Finding Task (Cellular Automation) with/without <> algoritm") { missPlAlgo = missPl; fHitBranchStrip = "LMDHitsStrip"; fClusterBranchStrip = "LMDStripClusterCand"; fDigiBranchStrip = "LMDStripDigis"; dXY = 0.5; // dXY = 0.01;//TEST } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- PndLmdTrackFinderCATask::~PndLmdTrackFinderCATask() {} // ------------------------------------------------------------------------- // ----- Initialization of Parameter Containers ------------------------- void PndLmdTrackFinderCATask::SetParContainers() { // Get Base Container /* FairRun* ana = FairRun::Instance(); FairRuntimeDb* rtdb=ana->GetRuntimeDb(); fGeoPar = (PndSdsGeoPar*)(rtdb->getContainer("PndSdsGeoPar")); */ } InitStatus PndLmdTrackFinderCATask::ReInit() { InitStatus stat=kERROR; return stat; /* FairRun* ana = FairRun::Instance(); FairRuntimeDb* rtdb=ana->GetRuntimeDb(); fGeoPar=(PndSdsGeoPar*)(rtdb->getContainer("PndSdsGeoPar")); return kSUCCESS; */ } // ----- Public method Init -------------------------------------------- InitStatus PndLmdTrackFinderCATask::Init() { FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { std::cout << "-E- PndLmdTrackFinderCATask::Init: " << "RootManager not instantiated!" << std::endl; return kFATAL; } // Get input array fStripHitArray = (TClonesArray*) ioman->GetObject(fHitBranchStrip); if ( !fStripHitArray){ std::cout << "-W- PndLmdTrackFinderCATask::Init: " << "No fStripHitArray!" << std::endl; return kERROR; } fStripClusterArray = (TClonesArray*) ioman->GetObject(fClusterBranchStrip); if ( !fStripClusterArray){ std::cout << "-W- PndLmdTrackFinderCATask::Init: " << "No StripclusterArray!" << std::endl; return kERROR; } fStripDigiArray = (TClonesArray*) ioman->GetObject(fDigiBranchStrip); if ( !fStripDigiArray){ std::cout << "-W- PndLmdTrackFinderCATask::Init: " << "No StripdigiArray!" << std::endl; return kERROR; } fTrackCandArray = new TClonesArray("PndTrackCand"); ioman->Register("LMDTrackCand", "PndLmd", fTrackCandArray, kTRUE); // fTrackCandArrayTemp = new TClonesArray("PndTrackCand"); // ioman->Register("LMDTrackCand", "PndLmd", fTrackCandArray, kTRUE); // fTruePointArray = new TClonesArray("PndSdsMCPoint"); std::cout << "-I- PndLmdTrackFinderCATask: Initialisation successfull" << std::endl; return kSUCCESS; } // ------------------------------------------------------------------------- // ----- Public method Exec -------------------------------------------- void PndLmdTrackFinderCATask::Exec(Option_t* opt) { // TStopwatch *timer_exec = new TStopwatch(); // timer_exec->Start(); // TStopwatch *timer_start = new TStopwatch(); // timer_start->Start(); fTrackCandArrayTemp = new TClonesArray("PndTrackCand"); if(fVerbose>2) cout << "Evt started--------------"<Clear(); Int_t nStripHits = fStripHitArray->GetEntriesFast(); if(nStripHits<2){ if(fVerbose>2) cout << "Evt finsihed: too less hits-----"< detZ; //find plane positions for (Int_t iHit = 0; iHit < nStripHits; iHit++){ Double_t tmp = ((PndSdsHit*) (fStripHitArray->At(iHit)))->GetZ(); bool newZ = true; for(Int_t idet = 0; idet < detZ.size(); idet++){ if(fabs(tmp-detZ.at(idet))<9.){ //check if already found [for using with Dipole] newZ = false; } } if(newZ){ detZ.push_back(tmp); //sort positions Int_t pos=-1; for(Int_t idet = detZ.size()-1; idet >= 0; idet--){ if(tmp < detZ.at(idet)) pos=idet; } if(pos!=-1){ Double_t swap = detZ.at(pos); detZ.at(pos) = tmp; tmp = swap; for(Int_t i=pos+1; i2){ if(detZ.size()>0){ for (Int_t i=0; iAt(hitsd.at(0).at(i)); cout<<"Plane0 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<1){ for (Int_t i=0; iAt(hitsd.at(1).at(i)); cout<<"Plane1 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<2){ for (Int_t i=0; iAt(hitsd.at(2).at(i)); cout<<"Plane2 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<3){ for (Int_t i=0; iAt(hitsd.at(3).at(i)); cout<<"Plane3 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<Stop(); // timer_start->Print("u"); // Double_t rtime = timer_start->RealTime(); // Double_t ctime = timer_start->CpuTime(); // cout << "Real time_start " << rtime << " s, CPU time_start " << ctime << " s" << endl; // // cout << endl; // delete timer_start; ///Track-Finder ---------------------------------------------------------- // TStopwatch *timer_makingcells = new TStopwatch(); // timer_makingcells->Start(); int Npoints=0; const int nplanes = detZ.size(); int NpointsI[nplanes]; for(int i=0;iNpoints) Npoints=hitsd.at(i).size(); } // int nc=0; // int ncI[nplanes]; // ncI[0]=0; // for(int i=1;iStart(); double d_max = 0.02; // double d_max1 = 0.01, d_max2 = 0.01, d_max; // double d_max1 = ., d_max2 = 4., d_max; //TEST int cd=0; bool stop=false; vector connect; vector conn_flag; // int nCon; while(!stop){ double d1=0, d2=0; for(int ipl=0;ipl<(nplanes-2);ipl++){ for(int p=ncI[ipl];pd_max || d2>d_max) cd++; // if(cd>Ncomb) stop=true; //??? here we can loose track which has huge multiple scattering! // cout<<"count="<-1;t--){ if(fVerbose>4) cout<<"pv["<0;jg--){ // cout<<"pv[connect[jg]] = "<3) cout<<"! detZ.size() = "<3) cout<<"Taking into account missing planes!"< > planes_new(detZ.size()); for(int j=2;jAt(hitsd.at(j-2).at(i)); PndSdsHit *hit1=(PndSdsHit*)fStripHitArray->At(hitsd.at(j).at(k)); /// Check dPhi, dTheta of cells to reduce wrong combination double x0 = hit0->GetX(); double y0 = hit0->GetY(); double z0 = hit0->GetZ(); double x1 = hit1->GetX(); double y1 = hit1->GetY(); double z1 = hit1->GetZ(); TVector3 dirc(x1-x0,y1-y0,z1-z0); // cout<<"dirc.Theta() = "<4) cout<<" connect.size() = "<-1;t--){ if(fVerbose>4) cout<<"pv["<5e-2 || fabs(dir.Phi())>0.26) continue; if(fVerbose>2){ cout<<"posSeed:"<setTrackSeed(posSeed,dir,-1); // cout<<"trk.size()-1 = "<At(hitsd.at(pl).at(id))); PndSdsClusterStrip* myCluster = (PndSdsClusterStrip*)(fStripClusterArray->At(myHit->GetClusterIndex())); PndSdsDigiStrip* astripdigi = (PndSdsDigiStrip*)fStripDigiArray->At(myCluster->GetDigiIndex(0)); myTCand->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Mag()); } int id = cells.at(7).at(trk[trk.size()-1]); int pl = cells.at(9).at(trk[trk.size()-1]); PndSdsHit* myHit = (PndSdsHit*)(fStripHitArray->At(hitsd.at(pl).at(id))); PndSdsClusterStrip* myCluster = (PndSdsClusterStrip*)(fStripClusterArray->At(myHit->GetClusterIndex())); PndSdsDigiStrip* astripdigi = (PndSdsDigiStrip*)fStripDigiArray->At(myCluster->GetDigiIndex(0)); myTCand->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Mag()); // cout<<"Save hit#"<RealTime(); // ctime = timer_makingtrk->CpuTime(); // cout << "Real time_makingtrk " << rtime << " s, CPU time_makingtrk " << ctime << " s" << endl; // // cout << endl; // delete timer_makingtrk; //if(fVerbose>2) cout<<"connect.size()="<5e-2 || fabs(dir.Phi())>0.26) continue; myTCand1->setTrackSeed(posSeed,dir,-1); if(fVerbose>2){ cout<<"posSeed:"<At(hitsd.at(pl).at(id))); PndSdsClusterStrip* myCluster = (PndSdsClusterStrip*)(fStripClusterArray->At(myHit->GetClusterIndex())); PndSdsDigiStrip* astripdigi = (PndSdsDigiStrip*)fStripDigiArray->At(myCluster->GetDigiIndex(0)); myTCand1->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Mag()); } int id = cells.at(7).at(trk[trk.size()-1]); int pl = cells.at(9).at(trk[trk.size()-1]); // cout<<"Save hit#"<At(hitsd.at(pl).at(id))); PndSdsClusterStrip* myCluster = (PndSdsClusterStrip*)(fStripClusterArray->At(myHit->GetClusterIndex())); PndSdsDigiStrip* astripdigi = (PndSdsDigiStrip*)fStripDigiArray->At(myCluster->GetDigiIndex(0)); myTCand1->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Mag()); new((*fTrackCandArrayTemp)[NtrkRec]) PndTrackCand(*(myTCand1)); //save Track Candidate // new((*fTrackCandArray)[NtrkRec]) PndTrackCand(*(myTCand1)); //save Track Candidate NtrkRec++; // cout<<"Ntrk No. "<2) cout << "Evt finsihed--------------"<RealTime(); // ctime = timer_exec->CpuTime(); // cout << "Real time_exec " << rtime << " s, CPU time_exec " << ctime << " s" << endl; // cout << endl; // delete timer_exec; //} if(missPlAlgo && detZ.size()==4){ if(fVerbose>2) cout<<" ------- Track-Candidates Fillter ------"<GetEntriesFast(); TMatrixD trkcan_point(ntcand,4); for(int trkcID=0;trkcIDAt(trkcID); const int numPts = trcnd->GetNHits(); //read how many points in this track // if(numPts==4) continue; for(unsigned int ihit=0; ihitGetSortedHit(ihit); //get hit Int_t index = theHit.GetHitId(); double rho = theHit.GetRho(); int pos_num; if(rho<1105) pos_num=0; else{ if(rho<1115) pos_num=1; else{ if(rho<1125) pos_num=2; else{ pos_num=3; } } } // Int_t detId = theHit.GetDetId(); // cout<<"index: "<At(index); // if(numPts==3) trkcan_point(trkcID,ihit+1)=index; // else trkcan_point(trkcID,ihit)=index; trkcan_point(trkcID,pos_num)=index; }//end of Hits in TCand } // cout<<"trkcan_point:"<4) trkcan_point.Print(); TMatrixD coincidence(ntcand,4); for(int trkcID=0;trkcID-1;trkcID1--){ for(int trkcID2=ntcand-2;trkcID2>-1;trkcID2--){ if(trkcID1==trkcID2) continue; for(unsigned int ihit=0; ihit<4; ihit++){ //loop on the hits if(trkcan_point(trkcID1,ihit)==-1 || trkcan_point(trkcID2,ihit)==-1) continue; if(trkcan_point(trkcID1,ihit)==trkcan_point(trkcID2,ihit)){ // cout<<"trkcID1 = "<4) coincidence.Print(); TVectorD distance(ntcand); TVectorF flag(ntcand); for(int trkcID=0;trkcIDAt(trkcID); const int numPts = trcnd->GetNHits(); //read how many points in this track int repE[ntcand]; if(numPts==4){ if(fVerbose>4) cout<<"trk-cand #"<GetEntriesFast(); if(fVerbose>4) cout<<"ntcand from ArrayTemp is "<At(trkcID); new((*fTrackCandArray)[NsaveTrk]) PndTrackCand(*(trcnd)); //save Track Candidate NsaveTrk++; } } // // for(int trkcID=0;trkcID0) repEl++; // // } // // flag(trkcID)=false; // // PndTrackCand* trcnd = (PndTrackCand*)fTrackCandArrayTemp->At(trkcID); // // const int numPts = trcnd->GetNHits(); //read how many points in this track // // if(repEl<3 || numPts==4){ // // // if(repEl<10 || numPts==4){ // // // if(repEl<1){ // // // PndTrackCand* trcnd = (PndTrackCand*)fTrackCandArrayTemp->At(trkcID); // // new((*fTrackCandArray)[NsaveTrk]) PndTrackCand(*(trcnd)); //save Track Candidate // // flag(trkcID)=true; // // NsaveTrk++; // // // delete trcnd; // // } // // else{ // // for(unsigned int ihit=1; ihit<3; ihit++){ // // int index_prev = trkcan_point(trkcID,ihit-1); // // if(index_prev==-1) continue; // // int index_mid = trkcan_point(trkcID,ihit); // // if(index_mid==-1) continue; // // int index_next = trkcan_point(trkcID,ihit+1); // // if(index_next==-1) continue; // // PndSdsHit* Hit_prev = (PndSdsHit*) fStripHitArray->At(index_prev); // // TVector3 Hit_prevPos = Hit_prev->GetPosition(); // // PndSdsHit* Hit_mid = (PndSdsHit*) fStripHitArray->At(index_mid); // // TVector3 Hit_midPos = Hit_mid->GetPosition(); // // PndSdsHit* Hit_next = (PndSdsHit*) fStripHitArray->At(index_next); // // TVector3 Hit_nextPos = Hit_next->GetPosition(); // // // cout<<"index_prev = "<0){ // // int othTrk = coincidence(trkcIDt,ihitt); // // cout<<" coincidence("<At(trkcIDt); // // // PndTrackCand* trcndo = (PndTrackCand*)fTrackCandArrayTemp->At(othTrk); // // // const int numPtsT = trcndt->GetNHits(); //read how many points in this track // // // const int numPtsO = trcndo->GetNHits(); //read how many points in other track // // // if(numPtsT!=numPtsO) break; // // new((*fTrackCandArray)[NsaveTrk]) PndTrackCand(*(trcndt)); //save Track Candidate // // cout<<"Trk No. "<0){ // int othTrk = coincidence(trkcIDt,ihitt); // if(flag(othTrk) || flag(trkcIDt)) continue; // // cout<<"Now we are compare trk #"<At(trkcIDt); // new((*fTrackCandArray)[NsaveTrk]) PndTrackCand(*(trcndt)); //save Track Candidate // // delete trcndt; // flag(trkcIDt)=true; // NsaveTrk++; // } // } // } // } // Delete fTrackCandArrayTemp; Int_t ntcandFin=fTrackCandArray->GetEntriesFast(); if(fVerbose>2) cout<<"Number of Trk-Cands is "<2) cout << "Evt finsihed--------------"<GetMomentum(); return (2/TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py())); } // ------------------------------------------------------------------------- Double_t PndLmdTrackFinderCATask::GetTrackDip(PndMCTrack* myTrack) { TVector3 p= myTrack->GetMomentum(); return (p.Mag()/TMath::Sqrt(p.Px()*p.Px() + p.Py()*p.Py())); } // ------------------------------------------------------------------------- ClassImp(PndLmdTrackFinderCATask);