HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoVertexing.cxx
Go to the documentation of this file.
1 //
2 // File HarpoVertexing.cxx
3 //
11 #include "HarpoVertexing.h"
12 #include "HarpoConfig.h"
13 #include "HarpoDetSet.h"
14 #include "HarpoDebug.h"
15 #include "HarpoDccEvent.h"
16 #include "Pmm2Event.h"
17 #include "HarpoEvent.h"
18 #include "HarpoRecoEvent.h"
19 #include "HarpoSimEvent.h"
20 #include "MakeNiceHisto.h"
21 
22 #include "TFile.h"
23 #include "TStyle.h"
24 #include "TCanvas.h"
25 #include "TRootEmbeddedCanvas.h"
26 #include "TLatex.h"
27 #include "TGraph.h"
28 #include "TF1.h"
29 #include "TLine.h"
30 #include "TMath.h"
31 #include "TGLabel.h"
32 #include "TEllipse.h"
33 #include "TSpectrum.h"
34 #include "TLinearFitter.h"
35 #include "TPolyMarker.h"
36 #include "TSystem.h"
37 
38 #include "RVersion.h"
39 
40 #include <cstdlib>
41 #include <cstring>
42 #include <cassert>
43 #include <fstream>
44 #include <iostream>
45 
46 ClassImp(HarpoVertexing);
47 
48 
49 
50 // typedef struct vPoint_t {
51 // Double_t x;
52 // Double_t y;
53 // Double_t w;
54 // } vPoint_t;
55 
56 
57 
58 
59 
60 
62  {
63  unsigned int nd; // number of detectors
65 
66  assert(hdr != NULL);
67  hdr->print();
68 
69  for (nd = 0; nd < gkNDetectors; nd++) {
70  // if (fEvt->isdataExist(nd)) {
71  HarpoDccMap *plane = fEvt->GetDccMap(nd);
72  if (plane != NULL )plane->print();
73  }
74  }
75 
77 {
78  // Bool_t drawEvent = kFALSE;
79  nEvents++;
80  if(!fEvt->GetRecoEvent()) return;
81 
82 
83  for(Int_t i = 0; i<20; i++){
84  fHistProj2D[i]->Reset();
85  fHistProj2Draw[i]->Reset();
86  fHistMean[i]->Reset();
87  fHistMap[i]->Reset();
88  }
89 
90  // Find vertex candidates
91  FindVertexes();
92  //RefineVertexPosition();
93 
94  // Compute track directions associated to the vertex
96 
97 
98 
99 
100 }
101 
102 
104 {
105 
106  // Compute track directions associated to the vertices found by FindVertexes()
107  // Completes the HarpoRecoVertex objects in fEvt
108 
109  for(Int_t i = 0; i<2; i++){
110  for(Int_t j = 0; j<10; j++){
111  for(Int_t k = 0; k<3; k++){
112  fHist[i][j][k] = 0;
113  fHist2[i][j][k] = 0;
114  }
115  }
116  }
117 
118  TClonesArray* vArray = fEvt->GetRecoEvent()->GetVertexArray();
119  Int_t nV2 = vArray->GetEntries();
120  HarpoDccMap* m[2];
121  for(Int_t plane = 0; plane<2;plane++)
122  m[plane] = fEvt->GetDccMap(plane);
123 
124  // Loop over the vertex candidates found by FindVertexes()
125  for(Int_t iV = 0; iV<nV2; iV++){
126  HarpoRecoVertex* vertex = (HarpoRecoVertex*)vArray->At(iV);
127  Int_t plane = vertex->GetPlane();
128  Double_t xV = vertex->GetXvertex();
129  Double_t zV = vertex->GetZvertex();
130  // Double_t pxV = vertex->GetPxVertex();
131  // Double_t pzV = vertex->GetPzVertex();
132  // Double_t thV = vertex->GetThetaVertex();
133 
134  // Fill a 2D histogram in polar coordinates
135  TH2F* hProj2DV_1 = (TH2F*)fHistProj2D[iV]->Clone("hProj2D_1");
136  // Use only the data connex with the vertex candidate
137  GetConnex(Int_t(zV),Int_t(xV),3,3,m[plane],fHistMap[iV]);
138  for(Int_t i=0;i<NADC;i++){ //Time bins
139  for(Int_t j=0;j<NCHAN;j++){ // Channels
140  Double_t q = fHistMap[iV]->GetBinContent(i+1,j+1);
141  if(q<=0) continue;
142  Double_t xTmp = j - xV, zTmp = i - zV;
143  Double_t rho = TMath::Sqrt(xTmp*xTmp+zTmp*zTmp);
144  Double_t theta = TMath::ATan2(xTmp,zTmp);
145  hProj2DV_1->Fill(rho,theta,q);
146  }
147  }
148  // Correct the charge to account for the surface change
149  for(Int_t bin = 1; bin<=fNbins; bin++){
150  Int_t k = Int_t(0.5/TMath::Pi()*fNbinsTheta/hProj2DV_1->GetXaxis()->GetBinCenter(bin));
151  for(Int_t i = 0; i<fNbinsTheta; i++){
152  Double_t q = hProj2DV_1->GetBinContent(bin,i+1)/(2*k+1.);
153  if(q<=0) continue;
154  //q *= bin+2;
155  for(Int_t j = -k; j<=k; j++){
156  Int_t biny = i+1+j;
157  // Wrap around the circle
158  if(biny<1) biny = fNbinsTheta + biny;
159  if(biny>fNbinsTheta) biny = -fNbinsTheta + biny;
160  fHistProj2Draw[iV]->SetBinContent(bin,biny,fHistProj2Draw[iV]->GetBinContent(bin,biny)+q);
161  }
162  }
163  }
164  hProj2DV_1->Delete();
165  // Double_t thetaTmp[fNbinsTheta*fNbins];
166  // Double_t qTmp[fNbinsTheta*fNbins];
167  Int_t nTmp = 0;
168  // In the polar histogram fHistProj2Draw[iV]
169  // Remove the bin which are not connected in a straight line to the vertex
170  for(Int_t i = 0; i<fNbinsTheta; i++){ // For each theta bin
171  Int_t nZero = 0;
172  Double_t qTot = 0;
173  for(Int_t bin = 2; bin<=fNbins; bin++){
174  Double_t q = fHistProj2Draw[iV]->GetBinContent(bin,i+1);
175  if(nZero>1){ // If at least 2 consecutive rho bins are empty
176  // Erase the rest of the theta bin
177  fHistProj2D[iV]->SetBinContent(bin,i+1,0);
178  continue;
179  }else{
180  fHistProj2D[iV]->SetBinContent(bin,i+1,q);
181  qTot+=q;
182  // thetaTmp[nTmp] = fHistProj2D[iV]->GetYaxis()->GetBinCenter(i+1);
183  // qTmp[nTmp] = q;
184  nTmp++;
185  }
186  // Count number of consecutive empty rho bin
187  if(q<=10) nZero++;
188  else nZero = 0;
189  }
190  // Fill projection on the theta axis
191  fHistMean[iV]->SetBinContent(fNbinsTheta/2+i+1,qTot);
192  // Wrap around the circle
193  if(i<fNbinsTheta/2)
194  fHistMean[iV]->SetBinContent( fNbinsTheta+fNbinsTheta/2+i+1,qTot);
195  else
196  fHistMean[iV]->SetBinContent(-fNbinsTheta+fNbinsTheta/2+i+1,qTot);
197 
198  }
199  // Double_t mu[4000], sigma[4000];
200  // Int_t nPeak = 0;
201 #if 1
202  // Look for peaks in the theta projection fHistMean[iV] (extended to -2pi,2pi)
203  TSpectrum *s = new TSpectrum(8);
204  Int_t nfound = s->Search(fHistMean[iV],2,"",0.01);
205  if(gHarpoDebug>1 || fDisplay)
206  Info("process","%d peaks found",nfound);
207 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
208  Double_t *xpeaks = s->GetPositionX();
209  Double_t *ypeaks = s->GetPositionY();
210 #else
211  Float_t *xpeaks = s->GetPositionX();
212  Float_t *ypeaks = s->GetPositionY();
213 #endif
214  Double_t peaks[nfound];
215  Int_t npeaks = 0;
216  Int_t* index = new Int_t[nfound];
217  // Select the highest peaks
218  TMath::Sort(nfound,ypeaks,index,kTRUE);
219  for(Int_t i = 0; i<nfound; i++){
220  // reject peaks outside (-pi,pi)
221  if(xpeaks[index[i]]<-TMath::Pi()) continue;
222  if(xpeaks[index[i]]>TMath::Pi()) continue;
223  peaks[npeaks] = xpeaks[index[i]];
224  if(gHarpoDebug>1)
225  Info("process","%d %g",npeaks,peaks[npeaks]);
226  npeaks++;
227  }
228  delete index;
229  s->Delete();
230  nfound = npeaks;
231  for(Int_t i = 0; i<nfound; i++){
232  for(Int_t j = i+1; j<nfound; j++){
233  if(TMath::Abs(peaks[i]-peaks[j])>2 &&
234  TMath::Abs(peaks[i]-peaks[j]+TMath::Pi()*2)>2 &&
235  TMath::Abs(peaks[i]-peaks[j]-TMath::Pi()*2)>2){
236  peaks[j] = -1000;
237  }
238  if(i==0) continue;
239  // merge extra peaks if they are close together
240  if(TMath::Abs(peaks[i]-peaks[j])<0.05)
241  peaks[i] = (peaks[i]+peaks[j])/2.;
242  if(TMath::Abs(peaks[i]-peaks[j]+TMath::Pi()*2)<0.05)
243  peaks[i] = (peaks[i]+peaks[j])/2.+TMath::Pi();
244  if(TMath::Abs(peaks[i]-peaks[j]-TMath::Pi()*2)<0.05)
245  peaks[i] = (peaks[i]+peaks[j])/2.+TMath::Pi();
246  }
247  }
248  npeaks = 0;
249  for(Int_t i = 0; i<nfound; i++){
250  if(peaks[i]<-10) continue;
251  peaks[npeaks] = peaks[i];
252  npeaks++;
253  }
254  // Keep only the two highest peaks, inside -pi,pi
255  if(npeaks>2) npeaks = 2;
256 #else
257  // Failed attempt to make a better peak search
258  // TArrayD* arr = GetPeaks(nTmp,thetaTmp,qTmp,plane,iV);
259  TArrayD* arr = GetPeaks2(fHistMean[iV]);
260  Int_t npeaks = 0;
261  Double_t peaks[20], ypeaks[20];
262  for(Int_t i = 0; i<10; i++){
263  if(arr->At(3*i) == -1000) break;
264  npeaks++;
265  peaks[i] = arr->At(3*i);
266  ypeaks[i] = arr->At(3*i+2)/10;
267  }
268  TPolyMarker * pm =
269  (TPolyMarker*)fHistMean[iV]->GetListOfFunctions()->FindObject("TPolyMarker");
270  if (pm) {
271  fHistMean[iV]->GetListOfFunctions()->Remove(pm);
272  delete pm;
273  }
274  pm = new TPolyMarker(npeaks, peaks, ypeaks);
275  fHistMean[iV]->GetListOfFunctions()->Add(pm);
276  pm->SetMarkerStyle(23);
277  pm->SetMarkerColor(kRed);
278  pm->SetMarkerSize(1.3);
279  // if(npeaks>2) npeaks = 2;
280 #endif
281  if(gHarpoDebug>1 || fDisplay)
282  Info("process","%d peaks confirmed",npeaks);
283 
284 
285  vertex->SetChi2Vertex(npeaks);
286 
287  if(npeaks==1){ // Single track
288  vertex->SetPxVertex(TMath::Sin(peaks[0]));
289  vertex->SetPzVertex(TMath::Cos(peaks[0]));
290  vertex->SetThetaVertex(0);
291  }
292  if(npeaks==2){ // Pair vertex
293  vertex->SetPxVertex(TMath::Sin(0.5*(peaks[0]+peaks[1])));
294  vertex->SetPzVertex(TMath::Cos(0.5*(peaks[0]+peaks[1])));
295  Double_t theta = TMath::Abs(peaks[0]-peaks[1]);
296  if(theta>2*TMath::Pi()) theta -= 2*TMath::Pi();
297  if(theta>TMath::Pi()) theta = 2*TMath::Pi() - theta;
298  vertex->SetThetaVertex(theta);
299  }
300  }
301  return;
302 
303 }
304 
305 
307 {
308 
309  TClonesArray* vArray = fEvt->GetRecoEvent()->GetVertexArray();
310  Int_t nV2 = vArray->GetEntries();
311  HarpoDccMap* m[2];
312  for(Int_t plane = 0; plane<2;plane++)
313  m[plane] = fEvt->GetDccMap(plane);
314 
315  for(Int_t iV = 0; iV<nV2; iV++){
316  HarpoRecoVertex* vertex = (HarpoRecoVertex*)vArray->At(iV);
317  Int_t plane = vertex->GetPlane();
318  Double_t xV = vertex->GetXvertex();
319  Double_t zV = vertex->GetZvertex();
320  // Double_t pxV = vertex->GetPxVertex();
321  // Double_t pzV = vertex->GetPzVertex();
322  // Double_t thV = vertex->GetThetaVertex();
323 
324  Double_t meanX = 0, meanZ = 0, qTot = 0;
325  for(Int_t ch = Int_t(xV - fRadiusX); ch<Int_t(xV + fRadiusX); ch++){
326  for(Int_t tb = Int_t(zV - fRadiusZ); tb<Int_t(zV + fRadiusZ); tb++){
327  if(ch<0 || ch>=NCHAN || tb<0 || tb>=NADC) continue;
328  Double_t q = m[plane]->GetData(ch,tb);
329  if(q<=0) continue;
330  meanX += ch*q;
331  meanZ += tb*q;
332  qTot += q;
333  }
334  }
335  if(qTot<=0) continue;
336 
337  vertex->SetXvertex(meanX/qTot);
338  vertex->SetZvertex(meanZ/qTot);
339 
340  }
341 
342 }
343 
344 
345 
346 
347 
349 {
350  // Find vertex candidates
351  // Reconstructed data (clusters, tracks, matched tracks)
352  HarpoRecoEvent* reco = fEvt->GetRecoEvent();
353 
354 #if 1
355  // Clusters in the event (both X and Y directions)
356  TClonesArray* clArray = reco->GetClustersArray();
357  Int_t nCl = clArray->GetEntries();
358 
359  Double_t x[2][nCl], z[2][nCl], px[2][nCl], pz[2][nCl], theta[2][nCl];
360  Int_t nV[2];
361  nV[0] = 0;
362  nV[1] = 0;
363  for(Int_t i = 0; i<nCl; i++){ // Loop over clusters
364  HarpoRecoClusters* cl = (HarpoRecoClusters*)clArray->At(i);
365  Double_t q = cl->GetQ();
366  if(q<fQmin) continue;
367  Int_t plane = cl->GetPlane();
368  Double_t xTmp = cl->GetX();
369  Double_t zTmp = cl->GetZ();
370  Double_t phi0, phi1;
371  Double_t frac = GetFraction(plane,xTmp,zTmp,phi0,phi1);
372  if(frac>fMinFrac) continue; // reject opening angle too large
373  px[plane][nV[plane]] = -TMath::Cos(0.5*(phi0 + phi1));
374  pz[plane][nV[plane]] = -TMath::Sin(0.5*(phi0 + phi1));
375  theta[plane][nV[plane]] = TMath::Abs(2*TMath::Pi() - phi1 + phi0);
376  if(theta[plane][nV[plane]] > +2*TMath::Pi())
377  theta[plane][nV[plane]] -= 2*TMath::Pi();
378  x[plane][nV[plane]] = xTmp;
379  z[plane][nV[plane]] = zTmp;
380  if(gHarpoDebug>1)
381  Info("FindVertex","%d %d %g %g %g %g %g",plane,nV[plane],zTmp, xTmp, pz[plane][nV[plane]], px[plane][nV[plane]], theta[plane][nV[plane]]);
382  nV[plane]++;
383  }
384 
385  for(Int_t plane = 0; plane<2; plane++){ // Remove multiple occurences of same vertex
386  Int_t used[nV[plane]];
387  for(Int_t i = 0; i<nV[plane]; i++)
388  used[i] = 0;
389  for(Int_t i = 0; i<nV[plane]; i++){
390  if(used[i]) continue;
391  used[i] = 1;
392  Double_t chi2 = -10;
393  Int_t jmin = i;
394  // Double_t thetaMin = 10;
395  for(Int_t j = 0; j<nV[plane]; j++){
396  if(used[j]) continue;
397  if(TMath::Abs(x[plane][i]-x[plane][j])<fRadiusX && TMath::Abs(z[plane][i]-z[plane][j])<fRadiusZ){
398  used[j] = 1;
399  if(TMath::Abs(theta[plane][j])<TMath::Abs(theta[plane][i])){
400  jmin = j;
401  }
402  }
403  }
404  HarpoRecoVertex* vertex = new HarpoRecoVertex(plane,z[plane][jmin], x[plane][jmin], pz[plane][jmin], px[plane][jmin], theta[plane][jmin], chi2, -1, -1);
405  reco->AddVertex(vertex);
406  vertex->Delete();
407  }
408  }
409 #else
410 
411 
412  HarpoRecoVertex* vertexX = new HarpoRecoVertex(0,reco->GetTstart()+8, reco->GetXstart(), 1, 0, 0, 0, -1, -1);
413  reco->AddVertex(vertexX);
414  HarpoRecoVertex* vertexY = new HarpoRecoVertex(1,reco->GetTstart()+8, reco->GetYstart(), 1, 0, 0, 0, -1, -1);
415  reco->AddVertex(vertexY);
416 
417 
418 #endif
419 
420 
421 }
422 
423 
424 
426 {
427  // Unused
428 
429  // Int_t plane = vertex->GetPlane();
430  Double_t xV = vertex->GetXvertex();
431  Double_t zV = vertex->GetZvertex();
432  Double_t pxV = vertex->GetPxVertex();
433  Double_t pzV = vertex->GetPzVertex();
434  // Double_t thV = vertex->GetThetaVertex();
435 
436  TGraph* g = GetGraph(h,3,xV,zV,pxV,pzV);
437 
438  TArrayD* par = FitGraph(g,2);
439  delete par;
440 }
441 
442 
443 TGraph* HarpoVertexing::GetGraph(TH2F* h, Int_t n, Double_t x0, Double_t z0, Double_t px, Double_t pz)
444 {
445  // Unused
446 
447  Int_t nbinsx = h->GetYaxis()->GetNbins();
448  Int_t nbinsz = h->GetXaxis()->GetNbins();
449 
450  TGraph* g = new TGraph();
451 
452  Int_t nP = 0;
453  for(Int_t i = 0; i<nbinsz; i+=n){
454  for(Int_t j = 0; j<nbinsx; j+=n){
455  Double_t x = 0, z = 0, q = 0;
456  for(Int_t i2 = 0; i2<n; i2++){
457  for(Int_t j2 = 0; j2<n; j2++){
458  Double_t val = h->GetBinContent(i+i2+1,j+j2+1);
459  z += (i+i2)*val;
460  x += (j+j2)*val;
461  q += val;
462  }
463  }
464  if(q<=0) continue;
465  x /= q;
466  z /= q;
467 
468  Double_t dx = (x-x0)/fRadiusX;
469  Double_t dz = (z-z0)/fRadiusZ;
470  if(dx*dx + dz*dz<0.5) continue;
471 
472  // g->SetPoint(nP,(x-x0)*px + (z-z0)*pz,-(z-z0)*px+(x-x0)*pz,q);
473  g->SetPoint(nP,(x-x0)*px + (z-z0)*pz,-(z-z0)*px+(x-x0)*pz);
474  nP++;
475  }
476  }
477 
478  return g;
479 }
480 
481 
482 TArrayD* HarpoVertexing::FitGraph(TGraph* g, const Int_t nFit)
483 {
484  // Unused
485 
486  Int_t nP = g->GetN();
487  Double_t* x = g->GetX();
488  Double_t* y = g->GetY();
489  // Double_t* q = g->GetZ();
490 
491  // Double_t w[nFit][nP];
492  Double_t p[nFit];
493  for(Int_t j = 0; j<nFit; j++)
494  p[j] = 1./nFit;
495  TArrayD* par = new TArrayD(2*nFit);
496  if(nFit == 1){
497  par->AddAt(0,0);
498  par->AddAt(0,1);
499  }else{
500  for(Int_t j = 0; j<nFit; j++){
501  par->AddAt(0,2*j);
502  par->AddAt(-1 + 2*j*1./(nFit-1),2*j+1);
503  }
504  }
505 
506  for(Int_t k = 0; k<5; k++){
507 
508  Double_t w[nFit][nP];
509  for(Int_t i = 0; i<nP; i++){
510  Double_t norm = 0;
511  for(Int_t j = 0; j<nFit; j++){
512  Double_t d = y[i] - x[i]*par->At(2*j+1) - par->At(2*j);
513  w[j][i] = p[j]*TMath::Gaus(d,0,1);
514  norm += w[j][i];
515  }
516  for(Int_t j = 0; j<nFit; j++)
517  w[j][i] /= norm;
518  }
519 
520  for(Int_t j=0; j<nFit; j++){
521 
522  Double_t xTmp[nP], yTmp[nP];
523  Int_t nTmp = 0;
524  for(Int_t i = 0; i<nP; i++){
525  Bool_t test = kTRUE;
526  for(Int_t J = 0; J<nFit; J++){
527  if(w[J][i]>w[j][i]){
528  test = kFALSE;
529  break;
530  }
531  }
532  if(!test) continue;
533  xTmp[nTmp] = x[i];
534  yTmp[nTmp] = y[i];
535  nTmp++;
536  }
537 
538  if(nTmp<2){
539  Info("FitGraph","Too many fits %d",nFit);
540  return 0;
541  }
542 
543  p[j] = nTmp*1./nP;
544 
545  TLinearFitter* fFitCh = new TLinearFitter(1,"pol1","D");
546  fFitCh->AssignData(nTmp, 1, xTmp, yTmp);
547  fFitCh->Eval();
548 
549  par->AddAt(fFitCh->GetParameter(0),2*j);
550  par->AddAt(fFitCh->GetParameter(1),2*j+1);
551 
552  Info("FitGraph","Iteration %d, Fit %d, chi2 = %g",k,j,fFitCh->GetChisquare());
553 
554  fFitCh->Delete();
555  }
556 
557  }
558 
559  return par;
560 }
561 
562 
563 TArrayD* HarpoVertexing::GetPeaks2(TH1F* h)
564 {
565  // Unused
566 
567  TArrayD* arr = new TArrayD(30);
568  for(Int_t k = 0; k<30; k++)
569  arr->AddAt(-1000,k);
570  Int_t nbins = h->GetXaxis()->GetNbins();
571  Int_t up = 0;
572  Double_t noise = 1000;
573  Double_t th = 0, q = 0, sig = 0, qold = 0;
574  Int_t nCl = 0;
575  Int_t istart = 1;
576  for(Int_t i = 1; i<=nbins; i++){
577  Double_t val = h->GetBinContent(i);
578  if(val<noise){
579  istart = i;
580  break;
581  }
582  }
583  Info("GetPeaks2","istart = %d",istart);
584 
585  for(Int_t i = istart; i<=nbins+istart; i++){
586  Double_t val, x;
587  if(i<=nbins){
588  val = h->GetBinContent(i);
589  x = h->GetXaxis()->GetBinCenter(i);
590  }else{
591  val = h->GetBinContent(i-nbins);
592  x = h->GetXaxis()->GetBinCenter(i-nbins);
593  }
594  if(up == 0 && val<noise) continue;
595  if((up == 2 && val>qold+noise) || val<100){ // end of cluster
596  if(q>0001){
597  // if(gHarpoDebug>1 || fDisplay)
598  Info("GetPeaks2","End cluster %g: mu = %g, sig = %g, q = %g, qold = %g",x,th/q,TMath::Sqrt(sig/q-th/q*th/q),q,qold);
599  arr->AddAt(th/q,3*nCl);
600  arr->AddAt(TMath::Sqrt(sig/q-th/q*th/q),3*nCl+1);
601  arr->AddAt(q,3*nCl+2);
602  nCl++;
603  }
604  th = 0; q = 0; sig = 0;
605  }
606  if(val>qold+noise){
607  if(up == 0) Info("GetPeaks2","Start cluster %g (%g %g)",x,val, qold);
608  up = 1;
609  }
610  if(val<qold-noise){ // peak
611  if(up == 1) Info("GetPeaks2","Peak %g (%g %g)",x,val, qold);
612  up = 2;
613  }
614  th += x*val;
615  sig += x*x*val;
616  q += val;
617  if(val<noise){
618  th = 0; q = 0; sig = 0; up = 0;
619  }
620  if(TMath::Abs(val-qold)>noise)
621  qold = val;
622  }
623 
624  return arr;
625 }
626 
627 
628 TArrayD* HarpoVertexing::GetPeaks(Int_t n, Double_t *x, Double_t *w, Int_t plane, Int_t v)
629 {
630  // Unused
631  Int_t nLeftOld = 0;
632  TArrayD* arr = new TArrayD(30);
633  for(Int_t k = 0; k<30; k++)
634  arr->AddAt(-1000,k);
635  Int_t i = 0;
636  Int_t loop = 0;
637  while(1){
638  Double_t mu, sig;
639  GetPeak(n,x,w,mu,sig,plane,v);
640  Int_t nLeft = 0;
641  Double_t q = 0;
642  Double_t qTot = 0, qTot2 = 0;
643  for(Int_t j = 0; j<n; j++){
644  qTot += w[j];
645  Double_t dist = TMath::Abs(x[j]-mu);
646  if(TMath::Abs(x[j]-mu-2*TMath::Pi())<dist) dist = TMath::Abs(x[j]-mu-2*TMath::Pi());
647  if(TMath::Abs(x[j]-mu+2*TMath::Pi())<dist) dist = TMath::Abs(x[j]-mu+2*TMath::Pi());
648  Double_t frac = dist < 3*sig;
649  if(frac<0.01) frac = 0;
650  //else Info("","frac = %g",frac);
651  q += w[j]*frac;
652  w[j] *= 1.-frac;
653  qTot2 += w[j];
654  if(w[j]<10) nLeft++;
655  }
656  if(gHarpoDebug>1 || fDisplay){
657  Info("GetPeaks","loop %d, qTot = %g, qTot2 = %g, q = %g",loop,qTot,qTot2, q);
658  Info("GetPeaks","mu = %g, sig = %g, q = %g, nLeft = %d",mu,sig,q,nLeft);
659  }
660  if(sig<0.2 && q > 1000){
661  arr->AddAt(mu,i);
662  i++;
663  arr->AddAt(sig,i);
664  i++;
665  arr->AddAt(q,i);
666  i++;
667  if(i>=20) break;
668  }
669  if(nLeft<10) break;
670  if(nLeft==nLeftOld) break;
671  nLeftOld = nLeft;
672  loop++;
673  }
674 
675  return arr;
676 
677 }
678 
679 void HarpoVertexing::GetPeak(Int_t nElem, Double_t *x, Double_t *w, Double_t &muOut, Double_t &sigOut, Int_t plane, Int_t v)
680 {
681  // Unused
682 
683  muOut = -100;
684  sigOut = -100;
685 
686  Double_t xCenter = 0.;
687  Double_t xWidth = 6.5;
688  Int_t fNbinr = 100;
689  Int_t nloop = 0, maxLoops = 5;
690  while(nloop < maxLoops){
691  if(gHarpoDebug>1)
692  Info("FindPairNew","loop == %d",nloop);
693 
694  TH1F* h = new TH1F("h","",fNbinr,xCenter - xWidth, xCenter + xWidth);
695  TH1F* hB = new TH1F("hB","",fNbinr,xCenter - xWidth, xCenter + xWidth);
696  TH1F* hW = new TH1F("hW","",fNbinr,xCenter - xWidth, xCenter + xWidth);
697  TH1F* h1 = new TH1F("h1","",fNbinr,xCenter - xWidth, xCenter + xWidth);
698  TH1F* h2 = new TH1F("h2","",fNbinr,xCenter - xWidth, xCenter + xWidth);
699  TH1F* h3 = new TH1F("h3","",fNbinr,xCenter - xWidth, xCenter + xWidth);
700  TH1F* h4 = new TH1F("h4","",fNbinr,xCenter - xWidth, xCenter + xWidth);
701 
702  for(Int_t i=0;i<nElem;i++){
703  if(x[i]<-10) continue;
704  if(w[i]<10) continue;
705  Double_t theta = x[i];
706  Double_t weight= w[i];
707  h->Fill(theta);
708  hW->Fill(theta, weight);
709  h1->Fill(theta, theta*weight);
710  h2->Fill(theta, theta*theta*weight);
711  h3->Fill(theta, theta*theta*theta*weight);
712  h4->Fill(theta, theta*theta*theta*theta*weight);
713 
714  if(theta>0) theta = theta - 2*TMath::Pi();
715  else theta = theta + 2*TMath::Pi();
716  h->Fill(theta);
717  hW->Fill(theta, weight);
718  h1->Fill(theta, theta*weight);
719  h2->Fill(theta, theta*theta*weight);
720  h3->Fill(theta, theta*theta*theta*weight);
721  h4->Fill(theta, theta*theta*theta*theta*weight);
722  }
723 
724  if(h->GetEntries()<3) {
725  h->Delete();
726  hB->Delete();
727  hW->Delete();
728  h1->Delete();
729  h2->Delete();
730  h3->Delete();
731  h4->Delete();
732  break;
733  }
734  // Double_t sRmax = 0, sTmax = 0;
735 
736  if(nloop<3){
737  // Info("","%d_%d_%d",plane,v,nloop);
738  fHist[plane][v][nloop] = (TH1F*)h->Clone(Form("h%d_%d_%d",plane,v,nloop));
739  }
740  // Calculate Mean and RMS in histograms
741  for (Int_t ir=1;ir<=fNbinr;ir++){
742  Double_t n = h->GetBinContent(ir);
743  Double_t weight = hW->GetBinContent(ir);
744  if(n<=0) continue;
745  if(weight<=0) continue;
746  Double_t m1Tmp = h1->GetBinContent(ir)/weight;
747  Double_t m2Tmp = h2->GetBinContent(ir)/weight;
748  Double_t m3Tmp = h3->GetBinContent(ir)/weight;
749  Double_t m4Tmp = h4->GetBinContent(ir)/weight;
750  m4Tmp = m4Tmp - 4*m1Tmp*m3Tmp + 6*m1Tmp*m1Tmp*m2Tmp - 3*m1Tmp*m1Tmp*m1Tmp*m1Tmp;
751  m2Tmp = m2Tmp - m1Tmp*m1Tmp;
752  // Double_t var4 = 1./n*(m4Tmp - (n-3)*m2Tmp*m2Tmp/(n-1));
753  //Info("GetPeak","%d %g %g %g (%d)",ir,n,m1Tmp,m2Tmp,nElem);
754  // if(m2Tmp>0)
755  // hB->SetBinContent(ir,n*h->GetXaxis()->GetBinWidth(1)/m2Tmp);
756  // else
757  hB->SetBinContent(ir,n);
758 
759  }
760 
761 
762  if(nloop<3){
763  fHist2[plane][v][nloop] = (TH1F*)h->Clone(Form("hB%d_%d_%d",plane,v,nloop));
764  }
765 
766  hB->GetXaxis()->SetRangeUser(-TMath::Pi(),TMath::Pi());
767  Int_t imax = hB->GetMaximumBin();
768  Double_t max = hB->GetXaxis()->GetBinLowEdge(imax);
769 
770 
771  Double_t muPeak = h1->GetBinContent(imax)/hW->GetBinContent(imax);
772  Double_t sigmaPeak = TMath::Sqrt(h2->GetBinContent(imax)/hW->GetBinContent(imax) - muPeak*muPeak);
773  //Info("GetPeak","%d imax = %d, thmax = %g, max=%g, mu = %g, sigma = %g, w = %g",nloop,imax,max,h->GetBinContent(imax),muPeak,sigmaPeak,h->GetXaxis()->GetBinWidth(1));
774 
775 
776  Double_t fSigmaMaxRebin = 0.25, fCutoffHough = 6, kfFacHough = 3;
777  Int_t fMinPairs = 3;
778  if(sigmaPeak<fSigmaMaxRebin*h->GetXaxis()->GetBinWidth(1) && nloop < maxLoops - 1 && h->GetBinContent(imax)>fMinPairs){
779  xCenter = max;
780  xWidth /= kfFacHough;
781  nloop++;
782  h->Delete();
783  hB->Delete();
784  hW->Delete();
785  h1->Delete();
786  h2->Delete();
787  h3->Delete();
788  h4->Delete();
789  continue;
790  }
791 
792  Int_t ioMax = h->GetXaxis()->GetNbins()/2;
793  Double_t rapr0 = 0;
794  for(Int_t io=1;io<=ioMax;io++){
795  Double_t n = hW->Integral(imax-io,imax+io);
796  Double_t mu=h1->Integral(imax-io,imax+io)/n;
797  Double_t sig=h2->Integral(imax-io,imax+io)/n - mu*mu;
798 
799  if(sig>0) sig = TMath::Sqrt(sig);
800  else sig = 0;
801  //Info("GetPeak","n = %g, mu = %g, sigma = %g",n,mu,sig);
802 
803  Double_t rapr=0;
804  if(sig>0) rapr = (io) * h->GetXaxis()->GetBinWidth(1) / sig;
805  //Info("GetPeak","%g = %d * %g / %g",rapr,io-1,h->GetXaxis()->GetBinWidth(1),sig);
806 
807  if(io==ioMax || (rapr>fCutoffHough && rapr0<fCutoffHough) ){
808  muOut = mu;
809  if(muOut>TMath::Pi()) muOut -= 2*TMath::Pi();
810  if(muOut<-TMath::Pi()) muOut += 2*TMath::Pi();
811  sigOut = sig;
812  h->Delete();
813  hB->Delete();
814  hW->Delete();
815  h1->Delete();
816  h2->Delete();
817  h3->Delete();
818  h4->Delete();
819  return;
820  }
821  rapr0 = rapr;
822  }
823  h->Delete();
824  hB->Delete();
825  hW->Delete();
826  h1->Delete();
827  h2->Delete();
828  h3->Delete();
829  h4->Delete();
830  }
831 }
832 
833 Double_t HarpoVertexing::GetFraction(Int_t ndet, Double_t x, Double_t z, Double_t &phi0, Double_t &phi1)
834 {
835 
836  // Look for the longest section of an ellipse that does not encounter a region with signal
837  // (x,z) is the centre of the ellipse, (fRadiusX,fRadiusZ) their radius
838  //
839 
840  HarpoDccMap* m = fEvt->GetDccMap(ndet);
841  Int_t n = 0;
842  Int_t l = 0, start = 1000; // start is initialised at 1000 to avoid problems when there is no signal at all along the ellipse
843  Bool_t empty = kFALSE;
844  Double_t phiStart = 0;
845  phi0 = -1; phi1 = -2;
846  for(Int_t i=0;i<1000;i++){
847  // Loop over points along the ellipse (twice around)
848  Double_t phi = i*4*TMath::Pi()/1000;
849  Double_t xTmp = x + fRadiusX*TMath::Cos(phi);
850  Double_t zTmp = z + fRadiusZ*TMath::Sin(phi);
851  // corresponding pixel
852  Int_t channel = Int_t(xTmp);
853  Int_t timebin = Int_t(zTmp);
854  if(channel<0 || channel>=NCHAN) continue;
855  if(timebin<0 || timebin>=NADC) continue;
856  Int_t q = m->GetData(channel,timebin);
857  // Add the neighbouring positive signals
858  if(channel>0) q+= TMath::Max(m->GetData(channel-1,timebin),0.);
859  if(channel<NCHAN-1) q+= TMath::Max(m->GetData(channel+1,timebin),0.);
860  if(timebin>0) q+= TMath::Max(m->GetData(channel,timebin-1),0.);
861  if(timebin<NADC-1) q+= TMath::Max(m->GetData(channel,timebin+1),0.);
862  if(q>0){
863  n++;
864  empty = kFALSE;
865  }else{
866  if(!empty){
867  phiStart = phi;
868  start = i;
869  }
870  if(i-start>l){
871  l = i-start;
872  phi0 = phiStart;
873  phi1 = phi;
874  }
875  empty = kTRUE;
876  }
877  }
878 
879  // The full length of the circle is 1000/2 (we go twice around)
880  // l*2./1000 is the longest fraction that does not meet any signal
881  // We return the converse, corresponding to an approximate bend of the track in this region
882  return 1 - l*2./1000;
883 }
884 
885 
886 
887 void HarpoVertexing::GetConnex(Int_t i, Int_t j, Int_t n, Int_t n0, HarpoDccMap* m, TH2F* h)
888 {
889 
890  // Create a 2D histogram containing the connex region connected to bin i,j
891  // Recursive function
892 
893  if(i<0 || j<0 || i>=NADC || j>=NCHAN) return;
894  if(h->GetBinContent(i+1,j+1)>0) return;
895 
896  Double_t q = m->GetData(j,i);
897  if(q==-2000){
898  q = 1;
899  }
900  if(q<=0){
901  // q=0;
902  if(n>0){
903  //Info("GetConnex","Gap %d %d %d %g",n,i,j,q);
904  n--;
905  q = 1;
906  }
907  else return;
908  }else n = n0;
909 
910  h->SetBinContent(i+1,j+1,q);
911  GetConnex(i-1,j ,n,n0,m,h);
912  GetConnex(i+1,j ,n,n0,m,h);
913  GetConnex(i ,j-1,n,n0,m,h);
914  GetConnex(i ,j+1,n,n0,m,h);
915 
916  return;
917 }
918 
919 
920 void HarpoVertexing::DisplayAnalysis(TRootEmbeddedCanvas* ecTab, TGListBox* /* infobox */)
921 {
922 
923  TCanvas* c = ecTab->GetCanvas();
924  c->GetPad(1)->Delete();
925  c->GetPad(2)->Delete();
926  c->Divide(2);
927 
928 
929 
930  TClonesArray* vArray = fEvt->GetRecoEvent()->GetVertexArray();
931  Int_t nV = vArray->GetEntries();
932  HarpoDccMap* m[2];
933  for(Int_t plane = 0; plane<2;plane++)
934  m[plane] = fEvt->GetDccMap(plane);
935 
936  Int_t iV[2][10];
937  Int_t nVp[2];
938  nVp[0] = 0;
939  nVp[1] = 0;
940  // TGraphErrors* gProjV[2][nV];
941  TH1F* hProjV[2][nV];
942  TH2F* hProj2DV[2][nV];
943  TH2F* hMap2DV[2][nV];
944  TH1F* hMeanV[2][nV];
945  TH1F* hMean2V[2][nV];
946  TH1F* hMean3V[2][nV];
947  TH1F* hMean4V[2][nV];
948  // TH1D* hProf[2][nV];
949  // Int_t nbins = 200;//200;
950  // Double_t xMin = -20, xMax = 180;
951  Double_t xMin = 0, xMax = 400;
952  for(Int_t i = 0; i<nV; i++){
953  HarpoRecoVertex* vertex = (HarpoRecoVertex*)vArray->At(i);
954  Int_t plane = vertex->GetPlane();
955  Double_t xV = vertex->GetXvertex();
956  Double_t zV = vertex->GetZvertex();
957  Double_t pxV = vertex->GetPxVertex();
958  Double_t pzV = vertex->GetPzVertex();
959  // Double_t thV = vertex->GetThetaVertex();
960 
961  iV[plane][nVp[plane]] = i;
962 
963  hProjV[plane][nVp[plane]] = new TH1F(Form("hProj%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax);
964  // hProj2DV[plane][nVp[plane]] = new TH2F(Form("hProj2D%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax,80,-40,40);
965  // Int_t nbinsTheta = 1000;
966  TH2F* hProj2DVtmp = new TH2F("hProj2Dtmp","",fNbins,xMin,xMax,fNbinsTheta,-TMath::Pi(),TMath::Pi());
967  hProj2DV[plane][nVp[plane]] = new TH2F(Form("hProj2D%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax,fNbinsTheta,-TMath::Pi(),TMath::Pi());
968  hMap2DV[plane][nVp[plane]] = new TH2F(Form("hMap2D%d_%d",nVp[plane],plane),"",512,0,512,288,0,288);
969  GetConnex(Int_t(zV),Int_t(xV),3,3,m[plane],hMap2DV[plane][nVp[plane]]);
970  // hMeanV[plane][nVp[plane]] = new TH1F(Form("hMean%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax);
971  hMeanV[plane][nVp[plane]] = new TH1F(Form("hMean%d_%d",nVp[plane],plane),"",fNbinsTheta,-TMath::Pi(),TMath::Pi());
972  hMean2V[plane][nVp[plane]] = new TH1F(Form("hMean2%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax);
973  hMean3V[plane][nVp[plane]] = new TH1F(Form("hMean3%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax);
974  hMean4V[plane][nVp[plane]] = new TH1F(Form("hMean4%d_%d",nVp[plane],plane),"",fNbins,xMin,xMax);
975  // hProf[plane][nVp[plane]] = 0;//new TH1F(Form("hProf%d_%d",nVp[plane],plane),"",100,-50,50);
976  hProjV[plane][nVp[plane]]->SetLineColor(kRed);
977  hMeanV[plane][nVp[plane]]->SetLineColor(kBlack);
978  hMean2V[plane][nVp[plane]]->SetLineColor(kBlue);
979  hMean4V[plane][nVp[plane]]->SetLineColor(kGreen);
980  for(Int_t i=0;i<NADC;i++){ //Time bins
981  for(Int_t j=0;j<NCHAN;j++){ // Channels
982  // Double_t q = m[plane]->GetData(j,i);
983  Double_t q = hMap2DV[plane][nVp[plane]]->GetBinContent(i+1,j+1);
984  if(q<=0) continue;
985  Double_t xTmp = j - xV, zTmp = i - zV;
986  Double_t a = xTmp*pzV - zTmp*pxV;
987  Double_t b = zTmp*pzV+xTmp*pxV;
988  Double_t rho = TMath::Sqrt(xTmp*xTmp+zTmp*zTmp);
989  Double_t theta = TMath::ATan2(xTmp,zTmp);
990  a = theta;
991  b = rho;
992 
993  hProj2DVtmp->Fill(b,a,q);
994  // hProj2DV[plane][nVp[plane]]->Fill(b,a,q);
995  //if(q<=100) continue;
996  hProjV[plane][nVp[plane]]->Fill(b,q);
997  //hMeanV[plane][nVp[plane]]->Fill(b,q*a);
998  hMean2V[plane][nVp[plane]]->Fill(b,q*a*a);
999  hMean3V[plane][nVp[plane]]->Fill(b,q*a*a*a);
1000  hMean4V[plane][nVp[plane]]->Fill(b,q*a*a*a*a);
1001  }
1002  }
1003  for(Int_t bin = 1; bin<=fNbins; bin++){
1004  Int_t k = Int_t(0.5/TMath::Pi()*fNbinsTheta/hProj2DV[plane][nVp[plane]]->GetXaxis()->GetBinCenter(bin));
1005  //if(k<1) break;
1006  for(Int_t i = 0; i<fNbinsTheta; i++){
1007  Double_t q = hProj2DVtmp->GetBinContent(bin,i+1);
1008  if(q<=0) continue;
1009  for(Int_t j = -k; j<=k; j++)
1010  hProj2DV[plane][nVp[plane]]->SetBinContent(bin,i+1+j,hProj2DV[plane][nVp[plane]]->GetBinContent(bin,i+1+j)+q);
1011  }
1012  }
1013  hProj2DVtmp->Delete();
1014  for(Int_t i = 0; i<fNbinsTheta; i++){
1015  Int_t nZero = 0;
1016  for(Int_t bin = 1; bin<=fNbins; bin++){
1017  //if(hProjV[plane][nVp[plane]]->GetXaxis()->GetBinCenter(bin)<10) continue;
1018  Double_t q = hProj2DV[plane][nVp[plane]]->GetBinContent(bin,i+1);
1019  if(nZero>1){
1020  hProj2DV[plane][nVp[plane]]->SetBinContent(bin,i+1,0);
1021  continue;
1022  }
1023  if(q<=0) nZero++;
1024  else nZero = 0;
1025  }
1026  }
1027 
1028  hProjV[plane][nVp[plane]]->SetMinimum(1);
1029  hProjV[plane][nVp[plane]]->GetXaxis()->SetRangeUser(-10,10);
1030  Double_t max = hProjV[plane][nVp[plane]]->GetMaximum();
1031  hProjV[plane][nVp[plane]]->GetXaxis()->SetRangeUser(xMin,xMax);
1032  Double_t bV;//, sigma2V = 1000;
1033  Bool_t foundV = kFALSE; //, foundS = kFALSE;
1034  for(Int_t bin = 1; bin<=fNbins; bin++){
1035  Double_t q = hProjV[plane][nVp[plane]]->GetBinContent(bin);
1036  if(q<=0) continue;
1037 
1038  Double_t mean = 0;//hMeanV[plane][nVp[plane]]->GetBinContent(bin)/q;
1039  Double_t mean2 = hMean2V[plane][nVp[plane]]->GetBinContent(bin)/q;
1040  Double_t sig2 = mean2-mean*mean;
1041  Double_t mean3 = hMean3V[plane][nVp[plane]]->GetBinContent(bin)/q;
1042  Double_t mean4 = hMean4V[plane][nVp[plane]]->GetBinContent(bin)/q;
1043  Double_t kurt = mean4 - 4*mean*mean3+6*mean*mean*mean2-3*mean*mean*mean*mean;
1044  kurt /= sig2*sig2;
1045  kurt -= 3;
1046  //hMeanV[plane][nVp[plane]]->SetBinContent(bin,mean);
1047  hMean2V[plane][nVp[plane]]->SetBinContent(bin,sig2);
1048  hMean4V[plane][nVp[plane]]->SetBinContent(bin,kurt);
1049  if(q>max*0.5 && !foundV){
1050  Double_t qTmp = hProjV[plane][nVp[plane]]->GetBinContent(bin-1);
1051  bV = q*hProjV[plane][nVp[plane]]->GetXaxis()->GetBinCenter(bin)
1052  + qTmp*hProjV[plane][nVp[plane]]->GetXaxis()->GetBinCenter(bin-1);
1053  bV /= q+qTmp;
1054  // sigma2V = sig2;
1055  foundV = kTRUE;
1056  }
1057  }
1058  nVp[plane]++;
1059 
1060 
1061  }
1062 
1063  // TH2F* hDummy = new TH2F("hDummy","",100,-100,200,100,-100,100);
1064  for(Int_t plane = 0; plane<2;plane++){
1065  TVirtualPad* cP = c->GetPad(plane+1);
1066  cP->Divide(3,nVp[plane]+1);
1067  for(Int_t i = 0; i<nVp[plane]; i++){
1068  // MakeNiceHisto(hMap2DV[plane][i],cP->GetPad(3*i+1),"colz");
1069  HarpoRecoVertex* vertex = (HarpoRecoVertex*)vArray->At(iV[plane][i]);
1070  Double_t xV = vertex->GetXvertex();
1071  Double_t zV = vertex->GetZvertex();
1072  MakeNiceHisto(fHistProj2Draw[iV[plane][i]],cP->GetPad(3*i+2),"colz");
1073  MakeNiceHisto(fHistMap[iV[plane][i]],cP->GetPad(3*i+1),"colz");
1074  // FIXME always 0.0 phi0, phi1
1075  Double_t phi0 = 0.0, phi1 = 0.0;
1076  // Double_t frac = GetFraction(plane,xV,zV,phi0,phi1);
1077  TEllipse* eStart = new TEllipse(zV,xV,fRadiusZ,fRadiusX,-phi0*180/TMath::Pi()+90,-phi1*180/TMath::Pi()+90);
1078  eStart->SetLineColor(kGray);
1079  eStart->SetLineWidth(3);
1080  eStart->SetFillStyle(0);
1081  // eStart->SetFillColor(kGray);
1082  eStart->Draw();
1083 
1084 
1085 
1086  Info("","Draw(fHistMean[%d])",iV[plane][i]);
1087  MakeNiceHisto(fHistMean[iV[plane][i]],cP->GetPad(3*i+3),"colz");
1088  // cP->GetPad(3*i+3)->SetLogy();
1089  hMeanV[plane][i]->Delete();
1090 
1091  // MakeNiceHisto(fHistProj2D[iV[plane][i]],cP->GetPad(3*i+3),"colz");
1092  }
1093  if(plane == XPLANE)
1094  MakeNiceHisto(fHistDiff,cP->GetPad(3*nVp[plane]+1));
1095  }
1096  c->Update();
1097 
1098  // c->GetPad(2)->SaveAs("exampleVertex.C");
1099  // c->GetPad(2)->SaveAs("exampleVertex.png");
1100  // c->GetPad(2)->SaveAs("exampleVertex.pdf");
1101 
1102  return;
1103 
1104 
1105 
1106 
1107 
1108 }
1109 
1110 
1111 
1112 void HarpoVertexing::ConfigFrame(TGMainFrame* fMain, Int_t id)
1113 {
1114 
1115  UInt_t xsize = 200;
1116  UInt_t ysize2 = 20;
1117  UInt_t ysize = 9*ysize2;
1118  TGTransientFrame* main = new TGTransientFrame(gClient->GetRoot(), fMain, xsize, ysize);
1119  main->Connect("CloseWindow()", "HarpoRecoMonitorGui", main, "CloseWindow()");
1120  main->DontCallClose(); // to avoid double deletions.
1121 
1122  // use hierarchical cleaning
1123  main->SetCleanup(kDeepCleanup);
1124 
1125  TGVerticalFrame* f213 = new TGVerticalFrame(main,xsize,ysize,kVerticalFrame);
1126  TGLabel* fLabel = new TGLabel(f213, "Vertexing");
1127 
1128 
1129  TGHorizontalFrame* RadiusXFrame = new TGHorizontalFrame(f213,xsize,ysize2,kHorizontalFrame);
1130  TGLabel* RadiusXLabel = new TGLabel(RadiusXFrame, "Radius X");
1131  fChooseRadiusX = new TGNumberEntry(RadiusXFrame);
1132  fChooseRadiusX->SetNumber(fRadiusX);
1133 
1134  TGHorizontalFrame* RadiusZFrame = new TGHorizontalFrame(f213,xsize,ysize2,kHorizontalFrame);
1135  TGLabel* RadiusZLabel = new TGLabel(RadiusZFrame, "Radius Z");
1136  fChooseRadiusZ = new TGNumberEntry(RadiusZFrame);
1137  fChooseRadiusZ->SetNumber(fRadiusZ);
1138 
1139  TGHorizontalFrame* MinFracFrame = new TGHorizontalFrame(f213,xsize,ysize2,kHorizontalFrame);
1140  TGLabel* MinFracLabel = new TGLabel(MinFracFrame, "Min Fraction");
1141  fChooseMinFrac = new TGNumberEntry(MinFracFrame);
1142  fChooseMinFrac->SetNumber(fMinFrac);
1143 
1144  TGHorizontalFrame* SeparationFrame = new TGHorizontalFrame(f213,xsize,ysize2,kHorizontalFrame);
1145  TGLabel* SeparationLabel = new TGLabel(SeparationFrame, "Min Fraction");
1146  fChooseSeparation = new TGNumberEntry(SeparationFrame);
1147  fChooseSeparation->SetNumber(fSeparation);
1148 
1149  TGHorizontalFrame* QminFrame = new TGHorizontalFrame(f213,xsize,ysize2,kHorizontalFrame);
1150  TGLabel* QminLabel = new TGLabel(QminFrame, "Min Fraction");
1151  fChooseQmin = new TGNumberEntry(QminFrame);
1152  fChooseQmin->SetNumber(fQmin);
1153 
1154  // TGHorizontalFrame* DUMMYFrame = new TGHorizontalFrame(f213,xsize,ysize2,kHorizontalFrame);
1155  // TGLabel* DUMMYLabel = new TGLabel(DUMMYFrame, "Qx/Qy");
1156  // fChooseDUMMY = new TGNumberEntry(DUMMYFrame);
1157  // fChooseDUMMY->SetNumber(fDUMMY);
1158 
1159 
1160  TGTextButton* setConf = new TGTextButton(f213,"Save Config",id);
1161  setConf->Associate(fMain);
1162 
1163  TGLayoutHints* fLayout1 = new TGLayoutHints(kLHintsLeft ,5,5,5,5);
1164  TGLayoutHints* fLayout2 = new TGLayoutHints(kLHintsRight ,5,5,5,5);
1165  TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsTop | kLHintsExpandX ,5,5,5,5);
1166  TGLayoutHints* fLayout4 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5);
1167 
1168  main->AddFrame(f213,fLayout4);
1169  f213->AddFrame(fLabel,fLayout3);
1170 
1171  f213->AddFrame(RadiusXFrame,fLayout3);
1172  RadiusXFrame->AddFrame(RadiusXLabel,fLayout1);
1173  RadiusXFrame->AddFrame(fChooseRadiusX,fLayout2);
1174 
1175  f213->AddFrame(RadiusZFrame,fLayout3);
1176  RadiusZFrame->AddFrame(RadiusZLabel,fLayout1);
1177  RadiusZFrame->AddFrame(fChooseRadiusZ,fLayout2);
1178 
1179  f213->AddFrame(MinFracFrame,fLayout3);
1180  MinFracFrame->AddFrame(MinFracLabel,fLayout1);
1181  MinFracFrame->AddFrame(fChooseMinFrac,fLayout2);
1182 
1183  f213->AddFrame(SeparationFrame,fLayout3);
1184  SeparationFrame->AddFrame(SeparationLabel,fLayout1);
1185  SeparationFrame->AddFrame(fChooseSeparation,fLayout2);
1186 
1187  f213->AddFrame(QminFrame,fLayout3);
1188  QminFrame->AddFrame(QminLabel,fLayout1);
1189  QminFrame->AddFrame(fChooseQmin,fLayout2);
1190 
1191  // f213->AddFrame(DUMMYFrame,fLayout3);
1192  // DUMMYFrame->AddFrame(DUMMYLabel,fLayout1);
1193  // DUMMYFrame->AddFrame(fChooseDUMMY,fLayout2);
1194 
1195  f213->AddFrame(setConf,fLayout3);
1196 
1197 
1198  main->MapSubwindows();
1199  main->MapWindow();
1200  main->Resize();
1201 
1202 }
1203 
1205 {
1206  fDisplay = kTRUE;
1207 
1208  if(!fChooseRadiusX) return;
1209 
1210  fQmin = fChooseQmin->GetNumber();
1211  fSeparation = fChooseSeparation->GetNumber();
1212  fRadiusX = fChooseRadiusX->GetNumber();
1213  fRadiusZ = fChooseRadiusZ->GetNumber();
1214  fMinFrac = fChooseMinFrac->GetNumber();
1215 
1216 }
1218 {
1219  fChooseRadiusX = 0;
1220  fDisplay = kFALSE;
1221 
1222  fQmin = 1000;
1223  fSeparation = 20;
1224  // fRadiusX = 15;
1225  // fRadiusZ = 30;
1226  fRadiusX = 13;//10;
1227  fRadiusZ = 25;//20;
1228  fMinFrac = 0.4;
1229 
1230  fNbins = 200;
1231  Double_t xMin = 0, xMax = 400;
1232  fNbinsTheta = 1000;
1233  for(Int_t i = 0; i<20; i++){
1234  fHistProj2D[i] = new TH2F(Form("fHistProj2D%d",i),"",fNbins,xMin,xMax,fNbinsTheta,-TMath::Pi(),TMath::Pi());
1235  fHistProj2Draw[i] = new TH2F(Form("fHistProj2Draw%d",i),"",fNbins,xMin,xMax,fNbinsTheta,-TMath::Pi(),TMath::Pi());
1236  fHistMean[i] = new TH1F(Form("fHistMean%d",i),"",2*fNbinsTheta,-2*TMath::Pi(),2*TMath::Pi());
1237  //fHistMean[i] = new TH1F(Form("fHistMean%d",i),"",fNbinsTheta,-TMath::Pi(),TMath::Pi());
1238  fHistMap[i] = new TH2F(Form("fHistMap%d",i),"",512,0,512,288,0,288);
1239 
1240  }
1241 
1242 
1243  fHistDiff = new TH1F("fHistDiff","",fNbinsTheta,-TMath::Pi()/10,TMath::Pi()/10);
1244 
1245  }
1246 
1247 void HarpoVertexing::Save(char * /* mode */)
1248  {
1249 
1250 
1251  OpenHistFile("recovertexing");
1252 
1253  fHistDiff->Write();
1254 
1255  // Save histograms here
1256 
1257 
1258  }
1259 
TGNumberEntry * fChooseSeparation
Double_t fRadiusX
TArrayD * FitGraph(TGraph *g, const Int_t nFit)
void SetChi2Vertex(Double_t val)
HarpoRecoEvent * GetRecoEvent()
Definition: HarpoEvent.h:46
Double_t fMinFrac
void FitVertex(TH2F *h, HarpoRecoVertex *vertex)
#define XPLANE
Definition: HarpoConfig.h:24
#define NCHAN
Definition: HarpoDccMap.h:16
TArrayD * GetPeaks(Int_t n, Double_t *x, Double_t *w, Int_t plane, Int_t v)
void SetPxVertex(Double_t val)
TH1F * fHist[2][10][3]
TH2F * fHistProj2Draw[20]
Double_t GetZvertex()
TGNumberEntry * fChooseRadiusZ
TArrayD * GetPeaks2(TH1F *h)
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
TGraph * GetGraph(TH2F *h, Int_t n, Double_t x0, Double_t z0, Double_t px, Double_t pz)
int main(int argc, char **argv)
Definition: drawAnalyse.cxx:25
void GetPeak(Int_t n, Double_t *x, Double_t *w, Double_t &muOut, Double_t &sigOut, Int_t plane, Int_t v)
TH2F * fHistProj2D[20]
Double_t fSeparation
void AddVertex(HarpoRecoVertex *val)
Object containing the reconstruction information for one event (with array of HarpoRecoClusters Harpo...
2D vertex object, containing position, angle and associated track numbers, and quality info ...
TH1F * fHist2[2][10][3]
void DisplayAnalysis(TRootEmbeddedCanvas *ecTab, TGListBox *infobox)
virtual void print()
Double_t GetFraction(Int_t ndet, Double_t x, Double_t z, Double_t &phi0, Double_t &phi1)
Redefine empty default.
FullEvent Header not scecific to the detectors The class is ....
Double_t GetPzVertex()
void SetZvertex(Double_t val)
TClonesArray * GetVertexArray()
virtual void print()
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...
Definition: HarpoDccMap.h:29
TVirtualPad * MakeNiceHisto(TH1 *hist, TVirtualPad *c1, const char *opt, Bool_t copy)
#define NADC
Definition: HarpoDccMap.h:18
void SetThetaVertex(Double_t val)
void SetXvertex(Double_t val)
TH2F * fHistMap[20]
Dummy analysis to run as test and example. Give basic histograms of the data.
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
TGNumberEntry * fChooseMinFrac
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
void ConfigFrame(TGMainFrame *fMain, Int_t id)
ULong_t nEvents
Definition: HarpoAnalyse.h:75
TH1F * fHistMean[20]
void RefineVertexPosition()
Double_t GetPxVertex()
void print()
Overloaded method which do all job.
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
TGNumberEntry * fChooseRadiusX
void Save(char *mode=NULL)
Double_t fRadiusZ
Double_t GetXvertex()
void GetConnex(Int_t i, Int_t j, Int_t n, Int_t n0, HarpoDccMap *m, TH2F *h)
TClonesArray * GetClustersArray()
void SetPzVertex(Double_t val)
TGNumberEntry * fChooseQmin