#include #include "PDK_MuGamma.h" #include "TMath.h" #include "TFitter.h" #include #include "fiTQun_shared.h" #include "mcguts.h" #include "apscndryC.h" #include using namespace fiTQun_parameters; PDK_MuGamma* PDK_MuGamma::static_PDK_MuGamma; extern"C" { void mcguts(int *ntracks); void trginfo_(float *); void vcrdvccm_(); } PDK_MuGamma::PDK_MuGamma() { std::cout << "Starting PDK_MuGamma Fitter." << std::endl; static_PDK_MuGamma = this; //GetTruePDK_MuGammaParams(tParams); } PDK_MuGamma::~PDK_MuGamma() { std::cout << "PDK routine ended." << std::endl; } //************************************************************************************************************************************ //void PDK_MuGamma::PDK_MuGammaWrapper(int& nDim, double* gout, double& result, double par[], int flg); //************************************************************************************************************************************ void PDK_MuGamma::PDK_MuGammaWrapper(int& nDim, double* gout, double& result, double par[], int flg){ double partmp[fiTQun_shared::nPDK_MuGammaParams]; for (int i=0; ipCherenkovThr(imu)) lnLpnl+=pow((fiTQun_shared::Get()->pCherenkovThr(imu)-par[6]),2.)*10.; if (par[13]pCherenkovThr(ie)) lnLpnl+=pow((fiTQun_shared::Get()->pCherenkovThr(ie)-par[13]),2.)*10.; int PCdumflg; //lnLpnl=0.; result = static_PDK_MuGamma->MuGammaNglogL(partmp,PCdumflg) + lnLpnl; } //************************************************************************************************************************************ //double PDK_MuGamma::RunMinimizer(double *X, int& PCflg, int *flgparfix, double *arStps){ //************************************************************************************************************************************ double PDK_MuGamma::RunMinimizer(double *X, int& PCflg, int *flgparfix, double *arStps){ int nPar = fiTQun_shared::nPDK_MuGammaParams; // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 // X = {X1, Y1, Z1, T1, theta1, phi1, p1, X2, Y2, Z2, T2, theta2, phi2, p2} const double Vtxres=50.; const double t0res=10.; const double angres=TMath::Pi()/16.; const double momres1=X[6]*0.1+20.; const double momres2=X[13]*0.1+5.; // const double Vtxres=500.; // const double t0res=20.; // const double angres=TMath::Pi()/8.; // const double momres1=X[6]*0.2+20.; // const double momres2=X[13]*0.1+5.; const int nRes = 5; double stpsize[nRes]={Vtxres,t0res,angres,momres1,momres2}; if (arStps!=NULL) { for (int i=0; iIsQuiet() ) { double p1 = -1; minimizer->ExecuteCommand("SET PRINTOUT",&p1,1); } minimizer->SetFCN(PDK_MuGammaWrapper); minimizer->SetParameter(0, "x1", X[0],stpsize[0],0,0); minimizer->SetParameter(1, "y1", X[1],stpsize[0],0,0); minimizer->SetParameter(2, "z1", X[2],stpsize[0],0,0); minimizer->SetParameter(3, "t1", X[3],stpsize[1],0,0); minimizer->SetParameter(4, "theta1", X[4],stpsize[2],0,0); minimizer->SetParameter(5, "phi1", X[5],stpsize[2],0,0); minimizer->SetParameter(6, "p1", X[6],stpsize[3],0,0); minimizer->SetParameter(7, "x2", X[7],stpsize[0],0,0); minimizer->SetParameter(8, "y2", X[8],stpsize[0],0,0); minimizer->SetParameter(9, "z2", X[9],stpsize[0],0,0); minimizer->SetParameter(10,"t2", X[10],stpsize[1],0,0); minimizer->SetParameter(11,"theta2", X[11],stpsize[2],0,0); minimizer->SetParameter(12,"phi2", X[12],stpsize[2],0,0); minimizer->SetParameter(13,"p2", X[13],stpsize[4],0,0); if (flgparfix!=NULL) { for (int i=0; iFixParameter(i); } } } if (fiTQun_shared::Get()->GetTimeflg() == false) minimizer->FixParameter(3); Double_t CmdOpts[2]={3000,0.1}; int ierflg = minimizer->ExecuteCommand("SIMPLEX",CmdOpts,1); // minimizer->ExecuteCommand("IMPROVE",0,0); for (int i=0; i < nPar; i++) { X[i]=minimizer->GetParameter(i); } if(same3Vertex) for(int i = 0; i < 3; i++) X[i+7] = X[i]; double pCthr1=fqshared->pCherenkovThr(imu); if (X[6]pCherenkovThr(ie); if (X[13]GetMinuit()->fNfcn; delete minimizer; double tmpnglnL = MuGammaNglogL(X,PCflg); if (ierflg!=0) { PCflg=-1-1000*nIter;//didn't converge! std::cout << "MINUIT did not converge!!! n_Iter=" << nIter << std::endl; // return 1e100; } return tmpnglnL; } //************************************************************************************************************************************ //double PDK_MuGamma::SetPDK_MuGammaSeed(double* fitpars, int& PCflg, bool seedpi0mass, bool translatevertex); //************************************************************************************************************************************ double PDK_MuGamma::SetPDK_MuGammaSeed(double* fitpars, int& PCflg){ // first 7 values of fitpars should be filled with 1-ring mu-like fit result as input const int nPoints = 100; double theta[nPoints]; double phi[nPoints]; double magic = 3.6; theta[0] = TMath::Pi(); phi [0] = 0.; for (int ipt = 1; ipt=0; il--) { lowestnglnL[il] = 1.e100; iLowestnglnL[il] = -1; itLowestnglnL[il] = -1; } const int ntPoints = 11; double toffsets[ntPoints] = {50., 40., 30., 25., 20., 15., 12.5, 10., 7.5, 5., 2.5}; for (int itoff=0; itoff=0; il--) { if (nglnL < lowestnglnL[il]) { lowestnglnL[il+1] = lowestnglnL[il]; iLowestnglnL[il+1] = iLowestnglnL[il]; itLowestnglnL[il+1] = itLowestnglnL[il]; lowestnglnL[il] = nglnL; iLowestnglnL[il] = ipt; itLowestnglnL[il] = itoff; // std::cout << "!!!!!! moving (t,theta,phi,nglnL) = (" << fitpars[10] << "," << fitpars[11] << "," << fitpars[12] << "," << nglnL << ") to position " << il << std::endl; } else break; }//for il }// for ipt } // loop over time - for (int itoff=0; for (int il=0; il= FQTESTMAXPI0) { // std::cout << "In fiTQun_shared::SaveTestPi0Fit: cannot save more than " << FQTESTMAXPI0 << " test 1 ring fits." <<\ // std::endl; // std::cout << " ---> This test fit will not be saved (istage = " << istage << ")" << std::endl; // return; // } // // fitqunpi0test_.fqtestpi0stage[fitqunpi0test_.fqtestnpi0] = istage; // fitqunpi0test_.fqtestpi0pos[fitqunpi0test_.fqtestnpi0][0] = fitparams[0]; // fitqunpi0test_.fqtestpi0pos[fitqunpi0test_.fqtestnpi0][1] = fitparams[1]; // fitqunpi0test_.fqtestpi0pos[fitqunpi0test_.fqtestnpi0][2] = fitparams[2]; // fitqunpi0test_.fqtestpi0t0[fitqunpi0test_.fqtestnpi0] = fitparams[3]; // fitqunpi0test_.fqtestpi0dir1[fitqunpi0test_.fqtestnpi0][0] = sin(fitparams[4])*cos(fitparams[5]); // fitqunpi0test_.fqtestpi0dir1[fitqunpi0test_.fqtestnpi0][1] = sin(fitparams[4])*sin(fitparams[5]); // fitqunpi0test_.fqtestpi0dir1[fitqunpi0test_.fqtestnpi0][2] = cos(fitparams[4]); // fitqunpi0test_.fqtestpi0mom1[fitqunpi0test_.fqtestnpi0] = fitparams[6]; // fitqunpi0test_.fqtestpi0dconv1[fitqunpi0test_.fqtestnpi0] = fitparams[7]; // fitqunpi0test_.fqtestpi0dir2[fitqunpi0test_.fqtestnpi0][0] = sin(fitparams[8])*cos(fitparams[9]); // fitqunpi0test_.fqtestpi0dir2[fitqunpi0test_.fqtestnpi0][1] = sin(fitparams[8])*sin(fitparams[9]); // fitqunpi0test_.fqtestpi0dir2[fitqunpi0test_.fqtestnpi0][2] = cos(fitparams[8]); // fitqunpi0test_.fqtestpi0mom2[fitqunpi0test_.fqtestnpi0] = fitparams[10]; // fitqunpi0test_.fqtestpi0dconv2[fitqunpi0test_.fqtestnpi0] = fitparams[11]; // // TVector3 dir1vect(sin(fitparams[4])*cos(fitparams[5]), // sin(fitparams[4])*sin(fitparams[5]), // cos(fitparams[4])); // TVector3 dir2vect(sin(fitparams[8])*cos(fitparams[9]), // sin(fitparams[8])*sin(fitparams[9]), // cos(fitparams[8])); // // fitqunpi0test_.fqtestpi0mass[fitqunpi0test_.fqtestnpi0] = sqrt( 2.*fitparams[6]*fitparams[10] // *(1 - dir1vect.Dot(dir2vect)) ); // fitqunpi0test_.fqtestpi0photangle[fitqunpi0test_.fqtestnpi0] = acos(dir1vect.Dot(dir2vect)); // TVector3 momtot = fitparams[6]*dir1vect + fitparams[10]*dir2vect; // fitqunpi0test_.fqtestpi0momtot[fitqunpi0test_.fqtestnpi0] = momtot.Mag(); // TVector3 dirtot = momtot.Unit(); // fitqunpi0test_.fqtestpi0dirtot[fitqunpi0test_.fqtestnpi0][0] = dirtot.X(); // fitqunpi0test_.fqtestpi0dirtot[fitqunpi0test_.fqtestnpi0][1] = dirtot.Y(); // fitqunpi0test_.fqtestpi0dirtot[fitqunpi0test_.fqtestnpi0][2] = dirtot.Z(); // // fitqunpi0test_.fqtestpi0totmu[fitqunpi0test_.fqtestnpi0] = totmu; // fitqunpi0test_.fqtestpi0nll[fitqunpi0test_.fqtestnpi0] = nll; // fitqunpi0test_.fqtestpi0pcflg[fitqunpi0test_.fqtestnpi0] = PCflg; // // fitqunpi0test_.fqtestnpi0++; // //} //************************************************************************************************************************************ //double PDK_MuGamma::PDK_MuGammaGetTwoRngnglogL(double *X, int& PCflg); //************************************************************************************************************************************ double PDK_MuGamma::MuGammaNglogL(double *X, int& PCflg){ Resetmu(); // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 // X = {X1, Y1, Z1, T1, theta1, phi1, p1, X2, Y2, Z2, T2, theta2, phi2, p2} double X1st[8]; for (int i=0; i<=6; i++) X1st[i]=X[i]; X1st[7] = 0.; double X2nd[8]; for (int i=0; i<=6; i++) X2nd[i]=X[i+7]; X2nd[7] = 0.; if (same3Vertex) { for (int i=0; i<=2; i++) X2nd[i]=X[i]; } int PCflg1=fiTQun::OneRing(imu,X1st,0); int PCflg2=fiTQun::OneRing(ie,X2nd,1); //int PCflg2 = 0; PCflg = abs(PCflg1)+2*abs(PCflg2); if ((PCflg1<0)||(PCflg2<0)) PCflg = -1; double nll = fiTQun::nglogL(); return nll; } //************************************************************************************************************************************ //PDK_MuGamma::GetTruePDK_MuGammaParams(double* tParams); Get true information for seed = 1 in the DoFit function. //************************************************************************************************************************************ void PDK_MuGamma::GetTruePDK_MuGammaParams(double* tParams){ //NEEDS A LOT OF CHANGES!!!!!!!!!! not sure how to do them. bool printStuff = true; int temp_track = -1; for (int ipar=0; iparGetTotqCoef(); // changed ctotqpnl to fiTQun_shared:: fiTQun_shared::Get()->SetTotqCoef(0);//no total charge constraint fiTQun_shared::Get()->SetFullScatflg(true); //Same as ctotqpnl bool var. //!!!!!!!!!!!!!!!!! seedtype values CHANGE!!!!!!!!!!!!!!!! these are from Pi0 DoFit // 1 = seed with truth // 2 = seed with fixed efit + scan with 50 MeV ring double tfitpars[fiTQun_shared::nPDK_MuGammaParams]; double fitpars[fiTQun_shared::nPDK_MuGammaParams]; int fixedpars[fiTQun_shared::nPDK_MuGammaParams]; double nglnL; double totmu; GetTruePDK_MuGammaParams(tfitpars); if (tfitpars[3] != 0) { nglnL = MuGammaNglogL(tfitpars,PCflg); totmu=GetTotmu(); std::cout << "(1) totmu = " << totmu << std::endl; // fqshared->SaveTestPDK_MuGammaFit(tfitpars,0,totmu,nglnL,PCflg); //CHANGE!!!!!! probably from shared.cc } else { std::cout << "Could not get the true time of the muon in this event!" << std::endl; } //These are for many different seed types. For now I'm trying just one, so check after the comment BLOCK. //Only working seedtype currently.....seed=2 is for seed with fixed efit + scan with 50 MeV ring if(seedtype == 1){ // seed with truth same3Vertex = true; for (int ipar=0; iparGetDefaultSnglTrkFit(fitpars,itwnd,0,imu,totmu,nglnL,PCflg); nglnL = SetPDK_MuGammaSeed(fitpars,PCflg); } else if (seedtype == 3){ double mufittime = 0; fqshared->GetDefaultSnglTrkFit(fitpars,itwnd,0,imu,totmu,nglnL,PCflg); mufittime = fitpars[3]; same3Vertex = true; for (int ipar=0; iparGetDrawflg() ) DrawPreddist(Form("%s_0",strBase.Data())); // fqshared->SaveTestPDK_MuGammaFit(fitpars,1,totmu,nglnL,PCflg); std::cout << "###########Initial parameters: "; for (int i=0; iGetDrawflg() ) DrawPreddist(); // Do final fit nglnL = RunMinimizer(fitpars,PCflg,fixedpars); totmu=GetTotmu(); // printstuff = false; // if (fiTQun_shared::Get()->GetDrawflg() ) DrawPreddist(Form("%s_fit",strBase.Data())); std::cout << "########### Fit result: "; for (int i=0; i