#include "fiTQun_shared.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "fQChrgPDF.h" #include "TRuntimeParameters.hxx" #include "fQEventManager.h" // Put compiler flag around sk info #ifndef NOSKLIBRARIES #include "skheadC.h" #include "skparmC.h" #include "geopmtC.h" #include "sktqC.h" #include "skbadcC.h" #else #include "WCSimWrap.h" #endif /// Some of variables from following are /// used in the code, so keep it. #include "spliTChanOutC.h" #include "fitqunoutC.h" using namespace fiTQun_parameters; extern"C" { #ifndef NOSKLIBRARIES void kzbloc_(char *,int *,int); void fortconsts_(); extern struct{ int isk23[MAXPM]; float qefactor[MAXPM]; } pmtinfcmn_; #endif void clrfqcmns_(int *); } fiTQun_shared* fiTQun_shared::staticthis = NULL; int fiTQun_shared::fMaxNPMT = 11146; const double pi=3.1415926535898; const double costhmax=1.-1e-12; const int fiTQun_shared::PIDarr[nPID]={22,11,13,211,321,2212,48};//Supported particle types(PDG code) const TString fiTQun_shared::PIDnames[nPID]={"g","e","mu","pip","kp","p","CG"};//Short Particle Names const double fiTQun_shared::m0[nPID]={0.,0.5110,105.6584,139.5702,493.677,938.2720,0.};//Particle rest mass double fiTQun_shared::dEdx[nPID]={1.,1.,2.14786,2.13069,2.06859,2.04043,1.};//dE/dx for upstream track calculation const int fiTQun_shared::nTrkPar[nTrkTyp]={8,7,7,7,7,7,7,12,11};//Number of fit parameters for each track type const int fiTQun_shared::npar[3]={4,6,4};//number of charge pdf parameters(Lo,Mid,Hi) double fiTQun_shared::Phi0[nPID]={0.983,0.973,0.898,0.921,0.921,0.921,1.004}; double fiTQun_shared::expbinwrecp; double fiTQun_shared::expbins[nexpbinm1+1]; double fiTQun_shared::expTbl[nexpbinm1+1]; double fiTQun_shared::epsilon_binwrecp; double fiTQun_shared::epsilon_bins[nEpsilonBins+1]; double fiTQun_shared::epsilon_Tbl [nEpsilonBins+1]; int fiTQun_shared::flgHit[nPMT_max]; int fiTQun_shared::flgMask[nPMT_max]; int fiTQun_shared::ihitPMT[nPMT_max]; int fiTQun_shared::nhitPMT; double fiTQun_shared::tsigmvtx; double fiTQun_shared::chrg[nPMT_max]; double fiTQun_shared::mutot; double fiTQun_shared::mu[nRngMX][nPMT_max]; double fiTQun_shared::muscat[nRngMX][nPMT_max]; double fiTQun_shared::tHit[nPMT_max]; double fiTQun_shared::tau[nRngMX][nPMT_max]; double fiTQun_shared::nglnLarr[nPMT_max]; double fiTQun_shared::nglnLtarr[nPMT_max]; double fiTQun_shared::costheta0[nPMT_max]; double fiTQun_shared::qtot_fwd; double fiTQun_shared::mutot_fwd; int fiTQun_shared::fRngTyp [nPID]; int fiTQun_shared::nring; int fiTQun_shared::PIDring[nRngMX];//Particle type of each ring double fiTQun_shared::inDirtPDFpars[3]; // LUT time PDFs hemi::Table3D * fiTQun_shared::tpdf_direct[nPID]; hemi::Table3D * fiTQun_shared::tpdf_indirect[nPID]; int fiTQun_shared::npfitr; // Number of pre-fit iterations. Maximum is 10. double fiTQun_shared::sgmar[10]; // Width (2*sigma^2) of the gaussian for the vertex estimator double fiTQun_shared::grdszVtx; // Spatial step size for vertex grid search double fiTQun_shared::grdsztime; // Temporal step size for vertex grid search int fiTQun_shared::nRingMaxTrials; // Number of rings to fit with maximum number of ring hypothesis (further rings fit only with one ring hypothesis -- e-like) fiTQun_shared::fiTQun_shared( int aMaxNPmt ){ flgLoaded=false; fMaxNPMT = aMaxNPmt; SK_Ver=1; WCSim_Config = "NULL"; WCSim_PMTType = "NULL"; // Set default indirect time likelihood parameters to SK values // gamma: inDirtPDFpars[0] = 25; // sigma: inDirtPDFpars[1] = 8; // t0: inDirtPDFpars[2] = 25; // Default values for vertex pre-fit: npfitr = 4; sgmar[0] = 500.; sgmar[1] = 200.; sgmar[2] = 80.; sgmar[3] = 32.; grdszVtx = 400.; grdsztime = 15.; // Default value for nRingMaxTrials nRingMaxTrials = 4; WAttenL[0]=7200.; WAttenL[1]=7900.; const double xmax=-10.; for (int i=0; i<=nexpbinm1; i++) { expbins[i]=i*xmax/nexpbinm1; expTbl[i]=exp(expbins[i]); } expbinwrecp=1./(expbins[1]-expbins[0]); const int fRngTyp_Def[nPID]={0,1,1,2,0,2,0};//Default ring type for each particle type (1:normal, 2;upstream track) for (int iPID=0; iPIDSetWAttL(TRuntimeParameters::Get().GetParameterD(Form("fiTQun.WaterAttenuationLength%s",strDetName.Data()))); nwtr = TRuntimeParameters::Get().GetParameterD("fiTQun.WaterRefractiveIndex"); darkrate = TRuntimeParameters::Get().GetParameterD(Form("fiTQun.DarkRate%s",strDetName.Data())); flgdraw = TRuntimeParameters::Get().GetParameterI("fiTQun.DrawFitStages"); std::cout << "Draw = " << flgdraw << std::endl; int flgDeactPMT = TRuntimeParameters::Get().GetParameterI("fiTQun.PhotoCoverageFracDenom"); flgDeactPMT += 10*TRuntimeParameters::Get().GetParameterI("fiTQun.DeactCapPMTs"); if (flgDeactPMT>1) { this->SetActivePMTs(flgDeactPMT); } std::string outZBSFileName = TRuntimeParameters::Get().GetOutZBSFileName(); char* coutZBSFileName = (char*)outZBSFileName.c_str(); int outZBSFileLength; for (int i=0; i<256; i++) { if (coutZBSFileName[i]=='\0') { outZBSFileLength=i; break; } } this->Setofilenm(coutZBSFileName); QEEff = TRuntimeParameters::Get().GetParameterD(Form("fiTQun.QEEff%s",strDetName.Data())); this->SetPhi0(ig,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrGamma1RFit")); this->SetPhi0(ie,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrElectron1RFit")); this->SetPhi0(imu,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrMuon1RFit")); this->SetPhi0(ipip,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrPionPlus1RFit")); this->SetPhi0(ikp,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrKaonPlus1RFit")); this->SetPhi0(ip,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrProton1RFit")); this->SetPhi0(icg,TRuntimeParameters::Get().GetParameterD("fiTQun.QECorrConeGenerator1RFit")); this->SetdEdx(ig,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxGamma")); this->SetdEdx(ie,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxElectron")); this->SetdEdx(imu,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxMuon")); this->SetdEdx(ipip,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxPionPlus")); this->SetdEdx(ikp,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxKaonPlus")); this->SetdEdx(ip,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxProton")); this->SetdEdx(icg,TRuntimeParameters::Get().GetParameterD("fiTQun.dEdxConeGenerator")); QmuConvFact = TRuntimeParameters::Get().GetParameterD(Form("fiTQun.QmuConvFact%s",strDetName.Data())); PIDCut_epip[0] = TRuntimeParameters::Get().GetParameterD(Form("fiTQun.PIDCutEPipa0%s",strDetName.Data())); PIDCut_epip[1] = TRuntimeParameters::Get().GetParameterD(Form("fiTQun.PIDCutEPipa1%s",strDetName.Data())); PIDCut_mupip[0] =TRuntimeParameters::Get().GetParameterD(Form("fiTQun.PIDCutMuPip0%s",strDetName.Data())); PIDCut_mupip[1] =TRuntimeParameters::Get().GetParameterD(Form("fiTQun.PIDCutMuPip1%s",strDetName.Data())); nPi0SeedScanPoints = TRuntimeParameters::Get().GetParameterI("fiTQun.nPi0SeedScanPoints"); pi0PreFitVtxShiftThr = TRuntimeParameters::Get().GetParameterD("fiTQun.pi0PreFitVtxShiftThr"); pi0PreFitVtxShiftStepSize = TRuntimeParameters::Get().GetParameterD("fiTQun.pi0PreFitVtxShiftStepSize"); pi0PreFitVtxShiftNsteps = TRuntimeParameters::Get().GetParameterI("fiTQun.pi0PreFitVtxShiftNsteps"); RCCut_a[0]=TRuntimeParameters::Get().GetParameterD(Form("fiTQun.RCCuta0%s",strDetName.Data())); RCCut_a[1]=TRuntimeParameters::Get().GetParameterD(Form("fiTQun.RCCuta1%s",strDetName.Data())); RCCut_1Ea0=TRuntimeParameters::Get().GetParameterD(Form("fiTQun.RCCut1Ea0%s",strDetName.Data())); RCCut_1Mua0=TRuntimeParameters::Get().GetParameterD(Form("fiTQun.RCCut1Mua0%s",strDetName.Data())); nSegMax = TRuntimeParameters::Get().GetParameterI("fiTQun.nSegMax"); MSScattSig = TRuntimeParameters::Get().GetParameterD("fiTQun.MSScattSig"); // Number of rings where maximum number of hypothesis are tried. Further rings are fitted with e-like assumption only. Default is 4. if( TRuntimeParameters::Get().HasParameter("fiTQun.nRingMaxTrials") ) nRingMaxTrials = TRuntimeParameters::Get().GetParameterI("fiTQun.nRingMaxTrials"); } void fiTQun_shared::SetTimePDFMode (bool flg){ flgTimePDFmode = flg; if (flgTimePDFmode) { // if we are using the LUT mode, then we need to load the tables fiTQun_shared::Get()->LoadLookupTableTimePDF(); } } void fiTQun_shared::ReadParameters(int fScat, int *fRngtmp, bool fFitCProf, bool fFittProf, int iDetGeom){ // All fiTQun constant root files must be placed in fQconstdir char *ctmp = getenv("FITQUN_ROOT"); if (ctmp!=NULL) { fQconstdir=ctmp; fQconstdir+="/"; } else { ctmp = getenv("ATMPD_ROOT"); if (ctmp!=NULL) { fQconstdir=ctmp; fQconstdir+="/src/recon/fitqun/"; } else { std::cout << "ATMPD_ROOT not set!" << std::endl; exit(-1); } } fQconstdir+="const/"; if (fRngtmp!=NULL) { for (int iPID=0; iPIDIsZombie()) {// new constants exist! std::cout << "Constants not found in " << fQconstdir << std::endl; exit(-1); } delete TestFile; std::cout << "Reading fiTQun constants from: " << fQconstdir << std::endl; TFile* tf; TH2D *hscattbl2d; TH3D *hscattbl3d; SctTbl2d[0]=NULL; SctTbl3d=NULL; if (fScat==3) { std::cout << "Scattering table mode 3 is no longer supported!" << std::endl; exit(-1); } // If we're using WCSim AND the WCSim detector configuration has been specified // in the parameters file load the appropriate PMT charge response. Otherwise // stick to default behaviour which is to determine the SK version automatically // from SKDETSIM input or to use SK1 for WCSim. TString ScatTable_Config = strSKVer; #ifdef NOSKLIBRARIES if ( TRuntimeParameters::Get().HasParameter("fiTQun.WCSimConfig") ){ WCSim_Config = TRuntimeParameters::Get().GetParameterS("fiTQun.WCSimConfig"); ScatTable_Config = Form("_%s", WCSim_Config.Data()); } #endif if (fScat==1 || fScat==4) {//scattered light enabled if (fRngTyp[icg]) {//CG Reconstruction tf = new TFile(Form("%s/%s%s.root",fQconstdir.Data(),"fiTQun_scattablesF_CG",ScatTable_Config.Data()));//CG scattering table std::cout << "Opening CG scattering table file..." << std::endl; } else { tf = new TFile(Form("%s/%s%s.root",fQconstdir.Data(),"fiTQun_scattablesF",ScatTable_Config.Data())); std::cout << "Opening scattering table file..." << std::endl; } if (tf->IsZombie()) { std::cout << "Scattering table file does not exist!" << std::endl; DeleteInstances(); exit(-1); } tf->GetObject("topscattable",top_scattable); tf->GetObject("botscattable",bot_scattable); tf->GetObject("sidescattable",side_scattable); tf->Close(); delete tf; top_scattable->PrintMinElement(); bot_scattable->PrintMinElement(); side_scattable->PrintMinElement(); top_scattable->fillbininfo(); bot_scattable->fillbininfo(); side_scattable->fillbininfo(); } if (fScat==2 || fScat==3 || fScat==4) {//3d scattering table std::cout << "Opening 3D scattering table file..." << std::endl; tf = new TFile(Form("%s/%s%s.root",fQconstdir.Data(),"fiTQun_scattable3d",ScatTable_Config.Data())); if (tf->IsZombie()) { std::cout << "3D scattering table file does not exist!" << std::endl; DeleteInstances(); exit(-1); } tf->GetObject("hscattable3D",hscattbl3d); nsct3dRbinm1=hscattbl3d->GetNbinsX()-1; nsct3dwlbinm1=hscattbl3d->GetNbinsY()-1; nsct3dthbinm1=hscattbl3d->GetNbinsZ()-1; sct3dRbins = new double[nsct3dRbinm1+1]; sct3dwlbins = new double[nsct3dwlbinm1+1]; sct3dthbins = new double[nsct3dthbinm1+1]; SctTbl3d = new float**[nsct3dRbinm1+1]; for (int iR=0; iR<=nsct3dRbinm1; iR++) { sct3dRbins[iR]=hscattbl3d->GetXaxis()->GetBinCenter(iR+1); SctTbl3d[iR] = new float*[nsct3dwlbinm1+1]; for (int iwl=0; iwl<=nsct3dwlbinm1; iwl++) { sct3dwlbins[iwl]=hscattbl3d->GetYaxis()->GetBinCenter(iwl+1); SctTbl3d[iR][iwl] = new float[nsct3dthbinm1+1]; for (int ith=0; ith<=nsct3dthbinm1; ith++) { sct3dthbins[ith]=hscattbl3d->GetZaxis()->GetBinCenter(ith+1); SctTbl3d[iR][iwl][ith]=hscattbl3d->GetBinContent(iR+1,iwl+1,ith+1); } } } sct3dRbinw=sct3dRbins[1]-sct3dRbins[0]; sct3dwlbinw=sct3dwlbins[1]-sct3dwlbins[0]; sct3dthbinw=sct3dthbins[1]-sct3dthbins[0]; delete hscattbl3d; tf->Close(); delete tf; std::cout << "3D scattering table successfully loaded!" << std::endl; if (fScat!=3) { nsct2dRbin=nsct3dRbinm1+1; nsct2dthbin=nsct3dthbinm1+1; sct2dRbins = new double[nsct2dRbin]; sct2dthbins = new double[nsct2dthbin]; for (int iR=0; iR0 && fScat<=4)) { std::cout << "fiTQun_shared: Scattered light disabled!" << std::endl; } TransDetToGlbl.SetXYZ(0.,0.,0.);// Detector centre in global coordinate system TVector3 DetZinGlbl(0.,0.,1.);// Detector local Z-axis in global coordinate system TVector3 DetXinGlbl(1.,0.,0.);// Detector local X-axis in global coordinate system /// put this into compiler flag #ifndef NOSKLIBRARIES fortconsts_();//fill commom blocks for SK constants PMTRadius = 25.4; for (int icab=0; icabPMTposs(); float ** geopmtdxyz = wc->PMTdirs(); int * geopmttype = wc->PMTtypes(); float * geopmtqe = wc->PMTQEs(); // float * geopmtr = wc->PMTRs(); // float * geopmtphi = wc->PMTphis(); PMTRadius = wc->PMTRad(); std::cout << "PMTRadius was found to be " << PMTRadius << std::endl; for (int icab=0; icab icab="<LocCoordOffset(0),wc->LocCoordOffset(1),wc->LocCoordOffset(2)); DetZinGlbl.SetXYZ(wc->LocCoordZdir(0),wc->LocCoordZdir(1),wc->LocCoordZdir(2)); DetXinGlbl.SetXYZ(wc->LocCoordXdir(0),wc->LocCoordXdir(1),wc->LocCoordXdir(2)); #endif /// RotDetToGlbl.SetZAxis(DetZinGlbl,DetXinGlbl);// Rotation matrix which transforms detector local frame to global frame double PMTmaxR=0.; for (int j=0; j<3; j++) PMTmaxPos[j]=0.; for (int icab=0; icabIsOpen() ){ std::cerr << "Error: PMT angular response file not found. Exiting..." << std::endl; std::cerr << angResp_FileName.Data() << std::endl; exit(-1); } std::cout << "Reading PMT angular response curve from " << angResp_FileName.Data() << std::endl; TF1 * angRespFunc = (TF1*) angRespIn->Get("angResp"); double cosetamax=1.; for (int i = 0; i <= nEpsilonBins; i++) { epsilon_bins[i] = i*cosetamax/nEpsilonBins; epsilon_Tbl[i] = angRespFunc->Eval(epsilon_bins[i]); } epsilon_binwrecp = 1./(epsilon_bins[1]-epsilon_bins[0]); angRespIn->Close(); } else { // If not populate sample "old" function and populate array std::cout << "Warning: PMT type not specified. Using default (SK) angular response function." << std::endl; double cosetamax=1.; for (int i = 0; i <= nEpsilonBins; i++) { epsilon_bins[i] = i*cosetamax/nEpsilonBins; // "Old" epsilon function if (epsilon_bins[i] < 0.196688){ double val = -0.183124+epsilon_bins[i]*(3.4469-epsilon_bins[i]*4.6833); if (val > 0.) { epsilon_Tbl[i] = val; } else { epsilon_Tbl[i] = 0.; } } else if (epsilon_bins[i] < 0.986394) { epsilon_Tbl[i] = -0.207593+epsilon_bins[i]*(4.03995+epsilon_bins[i]*(-8.99093+epsilon_bins[i]*(10.6753-epsilon_bins[i]*4.5175))); } else { epsilon_Tbl[i] = 0.879163+epsilon_bins[i]*0.120837; } } epsilon_binwrecp = 1./(epsilon_bins[1]-epsilon_bins[0]); } } TVector3 fiTQun_shared::TfmDetToGlblCoord(TVector3 tmpVct, bool flgPos, bool flgInverse){ if (flgInverse) { if (flgPos) tmpVct-=TransDetToGlbl; tmpVct*=RotDetToGlbl.Inverse(); } else { tmpVct*=RotDetToGlbl; if (flgPos) tmpVct+=TransDetToGlbl; } return tmpVct; } void fiTQun_shared::Boundlogmu(double& logmu) { if (!(logmu>=tpdfmurang[0] && logmu 0.)) { if (diwl >= nsct3dwlbinm1) { ipwl = nsct3dwlbinm1; iwl = ipwl; } else { iwl = 0; ipwl = 0; } } double yd=(dwalltmp-sct3dwlbins[iwl])/sct3dwlbinw; for (int iR=0; iR nsct2dRbin-2) { iR = nsct2dRbin - 2; } else if (iR < 0) { iR = 0; } if (ith > nsct2dthbin-2) { ith = nsct2dthbin - 2; } else if (ith < 0) { ith = 0; } double xd=dR-(double)iR; double yd=dth-(double)ith; int ibase=iR*nsct2dthbin+ith; double w1=SctTbl2d[istp][ibase]*(1.-yd)+SctTbl2d[istp][ibase+1]*yd; ibase+=nsct2dthbin; double w2=SctTbl2d[istp][ibase]*(1.-yd)+SctTbl2d[istp][ibase+1]*yd; return w1*(1.-xd)+w2*xd; } double fiTQun_shared::explintrp(double x) { double dix=x*expbinwrecp; if (!(dix > 0. && dix < nexpbinm1)) { return exp(x); } int ix=(int)dix; double xd=(x-expbins[ix])*expbinwrecp; return expTbl[ix]*(1.-xd)+expTbl[ix+1]*xd; } double fiTQun_shared::epsilon(double coseta) { double dix=coseta*epsilon_binwrecp; if (!(dix >= 0. && dix < nEpsilonBins)) { return 0; } int ix=(int)dix; double xd=(coseta-epsilon_bins[ix])*epsilon_binwrecp; return epsilon_Tbl[ix]*(1.-xd)+epsilon_Tbl[ix+1]*xd; } double fiTQun_shared::pCherenkovThr(int iPID) { const double nphase=1.334; return m0[iPID]/sqrt(nphase*nphase-1.); } //double fiTQun_shared::WAttenL(double Zsrc, double Zpmt) { // double Zbound = -1100.; // if (Zsrc > Zbound) { // if (Zpmt > Zbound) { // } else { // } // } else { // if (Zpmt > Zbound) { // } else { // } // } //} fiTQun_shared::~fiTQun_shared(){ DeleteInstances(); std::cout << "fiTQun_shared destructed!!" << std::endl; } void fiTQun_shared::DeleteInstances(){ DeleteProfiles(); if (SctTbl2d[0]) { delete[] sct2dRbins; delete[] sct2dthbins; for (int istp=0; istp<3; istp++) { delete[] SctTbl2d[istp]; } } if (SctTbl3d) { delete[] sct3dRbins; delete[] sct3dwlbins; delete[] sct3dthbins; for (int iR=0; iR<=nsct3dRbinm1; iR++) { for (int iwl=0; iwl<=nsct3dwlbinm1; iwl++) { delete[] SctTbl3d[iR][iwl]; } delete[] SctTbl3d[iR]; } delete[] SctTbl3d; } } void fiTQun_shared::SaveTimeWindow(int itwnd, double *twindow){ fitquntwnd_.fqtwnd[itwnd][0] = twindow[0]; fitquntwnd_.fqtwnd[itwnd][1] = twindow[1]; } void fiTQun_shared::GetPreFit(int itwnd, double* fitparams, double *twindow){ // fitparams[0] = fitquntwnd_.fqtwnd_prftpos[itwnd][0]; // fitparams[1] = fitquntwnd_.fqtwnd_prftpos[itwnd][1]; // fitparams[2] = fitquntwnd_.fqtwnd_prftpos[itwnd][2]; TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitquntwnd_.fqtwnd_prftpos[itwnd]),true,true); tmppos.GetXYZ(fitparams); fitparams[3] = fitquntwnd_.fqtwnd_prftt0 [itwnd]; if (twindow) { twindow[0] = fitquntwnd_.fqtwnd[itwnd][0]; twindow[1] = fitquntwnd_.fqtwnd[itwnd][1]; } } void fiTQun_shared::ClearPeaks(int itwnd){ fitquntwnd_.fqtwnd_npeak[itwnd] = 0; for (int ipeak=0; ipeak= MAXNPEAK) { std::cout << "In fiTQun_shared::SavePeak: cannot save more than " << MAXNPEAK << " peak information." << std::endl; std::cout << " ---> The following will not be saved (itwnd, peakt0, peakiness) = (" << itwnd << "," << peakt0 << "," << peakiness << ")." << std::endl; return; } int i=fitquntwnd_.fqtwnd_npeak[itwnd]; fitquntwnd_.fqtwnd_peakt0 [itwnd][i] = peakt0; fitquntwnd_.fqtwnd_peakiness[itwnd][i] = peakiness; fitquntwnd_.fqtwnd_npeak[itwnd]++; } void fiTQun_shared::GetPeaks(int itwnd, int& npeaks, double *peakt0, double *peakiness){ npeaks=fitquntwnd_.fqtwnd_npeak[itwnd]; for (int ipeak=0; ipeak= MAXNPEAK) { std::cout << "In fiTQun_shared::SaveSubEvtInfo: cannot save more than " << MAXNPEAK << " sub-event information." << std::endl; std::cout << " ---> The following will not be saved (ise, nHPMT, Totalq) = (" << ise << "," << nHPMT << "," << Totalq << ")." << std::endl; return; } fitqun1r_.fqitwnd [ise] = itwnd; fitqun1r_.fqipeak [ise] = ipeak; fitqun1r_.fqnhitpmt[ise] = nHPMT; fitqun1r_.fqtotq [ise] = Totalq; if (fitqun1r_.fqnse= MAXNPEAK) { std::cout << "In fiTQun_shared::SaveDefaultSnglTrkFit: cannot save more than " << MAXNPEAK << " one-ring information." << std::endl; return; } // fitqun1r_.fq1rpos [ise][iPID][0] = fitparams[0]; // fitqun1r_.fq1rpos [ise][iPID][1] = fitparams[1]; // fitqun1r_.fq1rpos [ise][iPID][2] = fitparams[2]; TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitparams),true,false); tmppos.GetXYZ(fitqun1r_.fq1rpos[ise][iPID]); fitqun1r_.fq1rt0 [ise][iPID] = fitparams[3]; //fitqun1r_.fq1rdir [ise][iPID][0] = sin(fitparams[4])*cos(fitparams[5]); // fitqun1r_.fq1rdir [ise][iPID][1] = sin(fitparams[4])*sin(fitparams[5]); // fitqun1r_.fq1rdir [ise][iPID][2] = cos(fitparams[4]); TVector3 orgdir; orgdir.SetMagThetaPhi(1.,fitparams[4],fitparams[5]); TVector3 tmpdir = TfmDetToGlblCoord(orgdir,false,false); tmpdir.GetXYZ(fitqun1r_.fq1rdir[ise][iPID]); fitqun1r_.fq1rmom [ise][iPID] = fitparams[6]; if (fRngTyp[iPID]==2) {// upstream-track fitqun1r_.fq1rdconv[ise][iPID] = 0.; fitqun1r_.fq1reloss[ise][iPID] = fitparams[7]; } else { fitqun1r_.fq1rdconv[ise][iPID] = fitparams[7]; fitqun1r_.fq1reloss[ise][iPID] = 0.; } fitqun1r_.fq1rtotmu[ise][iPID] = totmu; fitqun1r_.fq1rnll [ise][iPID] = nll; fitqun1r_.fq1rpcflg[ise][iPID] = PCflg; if (iPID==ie && n50 && q50) {//save n50 fitqun1r_.fqn50[ise]=*n50; fitqun1r_.fqq50[ise]=*q50; } //std::cout << "fq1rpos["<< ise << "][" << iPID << "][0] = " << fitqun1r_.fq1rpos[ise][iPID][0] << std::endl; //std::cout << "-lnL=" << fitqun1r_.fq1rnll[ise][iPID] << "; totq, totmu = " << fitqun1r_.fq1rtotmu[ise][iPID] << ", " << fitqun1r_.fq1rtotmu[ise][iPID] << "; Time=" << fitqun1r_.fq1rt0 [ise][iPID] << std::endl; } void fiTQun_shared::GetDefaultSnglTrkFit(double* fitparams, int itwnd, int ipeak, int iPID, double& totmu, double& nll, int& PCflg){ int ise=ipeak; for (int idx=0; idx= MAXNPEAK) { std::cout << "In fiTQun_shared::GetDefaultSnglTrkFit: ise >= MAXNPEAK!" << std::endl; return; } // fitparams[0] = fitqun1r_.fq1rpos [ise][iPID][0]; // fitparams[1] = fitqun1r_.fq1rpos [ise][iPID][1]; // fitparams[2] = fitqun1r_.fq1rpos [ise][iPID][2]; TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitqun1r_.fq1rpos[ise][iPID]),true,true); tmppos.GetXYZ(fitparams); fitparams[3] = fitqun1r_.fq1rt0 [ise][iPID]; // fitparams[4] = acos (fitqun1r_.fq1rdir[ise][iPID][2]); // fitparams[5] = atan2(fitqun1r_.fq1rdir[ise][iPID][1],fitqun1r_.fq1rdir[ise][iPID][0]); TVector3 tmpdir = TfmDetToGlblCoord(TVector3(fitqun1r_.fq1rdir[ise][iPID]),false,true); fitparams[4] = tmpdir.Theta(); fitparams[5] = tmpdir.Phi(); fitparams[6] = fitqun1r_.fq1rmom [ise][iPID]; if (fRngTyp[iPID]==2) {// upstream-track fitparams[7] = fitqun1r_.fq1reloss[ise][iPID]; } else { fitparams[7] = fitqun1r_.fq1rdconv[ise][iPID]; } totmu = fitqun1r_.fq1rtotmu[ise][iPID]; nll = fitqun1r_.fq1rnll [ise][iPID]; PCflg = fitqun1r_.fq1rpcflg[ise][iPID]; } void fiTQun_shared::SaveTestSnglTrkFit(double* fitparams, int istage, int itwnd, int iPID, double totmu, double nll, int PCflg){ if (fitqun1rtest_.fqtestn1r >= FQTESTMAX1R) { std::cout << "In fiTQun_shared::SaveTestSnglTrkFit: cannot save more than " << FQTESTMAX1R << " test 1 ring fits." << std::endl; std::cout << " ---> This test fit will not be saved (itwnd, iPID, totmu, nll) = (" << itwnd << "," << iPID << "," << totmu << "," << nll << ")." << std::endl; return; } fitqun1rtest_.fqtest1rstage[fitqun1rtest_.fqtestn1r] = istage; fitqun1rtest_.fqtest1rse [fitqun1rtest_.fqtestn1r] = itwnd; fitqun1rtest_.fqtest1rpid [fitqun1rtest_.fqtestn1r] = iPID; // fitqun1rtest_.fqtest1rpos [fitqun1rtest_.fqtestn1r][0] = fitparams[0]; // fitqun1rtest_.fqtest1rpos [fitqun1rtest_.fqtestn1r][1] = fitparams[1]; // fitqun1rtest_.fqtest1rpos [fitqun1rtest_.fqtestn1r][2] = fitparams[2]; TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitparams),true,false); tmppos.GetXYZ(fitqun1rtest_.fqtest1rpos[fitqun1rtest_.fqtestn1r]); fitqun1rtest_.fqtest1rt0 [fitqun1rtest_.fqtestn1r] = fitparams[3]; // fitqun1rtest_.fqtest1rdir [fitqun1rtest_.fqtestn1r][0] = sin(fitparams[4])*cos(fitparams[5]); // fitqun1rtest_.fqtest1rdir [fitqun1rtest_.fqtestn1r][1] = sin(fitparams[4])*sin(fitparams[5]); // fitqun1rtest_.fqtest1rdir [fitqun1rtest_.fqtestn1r][2] = cos(fitparams[4]); TVector3 orgdir; orgdir.SetMagThetaPhi(1.,fitparams[4],fitparams[5]); TVector3 tmpdir = TfmDetToGlblCoord(orgdir,false,false); tmpdir.GetXYZ(fitqun1rtest_.fqtest1rdir[fitqun1rtest_.fqtestn1r]); fitqun1rtest_.fqtest1rmom [fitqun1rtest_.fqtestn1r] = fitparams[6]; if (fRngTyp[iPID]==2) {// upstream-track fitqun1rtest_.fqtest1rdconv[fitqun1rtest_.fqtestn1r] = 0.; fitqun1rtest_.fqtest1reloss[fitqun1rtest_.fqtestn1r] = fitparams[7]; } else { fitqun1rtest_.fqtest1rdconv[fitqun1rtest_.fqtestn1r] = fitparams[7]; fitqun1rtest_.fqtest1reloss[fitqun1rtest_.fqtestn1r] = 0.; } fitqun1rtest_.fqtest1rtotmu[fitqun1rtest_.fqtestn1r] = totmu; fitqun1rtest_.fqtest1rnll [fitqun1rtest_.fqtestn1r] = nll; fitqun1rtest_.fqtest1rpcflg[fitqun1rtest_.fqtestn1r] = PCflg; fitqun1rtest_.fqtestn1r++; } void fiTQun_shared::SaveDefaultPi0Fit(double* fitparams, int index, double totmu, double nll, int PCflg){ // fitqunpi0_.fqpi0pos[index][0] = fitparams[0]; // fitqunpi0_.fqpi0pos[index][1] = fitparams[1]; // fitqunpi0_.fqpi0pos[index][2] = fitparams[2]; TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitparams),true,false); tmppos.GetXYZ(fitqunpi0_.fqpi0pos[index]); fitqunpi0_.fqpi0t0[index] = fitparams[3]; // fitqunpi0_.fqpi0dir1[index][0] = sin(fitparams[4])*cos(fitparams[5]); // fitqunpi0_.fqpi0dir1[index][1] = sin(fitparams[4])*sin(fitparams[5]); // fitqunpi0_.fqpi0dir1[index][2] = cos(fitparams[4]); TVector3 orgdir1; orgdir1.SetMagThetaPhi(1.,fitparams[4],fitparams[5]); TVector3 tmpdir1 = TfmDetToGlblCoord(orgdir1,false,false); tmpdir1.GetXYZ(fitqunpi0_.fqpi0dir1[index]); fitqunpi0_.fqpi0mom1[index] = fitparams[6]; fitqunpi0_.fqpi0dconv1[index] = fitparams[7]; // fitqunpi0_.fqpi0dir2[index][0] = sin(fitparams[8])*cos(fitparams[9]); // fitqunpi0_.fqpi0dir2[index][1] = sin(fitparams[8])*sin(fitparams[9]); // fitqunpi0_.fqpi0dir2[index][2] = cos(fitparams[8]); TVector3 orgdir2; orgdir2.SetMagThetaPhi(1.,fitparams[8],fitparams[9]); TVector3 tmpdir2 = TfmDetToGlblCoord(orgdir2,false,false); tmpdir2.GetXYZ(fitqunpi0_.fqpi0dir2[index]); fitqunpi0_.fqpi0mom2[index] = fitparams[10]; fitqunpi0_.fqpi0dconv2[index] = fitparams[11]; fitqunpi0_.fqpi0mass[index] = sqrt( 2.*fitqunpi0_.fqpi0mom1[index]*fitqunpi0_.fqpi0mom2[index] *(1 - tmpdir1.Dot(tmpdir2)) ); fitqunpi0_.fqpi0photangle[index] = acos(tmpdir1.Dot(tmpdir2)); TVector3 momtot = fitqunpi0_.fqpi0mom1[index]*tmpdir1 + fitqunpi0_.fqpi0mom2[index]*tmpdir2; fitqunpi0_.fqpi0momtot[index] = momtot.Mag(); TVector3 dirtot = momtot.Unit(); fitqunpi0_.fqpi0dirtot[index][0] = dirtot.X(); fitqunpi0_.fqpi0dirtot[index][1] = dirtot.Y(); fitqunpi0_.fqpi0dirtot[index][2] = dirtot.Z(); fitqunpi0_.fqpi0totmu[index] = totmu; fitqunpi0_.fqpi0nll[index] = nll; fitqunpi0_.fqpi0pcflg[index] = PCflg; } void fiTQun_shared::SaveTestPi0Fit(double* fitparams, int istage, double totmu, double nll, int PCflg){ if (fitqunpi0test_.fqtestnpi0 >= 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]; TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitparams),true,false); tmppos.GetXYZ(fitqunpi0test_.fqtestpi0pos[fitqunpi0test_.fqtestnpi0]); 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]); TVector3 orgdir1; orgdir1.SetMagThetaPhi(1.,fitparams[4],fitparams[5]); TVector3 tmpdir1 = TfmDetToGlblCoord(orgdir1,false,false); tmpdir1.GetXYZ(fitqunpi0test_.fqtestpi0dir1[fitqunpi0test_.fqtestnpi0]); 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]); TVector3 orgdir2; orgdir2.SetMagThetaPhi(1.,fitparams[8],fitparams[9]); TVector3 tmpdir2 = TfmDetToGlblCoord(orgdir2,false,false); tmpdir2.GetXYZ(fitqunpi0test_.fqtestpi0dir2[fitqunpi0test_.fqtestnpi0]); fitqunpi0test_.fqtestpi0mom2[fitqunpi0test_.fqtestnpi0] = fitparams[10]; fitqunpi0test_.fqtestpi0dconv2[fitqunpi0test_.fqtestnpi0] = fitparams[11]; fitqunpi0test_.fqtestpi0mass[fitqunpi0test_.fqtestnpi0] = sqrt( 2.*fitparams[6]*fitparams[10] *(1 - tmpdir1.Dot(tmpdir2)) ); fitqunpi0test_.fqtestpi0photangle[fitqunpi0test_.fqtestnpi0] = acos(tmpdir1.Dot(tmpdir2)); TVector3 momtot = fitparams[6]*tmpdir1 + fitparams[10]*tmpdir2; 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++; } void fiTQun_shared::ClearMRFit() { for (int iFit=0; iFit= FQMAXNMRFIT) { std::cout << "In fiTQun_shared::SaveMRFit: cannot save more than " << FQMAXNMRFIT << " multi-ring fits." << std::endl; std::cout << " ---> This MR fit will not be saved (idFit = " << idFit << ")" << std::endl; return; } if (!(nringtmp>=0 && nringtmp<=FQMAXNRING)) { std::cout << "In fiTQun_shared::SaveMRFit: nring must be [0-" << FQMAXNRING << "]!" << std::endl; exit(-1); } if (fitqunmr_.fqnmrfit=fitqunmr_.fqnmrfit) { // std::cout << "In fiTQun_shared::GetMRFit: cannot find result of (idFit = " << idFit << ")" << std::endl; return -1; } if (fitqunmr_.fqmrifit[iFit] == idFit) { break; } iFit++; } } nringtmp = fitqunmr_.fqmrnring[iFit]; PCflg = fitqunmr_.fqmrpcflg[iFit]; nll = fitqunmr_.fqmrnll[iFit]; totmu = fitqunmr_.fqmrtotmu[iFit]; for (int iring=0; iring=fitqunmr_.fqnmrfit) { std::cout << "In fiTQun_shared::MoveMRFit: Invalid destination iDest = " << iDest << std::endl; return -1; } bool flgRemove=false; if (iDest<0) { iDest=fitqunmr_.fqnmrfit-1; flgRemove=true; } int bufnring, bufTypeArr[FQMAXNRING], bufPCflg; double bufParArr[FQMAXNRING][fiTQun_shared::nSnglTrkParams], buftotmu, bufnlL; int iOrig = GetMRFit(idFit,bufnring,bufTypeArr,bufParArr,buftotmu,bufnlL,bufPCflg); if (iOrig<0) { std::cout << "In fiTQun_shared::MoveMRFit: Cannot find result. idFit = " << idFit << std::endl; return -1; } int iShift=0; if (iDestiOrig) { iShift=-1; } if (iShift) { for (int iFit=iOrig-iShift; iShift*(iFit-iDest)>=0; iFit-=iShift) { int tmpnring, tmpTypeArr[FQMAXNRING], tmpPCflg; double tmpParArr[FQMAXNRING][fiTQun_shared::nSnglTrkParams], tmptotmu, tmpnlL; int idtmp=fitqunmr_.fqmrifit[iFit]; GetMRFit(idtmp,tmpnring,tmpTypeArr,tmpParArr,tmptotmu,tmpnlL,tmpPCflg,iFit); SaveMRFit(idtmp,tmpnring,tmpTypeArr,tmpParArr,tmptotmu,tmpnlL,tmpPCflg,iFit+iShift); } SaveMRFit(idFit,bufnring,bufTypeArr,bufParArr,buftotmu,bufnlL,bufPCflg,iDest); } if (flgRemove) { SaveMRFit(0,0,NULL,NULL,0.,0.,0,iDest); fitqunmr_.fqnmrfit--; } return 0; } void fiTQun_shared::GetListMRFit(int &nMRFit, int *idList, double *nllList, int *iSort){ nMRFit=fitqunmr_.fqnmrfit; for (int iFit=0; iFit=0; jFit--) { if (nllList[iSort[jFit]]>nllList[iSort[jFit+1]]) { int iBuf=iSort[jFit]; iSort[jFit]=iSort[jFit+1]; iSort[jFit+1]=iBuf; } else break; } } } void fiTQun_shared::SaveDefaultPDK_MuGammaFit(double* fitparams, int index, double totmu, double nll, int PCflg){ TVector3 tmppos = TfmDetToGlblCoord(TVector3(fitparams),true,false); tmppos.GetXYZ(fitqunpmg_.fqpmgpos1[index]); fitqunpmg_.fqpmgt01[index] = fitparams[3]; TVector3 tmppos2 = TfmDetToGlblCoord(TVector3(&(fitparams[7])),true,false); tmppos2.GetXYZ(fitqunpmg_.fqpmgpos2[index]); fitqunpmg_.fqpmgt02[index] = fitparams[10]; TVector3 orgdir1; orgdir1.SetMagThetaPhi(1.,fitparams[4],fitparams[5]); TVector3 tmpdir1 = TfmDetToGlblCoord(orgdir1,false,false); tmpdir1.GetXYZ(fitqunpmg_.fqpmgdir1[index]); fitqunpmg_.fqpmgmom1[index] = fitparams[6]; TVector3 orgdir2; orgdir2.SetMagThetaPhi(1.,fitparams[11],fitparams[12]); TVector3 tmpdir2 = TfmDetToGlblCoord(orgdir2,false,false); tmpdir2.GetXYZ(fitqunpmg_.fqpmgdir2[index]); fitqunpmg_.fqpmgmom2[index] = fitparams[13]; fitqunpmg_.fqpmgtotmu[index] = totmu; fitqunpmg_.fqpmgnll[index] = nll; fitqunpmg_.fqpmgpcflg[index] = PCflg; } void fiTQun_shared::LoadLookupTableTimePDF() { std::cout << "loading Lookup Table Time PDFs..."; TString LUTtPDF_Config = strSKVer; // If we're using WCSim AND the WCSim detector configuration has been specified // in the parameters file load the appropriate PMT charge response. Otherwise // stick to default behaviour which is to determine the SK version automatically // from SKDETSIM input or to use SK1 for WCSim. #ifdef NOSKLIBRARIES if ( TRuntimeParameters::Get().HasParameter("fiTQun.WCSimConfig") ){ WCSim_Config = TRuntimeParameters::Get().GetParameterS("fiTQun.WCSimConfig"); LUTtPDF_Config = Form("_%s", WCSim_Config.Data()); } #endif TString object_name = "hist_tpdf"; TString fq_root = ""; // make sure we can find the files if (getenv("FITQUN_ROOT")==NULL) { printf("ERROR! FITQUN_ROOT is not set. See fiTQun::LoadLookupTableTimePDF()\n"); exit(-1); } else { fq_root = getenv("FITQUN_ROOT"); } for (int ipid = 0; ipid < nPID; ++ipid) { if (!fRngTyp[ipid]) continue; // direct time PDF lookup table TString LUTtpdf_dir_name = Form("%s/%d_LUTtpdfhist_dir%s.root",fQconstdir.Data(),PIDarr[ipid], LUTtPDF_Config.Data()); TFile *f = new TFile(LUTtpdf_dir_name.Data(), "OPEN"); TH3F *h = (TH3F*)f->Get(object_name.Data()); if (!h) { std::cerr << "could not open object " << object_name << " from " << LUTtpdf_dir_name << std::endl; exit(-1);} tpdf_direct[ipid] = new hemi::Table3D(h->GetNbinsX(), h->GetNbinsY(), h->GetNbinsZ(), // low edges h->GetXaxis()->GetBinCenter(1), h->GetYaxis()->GetBinCenter(1), h->GetZaxis()->GetBinCenter(1), // upper edges h->GetXaxis()->GetBinCenter(h->GetNbinsX()), h->GetYaxis()->GetBinCenter(h->GetNbinsY()), h->GetZaxis()->GetBinCenter(h->GetNbinsZ())); for (int z = 1; z <= h->GetNbinsZ(); ++z) for (int y = 1; y <= h->GetNbinsY(); ++y) for (int x = 1; x <= h->GetNbinsX(); ++x) { int idx = hemi::index(x-1, y-1, z-1, h->GetNbinsX(), h->GetNbinsY()); tpdf_direct[ipid]->writeOnlyHostPtr()[idx] = h->GetBinContent(x, y, z); } delete f; // indirect time PDF lookup table TString LUTtpdf_sct_name = Form("%s/%d_LUTtpdfhist_sct%s.root",fQconstdir.Data(),PIDarr[ipid], LUTtPDF_Config.Data()); f = new TFile(LUTtpdf_sct_name.Data(), "OPEN"); h = (TH3F*)f->Get(object_name.Data()); if (!h) { std::cerr << "could not open object " << object_name << " from " << LUTtpdf_sct_name << std::endl; exit(-1);} tpdf_indirect[ipid] = new hemi::Table3D(h->GetNbinsX(), h->GetNbinsY(), h->GetNbinsZ(), // low edges h->GetXaxis()->GetBinCenter(1), h->GetYaxis()->GetBinCenter(1), h->GetZaxis()->GetBinCenter(1), // upper edges h->GetXaxis()->GetBinCenter(h->GetNbinsX()), h->GetYaxis()->GetBinCenter(h->GetNbinsY()), h->GetZaxis()->GetBinCenter(h->GetNbinsZ())); for (int z = 1; z <= h->GetNbinsZ(); ++z) for (int y = 1; y <= h->GetNbinsY(); ++y) for (int x = 1; x <= h->GetNbinsX(); ++x) { int idx = hemi::index(x-1, y-1, z-1, h->GetNbinsX(), h->GetNbinsY()); tpdf_indirect[ipid]->writeOnlyHostPtr()[idx] = h->GetBinContent(x, y, z); } h = NULL; // dont let this pointer dangle delete f; } std::cout << " done" << std::endl; } void fiTQun_shared::LoadProfiles(bool fFitCProf, bool fFittProf){ TString cPDF_FileName = Form("%s/%s%s.root",fQconstdir.Data(),"cPDFpar",strSKVer.Data()); // If we're using WCSim AND the PMT type has been specified in the parameters file // load the appropriate PMT charge response. Otherwise stick to default behaviour // which is to determine the SK version automatically from SKDETSIM input or to // use SK1 for WCSim. #ifdef NOSKLIBRARIES if ( TRuntimeParameters::Get().HasParameter("fiTQun.WCSimPMTType") ){ WCSim_PMTType = TRuntimeParameters::Get().GetParameterS("fiTQun.WCSimPMTType"); cPDF_FileName = Form("%s/%s_%s.root",fQconstdir.Data(),"cPDFpar", WCSim_PMTType.Data()); } #endif char * LoadParamsArg = const_cast (cPDF_FileName.Data()); // Cast to non-const fQChrgPDF::Get()->LoadParams(LoadParamsArg);//read charge PDF parameters fUseFitCprof=fFitCProf; R0bins=NULL; th0bins=NULL; //pdg range and time// TFile *fpdg = new TFile(fQconstdir+"gpdgRange.root"); TFile* fpdgt = new TFile(fQconstdir+"gpdgTime.root"); if (fpdg->IsZombie() || fpdgt->IsZombie()) { std::cout << "PDG range table missing!" << std::endl; exit(-1); } gPDGRange = new TGraph(*(TGraph*)fpdg->Get("gpdgRange")); std::cout<Eval(1000.)<Get("gpdgTime")); delete fpdg; delete fpdgt; //////////// //Initialize Cherenkov profiles for (int iPID=0; iPIDIsZombie()) { std::cout << "Cherenkov profile is missing!" << std::endl; delete fcprof; DeleteInstances(); exit(-1); } for (int i=0; i<3; i++) {//I_n TH3F *hI3d = (TH3F*)fcprof->Get(Form("hI3d_%d",i)); if (i==0) {//Set integral table bins if (R0bins==NULL) {//R0, costh0 bins same for all particle types nR0bin=hI3d->GetNbinsX(); nth0bin=hI3d->GetNbinsY(); R0bins = new double[nR0bin]; th0bins = new double[nth0bin]; for (int j=0; jGetXaxis()->GetBinLowEdge(j+1); for (int j=0; jGetYaxis()->GetBinLowEdge(j+1); R0binwrecp=1./(R0bins[1]-R0bins[0]); th0binwrecp=1./(th0bins[1]-th0bins[0]); } nmom[iPID]=hI3d->GetNbinsZ(); mombins[iPID] = new double[nmom[iPID]]; for (int j=0; jGetZaxis()->GetBinLowEdge(j+1); } InTbl[iPID][i] = new float**[nR0bin]; for (int j=0; jGetBinContent(j+1,k+1,l+1); } } } } for (int i=0; i<2; i++) {//isotropic source integrale table TH1D *hIiso = (TH1D*)fcprof->Get(Form("hI_iso_%d",i+1)); int nmomtmp=hIiso->GetNbinsX(); gIniso[iPID][i] = new TGraph(nmomtmp); for (int j=0; jSetPoint(j,hIiso->GetXaxis()->GetBinLowEdge(j+1),hIiso->GetBinContent(j+1)); } } gNphot[iPID] = new TGraph(*(TGraph*)fcprof->Get("gNphot")); int ngpts=gNphot[iPID]->GetN(); gNphtmom[iPID] = new TGraph(ngpts); for (int i=0; iGetPoint(i,gx,gy); gNphtmom[iPID]->SetPoint(i,gy,gx); } gSmax[iPID] = new TGraph(*(TGraph*)fcprof->Get("gsthr")); delete fcprof; } } fUseFittpdf=fFittProf; //Initialize time likelihood parameters TString tPDF_Config = strSKVer; // If we're using WCSim AND the WCSim detector configuration has been specified // in the parameters file load the appropriate PMT charge response. Otherwise // stick to default behaviour which is to determine the SK version automatically // from SKDETSIM input or to use SK1 for WCSim. #ifdef NOSKLIBRARIES if ( TRuntimeParameters::Get().HasParameter("fiTQun.WCSimConfig") ){ WCSim_Config = TRuntimeParameters::Get().GetParameterS("fiTQun.WCSimConfig"); tPDF_Config = Form("_%s", WCSim_Config.Data()); } #endif for (int iPID=0; iPIDIsZombie()) { std::cout << "Time likelihood parameter file missing!" << std::endl; delete ftprof; DeleteInstances(); exit(-1); } TH1D *htpdfinfo = (TH1D*)ftprof->Get("htpdfinfo"); int ntmp=(int)(htpdfinfo->GetBinContent(1)+0.5); tpdfmurang[0]=htpdfinfo->GetBinContent(2); tpdfmurang[1]=htpdfinfo->GetBinContent(3); int ntmp2=(int)(htpdfinfo->GetBinContent(4)+0.5); tpdfprang[iPID][0]=htpdfinfo->GetBinContent(5); tpdfprang[iPID][1]=htpdfinfo->GetBinContent(6); if (ntmp!=ntpdfmupar || ntmp2!=ntpdfppar) { std::cout << "Incompatible time likelihood parameter file!" << std::endl; delete ftprof; DeleteInstances(); exit(-1); } delete htpdfinfo; if (fUseFittpdf) { std::cout << "Loading fit time profile parameters: " << PIDnames[iPID] << std::endl; TH2D *htpdfparmn = (TH2D*)ftprof->Get("htpdfparmn"); TH2D *htpdfparsg = (TH2D*)ftprof->Get("htpdfparsg"); for (int imupar=0; imuparGetBinContent(imupar+1,ippar+1); tpdfpar[iPID][1][imupar][ippar]=htpdfparsg->GetBinContent(imupar+1,ippar+1); } } } else { std::cout << "Loading time profile parameters: " << PIDnames[iPID] << std::endl; for (int i=0; iGet(Form("gtcmnpar_%d",i))); gtpar[iPID][1][i] = new TGraphErrors(*(TGraphErrors*)ftprof->Get(Form("gtcsgpar_%d",i))); } } delete ftprof; std::cout << "Time likelihood parameter " << PIDnames[iPID] << ": pmin=" << tpdfprang[iPID][0] << ", pmax=" << tpdfprang[iPID][1] << std::endl; } } void fiTQun_shared::LoadCProf(int iPID) { //Initialize Cherenkov profile parameters std::cout << "Loading fit Cherenkov profile parameters: " << PIDnames[iPID] << std::endl; TString cProfFileName = Form(fQconstdir+"CProf_%d_fit.root",PIDarr[iPID]); if ( TRuntimeParameters::Get().HasParameter("fiTQun.WCSimConfig") ) { cProfFileName = Form(fQconstdir+"CProf_%d_fit_WCSim.root",PIDarr[iPID]); } TFile *fcprof = new TFile(cProfFileName); if (fcprof->IsZombie()) { std::cout << "Cherenkov profile is missing!" << std::endl; delete fcprof; DeleteInstances(); exit(-1); } TH1D *hprofinf = (TH1D*)fcprof->Get("hprofinf"); int npars=(int)(hprofinf->GetBinContent(1)+0.5); int nsectmax=(int)(hprofinf->GetBinContent(2)+0.5); momofst[iPID]=hprofinf->GetBinContent(3); momminstp[iPID]=hprofinf->GetBinContent(4); momminmax[iPID][0]=hprofinf->GetBinContent(5); momminmax[iPID][1]=hprofinf->GetBinContent(6); delete hprofinf; if (npars!=5) { std::cout << "npars!=5" << std::endl; delete fcprof; DeleteInstances(); exit(-1); } //Initiatize integral table In for (int i=0; i<3; i++) {//I_n TH3D *hI3d = (TH3D*)fcprof->Get(Form("hI3d_par_%d",i)); TH2D *hInsect = (TH2D*)fcprof->Get(Form("hI3d_nsect_%d",i)); if (i==0) {//Set integral table bins if (R0bins==NULL) {//R0, costh0 bins same for all particle types nR0bin=hI3d->GetNbinsX(); nth0bin=hI3d->GetNbinsY(); R0bins = new double[nR0bin]; th0bins = new double[nth0bin]; for (int j=0; jGetXaxis()->GetBinLowEdge(j+1); for (int j=0; jGetYaxis()->GetBinLowEdge(j+1); R0binwrecp=1./(R0bins[1]-R0bins[0]); th0binwrecp=1./(th0bins[1]-th0bins[0]); } nmom[iPID]=(int)((momminmax[iPID][1]-momminmax[iPID][0])/momminstp[iPID]+0.5);//number of momentum bins mombins[iPID] = new double[nmom[iPID]+1]; for (int j=0; j<=nmom[iPID]; j++) mombins[iPID][j]=momminmax[iPID][0]+j*momminstp[iPID]; int nInParPtrs=nR0bin*nth0bin*nmom[iPID]; InParPtr[iPID] = new double*[nInParPtrs*3]; } int nsecttot=(int)(hInsect->Integral()+0.5);//total number of sections InPar[iPID][i] = new double[nsecttot*npars];//array which contains polynomial coefficients int ictr=0; for (int j=0; jGetBinContent(j+1,k+1)+0.5);//number of sections in this R0,th0 bin double *params = new double[(npars+1)*nsect+1]; for (int ipar=0; ipar<=(npars+1)*nsect; ipar++) { params[ipar]=hI3d->GetBinContent(j+1,k+1,ipar+1); } int l=0; for (int isect=0; isectGet(Form("hI_iso_%d",i+1)); int nmomtmp=hIiso->GetNbinsX(); gIniso[iPID][i] = new TGraph(nmomtmp); for (int j=0; jSetPoint(j,hIiso->GetXaxis()->GetBinLowEdge(j+1),hIiso->GetBinContent(j+1)); } } gNphot[iPID] = new TGraph(*(TGraph*)fcprof->Get("gNphot")); int ngpts=gNphot[iPID]->GetN(); gNphtmom[iPID] = new TGraph(ngpts); for (int i=0; iGetPoint(i,gx,gy); gNphtmom[iPID]->SetPoint(i,gy,gx); } gSmax[iPID] = new TGraph(*(TGraph*)fcprof->Get("gsthr")); Load1dpars(fcprof,"gNphot_pars",(npars1dcprof+1)*nsect1dcprof+1,nphotpar[iPID]); Load1dpars(fcprof,"gsthr_pars",(npars1dcprof+1)*nsect1dcprof+1,smaxpar[iPID]); Load1dpars(fcprof,"gI_iso_1_pars",(npars1dcprof+1)*nsect1dcprof+1,Inisopar[iPID][0]); Load1dpars(fcprof,"gI_iso_2_pars",(npars1dcprof+1)*nsect1dcprof+1,Inisopar[iPID][1]); delete fcprof; } void fiTQun_shared::Load1dpars(TFile *fin, const char *ctmp, int npartmp, double *par){ TH1D *hparam = (TH1D*)fin->Get(ctmp); for (int ipar=0; iparGetBinContent(ipar+1); } } double fiTQun_shared::fconpoly(double xval, int npars, int nsect, double *par) { int ibase=npars*nsect;//index of the first boundary int isect; for (isect=0; isect180.) { cosmintotq=-1.; } else { cosmintotq=cos(ctmp/180.*pi); } } void fiTQun_shared::SetActivePMTs(int iflgMode){ double R=this->DetGeomR; double h=this->DetGeomL; double x,y,z; double xh,yh; TFile *fDrPMT; TString ofnmtmp; int PhotCovFrac=iflgMode%10; int TBflag=(iflgMode-PhotCovFrac)/10; if (PhotCovFrac!=1 && PhotCovFrac!=2 && PhotCovFrac!=4) return; if (!(TBflag>=0 && TBflag<4)) return; if (ofnmflg==1) { ofnmtmp=Form("%s_PMTinfo.root",ofnmstr); } else { ofnmtmp="PMTinfo.root"; } chrgfact=(double)PhotCovFrac; std::cout << Form("Reduce photo coverage to 1/%d",PhotCovFrac) << std::endl; std::cout << Form("TBflag = %d",TBflag) << std::endl; // TH2D hPMTs(Form("hPMTinfo_%d",ievent),"",150,-(pi*R)-35.,(pi*R)-35.,147,-(h+2.*R),(h+2.*R)); TH2D hPMTs(Form("hPMTinfo"),"",150,-(pi*R)-35.,(pi*R)-35.,147,-(h+2.*R),(h+2.*R)); for (int i=0; iPMTpos[i][0]; y = this->PMTpos[i][1]; z = this->PMTpos[i][2]; if (z>=h) {//top if (TBflag==1 || TBflag==3) this->PMTtype[i]=-1; xh=-y-35.; yh=-x+h+R; } else if (z<=-h) {//bottom if (TBflag==2 || TBflag==3) this->PMTtype[i]=-1; xh=-y-35.; yh=x-h-R; } else {//side xh=R*acos(x/R); if (y>0) xh=-xh; yh=z; } int ixPMT=hPMTs.GetXaxis()->FindBin(xh); int iyPMT=hPMTs.GetYaxis()->FindBin(yh); if (PhotCovFrac==2) {// 1/2 PMT if ((ixPMT+iyPMT)%2) this->PMTtype[i]=-1; } else if (PhotCovFrac==4) {// 1/4 PMT if (ixPMT%2 || iyPMT%2) this->PMTtype[i]=-1; } hPMTs.Fill(xh,yh,this->PMTtype[i]); } fDrPMT = new TFile(ofnmtmp,"RECREATE"); hPMTs.SetOption("COLZ"); hPMTs.SetMinimum(0.); hPMTs.Write(); delete fDrPMT; } void fiTQun_shared::Setofilenm(char *ofname){ for (int i=0; i<256; i++) { ofnmstr[i]=ofname[i]; fQEventManager::ofname[i]=ofname[i]; if (ofname[i]=='\0') { break; } } ofnmflg=1; } void fiTQun_shared::SetPhi0(int iPhi0, double Phi0val){ if (iPhi0 >= 0) { Phi0[iPhi0] = Phi0val; return; } for (int i=0; i