void plotr0vstheta(){ TFile *f; int isSum=0; if(isSum==0){ f = TFile::Open("mergedV_Prod.root"); } else{ f = TFile::Open("mergedV_Sum.root"); } int xbin=0; // TVectorD* vecVmean = (TVectorD*)f->Get(Form("D_%d/Vmean",xbin)); TVectorD* vecV = (TVectorD*)f->Get(Form("D_%d/D_0/r01",xbin)); double *V = vecV->GetMatrixArray(); double Vmean = getmean(V,ntheta); double theta[ntheta]; for(int itheta=0;itheta<ntheta;itheta++){ theta[itheta]=itheta*TMath::Pi()/ntheta/nn; } int maxper10 = findmaxper(V,ntheta,Vmean); double maxper = (double)(maxper10+2)/10; TGraph *gV2theta = new TGraph(ntheta,theta,V); gV2theta->SetTitle(""); gV2theta->GetXaxis()->SetTitle("#theta"); gV2theta->GetYaxis()->SetTitle("r_{0}"); gV2theta->GetYaxis()->SetTitleOffset(1.1); gV2theta->GetXaxis()->SetTitleSize(0.04); gV2theta->GetYaxis()->SetTitleSize(0.04); gV2theta->SetMarkerStyle(20); gV2theta->SetMarkerSize(1.3); gV2theta->SetMarkerColor(1); gV2theta->SetLineColor(1); gV2theta->SetMinimum(Vmean*(1-maxper*1.5)); gV2theta->SetMaximum(Vmean*(1+maxper*1.5)); gV2theta->Draw("AP"); TLine *lup = new TLine(gV2theta->GetXaxis()->GetXmin(),Vmean*(1+maxper), gV2theta->GetXaxis()->GetXmax(),Vmean*(1+maxper)); TLine *ldown = new TLine(gV2theta->GetXaxis()->GetXmin(),Vmean*(1-maxper), gV2theta->GetXaxis()->GetXmax(),Vmean*(1-maxper)); TLine *l = new TLine(gV2theta->GetXaxis()->GetXmin(),Vmean, gV2theta->GetXaxis()->GetXmax(),Vmean); l->SetLineStyle(2); lup->SetLineStyle(2); ldown->SetLineStyle(2); l->SetLineWidth(1.2); lup->SetLineWidth(1.2); ldown->SetLineWidth(1.2); TLatex *tl = new TLatex(); // tl->SetNDC(); tl->SetTextFont(42); tl->SetTextSize(0.04); // tl->SetBorderStyle(0); tl->DrawLatex(0,Vmean*(1+maxper),Form("mean up %.f%%",maxper*100)); tl->DrawLatex(0,Vmean*(1-maxper),Form("mean down %.f%%",maxper*100)); tl->DrawLatex(1,0.2,Form("Multiplicity %d to %d",120,150)); l->Draw("same"); lup->Draw("same"); ldown->Draw("same"); if(isSum==0)c1->SaveAs("hr0theta_Prod.png"); else c1->SaveAs("hr0theta_Sum.png"); }
Parabola2D::Parabola2D(TVectorD x, TVectorD y, TVectorD z) : Parabola() { // Prepare the members int n = x.GetNoElements(); double* vx = x.GetMatrixArray(); double* vy = y.GetMatrixArray(); double* vz = z.GetMatrixArray(); vector<double> entry_x; vector<double> entry_y; vector<double> entry_z; for(int i=0; i<n; i++){ entry_x.push_back(vx[i]); entry_y.push_back(vy[i]); entry_z.push_back(vz[i]); } entries.push_back(entry_z); // _Has_ to be the first. entries.push_back(entry_x); entries.push_back(entry_y); // And do the magic FillMatrix(); // Do the fitting... FindMinimum(); // Find the Minimum... // Write out the information. The order that the coefficients appear has to be in increasing key, // as explained above. THIS IS IMPORTANT. FitFunction = new TF2("FitFnc","[5]*y*y+[4]*y*x+[3]*y+[2]*x*x+[1]*x+[0]"); for (int i = 0; i<6; i++) FitFunction->SetParameter(i,fit_coef_vec[i]); FitGraph = new TGraph2D(n,vx,vy,vz); }
TGraph *plotGF(int isSum, int xtheta, double *r0_theta, double *G2_theta, int marker, int color){ if(isSum) TFile *f = TFile::Open("mergedV_Sum.root"); else TFile *f = TFile::Open("mergedV_Prod.root"); TVectorD *vecDr = f->Get(Form("D_%d/r",xbin)); TVectorD *vecDg2 = f->Get(Form("D_%d/D_0/D_%d/G2",xbin,xtheta)); TVectorD *vecDr0 = f->Get(Form("D_%d/D_0/r0",xbin,xtheta)); TVectorD *vecDr01 = f->Get(Form("D_%d/D_0/r01",xbin,xtheta)); double *r = vecDr->GetMatrixArray(); double *g2 = vecDg2->GetMatrixArray(); double *r0 = vecDr0->GetMatrixArray(); double *r01 = vecDr01->GetMatrixArray(); (*r0_theta) = r0[xtheta]; for(int ir=0;ir<nstepr;ir++) if(r[ir] == r01[xtheta]) break; (*G2_theta) = g2[ir]; TGraph *gr = new TGraph(nstepr,r,g2); gr->SetMarkerSize(0.5); gr->SetMarkerColor(color); gr->SetMarkerStyle(marker); f->Close(); return gr; }
NBD(TString datastr, TString Glauberstr,TString histonamev){ dataname.SetString(datastr.Data()); Glaubername.SetString(Glauberstr.Data()); histoname.SetString(histonamev.Data()); mubest.ResizeTo(1); kbest.ResizeTo(1); chis.ResizeTo(1); Ndf.ResizeTo(1); };
TGraphErrors* plotTG(int i,bool isSum, int ntheta, TString dirname, int marker, int color){ if(ntheta==5){ if(!isSum) TFile *f = TFile::Open(Form("%s/M%d%d/mergedv_Prod2.root",dirname.Data(),trkpointmax[i],trkpointmin[i])); else TFile *f = TFile::Open(Form("%s/M%d%d/mergedv_Prod.root",dirname.Data(),trkpointmax[i],trkpointmin[i])); } else{ if(!isSum) TFile *f = TFile::Open(Form("theta%d/%s/M%d%d/mergedv_Prod2.root",ntheta,dirname.Data(),trkpointmax[i],trkpointmin[i])); else TFile *f = TFile::Open(Form("theta%d/%s/M%d%d/mergedv_Prod.root",ntheta,dirname.Data(),trkpointmax[i],trkpointmin[i])); } TVectorD *vecDv2 = (TVectorD*)f->Get(Form("D_%d/vmean",ibin)); TVectorD *vecDv2err = (TVectorD*)f->Get(Form("D_%d/deltavmean",ibin)); TVectorD *vecDavgpt = (TVectorD*)f->Get(Form("D_%d/avgpt",ibin)); double *avgpt = vecDavgpt->GetMatrixArray(); double *v2 = vecDv2->GetMatrixArray(); double *v2err = vecDv2err->GetMatrixArray(); int npt = vecDavgpt->GetNrows(); TGraphErrors *gr=new TGraphErrors(npt,avgpt,v2,0,v2err); gr->SetMarkerSize(1.3); gr->SetMarkerStyle(marker); gr->SetMarkerColor(color); gr->SetLineColor(color); f->Close(); return gr; }
double* getEPR(TString indir){ int ibin=0; TFile *f = TFile::Open(Form("%s/mergedVobs.root",indir.Data())); TVectorD *vecDEPR = (TVectorD*)f->Get(Form("D_%d/EPR",ibin)); double *EPR = vecDEPR->GetMatrixArray(); return EPR; }
void LYZ::endJobv(TString outstr){ using namespace std; ofstream fstrdNRe, fstrdNIm, fstrdDRe, fstrdDIm, fstrmult; // fstrdNRe.open("dNRe.txt",ios::app); // fstrdNIm.open("dNIm.txt",ios::app); // fstrdDRe.open("dDRe.txt",ios::app); // fstrdDIm.open("dDIm.txt",ios::app); // fstrmult.open("mult_.txt",ios::app); for(int ibin=0;ibin<nbin;ibin++){ // fstrmult<<Nevent[ibin]<<endl; for(int ivbin=0;ivbin<nvv; ivbin++){ // fstrmult<<(double)totmultv[ibin][ivbin]/Nevent[ibin]<<"\t"; // fstrmult<<(double)totptv[ibin][ivbin]/totmultv[ibin][ivbin]<<"\t"; } for(int itheta=0;itheta<ntheta;itheta++){ for(int ivbin=0;ivbin<nvv; ivbin++){ // fstrdNRe<<dNRe[ibin][itheta][ivbin]<<"\t"; // fstrdNIm<<dNIm[ibin][itheta][ivbin]<<"\t"; } // fstrdNRe<<endl; // fstrdNIm<<endl; // fstrdDRe<<dDRe[ibin][itheta]<<"\t"; // fstrdDIm<<dDIm[ibin][itheta]<<"\t"; } // fstrmult<<tottrk[ibin]<<endl; // fstrmult<<endl<<totmultall[ibin]<<endl; } // fstrmult<<endl; // fstrdNRe<<endl; // fstrdNIm<<endl; // fstrdDRe<<endl; // fstrdDIm<<endl; TFile *fs = new TFile(outstr,"Recreate"); fs->cd(); Nevent.Write("Nevent"); totmultall.Write("totmultall"); tottrk.Write("tottrk"); for(int ibin=0; ibin<nbin; ibin++){ dDRe[ibin].Write(Form("dDRe_%d",ibin)); dDIm[ibin].Write(Form("dDIm_%d",ibin)); for(int itheta=0;itheta<ntheta;itheta++){ dNRe[ibin][itheta].Write(Form("dNRe_%d_%d",ibin,itheta)); dNIm[ibin][itheta].Write(Form("dNIm_%d_%d",ibin,itheta)); } totmultv[ibin].Write(Form("totmult_%d",ibin)); totptv[ibin].Write(Form("totpt_%d",ibin)); totetav[ibin].Write(Form("toteta_%d",ibin)); } fs->Close(); }
void DrawCell( TMVA::PDEFoamCell *cell, TMVA::PDEFoam *foam, Double_t x, Double_t y, Double_t xscale, Double_t yscale ) { // recursively draw cell and it's daughters Float_t xsize = xscale*1.5; Float_t ysize = yscale/3; if (xsize > 0.15) xsize=0.1; //xscale/2; if (cell->GetDau0() != NULL) { TLine *a1 = new TLine(x-xscale/4, y-ysize, x-xscale, y-ysize*2); a1->SetLineWidth(2); a1->Draw(); DrawCell(cell->GetDau0(), foam, x-xscale, y-yscale, xscale/2, yscale); } if (cell->GetDau1() != NULL){ TLine *a1 = new TLine(x+xscale/4, y-ysize, x+xscale, y-ysize*2); a1->SetLineWidth(2); a1->Draw(); DrawCell(cell->GetDau1(), foam, x+xscale, y-yscale, xscale/2, yscale); } TPaveText *t = new TPaveText(x-xsize, y-ysize, x+xsize, y+ysize, "NDC"); t->SetBorderSize(1); t->SetFillStyle(1); // draw all cell elements t->AddText( Form("Intg=%.5f", cell->GetIntg()) ); t->AddText( Form("Var=%.5f", cell->GetDriv()) ); TVectorD *vec = (TVectorD*) cell->GetElement(); if (vec != NULL){ for (Int_t i = 0; i < vec->GetNrows(); ++i) { t->AddText( Form("E[%i]=%.5f", i, vec(i)) ); } } if (cell->GetStat() != 1) { // cell is inactive --> draw split point t->SetFillColor( TColor::GetColor("#BBBBBB") ); t->SetTextColor( TColor::GetColor("#000000") ); // cell position and size TMVA::PDEFoamVect cellPosi(foam->GetTotDim()), cellSize(foam->GetTotDim()); cell->GetHcub(cellPosi, cellSize); Int_t kBest = cell->GetBest(); // best division variable Double_t xBest = cell->GetXdiv(); // best division point t->AddText( Form("dim=%i", kBest) ); t->AddText( Form("cut=%.5g", foam->VarTransformInvers(kBest,cellPosi[kBest] + xBest*cellSize[kBest])) ); } else { t->SetFillColor( TColor::GetColor("#DD0033") ); t->SetTextColor( TColor::GetColor("#FFFFFF") ); } t->Draw(); return; }
void loadVectorsFromFile(const char *filename, const char *scanfmt, TVectorD& v1, TVectorD& v2, TVectorD& v3) { char linein[LINELEN]; vector<double> v; if (TString(scanfmt).Contains("%f")) { cerr << "Must use %lf format for doubles, sorry " << endl; exit(-1); } FILE *fp = fopen(filename, "r"); if (!fp) { cerr << "File failed to open, " << filename << endl; exit(-1); } if (gl_verbose) cout << "Loading vectors from file " << filename << " with scan format \"" << scanfmt << "\"" << endl; while (!feof(fp) && fgets(linein,LINELEN,fp)) { double x1, x2, x3; if( linein[0]=='#' ) continue; // comments are welcome if( sscanf(linein, scanfmt, &x1, &x2, &x3) != 3 ) { cerr << "scan failed, file " << filename << ", line = " << linein; cerr << ", scanfmt = " << scanfmt; cerr << ", skipping" << endl; //return; continue; } else { v.push_back(x1); v.push_back(x2); v.push_back(x3); } } int vecsize = v.size()/3; v1.ResizeTo(vecsize); v2.ResizeTo(vecsize); v3.ResizeTo(vecsize); if (gl_verbose) cout << "; read " << vecsize << " lines" << endl; for (int i=0; i<vecsize; i++) { v1[i] = v[3*i]; v2[i] = v[3*i+1]; v3[i] = v[3*i+2]; } fclose(fp); } // loadVectorsFromFile
// ------------ method called once each job just after ending the event loop ------------ void LYZ::endJobV(TString outstr) { //fstrGRe, fstrGIm // ofstream fstrQx1, fstrQy1, fstrQ2, fstrmult; // fstrGRe.open("GRe.txt",std::ios::app); // fstrGIm.open("GIm.txt",std::ios::app); // fstrQx1.open("Qx1.txt",std::ios::app); // fstrQy1.open("Qy1.txt",std::ios::app); // fstrQ2.open("Q2.txt",std::ios::app); // fstrmult.open("mult.txt",std::ios::app); for(int ibin=0; ibin<nbin; ibin++){ // fstrmult<<Nevent[ibin]<<"\t"; // fstrmult<<totmultall[ibin]<<"\t"; // fstrmult<<tottrk[ibin]<<std::endl; Q2[ibin]+=Qx2[ibin]+Qy2[ibin]; for(int ir=0; ir<nstepr; ir++){ for(int itheta=0;itheta<ntheta;itheta++){ // fstrGRe<<GRe[ibin][itheta][ir]<<"\t"; // fstrGIm<<GIm[ibin][itheta][ir]<<"\t"; } // fstrGRe<<std::endl; // fstrGIm<<std::endl; } // fstrGRe<<std::endl<<std::endl; // fstrGIm<<std::endl<<std::endl; // fstrQx1<<Qx1[ibin]<<"\t"; // fstrQy1<<Qy1[ibin]<<"\t"; // fstrQ2<<Qx2[ibin]+Qy2[ibin]<<"\t"; } // fstrmult.close(); // fstrGRe.close(); // fstrGIm.close(); // fstrQx1.close(); // fstrQy1.close(); // fstrQ2.close(); TFile *fs = new TFile(outstr,"Recreate"); fs->cd(); Nevent.Write("Nevent"); totmultall.Write("totmultall"); totwall.Write("totwall"); totptall.Write("totptall"); totetaall.Write("totetaall"); tottrk.Write("tottrk"); Qx1.Write("Qx1"); Qy1.Write("Qy1"); Q2.Write("Q2"); for(int ibin=0; ibin<nbin; ibin++){ for(int itheta=0;itheta<ntheta;itheta++){ GRe[ibin][itheta].Write(Form("GRe_%d_%d",ibin,itheta)); GIm[ibin][itheta].Write(Form("GIm_%d_%d",ibin,itheta)); } } fs->Close(); }
void loadVectorsFromFile(const char *filename, const char *scanfmt, TVectorD& vx, TVectorD& vy, char xheader[], char yheader[]) { char linein[LINELEN]; vector<double> v; FILE *fp = fopen(filename, "r"); if (!fp) { cerr << "File failed to open, " << filename << endl; return; } if (gl_verbose) cout << "Loading vectors from file " << filename; while (!feof(fp) && fgets(linein,LINELEN,fp)) { double x, y; if( linein[0]=='#' ) { if (!v.size()) { // first line, try to read headers TString hscanfmt(scanfmt); hscanfmt.ReplaceAll("lf","s"); if( sscanf(&linein[1],hscanfmt.Data(),xheader,yheader) != 2 ) { cerr << "failed to read in column headers" << endl; } } continue; // comments are welcome } if( sscanf(linein, scanfmt, &x, &y) != 2 ) { cerr << "scan failed, file " << filename << ", line = " << linein << endl; return; } else { v.push_back(x); v.push_back(y); } } int vecsize = v.size()/2; vx.ResizeTo(vecsize); vy.ResizeTo(vecsize); if (gl_verbose) cout << "; read " << vecsize << " lines" << endl; for (int i=0; i<vecsize; i++) { vx[i] = v[2*i]; vy[i] = v[2*i+1]; } } // loadVectorsFromFile
// ------------ method called once each job just after ending the event loop ------------ void qfit::endJobV(TString outstr) { TFile *fs = new TFile(outstr,"Recreate"); fs->cd(); Nevent.Write("Nevent"); totmultall.Write("totmultall"); totptall.Write("totptall"); totptall2.Write("totptall2"); totetaall.Write("totetaall"); tottrk.Write("tottrk"); q22.Write("q22"); q24.Write("q24"); for(int ibin=0; ibin<nbin; ibin++){ for(int itheta=0;itheta<ntheta;itheta++){ hq[ibin][itheta]->Write(); } hqx[ibin]->Write(); hqy[ibin]->Write(); hq2[ibin]->Write(); hvq2[ibin]->Write(); hq2nonf[ibin]->Write(); } fs->Close(); }
void MultiGaus(const TVectorD& parMeans, const TMatrixDSym& covMatrix, TVectorD& genPars) { TRandom3 rnd(0); int nPars = parMeans.GetNrows(); if(nPars <= 0) { Error("MultiGaus", "Must have >0 pars"); return; } if(covMatrix.GetNrows() != nPars) { Error("MultiGaus", "parMeans.GetNrows() != covMatrix.GetNrows()"); return; } // Check that covMatrix is symmetric for(int iRow = 0; iRow < nPars; iRow++) { for(int iCol = iRow; iCol < nPars; iCol++) { if(covMatrix(iRow, iCol) != covMatrix(iCol, iRow)) { Error("MultiGaus", "malformed cov matrix at row %d, col %d", iRow, iCol); return; } } } genPars.ResizeTo(nPars); TMatrixDSymEigen eigenvariances(covMatrix); TMatrixD V = eigenvariances.GetEigenVectors(); TVectorD rotParMeans = V * parMeans; for(int iPar = 0; iPar < nPars; iPar++) { double variance = eigenvariances.GetEigenValues()[iPar]; // check for positive-definiteness of covMatrix if(variance < 0) { Error("MultiGaus", "Got a negative eigenvariance (%f) on iPar = %d", variance, iPar); } genPars[iPar] = rnd.Gaus(rotParMeans[iPar], sqrt(variance)); } V.Invert(); genPars = V * genPars; }
void writeDataBackgroundHistosForModel(const std::map<TString,TGraph*>& m_bkgds, const std::vector<TH1D *>& vchans, TFile *allHistFile) { for (std::map<TString,TGraph*>::const_iterator it = m_bkgds.begin(); it != m_bkgds.end(); it++) { const TString& name = it->first; // determine binning from the signal histogram for this channel // - (sigh) have to find it first... // TString channame = name.Copy().Remove(0,strlen("Bckgrndtot_")); TH1D *sigh=(TH1D*)0; for (int ichan=0; ichan<NUMCHAN; ichan++) { sigh = vchans.at(ichan); if (strstr(sigh->GetName(),channame.Data())) break; } assert (sigh); // for variable binning - all histos must have the same binning per channel TAxis *xax = sigh->GetXaxis(); TVectorD xbins = TVectorD(sigh->GetNbinsX(),xax->GetXbins()->GetArray()); int lobin = xax->FindFixBin(sumwinmin); int hibin = xax->FindFixBin(sumwinmax)-1; int nbins = hibin-lobin+1; TVectorD xwindow = xbins.GetSub(lobin-1,hibin); printf("Booking TH1D(%s,%s,%d,xwindowarray)\n", name.Data(),name.Data(),nbins); TH1D *h = new TH1D(name.Data(),name.Data(),nbins,xwindow.GetMatrixArray()); for (int ibin=1; ibin <= nbins; ibin++) h->SetBinContent(ibin, it->second->Eval(h->GetBinCenter(ibin)) * h->GetBinWidth(ibin) ); allHistFile->WriteTObject(h); } } // writeDataBackgroundHistosForModel
void dumpElements(TVectorD& a) { cout << endl << endl; a.Print(); cout << endl << endl; return; }
void plotV2vstheta(){ TFile *f; if(isSum==0){ f = TFile::Open("mergedV_Prod.root"); } else{ f = TFile::Open("mergedV_Sum.root"); } int xbin=0; TVectorD* vecVmean = (TVectorD*)f->Get(Form("D_%d/Vmean",xbin)); TVectorD* vecV = (TVectorD*)f->Get(Form("D_%d/D_0/V",xbin)); double Vmean = (*vecVmean)[0]; cout<<Vmean<<endl; double *V = vecV->GetMatrixArray(); double theta[ntheta]; for(int itheta=0;itheta<ntheta;itheta++){ theta[itheta]=itheta*TMath::Pi()/ntheta/nn; cout<<V[itheta]<<endl; } TGraph *gV2theta = new TGraph(ntheta,theta,V); gV2theta->SetMarkerStyle(20); gV2theta->SetMarkerSize(1.3); gV2theta->SetMarkerColor(1); gV2theta->SetLineColor(1); gV2theta->SetMinimum(Vmean*0.98); gV2theta->SetMaximum(Vmean*1.02); gV2theta->Draw("AP"); TLine *lup = new TLine(gV2theta->GetXaxis()->GetXmin(),Vmean*1.01, gV2theta->GetXaxis()->GetXmax(),Vmean*1.01); TLine *ldown = new TLine(gV2theta->GetXaxis()->GetXmin(),Vmean*0.99, gV2theta->GetXaxis()->GetXmax(),Vmean*0.99); TLine *l = new TLine(gV2theta->GetXaxis()->GetXmin(),Vmean, gV2theta->GetXaxis()->GetXmax(),Vmean); l->SetLineStyle(2); lup->SetLineStyle(2); ldown->SetLineStyle(2); l->SetLineWidth(1.2); lup->SetLineWidth(1.2); ldown->SetLineWidth(1.2); l->Draw("same"); lup->Draw("same"); ldown->Draw("same"); if(isSum==0)c1->SaveAs("hV2theta_Prod.png"); else c1->SaveAs("hV2theta_Sum.png"); }
void loadVectorsFromFile(const char *filename, TVectorD& vx, TVectorD& vy, TVectorD& vz) { char linein[LINELEN]; vector<double> v; FILE *fp = fopen(filename, "r"); if (!fp) { cerr << "File failed to open, " << filename << endl; return; } if (gl_verbose) cout << "Loading vectors from file " << filename; while (!feof(fp) && fgets(linein,LINELEN,fp)) { double x, y, z; if( linein[0]=='#' ) continue; // comments are welcome if (sscanf(linein, "%lf %lf %lf", &x, &y, &z) != 3) { cerr << "scan failed, file " << filename << ", line = " << linein << endl; return; } else { v.push_back(x); v.push_back(y); v.push_back(z); } } int vecsize = v.size()/3; vx.ResizeTo(vecsize); vy.ResizeTo(vecsize); vz.ResizeTo(vecsize); if (gl_verbose) cout << "; read " << vecsize << " lines" << endl; for (int i=0; i<vecsize; i++) { vx[i] = v[2*i]; vy[i] = v[2*i+1]; vz[i] = v[2*i+2]; } } // loadVectorsFromFile
double operator() (double *x, double *p) { // 4 parameters int dim = X.GetNrows(); int k = 0; for (int i = 0; i<dim; ++i) { X[i] = x[i] - p[k]; k++; } for (int i = 0; i<dim; ++i) { CovMat(i,i) = p[k]*p[k]; k++; } for (int i = 0; i<dim; ++i) { for (int j = i+1; j<dim; ++j) { // p now are the correlations N(N-1)/2 CovMat(i,j) = p[k]*sqrt(CovMat(i,i)*CovMat(j,j)); CovMat(j,i) = CovMat(i,j); k++; } } if (debug) { X.Print(); CovMat.Print(); } double det = CovMat.Determinant(); if (det <= 0) { Fatal("GausND","Determinant is <= 0 det = %f",det); CovMat.Print(); return 0; } double norm = std::pow( 2. * TMath::Pi(), dim/2) * sqrt(det); // compute the gaussians CovMat.Invert(); double fval = std::exp( - 0.5 * CovMat.Similarity(X) )/ norm; if (debug) { std::cout << "det " << det << std::endl; std::cout << "norm " << norm << std::endl; std::cout << "fval " << fval << std::endl; } return fval; }
void qfit::endJobv(TString outstr){ using namespace std; TFile *fs = new TFile(outstr,"Recreate"); fs->cd(); Nevent.Write("Nevent"); totmultall.Write("totmultall"); tottrk.Write("tottrk"); for(int ibin=0; ibin<nbin; ibin++){ for(int itheta=0;itheta<ntheta;itheta++){ } totmultv[ibin].Write(Form("totmult_%d",ibin)); totptv[ibin].Write(Form("totpt_%d",ibin)); totetav[ibin].Write(Form("toteta_%d",ibin)); } fs->Close(); }
TGraph *plotGF(int isSum, int xtheta, double *r0_theta, double *G2_theta, int marker, int color){ TFile *f = TFile::Open("mergedV.root"); TVectorD *vecDr = f->Get(Form("r")); TVectorD *vecDGRe = f->Get(Form("GRe")); TVectorD *vecDGIm = f->Get(Form("GIm")); TVectorD *vecDG2 = f->Get(Form("G2")); double *r = vecDr->GetMatrixArray(); double *GRe = vecDGRe->GetMatrixArray(); double *GIm = vecDGIm->GetMatrixArray(); double *G2 = vecDG2->GetMatrixArray(); TGraph *gr = new TGraph(nstepr,r,G2); if(isSum){ gcl->SetNpx(10000); //gcl->SetParameters(sigma2[xtheta]-inV2*inV2*avgmult[xbin]*avgmult[xbin],inV2*avgmult[xbin]); //linv->SetX1(j01/avgmult[xbin]/inV2); //linv->SetX2(j01/avgmult[xbin]/inV2); //linv->SetY2(5e-9); } gr->SetMarkerSize(0.5); gr->SetMarkerColor(color); gr->SetMarkerStyle(marker); f->Close(); return gr; }
void plotV2vstheta(){ gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetErrorX(0); int xbin = 0; TFile *f = new TFile("mergedV_Prod.root"); TVectorD *vecV = (TVectorD*)f->Get(Form("D_%d/V")); TVectorD *vecdeltaV = (TVectorD*)f->Get(Form("D_%d/deltaV")); TVectorD *vecVmean = (TVectorD*)f->Get(Form("Vmean")); double *V = vecV->GetMatrixArray(); double *deltaV = vecdeltaV->GetMatrixArray(); double *Vmean = vecVmean->GetMatrixArray(); double theta[ntheta]; for(int itheta=0;itheta<ntheta;itheta++){ theta[itheta]=itheta*TMath::Pi()/ntheta/nn; } TH1D *hFrame = new TH1D("","",300,-1,2); hFrame->GetXaxis()->SetTitle("#theta"); hFrame->GetYaxis()->SetTitle("referenceV_{2}"); hFrame->GetXaxis()->SetTitleSize(0.04); hFrame->GetYaxis()->SetTitleSize(0.04); hFrame->GetXaxis()->SetRangeUser(-0.1,1.5); hFrame->SetMaximum(0.055); hFrame->SetMinimum(0.045); hFrame->Draw(); TGraphErrors *gr = new TGraphErrors(ntheta,theta,V,0,deltaV); gr->SetMarkerSize(1.2); gr->SetMarkerStyle(20); gr->Draw("Psame"); TLine *l = new TLine(0,inV2,1.4,inV2); l->SetLineStyle(2); l->Draw("same"); c1->Print("V2vstheta.png"); }
TMatrixD Chol (TVectorD& covV, TVectorD& newSig) { int nCov = covV.GetNrows(); int n = newSig.GetNrows(); std::cout << nCov << " " << n << std::endl; if ( nCov != n*(n+1)/2. ) { std::cout << "vecTest: mismatch in inputs" << std::endl; return TMatrixD(); } // // create modified vector (replacing std.dev.s) // TVectorD newCovV(covV); int ind(0); for ( int i=0; i<n; ++i ) { for ( int j=0; j<=i; ++j ) { if ( j==i ) newCovV[ind] = newSig(i); ++ind; } } return Chol(newCovV,newSig); }
TGraphErrors* plot(int ieta, int color,int marker){ int ibin=0; TFile *f = TFile::Open("mergedVobs.root"); TVectorD *vecDv2 = (TVectorD*)f->Get(Form("D_%d/E_%d/v2",ibin,ieta)); TVectorD *vecDv2obs = (TVectorD*)f->Get(Form("D_%d/E_%d/v2obs",ibin,ieta)); TVectorD *vecDv2sub3 = (TVectorD*)f->Get(Form("D_%d/E_%d/v23sub",ibin,ieta)); //TVectorD *vecDv2err = (TVectorD*)f->Get(Form("D_%d/deltavmean",ibin)); TVectorD *vecDavgpt = (TVectorD*)f->Get(Form("D_%d/avgpt",ibin)); double *avgpt = vecDavgpt->GetMatrixArray(); double *v2 = vecDv2->GetMatrixArray(); double *v2sub3 = vecDv2sub3->GetMatrixArray(); //double *v2err = vecDv2err->GetMatrixArray(); TGraphErrors *gr=new TGraphErrors(npt,avgpt,v2sub3,0,0); gr->SetTitle("v_{2} vs momentum"); gr->GetXaxis()->SetTitle("p_{T} (GeV/c)"); gr->GetYaxis()->SetTitle("v_{2}"); gr->SetMarkerSize(1); gr->SetMarkerColor(color); gr->SetMarkerStyle(marker); f->Close(); return gr; }
// ------------ method called once each job just before starting event loop ------------ void LYZ::beginJob() { double Vmax[nbin], eps[nbin]; for(int ibin=0; ibin<nbin ; ibin++) { Vmax[ibin]=0.065*(trkbin[ibin]+30); eps[ibin]=0.00025*(trkbin[ibin]+30); } Nevent.ResizeTo(nbin); totmultall.ResizeTo(nbin), tottrk.ResizeTo(nbin);; Nevent.Zero(); totmultall.Zero(), tottrk.Zero(); for(int ibin=0; ibin<nbin; ibin++) { for(int iptbin=0; iptbin<nptV; iptbin++) { Qx2[ibin][iptbin]=0; Qy2[ibin][iptbin]=0; } } for(int itheta=0; itheta<ntheta; itheta++) { theta[itheta]=itheta*TMath::Pi()/ntheta/nn; for(int ibin=0; ibin<nbin; ibin++) { for(int iptbin=0; iptbin<nptV; iptbin++) { GRe[ibin][iptbin][itheta].ResizeTo(nstepr); GRe[ibin][iptbin][itheta].Zero(); GIm[ibin][iptbin][itheta].ResizeTo(nstepr); GIm[ibin][iptbin][itheta].Zero(); } } } for(int ibin=0; ibin<nbin; ibin++) { for(int ir=0; ir<nstepr; ir++) if(isSimple==0) r[ibin][ir]=j01/(Vmax[ibin]-eps[ibin]*ir); else r[ibin][ir]=0.00025*20*(ir+1); Qx1[ibin].ResizeTo(nptV); Qy1[ibin].ResizeTo(nptV); Q2[ibin].ResizeTo(nptV); Qx1[ibin].Zero(); Qy1[ibin].Zero(); Q2[ibin].Zero(); totmult[ibin].ResizeTo(nptv); totmult[ibin].Zero(); totpt[ibin].ResizeTo(nptv); totpt[ibin].Zero(); dDRe[ibin].ResizeTo(ntheta); dDRe[ibin].Zero(); dDIm[ibin].ResizeTo(ntheta); dDIm[ibin].Zero(); for(int itheta=0; itheta<ntheta; itheta++) { dNRe[ibin][itheta].ResizeTo(nptv); dNRe[ibin][itheta].Zero(); dNIm[ibin][itheta].ResizeTo(nptv); dNIm[ibin][itheta].Zero(); } } }
TGraph *plotGF(int isSum, int xtheta, double *r0_theta, double *G2_theta, int marker, int color){ if(isSum) TFile *f = TFile::Open("mergedV_Sum.root"); else TFile *f = TFile::Open("mergedV_Prod.root"); TVectorD *vecDr = f->Get(Form("D_%d/r",xbin)); TVectorD *vecDg2 = f->Get(Form("D_%d/D_%d/G2",xbin,xtheta)); TVectorD *vecDr0 = f->Get(Form("D_%d/r0",xbin)); TVectorD *vecDr01 = f->Get(Form("D_%d/r01",xbin)); TVectorD *vecDsigma2 = f->Get(Form("D_%d/sigma2",xbin)); TVectorD *vecDavgmult = f->Get(Form("avgmult")); double *r = vecDr->GetMatrixArray(); double *g2 = vecDg2->GetMatrixArray(); double *r0 = vecDr0->GetMatrixArray(); double *r01 = vecDr01->GetMatrixArray(); double *sigma2 = vecDsigma2->GetMatrixArray(); double *avgmult = vecDavgmult->GetMatrixArray(); (*r0_theta) = r0[xtheta]; for(int ir=0;ir<nstepr;ir++) if(r[ir] == r01[xtheta]) break; (*G2_theta) = g2[ir]; TGraph *gr = new TGraph(nstepr,r,g2); if(isSum){ gcl->SetNpx(10000); gcl->SetParameters(sigma2[xtheta]-inV2*inV2*avgmult[xbin]*avgmult[xbin],inV2*avgmult[xbin]); linv->SetX1(j01/avgmult[xbin]/inV2); linv->SetX2(j01/avgmult[xbin]/inV2); linv->SetY2(5e-9); } gr->SetMarkerSize(0.5); gr->SetMarkerColor(color); gr->SetMarkerStyle(marker); f->Close(); return gr; }
double *read(TString dir, int isSum, int i, int isV2){ if(isSum==0) TFile *f = TFile::Open(Form("../../%s/M%d%d/mergedV_Prod.root",dir.Data(),trkpointmax[i],trkpointmin[i])); else TFile *f = TFile::Open(Form("../../%s/M%d%d/mergedV_Sum.root",dir.Data(),trkpointmax[i],trkpointmin[i])); int xbin=0; int xpt=0; const int nn = 2; TVectorD *vecNtrk = (TVectorD*)f->Get("avgtrk"); TVectorD *vecavgmult = (TVectorD*)f->Get("avgmultall"); if(dir=="tracknormcpt03to6"){ TVectorD *vecV2mean_0=(TVectorD*)f->Get(Form("Vmean",xbin)); TVectorD *vecV2_0=(TVectorD*)f->Get(Form("D_%d/V",xbin)); TVectorD *vecr0_0=(TVectorD*)f->Get(Form("D_%d/r0",xbin)); } else{ TVectorD *vecV2mean_0=(TVectorD*)f->Get(Form("D_%d/Vmean",xbin)); TVectorD *vecV2_0=(TVectorD*)f->Get(Form("D_%d/D_%d/V",xbin,xpt)); TVectorD *vecr0_0=(TVectorD*)f->Get(Form("D_%d/D_%d/r0",xbin,xpt)); } // TVectorD *vecV2err_0=(TVectorD*)f->Get(Form("D_%d/D_%d/deltaV",xbin,xpt)); double *V2_0=vecV2_0->GetMatrixArray(); double *r0_0=vecr0_0->GetMatrixArray(); if(dir=="tracknormcpt03to6") avgmult = vecavgmult->GetMatrixArray(); // double *V2err_0=vecV2err_0->GetMatrixArray(); double theta[ntheta]; for(int itheta=0;itheta<ntheta;itheta++){ theta[itheta]=itheta*TMath::Pi()/ntheta/nn; } f->Close(); if(isV2) return V2_0; else return r0_0; }
void initN(double *binv, int Nv, double methodv){ centbin.ResizeTo(Nv); kpoint.ResizeTo(Nv); centbin_.ResizeTo(Nv); kpoint_.ResizeTo(Nv); method.ResizeTo(1); if(methodv==0){ centbin=TVectorD(Nv,binv); centbin_=TVectorD(Nv,binv); } else{ kpoint=TVectorD(Nv,binv); kpoint_=TVectorD(Nv,binv); } N=Nv-1; method[0]=methodv; NpartAver.ResizeTo(N); NcollAver.ResizeTo(N);BAver.ResizeTo(N); Npartdis = new TObjArray(0); };
void dumpElements(TVectorD& a) { cout << endl << endl; const int nrows = a.GetNoElements(); cout << "------------------------------------------------------------------" << endl; for(int i=0; i< nrows; i++) { cout << a(i) << ", \t"; cout << endl; } cout << "------------------------------------------------------------------" << endl; cout << endl << endl; return; }
void loadVectorsFromFile(const char *filename, const char *scanfmt, TVectorD& vx, TVectorD& vy, TVectorD& exl,TVectorD& exh, TVectorD& eyl,TVectorD& eyh) { char linein[LINELEN]; vector<double> v; FILE *fp = fopen(filename, "r"); if (!fp) { cerr << "File failed to open, " << filename << endl; return; } if (gl_verbose) cout << "Loading vectors from file " << filename; while (!feof(fp) && fgets(linein,LINELEN,fp)) { double x, y, ymin,ymax; if( linein[0]=='#' ) continue; // comments are welcome if (sscanf(linein, scanfmt, &x, &ymin, &ymax, &y) != 4) { cerr << "scan failed, file " << filename << ", line = " << linein << endl; return; } else { v.push_back(x); v.push_back(y); v.push_back(0); v.push_back(0); v.push_back(y-ymin); v.push_back(ymax-y); } } int vecsize = v.size()/6; vx.ResizeTo(vecsize); vy.ResizeTo(vecsize); exl.ResizeTo(vecsize); exh.ResizeTo(vecsize); eyl.ResizeTo(vecsize); eyh.ResizeTo(vecsize); if (gl_verbose) cout << "; read " << vecsize << " lines" << endl; for (int i=0; i<vecsize; i++) { vx[i] = v[6*i]; vy[i] = v[6*i+1]; exl[i] = v[6*i+2]; exh[i] = v[6*i+3]; eyl[i] = v[6*i+4]; eyh[i] = v[6*i+5]; } } // loadVectorsFromFile
bool TProtoSerial::operator() (TVectorD& v, int protoField) { CHECK_FIELD(); switch (Mode) { case ESerialMode::IN: { const NGroundProto::TVectorD* vecProto = GetEmbedMessage<NGroundProto::TVectorD>(protoField); v = TVectorD(vecProto->x_size()); for (size_t vecIdx=0; vecIdx < v.size(); ++vecIdx) { v(vecIdx) = vecProto->x(vecIdx); } } break; case ESerialMode::OUT: { NGroundProto::TVectorD* vecProto = GetEmbedMutMessage<NGroundProto::TVectorD>(protoField); for (const auto& val: v) { vecProto->add_x(val); } } break; } return true; }