28 #include "TLinearFitter.h"
52 if (plane != NULL )plane->
print();
61 Info(
"process",
"Event %d",
nEvents);
71 Int_t nCl = clArray->GetEntries();
74 Int_t nV = vArray->GetEntries();
83 for(
int a = 0;a<4;a++){
84 for(
int b =0;b<4;b++){
89 Corig[a][b]=(2*inc)*(2*inc)+theta*theta;
97 for(Int_t plane = 0; plane<2; plane++){
103 Double_t xStart[
NTRACK][4];
108 for(Int_t iV = 0; iV<nV; iV++){
110 if(vertex->
GetPlane() != plane)
continue;
114 Int_t color = kRed, fill = 0;
129 for(Int_t j = 0; j<nTr; j++){
134 Xorig[0][0] = x+20*Xorig[2][0];
135 Xorig[1][0] = z+20*Xorig[3][0];
139 TArrow* arrow =
new TArrow();
140 arrow->SetLineColor(kGray);
141 arrow->SetLineWidth(2);
142 arrow->SetFillColor(color);
144 arrow->DrawArrow(z,x,z+30*Xorig[3][0],x+30*Xorig[2][0],0.01);
150 for(Int_t i = 0; i<4; i++) xStart[iTr][i] = Xorig[i][0];
152 arr[iTr] =
new TArrayI(nCl);
153 for(Int_t i = 0; i<nCl; i++) arr[iTr]->AddAt(-1,i);
156 std::vector<TMatrixD> output =
NextStep(Xorig,Corig,iTr,clArray,arr[iTr],0,plane,color,fill,0,0,kTRUE);
157 TMatrixD Xend = output[1];
158 for(Int_t i = 0; i<2; i++) xEnd[iTr][i] = Xend[i][0];
159 for(Int_t i = 2; i<4; i++) xEnd[iTr][i] = -Xend[i][0];
164 while(arr[iTr]->At(ncl[iTr])>=0) ncl[iTr]++;
175 for(Int_t i1 = 0; i1<iTr; i1++) usedTr[i1] = 0;
176 for(Int_t i1 = 0; i1<iTr; i1++){
177 if(!arr[i1])
continue;
178 if(usedTr[i1])
continue;
179 Int_t ncl1 = ncl[i1];
180 Int_t dFirstMin = 1000;
181 Int_t iFirstMin = -1;
182 Bool_t endMin = kFALSE;
185 for(Int_t i = 1; i<iTr; i++) merge[i] = -1;
187 for(Int_t i2 = i1+1; i2<iTr; i2++){
188 if(!arr[i2])
continue;
189 Int_t ncl2 = ncl[i2];
190 Bool_t first = kTRUE;
192 Int_t j1first = -1, j2first = -1;
195 for(Int_t j1 = 0; j1<ncl1; j1++){
196 if(arr[i1]->At(j1)<0){
197 Info(
"process",
"???????????????");
201 for(Int_t j2 = 0; j2<ncl2; j2++){
202 if(arr[i2]->At(j2)<0){
206 if(arr[i2]->At(j2)==arr[i1]->At(j1)){
207 if(first){j2first = j2; j1first = j1; first = kFALSE;}
217 if(nComm>=8 || nComm>0.3*ncl1 || nComm>0.3*ncl2){
223 dFirst = j1first - j2first;
227 dFirst = j1first - (ncl2-j2first);
231 if(dFirst<dFirstMin){ dFirstMin = dFirst; iFirstMin = i2; endMin = (j2first<j2last);}
235 merge[nMerge] = i2; nMerge++;
239 for(Int_t i = 0; i<nMerge; i++){
240 Int_t iTrack = merge[i];
242 for(Int_t j = 0; j<ncl[iTrack]; j++){
243 if(arr[iTrack]->At(j)<0)
break;
251 if(dFirstMin>=0 || nMerge==1){
253 for(Int_t i = 0; i<4; i++) Xorig[i][0] = xStart[i1][i];
257 for(Int_t i = 0; i<4; i++) Xorig[i][0] = xStart[iFirstMin][i];
259 for(Int_t i = 0; i<4; i++) Xorig[i][0] = xEnd[iFirstMin][i];
262 Int_t color = 2+nTracks, fill = 3001+nTracks;
263 for(Int_t icl = 0; icl<nCl; icl++)
265 for(Int_t i = 0; i<2; i++) Xorig[i][0] = Xorig[i][0]-10*Xorig[2+i][0];
270 TArrow* arrow =
new TArrow();
271 arrow->SetLineColor(kGray+2);
272 arrow->SetLineWidth(4);
273 arrow->SetLineStyle(2);
274 arrow->SetFillColor(color);
276 arrow->DrawArrow(Xorig[1][0],Xorig[0][0],Xorig[1][0]+30*Xorig[3][0],Xorig[0][0]+30*Xorig[2][0],0.01);
281 std::vector<TMatrixD> output =
NextStep(Xorig,Corig,nTracks,clArray,0,0,plane,color,fill,1,0,kFALSE);
284 if(output.size()<5)
continue;
285 TMatrixD extra = output[4];
286 Int_t nCl = Int_t(extra[0][0]);
289 Double_t angle = extra[1][0]/nCl;
292 for(Int_t i = 0; i<8; i++){
295 Double_t dangle = extra[3*i+2][0]/(nCl-i);
296 Double_t dangleSq = extra[3*i+3][0]/(nCl-i);
297 if(dangleSq-dangle*dangle<1e-6) rms[i] = -1;
298 else rms[i] = TMath::Sqrt(dangleSq-dangle*dangle);
303 Double_t rmsAngle = rms[0];
304 Double_t rmsAngle2 = rms[1];
308 HarpoRecoKalmanTracks* tr =
new HarpoRecoKalmanTracks(nTracks,qTot,angle,rmsAngle,rmsAngle2,0,0,nCl,plane,rms[0],rms[1],rms[2],rms[3],rms[4],rms[5],rms[6],rms[7]);
312 for(Int_t i = 0; i<nMerge; i++){
313 Int_t iTrack = merge[i];
314 Int_t iV = vert[iTrack][0];
315 Int_t j = vert[iTrack][1];
326 fHist[plane]->GetXaxis()->SetRangeUser(0,
NADC);
327 fHist[plane]->GetYaxis()->SetRangeUser(0,
NCHAN);
337 for(Int_t i = 0; i<
NTRACK; i++){
340 fGraph[plane][i] =
new TGraph();
341 fGraph2[plane][i] =
new TGraph();
345 Int_t nCl = clArray->GetEntries();
347 Warning(
"InitPlane",
"Too many clusters %d",nCl);
353 gCl->SetMarkerStyle(7);
356 for(Int_t icl = 0; icl<nCl; icl++){
362 if(cluster->
GetPlane() != plane)
continue;
366 gCl->SetPoint(gCl->GetN(),cluster->
GetZ(),cluster->
GetX());
381 Int_t nCl = clArray->GetEntries();
382 for(Int_t icl = 0; icl<nCl; icl++){
384 if(cluster->
GetPlane() != plane)
continue;
395 std::vector<TMatrixD>
HarpoKalmanNew::NextStep(TMatrixD X, TMatrixD C, Int_t iTr, TClonesArray* clArray, TArrayI* arr, Int_t ncl, Int_t plane, Int_t color, Int_t fill, Int_t smooth, Int_t qold, Bool_t finder)
397 if(
gHarpoDebug>2) Info(
"NextStep",
"SMOOTH = %d, FINDER = %d",smooth,finder);
398 std::vector<TMatrixD> output;
405 Double_t norm = TMath::Sqrt(X[2][0]*X[2][0]+X[3][0]*X[3][0]);
410 TArrow* arrow =
new TArrow();
411 arrow->SetLineColor(kBlack);
412 arrow->SetFillColor(color);
414 arrow->DrawArrow(X[1][0],X[0][0],X[1][0]+5*X[3][0],X[0][0]+5*X[2][0],0.01);
428 if(arr) arr->AddAt(iclMin,ncl);
430 Double_t xMin = cluster->
GetX();
431 Double_t zMin = cluster->
GetZ();
432 Int_t qMin = cluster->
GetQ();
436 Double_t lambdaMin = (xMin-X[0][0])*X[2][0]+(zMin-X[1][0])*X[3][0];
440 Info(
"FindNextClosest",
"Add New Cluster");
443 for(
int i = 0;i<4;i++){
444 for(
int j =0;j<4;j++){
456 Double_t inc = resMin;
457 if(inc==0) inc = 0.000001;
458 Double_t v = X[2][0]*X[2][0] + X[3][0]*X[3][0];
459 for(
int i = 0;i<4;i++){
460 for(
int j =0;j<4;j++){
463 Q[i][j]=theta*theta*(1-X[i][0]*X[i][0]/v);
469 for(
int i = 0;i<2;i++){
470 for(
int j =0;j<2;j++){
492 TMatrixD Xfilter(4,1);
493 TMatrixD Cfilter(4,4);
494 TMatrixD Cprojinv(4,4);
507 Cinv=Cprojinv+Ht*G*H;
510 Xfilter=Cfilter*((Cprojinv*Xproj)+(Ht*G*M));
515 Info(
"FindNextClosest",
"Add cluster %d, (%d %p) %d",iclMin,iTr,arr,
fStartIndex[iTr]%10);
519 Info(
"FindNextClosest",
"Test %d %p %p %d %d %d %d %d", iTr, clArray, arr, ncl, plane, color, fill,smooth);
524 std::vector<TMatrixD> matrices =
525 NextStep(Xfilter, Cfilter, iTr, clArray, arr, ncl+1, plane, color, fill,smooth,qMin+qold,finder);
527 if(smooth==0)
fGraph2[plane][iTr]->SetPoint(ncl,Xfilter[1][0],Xfilter[0][0]);
529 cluster->
SetXfit(0,Xfilter[0][0]);
530 cluster->
SetZfit(0,Xfilter[1][0]);
534 TMatrixD Xsmooth(4,1);
535 TMatrixD Csmooth(4,4);
536 Int_t nExtra = 1+3*8;
537 TMatrixD extraold(nExtra,1);
538 if(matrices.size()<5){
543 for(Int_t i = 0; i<8; i++){
544 extraold[3*i+1][0] = -1000;
545 extraold[3*i+2][0] = 0;
546 extraold[3*i+3][0] = 0;
548 extraold[1][0] = TMath::ATan2(Xfilter[2][0],Xfilter[3][0]);
550 TMatrixD Cprojnew = matrices[0];
551 TMatrixD Xprojnew = matrices[1];
552 TMatrixD Csmoothold = matrices[2];
553 TMatrixD Xsmoothold = matrices[3];
554 extraold = matrices[4];
558 TMatrixD Cprojnewinv(4,4);
559 Cprojnewinv = Cprojnew;
560 Cprojnewinv.Invert();
561 A = Cfilter*Ft*Cprojnewinv;
565 Xsmooth = Xfilter + A*(Xsmoothold-Xprojnew);
566 Csmooth = Cfilter + A*(Csmoothold-Cprojnew)*At;
573 output.push_back(Cproj);
574 output.push_back(Xproj);
575 output.push_back(Csmooth);
576 output.push_back(Xsmooth);
593 cluster->
SetXfit(0,Xsmooth[0][0]);
594 cluster->
SetZfit(0,Xsmooth[1][0]);
596 fGraph[plane][iTr]->SetPoint(ncl,Xsmooth[1][0],Xsmooth[0][0]);
621 Double_t angleTmp = TMath::ATan2(Xsmooth[2][0], Xsmooth[3][0]);
622 TMatrixD extra(nExtra,1);
623 extra[0][0] = extraold[0][0]+1;
624 extra[1][0] = angleTmp;
625 for(Int_t i = 0; i<8; i++){
626 Double_t angleOld = extraold[3*i+1][0];
628 if(angleOld>-100) dangle = angleTmp - angleOld;
629 if(dangle>TMath::Pi()) dangle -= TMath::Pi();
630 if(dangle<-TMath::Pi()) dangle += TMath::Pi();
631 extra[3*i+2][0] = extraold[3*i+2][0] + dangle;
632 extra[3*i+3][0] = extraold[3][0] + dangle*dangle;
633 if(i>0) extra[3*i+1][0] = extra[3*i-2][0];
635 output.push_back(extra);
643 if(
gHarpoDebug>2) Info(
"FindNextClosest",
"FINDER = %d",finder);
645 Double_t fRangeMax = 15;
652 Double_t dMin = 100000, xMin = -10000, zMin = -10000, rangeMin = 0, lambdaMin = 10000;
656 Int_t nCl = clArray->GetEntries();
657 for(Int_t i = 0; i<nCl; i++){
659 if(
used[icl]==iTr)
continue;
661 if(cluster->
GetPlane() != plane)
continue;
664 Double_t x = cluster->
GetX();
665 Double_t z = cluster->
GetZ();
669 Double_t lambda = (x-X[0][0])*X[2][0]+(z-X[1][0])*X[3][0];
674 Double_t dist = TMath::Abs((x-X[0][0])*X[3][0]-(z-X[1][0])*X[2][0]);
677 Double_t d = lambda*lambda*dist;
680 Double_t range = deltaRes*res + deltaScat*theta*lambda;
681 if(range>fRangeMax) range = fRangeMax;
683 if(finder && TMath::Abs(dist)>range)
continue;
699 Double_t w1 = rangeMin;
700 if(finder) w1 *= 5./lambdaMin;
701 Float_t z[4] = {(Float_t) (X[1][0]+5*X[3][0]+w1*X[2][0]),
702 (Float_t) (X[1][0]+5*X[3][0]-w1*X[2][0]),
703 (Float_t) (X[1][0]+lambdaMin*X[3][0]-rangeMin*X[2][0]),
704 (Float_t) (X[1][0]+lambdaMin*X[3][0]+rangeMin*X[2][0])};
705 Float_t x[4] = {(Float_t) (X[0][0]+5*X[2][0]-w1*X[3][0]),
706 (Float_t) (X[0][0]+5*X[2][0]+w1*X[3][0]),
707 (Float_t) (X[0][0]+lambdaMin*X[2][0]+rangeMin*X[3][0]),
708 (Float_t) (X[0][0]+lambdaMin*X[2][0]-rangeMin*X[3][0])};
710 Info(
"FindNextClosest",
"%g %g %g %g %g %g",x[0],z[0],x[1],z[1],x[2],z[2]);
712 triangle =
new TPolyLine(4,z,x,
"FL");
713 triangle->SetLineColor(kBlack);
714 triangle->SetFillColor(color);
715 triangle->SetFillStyle(fill);
717 triangle->Draw(
"FL");
719 fHist[plane]->GetXaxis()->SetRangeUser(zMin-20,zMin+20);
720 fHist[plane]->GetYaxis()->SetRangeUser(xMin-20,xMin+20);
775 for(Int_t plane = 0; plane<2; plane++){
776 for(Int_t i = 0; i<
NTRACK; i++){
784 hNcl =
new TH1F(
"hNcl",
"hNcl",500,0,500);
786 const Int_t nbinsDist = 500;
787 Double_t xminDist = 1e-6;
788 Double_t xmaxDist = 1e5;
789 Double_t logxminDist = TMath::Log(xminDist);
790 Double_t logxmaxDist = TMath::Log(xmaxDist);
791 Double_t binwidthDist = (logxmaxDist-logxminDist)/nbinsDist;
792 Double_t xbinsDist[nbinsDist+1];
793 xbinsDist[0] = xminDist;
794 for (Int_t i=1;i<=nbinsDist;i++)
795 xbinsDist[i] = TMath::Exp(logxminDist+i*binwidthDist);
796 hChi2 =
new TH1F(
"hChi2",
"hChi2",nbinsDist,xbinsDist);
799 const Int_t nbinsTheta = 100;
800 Double_t xminTheta = 1e-5;
801 Double_t xmaxTheta = 2;
802 Double_t logxminTheta = TMath::Log(xminTheta);
803 Double_t logxmaxTheta = TMath::Log(xmaxTheta);
804 Double_t binwidthTheta = (logxmaxTheta-logxminTheta)/nbinsTheta;
805 Double_t xbinsTheta[nbinsTheta+1];
806 xbinsTheta[0] = xminTheta;
807 for (Int_t i=1;i<=nbinsTheta;i++)
808 xbinsTheta[i] = TMath::Exp(logxminTheta+i*binwidthTheta);
810 hDistTracks =
new TH1F(
"hDistTracks",
"",nbinsDist,xbinsDist);
811 hDistMinTracks =
new TH1F(
"hDistMinTracks",
"",nbinsDist,xbinsDist);
812 hThetaTracks =
new TH1F(
"hThetaTracks",
"",nbinsTheta,xbinsTheta);
814 hThetaTracksNtr =
new TH2F(
"hThetaTracksNtr",
"",nbinsDist,xbinsDist,nbinsTheta,xbinsTheta);
815 for(Int_t i = 0; i<10; i++)
816 hThetaDist[i] =
new TH2F(Form(
"hThetaDist%d",i),
"",nbinsDist,xbinsDist,nbinsTheta,xbinsTheta);
819 const Int_t nbinsQ = 100;
820 Double_t xminQ = 1e-3;
821 Double_t xmaxQ = 1e3;
822 Double_t logxminQ = TMath::Log(xminQ);
823 Double_t logxmaxQ = TMath::Log(xmaxQ);
824 Double_t binwidthQ = (logxmaxQ-logxminQ)/nbinsQ;
825 Double_t xbinsQ[nbinsQ+1];
827 for (Int_t i=1;i<=nbinsQ;i++)
828 xbinsQ[i] = TMath::Exp(logxminQ+i*binwidthQ);
829 fHistQQtestVsDist =
new TH2F(
"fHistQQtestVsDist",
"",nbinsQ,xbinsQ,nbinsDist,xbinsDist);
830 fHistQQmin =
new TH2F(
"fHistQQmin",
"",nbinsQ,xbinsQ,nbinsDist,xbinsDist);
857 for(Int_t i = 0; i<10; i++){
876 TCanvas* cTab = ecTab->GetCanvas();
879 Int_t nCl = clArray->GetEntries();
883 g[0]->SetMarkerStyle(7);
885 g[1]->SetMarkerStyle(7);
886 for(Int_t icl = 0; icl<nCl; icl++){
889 Double_t x = cluster->
GetX();
890 Double_t z = cluster->
GetZ();
891 g[plane]->SetPoint(g[plane]->GetN(),z,x);
894 for(Int_t plane = 0; plane<2; plane++){
896 if(g[plane]->GetN()>0) g[plane]->Draw(
"Psame");
897 for(Int_t i = 0; i<
NTRACK; i++){
898 if(!
fGraph[plane][i])
continue;
899 fGraph[plane][i]->SetMarkerStyle(24);
900 fGraph[plane][i]->SetMarkerColor(i+2);
901 fGraph[plane][i]->SetLineColor(i+2);
902 if(
fGraph[plane][i]->GetN()>0)
fGraph[plane][i]->Draw(
"LPsame");
903 fGraph2[plane][i]->SetMarkerStyle(6);
904 fGraph2[plane][i]->SetMarkerColor(i+2);
905 fGraph2[plane][i]->SetLineColor(i+2);
906 if(
fGraph2[plane][i]->GetN()>5)
fGraph2[plane][i]->Draw(
"LPsame");
void SetTr2Vertex(Int_t val)
TH1F * hNcl
Redefine empty default.
HarpoRecoEvent * GetRecoEvent()
Int_t FindClosestNeighbour(TMatrixD X, Int_t iTr, TClonesArray *clArray, Int_t plane, Int_t color, Int_t fill, Bool_t finder=kTRUE)
void SetTr1Vertex(Int_t val)
void AddIdClusterTrack(Int_t val)
Int_t GetNclCommon(TClonesArray *clArray, Int_t plane, Int_t iTr1, Int_t iTr2)
TGraph * fGraph2[2][NTRACK]
Double_t GetResolution(HarpoRecoClusters *cl)
Double_t GetThetaVertex()
Object containing the reconstruction information for one event (with array of HarpoRecoClusters Harpo...
void AddTracks(HarpoRecoTracks *val)
2D vertex object, containing position, angle and associated track numbers, and quality info ...
void NormaliseBins(TH1 *h)
TClonesArray * GetVertexArray()
HarpoRecoTracks object, Obtained with Kalman filter.
void print()
Ovreloaded medod whic do all job.
Cluster object, containing position, charge and quality information.
TFile * OpenHistFile(const char *ananame)
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
void Save(char *mode=NULL)
Int_t fStartIndex[NTRACK]
void DisplayAnalysis(TRootEmbeddedCanvas *ecTab, TGListBox *infobox)
void SetXfit(Int_t i, Double_t val)
std::vector< TMatrixD > NextStep(TMatrixD X, TMatrixD C, Int_t Ntr, TClonesArray *clArray, TArrayI *arr, Int_t ncl, Int_t plane, Int_t color, Int_t fill, Int_t smooth, Int_t q, Bool_t finder=kTRUE)
HarpoEventHeader * GetHeader()
const ULong_t gkNDetectors
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
void SetZfit(Int_t i, Double_t val)
TGraph * fGraph[2][NTRACK]
TClonesArray * GetClustersArray()
void SetTrackType(Int_t val)
Bool_t CheckIdClusterTrack(Int_t val)
Int_t InitPlane(TClonesArray *clArray, Int_t plane)