2 #include "FairGeoNode.h"
3 #include "FairRootManager.h"
4 #include "FairRunAna.h"
5 #include "FairRuntimeDb.h"
7 #include "TClonesArray.h"
10 #include "TLorentzVector.h"
23 #include "Math/GSLMinimizer.h"
24 #include "Math/Functor.h"
26 #include "Math/Minimizer.h"
27 #include "Math/Factory.h"
28 #include "Math/Functor.h"
50 std::vector<double> ti;
51 std::vector<double>
fi;
52 std::vector<size_t> it;
53 double nopt_, beta_, nnz_;
114 double thc0(
double thc_,
double phc_,
double nopt,
double beta,
double nnz)
122 if (ctht>1) ctht = 1;
123 if (cthc>1) cthc = 1;
128 Double_t cthc_ = cthc, sthc_ = sthc;
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;
139 B0 = 4*stht2*sphc2_*sthc_*sthc_;
140 B1 = 8*stht2*sphc2_*sthc_*cthc_;
142 C0 = 4*nopt2*stht2*sthc2;
153 double fNopt, fBeta, fNnz;
154 double thcMid, thcMin, thcMax;
156 double thc(
const double phic,
161 if ((nopt!=fNopt)||(beta!=fBeta)||(nnz!=fNnz)) {
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;
188 return thc0(thc_,phic,nopt,beta,nnz);
267 double Chi2_v1(
const double *xx )
269 const double nopt = nopt_;
270 const double beta = xx[0];
271 const double nnz = nnz_;
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;
281 int Minimizer_v1(
const char * minName =
"Minuit2",
282 const char *algoName =
"" )
297 ROOT::Math::Minimizer*
min =
298 ROOT::Math::Factory::CreateMinimizer(minName, algoName);
301 min->SetMaxFunctionCalls(1000000);
302 min->SetMaxIterations(10000);
303 min->SetTolerance(1e-12);
304 min->SetPrintLevel(0);
308 ROOT::Math::Functor
f(&Chi2_v1,1);
312 min->SetVariable(0,
"beta", beta_, 0.001);
317 const double *xs = min->X();
318 const double *dxs = min->Errors();
322 chi2_ = min->MinValue();
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_;
337 double Chi2_v2(
const double *xx )
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]);
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;
362 int Minimizer_v2(
const char * minName =
"Minuit2",
363 const char *algoName =
"" )
378 ROOT::Math::Minimizer* min =
379 ROOT::Math::Factory::CreateMinimizer(minName, algoName);
382 min->SetMaxFunctionCalls(1000000);
383 min->SetMaxIterations(10000);
384 min->SetTolerance(1e-12);
385 min->SetPrintLevel(0);
389 ROOT::Math::Functor
f(&Chi2_v2,5);
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_);
402 const double *xs = min->X();
403 const double *dxs = min->Errors();
415 chi2_ = min->MinValue();
429 FairRootManager *fManager =FairRootManager::Instance();
442 fTrackPosition(0.,0.,0.),
443 fTrackDirection(0.,0.,0.),
463 fGeoVersion(version),
467 fTrackPosition(0.,0.,0.),
468 fTrackDirection(0.,0.,0.),
485 nlayers = nlayers ? nlayers : 3;
487 FairRootManager *fManager = FairRootManager::Instance();
490 fRichPDHit =
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"RichPDHit"));
495 Double_t zain = richOffset.Z() + aerogelOffset.Z();
496 fZamid = zain + 0.5*aerogelSize.Z();
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;
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());
517 for(UInt_t
i=0;
i<flatMirrorY.size()-1;
i++) {
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));
530 TVector3 norm = (TVector3(-1,0,0).Cross(TVector3(0,
531 flatMirrorY[i+1]-flatMirrorY[i],
532 flatMirrorZ[i+1]-flatMirrorZ[i]))).Unit();
536 for(UInt_t
i=0;
i<flatMirrorY.size()-1;
i++) {
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));
549 TVector3 norm = (TVector3(-1,0,0).Cross(TVector3(0,
550 -flatMirrorY[i+1]+flatMirrorY[i],
551 flatMirrorZ[i+1]-flatMirrorZ[i]))).Unit();
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);
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;
582 gInvCovMatr.ResizeTo(4,4);
583 gInvCovMatr = covMatr.Invert();
589 Float_t &chi2, Float_t &chTh, Float_t &dChTh, Int_t &nph ) {
591 if (
fRichPDHit->GetEntriesFast()==0 )
return;
594 TVectorT<double>
evt(4), evto(4);
601 TVector3
pos = pos0 + tam*dir0 + TVector3(evto[0],evto[1],0.);
604 dir.SetTheta(dir0.Theta()+evto[2]);
605 dir.SetPhi(dir0.Phi()+evto[3]);
614 tTrack = dir.Theta();
624 if (photons.size()) {
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_);
689 for(
size_t j=0; j<2; j++) {
690 std::vector<Double_t> bi(nch,0);
694 for(UInt_t
i=0;
i<photons.size();
i++) {
695 Double_t thcc = photons.at(
i).GetTheta();
697 Double_t thcm = thc(phcc,nopt,beta,nnz);
699 Int_t ib = (b-bmin)/(bmax-bmin)*nch;
701 if ((ib>=0)&&(ib<nch)&&
std::fabs(dt)<dtm) {
710 beta = bmin+ibm*(bmax-bmin)/nch;
716 std::vector<double> &ph,
717 std::vector<double> &th,
718 std::vector<PndRichPhoton> photons,
724 it.resize(photons.size());
725 ph.resize(photons.size());
726 th.resize(photons.size());
734 for(UInt_t
i=0;
i<photons.size();
i++) {
735 TVector3
hit = photons.at(
i).GetHitPos();
739 if (((hit.X()!=hitx)||(hit.Y()!=hity))&&(hity!=10)) {
740 Double_t thcm = thc(phccc,nopt,beta,nnz);
749 Double_t thcc = photons.at(
i).GetTheta();
751 Double_t thcm = thc(phcc,nopt,beta,nnz);
763 Double_t thcm = thc(phccc,nopt,beta,nnz);
796 std::vector<PndRichPhoton> ph;
797 for(
size_t ih=0; ih<
nHits; ih++ ) {
830 vector<PndRichMirrorSegment*> segs;
832 if (phot.
TrackCalc()) ph.push_back(phot);
838 if (phot.
TrackCalc()) ph.push_back(phot);
847 if (phot.
TrackCalc()) ph.push_back(phot);
std::vector< PndRichMirrorSegment > fMirrSegs
friend F32vec4 acos(const F32vec4 &a)
void SetMirror(std::vector< PndRichMirrorSegment * > mirrors)
friend F32vec4 cos(const F32vec4 &a)
std::vector< double > GetDThetas()
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)
friend F32vec4 sqrt(const F32vec4 &a)
std::vector< Double_t > phDetZ()
friend F32vec4 sin(const F32vec4 &a)
std::vector< double > GetThetas()
TString ctht(TString pts, TString exts="px py pz")
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
std::vector< Double_t > phDetY()
double BetaPeakFinding(std::vector< PndRichPhoton > photons, Double_t nopt, Double_t nnz)
void SetNormal(TVector3 normal)
TVectorT< double > gResVect
PndRichGeo * fGeo
PndRichPDHit TCA.
void AppendFlatMirrorReflections(std::vector< PndRichPhoton > &ph, TVector3 hit, Double_t hitTime, PndRichBarPoint *track)
void SetHitTime(Double_t hitTime)
TString tht(TString pts, TString exts="px py pz")
virtual Double_t GetTime()
TVector3 GetPosition() const
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
void SetMomentum0(TVector3 dir)
friend F32vec4 fabs(const F32vec4 &a)
std::vector< Double_t > flatMirrorZGlob()
void SetDimensions(TVector3 dims)
void SetPosition0(TVector3 pos)
TMatrixT< double > gRotMatr
std::vector< double > GetPhis()
std::vector< PndRichPhoton > CherenkovPhotonListFlat(PndRichBarPoint *track)
PndPidEmcAssociatorTask * ts
std::vector< Double_t > flatMirrorYGlob()