// ------------------------------------------------------------------------- // ----- 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; d_max = 0.01; hdist = new TH1D("hdist","distance from common point",1e4,0,10.); // dXY = 0.01;//TEST } // ------------------------------------------------------------------------- // ----- Constructor ------------------------------------------- PndLmdTrackFinderCATask::PndLmdTrackFinderCATask(const bool missPl, const double setdmax) : FairTask("LMD Track Finding Task (Cellular Automation) with/without <> algoritm") { missPlAlgo = missPl; fHitBranchStrip = "LMDHitsStrip"; fClusterBranchStrip = "LMDStripClusterCand"; fDigiBranchStrip = "LMDStripDigis"; dXY = 0.5; hdist = new TH1D("hdist","distance from common point",1e3,0,1.); d_max = setdmax; // 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; } fTrackCandArrayTemp = new TClonesArray("PndTrackCand"); fTrackCandArray = new TClonesArray("PndTrackCand"); ioman->Register("LMDTrackCand", "PndLmd", fTrackCandArray, kTRUE); 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(); fTrackCandArrayTemp->Clear(); Int_t nStripHits = fStripHitArray->GetEntriesFast(); if(nStripHits<2){ if(fVerbose>2) cout << "Evt finsihed: too less hits-----"< > hitsd(4); //hit'ids splitted by detectorplane for(Int_t iHit = 0; iHit < nStripHits; iHit++){ PndSdsHit* myHit = (PndSdsHit*)(fStripHitArray->At(iHit)); Int_t sensid = myHit->GetSensorID(); // Sensors: 1..32 Int_t planeid = floor((sensid)/8.); //8 sensors/plane => Planes: 0..3 hitsd.at(planeid).push_back(iHit); } Int_t nPlanes=0; for(Int_t iPlane = 0; iPlane < 4; iPlane++){ if(hitsd.at(iPlane).size()>0) nPlanes++; } if(nPlanes<3){ if(fVerbose>2) cout << "Evt finsihed: too less planes-----"<2){ if(hitsd.at(0).size()>0){ for (Int_t i=0; iAt(hitsd.at(0).at(i)); cout<<"Plane0 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<0){ for (Int_t i=0; iAt(hitsd.at(1).at(i)); cout<<"Plane1 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<0){ for (Int_t i=0; iAt(hitsd.at(2).at(i)); cout<<"Plane2 Hit=("<GetX()<<", "<GetY()<<", "<GetZ()<<") with err=(" <GetDx()<<", "<GetDy()<<", "<GetDz()<<")"<0){ 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 = 4; int NpointsI[nplanes]; for(int i=0;iNpoints) Npoints=hitsd.at(i).size(); } vector pv;//current Position value vector pv_new;//new Position value std::vector< std::vector > cells(10); std::vector< std::vector > planes(nplanes); int count = 0; for(int j=1;j<4;j++){ int maxI = NpointsI[j-1]; int maxK = NpointsI[j]; // cout<<"j="<Start(); 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];p1e-6) continue; if(fabs(cells.at(4).at(p)-cells.at(1).at(q))>1e-6) continue; if(fabs(cells.at(3).at(p)-cells.at(0).at(q))<1e-6){ /// v - vector of track direction /// w - vector between middle point and another end of cell /// d= [v,w]/|v| - distance /// [v,w]=(v_y*w_z-v_z*w_y, v_z*w_x-v_x*w_z,v_x*w_y-v_y*w_x) /// |v|=sqrt(v_x^2+v_y^2+v_z^2) double x0 = cells.at(0).at(p); double y0 = cells.at(1).at(p); double z0 = cells.at(2).at(p); double x1 = cells.at(3).at(q); double y1 = cells.at(4).at(q); double z1 = cells.at(5).at(q); double xt = cells.at(3).at(p); double yt = cells.at(4).at(p); double zt = cells.at(5).at(p); ///v(x1-x0,y1-y0,z1-z0) ///w(x0-xt,y0-yt,z0-zt) double d_x =(y1-y0)*(z0-zt)-(z1-z0)*(y0-yt); double d_y =(z1-z0)*(x0-xt)-(x1-x0)*(z0-zt); double d_z =(x1-x0)*(y0-yt)-(y1-y0)*(x0-xt); double norm_v = sqrt(pow((x1-x0),2)+pow((y1-y0),2)+pow((z1-z0),2)); double d = sqrt(d_x*d_x+d_y*d_y+d_z*d_z)/norm_v; if(fVerbose>3){ cout<<"For cell #"<Fill(d); // cout<<"d_max = "<0;jg--){ // cout<<"pv[connect[jg]] = "<3) cout<<"Taking into account missing planes!"<Fill(d); if(d4) cout<<" connect.size() = "<Fill(d); if(d-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()); myTCand->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Z()); } 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()); myTCand->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Z()); // 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()); myTCand1->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Z()); } 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()); myTCand1->AddHit(astripdigi->GetDetID(),hitsd.at(pl).at(id),myHit->GetPosition().Z()); 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 && nPlanes==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(); Int_t detectorID = theHit.GetDetId(); double rho = theHit.GetRho(); // cout<<"rho = "<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 } if(fVerbose>4) 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 #"<4) cout<<"Now we are in case with < 4 hits!"<5) cout<<"repE["<GetEntriesFast(); if(fVerbose>4) cout<<"ntcand from ArrayTemp is "<At(trkcID); new((*fTrackCandArray)[NsaveTrk]) PndTrackCand(*(trcnd)); //save Track Candidate 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);