FairRoot/PandaRoot
PndTrkLegendreTask.cxx
Go to the documentation of this file.
1 //
3 // PndTrkLegendreTask
4 //
5 // Class for secondary track pattern recognition
6 //
7 // authors: Lia Lavezzi - INFN Pavia (2012)
8 //
10 
11 #include "PndTrkLegendreTask.h"
12 
13 // stt
14 #include "PndSttHit.h"
15 #include "PndSttTube.h"
16 #include "PndSttMapCreator.h"
17 // sds
18 #include "PndSdsHit.h"
19 // track(cand)
20 #include "PndTrackCand.h"
21 #include "PndTrackCandHit.h"
22 #include "PndTrack.h"
23 
24 #include "PndTrkConformalHit.h"
25 #include "PndTrkConformalHitList.h"
27 #include "PndTrkTools.h"
28 #include "PndTrkSkewHit.h"
29 #include "PndTrkFitter.h"
30 // fairroot
31 #include "FairRootManager.h"
32 #include "FairRunAna.h"
33 #include "FairRuntimeDb.h"
34 // ROOT
35 #include "TClonesArray.h"
36 #include "TVector3.h"
37 #include "TArc.h"
38 #include "TLine.h"
39 #include "TMarker.h"
40 #include "TSpectrum2.h"
41 #include "TSpectrum.h"
42 #include "TStopwatch.h"
43 // tracking
44 #include "PndTrkClusterList.h"
45 #include "PndTrkGlpkFits.h"
46 #include "PndTrkClean.h"
47 
48 #include <iostream>
49 
50 using namespace std;
51 
52 
53 // ----- Default constructor -------------------------------------------
54 PndTrkLegendreTask::PndTrkLegendreTask() : FairTask("secondary track finder", 0), fDisplayOn(kFALSE), fPersistence(kTRUE), fUseMVDPix(kTRUE), fUseMVDStr(kTRUE), fUseSTT(kTRUE), fSecondary(kFALSE), fMvdPix_RealDistLimit(1000), fMvdStr_RealDistLimit(1000), fStt_RealDistLimit(1000), fMvdPix_ConfDistLimit(1000), fMvdStr_ConfDistLimit(1000), fStt_ConfDistLimit(1000), fInitDone(kFALSE) {
55  sprintf(fSttBranch,"STTHit");
56  sprintf(fMvdPixelBranch,"MVDHitsPixel");
57  sprintf(fMvdStripBranch,"MVDHitsStrip");
59 }
60 
61 PndTrkLegendreTask::PndTrkLegendreTask(int verbose) : FairTask("secondary track finder", verbose), fDisplayOn(kFALSE), fPersistence(kTRUE), fUseMVDPix(kTRUE), fUseMVDStr(kTRUE), fUseSTT(kTRUE), fSecondary(kFALSE), fMvdPix_RealDistLimit(1000), fMvdStr_RealDistLimit(1000), fStt_RealDistLimit(1000), fMvdPix_ConfDistLimit(1000), fMvdStr_ConfDistLimit(1000), fStt_ConfDistLimit(1000), fInitDone(kFALSE) {
62  sprintf(fSttBranch,"STTHit");
63  sprintf(fMvdPixelBranch,"MVDHitsPixel");
64  sprintf(fMvdStripBranch,"MVDHitsStrip");
66 }
67 
68 // -------------------------------------------------------------------------
69 
70 // ----- Destructor ----------------------------------------------------
72 
73 }
74 // -------------------------------------------------------------------------
75 
76 
77 
78 // ----- Public method Init --------------------------------------------
80 
81  fEventCounter = 0;
82 
83  fMvdPix_RealDistLimit = 0.5; // CHECK limits
84  fMvdStr_RealDistLimit = 0.5; // CHECK limits
85  fStt_RealDistLimit = 1.5 * 0.5; // CHECK limits
86  fMvdPix_ConfDistLimit = 0.003; // CHECK limits
87  fMvdStr_ConfDistLimit = 0.003; // CHECK limits
88  fStt_ConfDistLimit = 0.001; // CHECK limits
89  if(fSecondary) {
90  fMvdPix_ConfDistLimit = 0.007; // CHECK limits
91  fMvdStr_ConfDistLimit = 0.007; // CHECK limits
92  }
93 
94 
95  // Get RootManager
96  FairRootManager* ioman = FairRootManager::Instance();
97  if ( ! ioman ) {
98  cout << "-E- PndTrkLegendreTask::Init: "
99  << "RootManager not instantiated, return!" << endl;
100  return kFATAL;
101  }
102 
103  // -- HITS -------------------------------------------------
104  //
105  // STT
106  fSttHitArray = (TClonesArray*) ioman->GetObject(fSttBranch);
107  if ( ! fSttHitArray ) {
108  cout << "-W- PndTrkLegendreTask::Init: "
109  << "No STTHit array, return!" << endl;
110  return kERROR;
111  }
112  //
113  // MVD PIXEL
114  fMvdPixelHitArray = (TClonesArray*) ioman->GetObject(fMvdPixelBranch);
115  if ( !fMvdPixelHitArray){
116  std::cout << "-W- PndTrkLegendreTask::Init: " << "No MVD Pixel hitArray, return!" << std::endl;
117  return kERROR;
118  }
119  //
120  // MVD STRIP
121  fMvdStripHitArray = (TClonesArray*) ioman->GetObject(fMvdStripBranch);
122  if ( !fMvdStripHitArray){
123  std::cout << "-W- PndTrkLegendreTask::Init: " << "No MVD Strip hitArray, return!" << std::endl;
124  return kERROR;
125  }
126 
127  fTrackArray = new TClonesArray("PndTrack");
128  fTrackCandArray = new TClonesArray("PndTrackCand");
129  ioman->Register("Track", "pr", fTrackArray, fPersistence); // CHECK
130  ioman->Register("TrackCand", "pr", fTrackCandArray, fPersistence); // CHECK
131 
132 
133  // ---------------------------------------- maps of STT tubes
136  // ---------------------------------------------------- end map
137 
138  if(fDisplayOn) {
139  display = new TCanvas("display", "display", 0, 0, 800, 800); // CHECK
140  display->Divide(2, 2);
141  }
142 
144  if(fSecondary) legendre->SetUpLegendreHisto(180, 0, 180, 1000, -1., 1.);
147 
149 
150  tools = new PndTrkTools();
152 
153  return kSUCCESS;
154 
155 }
156 
157 // -------------------------------------------------------------------------
158 
160  FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
161  fSttParameters = (PndGeoSttPar*) rtdb->getContainer("PndGeoSttPar");
162 }
163 
164 // -------------------------------------------------------------------------
165 
166 
168 
172 
173  if(fUseSTT) {
174  stthitlist->AddTCA(FairRootManager::Instance()->GetBranchId(fSttBranch), fSttHitArray);
176  }
177 
178  if(fUseMVDPix) {
179  mvdpixhitlist->AddTCA(FairRootManager::Instance()->GetBranchId(fMvdPixelBranch), fMvdPixelHitArray);
181  }
182 
183  if(fUseMVDStr) {
184  mvdstrhitlist->AddTCA(FairRootManager::Instance()->GetBranchId(fMvdStripBranch), fMvdStripHitArray);
186  }
187 
189  fFoundPeaks.clear();
190 
191  fInitDone = kTRUE;
192 
193 }
194 
195 void PndTrkLegendreTask::Exec(Option_t*) {
196  fTrackArray->Delete();
197  fTrackCandArray->Delete();
198 
199  if(fVerbose > 0) cout << "*********************** " << fEventCounter << " ***********************" << endl;
200  // CHECK delete this ---
201  // if(fEventCounter == 126 || fEventCounter == 526) {
202  // fEventCounter++;
203  // return;
204  // }
205  // ---
206  fEventCounter++;
207 
208  // CHECK : it may happen that the hit of a track generate more than one track; e.g.
209  // some of them are associated together to form a track, some are left out. If later the left outs
210  // result in a new peak, this new peak will have also the old, already used hits, associated to it.
211  // This happens since the used hits do not enter the new legendre transform, but can be associated
212  // to the found cluster with the distance criterion. In this way the final cluster, which then is
213  // fitted again with the mvd in the legendre plane, will give an existing peak.
214  // This results in an infinite loop ---> FIX IT! (how: timeout? better hit-to-cluster association?
215  // forbidden peak positions in legendre transform?)
216 
217  // CHECK THIS!
218  if(fSttHitArray->GetEntriesFast() < 3) {
219  Reset();
220  return;
221  }
222 
223  Initialize();
224  if(fVerbose > 1) {
225  cout << "number of stt hits " << fSttHitArray->GetEntriesFast() << endl;
226  cout << "number of mvdpix hits " << fMvdPixelHitArray->GetEntriesFast() << endl;
227  cout << "number of mvdstr hits " << fMvdStripHitArray->GetEntriesFast() << endl;
228  }
229 
230 
231 
232 
233  if(fDisplayOn) {
234  Refresh();
235  char goOnChar;
236  // cout << "Start?";
237  // cin >> goOnChar;
238  display->Update();
239  display->Modified();
240  cout << " STARTING" << endl;
241  }
242 
243  // translation and rotation - CHECK no rotation now
244  Double_t delta = 0, trasl[2] = {0., 0.};
245  if(!fSecondary) {
246  conform->SetOrigin(trasl[0], trasl[1], delta);
247  Int_t nchits = FillConformalHitList();
248  // if(nchits == 0) return; // CHECK
249  // cout << nchits << " " << trasl[0] << " " << trasl[1] << " " << delta << endl;
250  }
251 
252  int maxpeak = 1000;
253  int ipeak = 0;
254  PndTrkClusterList *clusterlist = new PndTrkClusterList();
255  std::vector< std::pair<double, double> > foundpeaks;
256 
257 
258  // LOOP OVER PEAKS UNTILL ITS HEIGHT IS <= 3
259  fTimer = new TStopwatch();
260  fTimer->Start();
261  fTime = 0;
262  while(maxpeak > 3) {
263 
264  // TIME
265  if(fDisplayOn == kFALSE) {
266  fTimer->Stop();
267  fTime += fTimer->RealTime();
268  if(fTime > 1.5) {
269  if(fVerbose > 0) cerr << fTime << endl;
270  Reset();
271  return;
272  }
273  fTimer->Start();
274  }
275  //
276 
277  if(fSecondary) {
278 
279  // translation and rotation - CHECK
281  if(fVerbose > 1) cout << "refhit " << fRefHit << endl;
282  if(fRefHit == NULL) {
283  Reset();
284  return;
285  }
286  ComputeTraAndRot(fRefHit, delta, trasl);
287  conform->SetOrigin(trasl[0], trasl[1], delta);
288  Int_t nchits = FillConformalHitList();
289  // if(nchits == 0) return; // CHECK
290  if(fVerbose > 1) cout << nchits << " " << trasl[0] << " " << trasl[1] << " " << delta << endl;
291  }
292 
293  PndTrkCluster cluster;
294 
295  if(fDisplayOn) {
296  Refresh();
297  char goOnChar;
298  cout << endl;
299  cout << "Next peak? ";
300  cin >> goOnChar;
301  display->Update();
302  display->Modified();
303  }
304 
305  if(fVerbose > 1) cout << "@@@@ PEAK No. " << ipeak << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
306  ipeak++;
307 
308  // APPLY LEGENDRE TO STT ALONE
309  // -------------------------------------------------------
310 
311  double theta_max, r_max;
312  maxpeak = ApplyLegendre(theta_max, r_max);
313  if(maxpeak <= 3) break;
314 
315  double fitm, fitq;
317 
318  // ADD HITS TO CLUSTER: PIXEL, STRIP AND STT PARALLEL
319  // -------------------------------------------------------
320  // method of hit-to-track association:
321  // 0 conformal: mvd and stt in conformal plane
322  // 1 real: mvd and stt in real plane
323  // 2 mixed: mvd in real/stt in conformal plane
324  int method = 0;
325 // cout << "cluster " << cluster.GetNofHits() << endl;
326  cluster = CreateClusterByDistance(method, fitm, fitq);
327 // cout << "CREATED " << endl;
328 // for(int ihit = 0; ihit < cluster.GetNofHits(); ihit++) {
329 // PndTrkHit *comparehit = (PndTrkHit*) cluster.GetHit(ihit);
330 // cout << "hit " << comparehit->GetHitID() << " " << comparehit->GetDetectorID() << endl;
331 // }
332 
333  // APPLY LEGENDRE TO CLUSTER + MVD
334  // -------------------------------------------------------
335 
336  maxpeak = ApplyLegendre(&cluster, theta_max, r_max);
337 
338 
339  // CLEANUP
340  // -------------------------------------------------------
341  PndTrkCluster cleancluster = Cleanup(cluster);
342  cluster = cleancluster;
343 
344 
345  // FIT WITH LEAST SQUARE STRAIGHT LINE
346  // -------------------------------------------------------
347 
348 
349  double fitm2, fitq2;
350  fFitter->Reset();
351 
352  for(int ihit = 0; ihit < cluster.GetNofHits(); ihit++)
353  {
354  PndTrkHit *hit = cluster.GetHit(ihit);
355  double conformal[3];
356 
357  PndTrkConformalHit *chit = NULL;
358  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) chit = conform->GetConformalSttHit(hit);
359  else chit = conform->GetConformalHit(hit);
360 
361  double xi1 = chit->GetU() + fitm * chit->GetIsochrone()/ TMath::Sqrt(fitm * fitm + 1);
362  double yi1 = chit->GetV() - chit->GetIsochrone() / TMath::Sqrt(fitm * fitm + 1);
363 
364  double xi2 = chit->GetU() - fitm * chit->GetIsochrone() / TMath::Sqrt(fitm * fitm + 1);
365  double yi2 = chit->GetV() + chit->GetIsochrone()/ TMath::Sqrt(fitm * fitm + 1);
366 
367  double xi = 0, yi = 0;
368 
369  fabs(yi1 - (fitm * xi1 + fitq)) < fabs(yi2 - (fitm * xi2 + fitq)) ? (yi = yi1, xi = xi1) : (yi = yi2, xi = xi2);
370 
371  double sigma = chit->GetIsochrone();
372  fFitter->SetPointToFit(xi, yi, sigma);
373 
374  if(fDisplayOn) {
375  display->cd(2);
376  TMarker *mrk = new TMarker(xi, yi, 6);
377  mrk->Draw("SAME");
378  }
379  }
380 
381  fFitter->StraightLineFit(fitm2, fitq2);
382 
383 
384  if(fDisplayOn) {
385  char goOnChar;
386  display->cd(2);
387  TLine *line = new TLine(-0.07, fitq + fitm * (-0.07), 0.07, fitq + fitm * (0.07));
388  line->Draw("SAME");
389  TLine *line2 = new TLine(-0.07, fitq2 + fitm2 * (-0.07), 0.07, fitq2 + fitm2 * (0.07));
390  line2->SetLineColor(2);
391  line2->Draw("SAME");
392 
393  display->Update();
394  display->Modified();
395  // cin >> goOnChar;
396  }
397 
398  fitm = fitm2;
399  fitq = fitq2;
400 
401 
402 
403 
404  // -------------------------------------------------------
405  if(cluster.GetNofHits() > 3) {
406  if(fVerbose > 1) cout << "ADDING CLUSTER WITH " << cluster.GetNofHits() << " hits " << endl;
407  clusterlist->AddCluster(&cluster);
408  }
409  else {
410  maxpeak = -1;
411  if(fVerbose > 1) cout << "MAXPEAK " << maxpeak << endl;
412  continue;
413  }
414  if(fDisplayOn) {
415  char goOnChar;
416  display->cd(1);
417  LightCluster(&cluster);
418  cout << "waiting 2 " << endl;
419  cin >> goOnChar;
420  }
421 
422  // center and radius
423  Double_t xc, yc, R;
424  FromConformalToRealTrack(fitm, fitq, xc, yc, R);
425  if(fVerbose > 1) cout << "XR, YC, R: " << xc << " " << yc << " " << R << endl;
426 
427  PndTrkTrack *track = new PndTrkTrack(&cluster, xc, yc, R);
428 
429  if(fDisplayOn) {
430  display->cd(1);
431  track->Draw(kRed);
432  display->Update();
433  display->Modified();
434  char goOnChar;
435  cout << "waiting 3 " << endl;
436  cin >> goOnChar;
437  }
438 
439 
440  // SKEWED ASSOCIATION ********* CHECK *********
441  // -------------------------------------------------------
442  if(fVerbose > 1) cout << "%%%%%%%%%%%%%%%%%%%% ZFINDER %%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
443 
444  if(fDisplayOn) {
445  RefreshZ();
446  DrawZGeometry(2);
447  }
448  PndTrkCluster skewhitlist = CreateSkewHitList(track);
449  skewhitlist = CleanUpSkewHitList(&skewhitlist);
450 
451  int iz = -1, jz = -1;
452  // cout << "##################### CHOOSE Z" << endl;
453 
454  // 7. select which intersection is the most likely and add it to z fitting
455  fFitter->Reset();
456  for(int ihit = 0; ihit < skewhitlist.GetNofHits() - 1; ihit++) {
457  PndTrkSkewHit *skewhit1 = (PndTrkSkewHit*) skewhitlist.GetHit(ihit);
458  if(!skewhit1) continue;
459  TVector3 fin_intersection1[2] = {skewhit1->GetIntersection1(), skewhit1->GetIntersection2()};
460  double phi1[2] = {skewhit1->GetPhi1(), skewhit1->GetPhi2()};
461 
462  int jhit = ihit + 1;
463  PndTrkSkewHit *skewhit2 = (PndTrkSkewHit*) skewhitlist.GetHit(jhit);
464  if(!skewhit2) continue;
465  TVector3 fin_intersection2[2] = {skewhit2->GetIntersection1(), skewhit2->GetIntersection2()};
466  double phi2[2] = {skewhit2->GetPhi1(), skewhit2->GetPhi2()};
467 
468  // cout << "start from " << ihit << " " << jhit << ": " << iz << " " << jz << endl;
469  if(jz != -1) {
470  iz = jz;
471  double distance = fabs(fin_intersection1[iz].Z() - fin_intersection2[0].Z());
472  jz = 0;
473  // 11 22
474  fabs(fin_intersection1[iz].Z() - fin_intersection2[1].Z()) < distance ? (distance = fabs(fin_intersection1[iz].Z() - fin_intersection2[1].Z()), jz = 1) : distance;
475  }
476  else {
477  // 11 21
478  double distance = fabs(fin_intersection1[0].Z() - fin_intersection2[0].Z());
479  iz = 0;
480  jz = 0;
481  // 11 22
482  fabs(fin_intersection1[0].Z() - fin_intersection2[1].Z()) < distance ? (distance = fabs(fin_intersection1[0].Z() - fin_intersection2[1].Z()), iz = 0, jz = 1 ): distance;
483  // 12 21
484  fabs(fin_intersection1[1].Z() - fin_intersection2[0].Z()) < distance ? (distance = fabs(fin_intersection1[1].Z() - fin_intersection2[0].Z()), iz = 1, jz = 0) : distance;
485  // 12 22
486  fabs(fin_intersection1[1].Z() - fin_intersection2[1].Z()) < distance ? (distance = fabs(fin_intersection1[1].Z() - fin_intersection2[1].Z()), iz = 1, jz = 1): distance;
487  }
488  // cout << "end with " << ihit << " " << jhit << ": " << iz << " " << jz << endl;
489 
490  fFitter->SetPointToFit(phi1[iz], fin_intersection1[iz].Z(), 1.);// (fin_intersection1[0].Z() + fin_intersection1[1].Z())/2.); // CHECK sigma?
491 
492  // CHECK
493  if(iz == 0) skewhit1->SetPosition(skewhit1->GetIntersection1());
494  else skewhit1->SetPosition(skewhit1->GetIntersection2());
495 
496  // CHECK last point?
497  if(ihit == skewhitlist.GetNofHits() - 2) {
498  fFitter->SetPointToFit(phi2[jz], fin_intersection2[jz].Z(), 1.);// (fin_intersection2[0].Z() + fin_intersection2[1].Z())/2.); // CHECK sigma?
499 
500  // CHECK
501  if(jz == 0) skewhit2->SetPosition(skewhit2->GetIntersection1());
502  else skewhit2->SetPosition(skewhit2->GetIntersection2());
503  }
504 
505 
506  if(fDisplayOn) {
507  char goOnChar;
508  display->cd(4);
509  TMarker *mrkfoundzphi1 = new TMarker(phi1[iz], fin_intersection1[iz].Z(), 20);
510  mrkfoundzphi1->SetMarkerColor(kYellow);
511  mrkfoundzphi1->Draw("SAME");
512 
513  TMarker *mrkfoundzphi2 = new TMarker(phi2[jz], fin_intersection2[jz].Z(), 20);
514  mrkfoundzphi2->SetMarkerColor(kYellow);
515  mrkfoundzphi2->Draw("SAME");
516 
517  display->Update();
518  display->Modified();
519  // cin >> goOnChar;
520  }
521  }
522 
523 
524  // ADD MVD POINTS ==================== RECHECK
525  PndTrkCluster *mvdcluster = track->GetCluster();
526  for(int ihit = 0; ihit < mvdcluster->GetNofHits(); ihit++) {
527  // cout << ihit << " TROVATO " << endl;
528  PndTrkHit *hit = mvdcluster->GetHit(ihit);
529  if(hit->GetDetectorID() != FairRootManager::Instance()->GetBranchId(fMvdPixelBranch) && hit->GetDetectorID() != FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) continue;
530  TVector3 position = hit->GetPosition();
531  double phi = track->ComputePhi(position);
532  hit->SetPhi(phi);
533  // cout << ihit << " TROVATO " << phi << " " << position.Z() << endl;
534 
535  if(fDisplayOn) {
536  char goOnChar;
537  display->cd(4);
538  TMarker *mrkfoundzphi = new TMarker(phi, position.Z(), 21);
539  mrkfoundzphi->SetMarkerColor(kOrange);
540  mrkfoundzphi->Draw("SAME");
541  display->Update();
542  display->Modified();
543  // cin >> goOnChar;
544  }
545  fFitter->SetPointToFit(phi, position.Z(), 0.1); // CHECK ERROR
546  }
547  // ===================================
548 
549 
550  Double_t ml, pl;
551  Bool_t straightlinefit = fFitter->StraightLineFit(ml, pl);
552 
553 
554  // CHECK the following fit: if it fails, put the hits into play again?
555  if(straightlinefit = kTRUE) {
556 
557  if(fDisplayOn) {
558  char goOnChar;
559  display->cd(4);
560  TLine *l222 = new TLine(-1000, -1000 * ml + pl, 1000, 1000 * ml + pl);
561  l222->Draw("SAME");
562  display->cd(3);
563  l222->Draw("SAME");
564  display->Update();
565  display->Modified();
566  // cin >> goOnChar;
567  }
568 
569  PndTrkCluster *trkcluster = track->GetCluster();
570  // 8. last association z --> HIT: fill position and add to cluster ???? CHECK
571  for(int ihit = 0; ihit < skewhitlist.GetNofHits(); ihit++) {
572  PndTrkSkewHit *skewhit = (PndTrkSkewHit*) skewhitlist.GetHit(ihit);
573  bool doescontain = trkcluster->DoesContain(skewhit);
574  // cout << "SKEW HIT " << skewhit->GetHitID() << " " << doescontain << endl;
575  if(doescontain == kTRUE) {
576  trkcluster->Replace(skewhit);
577  }
578  else trkcluster->AddHit(skewhit);
579  // trkcluster->AddHit(skewhit);
580 
581  TVector3 intersection1 = skewhit->GetIntersection1();
582  double phi1 = track->ComputePhi(intersection1);
583  double calcz1 = ml * phi1 + pl;
584  TVector3 intersection2 = skewhit->GetIntersection2();
585  double phi2 = track->ComputePhi(intersection2);
586  double calcz2 = ml * phi2 + pl;
587 
588  fabs(intersection1.Z() - calcz1) < fabs(intersection2.Z() - calcz2) ? skewhit->SetPosition(intersection1) : skewhit->SetPosition(intersection2);
589 
590  }
591 
592 
593  // 9. add skewedhitlist to cluster of the track
594  // fill the last two (missing) parameters
595  for(int ihit = 0; ihit < trkcluster->GetNofHits(); ihit++) {
596  PndTrkHit *hit = trkcluster->GetHit(ihit);
597  double phi = track->ComputePhi(hit->GetPosition()); // CHECK is it neede to recalculate it?
598  hit->SetSortVariable(phi);
599  hit->SetPhi(phi);
600 
601  }
602  trkcluster->Sort();
603  track->ComputeCharge();
604 
605  // 10. z-phi refit
606  Bool_t zfit = ZPhiFit(0, trkcluster, ml, pl);
607  // cout << "zfit1 on " << trkcluster->GetNofHits() << " hits/ " << zfit << " " << ml << " " << pl << " tanl " << - track->GetCharge() * ml * (180./TMath::Pi())/R << endl;
608 
609  PndTrkCluster *tmpcluster = CleanupZPhiFit(trkcluster, ml, pl);
610  trkcluster = tmpcluster;
611 
612  if(fDisplayOn) {
613  char goOnChar;
614  display->cd(4);
615  DrawZGeometry();
616  hzphi->SetXTitle("#phi");
617  hzphi->SetYTitle("#z");
618  hzphi->Draw();
619  display->Update();
620  display->Modified();
621  }
622 
623  zfit = ZPhiFit(1, trkcluster, ml, pl);
624 
625  // 11. fill the last two (missing) parameters
626 
627  // tanl = -q ml (180/pi) /R: See PndTrkTrack.h for an explanation
628 
629  if(zfit) {
630  track->SetTanL(- track->GetCharge() * ml * (180./TMath::Pi())/R);
631  track->SetZ0(pl);
632  }
633  else { // CHECK put these in default
634  track->SetTanL(-999);
635  track->SetZ0(-999);
636  }
637  // cout << "GET TANL " << ml << " " << R << " " << track->GetTanL() << endl;
638 
639  // test -------------------------------------------------------
640  PndTrkCluster *trkcluster2 = track->GetCluster();
641  // trkcluster2->Print();
642 
643  if(fDisplayOn) {
644  char goOnChar;
645  display->cd(1);
646  Refresh();
647  for(int ihit = 0; ihit < trkcluster2->GetNofHits(); ihit++) {
648  PndTrkHit *hit = trkcluster2->GetHit(ihit);
649  hit->Draw(kMagenta);
650 
651  display->Update();
652  display->Modified();
653  // cin >> goOnChar;
654  }
655  }
656  }
657  else { // CHECK put these in default
658  track->SetTanL(-999);
659  track->SetZ0(-999);
660  }
661  // ------------------------------------------------------- end test
662 
663  // TRANSFORM TO PNDTRACK AND PNDTRACKCAND
664  // -------------------------------------------------------
665  RegisterTrack(track);
666  if(fVerbose > 1) cout << "MAXPEAK " << maxpeak << endl;
667  }
668  if(fDisplayOn) {
669  char goOnChar;
670  display->Update();
671  display->Modified();
672  cout << "Finish? ";
673  cin >> goOnChar;
674  cout << "FINISH" << endl;
675  }
676 
677  Reset();
678  delete clusterlist;
679 
680 
681 }
682 
684 {
685  if(fDisplayOn) {
686  char goOnChar;
687  display->Update();
688  display->Modified();
689  cout << "Finish? ";
690  cin >> goOnChar;
691  cout << "FINISH" << endl;
692  }
693 
694  if(fInitDone) {
695  if(stthitlist) delete stthitlist;
696  if(mvdpixhitlist) delete mvdpixhitlist;
697  if(mvdstrhitlist) delete mvdstrhitlist;
698  if(fTimer) {
699  fTimer->Stop();
700  fTime += fTimer->RealTime();
701 
702  if(fVerbose > 0) cerr << fEventCounter << " Real time " << fTime << " s" << endl;
703  }
704  }
705 
706  fInitDone = kFALSE;
707 }
708 // ============================================================================================
712 
713  // FILL ONCE FOR ALL THE CONFORMAL HIT LIST
714  for(int jhit = 0; jhit < mvdpixhitlist->GetNofHits(); jhit++) {
715  PndTrkHit *hit = mvdpixhitlist->GetHit(jhit);
717  conformalhitlist->AddHit(chit);
718  }
719  for(int jhit = 0; jhit < mvdstrhitlist->GetNofHits(); jhit++) {
720  PndTrkHit *hit = mvdstrhitlist->GetHit(jhit);
722  conformalhitlist->AddHit(chit);
723  }
724  for(int jhit = 0; jhit < stthitlist->GetNofHits(); jhit++) {
725  PndTrkHit *hit = stthitlist->GetHit(jhit);
726  // if(hit->IsSttSkew()) continue;
727  // PndTrkConformalHit * chit = conform->GetConformalSttHit(hit);
728  // conformalhitlist->AddHit(chit);
729  if(hit->IsSttSkew()) {
730  // continue;
732  conformalhitlist->AddHit(chit);
733  }
734  else {
736  conformalhitlist->AddHit(chit);
737  }
738  }
739 
740  return conformalhitlist->GetNofHits();
741 }
742 
744 {
745  // mode 0 STT alone
746  // 1 STT + MVD
747  for(int ihit = 0; ihit < conformalhitlist->GetNofHits(); ihit++) {
749  if(mode == 0 && chit->GetDetectorID() != FairRootManager::Instance()->GetBranchId(fSttBranch)) continue;
750  PndTrkHit *hit = chit->GetHit();
751  if(hit->IsUsed()) continue;
752  legendre->FillLegendreHisto(chit->GetU(), chit->GetV(), chit->GetIsochrone());
753  if(fDisplayOn) {
754  DrawConfHit(chit->GetU(), chit->GetV(), chit->GetIsochrone());
755  }
756  }
757 }
758 
760 {
761  // ---------------------------------------------------------------
762  for(int ihit = 0; ihit < cluster->GetNofHits(); ihit++) {
763  PndTrkHit *hit = cluster->GetHit(ihit);
764  double conformal[3];
766  legendre->FillLegendreHisto(chit->GetU(), chit->GetV(), chit->GetIsochrone());
767  // conformalhitlist->AddHit(chit);
768  }
769 
770  // add mvd hits to stt cluster
771  for(int ihit = 0; ihit < conformalhitlist->GetNofHits(); ihit++) {
773  if(chit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) continue;
774  PndTrkHit *hit = chit->GetHit();
775  if(hit->IsUsed()) continue;
776  legendre->FillLegendreHisto(chit->GetU(), chit->GetV(), chit->GetIsochrone());
777  if(fDisplayOn) {
778  DrawConfHit(chit->GetU(), chit->GetV(), chit->GetIsochrone());
779  }
780  }
781 }
782 
783 
784 
786 
787  PndTrkCluster cluster;
788  // ADD HIT IN CONFORMAL PLANE WITH DISTANCE CRITERION
789  // cost x + sint y - r = 0 -> |cost x0 + sint y0 - r|
790  // cout << "CONFORMALHITLIST " << conformalhitlist->GetNofHits() << endl;
791  for(int ihit = 0; ihit < conformalhitlist->GetNofHits(); ihit++) {
793  double dist = chit->GetDistanceFromTrack(fitm, fitq);
794  int hitID = chit->GetHitID();
795  int detID = chit->GetDetectorID();
796 
797  // CHECK limits
798  double distlimit = 0;
799  if(detID == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch)) distlimit = 0.003;
800  else if(detID == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) distlimit = 0.003;
801  else if(detID == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
802  if(chit->GetIsochrone() > 1.e-4) distlimit = 6 * chit->GetIsochrone();
803  else distlimit = 0.001;
804  }
805  // ---------------------------
806  Bool_t accept = kFALSE;
807 
808 
809  if(dist < distlimit) {
810  if(fDisplayOn) {
811  if(chit->GetIsochrone() > 0) {
812  TArc *arc = new TArc(chit->GetU(), chit->GetV(), chit->GetIsochrone());
813  arc->SetFillStyle(0);
814  arc->SetLineColor(5);
815  display->cd(2);
816  arc->Draw("SAME");
817  }
818  else {
819  TMarker *mrk;
820  if(detID == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch)) mrk = new TMarker(chit->GetU(), chit->GetV(), 21);
821  else if(detID == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) mrk = new TMarker(chit->GetU(), chit->GetV(), 25);
822  mrk->SetMarkerColor(5);
823  display->cd(2);
824  mrk->Draw("SAME");
825  }
826  }
827 
828  PndTrkHit *hit;
829  if(detID == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch)) {
830  hit = mvdpixhitlist->GetHit(hitID);
831  }
832  else if(detID == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) {
833  hit = mvdstrhitlist->GetHit(hitID);
834  }
835  else if(detID == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
836  hit = stthitlist->GetHit(hitID);
837  }
838 
839  // ********** CHECK ***********
840  // if you put "is used" the efficiency beecomes much lower!
841  // DO NOT: if(!hit->IsUsed())
842  cluster.AddHit(hit);
843  accept = kTRUE;
844 
845  }
846 
847  // else cout << "DISCARDED " << hitID << " " << detID << " " << dist << " " << distlimit << endl;
848  }
849 
850  return cluster;
851 }
852 
854  // ADD HIT IN REAL PLANE WITH DISTANCE CRITERION
855  // sqrt((xc - x)**2 + (yc - y)**2) < distlim
856  PndTrkCluster cluster;
857 
858  // .........................................................
859  if(fDisplayOn) {
860  TArc *arc = new TArc(xc0, yc0, R0);
861  arc->SetFillStyle(0);
862  arc->SetLineColor(5);
863  display->cd(1);
864  arc->Draw("SAME");
865  }
866  for(int ihit = 0; ihit < stthitlist->GetNofHits(); ihit++) {
867  PndTrkHit *hit = stthitlist->GetHit(ihit);
868  if(hit->IsSttSkew()) continue;
869  double dist = hit->GetXYDistanceFromTrack(xc0, yc0, R0);
870  // cout << ihit << " dist " << dist << endl;
871  // CHECK limits
872  double distlimit = 1.5 * 0.5;
873  if(dist < distlimit){
874  // cout << "TRACK " << xc0 << " " << yc0 << " " << R0 << endl;
875  // cout << "ADD HIT " << dist << " " << distlimit << " " << hit->GetHitID() << endl;
876  cluster.AddHit(hit);
877  if(fDisplayOn) {
878  TArc *arc = new TArc(hit->GetPosition().X(), hit->GetPosition().Y(), hit->GetIsochrone());
879  arc->SetFillStyle(0);
880  arc->SetLineColor(5);
881  display->cd(1);
882  arc->Draw("SAME");
883  }
884  }
885  }
886  for(int ihit = 0; ihit < mvdpixhitlist->GetNofHits(); ihit++) {
887  PndTrkHit *hit = mvdpixhitlist->GetHit(ihit);
888  double dist = hit->GetXYDistanceFromTrack(xc0, yc0, R0);
889  // CHECK limits
890  double distlimit = 0.5;
891  if(dist < distlimit) {
892  cluster.AddHit(hit);
893  if(fDisplayOn) {
894  TMarker *mrk = new TMarker(hit->GetPosition().X(), hit->GetPosition().Y(), 21);
895  mrk->SetMarkerColor(5);
896  display->cd(1);
897  mrk->Draw("SAME");
898  }
899  }
900  }
901  for(int ihit = 0; ihit < mvdstrhitlist->GetNofHits(); ihit++) {
902  PndTrkHit *hit = mvdstrhitlist->GetHit(ihit);
903  double dist = hit->GetXYDistanceFromTrack(xc0, yc0, R0);
904  // CHECK limits
905  double distlimit = 0.5;
906  if(dist < distlimit){
907  cluster.AddHit(hit);
908  if(fDisplayOn) {
909  TMarker *mrk = new TMarker(hit->GetPosition().X(), hit->GetPosition().Y(), 25);
910  mrk->SetMarkerColor(5);
911  display->cd(1);
912  mrk->Draw("SAME");
913  }
914  }
915  }
916  return cluster;
917 
918 }
919 
921 
922  PndTrkCluster cluster;
924  // CHECK
925  // ADD HIT IN MIXED MODE REAL P. FOR MVD & CONFORMAL P. FOR STT,
926  // WITH DISTANCE CRITERION
927  // real: fabs(R - sqrt((xc - x)**2 + (yc - y)**2)) < distlim
928  // cofn: cost x + sint y - r = 0 -> |cost x0 + sint y0 - r|
929 
930  // CHECK if this needs to be kept --> change xc0 to xc etc
931  // center and radius
932  Double_t xc0, yc0, R0;
933  FromConformalToRealTrack(fitm, fitq, xc0, yc0, R0);
934  // .........................................................
935  if(fDisplayOn) {
936  TArc *arc = new TArc(xc0, yc0, R0);
937  arc->SetFillStyle(0);
938  arc->SetLineColor(5);
939  display->cd(1);
940  arc->Draw("SAME");
941  }
942  for(int ihit = 0; ihit < mvdpixhitlist->GetNofHits(); ihit++) {
943  PndTrkHit *hit = mvdpixhitlist->GetHit(ihit);
944  double dist = hit->GetXYDistanceFromTrack(xc0, yc0, R0);
945  // CHECK limits
946  double distlimit = 0.5;
947  if(dist < distlimit) {
948  cluster.AddHit(hit);
949  if(fDisplayOn) {
950  TMarker *mrk = new TMarker(hit->GetPosition().X(), hit->GetPosition().Y(), 21);
951  mrk->SetMarkerColor(5);
952  display->cd(1);
953  mrk->Draw("SAME");
954  }
955  }
956  }
957  for(int ihit = 0; ihit < mvdstrhitlist->GetNofHits(); ihit++) {
958  PndTrkHit *hit = mvdstrhitlist->GetHit(ihit);
959  double dist = hit->GetXYDistanceFromTrack(xc0, yc0, R0);
960  // CHECK limits
961  double distlimit = 0.5;
962  if(dist < distlimit){
963  cluster.AddHit(hit);
964  if(fDisplayOn) {
965  TMarker *mrk = new TMarker(hit->GetPosition().X(), hit->GetPosition().Y(), 25);
966  mrk->SetMarkerColor(5);
967  display->cd(1);
968  mrk->Draw("SAME");
969  }
970  }
971  }
972 
973  for(int ihit = 0; ihit < conformalhitlist->GetNofHits(); ihit++) {
975  double dist = chit->GetDistanceFromTrack(fitm, fitq);
976 
977  int hitID = chit->GetHitID();
978  int detID = chit->GetDetectorID();
979 
980  // CHECK limits
981  if(detID != FairRootManager::Instance()->GetBranchId(fSttBranch)) continue;
982  double distlimit = 0;
983  if(chit->GetIsochrone() > 1.e-4) distlimit = 6 * chit->GetIsochrone();
984  else distlimit = 0.001;
985  // ---------------------------
986 
987  if(dist < distlimit) {
988 
989  // cout << "ADDED " << hitID << " " << detID << " " << dist << " " << distlimit << endl;
990 
991  if(fDisplayOn) {
992  TArc *arc = new TArc(chit->GetU(), chit->GetV(), chit->GetIsochrone());
993  arc->SetFillStyle(0);
994  arc->SetLineColor(5);
995  display->cd(2);
996  arc->Draw("SAME");
997  }
998 
999  PndTrkHit *hit = stthitlist->GetHit(hitID);
1000 
1001  // ********** CHECK ***********
1002  // if you put "is used" the efficiency beecomes much lower!
1003  // DO NOT: if(!hit->IsUsed())
1004  cluster.AddHit(hit);
1005  }
1006  }
1007  return cluster;
1008 }
1009 
1010 
1012  double dist = hit->GetXYDistanceFromTrack(x0, y0, R);
1013  int detID = hit->GetDetectorID();
1014  if(detID == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch)) {
1015  if(dist < fMvdPix_RealDistLimit) return kTRUE;
1016  }
1017  else if(detID == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) {
1018  if(dist < fMvdStr_RealDistLimit) return kTRUE;
1019  }
1020  else if(detID == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
1021  if(dist < fStt_RealDistLimit) return kTRUE;
1022  }
1023  return kFALSE;
1024 }
1025 
1026 
1028  double dist = chit->GetDistanceFromTrack(fitm, fitp);
1029  int detID = chit->GetDetectorID();
1030  if(detID == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch)) {
1031  if(dist < fMvdPix_ConfDistLimit) return kTRUE;
1032  }
1033  else if(detID == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) {
1034  if(dist < fMvdStr_ConfDistLimit) return kTRUE;
1035  }
1036  else if(detID == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
1037  if(chit->GetIsochrone() > 1.e-4) {
1038  if(dist < (6 * chit->GetIsochrone())) return kTRUE;
1039  }
1040  else if(dist < fStt_ConfDistLimit) return kTRUE;
1041  }
1042 
1043  return kFALSE;
1044 }
1045 
1047  PndTrkCluster cluster;
1048 
1049  // mode: -------------------------------------------
1050  // 0 all conformal: pix conf - str conf - stt conf
1051  // 1 all real: pix real - str real - stt real
1052  // 2 mix: pix real - str real - stt conf
1053  // --------------------------------------------------
1054  Double_t x0, y0, R;
1055  FromConformalToRealTrack(fitm, fitp, x0, y0, R);
1056 
1057  for(int ihit = 0; ihit < conformalhitlist->GetNofHits(); ihit++) {
1059  PndTrkHit *hit = chit->GetHit();
1060  Bool_t accept = kFALSE;
1061 
1062  if(hit == fRefHit) accept = DoesRealHitBelong(hit, x0, y0, R);
1063  else {
1064  if(mode == 0) accept = DoesConfHitBelong(chit, fitm, fitp);
1065  else if(mode == 1) accept = DoesRealHitBelong(hit, x0, y0, R);
1066  else if(mode == 2) {
1067  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) accept = DoesConfHitBelong(chit, fitm, fitp);
1068  else accept = DoesRealHitBelong(hit, x0, y0, R);
1069  }
1070  }
1071 
1072  if(accept == kTRUE && fDisplayOn) {
1073  display->cd(1);
1074  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
1075  TArc *arc = new TArc(hit->GetPosition().X(), hit->GetPosition().Y(), hit->GetIsochrone());
1076  arc->SetFillStyle(0);
1077  arc->SetLineColor(5);
1078  arc->Draw("SAME");
1079  }
1080  else {
1081  TMarker *mrk;
1082  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch)) mrk = new TMarker(hit->GetPosition().X(), hit->GetPosition().Y(), 21);
1083  else if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) mrk = new TMarker(hit->GetPosition().X(), hit->GetPosition().Y(), 25);
1084  mrk->SetMarkerColor(5);
1085  mrk->Draw("SAME");
1086  }
1087  }
1088 
1089  // ********** CHECK ***********
1090  // if you put "is used" the efficiency beecomes much lower!
1091  // DO NOT: if(!hit->IsUsed())
1092  if(accept == kTRUE) {
1093  //
1094  // cout << "ADDING TO CLUSTER " << hit->GetHitID() << " " << hit->GetDetectorID() << endl;
1095  cluster.AddHit(hit);
1096  }
1097  }
1098  return cluster;
1099 }
1100 
1101 void PndTrkLegendreTask::FromConformalToRealTrack(double fitm, double fitp, double &x0, double &y0, double &R) {
1102  // CHECK if this needs to be kept --> change xc0 to xc etc
1103  // center and radius
1104  Double_t xcrot0, ycrot0;
1105  ycrot0 = 1 / (2 * fitp);
1106  xcrot0 = - fitm * ycrot0;
1107  R = sqrt(xcrot0 * xcrot0 + ycrot0 * ycrot0);
1108  // re-rotation and re-traslation of xc and yc
1109  // rotation
1112  // traslation
1115 }
1116 
1118  if(hxy == NULL) hxy = new TH2F("hxy", "xy plane", 100, -43, 43, 100, -43, 43);
1119  else hxy->Reset();
1120  display->cd(1);
1121  hxy->Draw();
1122  display->Update();
1123  display->Modified();
1124 
1125 }
1126 
1127 void PndTrkLegendreTask::DrawZGeometry(int whichone, double phimin, double phimax, double zmin, double zmax)
1128 {
1129  if(hxz == NULL) hxz = new TH2F("hxz", "xz plane", 100, -43, 43, 100, -43, 113);
1130  else hxz->Reset();
1131  display->cd(3);
1132  hxz->Draw();
1133  if(whichone == 2) {
1134  if(hzphi == NULL) hzphi = new TH2F("hzphi", "z - phi plane", phimax - phimin, phimin, phimax, zmax - zmin, zmin, zmax);
1135  else {
1136  hzphi->Reset();
1137  hzphi->GetXaxis()->SetLimits(phimin, phimax);
1138  hzphi->GetYaxis()->SetLimits(zmin, zmax);
1139  }
1140  display->cd(4);
1141  hzphi->Draw();
1142  }
1143  display->Update();
1144  display->Modified();
1145 
1146 }
1147 
1148 // ============================================================================================
1149 // DISPLAY ***********************************************************************************
1150 // ============================================================================================
1151 
1153  // CHECK
1154  char goOnChar;
1155  // cout << "Refresh?" << endl;
1156  // cin >> goOnChar;
1157  // cout << "REFRESHING" << endl;
1158  DrawGeometry();
1159  if(fVerbose) cout << "Refresh stt" << endl;
1161  if(fVerbose) cout << "Refresh pixel" << endl;
1163  if(fVerbose) cout << "Refresh strip" << endl;
1165  if(fVerbose) cout << "Refresh stop" << endl;
1166 
1167 }
1168 
1170  display->cd(1);
1171  hitlist->Draw();
1172  display->Update();
1173  display->Modified();
1174 }
1175 void PndTrkLegendreTask::DrawGeometryConf(double x1, double y1, double x2, double y2) {
1176  // CHECK
1177  char goOnChar;
1178  // cout << "DRAWING GEOMETRY CONF" << endl;
1179  // cin >> goOnChar;
1180 
1181  // CHECK previous calculations, now not used;
1182  if(huv == NULL) huv = new TH2F("huv", "uv plane", 100, x1, y1, 100, x2, y2);
1183  else {
1184  huv->Reset();
1185  huv->GetXaxis()->SetLimits(x1, y1);
1186  huv->GetYaxis()->SetLimits(x2, y2);
1187  }
1188  display->cd(2);
1189  huv->Draw();
1190  display->Update();
1191  display->Modified();
1192 
1193 }
1194 
1195 
1197  display->cd(3);
1198  legendre->Draw();
1199  display->Update();
1200  display->Modified();
1201 }
1202 
1203 void PndTrkLegendreTask::RefreshConf() { // CHECK delete
1204  // CHECK
1205  char goOnChar;
1206  // cout << "RefreshConf?" << endl;
1207  // cin >> goOnChar;
1208  // cout << "REFRESHING CONF" << endl;
1209 }
1210 
1211 void PndTrkLegendreTask::RefreshZ() { // CHECK delete
1212  // CHECK
1213  char goOnChar;
1214  // cout << "RefreshZ?" << endl;
1215  // cin >> goOnChar;
1216  // cout << "REFRESHING Z" << endl;
1217 }
1218 
1219 
1220 void PndTrkLegendreTask::DrawConfHit(double u, double v, double r, int marker) {
1221  display->cd(2);
1222  if(r >= 0) {
1223  TArc *arc = new TArc(u, v, r);
1224  arc->SetFillStyle(0);
1225  arc->Draw("SAME");
1226  }
1227  else {
1228  TMarker *mrk = new TMarker(u, v, marker);
1229  mrk->Draw("SAME");
1230  }
1231  // display->Update();
1232  // display->Modified();
1233 }
1234 
1236 
1237 
1253  PndTrkCluster cluster;
1254  cluster.AddHit(firsthit);
1255  cluster.SetIRegion(firsthit->GetIRegion());
1256 
1257  // 2) LOOP on all the hits
1258  for(int ihit = 0; ihit < stthitlist->GetNofHits(); ihit++) {
1259  PndTrkHit *hit = stthitlist->GetHit(ihit);
1260 
1261  if(hit->IsUsed()) {
1262  // cout << "already used IV" << endl;
1263  continue;
1264  }
1265  if(!hit->IsRegion(firsthit->GetIRegion())) continue;
1266  // cout << ihit << " " << cluster.GetNofHits() << endl;
1267  // 3) LOOP (int hit3) on all the hits IN THE CLUSTER
1268  for(int jhit = 0; jhit < cluster.GetNofHits(); jhit++) {
1269  PndTrkHit *clushit = cluster.GetHit(jhit);
1270 
1271 
1272  if(*hit == *clushit) {
1273  continue;
1274  }
1275 
1276  Bool_t success = IsSttAssociate(hit, clushit);
1277  // cout << "success " << success << endl;
1278  if(!success) continue;
1279 
1280  cluster.AddHit(hit);
1281  break;
1282  }
1283  }
1284 
1285  if(cluster.GetNofHits() < 2) for(int ihit = 0; ihit < cluster.GetNofHits(); ihit++) cluster.DeleteAllHits();
1286  return cluster;
1287 }
1288 
1290 
1291  double distance = hit1->GetXYDistance(hit2); // ComputeDistance(hit1, hit2);
1292 
1293  if(distance < STTPARALDISTANCE) {
1294  // cout << "distance " << distance << endl;
1295  return kTRUE;
1296  }
1297  return kFALSE;
1298 
1299 }
1300 
1302 
1303  // cout << "LIGHT UP" << endl;
1304  Refresh();
1305  cluster->LightUp();
1306  display->Update();
1307  display->Modified();
1308 }
1309 
1310 // ================================== ZFINDER
1312 
1313  double xc = track->GetCenter().X();
1314  double yc = track->GetCenter().Y();
1315  double R = track->GetRadius();
1316  PndTrkCluster skewhitlist;
1317 
1318  double phimin = 400, phimax = -1, zmin = 1000, zmax = -1;
1319  for(int ihit = 0; ihit < stthitlist->GetNofHits(); ihit++) {
1320  PndTrkHit *hit = stthitlist->GetHit(ihit);
1321  // if(hit->IsUsed()) {
1322  // cout << "already used IV" << endl;
1323  // continue;
1324  // }
1325  if(hit->IsSttSkew() == kFALSE) continue;
1326 
1327  int tubeID = hit->GetTubeID();
1328  PndSttTube *tube = (PndSttTube*) fTubeArray->At(tubeID);
1329 
1330  TVector3 wireDirection = tube->GetWireDirection();
1331  Double_t halflength = tube->GetHalfLength();
1332 
1333  TVector3 first = tube->GetPosition() + wireDirection * halflength; // CHECK
1334  TVector3 second = tube->GetPosition() - wireDirection * halflength; // CHECK
1335  // if(fDisplayOn) {
1336  // char goOnChar;
1337  // display->cd(1);
1338  // TLine *l = new TLine(first.X(), first.Y(), second.X(), second.Y());
1339  // l->SetLineColor(kBlue);
1340  // l->Draw("SAME");
1341  // display->Update();
1342  // display->Modified();
1343  // cin >> goOnChar;
1344  // }
1345 first.Print();
1346 second.Print();
1347  double m1 = (first - second).Y()/(first - second).X();
1348  double q1 = first.Y() - m1 * first.X();
1349 
1350  // 1. compute intersection between the track circle and the wire
1351  TVector2 intersection1, intersection2;
1352  Int_t nofintersections = tools->ComputeSegmentCircleIntersection(TVector2(first.X(), first.Y()), TVector2(second.X(), second.Y()), xc, yc, R, intersection1, intersection2);
1353 
1354  if(nofintersections == 0) continue;
1355  if(nofintersections >= 2) {
1356  cout << "ERROR: MORE THAN 1 INTERSECTION!!" << endl;
1357  continue; // CHECK
1358  }
1359 
1360  if(fDisplayOn) {
1361  char goOnChar;
1362  display->cd(1);
1363  TLine *l = new TLine(first.X(), first.Y(), second.X(), second.Y());
1364  l->SetLineColor(kBlue);
1365  l->Draw("SAME");
1366 
1367  TMarker *mrk = new TMarker(intersection1.X(), intersection1.Y(), 20);
1368  mrk->SetMarkerColor(kBlue);
1369  mrk->Draw("SAME");
1370 
1371  display->Update();
1372  display->Modified();
1373 
1374 
1375  // cin >> goOnChar;
1376  }
1377 
1378 
1379  // 2. find the tangent to the track in the intersection point
1380  // tangent approximation
1381  TVector2 tangent = tools->ComputeTangentInPoint(xc, yc, intersection1);
1382 
1383  // 3. rotate clockwise the tangent/point/(wire, not explicitely)
1384  // in order to have the wire parallel to the x axis;
1385  // then translate everything to have the wire ON the x axis
1386  double beta = wireDirection.Phi();
1387  if(beta < 0) beta += TMath::Pi();
1388  // ... rotate the tangent
1389  double rtx = TMath::Cos(beta) * tangent.X() + TMath::Sin(beta) * tangent.Y();
1390  double rty = TMath::Cos(beta) * tangent.Y() - TMath::Sin(beta) * tangent.X();
1391  TVector2 rottangent(rtx, rty);
1392  rottangent = rottangent.Unit();
1393  // ... rotate the point
1394  double rx = TMath::Cos(beta) * intersection1.X() + TMath::Sin(beta) * intersection1.Y();
1395  double ry = TMath::Cos(beta) * intersection1.Y() - TMath::Sin(beta) * intersection1.X();
1396 
1397  // translation
1398  Double_t deltay = ry;
1399  rty -= deltay;
1400  ry -= deltay;
1401 
1402  // rotm, rotp
1403  Double_t rotm = rottangent.Y()/rottangent.X();
1404  Double_t rotp = ry - rotm * rx;
1405 
1406  // ellipsis
1407  double a = hit->GetIsochrone() * TMath::Cos(SKEW_ANGLE); // CHECK skew angle hard coded
1408  double b = hit->GetIsochrone();
1409 
1410  // center of ellipsis
1411  Double_t x0a, x0b, y0;
1412  y0 = 0.;
1413  x0a = (-rotp + TMath::Sqrt(b * b + a * a * rotm * rotm)) / rotm;
1414  x0b = (-rotp - TMath::Sqrt(b * b + a * a * rotm * rotm)) / rotm;
1415 
1416  // intersection point
1417  double intxa = (x0a * b * b - rotm * rotp * a * a) / (b * b + rotm * rotm * a * a);
1418  double intya = rotm * intxa + rotp;
1419  double intxb = (x0b * b * b - rotm * rotp * a * a) / (b * b + rotm * rotm * a * a);
1420  double intyb = rotm * intxb + rotp;
1421 
1422  // 4. retraslate/rerotate all back to the original plane
1423  // retranslate
1424  y0 += deltay;
1425  intya += deltay;
1426  intyb += deltay;
1427 
1428  // rerotate
1429  double x0anew = TMath::Cos(beta) * x0a - TMath::Sin(beta) * y0;
1430  double y0anew = TMath::Cos(beta) * y0 + TMath::Sin(beta) * x0a;
1431  double x0bnew = TMath::Cos(beta) * x0b - TMath::Sin(beta) * y0;
1432  double y0bnew = TMath::Cos(beta) * y0 + TMath::Sin(beta) * x0b;
1433 
1434  double intxanew = TMath::Cos(beta) * intxa - TMath::Sin(beta) * intya;
1435  double intyanew = TMath::Cos(beta) * intya + TMath::Sin(beta) * intxa;
1436  double intxbnew = TMath::Cos(beta) * intxb - TMath::Sin(beta) * intyb;
1437  double intybnew = TMath::Cos(beta) * intyb + TMath::Sin(beta) * intxb;
1438 
1439  intxa = intxanew;
1440  intya = intyanew;
1441  intxb = intxbnew;
1442  intyb = intybnew;
1443 
1444  // now we have x0a, y0a, center of the 1st ellipse
1445  // and x0b, y0b, center of the 2nd ellipse
1446  x0a = x0anew;
1447  double y0a = y0anew;
1448  x0b = x0bnew;
1449  double y0b = y0bnew;
1450 
1451  if(fDisplayOn) {
1452  char goOnChar;
1453  display->cd(1);
1454 
1455  TEllipse *ell1 = new TEllipse(x0a, y0a, a, b, 0, 360, -beta);
1456  ell1->SetFillStyle(0);
1457  ell1->SetLineColor(4);
1458  ell1->Draw("SAME");
1459  TEllipse *ell2 = new TEllipse(x0b, y0b, a, b, 0, 360, -beta);
1460  ell2->SetFillStyle(0);
1461  ell2->SetLineColor(6);
1462  ell2->Draw("SAME");
1463 
1464  TMarker *mrkinta = new TMarker(intxa, intya, 20);
1465  mrkinta->SetMarkerColor(4);
1466  mrkinta->Draw("SAME");
1467  TMarker *mrkintb = new TMarker(intxb, intyb, 20);
1468  mrkintb->SetMarkerColor(6);
1469  mrkintb->Draw("SAME");
1470  // cin >> goOnChar;
1471  }
1472 
1473  // 5. calculate z coordinate for each intersection
1474 
1475  // calculate z0a, z0b of the center of the ellipse
1476  Double_t t = ((x0a + y0a) - (first.X() + first.Y())) / ((second.X() - first.X()) + (second.Y() - first.Y()));
1477  Double_t z0a = first.Z() + (second.Z() - first.Z()) * t;
1478  // cout << "0 : calculate t, z0a " << t << " " << z0a << endl;
1479 
1480  t = ((x0b + y0b) - (first.X() + first.Y())) / ((second.X() - first.X()) + (second.Y() - first.Y()));
1481  Double_t z0b = first.Z() + (second.Z() - first.Z()) * t;
1482 
1483  TVector3 center1(x0a, y0a, z0a);
1484  TVector3 center2(x0b, y0b, z0b);
1485  if(fDisplayOn) {
1486  char goOnChar;
1487  display->cd(3);
1488  // cout << "COMPUTE Z COORDINATE" << endl;
1489  RefreshZ();
1490  DrawZGeometry();
1491  TLine *linezx = new TLine(first.X(), first.Z(), second.X(), second.Z());
1492  linezx->Draw("SAME");
1493  TMarker *mrkza = new TMarker(x0a, z0a, 20);
1494  mrkza->SetMarkerColor(4);
1495  mrkza->Draw("SAME");
1496  TMarker *mrkzb = new TMarker(x0b, z0b, 20);
1497  mrkzb->SetMarkerColor(6);
1498  mrkzb->Draw("SAME");
1499  // cin >> goOnChar;
1500  }
1501 
1502  // calculate the z of the intersection ON the ellipse (CHECK this step calculations!)
1503  double dx = intxa - x0a;
1504  double dy = intya - y0a;
1505  TVector3 dxdy(dx, dy, 0.0);
1506 
1507  TVector3 tfirst = first + dxdy;
1508  TVector3 tsecond = second + dxdy;
1509 
1510  t = ((intxa + intya) - (tfirst.X() + tfirst.Y())) / ((tsecond.X() - tfirst.X()) + (tsecond.Y() - tfirst.Y()));
1511  double intza = tfirst.Z() + (tsecond.Z() - tfirst.Z()) * t;
1512  if(fDisplayOn) {
1513  char goOnChar;
1514  display->cd(3);
1515  TLine *linezx1 = new TLine(tfirst.X(), tfirst.Z(), tsecond.X(), tsecond.Z());
1516  linezx1->SetLineStyle(1);
1517  linezx1->Draw("SAME");
1518  TMarker *mrkza1 = new TMarker(intxa, intza, 20);
1519  mrkza1->SetMarkerColor(kBlue - 9);
1520  mrkza1->Draw("SAME");
1521  // cin >> goOnChar;
1522  }
1523 
1524  tfirst = first - dxdy;
1525  tsecond = second - dxdy;
1526 
1527  t = ((intxb + intyb) - (tfirst.X() + tfirst.Y())) / ((tsecond.X() - tfirst.X()) + (tsecond.Y() - tfirst.Y()));
1528  double intzb = tfirst.Z() + (tsecond.Z() - tfirst.Z()) * t;
1529 
1530  TVector3 fin_intersection1(intxa, intya, intza);
1531  TVector3 fin_intersection2(intxb, intyb, intzb);
1532 
1533  if(fDisplayOn) {
1534  char goOnChar;
1535  display->cd(3);
1536  TLine *linezx2 = new TLine(tfirst.X(), tfirst.Z(), tsecond.X(), tsecond.Z());
1537  linezx2->SetLineStyle(1);
1538  linezx2->Draw("SAME");
1539  TMarker *mrkzb1 = new TMarker(intxb, intzb, 20);
1540  mrkzb1->SetMarkerColor(kMagenta - 7);
1541  mrkzb1->Draw("SAME");
1542  // cin >> goOnChar;
1543  }
1544  // int1.SetXYZ(intxa, intya, intza);
1545  // int2.SetXYZ(intxb, intyb, intzb);
1546  // errz = fabs(intza - intzb)/2. ;
1547 
1548  // CHECK to be changed
1549  int trackID = 1;
1550  double phi1 = track->ComputePhi(fin_intersection1);
1551  double phi2 = track->ComputePhi(fin_intersection2);
1552 
1553  PndTrkSkewHit *skewhit = new PndTrkSkewHit(*hit, trackID, center1, fin_intersection1, phi1, center2, fin_intersection2, phi2, a, b, -1, beta);
1554  // skewhit->Print();
1555  skewhitlist.AddHit(skewhit);
1556 
1557 
1558  }
1559  // cout << "PHI: " << phimin << " " << phimax << endl;
1560  // cout << "Z : " << zmin << " " << zmax << endl;
1561 
1562 
1563  return skewhitlist;
1564 }
1565 
1567 
1568 
1569  // 6. FIRST CLEANING of the track skewed associations
1570  // find most probable z - CHECK what happens if a track is very fwd peaked?
1571  // TRY WITH DELTA z = COST
1572  // cout << "##################### FIND MOST PROBABLE Z" << endl;
1573  double phimin = 400, phimax = -1, zmin = 1000, zmax = -1;
1574 
1575  for(int ihit = 0; ihit < skewhitlist->GetNofHits(); ihit++) {
1576  PndTrkSkewHit *skewhit = (PndTrkSkewHit*) skewhitlist->GetHit(ihit);
1577  if(!skewhit) continue;
1578  TVector3 fin_intersection1 = skewhit->GetIntersection1();
1579  TVector3 fin_intersection2 = skewhit->GetIntersection2();
1580 
1581  double phi1 = skewhit->GetPhi1();
1582  double phi2 = skewhit->GetPhi2();
1583 
1584  if(phi1 < phimin) phimin = phi1;
1585  if(phi2 < phimin) phimin = phi2;
1586  if(fin_intersection1.Z() < zmin) zmin = fin_intersection1.Z();
1587  if(fin_intersection2.Z() < zmin) zmin = fin_intersection2.Z();
1588 
1589  if(phi1 > phimax) phimax = phi1;
1590  if(phi2 > phimax) phimax = phi2;
1591  if(fin_intersection1.Z() > zmax) zmax = fin_intersection1.Z();
1592  if(fin_intersection2.Z() > zmax) zmax = fin_intersection2.Z();
1593  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ CHECK
1594  }
1595  // cout << "PHI: " << phimin << " " << phimax << endl;
1596  // cout << "Z : " << zmin << " " << zmax << endl;
1597 
1598  // DISPLAY ----------------------------
1599  if(fDisplayOn) {
1600  char goOnChar;
1601  display->cd(4);
1602  phimin -= 30;
1603  phimax += 30;
1604  zmin -= 13;
1605  zmax += 13;
1606  DrawZGeometry(2, phimin, phimax, zmin, zmax);
1607  hzphi->SetXTitle("#phi");
1608  hzphi->SetYTitle("#z");
1609  hzphi->Draw();
1610  display->Update();
1611  display->Modified();
1612 
1613 
1614  for(int ihit = 0; ihit < skewhitlist->GetNofHits(); ihit++) {
1615  PndTrkSkewHit *skewhit = (PndTrkSkewHit*) skewhitlist->GetHit(ihit);
1616  if(!skewhit) continue;
1617 
1618  TVector3 fin_intersection1 = skewhit->GetIntersection1();
1619  TVector3 fin_intersection2 = skewhit->GetIntersection2();
1620 
1621  double phi1 = skewhit->GetPhi1();
1622  double phi2 = skewhit->GetPhi2();
1623 
1624  TLine *linezphi = new TLine(phi1, fin_intersection1.Z(), phi2, fin_intersection2.Z());
1625  // TLine *linezphi = new TLine(fin_intersection1.Z(), phi1, fin_intersection2.Z(), phi2);
1626  linezphi->SetLineStyle(1);
1627  linezphi->Draw("SAME");
1628 
1629  TMarker *mrkzphi1 = new TMarker(phi1, fin_intersection1.Z(), 20);
1630  // TMarker *mrkzphi1 = new TMarker(fin_intersection1.Z(), phi1, 20);
1631 
1632  mrkzphi1->SetMarkerColor(kBlue - 9);
1633  mrkzphi1->Draw("SAME");
1634 
1635  TMarker *mrkzphi2 = new TMarker(phi2, fin_intersection2.Z(), 20);
1636  // TMarker *mrkzphi2 = new TMarker(fin_intersection2.Z(), phi2, 20);
1637  mrkzphi2->SetMarkerColor(kMagenta - 7);
1638  mrkzphi2->Draw("SAME");
1639  }
1640  display->Update();
1641  display->Modified();
1642  // cin >> goOnChar;
1643  }
1644  // DISPLAY ----------------------------
1645 
1646  TH1F hz("hz", "z", (zmax - zmin)/10., zmin, zmax); // CHECK
1647  for(int ihit = 0; ihit < skewhitlist->GetNofHits(); ihit++) {
1648  PndTrkSkewHit *skewhit = (PndTrkSkewHit*) skewhitlist->GetHit(ihit);
1649  if(!skewhit) continue;
1650  TVector3 fin_intersection1 = skewhit->GetIntersection1();
1651  TVector3 fin_intersection2 = skewhit->GetIntersection2();
1652  hz.Fill(fin_intersection1.Z());
1653  hz.Fill(fin_intersection2.Z());
1654  }
1655  int maxbinz = hz.GetMaximumBin();
1656  double mostprobZ = hz.GetBinCenter(maxbinz);
1657  // cout << mostprobZ << endl;
1658 
1659  // delete hits too far away ..........
1660  // cout << "##################### DELETE HITS" << endl;
1661  PndTrkCluster tmpskewhitlist;
1662  for(int ihit = 0; ihit < skewhitlist->GetNofHits(); ihit++) {
1663  PndTrkSkewHit *skewhit = (PndTrkSkewHit*) skewhitlist->GetHit(ihit);
1664  if(!skewhit) continue;
1665  TVector3 fin_intersection1 = skewhit->GetIntersection1();
1666  TVector3 fin_intersection2 = skewhit->GetIntersection2();
1667  double phi1 = skewhit->GetPhi1();
1668  double phi2 = skewhit->GetPhi2();
1669 
1670  if(fabs(fin_intersection1.Z() - mostprobZ) > 30. && fabs(fin_intersection2.Z() - mostprobZ) > 30.) {
1671  // cout << "THROW AWAY " << ihit << " " << fabs(fin_intersection1.Z() - mostprobZ) << " " << fabs(fin_intersection2.Z() - mostprobZ) << endl;
1672  continue;
1673  }
1674  skewhit->SetSortVariable((phi1 + phi2)/2.);
1675  tmpskewhitlist.AddHit(skewhit);
1676  }
1677  tmpskewhitlist.Sort();
1678  return tmpskewhitlist;
1679 }
1680 
1681 
1682 
1684  PndTrack *finaltrack = track->ConvertToPndTrack();
1685 
1686  TClonesArray& clref1 = *fTrackArray;
1687  Int_t size = clref1.GetEntriesFast();
1688  PndTrack *outputtrack = new(clref1[size]) PndTrack(finaltrack->GetParamFirst(), finaltrack->GetParamLast(), finaltrack->GetTrackCand());
1689 
1690  TClonesArray& clref2 = *fTrackCandArray;
1691  size = clref2.GetEntriesFast();
1692  PndTrackCand *outputtrackcand = new(clref2[size]) PndTrackCand(finaltrack->GetTrackCand());
1693 
1694  if(fVerbose > 1) {
1695  cout << "MOM FIRST: TOT, PT, PL " << outputtrack->GetParamFirst().GetMomentum().Mag() << " " << outputtrack->GetParamFirst().GetMomentum().Perp() << " " << outputtrack->GetParamFirst().GetMomentum().Z() << endl;
1696  cout << "MOM LAST: TOT, PT, PL " << outputtrack->GetParamLast().GetMomentum().Mag() << " " << outputtrack->GetParamLast().GetMomentum().Perp() << " " << outputtrack->GetParamLast().GetMomentum().Z() << endl;
1697  }
1698  if(fDisplayOn) {
1699  char goOnChar;
1700  display->cd(1);
1701  Refresh();
1702 
1703  track->Draw(kRed);
1704  display->Update();
1705  display->Modified();
1706 
1707  cout << "X, Y, R " << track->GetCenter().X() << " " << track->GetCenter().Y() << " " << track->GetRadius() << endl;
1708  cout << "Z0, TANL " << track->GetZ0() << " " << track->GetTanL() << endl;
1709  cout << "CHARGE " << track->GetCharge() << endl;
1710  // cin >> goOnChar;
1711  }
1712 
1713 }
1714 
1715 
1716 // ----------------------- FOR SECONDARIES
1718 {
1719 
1720  if(stthitlist->GetNofHits() == 0) return NULL;
1721  // loop on stt hits
1722  int tmphitid = -1;
1723  Double_t tmpiso = 1.;
1724  for(int jhit = 0; jhit < stthitlist->GetNofHits(); jhit++) {
1725  PndTrkHit *hit = stthitlist->GetHit(jhit);
1726  if(hit->IsUsed()) {
1727  if(fVerbose > 1) cout << "STT hit " << jhit << "already used " << endl;
1728  continue; }
1729  if(hit->IsSttSkew()) continue;
1730  if(hit->GetIsochrone() < tmpiso) {
1731  tmphitid = jhit;
1732  tmpiso = hit->GetIsochrone();
1733  }
1734  }
1735  if(tmphitid == -1) return NULL;
1736 
1737  PndTrkHit *refhit = stthitlist->GetHit(tmphitid);
1738  if(fVerbose > 1) cout << "STT REFERENCE HIT " << tmphitid << " " << refhit->GetIsochrone() << endl;
1739  return refhit;
1740 }
1741 
1743 {
1744  if(mvdpixhitlist->GetNofHits() == 0) return NULL;
1745  // loop on mvd pix hits
1746  int tmphitid = -1;
1747  PndTrkHit *refhit = NULL;
1748  for(int jhit = 0; jhit < mvdpixhitlist->GetNofHits(); jhit++) {
1749  PndTrkHit *hit = mvdpixhitlist->GetHit(jhit);
1750  if(hit->IsUsed()) {
1751  if(fVerbose > 1) cout << "already used V" << endl;
1752  continue;
1753  }
1754  tmphitid = jhit;
1755  break;
1756  }
1757  if(tmphitid == -1) return NULL;
1758  refhit = mvdpixhitlist->GetHit(tmphitid);
1759  if(fVerbose > 1) cout << "MVD PIXEL REFERENCE HIT " << refhit->GetHitID() << endl;
1760  return refhit;
1761 }
1762 
1764 {
1765  if(mvdstrhitlist->GetNofHits() == 0) return NULL;
1766  // loop on mvd str hits
1767  int tmphitid = -1;
1768  PndTrkHit *refhit = NULL;
1769  for(int jhit = 0; jhit < mvdstrhitlist->GetNofHits(); jhit++) {
1770  PndTrkHit *hit = mvdstrhitlist->GetHit(jhit);
1771  if(hit->IsUsed()) {
1772  if(fVerbose > 1) cout << "already used V" << endl;
1773  continue;
1774  }
1775  tmphitid = jhit;
1776  break;
1777  }
1778  if(tmphitid == -1) return NULL;
1779  refhit = mvdstrhitlist->GetHit(tmphitid);
1780  if(fVerbose > 1) cout << "MVD STRIP REFERENCE HIT " << refhit->GetHitID() << endl;
1781  return refhit;
1782 }
1783 
1785 {
1786  PndTrkHit *refhit = NULL;
1787  refhit = FindMvdStripReferenceHit();
1788  // refhit = FindMvdPixelReferenceHit();
1789  if(refhit != NULL) return refhit;
1790  // refhit = FindMvdStripReferenceHit();
1792  return refhit;
1793 }
1794 
1796 {
1797  PndTrkHit *refhit = NULL;
1798  // refhit = FindMvdReferenceHit();
1799  refhit = FindSttReferenceHit();
1800  if(refhit != NULL) return refhit;
1801  // refhit = FindSttReferenceHit();
1803 
1804  return refhit;
1805 }
1806 
1808 
1809  trasl[0] = hit->GetPosition().X();
1810  trasl[1] = hit->GetPosition().Y();
1811 
1812  delta = 0.; // TMath::ATan2(hit->GetPosition().Y() - 0., hit->GetPosition().X() - 0.); // CHECK
1813 
1814 }
1815 
1816 
1818 
1819  // cout << "RESETTING LEGENDRE HISTO" << endl;
1821 
1822  if(fDisplayOn) {
1823  RefreshConf();
1824  if(fSecondary) DrawGeometryConf(-1., 1., -1., 1.);
1825  else DrawGeometryConf(-0.07, 0.07, -0.07, 0.07);
1826  }
1827  // cout << "%%%%%%%%%%%%%%%%%%%% XY FINDE %%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
1828  FillLegendreHisto(cluster);
1829 }
1830 
1832 
1833  // cout << "RESETTING LEGENDRE HISTO" << endl;
1835 
1836  if(fDisplayOn) {
1837  RefreshConf();
1838  if(fSecondary) DrawGeometryConf(-1., 1., -1., 1.);
1839  else DrawGeometryConf(-0.07, 0.07, -0.07, 0.07);
1840  }
1841  if(fVerbose > 1) cout << "%%%%%%%%%%%%%%%%%%%% XY FINDER %%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
1842  FillLegendreHisto(0);
1843 }
1844 
1845 Int_t PndTrkLegendreTask::ApplyLegendre(double &theta_max, double &r_max) {
1846  PrepareLegendre();
1847  return ExtractLegendre(0, theta_max, r_max);
1848 }
1849 
1850 Int_t PndTrkLegendreTask::ApplyLegendre(PndTrkCluster *cluster, double &theta_max, double &r_max) {
1851  RePrepareLegendre(cluster);
1852  return ExtractLegendre(1, theta_max, r_max);
1853 }
1854 
1855 
1856 
1857 Int_t PndTrkLegendreTask::ExtractLegendre(Int_t mode, double &theta_max, double &r_max) {
1858  if(fDisplayOn) {
1859  char goOnChar;
1860  // cin >> goOnChar;
1862  // cout << "LEGENDRE (nof conf hits = " << conformalhitlist->GetNofHits() << ")" << endl;
1863  display->cd();
1864  // cin >> goOnChar;
1865  display->Update();
1866  display->Modified();
1867  }
1868 
1869  // FIND MAXIMUM IN LEGENDRE HISTO
1870 
1871  // legendre->ApplyThresholdLegendreHisto(0.3);
1872  int maxpeak = legendre->ExtractLegendreMaximum(theta_max, r_max);
1873 
1874  bool alreadythere = false;
1875  if(mode == 0) {
1876 
1877  if(maxpeak <= 3) {
1878  if(fVerbose > 1) cout << "MAXPEAK " << maxpeak << ", BREAK NOW! " << endl;
1879  return maxpeak;
1880  }
1881 
1882  for(int ialready = 0; ialready < fFoundPeaks.size(); ialready++) {
1883  std::pair<double, double> foundthetar = fFoundPeaks.at(ialready);
1884  double foundtheta = foundthetar.first;
1885  double foundr = foundthetar.second;
1886  // IF THIS PEAK WAS ALREADY FOUND, DELETE THE PEAK AND GO ON (TO AVOID INFINITE LOOPS)
1887  if(theta_max == foundtheta && r_max == foundr) {
1888  legendre->DeleteZoneAroundXYLegendre(theta_max, r_max);
1889  maxpeak = legendre->ExtractLegendreMaximum(theta_max, r_max);
1890  alreadythere = true;
1891  if(fVerbose > 0) cout << "OH NO! THIS PEAK IS ALREADY THERE" << endl;
1892  return -1;
1893  }
1894  }
1895 
1896  if(alreadythere == false) {
1897  std::pair<double, double> tr(theta_max, r_max);
1898  fFoundPeaks.push_back(tr);
1899  }
1900  }
1901  // ZOOM LEGENDRE HISTO
1902  legendre->SetUpZoomHisto(theta_max, r_max, 3, 0.005);
1903  // cout << "THETA/R " << theta_max << " " << r_max << " maxpeak " << maxpeak << endl;
1904 
1905  for(int ihit = 0; ihit < conformalhitlist->GetNofHits(); ihit++) {
1907  legendre->FillZoomHisto(chit->GetU(), chit->GetV(), chit->GetIsochrone());
1908  }
1909 
1910  if(mode == 0 && alreadythere == true) {
1911  cout << "THIS PEAK IS ALREADY THERE" << endl;
1912  legendre->DeleteZoneAroundXYZoom(theta_max, r_max);
1913  }
1914 
1915  int maxpeakzoom = legendre->ExtractZoomMaximum(theta_max, r_max);
1916  // cout << "THETA/R ZOOM " << theta_max << " " << r_max << " maxpeakzoom " << maxpeakzoom << endl;
1917 
1918  if(fDisplayOn) {
1919  char goOnChar;
1920  display->cd(3);
1921  TMarker *mrk = new TMarker(theta_max, r_max, 29);
1922  mrk->Draw("SAME");
1923  display->cd(4);
1924  legendre->DrawZoom();
1925  mrk->Draw("SAME");
1926  display->Update();
1927  display->Modified();
1928  // cin >> goOnChar;
1929  }
1930 
1931  return maxpeak;
1932 }
1933 
1934 
1936 
1937  // CLEANUP
1938  // -------------------------------------------------------
1939  // CleanCluster(cluster);
1940  // cluster->SortMvdPixelByLayerID();
1941  // cluster->SortByLayerID();
1942  PndTrkClean clean;
1943  int leftvotes = 0;
1944  int rightvotes = 0;
1945 
1946  TVector2 trasl = conform->GetTranslation();
1948 
1949  // SET SORT VARIABLE
1950  // MVD PIX PART OF CLUSTER
1951  PndTrkCluster mvdpixcluster = cluster.GetMvdPixelHitList();
1952  for(int ihit = 0; ihit < mvdpixcluster.GetNofHits(); ihit++) {
1953  PndTrkHit *hit = mvdpixcluster.GetHit(ihit);
1954  if(fSecondary) hit->SetSortVariable(hit->GetDistance(TVector3(trasl.X(), trasl.Y(), angle)));
1955  else hit->SetSortVariable(hit->GetDistance(TVector3(0., 0., 0)));
1956  int sensorID = hit->GetSensorID();
1957  int layerID = clean.FindMvdLayer(sensorID);
1958  if(layerID%2 == 0) rightvotes++;
1959  else leftvotes++;
1960  }
1961  // MVD STR PART OF CLUSTER
1962  PndTrkCluster mvdstrcluster = cluster.GetMvdStripHitList();
1963  for(int ihit = 0; ihit < mvdstrcluster.GetNofHits(); ihit++) {
1964  PndTrkHit *hit = mvdstrcluster.GetHit(ihit);
1965  if(fSecondary) hit->SetSortVariable(hit->GetDistance(TVector3(trasl.X(), trasl.Y(), angle)));
1966  else hit->SetSortVariable(hit->GetDistance(TVector3(0., 0., 0)));
1967  int sensorID = hit->GetSensorID();
1968  int layerID = clean.FindMvdLayer(sensorID);
1969  if(layerID%2 == 0) rightvotes++;
1970  else leftvotes++;
1971  }
1972  // STT PARALLEL PART OF CLUSTER
1973  PndTrkCluster sttcluster = cluster.GetSttParallelHitList();
1974  for(int ihit = 0; ihit < sttcluster.GetNofHits(); ihit++) {
1975  PndTrkHit *hit = sttcluster.GetHit(ihit);
1976  int layerID = -999, tubeID = hit->GetTubeID(), sectorID = -999;
1977  PndSttTube *tube = (PndSttTube*) fTubeArray->At(tubeID);
1978  layerID = tube->GetLayerID();
1979  sectorID = tube->GetSectorID();
1980  if(fSecondary) hit->SetSortVariable(hit->GetDistance(TVector3(trasl.X(), trasl.Y(), angle)));
1981  else hit->SetSortVariable(1000+layerID);
1982  if(sectorID < 3) rightvotes++;
1983  else leftvotes++;
1984  }
1985 
1986  // cout << "VOTES: LEFT " << leftvotes << " RIGHT " << rightvotes << endl;
1987  for(int ihit = 0; ihit < cluster.GetNofHits(); ihit++) {
1988  PndTrkHit *hit = cluster.GetHit(ihit);
1989  // cout << "for sorting " << hit->GetDetectorID () << " " << hit->GetHitID() << " " << hit->GetSortVariable() << endl;
1990  }
1991 
1992  cluster.Sort();
1993  for(int ihit = 0; ihit < cluster.GetNofHits(); ihit++) {
1994  PndTrkHit *hit = cluster.GetHit(ihit);
1995  // cout << "sorted " << hit->GetDetectorID () << " " << hit->GetHitID() << " " << hit->GetSortVariable() << endl;
1996  }
1997 
1998  // cluster.Print();
1999 
2000  // DELETE HITS
2001  PndTrkCluster deletioncluster;
2002 
2003  // LEFT/RIGHT CRITERION ------------------------------------------ NOW OFF
2004  // PIXEL
2005  mvdpixcluster = cluster.GetMvdPixelHitList();
2006  for(int ihit = 0; ihit < mvdpixcluster.GetNofHits(); ihit++) {
2007  PndTrkHit *hit = mvdpixcluster.GetHit(ihit);
2008  int sensorID = hit->GetSensorID();
2009  int layerID = clean.FindMvdLayer(sensorID);
2010  // cout << "pixel sorted " << hit->GetHitID() << " " << hit->GetSortVariable() << " " << sensorID << " " << layerID << endl;
2011 
2012 
2013  if((leftvotes > rightvotes) && (layerID%2 == 0)) {
2014  // deletioncluster.AddHit(hit);
2015  // cout << "pixel DELETED " << hit->GetHitID() << " " << ihit << " " << mvdpixcluster.GetNofHits() << endl;
2016  }
2017  else if((leftvotes < rightvotes) && (layerID%2 != 0)) {
2018  // deletioncluster.AddHit(hit);
2019  // cout << "pixel DELETED " << hit->GetHitID() << " " << ihit << " " << mvdpixcluster.GetNofHits() << endl;
2020  }
2021 
2022  if(fDisplayOn) {
2023  char goOnChar;
2024  display->cd(1);
2025  hit->Draw(kGreen);
2026  display->Update();
2027  display->Modified();
2028  cout << "WAITING" << endl;
2029  cin >> goOnChar;
2030  }
2031  }
2032  // STRIP
2033  mvdstrcluster = cluster.GetMvdStripHitList();
2034  for(int ihit = 0; ihit < mvdstrcluster.GetNofHits(); ihit++) {
2035  PndTrkHit *hit = mvdstrcluster.GetHit(ihit);
2036  int sensorID = hit->GetSensorID();
2037  // cout << "strip sorted " << hit->GetHitID() << " " << hit->GetSortVariable() << " " << sensorID << " " << clean.FindMvdLayer(sensorID) << endl;
2038  int layerID = clean.FindMvdLayer(sensorID);
2039  if((leftvotes > rightvotes) && (layerID%2 == 0)) {
2040  // deletioncluster.AddHit(hit);
2041  // cout << "strip DELETED " << hit->GetHitID() << endl;
2042  }
2043  else if((leftvotes < rightvotes) && (layerID%2 != 0)) {
2044  // deletioncluster.AddHit(hit);
2045  // cout << "strip DELETED " << hit->GetHitID() << endl;
2046  }
2047  if(fDisplayOn) {
2048  char goOnChar;
2049  display->cd(1);
2050  hit->Draw(kBlue);
2051  display->Update();
2052  display->Modified();
2053  // cin >> goOnChar;
2054  }
2055  }
2056 
2057  // STT PARALLEL
2058  sttcluster = cluster.GetSttParallelHitList();
2059  for(int ihit = 0; ihit < sttcluster.GetNofHits(); ihit++) {
2060  PndTrkHit *hit = sttcluster.GetHit(ihit);
2061  int layerID = -999, tubeID = hit->GetTubeID();
2062  PndSttTube *tube = (PndSttTube*) fTubeArray->At(tubeID);
2063  layerID = tube->GetLayerID();
2064  // cout << "stt sorted " << hit->GetHitID() << " " << hit->GetSortVariable() << " " << tubeID << " " << layerID << endl;
2065 
2066  int sectorID = tube->GetSectorID();
2067 
2068  if((leftvotes > rightvotes) && (sectorID < 3)) {
2069  // deletioncluster.AddHit(hit);
2070  // cout << "stt DELETED " << hit->GetHitID() << " " << sectorID << endl;
2071  }
2072  else if((leftvotes < rightvotes) && (sectorID >= 3)) {
2073  // deletioncluster.AddHit(hit);
2074  // cout << "stt DELETED " << hit->GetHitID() << " " << sectorID << endl;
2075  }
2076  // ~~~~~~~~~~~~~~~~~~ check *******************
2077  else { // NEIGHBORING CRITERION ------------------------------------------------
2078  TArrayI neighboring = tube->GetNeighborings();
2079  // cout << "NEIGHBORING TO TUBE " << tubeID << endl;
2080  // for(int nhit = 0; nhit < neighboring.GetSize(); nhit++) {
2081  // cout << " " << neighboring.At(nhit);
2082  // }
2083  // cout << endl;
2084 
2085  int neighboringcounter = 0;
2086  for(int ohit = 0; ohit < sttcluster.GetNofHits(); ohit++) {
2087  if(ihit == ohit) continue;
2088  PndTrkHit *otherhit = sttcluster.GetHit(ohit);
2089  int otherhitID = otherhit->GetTubeID();
2090 
2091  for(int nhit = 0; nhit < neighboring.GetSize(); nhit++) {
2092  if(otherhitID == neighboring.At(nhit)) neighboringcounter++;
2093  }
2094 
2095  // if(isthere == false)
2096  // {
2097  // deletioncluster.AddHit(hit);
2098  // cout << "stt DELETEDbis " << hit->GetHitID() << " " << sectorID << endl;
2099  // }
2100  }
2101  // cout << "hit " << ihit << " has " << neighboringcounter << " NEIGHBORINS" << endl;
2102 
2103  if(layerID != 0 && layerID != 7 && layerID != 8 && ihit != sttcluster.GetNofHits() - 1 && neighboringcounter == 1) {
2104  // cout << "I SHOULD DELETE THIS" << endl;
2105  // deletioncluster.AddHit(hit);
2106  // OFF FOR NOW: delete if there is just 1 neighboring
2107  // cout << "stt DELETED " << hit->GetHitID() << " " << sectorID << endl;
2108  }
2109 
2110  // ON, delete if there is no neighboring (isolated hit)
2111  if(neighboringcounter == 0) {
2112  // cout << "I WILL DELETE THIS" << endl;
2113  deletioncluster.AddHit(hit);
2114  // cout << "stt DELETED " << hit->GetHitID() << " " << sectorID << endl;
2115  }
2116 
2117  if(fDisplayOn) {
2118  char goOnChar;
2119  display->cd(1);
2120  hit->Draw(kCyan);
2121  display->Update();
2122  display->Modified();
2123  // cin >> goOnChar;
2124  }
2125  }
2126  }
2127 
2128  if(fDisplayOn) {
2129  char goOnChar;
2130  // cin >> goOnChar;
2131  }
2132  // ~~~~~~~~~~~~~~~~~~
2133 
2134 
2135 
2136  // ACTUAL DELETION OF HITS
2137 
2138  PndTrkCluster finalcluster;
2139  for(int ihit = 0; ihit < cluster.GetNofHits(); ihit++) {
2140  PndTrkHit *hit = cluster.GetHit(ihit);
2141  bool stop = false;
2142  for(int jhit = 0; jhit < deletioncluster.GetNofHits(); jhit++) {
2143  PndTrkHit *dhit = deletioncluster.GetHit(jhit);
2144  if(hit == dhit) {
2145  // ********** CHECK ***********
2146  // cout << "trhrow in again" << endl;
2147  // dhit->SetUsedFlag(0);
2148  stop = true;
2149  break;
2150  }
2151  }
2152  if(!stop) finalcluster.AddHit(hit);
2153  }
2154 
2155  return finalcluster;
2156 }
2157 
2158 
2160 
2161  PndTrkCluster *cleancluster = new PndTrkCluster();
2162  for(int ihit = 0; ihit < cluster->GetNofHits(); ihit++) {
2163  PndTrkHit *hit = cluster->GetHit(ihit);
2164  if(hit->IsSttParallel()) {
2165  cleancluster->AddHit(hit);
2166  continue; // CHECK IsSttParrallel will be changed
2167  }
2168 
2169  TVector3 position = hit->GetPosition();
2170  double phi = hit->GetPhi();
2171 
2172  // d = | m x - y + p | / sqrt(m**2 + 1)
2173  double distance = fabs(fitm * phi - position.Z() + fitp )/sqrt(fitm * fitm + 1);
2174  // cout << "distance " << hit->GetHitID() << " " << distance << endl;
2175 
2176  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch) || hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) {
2177  if(distance < 1) cleancluster->AddHit(hit);
2178  }
2179  else if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
2180  if(distance < 5) cleancluster->AddHit(hit);
2181  }
2182  }
2183  // cout << "cleancluster " << cleancluster->GetNofHits () << endl;
2184  return cleancluster;
2185 }
2186 
2187 
2188 Bool_t PndTrkLegendreTask::ZPhiFit(int iter, PndTrkCluster *cluster, double &fitm, double &fitp)
2189 {
2190 
2191  if(iter != 0) {
2192  if(fDisplayOn) {
2193  char goOnChar;
2194  display->cd(3);
2195  DrawZGeometry();
2196  hzphi->SetXTitle("#phi");
2197  hzphi->SetYTitle("#z");
2198  hzphi->Draw();
2199  display->Update();
2200  display->Modified();
2201  }
2202  }
2203 
2204  fFitter->Reset();
2205  PndTrkHit *hit = NULL;
2206  PndTrkHit *refhit = NULL;
2207  double refiso = 1000;
2208  for(int ihit = 0; ihit < cluster->GetNofHits(); ihit++) {
2209  hit = cluster->GetHit(ihit);
2210  if(hit->IsSttParallel()) continue; // CHECK IsSttParrallel will be changed
2211 
2212 
2213  TVector3 position = hit->GetPosition();
2214  double phi = hit->GetPhi();
2215  // fFitter->SetPointToFit(phi, position.Z(), 0.1);
2216 
2217  // CHECK refhit stuff
2218  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch) || hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) {
2219  if(iter != 0) refhit = hit;
2220  fFitter->SetPointToFit(phi, position.Z(), 0.001);
2221  }
2222  else if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
2223  if(iter != 0 && refhit == NULL && hit->GetIsochrone() < refiso) refhit = hit;
2224  fFitter->SetPointToFit(phi, position.Z(), 0.1);
2225  }
2226 
2227  if(fDisplayOn) {
2228  char goOnChar;
2229  if(iter == 0) display->cd(4);
2230  TMarker *mrkfoundzphi = NULL;
2231  if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdPixelBranch) || hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fMvdStripBranch)) {
2232  mrkfoundzphi = new TMarker(phi, position.Z(), 21);
2233  if(iter == 0) mrkfoundzphi->SetMarkerColor(kOrange);
2234  else mrkfoundzphi->SetMarkerColor(4);
2235  }
2236  else if(hit->GetDetectorID() == FairRootManager::Instance()->GetBranchId(fSttBranch)) {
2237  mrkfoundzphi = new TMarker(phi, position.Z(), 20);
2238  if(iter == 0) mrkfoundzphi->SetMarkerColor(kGreen);
2239  else mrkfoundzphi->SetMarkerColor(4);
2240  }
2241  mrkfoundzphi->Draw("SAME");
2242  // display->cd(3);
2243  // mrkfoundzphi->Draw("SAME");
2244 
2245  }
2246  }
2247  // ===================================
2248  bool fit = kFALSE;
2249  if(iter == 0) fit = fFitter->StraightLineFit(fitm, fitp);
2250  else {
2251  if(refhit != NULL) fit = fFitter->ConstrainedStraightLineFit(refhit->GetPhi(), refhit->GetPosition().Z(), fitm, fitp);
2252  else fit = fFitter->StraightLineFit(fitm, fitp);
2253  }
2254 
2255  if(fit) {
2256  if(fDisplayOn) {
2257  char goOnChar;
2258  if(iter != 0) display->cd(4);
2259  TLine *l22 = new TLine(-1000, -1000 * fitm + fitp, 1000, 1000 * fitm + fitp);
2260  if(iter == 0) l22->SetLineColor(3);
2261  else if(iter == 1) l22->SetLineColor(4);
2262  l22->Draw("SAME");
2263  display->cd(3);
2264  l22->Draw("SAME");
2265  display->Update();
2266  display->Modified();
2267  cin >> goOnChar;
2268  }
2269  }
2270  // ++++++++++++++++++++++++++++++++++
2271 
2272  return fit;
2273 }
2274 
2275 double PndTrkLegendreTask::ComputeZRediduals(PndTrkCluster *cluster, double fitm, double fitp) {
2276 
2277  TH1F hresiduals("hresiduals", "residuals in z", 20, -5, 5);
2278 
2279  for(int ihit = 0; ihit < cluster->GetNofHits(); ihit++) {
2280  PndTrkHit *hit = cluster->GetHit(ihit);
2281 
2282  if(hit->GetDetectorID() != FairRootManager::Instance()->GetBranchId(fSttBranch)) continue;
2283  if(hit->IsSttParallel()) continue;
2284 
2285  TVector3 position = hit->GetPosition();
2286  double phi = hit->GetPhi();
2287 
2288 
2289  double distance = fitm * phi + fitp - position.Z();
2290 
2291  hresiduals.Fill(distance);
2292  }
2293 
2294  if(fDisplayOn) {
2295  display->cd(4);
2296  char goOnChar;
2297  cout << "residuals";
2298  cin >> goOnChar;
2299  hresiduals.Draw();
2300  display->Update();
2301  display->Modified();
2302  cin >> goOnChar;
2303  }
2304  return hresiduals.GetMean();
2305 }
2306 
2307 double PndTrkLegendreTask::CorrectZ(PndTrkCluster *cluster, double deltaz, double fitm, double fitp) {
2308 
2309  for(int ihit = 0; ihit < cluster->GetNofHits(); ihit++) {
2310  PndTrkHit *hit = cluster->GetHit(ihit);
2311 
2312  if(hit->GetDetectorID() != FairRootManager::Instance()->GetBranchId(fSttBranch)) continue;
2313  if(hit->IsSttParallel()) continue;
2314 
2315  TVector3 position = hit->GetPosition();
2316  double newz = position.Z() - deltaz;
2317 
2318 
2319  int tubeID = hit->GetTubeID();
2320  PndSttTube *tube = (PndSttTube*) fTubeArray->At(tubeID);
2321 
2322  TVector3 wireDirection = tube->GetWireDirection();
2323  Double_t halflength = tube->GetHalfLength();
2324 
2325  TVector3 first = tube->GetPosition() + wireDirection * halflength; // CHECK
2326  TVector3 second = tube->GetPosition() - wireDirection * halflength; // CHECK
2327 
2328  double m, p;
2329  double newx = position.X();
2330  double newy = position.Y();
2331  if((second.X() - first.X()) != 0) {
2332  m = (second.Z() - first.Z())/(second.X() - first.X());
2333  p = position.Z() - m * position.X();
2334  newx = (newz - p)/m;
2335  }
2336 
2337  if((second.Y() - first.Y()) != 0) {
2338 
2339  m = (second.Z() - first.Z())/(second.Y() - first.Y());
2340  p = position.Z() - m * position.Y();
2341  newy = (newz - p)/m;
2342  }
2343 
2344  hit->SetPosition(TVector3(newx, newy, newz));
2345 
2346  if(fDisplayOn) {
2347  display->cd(1);
2348  char goOnChar;
2349  cout << endl;
2350  cout << "SEE IT" ;
2351  TMarker *mrk = new TMarker(newx, newy, 6);
2352  mrk->SetMarkerColor(kOrange);
2353  mrk->Draw("SAME");
2354  display->Update();
2355  display->Modified();
2356 
2357  cout << "old " << position.X() << " " << position.Y() << " " << position.Z() << endl;
2358  cout << "new " << newx << " " << newy << " " << newz << endl;
2359 
2360  cin >> goOnChar;
2361  }
2362 
2363  }
2364 }
2366 
PndTrkHit * FindReferenceHit()
Double_t x0
Definition: checkhelixhit.C:70
Double_t p
Definition: anasim.C:58
int fVerbose
Definition: poormantracks.C:24
void Replace(PndTrkHit *hit)
double dy
void SetUpZoomHisto(double theta, double r, double deltatheta, double deltar)
Double_t GetRadius()
Definition: PndTrkTrack.h:43
PndTrkHit * FindMvdPixelReferenceHit()
void AddTCA(Int_t detID, TClonesArray *array)
double r
Definition: RiemannTest.C:14
PndTrkCluster Cleanup(PndTrkCluster cluster)
int FindMvdLayer(int sensorID)
__m128 m
Definition: P4_F32vec4.h:28
TTree * b
PndTrack ConvertToPndTrack()
Int_t ExtractLegendre(Int_t mode, double &theta_max, double &r_max)
Double_t GetHalfLength()
Definition: PndSttTube.cxx:99
PndSttMapCreator * fMapper
Double_t GetPhi1()
Definition: PndTrkSkewHit.h:37
PndTrkHit * FindMvdReferenceHit()
Bool_t IsSttAssociate(PndTrkHit *hit1, PndTrkHit *hit2)
Double_t GetPhi()
Definition: PndTrkHit.h:67
void FromConformalToRealTrack(double fitm, double fitp, double &x0, double &y0, double &R)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
PndTrkSttHitList * Instanciate()
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
PndTrkSttHitList * stthitlist
void DrawConfHit(double x, double y, double r, int marker=2)
#define verbose
PndTrkCluster GetCluster()
Definition: PndTrkTrack.h:48
PndTrkLegendreTransform * legendre
static T Sin(const T &x)
Definition: PndCAMath.h:42
void SetTanL(double tanl)
Definition: PndTrkTrack.h:39
PndGeoSttPar * fSttParameters
double ComputeZRediduals(PndTrkCluster *cluster, double fitm, double fitp)
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
void FillLegendreHisto(double x, double y, double radius)
void SetPhi(Double_t phi)
Definition: PndTrkHit.h:48
Double_t GetZ0()
Definition: PndTrkTrack.h:46
void FillLegendreHisto(Int_t mode)
void SetSortVariable(Double_t sortvar)
Definition: PndTrkHit.h:44
void AddHit(PndTrkHit *hit)
double Y
Definition: anaLmdDigi.C:68
static T Cos(const T &x)
Definition: PndCAMath.h:43
PndTrkCluster CreateClusterByMixedDistance(double fitm, double fitq)
__m128 v
Definition: P4_F32vec4.h:4
PndTrkHit * GetHit(int index)
void DeleteZoneAroundXYLegendre(double x, double y)
TVector3 GetIntersection2()
Definition: PndTrkSkewHit.h:35
void ComputeTraAndRot(PndTrkHit *hit, Double_t &delta, Double_t trasl[2])
TClonesArray * fMvdPixelHitArray
TVector2 GetCenter()
Definition: PndTrkTrack.h:44
void SetIRegion(int iregion)
Definition: PndTrkCluster.h:46
PndTrkHit * GetHit(int index)
void AddCluster(PndTrkCluster *cluster)
int ExtractLegendreMaximum(double &theta_max, double &r_max)
Int_t GetHitID()
Definition: PndTrkHit.h:56
Double_t ComputePhi(TVector3 hit)
virtual InitStatus Init()
Bool_t IsSttParallel()
Definition: PndTrkHit.h:70
void RePrepareLegendre(PndTrkCluster *cluster)
int GetLayerID()
Definition: PndSttTube.cxx:128
Int_t GetSensorID()
Definition: PndTrkHit.h:60
void DrawZGeometry(int whichone=1, double phimin=0, double phimax=360, double zmin=-43, double zmax=113)
void ComputeCharge()
Int_t mode
Definition: autocutx.C:47
Int_t GetCharge()
Definition: PndTrkTrack.h:57
PndTrkConformalTransform * conform
void AddHit(PndTrkConformalHit *chit)
void DrawGeometryConf(double x1, double y1, double x2, double y2)
PndTrkHit * FindMvdStripReferenceHit()
Int_t a
Definition: anaLmdDigi.C:126
TClonesArray * fTubeArray
Bool_t DoesConfHitBelong(PndTrkConformalHit *hit, double fitm, double fitp)
Int_t GetIRegion()
Definition: PndTrkHit.h:64
Int_t GetDetectorID()
Definition: PndTrkHit.h:57
#define MVDSTRIP
PndTrkCluster GetSttParallelHitList()
Double_t GetPhi2()
Definition: PndTrkSkewHit.h:38
PndTrackCand GetTrackCand()
Definition: PndTrack.h:47
Double_t
std::vector< std::pair< double, double > > fFoundPeaks
Bool_t ZPhiFit(int iter, PndTrkCluster *cluster, double &fitm, double &fitp)
Double_t GetDistance(PndTrkHit *fromhit)
Definition: PndTrkHit.cxx:83
PndTrkConformalHit * GetHit(int index)
TArrayI GetNeighborings()
Definition: PndSttTube.cxx:137
PndTrkConformalHit GetConformalHit(PndTrkHit *hit)
PndTrkSdsHitList * InstanciateStrip()
int ExtractZoomMaximum(double &theta_max, double &r_max)
#define STTPARALDISTANCE
Double_t y0
Definition: checkhelixhit.C:71
void Draw(Color_t color=kBlack)
TVector3 GetPosition()
Definition: PndTrkHit.h:62
PndMCTrack * track
Definition: anaLmdCluster.C:89
TVector3 GetPosition()
Definition: PndSttTube.cxx:87
void SetPosition(TVector3 pos)
Definition: PndTrkHit.h:47
FairTrackParP GetParamLast()
Definition: PndTrack.h:50
TVector2 ComputeTangentInPoint(double xc, double yc, TVector2 point)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
void FillZoomHisto(double x, double y, double radius)
TClonesArray * fTrackCandArray
TClonesArray * FillTubeArray()
void SetOrigin(double x, double y, double delta)
void Draw(Color_t color=kBlack)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
PndTrkCluster CreateSkewHitList(PndTrkTrack *track)
Bool_t ConstrainedStraightLineFit(Double_t x0, Double_t y0, Double_t &fitm, Double_t &fitp)
PndTrkCluster * CleanupZPhiFit(PndTrkCluster *cluster, double fitm, double fitp)
void ExtractLegendreSingleLineParameters(double &slope, double &intercept)
static PndGeoHandling * Instance()
void RegisterTrack(PndTrkTrack *track)
PndTrkCluster CreateClusterByConfDistance(double fitm, double fitq)
PndTrkSdsHitList * mvdpixhitlist
double GetDistanceFromTrack(double fitm, double fitp)
Bool_t IsUsed()
Definition: PndTrkHit.h:58
Int_t ApplyLegendre(double &theta_max, double &r_max)
double dx
virtual void Exec(Option_t *opt)
double X
Definition: anaLmdDigi.C:68
TClonesArray * fSttHitArray
Double_t GetXYDistanceFromTrack(double x0, double y0, double R)
Definition: PndTrkHit.cxx:105
void DeleteZoneAroundXYZoom(double x, double y)
PndTrkCluster GetMvdPixelHitList()
Int_t ComputeSegmentCircleIntersection(TVector2 ex1, TVector2 ex2, double xc, double yc, double R, TVector2 &intersection1, TVector2 &intersection2)
Definition: PndTrkTools.cxx:77
void Draw(Color_t color)
Definition: PndTrkHit.cxx:109
Int_t GetNofHits()
Definition: PndTrkHitList.h:43
Bool_t DoesContain(PndTrkHit *hit)
TVector3 GetIntersection1()
Definition: PndTrkSkewHit.h:34
Double_t GetXYDistance(PndTrkHit *fromhit)
Definition: PndTrkHit.cxx:94
PndTrkConformalTransform * GetConformalTransform()
TClonesArray * fTrackArray
Bool_t StraightLineFit(Double_t &fitm, Double_t &fitp)
PndTrkHit * FindSttReferenceHit()
void SetZ0(double z0)
Definition: PndTrkTrack.h:40
void LightCluster(PndTrkCluster *cluster)
PndTrkConformalHit GetConformalSttHit(PndTrkHit *hit)
ClassImp(PndAnaContFact)
double Z
Definition: anaLmdDigi.C:68
TTree * t
Definition: bump_analys.C:13
double CorrectZ(PndTrkCluster *cluster, double deltaz, double fitm, double fitp)
void SetConformalTransform(PndTrkConformalTransform *conformal)
PndSdsMCPoint * hit
Definition: anasim.C:70
Double_t GetIsochrone()
Definition: PndTrkHit.h:63
Double_t angle
#define MVDPIXEL
PndTrkCluster CreateClusterByRealDistance(double xc0, double yc0, double R0)
Int_t GetNofHits()
Definition: PndTrkCluster.h:52
PndTrkCluster CreateClusterByDistance(Int_t mode, double fitm, double fitq)
Double_t Pi
int GetSectorID()
Definition: PndSttTube.cxx:124
#define SKEW_ANGLE
PndTrkSdsHitList * mvdstrhitlist
PndTrkFitter * fFitter
Bool_t DoesRealHitBelong(PndTrkHit *hit, double x0, double y0, double R)
Int_t GetTubeID()
Definition: PndTrkHit.h:61
Double_t R
Definition: checkhelixhit.C:61
void DrawHits(PndTrkHitList *hitlist)
Double_t GetTanL()
Definition: PndTrkTrack.h:45
PndTrkCluster GetMvdStripHitList()
TVector3 GetWireDirection()
Definition: PndSttTube.cxx:107
PndTrkCluster CreateSttCluster(PndTrkHit *firsthit)
Bool_t IsSttSkew()
Definition: PndTrkHit.h:71
FairTrackParP GetParamFirst()
Definition: PndTrack.h:49
TClonesArray * fMvdStripHitArray
PndTrkCluster CleanUpSkewHitList(PndTrkCluster *skewhitlist)
PndTrkConformalHitList * conformalhitlist
void SetPointToFit(double x, double y, double sigma)
Bool_t IsRegion(Int_t iregion)
Definition: PndTrkHit.h:65
PndTrkSdsHitList * InstanciatePixel()