#include "TChough1.h" #include #include"TGraph.h" #include"TCanvas.h" #include"TApplication.h" #include"TSystem.h" #include"TRandom.h" #include"TEllipse.h" TChough1::TChough1(const TVector3& _yp,const TVector3& _zp,double _r1,double _r2) : TCabsHough(_yp,_zp){ r1Y=_r1; r2Y=_r2; minAY = -5.; maxAY = 5.; minBY = -1.; maxBY = 1.; nBinsAY = 50; nBinsBY = 50; canvas1 = NULL; houghHistoYZ=NULL; for(int i=0;iDivide(1,2); c->cd(1); g->SetTitle(""); g->GetXaxis()->SetTitle("z"); g->SetMarkerStyle(24); g->SetMarkerSize(2.); g->Draw("AP"); std::vector selHits; for(int i=0;iSetLineStyle(1); houghLinesYZ[i]->SetLineWidth(1); houghLinesYZ[i]->SetLineColor(kGreen); } } double xsel[selHits.size()]; double ysel[selHits.size()]; for(int i=0;iSetMarkerStyle(20); gsel->SetMarkerColor(kGreen); gsel->Draw("P"); c->cd(2); houghHistoYZ->Draw("colz"); double r1=getScaleA()*r1Y; double r2=getScaleB()*r2Y; TEllipse* ell = new TEllipse(aymax,bymax,r1,r2); ell->SetFillStyle(0); ell->SetLineWidth(4); ell->Draw("same"); for(int i=0;iDraw("same"); } if(stop){ gApplication->SetReturnFromRun(kTRUE); gSystem->Run(); } } void TChough1::doHough(){ cleanup(); NumberOfHits = nHits(); assert(NumberOfHits<=Max_NumberOfHits); for(int i=0;i=0) { return true; } return false; } void TChough1::findMaxInHisto(double& amax,double& bmax) { double minA,maxA,minB,maxB,nBinsA,nBinsB; TH2D* hist; hist = houghHistoYZ; minA = minAY; maxA = maxAY; minB = minBY; maxB = maxBY; nBinsA = nBinsAY; nBinsB = nBinsBY; double binA = (maxA - minA)/nBinsA; double binB = (maxB - minB)/nBinsB; double maxEntry = -1; for(int ia=0;iaGetBinContent(ia+1,ib+1) > maxEntry) { maxEntry = hist->GetBinContent(ia+1,ib+1); amax = minA + ia*binA + 0.5*binA; bmax = minB + ib*binB + 0.5*binB; } } } } void TChough1::cleanup() { // std::cout << "Cleaning up..." << std::endl; delete canvas1; delete houghHistoYZ; for(int i=0;iSetLineColor(kBlue); houghLinesYZ[i]->SetLineStyle(2); } } void TChough1::findHitsOnTrack(){ double z,y; double discr; for(int i=0;i=0) { selHits[nSelHits] = ihit; nSelHits++; } if(discr>=0) houghLinesYZ[ihit]->SetLineStyle(1); if(discr>=0) houghLinesYZ[ihit]->SetLineWidth(1); if(discr>=0) houghLinesYZ[ihit]->SetLineColor(kGreen); } } void TChough1::makeHoughHisto(){ char buf[50]; static TRandom r(0); sprintf(buf,"houghHistoYZ%5.5f",r.Uniform()); houghHistoYZ = new TH2D(buf,"",nBinsAY,minAY,maxAY,nBinsBY,minBY,maxBY); houghHistoYZ->SetStats(kFALSE); houghHistoYZ->GetYaxis()->SetTitle("B"); houghHistoYZ->GetXaxis()->SetTitle("A"); for(int ihit=0;ihit 0) { houghHistoYZ->SetBinContent(ia+1,ib+1,houghHistoYZ->GetBinContent(ia+1,ib+1) + weight); } } } } } int TChough1::binWeight(int ia, int ib, int ihit) { double minA,maxA,minB,maxB,nBinsA,nBinsB; double y; double z = HitCoordinates[ihit][1]; y = HitCoordinates[ihit][0]; minA = minAY; maxA = maxAY; minB = minBY; maxB = maxBY; nBinsA = nBinsAY; nBinsB = nBinsBY; double binA = (maxA - minA)/nBinsA; double binB = (maxB - minB)/nBinsB; double a0 = minA + ia*binA; double b0 = minB + ib*binB; double a1 = a0 + binA; double b1 = b0 + binB; double a_at_b0 = (y-b0)/z; double a_at_b1 = (y-b1)/z; double b_at_a0 = -1.0*a0*z+y; double b_at_a1 = -1.0*a1*z+y; bool left=false; bool right=false; bool top=false; bool bottom=false; if(b_at_a0>b0 && b_at_a0b0 && b_at_a1a0 && a_at_b0a0 && a_at_b1& _c){ TVector3 xp=yp.Cross(zp); TMatrixT S(3,3); S[0][0]=xp.X(); S[1][0]=xp.Y(); S[2][0]=xp.Z(); S[0][1]=yp.X(); S[1][1]=yp.Y(); S[2][1]=yp.Z(); S[0][2]=zp.X(); S[1][2]=zp.Y(); S[2][2]=zp.Z(); //TMatrixT Stransp = S; //Stransp.T(); clear(); for(unsigned int i=0;i<_c.size();++i){ TVector3 hitPrime = S * _c.at(i).posXYZ(); //xprime isnt needed ypHit.push_back(hitPrime.Y()); zpHit.push_back(hitPrime.Z()); } //renormalize y and z double y1=-1.; double y2=1.; double z1=-1; double z2=1.; double minY=1.E50; double maxY=-1.E50; double minZ=1.E50; double maxZ=-1.E50; for(unsigned int i=0;imaxY) maxY=ypHit.at(i); if(ypHit.at(i)maxZ) maxZ=zpHit.at(i); if(zpHit.at(i)