#include "PndRichReco.h" #include "FairGeoNode.h" #include "FairRootManager.h" #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "TClonesArray.h" #include "PndMCTrack.h" #include "TLorentzVector.h" #include "PndRichGeo.h" #include "PndRichPhoton.h" #include "PndRichPDHit.h" #include "TH1F.h" #include "TF1.h" #include "TProfile.h" #include #include "Math/GSLMinimizer.h" #include "Math/Functor.h" #include "Math/Minimizer.h" #include "Math/Factory.h" #include "Math/Functor.h" #include "TRandom2.h" #include "TError.h" #include #include namespace { // Show usage with all the possible minimizers. // Minimize the Rosenbrock function (a 2D -function) // This example is described also in // http://root.cern.ch/drupal/content/numerical-minimization#multidim_minim // input : minimizer name + algorithm name // randomSeed: = <0 : fixed value: 0 random with seed 0; >0 random with given seed // // Author: L. Moneta Dec 2010 //------------------------------------------------------------------ std::vector ti; std::vector fi; double nopt_, beta_, nnz_; double dnopt_, dbeta_, dnnz_; double chi2_; double thc(const double phic, const double nopt, const double beta, const double nnz0) { Double_t cthc = 1.0/nopt/beta; Double_t nnz = nnz0; if (nnz>1) nnz = 1; if (cthc>1) cthc = 1; Double_t sthc = std::sqrt(1-cthc*cthc); Double_t nng = nnz*cthc+std::sqrt(1-nnz*nnz)*sthc*std::cos(phic); Double_t cdthc = nopt*(1-nng*nng); cdthc = cdthc + std::sqrt(std::fabs(1-nopt*cdthc))*nng; if (cdthc>1) cdthc = 1; return std::acos(cdthc)+std::acos(cthc); } double Chi2(const double *xx ) { const double nopt = xx[0]; const double beta = xx[1]; const double nnz = xx[2]; double Chi2_ = 0; size_t n = fi.size(); for(size_t i=0;iSetMaxFunctionCalls(1000000); // for Minuit/Minuit2 min->SetMaxIterations(10000); // for GSL min->SetTolerance(1e-12); min->SetPrintLevel(0); // create funciton wrapper for minmizer // a IMultiGenFunction type ROOT::Math::Functor f(&Chi2,3); double step[3] = {0.00,0.001,0.00}; // starting point double variable[3] = { nopt_, beta_, nnz_ }; min->SetFunction(f); // Set the free variables to be minimized! min->SetVariable(0,"nopt",variable[0], step[0]); min->SetVariable(1,"beta",variable[1], step[1]); min->SetVariable(2,"nnz",variable[2], step[2]); // do the minimization min->Minimize(); const double *xs = min->X(); const double *dxs = min->Errors(); nopt_ = xs[0]; beta_ = xs[1]; nnz_ = xs[2]; dnopt_ = dxs[0]; dbeta_ = dxs[1]; dnnz_ = dxs[2]; chi2_ = min->MinValue(); return 0; } double Chi2_v1(const double *xx ) { const double nopt = nopt_; const double beta = xx[0]; const double nnz = nnz_; double Chi2_ = 0; size_t n = fi.size(); for(size_t i=0;iSetMaxFunctionCalls(1000000); // for Minuit/Minuit2 min->SetMaxIterations(10000); // for GSL min->SetTolerance(1e-12); min->SetPrintLevel(0); // create funciton wrapper for minmizer // a IMultiGenFunction type ROOT::Math::Functor f(&Chi2_v1,1); min->SetFunction(f); // Set the beta variable to be minimized! min->SetVariable(0, "beta", beta_, 0.001); // do the minimization min->Minimize(); const double *xs = min->X(); const double *dxs = min->Errors(); beta_ = xs[0]; dbeta_ = dxs[0]; chi2_ = min->MinValue(); return 0; } //------------------------------------------------------------------ } ClassImp(PndRichReco) //___________________________________________________________ PndRichReco::~PndRichReco() { // FairRootManager *fManager =FairRootManager::Instance(); fManager->Write(); } // ----- Default constructor ------------------------------------------- PndRichReco::PndRichReco() : fRichPDHit(0) { fGeoVersion = 13; FairRootManager *fManager =FairRootManager::Instance(); fGeo = new PndRichGeo(); fGeo->init(fGeoVersion); fRichPDHit = dynamic_cast (fManager->GetObject("RichPDHit")); // TVector3 richOffset = fGeo->richOffset(); TVector3 aerogelOffset = fGeo->aerogelOffset(); TVector3 aerogelSize = fGeo->aerogelSize(); Double_t zain = richOffset.Z() + aerogelOffset.Z(); fZamid = zain + aerogelSize.Z()/2; // fPhDetAngle = fGeo->phDetAngle(); std::vector flatMirrorY = fGeo->flatMirrorYGlob(); std::vector flatMirrorZ = fGeo->flatMirrorZGlob(); // Double_t mirrorLength = fGeo->mirrorLength(); fNumberOfFlatMirrorSegments = flatMirrorY.size()-1; for(UInt_t i=0; iGetEntriesFast()==0 ) return; // finding position of the track in middle depth of the aerogel bar Double_t tam = (fZamid-pos0.Z())/dir.Z(); TVector3 pos = pos0 + tam*dir; // flat mirror if (fGeoVersion==13) { std::vector< std::vector > photonsx; std::vector photons; beta_ = 1; dbeta_ = 0; photons = CherenkovPhotonListFlat(pos,dir,21.8); if (photons.size()) { Double_t nnz = dir.Z(); Double_t nopt = 1.05; // beta peak finding Double_t beta = BetaPeakFinding(photons,nopt,nnz); // hits selection HitSelection(fi,ti,photons,beta,nopt,nnz); // nopt_ = nopt; beta_ = beta; nnz_ = nnz; Minimizer_v1(); } chi2 = chi2_; chTh = beta_; dChTh = dbeta_; nph = fi.size(); } } double PndRichReco::BetaPeakFinding(std::vector photons, Double_t nopt, Double_t nnz) { // beta peak finding Int_t nch = 60; Double_t bmin = 1.0/nopt; Double_t bmax = 1+(1-bmin)*0.2; Double_t dbeta = (bmax-bmin)/nch; Double_t beta = 1.0; Double_t thcmin = 0; Double_t thcmax = std::acos(bmin); Double_t bim = 0; Int_t ibm = -1; int nph = 0; for(size_t j=0; j<2; j++) { std::vector bi(nch,0); bim = 0; ibm = -1; nph = 0; for(UInt_t i=0; i=0)&&(ib &ph, std::vector &th, std::vector photons, Double_t beta, Double_t nopt, Double_t nnz) { // ph.resize(photons.size()); th.resize(photons.size()); Double_t hitx, hity = 10; Double_t thccc, phccc, dthccc = 10; Double_t dthc = 0.03; Double_t dt = 0; Int_t ind = 0; for(UInt_t i=0; i PndRichReco::CherenkovPhotonListFlat( TVector3 pos, TVector3 dir, Double_t time ) { size_t nHits = fRichPDHit->GetEntriesFast(); std::vector ph(nHits*fNumberOfFlatMirrorSegments); PndRichPDHit* richPDHit = NULL; TVector3 axis = TVector3(0,0,1); TVector3 axisTx = axis-dir*(dir*axis); if (axisTx.Mag()) axisTx = axisTx.Unit(); else axisTx = TVector3(1,0,0); TVector3 axisTy = (dir.Cross(axisTx)).Unit(); size_t ind = 0; for(size_t ih=0; ihAt(ih); TVector3 hit = richPDHit->GetPosition(); std::vector pi = FlatMirrorReflections(pos,hit); for(size_t ir=0; irGetTime() - length/30 - time ); ind++; } } } ph.resize(ind); return ph; } vector PndRichReco::FlatMirrorReflections( TVector3 point1, TVector3 point2z ) { vector pi; //photodetector: cell size Double_t sy = point2z.Y()>0 ? 1 : -1; TVector3 nl = TVector3( 0, sy*std::sin(fPhDetAngle), std::cos(fPhDetAngle) ); TVector3 nx = TVector3( 1, 0, 0 ); Double_t l = point2z*nl;; Double_t dl = l - (int)(l/0.32)*0.32; Double_t x = point2z.X(); Double_t dx = x - (int)(x/0.38016)*0.38016; TVector3 point2 = point2z - dl*nl - dx*nx; point2 = point2z; // for(UInt_t i=0; i