FairRoot/PandaRoot
PndRichReco.cxx
Go to the documentation of this file.
1 #include "PndRichReco.h"
2 #include "FairGeoNode.h"
3 #include "FairRootManager.h"
4 #include "FairRunAna.h"
5 #include "FairRuntimeDb.h"
6 
7 #include "TClonesArray.h"
8 
9 #include "PndMCTrack.h"
10 #include "TLorentzVector.h"
11 
12 #include "PndRichGeo.h"
13 #include "PndRichPhoton.h"
14 #include "PndRichPDHit.h"
15 #include "PndRichMirrorSegment.h"
16 #include "PndRichHitFinder.h"
17 
18 #include "TH1F.h"
19 #include "TF1.h"
20 #include "TProfile.h"
21 #include <cmath>
22 
23 #include "Math/GSLMinimizer.h"
24 #include "Math/Functor.h"
25 
26 #include "Math/Minimizer.h"
27 #include "Math/Factory.h"
28 #include "Math/Functor.h"
29 #include "TRandom2.h"
30 #include "TError.h"
31 #include <iostream>
32 #include <algorithm>
33 
34 #include <TVectorD.h>
35 
36 namespace {
37 
38  // Show usage with all the possible minimizers.
39  // Minimize the Rosenbrock function (a 2D -function)
40  // This example is described also in
41  // http://root.cern.ch/drupal/content/numerical-minimization#multidim_minim
42  // input : minimizer name + algorithm name
43  // randomSeed: = <0 : fixed value: 0 random with seed 0; >0 random with given seed
44  //
45  // Author: L. Moneta Dec 2010
46 
47 
48 //------------------------------------------------------------------
49 
50  std::vector<double> ti;
51  std::vector<double> fi;
52  std::vector<size_t> it;
53  double nopt_, beta_, nnz_;
54  double dbeta_; //, dnopt_, dnnz_; //[R.K.03/2017] unused variable
55  double chi2_;
56 
57  // //[R.K.03/2017] unused function?
58  //double thc_old(const double phic,
59  //const double nopt,
60  //const double beta,
61  //const double nnz0)
62  //{
63  //Double_t cthc = 1.0/nopt/beta;
64  //Double_t nnz = nnz0;
65  //if (nnz>1) nnz = 1;
66  //if (cthc>1) cthc = 1;
67  //Double_t sthc = std::sqrt(1-cthc*cthc);
68  //Double_t nng = nnz*cthc+std::sqrt(1-nnz*nnz)*sthc*std::cos(phic);
69  //Double_t cdthc = nopt*(1-nng*nng);
70  //cdthc = cdthc + std::sqrt(std::fabs(1-nopt*cdthc))*nng;
71  //if (cdthc>1) cdthc = 1;
72  //return std::acos(cdthc)+std::acos(cthc);
73  //}
74  //[R.K.03/2017] unused function
75  //double thc_v1(const double phic,
76  //const double nopt,
77  //const double beta,
78  //const double nnz0)
79  //{
80  //Double_t cphc_ = std::cos(phic);
81  //Double_t sphc_ = std::sin(phic);
84  //Double_t ctht = nnz0;
85  //Double_t cthc = 1.0/nopt/beta;
86  //if (ctht>1) ctht = 1;
87  //if (cthc>1) cthc = 1;
88  //Double_t stht = std::sqrt(1-ctht*ctht);
89  //Double_t sthc = std::sqrt(1-cthc*cthc);
90  //Double_t cphc = cphc_;
91  //Double_t nng, cthc_, sthc_, sphc;
92  //for(Int_t i=0; i<5; i++) {
93  //nng = ctht*cthc + stht*sthc*cphc;
94  //cthc_ = 1.0/beta + ctht*(std::sqrt(std::fabs(1-nopt*nopt*(1-nng*nng)))-nopt*nng);
95  //if (cthc_>1) cthc_ = 1;
96  //sthc_ = std::sqrt(1-cthc_*cthc_);
97  //sphc = sphc_/nopt*sthc_/sthc;
98  //Double_t cphc2 = 1-sphc*sphc;
99  //Double_t cphcp, cphcm;
100  //if (cphc2>=0) {
101  //cphcp = std::sqrt(cphc2);
102  //cphcm = -cphcp;
103  //} else {
104  //cphcp = 0*cphc_;
105  //cphcm = 0*cphc_;
106  //}
107  //Double_t np = cphcp*cphc_+sphc*sphc_;
108  //Double_t nm = cphcm*cphc_+sphc*sphc_;
109  //cphc = np>nm ? cphcp : cphcm;
110  //}
111  //return std::acos(cthc_);
112  //}
113 
114  double thc0(double thc_, double phc_, double nopt, double beta, double nnz)
115  {
116  //Double_t cphc_ = std::cos(phc_); //[R.K. 01/2017] unused variable?
117  Double_t sphc_ = std::sin(phc_);
118  Double_t sphc2_ = sphc_*sphc_;
119  Double_t nopt2 = nopt*nopt;
120  Double_t ctht = nnz;
121  Double_t cthc = 1.0/nopt/beta;
122  if (ctht>1) ctht = 1;
123  if (cthc>1) cthc = 1;
124  Double_t stht2 = 1-ctht*ctht;
125  Double_t sthc2 = 1-cthc*cthc;
126  //Double_t stht = std::sqrt(stht2); //[R.K. 01/2017] unused variable?
127  Double_t sthc = std::sqrt(sthc2);
128  Double_t cthc_ = cthc, sthc_ = sthc;
129  Double_t p;
130  Double_t A0, A1;//, A2; //[R.K. 01/2017] unused variable?
131  Double_t B0, B1;//, B2; //[R.K. 01/2017] unused variable?
132  Double_t C0;
133  Double_t F0, F1;//, F2; //[R.K. 01/2017] unused variable?
134  for(Int_t i=0; i<10; i++) {
135  p = (cthc_-nopt*cthc)/ctht;
136  A0 = (1-nopt2)/p-p-2*nopt*ctht*cthc;
137  A1 = ((1-nopt2)/p/p+1)*sthc_/ctht;
138  //A2 = ((1-nopt2)*(cthc_+2*sthc_*sthc_/p/ctht)/p/p+cthc_)/ctht;
139  B0 = 4*stht2*sphc2_*sthc_*sthc_;
140  B1 = 8*stht2*sphc2_*sthc_*cthc_;
141  //B2 = 8*stht2*sphc2_*(cthc_*cthc_-sthc_*sthc_);
142  C0 = 4*nopt2*stht2*sthc2;
143  F0 = A0*A0+B0-C0;
144  F1 = 2*A0*A1+B1;
145  //F2 = 2*A0*A2+2*A1*A1+B2;
146  thc_ -= F0/F1;
147  cthc_ = std::cos(thc_);
148  sthc_ = std::sin(thc_);
149  }
150  return thc_;
151  }
152 
153  double fNopt, fBeta, fNnz;
154  double thcMid, thcMin, thcMax;
155 
156  double thc(const double phic,
157  const double nopt,
158  const double beta,
159  const double nnz)
160  {
161  if ((nopt!=fNopt)||(beta!=fBeta)||(nnz!=fNnz)) {
162  fNopt = nopt;
163  fBeta = beta;
164  fNnz = nnz;
165 
166  Double_t cthc = 1.0/fNopt/fBeta;
167  Double_t ctht = fNnz;
168  Double_t thc = acos(cthc);
169  Double_t tht = acos(ctht);
170  Double_t dthp = tht + thc;
171  Double_t dthm = tht - thc;
172  Double_t cdthp = cos(dthp), sdthp = sin(dthp);
173  Double_t cdthm = cos(dthm), sdthm = sin(dthm);
174  Double_t rp = 1-fNopt*fNopt*sdthp*sdthp;
175  Double_t rm = 1-fNopt*fNopt*sdthm*sdthm;
176  thcMax = acos(fNopt*cthc-ctht*(fNopt*cdthp-sqrt(rp>0?rp:0)));
177  thcMin = acos(fNopt*cthc-ctht*(fNopt*cdthm-sqrt(rm>0?rm:0)));
178  thcMid = ((thcMin+thcMax)/2+thc)/2;
179  }
180  Double_t thc_ = std::cos(phic)>0 ? 0.7*thcMid : 1.3*thcMid;
181  //Double_t thc_ = std::cos(phic)>0 ? 0.9*thcMin : 1.1*thcMax;
182  //Double_t cphc_ = std::cos(phic);
183  //Double_t thc_ = thcMid;
184  //thc_ += cphc_*( cphc_>0 ? thcMin-thcMid : thcMid-thcMax );
185  //thc_ += thcMid * ( cphc_>0 ? -0.2 : 0.2 );
186  //thc_ = 1.1*( cphc_>0 ? thcMin : thcMax );
187  //Double_t thc_ = acos(1.0/fNopt) - 0.1*cos(phic);
188  return thc0(thc_,phic,nopt,beta,nnz);
189  }
190 
191  //[R.K.03/2017] unused function
192  //double Chi2(const double *xx )
193  //{
194  //const double nopt = xx[0];
195  //const double beta = xx[1];
196  //const double nnz = xx[2];
197  //double Chi2_ = 0;
198  //size_t n = fi.size();
199  //for(size_t i=0;i<n;i++) {
200  //double chi = (ti.at(i) - thc(fi.at(i),nopt,beta,nnz))/0.05;
201  //Chi2_ += chi*chi;
202  //}
203  //return Chi2_;
204  //}
205 
206  //[R.K.03/2017] unused function
207  //int Minimizer(const char * minName = "Minuit2",
208  //const char *algoName = "" ,
209  //int randomSeed = -1)
210  //{
223  //ROOT::Math::Minimizer* min =
224  //ROOT::Math::Factory::CreateMinimizer(minName, algoName);
225 
227  //min->SetMaxFunctionCalls(1000000); // for Minuit/Minuit2
228  //min->SetMaxIterations(10000); // for GSL
229  //min->SetTolerance(1e-12);
230  //min->SetPrintLevel(0);
231 
234  //ROOT::Math::Functor f(&Chi2,3);
235  //double step[3] = {0.00,0.001,0.00};
236 
238 
239  //double variable[3] = { nopt_, beta_, nnz_ };
240 
241  //min->SetFunction(f);
242 
244  //min->SetVariable(0,"nopt",variable[0], step[0]);
245  //min->SetVariable(1,"beta",variable[1], step[1]);
246  //min->SetVariable(2,"nnz",variable[2], step[2]);
247 
249  //min->Minimize();
250 
251  //const double *xs = min->X();
252  //const double *dxs = min->Errors();
253 
254  //nopt_ = xs[0];
255  //beta_ = xs[1];
256  //nnz_ = xs[2];
257  //dnopt_ = dxs[0];
258  //dbeta_ = dxs[1];
259  //dnnz_ = dxs[2];
260  //chi2_ = min->MinValue();
261 
262  //return 0;
263  //}
264 
265 //---------------------------------------------------------------------------
266 
267  double Chi2_v1(const double *xx )
268  {
269  const double nopt = nopt_;
270  const double beta = xx[0];
271  const double nnz = nnz_;
272  double Chi2_ = 0;
273  size_t n = fi.size();
274  for(size_t i=0;i<n;i++) {
275  double chi = (ti.at(i) - thc(fi.at(i),nopt,beta,nnz))/0.0025;
276  Chi2_ += chi*chi;
277  }
278  return Chi2_;
279  }
280 
281  int Minimizer_v1(const char * minName = "Minuit2",
282  const char *algoName = "" )
283  //, int randomSeed = -1) // //[R.K.03/2017] unused variable(s)
284  {
285  // create minimizer giving a name and a name (optionally) for the specific
286  // algorithm
287  // possible choices are:
288  // minName algoName
289  // Minuit /Minuit2 Migrad, Simplex,Combined,Scan (default is Migrad)
290  // Minuit2 Fumili2
291  // Fumili
292  // GSLMultiMin ConjugateFR, ConjugatePR, BFGS,
293  // BFGS2, SteepestDescent
294  // GSLMultiFit
295  // GSLSimAn
296  // Genetic
297  ROOT::Math::Minimizer* min =
298  ROOT::Math::Factory::CreateMinimizer(minName, algoName);
299 
300  // set tolerance , etc...
301  min->SetMaxFunctionCalls(1000000); // for Minuit/Minuit2
302  min->SetMaxIterations(10000); // for GSL
303  min->SetTolerance(1e-12);
304  min->SetPrintLevel(0);
305 
306  // create funciton wrapper for minmizer
307  // a IMultiGenFunction type
308  ROOT::Math::Functor f(&Chi2_v1,1);
309  min->SetFunction(f);
310 
311  // Set the beta variable to be minimized!
312  min->SetVariable(0, "beta", beta_, 0.001);
313 
314  // do the minimization
315  min->Minimize();
316 
317  const double *xs = min->X();
318  const double *dxs = min->Errors();
319 
320  beta_ = xs[0];
321  dbeta_ = dxs[0];
322  chi2_ = min->MinValue();
323 
324  return 0;
325  }
326 
327 //---------------------------------------------------------------------------
328 
329  TMatrixT<double> gInvCovMatr;
331  std::vector<PndRichPhoton> photons;
332  double xTrack, yTrack, zTrack, tTrack, fTrack;
333  double xTrack_, yTrack_, tTrack_, fTrack_;
334  double dxTrack_, dyTrack_, dtTrack_, dfTrack_;
335  TVector3 dir_;
336 
337  double Chi2_v2(const double *xx )
338  {
339  const double nopt = nopt_;
340  const double beta = xx[0];
341  const double nnz = nnz_;
342  TVectorT<double> dTrackPars(4);
343  dTrackPars[0] = xx[1] - xTrack;
344  dTrackPars[1] = xx[2] - yTrack;
345  dTrackPars[2] = xx[3] - tTrack;
346  dTrackPars[3] = xx[4] - fTrack;
347  double Chi2_ = dTrackPars*(gInvCovMatr*dTrackPars);
348  size_t n = it.size();
349  for(size_t i=0;i<n;i++) {
350  dir_.SetMagThetaPhi(1.0,xx[3],xx[4]);
351  track->SetMomentum0(dir_);
352  track->SetPosition0(TVector3(xx[1],xx[2],zTrack));
353  double theta = photons[it.at(i)].GetTheta();
354  double phi = photons[it.at(i)].GetPhi();
355  double chi = (theta - thc(phi,nopt,beta,nnz))/0.0025;
356  Chi2_ += chi*chi;
357  }
358 
359  return Chi2_;
360  }
361 
362  int Minimizer_v2(const char * minName = "Minuit2",
363  const char *algoName = "" )
364  //, int randomSeed = -1) // //[R.K.03/2017] unused variable(s)
365  {
366  // create minimizer giving a name and a name (optionally) for the specific
367  // algorithm
368  // possible choices are:
369  // minName algoName
370  // Minuit /Minuit2 Migrad, Simplex,Combined,Scan (default is Migrad)
371  // Minuit2 Fumili2
372  // Fumili
373  // GSLMultiMin ConjugateFR, ConjugatePR, BFGS,
374  // BFGS2, SteepestDescent
375  // GSLMultiFit
376  // GSLSimAn
377  // Genetic
378  ROOT::Math::Minimizer* min =
379  ROOT::Math::Factory::CreateMinimizer(minName, algoName);
380 
381  // set tolerance , etc...
382  min->SetMaxFunctionCalls(1000000); // for Minuit/Minuit2
383  min->SetMaxIterations(10000); // for GSL
384  min->SetTolerance(1e-12);
385  min->SetPrintLevel(0);
386 
387  // create funciton wrapper for minmizer
388  // a IMultiGenFunction type
389  ROOT::Math::Functor f(&Chi2_v2,5);
390  min->SetFunction(f);
391 
392  // Set the beta variable to be minimized!
393  min->SetVariable(0, "beta", beta_, 0.001);
394  min->SetVariable(1, "xt", xTrack_, dxTrack_);
395  min->SetVariable(2, "yt", yTrack_, dyTrack_);
396  min->SetVariable(3, "theta", tTrack_, dtTrack_);
397  min->SetVariable(4, "phi", fTrack_, dfTrack_);
398 
399  // do the minimization
400  min->Minimize();
401 
402  const double *xs = min->X();
403  const double *dxs = min->Errors();
404 
405  beta_ = xs[0];
406  xTrack_ = xs[1];
407  yTrack_ = xs[2];
408  tTrack_ = xs[3];
409  fTrack_ = xs[4];
410  dbeta_ = dxs[0];
411  dxTrack_ = dxs[1];
412  dyTrack_ = dxs[2];
413  dtTrack_ = dxs[3];
414  dfTrack_ = dxs[4];
415  chi2_ = min->MinValue();
416 
417  return 0;
418  }
419 
420 //------------------------------------------------------------------
421 }
422 
424 
425 //___________________________________________________________
427 {
428  //
429  FairRootManager *fManager =FairRootManager::Instance();
430  fManager->Write();
431 }
432 
433 // ----- Default constructor -------------------------------------------
435  fRichPDHit(0),
436  fGeo(NULL),
437  fEvent(0),
438  fGeoVersion(0),
439  fGeoVersionMirr(0),
440  fParticleID(0),
441  fMirrorLength(0.),
442  fTrackPosition(0.,0.,0.),
443  fTrackDirection(0.,0.,0.),
444  fMirrSegs(),
445  fPhDetAngle(0.),
446  fZamid(0.),
447  gResVect(),
448  gRotMatr()
449 {
450  fGeoVersion = 313;
451  Init(); // init geometry parameters
452  Register();
453 
454 //-----------------------------------------------------
455 }
456 
457 // ----- Default constructor -------------------------------------------
459  :
460  fRichPDHit(0),
461  fGeo(NULL),
462  fEvent(0),
463  fGeoVersion(version),
464  fGeoVersionMirr(0),
465  fParticleID(0),
466  fMirrorLength(0.),
467  fTrackPosition(0.,0.,0.),
468  fTrackDirection(0.,0.,0.),
469  fMirrSegs(),
470  fPhDetAngle(0.),
471  fZamid(0.),
472  gResVect(),
473  gRotMatr()
474 {
475  Init(); // init geometry parameters
476  Register();
477 
478 //-----------------------------------------------------
479 }
480 
482 {
483  size_t nlayers = (fGeoVersion%1000)/100;
485  nlayers = nlayers ? nlayers : 3;
486 
487  FairRootManager *fManager = FairRootManager::Instance();
488  fGeo = new PndRichGeo();
490  fRichPDHit = dynamic_cast<TClonesArray *> (fManager->GetObject("RichPDHit"));
491  //
492  TVector3 richOffset = fGeo->richOffset();
493  TVector3 aerogelOffset = fGeo->aerogelOffset();
494  TVector3 aerogelSize = fGeo->aerogelSize();
495  Double_t zain = richOffset.Z() + aerogelOffset.Z();
496  fZamid = zain + 0.5*aerogelSize.Z(); // midle position of the point of cherenkov photons emission
497  //fZamid = zain + 0.69075*aerogelSize.Z(); // optimal position of the point of cherenkov photons emission
498  //
500  std::vector<Double_t> flatMirrorY = fGeo->flatMirrorYGlob();
501  std::vector<Double_t> flatMirrorZ = fGeo->flatMirrorZGlob();
502  //
503  std::vector<Double_t> phDetY = fGeo->phDetY();
504  std::vector<Double_t> phDetZ = fGeo->phDetZ();
505  TVector3 pPhDet = TVector3(0,phDetY[0],phDetZ[0]+zain);
506  TVector3 nPhDet = TVector3(0,phDetZ[0]-phDetZ[1],phDetY[1]-phDetY[0]).Unit();
507  Int_t ns = flatMirrorY.size()-2;
508  TVector3 pnt, point;
509  for(int i=ns; i>=0; i--) {
510  pnt = TVector3(0,flatMirrorY[i],flatMirrorZ[i]);
511  point = pnt-2*nPhDet*((pnt-pPhDet)*nPhDet);
512  flatMirrorY.push_back(point.Y());
513  flatMirrorZ.push_back(point.Z());
514  }
515  //
517  for(UInt_t i=0; i<flatMirrorY.size()-1; i++) {
518  PndRichMirrorSegment mirrSeg;
519  // middle point on the mirror segment
520  Double_t xm = 0;
521  Double_t ym = (flatMirrorY[i+1]+flatMirrorY[i])/2;
522  Double_t zm = (flatMirrorZ[i+1]+flatMirrorZ[i])/2;
523  mirrSeg.SetPoint(TVector3(xm,ym,zm));
524  // size of the flat mirror segment
525  Double_t dxm = 3*fMirrorLength/2;
526  Double_t dym = std::fabs(flatMirrorY[i+1]-flatMirrorY[i])/2;
527  Double_t dzm = std::fabs(flatMirrorZ[i+1]-flatMirrorZ[i])/2;
528  mirrSeg.SetDimensions(TVector3(dxm,dym,dzm));
529  // normal vector of the flat mirror segment
530  TVector3 norm = (TVector3(-1,0,0).Cross(TVector3(0,
531  flatMirrorY[i+1]-flatMirrorY[i],
532  flatMirrorZ[i+1]-flatMirrorZ[i]))).Unit();
533  mirrSeg.SetNormal(norm.Unit());
534  fMirrSegs.push_back(mirrSeg);
535  }
536  for(UInt_t i=0; i<flatMirrorY.size()-1; i++) {
537  PndRichMirrorSegment mirrSeg;
538  // middle point on the mirror segment
539  Double_t xm = 0;
540  Double_t ym = -(flatMirrorY[i+1]+flatMirrorY[i])/2;
541  Double_t zm = (flatMirrorZ[i+1]+flatMirrorZ[i])/2;
542  mirrSeg.SetPoint(TVector3(xm,ym,zm));
543  // size of the flat mirror segment
544  Double_t dxm = 3*fMirrorLength/2;
545  Double_t dym = std::fabs(flatMirrorY[i+1]-flatMirrorY[i])/2;
546  Double_t dzm = std::fabs(flatMirrorZ[i+1]-flatMirrorZ[i])/2;
547  mirrSeg.SetDimensions(TVector3(dxm,dym,dzm));
548  // normal vector of the flat mirror segment
549  TVector3 norm = (TVector3(-1,0,0).Cross(TVector3(0,
550  -flatMirrorY[i+1]+flatMirrorY[i],
551  flatMirrorZ[i+1]-flatMirrorZ[i]))).Unit();
552  mirrSeg.SetNormal(norm.Unit());
553  fMirrSegs.push_back(mirrSeg);
554  }
555  fEvent = 0;
556 
557  // covariance matrix of track resolutions (for test)
558  double scal = TMath::Pi()/180;
559  double sigx = 0.1, sigy = 0.2, rhoxy = 0.3;
560  double sigt = 0.3*scal, sigf = 0.5*scal, rhotf = -0.5;
561  TMatrixT<double> covMatr(4,4);
562 
563  for(int i=0;i<4;i++)
564  for(int j=0;j<4;j++)
565  covMatr[i][j] = 0;
566  covMatr[0][0] = sigx*sigx;
567  covMatr[0][1] = sigx*sigy*rhoxy;
568  covMatr[1][0] = covMatr[0][1];
569  covMatr[1][1] = sigy*sigy;
570  covMatr[2][2] = sigt*sigt;
571  covMatr[2][3] = sigt*sigf*rhotf;
572  covMatr[3][2] = covMatr[2][3];
573  covMatr[3][3] = sigf*sigf;
574 
575  gResVect.ResizeTo(4);
576  gRotMatr.ResizeTo(4,4);
577  gRotMatr = covMatr.EigenVectors(gResVect);
578  covMatr.Print();
579  gRotMatr.Print();
580  gResVect.Print();
581 
582  gInvCovMatr.ResizeTo(4,4);
583  gInvCovMatr = covMatr.Invert();
584 
585 }
586 
587 //______________________________________________________
588 void PndRichReco::RichFullReconstruction(TVector3 pos0, TVector3 dir0, Float_t ts,
589  Float_t &chi2, Float_t &chTh, Float_t &dChTh, Int_t &nph ) {
590 
591  if ( fRichPDHit->GetEntriesFast()==0 ) return;
592 
593  // randomization with correlation of ideal track parameters (for test)
594  TVectorT<double> evt(4), evto(4);
595  for(int i=0;i<4;i++)
596  evt[i] = 0*gRandom->Gaus(0,sqrt(gResVect[i]));
597  evto = gRotMatr*evt;
598 
599  // finding position of the track in middle depth of the aerogel bar
600  Double_t tam = (fZamid-pos0.Z())/dir0.Z();
601  TVector3 pos = pos0 + tam*dir0 + TVector3(evto[0],evto[1],0.);
602 
603  TVector3 dir(1,0,0);
604  dir.SetTheta(dir0.Theta()+evto[2]);
605  dir.SetPhi(dir0.Phi()+evto[3]);
606  dir = dir.Unit();
607 
608  fTrackTime = ts;
609 
610  track = new PndRichBarPoint(pos,dir,ts);
611  xTrack = pos.X();
612  yTrack = pos.Y();
613  zTrack = pos.Z();
614  tTrack = dir.Theta();
615  fTrack = dir.Phi();
616 
617  // flat mirror
618  if (((fGeoVersionMirr>=11)&&(fGeoVersionMirr<=19))||
619  ((fGeoVersionMirr>=21)&&(fGeoVersionMirr<=29))) {
620  //std::vector<PndRichPhoton> photons;
621  beta_ = 1;
622  dbeta_ = 0;
623  photons = CherenkovPhotonListFlat(track);
624  if (photons.size()) {
625  Double_t nnz = dir.Z();
626  Double_t nopt = 1.05;
627  // beta peak finding
628  Double_t beta = BetaPeakFinding(photons,nopt,nnz);
629  // hits selection
630  HitSelection(it,fi,ti,photons,beta,nopt,nnz,0.03);
631  //
632  nopt_ = nopt;
633  beta_ = beta;
634  nnz_ = nnz;
635  Minimizer_v1();
636 
637  // hits selection
638  HitSelection(it,fi,ti,photons,beta_,nopt_,nnz_,0.01);
639  Minimizer_v1();
640 
641  // fit with track parameters
642  xTrack_ = xTrack;
643  yTrack_ = yTrack;
644  tTrack_ = tTrack;
645  fTrack_ = fTrack;
646  dxTrack_ = 0.001;
647  dyTrack_ = 0.001;
648  dtTrack_ = 0.001;
649  dfTrack_ = 0.001;
650  //Minimizer_v2();
651  }
652 
653  chi2 = chi2_;
654  chTh = beta_;
655  dChTh = dbeta_;
656  nph = fi.size();
657 
658  }
659  fEvent++;
660 }
661 
662 std::vector<double> PndRichReco::GetPhis() { return fi; };
663 
664 std::vector<double> PndRichReco::GetThetas() { return ti; };
665 
666 std::vector<double> PndRichReco::GetDThetas() {
667  size_t n = fi.size();
668  std::vector<double> dth(n);
669  for(size_t i=0;i<n;i++)
670  dth.at(i) = ti.at(i) - thc(fi.at(i),nopt_,beta_,nnz_);
671  return dth;
672 }
673 
674 double PndRichReco::BetaPeakFinding(std::vector<PndRichPhoton> photons,
675  Double_t nopt,
676  Double_t nnz) {
677  // beta peak finding
678  Int_t nch = 60;
679  Double_t bmin = 1.0/nopt;
680  Double_t bmax = 1+(1-bmin)*0.2;
681  //Double_t dbeta = (bmax-bmin)/nch; //[R.K. 01/2017] unused variable?
682  Double_t beta = 1.0;
683  //Double_t thcmin = 0; //[R.K. 01/2017] unused variable?
684  //Double_t thcmax = std::acos(bmin); //[R.K. 01/2017] unused variable?
685  Double_t bim = 0;
686  Int_t ibm = -1;
687  Double_t dtm = 3;//0.5;
688  int nph = 0;
689  for(size_t j=0; j<2; j++) {
690  std::vector<Double_t> bi(nch,0);
691  bim = 0;
692  ibm = -1;
693  nph = 0;
694  for(UInt_t i=0; i<photons.size(); i++) {
695  Double_t thcc = photons.at(i).GetTheta();
696  Double_t phcc = photons.at(i).GetPhi();
697  Double_t thcm = thc(phcc,nopt,beta,nnz);
698  Double_t b = bmin+thcc*(beta-bmin)/thcm;
699  Int_t ib = (b-bmin)/(bmax-bmin)*nch;
700  Double_t dt = photons.at(i).GetTime() - fTrackTime;
701  if ((ib>=0)&&(ib<nch)&&std::fabs(dt)<dtm) {
702  nph++;
703  bi.at(ib)++;
704  if (bim<bi.at(ib)) {
705  bim = bi.at(ib);
706  ibm = ib;
707  }
708  }
709  }
710  beta = bmin+ibm*(bmax-bmin)/nch;
711  }
712  return beta;
713 }
714 
715 void PndRichReco::HitSelection(std::vector<size_t> &it,
716  std::vector<double> &ph,
717  std::vector<double> &th,
718  std::vector<PndRichPhoton> photons,
719  Double_t beta,
720  Double_t nopt,
721  Double_t nnz,
722  Double_t dthc) {
723  //
724  it.resize(photons.size());
725  ph.resize(photons.size());
726  th.resize(photons.size());
727  Double_t hitx, hity = 10;
728  Double_t thccc, phccc, dthccc = 10;
729  //Double_t dthc = 0.03;
730  size_t itccc;
731  Double_t dt = 0;
732  Int_t ind = 0;
733  Double_t dtm = 3;
734  for(UInt_t i=0; i<photons.size(); i++) {
735  TVector3 hit = photons.at(i).GetHitPos();
736  //th.at(ind) = photons.at(i).GetTheta();
737  //ph.at(ind) = photons.at(i).GetPhi();
738  //ind++;
739  if (((hit.X()!=hitx)||(hit.Y()!=hity))&&(hity!=10)) {
740  Double_t thcm = thc(phccc,nopt,beta,nnz);
741  if (std::fabs(thccc-thcm)<dthc && std::fabs(dt)<dtm) {
742  it.at(ind) = itccc;
743  th.at(ind) = thccc;
744  ph.at(ind) = phccc;
745  ind++;
746  }
747  dthccc = 10;
748  }
749  Double_t thcc = photons.at(i).GetTheta();
750  Double_t phcc = photons.at(i).GetPhi();
751  Double_t thcm = thc(phcc,nopt,beta,nnz);
752  Double_t dthccl = std::fabs(thcc-thcm);
753  if (dthccl<dthccc) {
754  itccc = i;
755  dthccc = dthccl;
756  thccc = thcc;
757  phccc = phcc;
758  dt = photons.at(i).GetTime() - fTrackTime;
759  }
760  hitx = hit.X();
761  hity = hit.Y();
762  }
763  Double_t thcm = thc(phccc,nopt,beta,nnz);
764  if (std::fabs(thccc-thcm)<dthc && std::fabs(dt)<dtm) {
765  it.at(ind) = itccc;
766  th.at(ind) = thccc;
767  ph.at(ind) = phccc;
768  ind++;
769  }
770  //
771  /*
772  ph.resize(photons.size());
773  th.resize(photons.size());
774  Double_t dthc = 0.02;
775  Int_t ind = 0;
776  for(UInt_t i=0; i<photons.size(); i++) {
777  Double_t thcc = photons.at(i).GetTheta();
778  Double_t phcc = photons.at(i).GetPhi();
779  Double_t thcm = thc(phcc,nopt,beta,nnz);
780  if (std::fabs(thcc-thcm)<dthc) {
781  th.at(ind) = thcc;
782  ph.at(ind) = phcc;
783  ind++;
784  }
785  }*/
786  it.resize(ind);
787  ph.resize(ind);
788  th.resize(ind);
789 }
790 
791 // Чернова-Лисовского(?) алгоритм восстановления окружностей std::vector<PndRichPhoton> PndRichReco::CherenkovPhotonListFlat( PndRichBarPoint *track ) { size_t nHits = fRichPDHit->GetEntriesFast(); PndRichPDHit* richPDHit = NULL; std::vector<PndRichPhoton> ph; for(size_t ih=0; ih<nHits; ih++ ) { // richPDHit = (PndRichPDHit*) fRichPDHit->At(ih); TVector3 hit = richPDHit->GetPosition(); Double_t hitTime = richPDHit->GetTime(); AppendFlatMirrorReflections(ph,hit,hitTime,track); // if ((fGeoVersionMirr>=21)&&(fGeoVersionMirr<=29)) { Double_t x_hit = hit.X(); // left mirror TVector3 hitLeft = richPDHit->GetPosition(); hitLeft.SetX(fMirrorLength - x_hit); AppendFlatMirrorReflections(ph,hitLeft,hitTime,track); // right mirror TVector3 hitRight = richPDHit->GetPosition(); hitRight.SetX(-fMirrorLength - x_hit); AppendFlatMirrorReflections(ph,hitRight,hitTime,track); } } return ph; } void PndRichReco::AppendFlatMirrorReflections(std::vector<PndRichPhoton> &ph, TVector3 hit, Double_t hitTime, PndRichBarPoint *track) { PndRichPhoton phot; phot.SetHitPos(hit); phot.SetHitTime(hitTime); phot.SetTrack(track); //phot.SetTrackPos(pos); //phot.SetTrackDir(dir); //phot.SetDTime(time); vector<PndRichMirrorSegment*> segs; // direct photon tracks if (phot.TrackCalc()) ph.push_back(phot); // single reflection photon tracks for(UInt_t i=0; i<fMirrSegs.size(); i++) { segs.clear(); segs.push_back(&fMirrSegs[i]); phot.SetMirror(segs); if (phot.TrackCalc()) ph.push_back(phot); } // double reflection photon tracks for(UInt_t i=0; i<fMirrSegs.size()-1; i++) { for(UInt_t j=i+1; j<fMirrSegs.size(); j++) { segs.clear(); segs.push_back(&fMirrSegs[i]); segs.push_back(&fMirrSegs[j]); phot.SetMirror(segs); if (phot.TrackCalc()) ph.push_back(phot); } } } void PndRichReco::Register() { /** This will create a branch in the output tree called PndRichPDPoint, setting the last parameter to kFALSE means: this collection will not be written to the file, it will exist only during the simulation. */ } // -------------------------------------------------------------------------
792 
793 std::vector<PndRichPhoton> PndRichReco::CherenkovPhotonListFlat( PndRichBarPoint *track ) {
794  size_t nHits = fRichPDHit->GetEntriesFast();
795  PndRichPDHit* richPDHit = NULL;
796  std::vector<PndRichPhoton> ph;
797  for(size_t ih=0; ih<nHits; ih++ ) {
798  //
799  richPDHit = (PndRichPDHit*) fRichPDHit->At(ih);
800  TVector3 hit = richPDHit->GetPosition();
801  Double_t hitTime = richPDHit->GetTime();
802  AppendFlatMirrorReflections(ph,hit,hitTime,track);
803  //
804  if ((fGeoVersionMirr>=21)&&(fGeoVersionMirr<=29)) {
805  Double_t x_hit = hit.X();
806  // left mirror
807  TVector3 hitLeft = richPDHit->GetPosition();
808  hitLeft.SetX(fMirrorLength - x_hit);
809  AppendFlatMirrorReflections(ph,hitLeft,hitTime,track);
810  // right mirror
811  TVector3 hitRight = richPDHit->GetPosition();
812  hitRight.SetX(-fMirrorLength - x_hit);
813  AppendFlatMirrorReflections(ph,hitRight,hitTime,track);
814  }
815  }
816  return ph;
817 }
818 
819 void PndRichReco::AppendFlatMirrorReflections(std::vector<PndRichPhoton> &ph,
820  TVector3 hit,
821  Double_t hitTime,
822  PndRichBarPoint *track) {
824  phot.SetHitPos(hit);
825  phot.SetHitTime(hitTime);
826  phot.SetTrack(track);
827  //phot.SetTrackPos(pos);
828  //phot.SetTrackDir(dir);
829  //phot.SetDTime(time);
830  vector<PndRichMirrorSegment*> segs;
831  // direct photon tracks
832  if (phot.TrackCalc()) ph.push_back(phot);
833  // single reflection photon tracks
834  for(UInt_t i=0; i<fMirrSegs.size(); i++) {
835  segs.clear();
836  segs.push_back(&fMirrSegs[i]);
837  phot.SetMirror(segs);
838  if (phot.TrackCalc()) ph.push_back(phot);
839  }
840  // double reflection photon tracks
841  for(UInt_t i=0; i<fMirrSegs.size()-1; i++) {
842  for(UInt_t j=i+1; j<fMirrSegs.size(); j++) {
843  segs.clear();
844  segs.push_back(&fMirrSegs[i]);
845  segs.push_back(&fMirrSegs[j]);
846  phot.SetMirror(segs);
847  if (phot.TrackCalc()) ph.push_back(phot);
848  }
849  }
850 }
851 
853 {
854 
861 }
862 
863 
864 // -------------------------------------------------------------------------
865 
std::vector< PndRichMirrorSegment > fMirrSegs
Definition: PndRichReco.h:39
TVector3 pos
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
void SetMirror(std::vector< PndRichMirrorSegment * > mirrors)
Double_t p
Definition: anasim.C:58
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
std::vector< double > GetDThetas()
TLorentzVector phot
TVector3 aerogelOffset()
Definition: PndRichGeo.h:129
void HitSelection(std::vector< size_t > &it, std::vector< double > &ph, std::vector< double > &th, std::vector< PndRichPhoton > photons, Double_t beta, Double_t nopt, Double_t nnz, Double_t dthc)
void SetTrack(PndRichBarPoint *track)
Int_t i
Definition: run_full.C:25
TTree * b
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
std::vector< Double_t > phDetZ()
Definition: PndRichGeo.h:183
TVector3 aerogelSize()
Definition: PndRichGeo.h:126
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
Double_t fPhDetAngle
Definition: PndRichReco.h:41
std::vector< double > GetThetas()
TString ctht(TString pts, TString exts="px py pz")
Definition: invexp.C:179
int n
TClonesArray * pnt
int evt
Definition: checkhelixhit.C:36
void SetHitPos(TVector3 hit)
void SetPoint(TVector3 point)
void RichFullReconstruction(TVector3 pos, TVector3 dir, Float_t ts, Float_t &chi2, Float_t &chTh, Float_t &dChTh, Int_t &nph)
TClonesArray * fRichPDHit
Definition: PndRichReco.h:28
std::vector< Double_t > phDetY()
Definition: PndRichGeo.h:180
Double_t fZamid
Definition: PndRichReco.h:42
UInt_t fEvent
Definition: PndRichReco.h:31
double BetaPeakFinding(std::vector< PndRichPhoton > photons, Double_t nopt, Double_t nnz)
void SetNormal(TVector3 normal)
TVectorT< double > gResVect
Definition: PndRichReco.h:44
PndRichGeo * fGeo
PndRichPDHit TCA.
Definition: PndRichReco.h:30
Double_t fMirrorLength
Definition: PndRichReco.h:35
int nHits
Definition: RiemannTest.C:16
void AppendFlatMirrorReflections(std::vector< PndRichPhoton > &ph, TVector3 hit, Double_t hitTime, PndRichBarPoint *track)
TFile * fi
Double_t fTrackTime
Definition: PndRichReco.h:43
Double_t
void Register()
void SetHitTime(Double_t hitTime)
PndMCTrack * track
Definition: anaLmdCluster.C:89
TString tht(TString pts, TString exts="px py pz")
Definition: invexp.C:168
TFile * f
Definition: bump_analys.C:12
virtual Double_t GetTime()
Definition: PndRichPDHit.h:47
TVector3 GetPosition() const
Definition: PndRichPDHit.h:50
void init(size_t ver=0)
Definition: PndRichGeo.cxx:82
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
void SetMomentum0(TVector3 dir)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
std::vector< Double_t > flatMirrorZGlob()
Definition: PndRichGeo.h:177
UInt_t fGeoVersionMirr
Definition: PndRichReco.h:33
Double_t phDetAngle()
Definition: PndRichGeo.h:102
void SetDimensions(TVector3 dims)
Double_t mirrorLength()
Definition: PndRichGeo.h:153
void SetPosition0(TVector3 pos)
TVector3 richOffset()
Definition: PndRichGeo.h:117
TMatrixT< double > gRotMatr
Definition: PndRichReco.h:45
UInt_t fGeoVersion
Definition: PndRichReco.h:32
ClassImp(PndAnaContFact)
std::vector< double > GetPhis()
virtual bool TrackCalc()
PndSdsMCPoint * hit
Definition: anasim.C:70
std::vector< PndRichPhoton > CherenkovPhotonListFlat(PndRichBarPoint *track)
PndPidEmcAssociatorTask * ts
Double_t Pi
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72
std::vector< Double_t > flatMirrorYGlob()
Definition: PndRichGeo.h:174