//================================================ void DeltaZVsPt(const Int_t save = 0) { THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType])); TH2F *hTrkDzVsPt = (TH2F*)hn->Projection(1,0); c = draw2D(hTrkDzVsPt,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_vs_pt_%s.pdf",run_type,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_vs_pt_%s.png",run_type,trigName[kTrigType])); } Double_t pt_cut = 1; hTrkDzVsPt->GetXaxis()->SetRangeUser(pt_cut+0.1,100); TH1F *hMthDz = (TH1F*)hTrkDzVsPt->ProjectionY(Form("hTrkDzVsPt_%s_proj",trigName[kTrigType])); hMthDz->SetTitle(Form("%s: #Deltaz of matched track-hit pairs (p_{T}>%1.1f GeV/c);#Deltaz (cm)",trigName[kTrigType],pt_cut)); TH1F *hClone = (TH1F*)hMthDz->Clone(Form("%s_clone",hMthDz->GetName())); c = draw1D(hClone,"",kFALSE,kFALSE); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_%s.pdf",run_type,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_%s.png",run_type,trigName[kTrigType])); } Double_t range = 50; TF1 *func = new TF1("func","gaus(0)+gaus(3)",-1*range,range); func->SetParameters(10000,0,10,1000,0,40); c = FitDeltaZ(hMthDz,func,range,20.); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%s.pdf",run_type,pt_cut,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%s.png",run_type,pt_cut,trigName[kTrigType])); } // pt dependence Double_t pt_cuts[5] = {1,2,3,5,20}; for(Int_t i=0; i<4; i++) { hTrkDzVsPt->GetXaxis()->SetRangeUser(pt_cuts[i]+0.1,pt_cuts[i+1]-0.1); TH1F *htmp = (TH1F*)hTrkDzVsPt->ProjectionY(Form("hTrkDz_pt%1.0f-%1.0f_%s",pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); htmp->SetTitle(Form("%s: #Deltaz of matched track-hit pairs (%1.0f < p_{T} < %1.0f GeV/c);#Deltaz (cm)",trigName[kTrigType],pt_cuts[i],pt_cuts[i+1])); TF1 *func = new TF1(Form("func_pt%1.0f-%1.0f",pt_cuts[i],pt_cuts[i+1]),"gaus(0)+gaus(3)",-1*range,range); if(i==0) func->SetParameters(100,0,100,1000,0,10); if(i==1) func->SetParameters(1000,0,15,1000,0,60); if(i==2) func->SetParameters(1000,0,15,1000,0,60); if(i==3) func->SetParameters(1000,0,60,1000,0,15); c = FitDeltaZ(htmp,func,range,20.); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%1.0f_%s.pdf",run_type,pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%1.0f_%s.png",run_type,pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); } } }
void gg_analysis(){ gStyle->SetOptStat(kFALSE); gStyle->SetPadGridX(false); gStyle->SetPadGridY(false); //gStyle->SetHistMinimumZero(1); const Double_t fitmin = 500; const Double_t fitmax = 700; TFile *sim; sim = new TFile("./geant4spec/78cu_h_77ni_610.root"); TH2F *hsim_id_doppler; hsim_id_doppler = (TH2F*)sim->Get("addback_mult_4;1"); TH1D *hsim; hsim = new TH1D("hsim","hsim",200,0,5000); hsim = (TH1D*)hsim_id_doppler->ProjectionY("hsim",1,186); peakg[0] = new TGraph(hsim); TFile *gg_exp; gg_exp = new TFile("./gg_test_Ni77.root"); TH2F *hh; hh = (TH2F*)gg_exp->Get("h_gg;1"); // ========= GG analysis with Fit ========= // define fit function (gaus+pol0) TF1 *whole1 = new TF1( "whole1", ex_respf1,fitmin,fitmax,5); whole1->SetParameters(1,1.9,-0.000080,1.9,-0.000080); whole1->SetParLimits(0,0.0001,1000.1); whole1->SetParLimits(1,0,10); whole1->SetParLimits(2,-0.1,0); whole1->SetParLimits(3,0,10); whole1->SetParLimits(4,-0.1,0); whole1->SetLineColor(1); whole1->SetLineWidth(2); // prepare histogram (TGraphError is also ok) TH1F *hgg = new TH1F("hgg","GG spectrum gated on the first peak (fit method)",200,0.,5000.); // fit for(int bin=1;bin<=200;bin++){ // 25 keV/bin from 0 to 5000 keV hh->ProjectionY("htmp",bin,bin); htmp->Fit(whole1,"rLwwq"); cout<<"bin = "<<bin<<", counts = "<<whole1->GetParameter(0)*50000<<endl; hgg->SetBinContent(bin, whole1->GetParameter(0)*50000); //hgg->SetBinError(bin, whole1->GetParError(0)); } // draw spectrum TCanvas *fCanvas=new TCanvas("Canvas","77Ni",700,500); fCanvas->SetBorderSize(0); fCanvas->SetBorderMode(0); fCanvas->SetFrameBorderMode(0); fCanvas->SetFrameFillColor(0); fCanvas->SetBottomMargin(0.15); fCanvas->cd(); hgg->Draw(); }
void AliITSLegoPlot(Float_t nchtheta, Float_t nchphi, const char *inFile = "galice.root") { // macro to visualize the lego plots generated by gAlive->RunLego gROOT->Reset(); TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile); if (!file->IsOpen()) { cerr<<"Can't open "<<inFile<<" !" << endl; return 1; } // end if !file Float_t theta = 10; Float_t phi = 170; Int_t ncont = 50; TCanvas *cradl = new TCanvas("cradl","radl",10,10,800,600); cradl->SetTheta(theta); cradl->SetPhi(phi); TH2F *hradl = (TH2F*)file->Get("hradl"); hradl->SetStats(kFALSE); hradl->GetXaxis()->SetTitle("Phi (degrees)"); hradl->GetYaxis()->SetTitle("Theta (degrees)"); hradl->SetFillColor(2); hradl->SetContour(ncont); hradl->Draw("colz"); TCanvas *cradlx = new TCanvas("cradl1","radl",50,50,800,600); hradl->ProjectionX(); hradl_px->SetStats(kFALSE); // hradl_px->SetOptLogY(); // hradl_px->SetMinimum(0.001); // hradl_px->SetMaximum(1); hradl_px->Scale(1./nchtheta); hradl_px->GetXaxis()->SetTitle("Phi (degrees)"); hradl_px->GetYaxis()->SetTitle("X/X0"); hradl_px->Draw(); // cout << "Average over Phi: " << hradl_px->GetSumOfWeights()/nchphi << " X/X0" << endl; TCanvas *cradly = new TCanvas("cradl2","radl",100,100,800,600); hradl->ProjectionY(); hradl_py->SetStats(kFALSE); // hradl_py->SetOptLogY(); // hradl_py->SetMinimum(0.001); // hradl_py->SetMaximum(1); hradl_py->Scale(1./nchphi); hradl_py->GetXaxis()->SetTitle("Theta (degrees)"); hradl_py->GetYaxis()->SetTitle("X/X0"); hradl_py->Draw(); // cout << "Average over Theta: " << hradl_py->GetSumOfWeights()/nchtheta << " X/X0" << endl; cout << "Average: " << hradl_py->GetSumOfWeights()/nchtheta << " X/X0" << endl; }
void getmult(){ const int ncent = 6; int centmin[ncent] = {0,6,11,21,41,61}; int centmax[ncent] = {5,10,20,40,60,80}; TFile *f=TFile::Open("../../../work/200GeV/output_Ridge.root"); TFile *f1=TFile::Open("../../../work/200GeV/output_Ridge.root"); // for(int icent=0;icent<ncent;icent++){ //TH2F* hbbcsnfvtxs = (TH2F*)f->Get(Form("hbbcsnfvtxs_%d",icent)); TH2F* hcentnfvtxs = (TH2F*)f->Get(Form("hcentnfvtxs")); TH2F* hcentbbcs = (TH2F*)f1->Get(Form("hcentbbcs")); for(int icent=0;icent<ncent;icent++){ cout<<icent<<endl; h1 = hcentnfvtxs->ProjectionY("h1",centmin[icent]+1,centmax[icent]+1); h2 = hcentbbcs->ProjectionY("h2",centmin[icent]+1,centmax[icent]+1); //hbbcsnfvtxs->GetYaxis()->SetRangeUser(0,50); //cout<<"mean bbc mult = "<<hbbcsnfvtxs->GetMean(1)<<endl; //cout<<"mean fvtx mult = "<<hbbcsnfvtxs->GetMean(2)<<endl; cout<<"mean bbc mult = "<<h2->GetMean(1)<<endl; cout<<"mean fvtx mult = "<<h1->GetMean(1)<<endl; } }
void Drawbbc(){ TFile *f = new TFile("merged.root"); TH1D* hbbcs; TH1D* hbbcn; TCanvas *c1; TCanvas *c2; TLegend *leg = new TLegend(0.5,0.7,0.7,0.85); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetTextSize(0.048); TH2F* bbcsbbcn = (TH2F*)f->Get(Form("bbcsbbcn_0")); for(int xcent=1; xcent < 6; xcent++){ TH1F* bbcsbbcndis_t = (TH1F*)f->Get(Form("bbcsbbcn_%d",xcent)); bbcsbbcn->Add(bbcsbbcndis_t); } hbbcs = (TH1D*)bbcsbbcn->ProjectionX("bbcs",0,-1); hbbcn = (TH1D*)bbcsbbcn->ProjectionY("bbcn",0,-1); hbbcs->Rebin(4); hbbcn->Rebin(4); c1= new TCanvas(); c1->cd(); c1->SetLogy(); SetTitle(*hbbcs,"bbc charge","# of events",""); SetRange(*hbbcs,0,1e-1,100,hbbcn->GetMaximum()*5); SetStyle(*hbbcs,1.2,1,20,0,0); SetStyle(*hbbcn,1.2,2,24,0,0); hbbcs->Draw("P"); hbbcn->Draw("Psame"); leg->AddEntry(hbbcs,"bbc south"); leg->AddEntry(hbbcn,"bbc north"); leg->Draw("same"); c1->Print(Form("bbcdis.png")); c2= new TCanvas(); c2->cd(); c2->SetLogy(); hbbcs_norm = (TH1D*)hbbcs->Clone("hbbcs_norm"); hbbcn_norm = (TH1D*)hbbcn->Clone("hbbcn_norm"); hbbcs_norm->Scale(1./hbbcs_norm->Integral()); hbbcn_norm->Scale(1./hbbcn_norm->Integral()); SetRange(*hbbcs_norm,0,1e-9,100,1); hbbcs_norm->Draw("P"); hbbcn_norm->Draw("Psame"); leg->Draw("same"); c2->Print(Form("bbcdis_norm.png")); c3= new TCanvas(); c3->cd(); c3->SetLogz(); SetTitle(*bbcsbbcn,"bbc charge south","bbc charge north","# of events"); SetRange(*bbcsbbcn,0,0,100,100); bbcsbbcn->Draw("colz"); c3->Print("bbcsbbcn.png"); }
TH1D * getSpectrum(TFile * f, char * type, int minCent, int maxCent, double etaMin, double etaMax ) { TH3F *h = (TH3F*) f->Get(Form("%s",type)); h->GetZaxis()->SetRangeUser( minCent+0.001, maxCent-0.001); TH2F * ch = (TH2F*) h->Project3D("yxe"); TH1D* hPt; TH1D* hPtN; Int_t etabin10m=ch->GetXaxis()->FindBin(etaMin+0.01); Int_t etabin10p=ch->GetXaxis()->FindBin(etaMax-0.01); Int_t Netabin10p=ch->GetXaxis()->FindBin(-etaMin-0.01); Int_t Netabin10m=ch->GetXaxis()->FindBin(-etaMax+0.01); hPt = (TH1D*) ch->ProjectionY(Form("hPt_%d",rand()),etabin10m,etabin10p,"e"); hPtN = (TH1D*) ch->ProjectionY("hPtN",Netabin10m,Netabin10p,"e"); hPt->Add( hPtN, 1.0); delete h; delete ch; delete hPtN; return hPt; }
TH1D* Template::getProjected1DTemplate(unsigned int axis) /*****************************************************************/ { if(axis>=numberOfDimensions()) { stringstream error; error << "Template::getProjected1DTemplate(): Projection requested on axis "<<axis<<" for "<<numberOfDimensions()<<"D template '"<<m_name<<"'\n"; throw runtime_error(error.str()); } unsigned int nbins1 = 0; unsigned int nbins2 = 0; if(axis==0) { nbins1 = m_template->GetNbinsY(); nbins2 = m_template->GetNbinsZ(); } else if(axis==1) { nbins1 = m_template->GetNbinsX(); nbins2 = m_template->GetNbinsZ(); } else if(axis==2) { nbins1 = m_template->GetNbinsX(); nbins2 = m_template->GetNbinsY(); } stringstream projName; projName << m_template->GetName() << "_projFromTmp"<< axis; TH1D* projectedTemplate = NULL; if(numberOfDimensions()==2) { TH2F* tmp = dynamic_cast<TH2F*>(m_template); if(axis==0) projectedTemplate = tmp->ProjectionX(projName.str().c_str(), 1, nbins1, "e"); else if(axis==1) projectedTemplate = tmp->ProjectionY(projName.str().c_str(), 1, nbins1, "e"); } if(numberOfDimensions()==3) { TH3F* tmp = dynamic_cast<TH3F*>(m_template); if(axis==0) projectedTemplate = tmp->ProjectionX(projName.str().c_str(), 1, nbins1, 1, nbins2, "e"); else if(axis==1) projectedTemplate = tmp->ProjectionY(projName.str().c_str(), 1, nbins1, 1, nbins2, "e"); else if(axis==2) projectedTemplate = tmp->ProjectionZ(projName.str().c_str(), 1, nbins1, 1, nbins2, "e"); } return projectedTemplate; }
INT MDQ_PulseShapes_eor(INT run_number) // Make projection { typedef std::map<std::string, std::string>::iterator String2StringMapIter; std::map<std::string, std::string> Bank2DetMap = gSetup->fBankToDetectorMap; for(String2StringMapIter mapIter = Bank2DetMap.begin(); mapIter != Bank2DetMap.end(); mapIter++) { std::string bankname = mapIter->first; std::string detname = gSetup->GetDetectorName(bankname); if (DQ_PulseShapes_histograms_map.find(bankname) != DQ_PulseShapes_histograms_map.end()) { TH2F* hPulseShapes = DQ_PulseShapes_histograms_map[bankname]; TH1D* hDQ_Histogram_projY = hPulseShapes->ProjectionY(); DQ_PulseShapesProjectionY_histograms_map[bankname]->Add( hDQ_Histogram_projY, 1); hDQ_Histogram_projY->SetDirectory(0); // not save this in the output // Take pedestal and noise as mean and RMS of the projections // but first set the range so that we don't get the massive bins at 0 or the max_adc_value hDQ_Histogram_projY->GetXaxis()->SetRange(2, hDQ_Histogram_projY->GetNbinsX()-1); int max_bin = hDQ_Histogram_projY->GetMaximumBin(); double pedestal = hDQ_Histogram_projY->GetBinCenter(max_bin); double pedestal_value = hDQ_Histogram_projY->GetBinContent(max_bin); double noise = 0; for (int iBin = max_bin; iBin < hDQ_Histogram_projY->GetNbinsX(); ++iBin) { double value = hDQ_Histogram_projY->GetBinContent(iBin); if (value < 0.5*pedestal_value) { noise = hDQ_Histogram_projY->GetBinCenter(iBin) - pedestal; break; } } std::string binlabel = bankname + " (" + detname + ")"; hDQ_PulseShapes_Pedestals->Fill(binlabel.c_str(), pedestal); hDQ_PulseShapes_Noises->Fill(binlabel.c_str(), 2*noise); // at the moment, noise is just from the peak to the half-way down on one side so multiply by 2 } } return SUCCESS; }
void getResv(){ double theta[ntheta]; TFile *f[nFileAlltrack]; for(int itheta=0;itheta<ntheta;itheta++) theta[itheta]=itheta*TMath::Pi()/ntheta/nn; string SumorProd = getenv("SUMORPROD"); string mdir = getenv("DIR"); ofstream fstrv; if(SumorProd=="Sum")fstrv.open("v.txt"); else fstrv.open("v_2.txt"); TVectorD totmult[nbin], totpt[nbin]; TVectorD Nevent, totmultall, totmultall_; TVectorD totmulthisto[nbin], totmulthistocorr[nbin]; TVectorD V_int, V_interr; TVectorD V_intcorr, V_intcorrerr; TVectorD* V_mean; TVectorD* deltaV_mean; TVectorD* V[nbin]; TVectorD* chi[nbin]; TVectorD* dDRe[nbin]; TVectorD* dDIm[nbin]; TVectorD* dNRe[nbin][ntheta]; TVectorD* dNIm[nbin][ntheta]; TComplex dD[nbin][ntheta], dN[nbin][ntheta][nptv]; TVectorD avgmult[nbin]; TVectorD avgmultall; TVectorD avgpt[nbin]; TVectorD v[nbin][ntheta],vmean[nbin],deltav[nbin][ntheta],deltavmean[nbin]; if(SumorProd=="Sum") TFile *infile = TFile::Open("mergedV_Sum.root"); else TFile *infile = TFile::Open("mergedV_Prod.root"); Nevent.ResizeTo(nbin); Nevent.Zero(); totmultall.ResizeTo(nbin); totmultall.Zero(); totmultall_.ResizeTo(nbin); totmultall_.Zero(); avgmultall.ResizeTo(nbin); V_int.ResizeTo(nbin); V_int.Zero(); V_interr.ResizeTo(nbin); V_interr.Zero(); V_intcorr.ResizeTo(nbin); V_intcorr.Zero(); V_intcorrerr.ResizeTo(nbin); V_intcorrerr.Zero(); for(int ibin=0;ibin<nbin;ibin++){ totmult[ibin].ResizeTo(nptv); totmult[ibin].Zero(); totmulthisto[ibin].ResizeTo(nptv); totmulthistocorr[ibin].ResizeTo(nptv); avgmult[ibin].ResizeTo(nptv); avgpt[ibin].ResizeTo(nptv); totpt[ibin].ResizeTo(nptv); totpt[ibin].Zero(); vmean[ibin].ResizeTo(nptv); deltavmean[ibin].ResizeTo(nptv); V[ibin] = (TVectorD*) infile->Get(Form("D_%d/D_0/V",ibin)); chi[ibin] = (TVectorD*) infile->Get(Form("D_%d/chi",ibin)); V_mean = (TVectorD*) infile->Get(Form("D_%d/Vmean",ibin)); deltaV_mean = (TVectorD*) infile->Get(Form("D_%d/deltaVmean",ibin)); for(int itheta=0;itheta<ntheta;itheta++){ v[ibin][itheta].ResizeTo(nptv); deltav[ibin][itheta].ResizeTo(nptv); dD[ibin][itheta]=0; for(int iptbin=0;iptbin<nptv;iptbin++){ dN[ibin][itheta][iptbin]=0; } } } for(int ifile=0; ifile<nFileAlltrack; ifile++){ if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/lio/lfs/cms/store/user/qixu/flow/pbsjoboutput/PFcandpt01to10tracknormcpt03to6/%s/Anav_Prod_%d.root",mdir.c_str(),ifile)); else f[ifile] = TFile::Open(Form("/lio/lfs/cms/store/user/qixu/flow/pbsjoboutput/PFcandpt01to10tracknormcpt03to6/%s/Anav_Prod2_%d.root",mdir.c_str(),ifile)); TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get("Nevent"); TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get("totmultall"); for(int ibin=0;ibin<nbin;ibin++){ TVectorD* totmult_t = (TVectorD*)f[ifile]->Get(Form("totmult_%d",ibin)); TVectorD* totpt_t = (TVectorD*)f[ifile]->Get(Form("totpt_%d",ibin)); dDRe[ibin] = (TVectorD*)f[ifile]->Get(Form("dDRe_%d",ibin)); dDIm[ibin] = (TVectorD*)f[ifile]->Get(Form("dDIm_%d",ibin)); Nevent[ibin]+=(*Nevent_t)[ibin]; totmultall[ibin]+=(*totmultall_t)[ibin]; for(int iptbin=0;iptbin<nptv;iptbin++){ totmult[ibin][iptbin]+=(*totmult_t)[iptbin]; totpt[ibin][iptbin]+=(*totpt_t)[iptbin]; } for(int itheta=0;itheta<ntheta;itheta++){ dNRe[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNRe_%d_%d",ibin,itheta)); dNIm[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNIm_%d_%d",ibin,itheta)); dD[ibin][itheta]+=TComplex((*dDRe[ibin])[itheta],(*dDIm[ibin])[itheta]); for(int iptbin=0;iptbin<nptv;iptbin++) dN[ibin][itheta][iptbin]+=TComplex((*dNRe[ibin][itheta])[iptbin],(*dNIm[ibin][itheta])[iptbin]); } } f[ifile]->Close(); } TH1D* hpt[nbin]; TH1D* hpteffcorr[nbin]; TFile *fhisto = TFile::Open("histomerged.root"); TFile *feff = TFile::Open("/home/xuq7/HI/flow/LYZ/v2/TrackCorrections_HIJING_538_OFFICIAL_Mar24.root"); TH2F* heff = (TH2F*)feff->Get("rTotalEff3D"); TH1D* hpteff = (TH1D*)heff->ProjectionY("hpteff",heff->GetXaxis()->FindBin(-2.4),heff->GetXaxis()->FindBin(2.4)-1,"o"); TArrayD *ptarr = (TArrayD*)heff->GetYaxis()->GetXbins(); double *ptbinhisto = ptarr->GetArray(); int NbinX = heff->GetXaxis()->GetNbins(); int NbinY = heff->GetYaxis()->GetNbins(); hpteff->Scale(1.0/NbinX); for(int ibin=0;ibin<nbin;ibin++) for(int itheta=0;itheta<ntheta;itheta++) dD[ibin][itheta]*=TComplex::Power(TComplex::I(),mm-1)/(Double_t)Nevent[ibin]; for(int ibin=0;ibin<nbin;ibin++){ avgmultall[ibin]=1.0*totmultall[ibin]/Nevent[ibin]; hpt[ibin] = (TH1D*)fhisto->Get(Form("D_%d/hpt",ibin)); TH1D* hptre = (TH1D*)hpt[ibin]->Rebin(NbinY,"hptre",ptbinhisto); hpteffcorr[ibin] = (TH1D*)hptre->Clone(Form("hpteffcorr_%d",ibin)); hpteffcorr[ibin]->Divide(hpteff); for(int iptbin=0;iptbin<nptv; iptbin++){ vmean[ibin][iptbin]=0; deltavmean[ibin][iptbin]=0; avgmult[ibin][iptbin]=1.0*totmult[ibin][iptbin]/Nevent[ibin]; avgpt[ibin][iptbin]=1.0*totpt[ibin][iptbin]/totmult[ibin][iptbin]; for(int itheta=0;itheta<ntheta;itheta++){ dN[ibin][itheta][iptbin]/=totmult[ibin][iptbin]; TComplex Res=dN[ibin][itheta][iptbin]/dD[ibin][itheta]; v[ibin][itheta][iptbin]=(*V[ibin])[itheta]*avgmultall[ibin]*TMath::BesselJ1(j01)/Besselj01(mm)*Res.Re(); vmean[ibin][iptbin]+=v[ibin][itheta][iptbin]; deltav[ibin][itheta][iptbin]=TMath::Cos(mm*nn*theta[itheta])/totmult[ibin][iptbin]*(TMath::Exp(j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Power(-1,mm)*TMath::Exp(-j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.))); deltavmean[ibin][iptbin]+=deltav[ibin][itheta][iptbin]; // fstrv<<itheta<<"\t"<<v[ibin][itheta][iptbin]<<"\t"<<deltav[ibin][itheta][iptbin]<<endl; } deltavmean[ibin][iptbin]=TMath::Sqrt(deltavmean[ibin][iptbin])/2./Besselj01(mm); //fstrv<<endl; vmean[ibin][iptbin]/=ntheta; deltavmean[ibin][iptbin]/=TMath::Sqrt(ntheta); fstrv<<ptbinv[iptbin]<<"-"<<ptbinv[iptbin+1]<<"\t"<<vmean[ibin][iptbin]<<"\t"<<deltavmean[ibin][iptbin]<<endl; if(ptbinv[iptbin+1]>3.0) continue; totmulthisto[ibin][iptbin]=hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(ptbinv[iptbin]),hpt[ibin]->GetXaxis()->FindBin(ptbinv[iptbin+1])-1); totmulthistocorr[ibin][iptbin]=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[iptbin]),hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[iptbin+1])-1); V_int[ibin]+=vmean[ibin][iptbin]*totmult[ibin][iptbin]; V_interr[ibin]+=deltavmean[ibin][iptbin]*totmult[ibin][iptbin]; V_intcorr[ibin]+=vmean[ibin][iptbin]*totmulthistocorr[ibin][iptbin]; V_intcorrerr[ibin]+=deltavmean[ibin][iptbin]*totmulthistocorr[ibin][iptbin]; totmultall_[ibin]+=totmult[ibin][iptbin]; } V_int[ibin]/=totmultall_[ibin]; V_interr[ibin]/=totmultall_[ibin]; V_intcorr[ibin]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1); V_intcorrerr[ibin]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1); } fstrv<<endl<<"pt range\t\t"<<"totmult"<<"\t\t"<<"totmult from histo"<<"\t"<<"totmult corrected"<<endl; for(int ibin=0;ibin<nbin;ibin++){ for(int iptbin=0;iptbin<nptv; iptbin++){ fstrv<<ptbinv[iptbin]<<"-"<<ptbinv[iptbin+1]<<"\t\t"<<totmult[ibin][iptbin]<<"\t"<<totmulthisto[ibin][iptbin]<<"\t"<<totmulthistocorr[ibin][iptbin]<<endl; } fstrv<<"Integral\t\t"<<totmultall[ibin]<<"\t"<<hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpt[ibin]->GetXaxis()->FindBin(3.0)-1)<<"\t"<<hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1)<<endl; fstrv<<"V ref="<<(*V_mean)[ibin]<<"\t"<<"V int="<<V_int[ibin]<<"\t"<<"V int corr="<<V_intcorr[ibin]<<endl; fstrv<<"V ref err="<<(*deltaV_mean)[ibin]<<"\t"<<"V int err="<<V_interr[ibin]<<"\t"<<"V int corr err="<<V_intcorrerr[ibin]<<endl; } if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod.root","Recreate"); else TFile *fout = new TFile("mergedv_Prod2.root","Recreate"); for(ibin=0;ibin<nbin;ibin++){ Nevent.Write("Nevent"); V_int.Write("V_int"); V_interr.Write("V_interr"); V_intcorr.Write("V_intcorr"); V_intcorrerr.Write("V_intcorrerr"); TDirectory *dir = fout->mkdir(Form("D_%d",ibin)); dir->cd(); avgpt[ibin].Write("avgpt"); totmult[ibin].Write("totmult"); vmean[ibin].Write("vmean"); deltavmean[ibin].Write("deltavmean"); } infile->Close(); fout->Close(); }
void packTemplatesMass(const int iMass) { // This Root macro is for the purpose of providing input for expected limit computation // It packs predicted background and a set of signal samples into a root file per Higgs mass // TH1::SetDefaultSumw2(); TH2::SetDefaultSumw2(); canvas = new TCanvas ("cg1","PadX",10,10,800,600); gStyle->SetPadColor(0); canvas->SetFillColor(0); // const int nbtag = 4; const int nbtag = 1; //const std::string sbtag[nbtag] = { "TCHPT", "TCHP6", "CSVT", "SSVHPT" }; const std::string sbtag[nbtag] = { "CSVT" }; const int nfc=3; const int ncateg=3; string sfc[nfc] = { "q", "c", "b" }; // this is for the combination of triggers in real data int nTCombData = 4; std::string tCombData[] = {"Trig0", "Trig1", "Trig2", "Trig3"}; std::string L1L2Mode("Weight"); std::string signalMode("PU_WEIGHTED-NEW"); // std::string L1L2Mode("Cut"); // std::string signalMode("CUT_BASED"); //std::string scenario("LowMass2011"); //std::string scenario("MediumMass2011"); std::string scenario; bool useTemplateError; bool useNP; if ( getHbbCfg(scenario,useTemplateError,useNP) != 0 ) return; string IgorVersion("V6"); #include "Analysis/Utilities/interface/HbbMass.h" if (iMass >= nSignal) { std::cout << "Bad iMass=" << iMass << std::endl; return; } // const int nSignal=7; // int signalMass[nSignal] = { 90, 100, 120, 140, 180, 250, 350 }; // int signalMass[nSignal] = { 90, 100, 120, 130, 140, 160, 180, 200, 250, 350 } // there are also : 450, 500, 600, 700, 800, 900, 1000 // double efficiency[nSignal] = { 0.0022081, 0.00324694, 0.00600146, 0.00918135, // 0.0138382, 0.0189684, 0.0206572 }; double efficiency[nSignal][nbtag]; double intLumi = 0; string IgorScen(""); string spacer(""); string SashaPath(""); string IgorPath("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/SignalTemplates-Production"); if (IgorVersion == "V4") { IgorPath.assign("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-4"); } else if (IgorVersion == "V6") { IgorPath.assign("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/SignalTemplates-Production2"); } if (scenario == "LowMass2011") { //intLumi = 2.66794; // in fb-1 intLumi = 2.692643; // with new method IgorScen.assign("low"); spacer.assign(""); //SashaPath.assign("Data-Run2011AB"); SashaPath.assign("Data-Run2011AB/TripleBtagAnalysis_CR3_SF7"); } else if (scenario == "MediumMass2011") { //intLumi = 3.99983; // in fb-1 intLumi = 4.040802; IgorScen.assign("medium"); spacer.assign("/MEDIUM"); //SashaPath.assign("Data-Run2011AB-Medium"); SashaPath.assign("Data-Run2011AB/TripleBtagAnalysis_CR3_SF7_med"); } else if (scenario == "MediumMass2012") { //intLumi = 3.99983; // in fb-1 intLumi = 2.663; IgorScen.assign("medium"); spacer.assign("/MEDIUM"); //SashaPath.assign("Data-Run2011AB-Medium"); SashaPath.assign(""); } else { std::cout << "Bad scenario in packing" << std::endl; return; } string signalHistPattern("massEvBtag/mjjEvBTag_%s"); if (L1L2Mode == "Weight") { signalHistPattern.assign("massEvBtagTW/mjjEvBTagTW_%s"); } double fScal[nSignal][nbtag]; // systematics // const int nSyst = 3; // std::string systName[nSyst] = { "JES", "SFbc", "SFudsg" }; // bool realDataNuisance[nSyst] = { false, true, true }; // indicate if relevant for real data string bbPurity("DataDriven"); // "MC", "DataDrivenR", "None" //string bbPurity("None"); // "MC", "DataDrivenR", "None" bool onlineBtagCorr = true; int nSyst = 4; std::string systName[] = { "JES", "SFbc", "SFudsg", "JER" }; bool realDataNuisance[] = { false, true, true, false }; // indicate if relevant for real data const int nUpDown = 2; std::string signalFile = ""; bool dosignal=true; #if defined(MEDIUM2012) dosignal=false; nTCombData=1; ///only one trigger //nSyst=0; /// no syst templates #endif // signal templates if (IgorVersion != "V3") { std::cout << "Using signal files " << IgorVersion << std::endl; signalFile.assign( Form("%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/SF/job_1/TripleBtagAnalysisM-%d_%s.root",IgorPath.c_str(),signalMass[iMass],spacer.c_str(),signalMass[iMass],IgorScen.c_str() ) ); } else { std::cout << "Using V3 signal files" << std::endl; signalFile.assign( Form("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-3/%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/SF/job_1/TripleBtagAnalysisM-%d_%s.root",signalMode.c_str(),signalMass[iMass],spacer.c_str(),signalMass[iMass],IgorScen.c_str() ) ); } std::string signalSystFiles[nSyst][nUpDown]; //bool activeNuisance[nSyst] = { true, true, true }; std::string upDownName[nUpDown] = { "Up", "Down" }; TH2F* hSignalSyst[nSyst][nUpDown][nbtag]; // output file TFile* hout = new TFile(Form("packedTemplates-M-%d.root",signalMass[iMass]),"recreate"); hout->cd(); TH2::AddDirectory(true); TFile* fSig = new TFile( signalFile.c_str() ); if ( fSig == NULL ) { std::cout << "Could not open signal central file " << signalFile.c_str() << std::endl; return; } else { std::cout << "Open signal file " << signalFile.c_str() << std::endl; } TH2F* hSignalCentral[nbtag]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { hSignalCentral[ibtag] = mergeSignal(fSig,Form(signalHistPattern.c_str(),sbtag[ibtag].c_str()), Form("bbH_%s",sbtag[ibtag].c_str())); // read the efficiency TH1F* histEffMerged = (TH1F*) fSig->Get(Form("TrigEff/EffMerged%s",sbtag[ibtag].c_str())); if ( histEffMerged == NULL) { std::cout << "Efficiency histo not found" << std::endl; return; } double newEff = histEffMerged->GetBinContent(1); std::cout << "Mass= " << signalMass[iMass] << " btag= " << sbtag[ibtag] << " Efficiency = " << newEff << std::endl; efficiency[iMass][ibtag] = newEff; double normShould = 1000 * intLumi * efficiency[iMass][ibtag]; double normIs = hSignalCentral[ibtag]->GetSumOfWeights(); std::cout << hSignalCentral[ibtag]->GetName() << " TotalContents=" << hSignalCentral[ibtag]->GetSumOfWeights() << std::endl; fScal[iMass][ibtag] = normShould / normIs; std::cout << "normShould = " << normShould << " normIs " << normIs << " rescale by " << fScal[iMass][ibtag] << std::endl; hSignalCentral[ibtag]->Scale( fScal[iMass][ibtag] ); hout->cd(); hSignalCentral[ibtag]->Write(); histEffMerged->Write(); // create empty file just as marker ofstream markerFile; markerFile.open(Form("pack-%s-%s.txt",sbtag[ibtag].c_str(),scenario.c_str()),ios::app); markerFile << "Template for mass " << signalMass[iMass] << std::endl; markerFile.close(); } // read the nominal cross section TH1F* histXSect = (TH1F*) fSig->Get("xsection/xsect"); if ( histXSect == NULL) { std::cout << "xsection/xsect" << " not found" << std::endl; return; } histXSect->Write(); for (int iSyst=0; iSyst<nSyst; ++iSyst) { for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { if (IgorVersion != "V3") { signalSystFiles[iSyst][iUpDown] = Form( "%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/%s_Sys%s/job_1/TripleBtagAnalysisM-%d_%s.root", IgorPath.c_str(),signalMass[iMass],spacer.c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),signalMass[iMass],IgorScen.c_str()); } else { signalSystFiles[iSyst][iUpDown] = Form( "/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-3/%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/%s_Sys%s/job_1/TripleBtagAnalysisM-%d_%s.root", signalMode.c_str(),signalMass[iMass],spacer.c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),signalMass[iMass],IgorScen.c_str()); } std::cout << "Signal systematics file " << signalSystFiles[iSyst][iUpDown] << std::endl; TFile* fSigSys = new TFile( signalSystFiles[iSyst][iUpDown].c_str() ); if ( fSigSys == NULL ) { std::cout << "Could not open signal syst file " << signalSystFiles[iSyst][iUpDown].c_str() << std::endl; return; } for (int ibtag=0; ibtag<nbtag; ++ibtag) { hSignalSyst[iSyst][iUpDown][ibtag] = mergeSignal(fSigSys,Form(signalHistPattern.c_str(),sbtag[ibtag].c_str()), Form("bbH_%s_%s_%s",systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str())); std::cout << "The merged hist has name " << hSignalSyst[iSyst][iUpDown][ibtag]->GetName() << std::endl; std::cout << hSignalSyst[iSyst][iUpDown][ibtag]->GetName() << " TotalContents=" << hSignalSyst[iSyst][iUpDown][ibtag]->GetSumOfWeights() << std::endl; hSignalSyst[iSyst][iUpDown][ibtag]->Scale( fScal[iMass][ibtag] ); hout->cd(); hSignalSyst[iSyst][iUpDown][ibtag]->Write(); } fSigSys->Close(); } } // real data std::string backgroundFile( Form("/afs/naf.desy.de/user/r/rmankel/scratch/HbbPat/CMSSW_4_2_4_patch1/src/Analysis/HbbMSSMAnalysis/test/results/v1/%s/TripleBtagAnalysis_SF/TripleBtagAnalysis.root",SashaPath.c_str()) ); #if defined(MEDIUM2012) //bool dosignal=true; //backgroundFile = std::string("/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/MVA-production-selection-trees/TripleBtagAnalysis.root"); backgroundFile = std::string("/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/Blind-test-BG-only-Fit/MEDIUM/TripleBtagAnalysis_SF/TripleBtagAnalysis.root"); #endif std::cout << "Background central file : " << backgroundFile << std::endl; TFile* fBac = new TFile( backgroundFile.c_str() ); if ( fBac == NULL ) { std::cout << "Could not open background central file " << signalFile.c_str() << std::endl; return; } // hist-to-be-fitted TH2F* mjjEbtdata[nbtag]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { mjjEbtdata[ibtag] = getTrigsAndMerge(fBac,Form("massEvBtag/mjjEvBTag_%s",sbtag[ibtag].c_str()),nTCombData,tCombData); if (mjjEbtdata[ibtag] == NULL) { std::cout << "Histogram not found: " << Form("massEvBtag/mjjEvBTag_%s",sbtag[ibtag].c_str()) << std::endl; return; } // rename mjjEbtdata[ibtag]->SetName( Form("Data_%s",sbtag[ibtag].c_str() ) ); hout->cd(); mjjEbtdata[ibtag]->Write(); } TH2F* hBackgroundCentral[nbtag][ncateg][nfc]; TH2F* hBackgroundCentralError[nbtag][ncateg][nfc]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { int theTpat; if (onlineBtagCorr) { theTpat = 3; } else { theTpat = icateg; } for (int ifc=0; ifc<nfc; ++ifc) { string templateCore("massBTagTemplatesCld/MassBTagTemplateCld"); if (bbPurity == "None") { templateCore.assign("massBTagTemplatesCld/MassBTagTemplateUncld"); } string hbSystName( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundCentral[ibtag][icateg][ifc] = getTrigsAndMerge(fBac,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundCentral[ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystName << std::endl; return; } // rename templateId tName(ifc,icateg); hBackgroundCentral[ibtag][icateg][ifc]->SetName( Form("%s_%s",tName.name().c_str(),sbtag[ibtag].c_str()) ); // read the template errors templateCore.assign("errorMassBTagTemplates/ErrorMassBTagTemplate"); string hbSystNameError( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundCentralError[ibtag][icateg][ifc] = getTrigsAndMerge(fBac,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundCentralError[ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystNameError << std::endl; return; } if (useTemplateError) { // add the template error std::cout << " ==== Adding Btag Errors ==== " << hBackgroundCentral[ibtag][icateg][ifc]->GetName() << std::endl; for (int ibinx=1; ibinx<= (hBackgroundCentral[ibtag][icateg][ifc]->GetXaxis()->GetNbins()); ++ibinx) { for (int ibiny=1; ibiny<= (hBackgroundCentral[ibtag][icateg][ifc]->GetYaxis()->GetNbins()); ++ibiny) { float oldError = hBackgroundCentral[ibtag][icateg][ifc]->GetBinError(ibinx,ibiny); float addError = hBackgroundCentralError[ibtag][icateg][ifc]->GetBinContent(ibinx,ibiny); float newError = sqrt( oldError * oldError + addError * addError ); hBackgroundCentral[ibtag][icateg][ifc]->SetBinError(ibinx,ibiny,newError); } } } hout->cd(); hBackgroundCentral[ibtag][icateg][ifc]->Write(); } } } std::string backgroundSystFiles[nSyst][nUpDown]; std::string systNameSasha[] = { "JES", "SFbc", "SFq" }; std::string upDownNameSasha[nUpDown] = { "plus2", "minus2" }; TH2F* hBackgroundSyst[nSyst][nUpDown][nbtag][ncateg][nfc]; TH2F* hBackgroundSystError[nSyst][nUpDown][nbtag][ncateg][nfc]; //#if !defined(MEDIUM2012) // for nuisances like JEC, the up/down templates are just copies of the central templates for (int iSyst=0; iSyst<nSyst; ++iSyst) { if (! realDataNuisance[iSyst]) { std::cout << "Non-real data relevant nuisance: " << systName[iSyst].c_str() << std::endl; for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { for (int ifc=0; ifc<nfc; ++ifc) { hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] = new TH2F( *hBackgroundCentral[ibtag][icateg][ifc] ); // rename templateId tName(ifc,icateg); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] ->SetName( Form("%s_%s_%s_%s", tName.name().c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str()) ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); } } } } } } //#endif fBac->Close(); for (int iSyst=0; iSyst<nSyst; ++iSyst) { if (realDataNuisance[iSyst]) { std::cout << "Real data relevant nuisance: " << systName[iSyst].c_str() << std::endl; for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { // backgroundSystFiles[iSyst][iUpDown] = Form( "/afs/naf.desy.de/user/r/rmankel/scratch/HbbPat/CMSSW_4_2_4_patch1/src/Analysis/HbbMSSMAnalysis/test/results/v1/%s/TripleBtagAnalysis_%s%s/TripleBtagAnalysis.root",SashaPath.c_str(),systNameSasha[iSyst].c_str(),upDownNameSasha[iUpDown].c_str() ); backgroundSystFiles[iSyst][iUpDown] = Form( "/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/Blind-test-BG-only-Fit/MEDIUM/TripleBtagAnalysis_%s%s/TripleBtagAnalysis.root",systNameSasha[iSyst].c_str(),upDownNameSasha[iUpDown].c_str() ); TFile* fBacSys = new TFile( backgroundSystFiles[iSyst][iUpDown].c_str() ); std::cout << "Background systematics file " << backgroundSystFiles[iSyst][iUpDown] << std::endl; if ( fBacSys == NULL ) { std::cout << "Could not open background syst file " << backgroundSystFiles[iSyst][iUpDown] << std::endl; return; } for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { int theTpat; if (onlineBtagCorr) { theTpat = 3; } else { theTpat = icateg; } for (int ifc=0; ifc<nfc; ++ifc) { string templateCore("massBTagTemplatesCld/MassBTagTemplateCld"); if (bbPurity == "None") { templateCore.assign("massBTagTemplatesCld/MassBTagTemplateUncld"); } string hbSystName( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] = getTrigsAndMerge(fBacSys,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystName << std::endl; return; } // rename templateId tName(ifc,icateg); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] ->SetName( Form("%s_%s_%s_%s", tName.name().c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str()) ); // read template errors templateCore.assign("errorMassBTagTemplates/ErrorMassBTagTemplate"); string hbSystNameError( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc] = getTrigsAndMerge(fBacSys,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystNameError << std::endl; return; } if (useTemplateError) { // add the template error std::cout << " ==== ErrorAdd ==== " << hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName() << std::endl; for (int ibinx=1; ibinx<= (hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetXaxis()->GetNbins()); ++ibinx) { for (int ibiny=1; ibiny<= (hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetYaxis()->GetNbins()); ++ibiny) { float oldError = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetBinError(ibinx,ibiny); float addError = hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc]->GetBinContent(ibinx,ibiny); float newError = sqrt( oldError * oldError + addError * addError ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->SetBinError(ibinx,ibiny,newError); } } } hout->cd(); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); } } } fBacSys->Close(); } } } std::cout << "Everything done " << std::endl; #ifdef PROJECTIONS TFile * projections_out=TFile::Open("projections.root","RECREATE"); // loop over background templates //TH1D* bgProX[nbtag][ncateg][nfc]; TH1D* bgSystProX[nSyst][nUpDown][nbtag][ncateg][nfc]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { for (int ifc=0; ifc<nfc; ++ifc) { TH2F* theTemp = hBackgroundCentral[ibtag][icateg][ifc]; TH1D* theTempProX = theTemp->ProjectionX(Form("%sProX",theTemp->GetName()),0,-1,"e"); theTempProX->SetName( Form("%sProX",theTemp->GetName()) ); TH1D* theTempProY = theTemp->ProjectionY(Form("%sProY",theTemp->GetName()),0,-1,"e"); std::cout << "Made projection " << theTempProX->GetName() << std::endl; if ( (icateg == 0) && (ifc == 0) ) { for (int ibinx=1; ibinx<= theTempProX->GetXaxis()->GetNbins(); ++ibinx) { std::cout << ibinx << " content " << theTempProX->GetBinContent(ibinx) << " error " << theTempProX->GetBinError(ibinx) << std::endl; } } theTempProX->SetMarkerStyle(20); theTempProX->SetMarkerColor(1); theTempProX->SetLineColor(1); theTempProX->SetMarkerSize(1); std::cout << "Draw" << std::endl; theTempProX->Draw("EP"); theTempProX->Write(); //theTempProX->Draw("LP,SAME"); // draw the SFbc systematics int colSyst[3] = {1, 2, 4}; int lstyleUpDown[2] = {1, 1}; for (int iSyst=1; iSyst<nSyst; ++iSyst) { for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc] = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->ProjectionX(Form("%sProXX",hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName()),0,-1,"e"); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->SetName( Form("%sProXX",hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName()) ); std::cout << "Made projection " << bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->GetName() << std::endl; bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->SetLineColor( colSyst[iSyst] ); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->Draw("HIST,SAME"); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); // TH2F* theTemp = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]; // TH1D* theTempProX = theTemp->ProjectionX(Form("%sProX",theTemp->GetName()),0,-1,"e"); // theTempProX->SetLineColor( colSyst[iSyst] ); // TH1D* theTempProY = theTemp->ProjectionY(Form("%sProY",theTemp->GetName()),0,-1,"e"); // theTempProY->SetLineColor( colSyst[iSyst] ); // //theTempProX->Draw("HIST"); } } canvas->Print(Form("Template_%s_%s_Cat%d_ProX.png",sbtag[ibtag].c_str(),sfc[ifc].c_str(),icateg)); theTempProY->SetMarkerStyle(20); theTempProY->SetMarkerColor(1); theTempProY->SetLineColor(1); theTempProY->SetMarkerSize(1); std::cout << "Draw" << std::endl; theTempProY->Draw("EP"); theTempProY->Write(); } } } projections_out->Write(); projections_out->Close(); #endif hout->Write(); hout->Close(); // close the signal central file fSig->Close(); return; }
TH1D *GetHisto(float ptcut = 0.15, char *name, char *filename, float etacut){ TFile *file = new TFile(filename); TList *list = file->FindObject("out2"); //TH2F *allhad = ((TH2F*) out2->FindObject("EtSimulatedAllHadron"))->Clone("allhad"); TH2F *allhad = ((TH2F*) out2->FindObject("EtSimulatedChargedHadron"))->Clone("allhad"); TH2F *ptlow = ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingNoPt"))->Clone("ptlow"); TH2F *pthigh; if(ptcut>0.14){//TPC cut off (TH2F*)pthigh =(TH2F*) ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingPtTPCCut"))->Clone("pthigh"); } else{ (TH2F*)pthigh =(TH2F*) ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingPtITSCut"))->Clone("pthigh"); } int lowbin = allhad->GetXaxis()->FindBin(0.0);//make sure we don't accidentally get the wrong bin int highbin = allhad->GetXaxis()->FindBin(ptcut); int nbins = allhad->GetXaxis()->GetNbins(); cout<<"Projecting from "<<allhad->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<allhad->GetXaxis()->GetBinLowEdge(highbin+1)<<endl; cout<<"Projecting from "<<allhad->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<allhad->GetXaxis()->GetBinLowEdge(nbins)<<endl; //allhad->Sumw2(); TH1D *numerator = allhad->ProjectionY("name",lowbin,highbin); TH1D *denominator = allhad->ProjectionY("denominator",lowbin,nbins); TH1D *numeratorLow = ptlow->ProjectionY("nameLow",lowbin,highbin); TH1D *denominatorLow = allhad->ProjectionY("denominatorLow",highbin,nbins); denominatorLow->Add(ptlow); TH1D *numeratorHigh = pthigh->ProjectionY("nameHigh",lowbin,highbin); TH1D *denominatorHigh = allhad->ProjectionY("denominatorHigh",highbin,nbins); denominatorHigh->Add(pthigh); numerator->Divide(denominator); numeratorLow->Divide(denominatorLow); numeratorHigh->Divide(denominatorHigh); TF1 *funcLow = new TF1("funcLow","[0]",-.7,.7); funcLow->SetParameter(0,0.01); numeratorLow->Fit(funcLow); TF1 *func = new TF1("func","[0]",-.7,.7); func->SetParameter(0,0.02); numerator->Fit(func); TF1 *funcHigh = new TF1("funcHigh","[0]",-.7,.7); funcHigh->SetParameter(0,0.02); numeratorHigh->Fit(funcHigh); mean = 1.0-func->GetParameter(0); lowbound = 1.0-funcHigh->GetParameter(0); highbound = 1.0-funcLow->GetParameter(0); cout<<"fpTcut = "<<mean<<","<<lowbound<<","<<highbound<<endl; cout<<"1/fpTcut = "<<1.0/mean<<","<<1.0/lowbound<<","<<1.0/highbound<<endl; //cout<<"fpTcut = "<<mean<<"-"<<mean-lowbound<<"+"<<highbound-mean<<endl; syserr = highbound-mean; if(mean-lowbound>syserr) syserr = mean-lowbound; cout<<Form("%2.4f^{+%2.4f}_{-%2.4f}",mean,highbound-mean,mean-lowbound)<<endl; cout<<"latex here "; cout<<Form("%2.4f \\pm %2.4f",mean,syserr)<<endl; cout<<"1/fpTcut = "<<1.0/mean<<"+"<<1.0/lowbound-1.0/mean<<"-"<<1.0/mean-1.0/highbound<<endl; numerator->SetYTitle("E_{T}^{had, p_{T}<cut-off}/E_{T}^{had, all p_{T}}"); numerator->GetYaxis()->SetTitleOffset(1.); numerator->GetYaxis()->SetTitleSize(0.08); numerator->GetYaxis()->SetLabelSize(0.05); numerator->GetXaxis()->SetTitleSize(0.08); numerator->GetXaxis()->SetLabelSize(0.05); numerator->GetXaxis()->SetTitleOffset(.6); //numerator->Rebin(2); //numerator->Scale(0.5); //numerator->Draw("e"); return numerator; }
void Getvn2D(bool usingCNTEP=0){ TString str; TFile *fin; int nrun = GetTotalRun(); std::cout<<"Totally we have "<<nrun<<" runs/segments!"<<std::endl; FillGoodRun(); std::cout<<"Filling Good run finished!"<<std::endl; if(nrun<0) exit(1); ofstream fout, foutraw, fout1, fout2; int iharE=0; if(nhar==1||nhar==2) iharE=1; for(int icent=0;icent<ncent;icent++){ for(int ihar=0;ihar<nhar;ihar++){ if(icent!=0) continue; for(int isub=0;isub<nsub;isub++){ int n = ihar+1.0+iharE; str = choosesub(isub); TString UseCNTEP; if(str=="ABORT") continue; if(usingCNTEP) UseCNTEP = "UseCNTEP"; else UseCNTEP = "NoUseCNTEP"; std::cout<<UseCNTEP<<std::endl; std::cout<<"starting doing "<<str<<" v"<<n<<" analysis!"<<std::endl; cout<<Form("Result/%s/res%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())<<endl; fout1.open(Form("Result/%s/res%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())); //using str as event plane detector fout2.open(Form("Result/%s/psi%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())); //using str as event plane detector float reso = GetReso(icent,ihar,isub,usingCNTEP); fout1<<reso<<std::endl; if(reso<0) {std::cout<<"resolution is wrong!"<<std::endl; reso = -9999;} for(int irun=0;irun<nrun;irun++){ fout2<<GetRun(irun)<<" "<<GoodRunFit[icent][ihar][isub][irun]<<std::endl; } TH2F* hvobsall = new TH2F(Form("hvobs_%d_%d_%d",icent,ihar,isub),Form("hvobs_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); // TH2F* hvobsallsq = new TH2F(Form("hvobssq_%d_%d_%d",icent,ihar,isub),Form("hvobssq_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); for(int iphi=0;iphi<nphi+1;iphi++){ TH2F* hvobs = new TH2F(Form("hvobs_%d_%d_%d_%d",icent,ihar,isub,iphi),Form("hvobs_%d_%d_%d_%d",icent,ihar,isub,iphi),60,0,6,220,-1.1,1.1); // TH2F* hvobssq = new TH2F(Form("hvobssq_%d_%d_%d_%d",icent,ihar,isub,iphi),Form("hvobssq_%d_%d_%d_%d",icent,ihar,isub,iphi),60,0,6,220,-1.1,1.1); string phistr = (iphi==0)?"_east":"_west"; if(iphi==nphi) phistr = ""; cout<<"open v2 file"<<endl; fout.open(Form("Result/%s/v%d_%d%s_%s.dat",UseCNTEP.Data(),n,icent,phistr.c_str(),str.Data())); //using str as event plane detector cout<<"open v2raw file"<<endl; foutraw.open(Form("Result/%s/v%draw_%d%s_%s.dat",UseCNTEP.Data(),n,icent,phistr.c_str(),str.Data())); //using str as event plane detector if(iphi<nphi){ for(int irun=0;irun<nrun;irun++){ //std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<" "<<phistr<<std::endl; //fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s.root",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data())); //fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/output/%s",GetRun(irun).Data())); fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/treeout/%s",GetRun(irun).Data())); if(!(GoodRunFit[icent][ihar][isub][irun]>0.2 && GoodRunFit[icent][ihar][isub][irun]<3.0)){ std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<std::endl; fin->Close(); continue; } TH2F* hvobstemp = (TH2F*)fin->Get(Form("vobs%s_0_0_%d_%d_%d",str.Data(),icent,ihar,iphi)); //TH2F* hvobssqtemp = (TH2F*)fin->Get(Form("vobs%ssq_%d_%d_%d",str.Data(),icent,ihar,iphi)); hvobs->Add(hvobstemp); //hvobssq->Add(hvobssqtemp); fin->Close(); } } hvobsall->Add(hvobs); //hvobsallsq->Add(hvobssq); if(iphi==nphi){ hvobs = hvobsall; //hvobssq = hvobsallsq; } TH1F* ptProj = (TH1F*)hvobs->ProjectionX(Form("hptProj"),0,-1); for(int ipt=0;ipt<npt-1;ipt++){ int xbinmin = hvobs->GetXaxis()->FindBin(ptbin[ipt]+eps); int xbinmax = hvobs->GetXaxis()->FindBin(ptbin[ipt+1]-eps); // std::cout<<xbinmin<<" "<<xbinmax<<std::endl; // std::cout<<ptbin[ipt]<<" "<<ptbin[ipt+1]<<std::endl; TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),xbinmin,xbinmax); // TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),xbinmin,xbinmax); float vobs = hvobsProj->GetMean(); float Ntracks = hvobsProj->Integral(); // float vobssq = hvobssqProj->GetMean(); float v = vobs/reso; if(Ntracks>0) float verr = hvobsProj->GetRMS()/reso/sqrt(Ntracks); else verr = -9999; // float verr = sqrt(vobssq/reso/reso-(v*v))/sqrt(Ntracks); ptProj->GetXaxis()->SetRangeUser(ptbin[ipt]+eps,ptbin[ipt+1]-eps); float pt = ptProj->GetMean(); fout<<pt<<" "<<v<<" "<<verr<<" "<<std::endl; foutraw<<pt<<" "<<vobs<<" "<<verr*reso<<" "<<std::endl; } fout.close(); foutraw.close(); } fout1.close(); fout2.close(); } } } }
//************************************************************************************************* //Main part of the macro //************************************************************************************************* void NormalizeElectronNtuple(const string InputFilename, const string datasetName, const string OutputFilename, Int_t sampleType, const string normalizationFile = "") { Double_t normalizationWeight = 0; Bool_t useReweightFactor = kFALSE; TH2F *PtEtaReweightFactor = 0; Double_t overallWJetsNormalizationFactor = 0; //For Normalizing each sample individually if (sampleType == 0 || sampleType >= 10) { TTree* electronTree = getTreeFromFile(InputFilename.c_str()); assert(electronTree); MitNtupleElectron ele(electronTree); normalizationWeight = getNormalizationWeight(InputFilename, datasetName); //************************************************************************************************* //Create new normalized tree //************************************************************************************************* TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE"); outputFile->cd(); TTree *normalizedTree = electronTree->CloneTree(0); for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); if (sampleType == 10) { if (ele.electron_branch_passedSelectionCut == 1) { if (datasetName == "s09-wwll10-mc3" || datasetName == "s09-ttbar-mc3") { //for mu-e there should be only 1 electron candidate ele.electron_branch_weight = normalizationWeight; normalizedTree->Fill(); } else if (datasetName == "s09-we-mc3" || datasetName == "s09-wm-mc3" || datasetName == "s09-wt-mc3") { //For the W->enu sample, fill only the fake electron candidates. ele.electron_branch_weight = normalizationWeight; if (ele.electron_branch_electronType < 100) { normalizedTree->Fill(); } } else { cout << "Warning: The specified dataset " << datasetName << " is not recognized to be one of the selection cut samples.\n"; } } } else { //For regular samples just fill all electrons ele.electron_branch_weight = normalizationWeight; normalizedTree->Fill(); } } normalizedTree->Write(); cout << "Original Tree Entries: " << electronTree->GetEntries() << " Normalized Tree Entries: " << normalizedTree->GetEntries() << endl; outputFile->Close(); } //For Normalization of Background sample else if (sampleType == 1) { TTree* electronTree = getTreeFromFile(InputFilename.c_str(), kFALSE); assert(electronTree); MitNtupleElectron ele(electronTree); //************************************************************************************************* //Create new reweighted tree //************************************************************************************************* TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE"); TTree *reweightedTree = electronTree->CloneTree(0); if (normalizationFile == "") { //normalize according to total number of electrons expected in W+Jets/W+gamma bkg Double_t totalWeight = 0; for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); totalWeight += ele.electron_branch_weight; } cout << "Input Bkg Ntuple Total Weight = " << totalWeight << endl; normalizationWeight = 1126.5 / totalWeight; } else { //do pt/eta Reweighting TFile *reweightInputFile = new TFile(normalizationFile.c_str(), "READ"); assert(reweightInputFile); TH2F *WJetsFakeElectronPtEta = (TH2F*)reweightInputFile->Get("hWJetsFakeElectronPtEta"); assert(WJetsFakeElectronPtEta); WJetsFakeElectronPtEta = (TH2F*)(WJetsFakeElectronPtEta->Clone()); WJetsFakeElectronPtEta->SetDirectory(0); reweightInputFile->Close(); //Create histogram for reweighting factor PtEtaReweightFactor = (TH2F*)WJetsFakeElectronPtEta->Clone(); PtEtaReweightFactor->SetName("PtEtaReweightFactor"); PtEtaReweightFactor->SetDirectory(0); TH2F *BkgFakeElectronPtEta = new TH2F("BkgFakeElectronPtEta", ";Pt [GeV/c];#eta;" , WJetsFakeElectronPtEta->GetXaxis()->GetNbins(), WJetsFakeElectronPtEta->GetXaxis()->GetBinLowEdge(1), WJetsFakeElectronPtEta->GetXaxis()->GetBinUpEdge(WJetsFakeElectronPtEta->GetXaxis()->GetNbins()), WJetsFakeElectronPtEta->GetYaxis()->GetNbins(), WJetsFakeElectronPtEta->GetYaxis()->GetBinLowEdge(1), WJetsFakeElectronPtEta->GetYaxis()->GetBinUpEdge(WJetsFakeElectronPtEta->GetYaxis()->GetNbins())); BkgFakeElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); BkgFakeElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } PtEtaReweightFactor->Divide(WJetsFakeElectronPtEta, BkgFakeElectronPtEta, 1.0,1.0,"B"); useReweightFactor = kTRUE; } cout << "Reweighting Background Ntuple\n"; outputFile->cd(); //check Reweighting TH2F *ReweightedBkgFakeElectronPtEta = new TH2F("BkgFakeElectronPtEta", ";Pt [GeV/c];#eta;" , 200, 0, 200, 200, -3.0, 3.0); ReweightedBkgFakeElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { if (n%250000 == 0) cout << "Entry " << n << endl; ele.GetEntry(n); if (useReweightFactor) { Double_t reweightFactor = PtEtaReweightFactor->GetBinContent(PtEtaReweightFactor->GetXaxis()->FindFixBin(ele.electron_branch_pt),PtEtaReweightFactor->GetYaxis()->FindFixBin(ele.electron_branch_eta)); ele.electron_branch_weight = ele.electron_branch_weight*reweightFactor;//*overallWJetsNormalizationFactor; } else { ele.electron_branch_weight = normalizationWeight; } reweightedTree->Fill(); ReweightedBkgFakeElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } reweightedTree->Write(); cout << "Original Tree Entries: " << electronTree->GetEntries() << " Normalized Tree Entries: " << reweightedTree->GetEntries() << endl; outputFile->Close(); TCanvas *cv = new TCanvas("BkgReweightedFakeElectronPtEta", "BkgReweightedFakeElectronPtEta", 0,0,800,600); ReweightedBkgFakeElectronPtEta->ProjectionX()->DrawCopy("E1"); cv->SaveAs("BkgReweightedFakeElectronPt.gif"); ReweightedBkgFakeElectronPtEta->ProjectionY()->DrawCopy("E1"); cv->SaveAs("BkgReweightedFakeElectronEta.gif"); } //For Normalization of Signal sample else if (sampleType == 2) { TTree* electronTree = getTreeFromFile(InputFilename.c_str(), kFALSE); assert(electronTree); MitNtupleElectron ele(electronTree); //************************************************************************************************* //Create new reweighted tree //************************************************************************************************* TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE"); TTree *reweightedTree = electronTree->CloneTree(0); if (normalizationFile == "") { //normalize according to total number of electrons expected in WW -> ee nunu signal Double_t totalWeight = 0; for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); totalWeight += ele.electron_branch_weight; } cout << "Input Bkg Ntuple Total Weight = " << totalWeight << endl; normalizationWeight = 1126.5 / totalWeight; } else { //do pt/eta Reweighting TFile *reweightInputFile = new TFile(normalizationFile.c_str(), "READ"); assert(reweightInputFile); TH2F *WWSigElectronPtEta = (TH2F*)reweightInputFile->Get("hWWRealElectronPtEta"); assert(WWSigElectronPtEta); WWSigElectronPtEta = (TH2F*)(WWSigElectronPtEta->Clone()); WWSigElectronPtEta->SetDirectory(0); reweightInputFile->Close(); //Create histogram for reweighting factor PtEtaReweightFactor = (TH2F*)WWSigElectronPtEta->Clone(); PtEtaReweightFactor->SetName("PtEtaReweightFactor"); PtEtaReweightFactor->SetDirectory(0); TH2F *SigSampleElectronPtEta = new TH2F("SigSampleElectronPtEta", ";Pt [GeV/c];#eta;" , WWSigElectronPtEta->GetXaxis()->GetNbins(), WWSigElectronPtEta->GetXaxis()->GetBinLowEdge(1), WWSigElectronPtEta->GetXaxis()->GetBinUpEdge(WWSigElectronPtEta->GetXaxis()->GetNbins()), WWSigElectronPtEta->GetYaxis()->GetNbins(), WWSigElectronPtEta->GetYaxis()->GetBinLowEdge(1), WWSigElectronPtEta->GetYaxis()->GetBinUpEdge(WWSigElectronPtEta->GetYaxis()->GetNbins())); SigSampleElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); SigSampleElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } PtEtaReweightFactor->Divide(WWSigElectronPtEta, SigSampleElectronPtEta, 1.0,1.0,"B"); useReweightFactor = kTRUE; } cout << "Reweighting Signal Ntuple\n"; outputFile->cd(); //check Reweighting TH2F *ReweightedSigRealElectronPtEta = new TH2F("ReweightedSigRealElectronPtEta", ";Pt [GeV/c];#eta;" , 200, 0, 200, 200, -3.0, 3.0); ReweightedSigRealElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { if (n%250000 == 0) cout << "Entry " << n << endl; ele.GetEntry(n); if (useReweightFactor) { Double_t reweightFactor = PtEtaReweightFactor->GetBinContent(PtEtaReweightFactor->GetXaxis()->FindFixBin(ele.electron_branch_pt),PtEtaReweightFactor->GetYaxis()->FindFixBin(ele.electron_branch_eta)); ele.electron_branch_weight = ele.electron_branch_weight*reweightFactor;//*overallWJetsNormalizationFactor; } else { ele.electron_branch_weight = normalizationWeight; } reweightedTree->Fill(); ReweightedSigRealElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } reweightedTree->Write(); cout << "Original Tree Entries: " << electronTree->GetEntries() << " Normalized Tree Entries: " << reweightedTree->GetEntries() << endl; outputFile->Close(); TCanvas *cv = new TCanvas("BkgReweightedFakeElectronPtEta", "BkgReweightedFakeElectronPtEta", 0,0,800,600); ReweightedSigRealElectronPtEta->ProjectionX()->DrawCopy("E1"); cv->SaveAs("SigReweightedRealElectronPt.gif"); ReweightedSigRealElectronPtEta->ProjectionY()->DrawCopy("E1"); cv->SaveAs("SigReweightedRealElectronEta.gif"); } else { cout << "Warning: Specified sampleType " << sampleType << " is not recognized.\n"; } }
TH2F* rebin_lowstatistics(TH2F* finalhist, int sampleIndex){ int nXbins=finalhist->GetNbinsX(); int nYbins=finalhist->GetNbinsY(); TH2F* origHist = new TH2F (*finalhist); //Project Fisher v m4L to 1D Fisher plots for low, high, and full mass range TH1F* lowProj = (TH1F*) origHist->ProjectionY("lowProj",1,40); TH1F* highProj = (TH1F*) origHist->ProjectionY("highProj",41,750); TH1F* fullProj = (TH1F*) origHist->ProjectionY(); double temp; //Plots if need to see tails /*if(sampleIndex!=2 && sampleIndex!=3 && sampleIndex!=5){ TCanvas* clow = new TCanvas("clow","clow",800,800); clow->cd(); lowProj->Draw(); TCanvas* chigh = new TCanvas("chigh","chigh",800,800); chigh->cd(); highProj->Draw(); TCanvas* cfull = new TCanvas("cfull","cfull",800,800); cfull->cd(); fullProj->Draw(); }*/ //qqZZ + WH + ZH if(sampleIndex==2 || sampleIndex==5 || sampleIndex==6){ //Tail smoothing goes here if needed //Fill each mass point with low or high mass projections for(int i=1; i<=nXbins;i++){ for(int j=1; j<=nYbins;j++){ float binMzz = finalhist->GetBinCenter(i); if (binMzz<180){ temp=lowProj->GetBinContent(j); finalhist->SetBinContent(i,j,temp); } else if (binMzz>=180){ temp=highProj->GetBinContent(j); finalhist->SetBinContent(i,j,temp); } } } //Store plots of fits, in case anything goes wrong if(sampleIndex==2){ fqqZZ->cd(); } else if(sampleIndex==5){ fZH->cd(); } else if(sampleIndex==6){ fWH->cd(); } lowProj->Write("H_low"); highProj->Write("H_high"); } //ggZZ + ttH + Z+X else if(sampleIndex==3 || sampleIndex==4 || sampleIndex==7){ //Fill each mass point with full projection for(int i=1; i<=nXbins;i++){ for(int j=1; j<=nYbins;j++){ temp=fullProj->GetBinContent(j); finalhist->SetBinContent(i,j,temp); } } //Store plots of fits, in case anything goes wrong if(sampleIndex==3){ fggZZ->cd(); } if(sampleIndex==4){ fZX->cd(); } if(sampleIndex==7){ fttH->cd(); } fullProj->Write("H_full"); } double norm; TH1F* tempProj; //Normalize for(int i=1; i<=nXbins; i++){ tempProj = (TH1F*) finalhist->ProjectionY("tempProj",i,i); norm=tempProj->Integral(); if (norm>0) { // Avoid introducing NaNs in the histogram for(int j=1; j<=nYbins; j++){ finalhist->SetBinContent(i,j, finalhist->GetBinContent(i,j)/norm); } } } return finalhist; }
void Getdphi(int ihar=0, int iangle1=0, int iangle2=0, bool usingCNTEP=0){ TString str; int nrun = GetTotalRun(); std::cout<<"Totally we have "<<nrun<<" runs/segments!"<<std::endl; FillGoodRun(ihar); std::cout<<"Filling Good run finished!"<<std::endl; float pi = acos(-1.0); if(nrun<0) exit(1); int iharE=0; if(nhar==1 || nhar ==2) iharE=1; TFile *fin; int n = ihar+1.0+iharE; cout<<"iangle1 = "<<iangle1<<" iangle2 = "<<iangle2<<endl; TFile *fout = new TFile(Form("dphiv%d.root",n),"recreate"); for(int icent=0;icent<ncent;icent++){ // for(int ihar=0;ihar<nhar;ihar++){ // if(ihar!=1) continue; for(int isub=0;isub<nsub;isub++){ str = choosesub(isub); TString UseCNTEP; if(str=="ABORT") continue; if(usingCNTEP) UseCNTEP = "UseCNTEP"; else UseCNTEP = "NoUseCNTEP"; std::cout<<UseCNTEP<<std::endl; std::cout<<"starting doing "<<str<<" v"<<n<<" analysis!"<<std::endl; // float reso = GetReso(iangle1, iangle2, icent,ihar,isub,usingCNTEP); // if(reso<=0) {std::cout<<"resolution is wrong!"<<std::endl; reso = 1.0;} TH2F* hvall = new TH2F(Form("hdphiall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hdphiall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6,200,-pi,pi); TH2F* hvnall = new TH2F(Form("hdphinall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hdphinall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6,100,-pi/2,pi/2); for(int iphi=0;iphi<nphi+1;iphi++){ TH2F* hv = new TH2F(Form("hdphi_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hdphi_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6,200,-pi,pi); TH2F* hvn = new TH2F(Form("hdphin_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hdphin_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6,100,-pi/2,pi/2); string phistr = (iphi==0)?"_east":"_west"; if(iphi==nphi) phistr = ""; if(iphi<nphi){ for(int irun=0;irun<nrun;irun++){ fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/treeout/%s",GetRun(irun).Data())); if(!(GoodRunFit[icent][ihar][isub][irun]>0.2 && GoodRunFit[icent][ihar][isub][irun]<3.0)){ std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<std::endl; fin->Close(); continue; } TH2F *hvtemp; TH2F *hvsqtemp; hvtemp = (TH2F*)fin->Get(Form("v%s_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi)); hvntemp = (TH2F*)fin->Get(Form("vn%s_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi)); hv->Add(hvtemp); hvn->Add(hvntemp); fin->Close(); } } hvall->Add(hv); hvnall->Add(hvn); if(iphi==nphi){ hv = hvall; hvn = hvnall; } fout->cd(); hv->Write(); hvn->Write(); for(int ipt=0;ipt<npt-1;ipt++){ int xbinmin = hv->GetXaxis()->FindBin(ptbin[ipt]+eps); int xbinmax = hv->GetXaxis()->FindBin(ptbin[ipt+1]-eps); // std::cout<<xbinmin<<" "<<xbinmax<<std::endl; // std::cout<<ptbin[ipt]<<" "<<ptbin[ipt+1]<<std::endl; TH1F* hvProj = (TH1F*)hv->ProjectionY(Form("hvProj_%d",ipt),xbinmin,xbinmax); TH1F* hvnProj = (TH1F*)hvn->ProjectionY(Form("hvnProj_%d",ipt),xbinmin,xbinmax); } } } // } } fout->Close(); }
// This ROOT macro plots the stopping depth of the muons in local coordinates void StoppingDepth(std::string filename) { TCanvas* c1 = new TCanvas("c1", "c1"); c1->SetRightMargin(0.15); int n_entries = 100000; TFile* file = new TFile(filename.c_str(), "READ"); TTree* tree = (TTree*) file->Get("tree"); double n_input_muons = tree->GetEntries(); size_t secondslash = filename.rfind("/")+1; // don't want to include the slash size_t firstdot = filename.rfind("."); size_t n_chars = firstdot - secondslash; std::string base_filename = filename.substr(secondslash, n_chars); std::string histtitle = "Plot of the Stopping Depth of Muons in " + base_filename; TH2F* hStopDepth = new TH2F("hStopDepth", histtitle.c_str(), 120,-6,6, 120,-5,55); hStopDepth->GetYaxis()->SetTitle("Local Z [#mum]"); hStopDepth->GetXaxis()->SetTitle("Local X [cm]"); hStopDepth->GetZaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}"); hStopDepth->Scale(1.0 / n_input_muons); hStopDepth->SetStats(false); tree->Draw("-1*((M_local_Oz*10000)-25):M_local_Ox>>hStopDepth", "M_particleName==\"mu-\" && M_volName==\"Target\" && M_stopped == 1", "COLZ", n_entries); c1->Update(); std::string canvasname = "hStopDepth_" + base_filename + ".png"; // c1->Print(canvasname.c_str()); TH1D* hStopZDepth = hStopDepth->ProjectionY(); hStopZDepth->Draw(); hStopZDepth->SetStats(false); hStopZDepth->GetYaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}"); // hStopZDepth->Scale(1.0 / n_input_muons); c1->Update(); canvasname = "hStopZDepth_" + base_filename + ".png"; // c1->Print(canvasname.c_str()); TH2F* hStopDepthVsTime = new TH2F("hStopDepthVsTime", histtitle.c_str(), 120,-30,30, 120,0,12); hStopDepthVsTime->GetXaxis()->SetTitle("Local Z [#mum]"); hStopDepthVsTime->GetYaxis()->SetTitle("Time [ns]"); hStopDepthVsTime->GetZaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}"); hStopDepthVsTime->Scale(1.0 / n_input_muons); hStopDepthVsTime->SetStats(false); // tree->Draw("M_Ot:M_local_Oz*10000>>hStopDepthVsTime", "M_particleName==\"mu-\" && M_volName==\"Target\" && M_stopped == 1", "COLZ", n_entries); c1->Update(); canvasname = "hStopDepthVsTime_" + base_filename + ".png"; // c1->Print(canvasname.c_str()); TH2F* hStopDepthVsMomentum = new TH2F("hStopDepthVsMomentum", histtitle.c_str(), 120,-30,30, 120,0,30); hStopDepthVsMomentum->GetXaxis()->SetTitle("Local Z [#mum]"); hStopDepthVsMomentum->GetYaxis()->SetTitle("Momentum [MeV]"); hStopDepthVsMomentum->GetZaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}"); hStopDepthVsMomentum->Scale(1.0 / n_input_muons); hStopDepthVsMomentum->SetStats(false); // tree->Draw("sqrt(M_px*M_px + M_py*M_py+ M_pz*M_pz)*1000:M_local_Oz*10000>>hStopDepthVsMomentum", "M_particleName==\"mu-\" && M_volName==\"Target\" && M_stopped == 1", "COLZ", n_entries); c1->Update(); canvasname = "hStopDepthVsMomentum_" + base_filename + ".png"; // c1->Print(canvasname.c_str()); // file->Close(); std::string outfilename = "plot_" + base_filename + ".root"; TFile* output = new TFile(outfilename.c_str(), "RECREATE"); hStopDepth->Write(); hStopZDepth->Write(); hStopDepthVsTime->Write(); hStopDepthVsMomentum->Write(); output->Close(); }
int QA_calm_plots_diff(const char* filename1, const char* filename2, const char* type = "PipPip", const char* type2 = "PipPip", bool ifSave = false) { TFile* f1 = new TFile(filename1,"READ"); TH2F* hevmultPID = ((TH2F*) f1->Get(Form("hevmultPID%s",type))); TH1D* heta = ((TH1D*) f1->Get(Form("heta%s",type))); TH1D* hpt = ((TH1D*) f1->Get(Form("hpt%s",type))); TH1D* hphiS = ((TH1D*) f1->Get(Form("hphiS%s",type))); TH1D* hphiP = ((TH1D*) f1->Get(Form("hphiP%s",type))); TH1D* hpid1 = ((TH1D*) f1->Get(Form("hpid1%s",type))); TH1D* hpid2 = ((TH1D*) f1->Get(Form("hpid2%s",type))); TH1D* hevmultAll = ((TH1D*) f1->Get(Form("hevmultAll%s",type))); TH1D* hevmult = ((TH1D*) f1->Get(Form("hevmult%s",type))); TH1D* hevweight = ((TH1D*) f1->Get(Form("hevweight%s",type))); TH1D* hevweighttaken = ((TH1D*) f1->Get(Form("hevweighttaken%s",type))); TH1D* hevweightdensity= ((TH1D*) f1->Get(Form("hevweightdensity%s",type))); TH1D* hptTotal = ((TH1D*) f1->Get(Form("hptTotal%s",type))); TFile* f2 = new TFile(filename2,"READ"); TH2F* hevmultPID2 = ((TH2F*) f2->Get(Form("hevmultPID%s",type2))); TH1D* heta2 = ((TH1D*) f2->Get(Form("heta%s",type2))); TH1D* hpt2 = ((TH1D*) f2->Get(Form("hpt%s",type2))); TH1D* hphiS2 = ((TH1D*) f2->Get(Form("hphiS%s",type2))); TH1D* hphiP2 = ((TH1D*) f2->Get(Form("hphiP%s",type2))); TH1D* hpid12 = ((TH1D*) f2->Get(Form("hpid1%s",type2))); TH1D* hpid22 = ((TH1D*) f2->Get(Form("hpid2%s",type2))); TH1D* hevmultAll2 = ((TH1D*) f2->Get(Form("hevmultAll%s",type2))); TH1D* hevmult2 = ((TH1D*) f2->Get(Form("hevmult%s",type2))); TH1D* hevweight2 = ((TH1D*) f2->Get(Form("hevweight%s",type2))); TH1D* hevweighttaken2 = ((TH1D*) f2->Get(Form("hevweighttaken%s",type2))); TH1D* hevweightdensity2= ((TH1D*) f2->Get(Form("hevweightdensity%s",type2))); TH1D* hptTotal2 = ((TH1D*) f2->Get(Form("hptTotal%s",type))); int rebin = 2; double eta = 1.1; gStyle->SetOptStat(000);//111); const char* first = "";//Cons. laws only"; const char* second = "";//Minijets"; if(rebin>0) { heta->Rebin(rebin); hpt->Rebin(rebin); hphiS->Rebin(rebin); hphiP->Rebin(rebin); heta2->Rebin(rebin); hpt2->Rebin(rebin); hphiS2->Rebin(rebin); hphiP2->Rebin(rebin); } heta2->SetLineColor(kGreen+2); hpt2->SetLineColor(kGreen+2); hphiS2->SetLineColor(kGreen+1); hphiP2->SetLineColor(kGreen+2); hpid12->SetLineColor(kGreen+2); hpid22->SetLineColor(kGreen+2); hevmultAll2->SetLineColor(kGreen+2); hevmult2->SetLineColor(kGreen+2); heta->Scale(1./heta->Integral()); heta2->Scale(1./heta2->Integral()); hpt->Scale(1./hpt->Integral()); hpt2->Scale(1./hpt2->Integral()); hevmult->Scale(1./hevmult->Integral()); hevmult2->Scale(1./hevmult2->Integral()); hevmultAll->Scale(1./hevmultAll->Integral()); hevmultAll2->Scale(1./hevmultAll2->Integral()); hpid1->Scale(1./hpid1->Integral()); hpid2->Scale(1./hpid2->Integral()); hpid12->Scale(1./hpid12->Integral()); hpid22->Scale(1./hpid22->Integral()); hphiP->Scale(1./hphiP->Integral()); hphiS->Scale(1./hphiS->Integral()); hphiP2->Scale(1./hphiP2->Integral()); hphiS2->Scale(1./hphiS2->Integral()); hptTotal->Scale(1./hptTotal->Integral()); hptTotal2->Scale(1./hptTotal2->Integral()); TCanvas* canv = new TCanvas("canv", "GENBOD results", 10,10,3*550,2*400); canv->Divide(3,3); canv->cd(1); heta->Draw(); heta2->Draw("same"); canv->cd(2); hpt->GetXaxis()->SetRangeUser(0,5); hpt->Draw(); hpt2->Draw("same"); hptTotal->SetLineColor(kMagenta); hptTotal->Draw("same"); canv->cd(3); hphiS->Draw(); hphiP->SetLineColor(kRed); hphiP->Draw("same"); hphiP2->Draw("same"); hphiS2->Draw("same"); canv->cd(4); hpid1->Draw(); hpid12->Draw("same"); canv->cd(5); hpid2->Draw(); hpid22->Draw("same"); canv->cd(6); hevmultAll->GetXaxis()->SetRangeUser(5,41); hevmultAll->Draw(); hevmultAll2->Draw("same"); canv->cd(7); hevmult->GetXaxis()->SetRangeUser(0,41); hevmult->Draw(); hevmult2->Draw("same"); canv->cd(8); hevweight->Draw(); hevweight->Draw("same"); canv->cd(9); //hevweightdensity->SetLineColor(kRed); //hevweightdensity->Draw(); //hevweightdensity2->Draw("same"); hptTotal->Draw(); hptTotal2->SetLineColor(kGreen+2); hptTotal2->Draw("same"); TF1* Ptot = new TF1("Ptot","4.33538e-02*TMath::Landau(x,3.24886e+00,2.17010e+00)*exp(8.34570e-03*x)",0,30); Ptot->Draw("same"); TCanvas* canv2 = new TCanvas("canv2", "GENBOD results", 10,10,550,400); //canv->Divide(3,3); canv2->cd(); hevmultPID->Draw("colz"); double counter[11]; double counttrue[] = {1.493,1.493, 1.493,0.183, 0.183,0.083,0.083, 0.048, 0.048,0.183,0.183}; for(int i=1;i<12;i++) counter[i-1] = ((TH1F*)hevmultPID->ProjectionY("_py",i,i))->GetMean(); for(int i=1;i<12;i++) { TLatex *part = new TLatex(0.072*i+0.05,0.7,Form("%.2f",counter[i-1])); part->SetNDC(); //part->SetTextColor(kRed+2); part->SetTextFont(42); part->SetTextSize(0.04); part->SetLineWidth(2); part->Draw(); TLatex *part1 = new TLatex(0.072*i+0.05,0.6,Form("%.1f%%",counter[i-1]/counter[0]*100.)); cout<<Form("%.1f%%",counter[i-1]/counter[0]*100.)<<endl; part1->SetNDC(); part1->SetTextColor(kRed+2); part1->SetTextFont(42); part1->SetTextSize(0.03); part1->SetLineWidth(2); part1->Draw(); TLatex *part2 = new TLatex(0.072*i+0.05,0.5,Form("%.1f%%",counttrue[i-1]/counttrue[0]*100.)); cout<<Form("%.1f%%",counttrue[i-1]/counttrue[0]*100.)<<endl; part2->SetNDC(); part2->SetTextColor(kBlue+2); part2->SetTextFont(42); part2->SetTextSize(0.03); part2->SetLineWidth(2); part2->Draw(); } }
void getResvsub(int ispt=1){ double theta[ntheta]; TFile *f[nFileAll]; for(int itheta=0;itheta<ntheta;itheta++) theta[itheta]=itheta*TMath::Pi()/ntheta/nn; int nvv; const double *binv; if(ispt){ nvv = nptv; binv = ptbinv;} else{ nvv = netav; binv = etabinv;} string SumorProd = getenv("SUMORPROD"); string mdir = getenv("DIR"); ofstream fstrv; if(ispt){ if(SumorProd=="Sum")fstrv.open("v_sub.txt"); else fstrv.open("v_2_sub.txt"); } else{ if(SumorProd=="Sum")fstrv.open("v_eta_sub.txt"); else fstrv.open("v_2_coarse_eta_sub.txt"); } TVectorD Nevent[nbin], totmultall[nbin], totmultall_[nbin]; TVectorD totmult[nbin], totpt[nbin],toteta[nbin]; TVectorD totmulthisto[nbin], totmulthistocorr[nbin]; TVectorD V_int[nbin], V_interr[nbin]; TVectorD V_intcorr[nbin], V_intcorrerr[nbin]; TVectorD* V_mean; TVectorD* deltaV_mean; TVectorD vmeanmean[nbin], deltavmeanmean[nbin], sigmavmeanmean[nbin], avgavgpt[nbin], avgavgeta[nbin]; TVectorD* V[nbin]; TVectorD* chi[nbin]; TVectorD* dDRe[nbin]; TVectorD* dDIm[nbin]; TVectorD* dNRe[nbin][ntheta]; TVectorD* dNIm[nbin][ntheta]; TComplex dD[nbin][ntheta], dN[nbin][ntheta][nvv]; TVectorD avgmult[nbin]; TVectorD avgmultall; TVectorD avgpt[nbin],avgeta[nbin]; TVectorD v[nbin][ntheta],vmean[nbin],deltav[nbin][ntheta],deltavmean[nbin]; TVectorD IFILE[nbin]; if(SumorProd=="Sum") TFile *infile = TFile::Open("mergedV_Sum.root"); else TFile *infile = TFile::Open("mergedV_Prod.root"); if(ispt){ if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod_sub.root","Recreate"); else TFile *fout = new TFile("mergedv_Prod2_sub.root","Recreate"); } else{ if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod_eta_sub.root","Recreate"); else TFile *fout = new TFile("mergedv_Prod2_coarse_eta_sub.root","Recreate"); } TVectorD Nevent_; Nevent_.ResizeTo(nbin); Nevent_.Zero(); TH1D* hpt[nbin]; TH1D* hpteffcorr[nbin]; for(int ibin=0;ibin<nbin;ibin++){ for(int ifile=0; ifile<nFileAll; ifile++){ if(ispt){ if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod_%d.root",mdir.c_str(),ifile)); else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod2_%d.root",mdir.c_str(),ifile)); } else{ if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6c/coarsebins/%s/Anaveta_Prod_%d.root",mdir.c_str(),ifile)); else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/coarsebins/%s/Anaveta_Prod2_%d.root",mdir.c_str(),ifile)); } TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get(Form("Nevent")); Nevent_[ibin]+=(*Nevent_t)[ibin]; f[ifile]->Close(); } IFILE[ibin].ResizeTo(nsamples); Nevent[ibin].ResizeTo(nsamples); Nevent[ibin].Zero(); totmultall[ibin].ResizeTo(nsamples); totmultall[ibin].Zero(); totmultall_[ibin].ResizeTo(nsamples); totmultall_[ibin].Zero(); TDirectory *dir0 = fout->mkdir(Form("D_%d",ibin)); vmeanmean[ibin].ResizeTo(nvv); vmeanmean[ibin].Zero(); deltavmeanmean[ibin].ResizeTo(nvv); deltavmeanmean[ibin].Zero(); sigmavmeanmean[ibin].ResizeTo(nvv); sigmavmeanmean[ibin].Zero(); avgavgpt[ibin].ResizeTo(nvv); avgavgpt[ibin].Zero(); avgavgeta[ibin].ResizeTo(nvv); avgavgeta[ibin].Zero(); V_interr[ibin].ResizeTo(nsamples); V_interr[ibin].Zero(); V_int[ibin].ResizeTo(nsamples); V_int[ibin].Zero(); if(ispt){ V_intcorr[ibin].ResizeTo(nsamples); V_intcorr[ibin].Zero(); V_intcorrerr[ibin].ResizeTo(nsamples); V_intcorrerr[ibin].Zero(); } for(int isample=0;isample<nsamples;isample++){ TVectorD Nevent0; Nevent0.ResizeTo(nbin); Nevent0.Zero(); avgmultall.ResizeTo(nbin); totmult[ibin].ResizeTo(nvv); totmult[ibin].Zero(); if(ispt){ totmulthisto[ibin].ResizeTo(nvv); totmulthisto[ibin].Zero(); totmulthistocorr[ibin].ResizeTo(nvv);totmulthistocorr[ibin].Zero(); } avgmult[ibin].ResizeTo(nvv); avgpt[ibin].ResizeTo(nvv); avgeta[ibin].ResizeTo(nvv); totpt[ibin].ResizeTo(nvv); totpt[ibin].Zero(); toteta[ibin].ResizeTo(nvv); toteta[ibin].Zero(); vmean[ibin].ResizeTo(nvv); deltavmean[ibin].ResizeTo(nvv); V[ibin] = (TVectorD*) infile->Get(Form("D_%d/V",ibin,isample)); chi[ibin] = (TVectorD*) infile->Get(Form("chi",ibin,isample)); V_mean = (TVectorD*) infile->Get(Form("Vmean",ibin,isample)); deltaV_mean = (TVectorD*) infile->Get(Form("deltaVmean",ibin,isample)); for(int itheta=0;itheta<ntheta;itheta++){ v[ibin][itheta].ResizeTo(nvv); deltav[ibin][itheta].ResizeTo(nvv); dD[ibin][itheta]=0; for(int ivbin=0;ivbin<nvv;ivbin++){ dN[ibin][itheta][ivbin]=0; } } for(int ifile=0; ifile<nFileAll; ifile++){ if(ispt){ if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod_%d.root",mdir.c_str(),ifile)); else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod2_%d.root",mdir.c_str(),ifile)); } else{ if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/coarsebins/%s/Anaveta_Prod_%d.root",mdir.c_str(),ifile)); else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/coarsebins/%s/Anaveta_Prod2_%d.root",mdir.c_str(),ifile)); } TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get("Nevent"); TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get("totmultall"); Nevent0[ibin] += (*Nevent_t)[ibin]; double start=isample*Nevent_[ibin]/nsamples; double end=(isample+1)*Nevent_[ibin]/nsamples; if(Nevent0[ibin]>start && Nevent0[ibin]<=end){ IFILE[ibin][isample]=(double)ifile; Nevent[ibin][isample] += (*Nevent_t)[ibin]; TVectorD* totmult_t = (TVectorD*)f[ifile]->Get(Form("totmult_%d",ibin)); TVectorD* totpt_t = (TVectorD*)f[ifile]->Get(Form("totpt_%d",ibin)); TVectorD* toteta_t = (TVectorD*)f[ifile]->Get(Form("toteta_%d",ibin)); dDRe[ibin] = (TVectorD*)f[ifile]->Get(Form("dDRe_%d",ibin)); dDIm[ibin] = (TVectorD*)f[ifile]->Get(Form("dDIm_%d",ibin)); totmultall[ibin][isample]+=(*totmultall_t)[ibin]; for(int ivbin=0;ivbin<nvv;ivbin++){ totmult[ibin][ivbin]+=(*totmult_t)[ivbin]; totpt[ibin][ivbin]+=(*totpt_t)[ivbin]; toteta[ibin][ivbin]+=(*toteta_t)[ivbin]; } for(int itheta=0;itheta<ntheta;itheta++){ dNRe[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNRe_%d_%d",ibin,itheta)); dNIm[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNIm_%d_%d",ibin,itheta)); dD[ibin][itheta]+=TComplex((*dDRe[ibin])[itheta],(*dDIm[ibin])[itheta]); for(int ivbin=0;ivbin<nvv;ivbin++){ if(ifile<188) dN[ibin][itheta][ivbin]+=TComplex((*dNRe[ibin][itheta])[ivbin],(*dNIm[ibin][itheta])[ivbin]); else dN[ibin][itheta][nvv-ivbin-1]+=TComplex((*dNRe[ibin][itheta])[ivbin],(*dNIm[ibin][itheta])[ivbin]); } } } f[ifile]->Close(); } TFile *fhisto = TFile::Open("histomerged.root"); TFile *feff = TFile::Open("/home/xuq7/HI/flow/LYZ/v2/TrackCorrections_HIJING_538_OFFICIAL_Mar24.root"); TH2F* heff = (TH2F*)feff->Get("rTotalEff3D"); TH1D* hpteff = (TH1D*)heff->ProjectionY("hpteff",heff->GetXaxis()->FindBin(-2.4),heff->GetXaxis()->FindBin(2.4)-1,"o"); TArrayD *ptarr = (TArrayD*)heff->GetYaxis()->GetXbins(); double *ptbinhisto = ptarr->GetArray(); int NbinX = heff->GetXaxis()->GetNbins(); int NbinY = heff->GetYaxis()->GetNbins(); hpteff->Scale(1.0/NbinX); for(int itheta=0;itheta<ntheta;itheta++) dD[ibin][itheta]*=TComplex::Power(TComplex::I(),mm-1)/(Double_t)Nevent[ibin][isample]; avgmultall[ibin]=1.0*totmultall[ibin][isample]/Nevent[ibin][isample]; hpt[ibin] = (TH1D*)fhisto->Get(Form("D_%d/hpt",ibin)); //TH1D* hptre = (TH1D*)hpt[ibin]->Rebin(NbinY,"hptre",ptbinhisto); //hpteffcorr[ibin] = (TH1D*)hptre->Clone(Form("hpteffcorr_%d",ibin)); //hpteffcorr[ibin]->Divide(hpteff); for(int ivbin=0;ivbin<nvv; ivbin++){ vmean[ibin][ivbin]=0; deltavmean[ibin][ivbin]=0; avgmult[ibin][ivbin]=1.0*totmult[ibin][ivbin]/Nevent[ibin][isample]; avgpt[ibin][ivbin]=1.0*totpt[ibin][ivbin]/totmult[ibin][ivbin]; avgeta[ibin][ivbin]=1.0*toteta[ibin][ivbin]/totmult[ibin][ivbin]; for(int itheta=0;itheta<ntheta;itheta++){ dN[ibin][itheta][ivbin]/=totmult[ibin][ivbin]; TComplex Res=dN[ibin][itheta][ivbin]/dD[ibin][itheta]; v[ibin][itheta][ivbin]=(*V[ibin])[itheta]*avgmultall[ibin]*TMath::BesselJ1(j01)/Besselj01(mm)*Res.Re(); vmean[ibin][ivbin]+=v[ibin][itheta][ivbin]; deltav[ibin][itheta][ivbin]=TMath::Cos(mm*nn*theta[itheta])/totmult[ibin][ivbin]*(TMath::Exp(j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Power(-1,mm)*TMath::Exp(-j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.))); deltavmean[ibin][ivbin]+=deltav[ibin][itheta][ivbin]; // fstrv<<itheta<<"\t"<<v[ibin][itheta][ivbin]<<"\t"<<deltav[ibin][itheta][ivbin]<<endl; } deltavmean[ibin][ivbin]=TMath::Sqrt(deltavmean[ibin][ivbin])/2./Besselj01(mm); //fstrv<<endl; vmean[ibin][ivbin]/=ntheta; deltavmean[ibin][ivbin]/=TMath::Sqrt(ntheta); fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t"<<vmean[ibin][ivbin]<<"\t"<<deltavmean[ibin][ivbin]<<endl; if(ispt){ if(binv[ivbin+1]>3.0) continue; totmulthisto[ibin][ivbin]=hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(binv[ivbin]),hpt[ibin]->GetXaxis()->FindBin(binv[ivbin+1])-1); // totmulthistocorr[ibin][ivbin]=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[ivbin]),hpteffcorr[ibin]->GetXaxis()->FindBin(binv[ivbin+1])-1); totmulthistocorr[ibin][ivbin]=totmulthisto[ibin][ivbin]/hpteff->GetBinContent(hpteff->FindBin((binv[ivbin]+binv[ivbin+1])/2)); V_int[ibin][isample]+=vmean[ibin][ivbin]*totmult[ibin][ivbin]; V_interr[ibin][isample]+=deltavmean[ibin][ivbin]*totmult[ibin][ivbin]; V_intcorr[ibin][isample]+=vmean[ibin][ivbin]*totmulthistocorr[ibin][ivbin]; V_intcorrerr[ibin][isample]+=deltavmean[ibin][ivbin]*totmulthistocorr[ibin][ivbin]; } totmultall_[ibin][isample]+=totmult[ibin][ivbin]; } V_int[ibin][isample]/=totmultall_[ibin][isample]; V_interr[ibin][isample]/=totmultall_[ibin][isample]; //V_intcorr[ibin][isample]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1); //V_intcorr[ibin][isample]/=totmulthistocorr[ibin]; //V_intcorrerr[ibin][isample]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1); if(ispt){ fstrv<<endl<<"pt range\t\t"<<"totmult"<<"\t\t"<<"totmult from histo"<<"\t"<<"totmult corrected"<<endl; for(int ivbin=0;ivbin<nvv; ivbin++){ fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t\t"<<totmult[ibin][ivbin]<<"\t"<<totmulthisto[ibin][ivbin]<<"\t"<<totmulthistocorr[ibin][ivbin]<<endl; } //fstrv<<"Integral\t\t"<<totmultall[ibin][isample]<<"\t"<<hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(binv[0]),hpt[ibin]->GetXaxis()->FindBin(3.0)-1)<<"\t"<<hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1)<<endl; fstrv<<"V ref="<<(*V_mean)[ibin]<<"\t"<<"V int="<<V_int[ibin][isample]<<"\t"<<"V int corr="<<V_intcorr[ibin][isample]<<endl; fstrv<<"V ref err="<<(*deltaV_mean)[ibin]<<"\t"<<"V int err="<<V_interr[ibin][isample]<<"\t"<<"V int corr err="<<V_intcorrerr[ibin][isample]<<endl; } TDirectory *dirsample = dir0->mkdir(Form("s_%d",isample)); dirsample->cd(); avgpt[ibin].Write("avgpt"); avgeta[ibin].Write("avgeta"); totmult[ibin].Write("totmult"); vmean[ibin].Write("vmean"); deltavmean[ibin].Write("deltavmean"); for(int ivbin=0;ivbin<nvv; ivbin++){ avgavgpt[ibin][ivbin]+=avgpt[ibin][ivbin]*Nevent[ibin][isample]; avgavgeta[ibin][ivbin]+=avgeta[ibin][ivbin]*Nevent[ibin][isample]; vmeanmean[ibin][ivbin]+=vmean[ibin][ivbin]/nsamples; deltavmeanmean[ibin][ivbin]+=deltavmean[ibin][ivbin]/nsamples; sigmavmeanmean[ibin][ivbin]+=TMath::Power(vmean[ibin][ivbin]/nsamples,2); } }//subsample loop dir0->cd(); IFILE[ibin].Write("IFILE"); V_int[ibin].Write("V_int"); V_interr[ibin].Write("V_interr"); V_intcorr[ibin].Write("V_intcorr"); V_intcorrerr[ibin].Write("V_intcorrerr"); Nevent[ibin].Write("Nevent"); totmultall[ibin].Write("totmultall"); for(int ivbin=0;ivbin<nvv; ivbin++){ avgavgpt[ibin][ivbin]/=Nevent_[ibin]; avgavgeta[ibin][ivbin]/=Nevent_[ibin]; sigmavmeanmean[ibin][ivbin]=TMath::Sqrt(sigmavmeanmean[ibin][ivbin]*nsamples-vmeanmean[ibin][ivbin]*vmeanmean[ibin][ivbin])/TMath::Sqrt(nsamples); } avgavgpt[ibin].Write("avgavgpt"); avgavgeta[ibin].Write("avgavgeta"); vmeanmean[ibin].Write("vmeanmean"); deltavmeanmean[ibin].Write("deltavmeanmean"); sigmavmeanmean[ibin].Write("sigmavmeanmean"); }//ntrk bin loop infile->Close(); fout->Close(); }
void makeCorrections(int typeData = 0, int hyp=1 , int niter=0 , int acc = 5 , double E = 0.9 , int typeMC = 0 , int iTr = 1 , int syst = 0 , int syst_sign = 0 , bool doPTcorr = true , double Emc = 0 , TString filename = "" , int scaleWbin0 = true , bool drawcanv = true , float mu = 14 , float sigma = 15 ){ if(typeMC==0){ typeMC = 10; if(E == 7.0) typeMC = 31; } //gROOT->ProcessLine(".x ../macro/BuildLibDico.C+"); useData = true; doptcorr = doPTcorr; if(Emc==0) Emc = E; double syst_val = 0; if(syst==0) syst_sign=0; #include "../macro/acceptanceMap.C" TString filedir("../plots/simpleana_current/"); //TString addstr("binning1"); TString addstr(""); if(syst==201) addstr = "evtSelSyst"; if(syst==600) addstr = "nsigma5"; //addstr = filename; TFile* mctmp = NULL; //Get the MC file TString mcfile = fileManager(2,typeMC,Emc,iTr,0,0,addstr,filedir); TFile* mc = TFile::Open(mcfile,"READ");//"newbinning","../plots/unfoldingv2/" cout<<"MC input file : "<<mcfile<<endl; //#include "syst_MCfile.C" //Get the data file TString datafile = fileManager(2,typeData,E,iTr,0,0,addstr,filedir); TFile* data = TFile::Open(datafile,"READ"); cout<<"Data input file : "<<datafile<<endl; //Checking if both files exist if(mc == 0){ cout<<"The MC input file doesn't exist ..."<<endl; } if(data == 0){ cout<<"The Data input file doesn't exist ..."<<endl; } if(mc == 0 || data == 0) return; ostringstream dirstr(""); dirstr << "/ptGen" << accMap.at(acc).at(0) << "_etaGen" << accMap.at(acc).at(1) << "_ptReco" << accMap.at(acc).at(2) << "_etaReco" << accMap.at(acc).at(3) ; if(accMap.at(acc).at(4)==-1) dirstr << "_chargemin"; else if(accMap.at(acc).at(4)==1) dirstr << "_chargeplus"; dirstr << "/"; TString dir = dirstr.str(); //cout<<dir<<endl; //return; //------------------------------------------------------------ //Don't even create the output file if can't do the systematic. if(syst%100==typeMC){ cout<<"!! WARNING : this is not a systematic, the MC tune for the SD distri is the same as for the rest. Exiting now ..."<<endl; return; } if( (getNIter(acc,E)-(syst%300)) < 1 && int(syst/100) == 3 && syst_sign == -1){ cout<<"!! WARNING : can't do the negative systematic, niter is already 1. Exiting now ..."<<endl; return; } if((syst==401 ||syst==402 || syst==403) && E==7.0){ cout<<"!! WARNING : can't do this systematic, don't have the right energy mc. Exiting now ..."<<endl; return; } if(syst%400==typeMC){ cout<<"!! WARNING : this is not a systematic, the MC tune for the matrix is the same as for the rest. Exiting now ..."<<endl; return; } //------------------------------------------------------------ //Opening the output file ostringstream outstr(""); outstr << "hyp" << hyp << "_niter" << niter << "_cut" << acc << "_DataType" << typeData; if(E!=Emc) outstr << "_Emc"<<Emc; if(!doptcorr) outstr<<"_noPtCorr"; if(filename!="") outstr << "__" << filename; cout<<"Output file : "<<fileManager(3,typeMC,E,iTr,syst,syst_sign,outstr.str())<<endl; TFile* out = new TFile(fileManager(3,typeMC,E,iTr,syst,syst_sign,outstr.str()),"RECREATE"); out->cd(); TDirectory* currentdir = gDirectory; //Getting the good #iter if adaptive. //BEWARE : needs to be after output file naming/creation. if(niter==0){ niter = getNIter(acc,E); cout<<"Will use "<<niter<<" iterations for the unfolding ..."<<endl; } //including the systematic on #iterations #include "syst_niter.C" //------------------------------------------------------------------------------ //---------------------------- UNFOLDING --------------------------------------- //------------------------------------------------------------------------------ gDirectory->mkdir("unfolding"); gDirectory->cd("unfolding"); //Get the Unfolding matrix //TFile* mc_matrix = new TFile(fileManager(2,type,0.9,iTr),"READ"); //TH2F* matrixhist = (TH2F*) mc_matrix->Get(dir+st("MatrixPlots_evtSel",acc)+st("/nch_matrix_evtSel",acc)); TH2F* matrixhist = (TH2F*) mc->Get(dir+st("MatrixPlots_evtSel",acc)+st("/nch_matrix_evtSel",acc)); #include "syst_matrix.C" //if(matrixhist==0)cout<<dir+st("MatrixPlots_evtSel",acc)+st("/nch_matrix_evtSel",acc)<<endl; matrixhist->SetName("nch_matrix"); /*for(int i=1;i<=matrixhist->GetNbinsX();++i){ matrixhist->SetBinContent(i,1,0); //matrixhist->SetBinContent(1,i,0); }*/ //Setting the limits from the matrix Ngen1 = matrixhist->GetNbinsX(); Nreco1 = matrixhist->GetNbinsX(); if(drawcanv){ TCanvas* cm = new TCanvas("cm","c",2500,10,500,500); cm->cd(); matrixhist->Draw("colz"); //gPad->WaitPrimitive(); } //Transform the TH2F into an array matrix4dObj matrix; transform2Matrix(matrixhist,matrix); //get the true nch distribution (from MC) //TH1F* nch_trueGen = (TH1F*) mc->Get("GenMultiPlots_etaCut/MultiPlots_NSD_etaCut/nch_NSD_etaCut"); TH1F* nch_trueGen_afterUnfolding = (TH1F*) mc->Get(dir+st("MatrixPlots_evtSel",acc)+st("/nch_gen_evtSel",acc)); nch_trueGen_afterUnfolding->SetName("nch_MC_gen_afterUnfolding"); //TH1F* nch_trueGen = (TH1F*) mc->Get("MatrixPlots_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx/nch_gen_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx"); TH1F* nch_trueGen = (TH1F*) mc->Get(dir+st("MultiPlots_etaCut_noSel_NSD_gen",acc)+st("/nch_etaCut_noSel_NSD_gen",acc)); nch_trueGen->SetName("nch_MC_gen_afterEvtSelCorrection"); //nch_trueGen->Scale(1./nch_trueGen->GetEntries()); //nch_trueGen->Draw(); //gPad->WaitPrimitive(); //get the nch to Unfold distribution TH1F* nch_INC; if(!useData) //nch_INC = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_INC_evtSel_reco",acc)+st("/nch_INC_evtSel_reco",acc)); nch_INC = (TH1F*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/nch_evtSel_INC_reco",acc)); else nch_INC = (TH1F*) data->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/nch_evtSel_INC_reco",acc)); //nch_INC = (TH1F*) data->Get(dir+st("MultiPlots_evtSel_PV",acc)+st("/nch_evtSel_PV",acc)); nch_INC->SetName("nch_data_INC_beforeSDsub"); //nch_INC->SetBinContent(1,0); //insertion of systematic code: #include "syst_tracking.C" //Getting the class MultiPlots* mp_INC_evtSel_reco_MC; MultiPlots* mp_INC_evtSel_reco_data; mp_INC_evtSel_reco_MC = (MultiPlots*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_INC_evtSel_reco",acc)+st("/multi_class_INC_evtSel_reco",acc)); if(useData) mp_INC_evtSel_reco_data = (MultiPlots*) data->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); else mp_INC_evtSel_reco_data = (MultiPlots*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); //nch_INC->Scale(1./double(mp_INC_evtSel_reco_data->nbEvts)); double MC_factor; if(nch_INC->Integral()<2) MC_factor = 1. / double(mp_INC_evtSel_reco_MC->nbEvts) ; else MC_factor = double(mp_INC_evtSel_reco_data->nbEvts) / double(mp_INC_evtSel_reco_MC->nbEvts) ; cout<<"The ratio data_INC/MC_INC is "<<MC_factor<<endl; //if( useData ) { //TH1F* nch_trueRec = (TH1F*) mc->Get("MatrixPlots_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx/nch_reco_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx"); //nch_trueRec->Draw("same"); //} //------------------------------------------------------------------------------ //---------------------------- SD Substraction --------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING SD SUB ++++" <<endl; TH1F* nch_evtSel_SD = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_SD_evtSel_reco",acc)+st("/nch_SD_evtSel_reco",acc)); TH1F* nch_evtSel_NSD = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_NSD_evtSel_reco",acc)+st("/nch_NSD_evtSel_reco",acc)); TH1F* nch_evtSel_INC = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_INC_evtSel_reco",acc)+st("/nch_INC_evtSel_reco",acc)); nch_evtSel_SD->SetName("nch_MC_gen_SD"); nch_evtSel_NSD->SetName("nch_MC_gen_NSD"); nch_evtSel_INC->SetName("nch_MC_gen_INC"); nch_evtSel_SD->Scale(MC_factor); nch_evtSel_NSD->Scale(MC_factor); nch_evtSel_INC->Scale(MC_factor); TH1F* nch_NSD = (TH1F*) nch_INC->Clone("nch_data_NSD_afterSDsub"); //Checking the integral, nentries & nevts if( nch_evtSel_INC->GetEntries()!=mp_INC_evtSel_reco_MC->nbEvts || nch_INC->GetEntries()!=mp_INC_evtSel_reco_data->nbEvts){ cout<<"Problem in normalization of SD MC component, please correct it or resampling will be wrong !"<<endl; return; } if( int(nch_INC->GetEntries() - nch_INC->Integral()) != 0 ){ cout<<"!! WARNING : nch_INC->Integral differs from the #entries ==> there are some over/underflows ..."<<endl; cout<<" ===> Integral : "<<nch_INC->Integral()<<" | #Entries : "<<nch_INC->GetEntries() <<" | Diff : "<<nch_INC->Integral()-nch_INC->GetEntries()<<endl; cout<<" ===> #Overflows : "<<nch_INC->GetBinContent(nch_INC->GetNbinsX()+1)<<endl; } //Current % of SD & NSD /*double frac_SD = nch_evtSel_SD->Integral() / nch_evtSel_INC->GetEntries(); double frac_NSD = nch_evtSel_NSD->Integral() / nch_evtSel_INC->GetEntries();*/ double frac_SD = nch_evtSel_SD->Integral() / nch_evtSel_INC->Integral(); double frac_NSD = nch_evtSel_NSD->Integral() / nch_evtSel_INC->Integral(); if(nch_evtSel_INC->GetBinContent(nch_evtSel_INC->GetNbinsX()+1)!=0) cout<<"!! WARNING : the MC INC distri has overflows ..."<<endl; cout<<"Fraction of SD events : "<< frac_SD * 100. << endl; cout<<"Fraction of NSD events : "<< frac_NSD * 100. << endl; //inserting the SD systematic #include "syst_SDsub.C" //Doing the SD substraction nch_NSD->Add(nch_evtSel_SD,-1); //nch_NSD->SetBinContent(1,0); /*int bintochange = 15; int nsigma = 3; nch_NSD->SetBinContent(bintochange,nch_NSD->GetBinContent(bintochange)- nsigma * nch_NSD->GetBinError(bintochange)); //nch_NSD->SetBinContent(bintochange+1,nch_NSD->GetBinContent(bintochange+1)- nsigma * nch_NSD->GetBinError(bintochange+1)); bintochange +=4; //nch_NSD->SetBinContent(bintochange,nch_NSD->GetBinContent(bintochange)- nsigma * nch_NSD->GetBinError(bintochange)); */ if(drawcanv){ TCanvas* c_SDsub = new TCanvas("c_SDsub","c_SDsub",2500,510,500,500); c_SDsub->cd(); nch_INC->SetLineColor(kGreen); nch_INC->Draw(); nch_evtSel_SD->SetLineColor(kRed); nch_evtSel_SD->Draw("hist same"); nch_evtSel_NSD->Draw("hist same"); nch_NSD->SetLineColor(kBlue); nch_NSD->Draw("e same"); TLegend *leg = new TLegend (.65,.70,.90,.99); leg->AddEntry(nch_INC,"data - Raw","l" ); leg->AddEntry(nch_NSD,"Data after SD corr","l" ); leg->AddEntry(nch_evtSel_SD,"MC SD","l" ); leg->AddEntry(nch_evtSel_NSD,"MC NSD","l" ); leg->Draw("same"); } TH1F* eff_evtSel = (TH1F*) mc->Get(dir+st("eff_evtSel",acc)); TH1F* evtSel_before = (TH1F*) mc->Get(dir+st("evtSel_before",acc)); TH1F* evtSel_after = (TH1F*) mc->Get(dir+st("evtSel_after",acc)); eff_evtSel->Divide(evtSel_after,evtSel_before,1,1,"B"); eff_evtSel->SetName("eff_evtSel"); TH1F* nch_toUnfold = (TH1F*) nch_NSD->Clone("nch_toUnfold"); //nch_toUnfold->Divide(eff_evtSel); divideByWidth(nch_evtSel_SD); divideByWidth(nch_evtSel_NSD); divideByWidth(nch_evtSel_INC); nch_evtSel_SD->Write(); nch_evtSel_NSD->Write(); nch_evtSel_INC->Write(); ////////////////////////////////////////////////////////////////////////////////// ///////////////////////// TEST AREA /////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ////////// TEMP TO CHECK ERRORS // makeFakeMatrix(matrixhist,nch_toUnfold,1); // transform2Matrix(matrixhist,matrix); // matrixhist->Scale(1,"width"); // matrixhist->Write(); ////////// TEMP TO CHECK ERRORS //------------------------------------------------------------------------------ //---------------------------- Unfolding --------------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING UNFOLDING ++++" <<endl; TH1F nch_unfolded("","",1,0,1); TH1F* hypothesis = (TH1F*) nch_trueGen->Clone("hypothesis"); if (hyp == 0){ for (int i=1;i<=hypothesis->GetNbinsX();i++) hypothesis->SetBinContent(i,hypothesis->GetBinWidth(i)); } else if (hyp == 1) hypothesis = nch_trueGen_afterUnfolding; else if (hyp == 2) hypothesis = nch_toUnfold; else if (hyp == 3) { hypothesis->Reset(); for (int i=0 ; i<10000 ; ++i) hypothesis->Fill(gRandom->Gaus(mu,sigma) ) ; } else if(hyp == 4){ hypothesis->Reset(); for(int i=0 ; i<=hypothesis->GetNbinsX() ; ++i) hypothesis->SetBinContent(i,NBD(i , 26.9 , 7 )); } else if(hyp == 5){ hypothesis->Reset(); TH1F* nbd1 = (TH1F*) hypothesis->Clone("nbd1"); for(int i=1 ; i<=hypothesis->GetNbinsX() ; ++i) nbd1->SetBinContent(i,NBD(i , 26.9 , 7 )); TH1F* nbd2 = (TH1F*) hypothesis->Clone("nbd2"); for(int i=1 ; i<=hypothesis->GetNbinsX() ; ++i) nbd2->SetBinContent(i,NBD(i , 57.9 , 13 )); //hypothesis->Add(nbd1,nbd2,0.72,0.28); hypothesis->Add(nbd1,nbd2,1,0); //hypothesis->SetBinContent(1,0.1); TCanvas t("t","t"); hypothesis->Draw(); gPad->WaitPrimitive(); } bool reweightmtx = false; if(E==7.) reweightmtx = true; TH1D* projX = new TH1D(); TH1D* projY = new TH1D(); cout << "Reweighting the matrix : " << reweightmtx << endl; if(reweightmtx){ matrixhist->Write("nch_matrix_beforeReweighting"); projY = (TH1D*) (matrixhist->ProjectionY("_py",1,matrixhist->GetNbinsY())); //reweighting the reco side for(int ireco = 1 ; ireco <= matrixhist->GetNbinsY() ; ++ireco){ double factor = 0; if(projY->GetBinContent(ireco)!=0) factor = nch_toUnfold->GetBinContent(ireco) / projY->GetBinContent(ireco); double sumb = 0 , suma = 0; for(int igen = 1 ; igen <= matrixhist->GetNbinsX() ; ++igen){ sumb += matrixhist->GetBinContent(igen , ireco); matrixhist->SetBinContent(igen , ireco , matrixhist->GetBinContent(igen , ireco) * factor ); suma += matrixhist->GetBinContent(igen , ireco); } //cout << "bin " << ireco << " before = " << sumb << "( " << projY->GetBinContent(ireco) << " ) after = " << suma << "( " << nch_toUnfold->GetBinContent(ireco) << " )" << endl; } } projX = (TH1D*) (matrixhist->ProjectionX("_px",1,matrixhist->GetNbinsX())); projY = (TH1D*) (matrixhist->ProjectionY("_py",1,matrixhist->GetNbinsY())); nch_unfolded = (runalgo(matrixhist,nch_toUnfold,hypothesis,niter)); TH1F* nch_unfoldedPtr = (TH1F*) nch_unfolded.Clone("nch_unfoldedPtr"); cout<< nch_unfoldedPtr->GetBinContent(31) << " " << nch_unfoldedPtr->GetBinError(31) << endl; //------------------------------------------------------------------------------ //---------------------------- ReScaling ------------------------------------- //------------------------------------------------------------------------------ /*nch_unfoldedPtr->Scale(1./double(mp_INC_evtSel_reco_data->nbEvts)); nch_INC->Scale(1./double(mp_INC_evtSel_reco_data->nbEvts)); if(nch_unfoldedPtr->Integral()<2) MC_factor = 1. / double(mp_INC_evtSel_reco_MC->nbEvts) ; else MC_factor = double(mp_INC_evtSel_reco_data->nbEvts) / double(mp_INC_evtSel_reco_MC->nbEvts) ; */ //------------------------------------------------------------------------------ //---------------------------- Resampling & moments ---------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING RESAMPLING & MOMENTS' STAT ERRORS ++++" <<endl; TMoments* moment = new TMoments(); gDirectory->mkdir("hist_resampling"); gDirectory->cd("hist_resampling"); int niter_resampling = 100; if(syst!=0) niter_resampling = 1; cout << "WARNING !! The resampling is done with " << niter_resampling << " iterations ..." << endl; TH1F nch_resampled = resample(matrixhist,nch_INC,nch_NSD,nch_unfoldedPtr,hypothesis,niter_resampling,0,nch_evtSel_SD,moment,eff_evtSel,false); TH1F* nch_resampledPtr = &nch_resampled; gDirectory->cd("../"); if(drawcanv){ TCanvas* c_resample = new TCanvas("resampling","resampling",1460,510,500,500); c_resample->cd(); nch_unfoldedPtr->SetLineColor(kBlack); nch_unfoldedPtr->Draw("hist"); nch_resampledPtr->Draw("e"); //gPad->WaitPrimitive(); } gDirectory->mkdir("mtx_resampling"); gDirectory->cd("mtx_resampling"); TH1F nch_mtxresampled = mtxresample(matrixhist,nch_toUnfold,hypothesis,niter_resampling,moment,eff_evtSel); TH1F* nch_mtxresampledPtr = &nch_mtxresampled; gDirectory->cd("../"); /* for(int nbin = 1 ; nbin<=nch_unfoldedPtr->GetNbinsX() ; ++nbin){ nch_unfoldedPtr->SetBinError(nbin , sqrt(pow(nch_resampledPtr->GetBinError(nbin),2)+pow(nch_mtxresampledPtr->GetBinError(nbin),2))); }*/ //------------------------------------------------------------------------------ //---------------------------- EvtSel Correction ------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING EVT SEL CORRECTION ++++" <<endl; TH1F* nch_corrected = (TH1F*) nch_unfoldedPtr->Clone("nch_data_corrected"); //eff_evtSel->Sumw2(); //including the systematic for evtSel Eff #include "syst_evtSelEff.C" nch_corrected->Divide(nch_corrected,eff_evtSel,1,1); /* nch_corrected->Scale(1./nch_corrected->Integral()); nch_trueGen->Scale(1./nch_trueGen->Integral()); nch_trueGen_afterUnfolding->Scale(1./nch_trueGen_afterUnfolding->Integral());*/ if(drawcanv){ TCanvas* c_effcorr = new TCanvas("c_effcorr","c_effcorr",1980,510,500,500); c_effcorr->cd(); nch_trueGen->Draw("hist"); nch_corrected->Draw("same e"); nch_trueGen_afterUnfolding->Draw("same hist"); nch_unfoldedPtr->SetLineWidth(2); nch_unfoldedPtr->SetLineColor(kGreen); nch_unfoldedPtr->Draw("same e"); TLegend* leg = new TLegend (.65,.70,.90,.99); leg->AddEntry(nch_trueGen,"MC after Correction","l" ); leg->AddEntry(nch_corrected,"Data after Correction","l" ); leg->AddEntry(nch_trueGen_afterUnfolding,"MC after Unfolding","l" ); leg->AddEntry(nch_unfoldedPtr,"Data after Unfolding","l" ); leg->Draw("same"); } //------------------------------------------------------------------------------ //---------------------------- pt frac Correction ------------------------------ //------------------------------------------------------------------------------ TH1F* nch_evtSelCorr = (TH1F*) nch_corrected->Clone("nch_data_evtSelCorr"); if(doPTcorr){ cout<<" ++++ DOING PT FRAC CORRECTION ++++" <<endl; #include "ptcorr.C" if(syst==700) ptcorr_val += 1. * syst_sign; increaseNTracks(nch_corrected , ptcorr_val , 1); } cout<<"Mean of multiplicity --------> "<<nch_corrected->GetMean()<<endl; cout<<"RMS of multiplicity --------> "<<nch_corrected->GetRMS()<<endl; //------------------------------------------------------------------------------ //-------------------------- Adding Stat Errors ---------------------------- //-------------------------- to the final curve ---------------------------- //------------------------------------------------------------------------------ for(int nbin = 1 ; nbin<=nch_corrected->GetNbinsX() ; ++nbin){ nch_corrected->SetBinError(nbin , sqrt(pow(nch_resampledPtr->GetBinError(nbin),2)+pow(nch_mtxresampledPtr->GetBinError(nbin),2))); //cout<<nbin<<" "<<nch_resampledPtr->GetBinError(nbin)<<" "<<nch_mtxresampledPtr->GetBinError(nbin)<<endl; //cout<<" "<<sqrt(pow(nch_resampledPtr->GetBinError(nbin),2)+pow(nch_mtxresampledPtr->GetBinError(nbin),2)) // <<" "<<nch_unfoldedPtr->GetBinError(nbin)<<endl; } //------------------------------------------------------------------------------ //--------------------------------- Rescaling ---------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ RESCALING ++++" <<endl; divideByWidth(nch_trueGen); divideByWidth(nch_trueGen_afterUnfolding); divideByWidth(nch_INC); divideByWidth(nch_NSD); divideByWidth(nch_unfoldedPtr); if(doPTcorr) divideByWidth(nch_evtSelCorr); divideByWidth(nch_corrected); divideByWidth(nch_resampledPtr); divideByWidth(nch_mtxresampledPtr); divideByWidth(matrixhist); divideByWidth(hypothesis); divideByWidth(projX); divideByWidth(projY); //divideByWidth(projX); //divideByWidth(projY); //nch_corrected->Scale(1./nch_corrected->Integral()); //------------------------------------------------------------------------------ //--------------------------------- Moments ------------------------------------ //------------------------------------------------------------------------------ cout<<" ++++ DOING MOMENTS ++++" <<endl; gDirectory->mkdir("moments"); gDirectory->cd("moments"); /*const int nmoments = 6; TH1F** moments = new TH1F*[nmoments]; vector<double> cmom = getCMoments(nch_corrected); vector<double> fmom = getFMoments(nch_corrected); vector<double> cmomerror = getMomentErrors(nch_corrected); for(int m = 0 ; m < nmoments ; ++m){ cout<<cmom[m]<<" "<<cmomerror[m]<<endl; ostringstream momname(""); momname << "moment_" << m; moments[m] = new TH1F(momname.str().c_str() , momname.str().c_str() , 1 , E*1000.-0.5 , E*1000.+0.5); moments[m]->SetBinContent(1, cmom[m]); moments[m]->SetBinError(1, cmomerror[m]); moments[m]->Write(); }*/ //TMoments* moment = new TMoments(nch_corrected); //moment->print(); moment->Add(nch_corrected); moment->ComputeMoments(); //moment->print(); //moment->ComputeErrorsFromResampling(nch_corrected); moment->print(); moment->Write("moments"); /* TH1F* test = new TH1F("jj","jj",3,4.5,7.5); test->Fill(5,10); test->Fill(6,10); test->Fill(7,10); TH1F* test = new TH1F("jj","jj",20000,-5,20); for(int t=0;t<1000000;++t) test->Fill(gRandom->Poisson(1)); cout<<"--------------------------"<<endl; getCMoments(test); getFMoments(test); TMoments* moment = new TMoments(); for(int ll = 1 ; ll <= test->GetNbinsX() ; ++ll){ cout<<"hjkhkjhkjhkhkjhjkhjkhjkhkjhjkhjkhjkhjkhkj "<<ll<<endl; moment->Add(test->GetBinCenter(ll) , test->GetBinContent(ll)); } moment->ComputeMoments(); moment->print(); */ gDirectory->cd("../"); //------------------------------------------------------------------------------ //------------------------------------ KNO ------------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING KNO ++++" <<endl; double knomean = nch_corrected->GetMean(); TString tkno = out->GetName(); tkno.ReplaceAll("plots/","plots/current_b1_2/"); cout<<"Opening for kno mean the file : "<<tkno<<endl; TFile* fkno = TFile::Open(tkno,"READ"); if(fkno!=0){ TMoments* mom_kno = (TMoments*) fkno->Get("unfolding/moments/moments"); knomean = mom_kno->mean->GetMean(); } else{ cout<<"WARNING !! The file does not exist, taking the mean of the hist instead"<<endl; } TH1F* kno = new TH1F("kno_corrected","kno_corrected;z = n_{ch} / < n_{ch} >;#psi(z)",nch_corrected->GetNbinsX(),Divide(nch_corrected->GetXaxis()->GetXbins(),knomean)); kno->Sumw2(); /*for( int k = 60 ; k <= nch_corrected->GetNbinsX() ; ++k) nch_corrected->SetBinContent(k,0);*/ for( int k = 1 ; k <= nch_corrected->GetNbinsX() ; ++k){ kno->SetBinContent(k , knomean * nch_corrected->GetBinContent(k) / nch_corrected->Integral()); kno->SetBinError(k , knomean * nch_corrected->GetBinError(k) / nch_corrected->Integral()); } if(drawcanv){ TCanvas* c_kno = new TCanvas("c_kno","c_kno",200,510,500,500); c_kno->cd(); kno->Draw(); } TMoments* moment_gen = new TMoments(nch_trueGen); moment_gen->ComputeMoments(); knomean = moment_gen->mean->GetMean(); if(fkno!=0){ TH1F* mom_kno_gen = (TH1F*) fkno->Get("unfolding/nch_MC_gen_afterEvtSelCorrection"); knomean = mom_kno_gen->GetMean(); } TH1F* kno_gen = new TH1F("kno_gen","kno_gen;z = n_{ch} / < n_{ch} >;#psi(z)",nch_trueGen->GetNbinsX(),Divide(nch_trueGen->GetXaxis()->GetXbins(),knomean)); kno_gen->Sumw2(); for( int k = 1 ; k <= nch_trueGen->GetNbinsX() ; ++k){ kno_gen->SetBinContent(k , knomean * nch_trueGen->GetBinContent(k) / nch_trueGen->Integral()); kno_gen->SetBinError(k , knomean * nch_trueGen->GetBinError(k) / nch_trueGen->Integral()); } out->cd("unfolding"); kno_gen->Write(); //------------------------------------------------------------------------------ //---------------------------------- Plots ------------------------------------- //------------------------------------------------------------------------------ if(drawcanv){ TCanvas* c_final = new TCanvas("c_final","c_final",1980,10,500,500); c_final->SetLeftMargin(0.17); c_final->SetBottomMargin(0.10); c_final->SetFillColor(0); c_final->GetFrame()->SetFillColor(21); c_final->GetFrame()->SetBorderSize(12); c_final->SetGrid(); //Unfolding nch_trueGen->SetLineWidth(2); nch_INC->SetLineWidth(2); nch_corrected->SetLineWidth(2); nch_trueGen->SetLineColor(kBlue); nch_INC->SetLineColor(kGreen); nch_corrected->SetLineColor(kRed); nch_INC->Draw("hist"); nch_trueGen->Draw("same hist"); nch_corrected->Draw("same e"); /*nch_trueGen->Scale(1./nch_trueGen->Integral()); nch_INC->Scale(1./nch_INC->Integral()); nch_corrected->Scale(1./nch_corrected->Integral());*/ // UA5 bool lua5 = true; TGraphAsymmErrors* ua5_multi; if ( lua5 ) { ifstream ua5("/user/xjanssen/ua5_dsigdn_eta15"); const Int_t n = 300 ; Int_t i = 0; Double_t xl[n], xh[n], x[n] , y[n], eyl[n] , eyh[n] , ex[n]; //ua5.open ("/user/xjanssen/ua5_dsigdn_eta15"); while ( ua5 >> xl[i] >> xh[i] >> y[i] >> eyh[i] >> eyl[i] ) { eyl[i] = -eyl[i] ; x[i] = xl[i]+(xh[i]-xl[i])/2; //y[i] = 3*50000 * y[i]; //eyl[i]*=3*50000; //eyh[i]*=3*50000; //cout<<y[i]<<endl; ex[i] = (xh[i]-xl[i])/2; i++; } ua5.close(); ua5_multi = new TGraphAsymmErrors(i,x,y,ex,ex,eyl,eyh); //gr->SetMarkerColor(0); //gr->SetMarkerStyle(24); ua5_multi->Draw("L"); ua5_multi->Write("ua5"); } TLegend* leg = new TLegend (.65,.90,.90,.99); leg->AddEntry(nch_trueGen,"PYTHIA D6T","l" ); if (useData) { leg->AddEntry(nch_INC,"Data - Raw","l" ); leg->AddEntry(nch_corrected,"Data - Corrected","l" ); } else { leg->AddEntry(nch_INC,"MC - Raw","l" ); leg->AddEntry(nch_corrected,"MC - Corrected","l" ); } if (lua5) leg->AddEntry(ua5_multi,"UA5 #eta < 1.5","l"); leg->SetBorderSize(0); leg->SetFillColor(0); leg->Draw(); cout<<"bin 0 corrected:"<<nch_corrected->GetBinContent(1)<<endl; cout<<"Err bin 0 corrected:"<<nch_corrected->GetBinError(1)<<endl; cout<<"bin 0 before:"<<nch_unfoldedPtr->GetBinContent(1)<<endl; cout<<"Err bin 0 before:"<<nch_unfoldedPtr->GetBinError(1)<<endl; cout<<"bin 0 eff:"<<eff_evtSel->GetBinContent(1)<<endl; cout<<"Err bin 0 eff:"<<eff_evtSel->GetBinError(1)<<endl; //------------------------------------------------------------------------------ //---------------------------------- Fits ------------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING FITS ++++" <<endl; #include "fitting.C" }//End of if(drawcanv) for final plot //Unfolding hypothesis->Write("hypothesis"); nch_trueGen->Write(); nch_trueGen_afterUnfolding->Write(); nch_INC->Write(); nch_NSD->Write(); nch_unfoldedPtr->Write(); if(doPTcorr) nch_evtSelCorr->Write(); nch_corrected->Write(); nch_resampledPtr->Write("nch_histresampled"); nch_mtxresampledPtr->Write("nch_mtxresampledPtr"); eff_evtSel->Write(); h2g(nch_corrected).Write(); //h2g(nch_mtxresampledPtr).Write(); //eff_nch_L1_hf_vtxSel->Write(); kno->Write(); matrixhist->Write(); projX->Write(); projY->Write(); gDirectory->cd("../"); //------------------------------------------------------------------------------ //-------------------------------- Corrections --------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING BASIC CORRECTIONS ++++" <<endl; MultiPlots* mp_etaCut_noSel_NSD_gen = (MultiPlots*) mc->Get(dir+st("MultiPlots_etaCut_noSel_NSD_gen",acc)+st("/multi_class_etaCut_noSel_NSD_gen",acc)); MultiPlots* mp_etaCut_evtSel_INC_reco_MC = (MultiPlots*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); MultiPlots* mp_etaCut_evtSel_INC_reco_data; if(!useData) mp_etaCut_evtSel_INC_reco_data = (MultiPlots*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); else mp_etaCut_evtSel_INC_reco_data = (MultiPlots*) data->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); cout << " nbEvts MC gen,reco : " << mp_etaCut_noSel_NSD_gen->nbEvts << " " << mp_etaCut_evtSel_INC_reco_data->nbEvts << endl; #include "makeBasicCorrections.C" // out->Close(); //data->Close(); //mc->Close(); /* delete c1; delete cm; out->Close(); data->Close(); mc->Close(); delete mc; delete data; */ }
void checkTrkInputs( TString infrec="nt_djhp_HyUQ110v0_djcalo.root", TString infgen="nt_djhp_HyUQ110v0_djcalo_genp.root", TCut evtCut="cent<30") { //TH1::SetDefaultSumw2(); TChain * trec = new TChain("tjttrk"); trec->Add(infrec); setupAlias(trec); TChain * tgen = new TChain("tjttrk"); tgen->Add(infgen); cout << infrec << " cut " << TString(evtCut) << ": " << trec->GetEntries() << endl; cout << infgen << " cut " << TString(evtCut) << ": " << tgen->GetEntries() << endl; // Correction Histograms TFile * fTrkCorr = new TFile("djtrkhist_hydjetBassv2_djuq110.root"); TString corrModule = "hitrkEffAnalyzer"; TH2F * hrec = (TH2F*)fTrkCorr->Get(Form("%s/hrec",corrModule.Data())); TH1D * hrec_pt = (TH1D*)hrec->ProjectionY(); TH2F * hsim = (TH2F*)fTrkCorr->Get(Form("%s/hsim",corrModule.Data())); TH1D * hsim_pt = (TH1D*)hsim->ProjectionY(); // Frag Histograms //TH1D * hPPtRecRaw = new TH1D("hPPtRecRaw",";p_{T} (GeV/c); count;"); TH1D * hPPtRecRaw = (TH1D*)hrec_pt->Clone("hPPtRecRaw"); hPPtRecRaw->Reset(); TH1D * hPPtGen = (TH1D*)hrec_pt->Clone("hPPtGen"); hPPtGen->Reset(); trec->Project("hPPtRecRaw","ppt",""); tgen->Project("hPPtGen","ppt",""); TH1D * hRecSimRat_pt = (TH1D*)hrec_pt->Clone("hRecSimRat_pt"); hRecSimRat_pt->Sumw2(); hRecSimRat_pt->Divide(hrec_pt,hsim_pt); TH1D * hPPtRat = (TH1D*)hrec_pt->Clone("hPPtRat"); hPPtRat->Sumw2(); hPPtRat->Divide(hPPtRecRaw,hPPtGen); // Normalize normHist(hsim_pt,0,true,1); normHist(hrec_pt,0,true,1); normHist(hPPtGen,0,true,1); normHist(hPPtRecRaw,0,true,1); // Plot hsim_pt->SetAxisRange(0,100,"X"); hsim_pt->SetTitle(";p_{T} (GeV/c); count"); hRecSimRat_pt->SetTitle(";p_{T} (GeV/c); reco/gen ratio"); hsim_pt->SetLineColor(kRed); hPPtGen->SetMarkerColor(kRed); hPPtGen->SetLineColor(kRed); hRecSimRat_pt->SetAxisRange(0,100,"X"); hRecSimRat_pt->SetAxisRange(-0.2,1.2,"Y"); hRecSimRat_pt->SetLineColor(kRed); TCanvas *cRec = new TCanvas("cRec","Rec",500,900); cRec->Divide(1,2); cRec->cd(1); cRec->GetPad(1)->SetLogy(); hsim_pt->Draw("hist"); hPPtGen->Draw("sameE"); hrec_pt->Draw("hist same"); hPPtRecRaw->Draw("sameE"); cRec->cd(2); hRecSimRat_pt->Draw("hist"); hPPtRat->Draw("sameE"); // ==================== TLegend *leg = new TLegend(0.61,0.78,0.91,0.91); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextSize(0.035); }
void PlotEvolutionsWIII(const TString &sim, UInt_t mask = 3, const TString &options="png") { #ifdef __CINT__ gSystem->Load("libptools.so"); #endif string imask = DecToBin(mask); cout << Form("\n Plotting Evolultion with mask: %s",imask.c_str()) << endl; PGlobals::Initialize(); // Palettes! gROOT->Macro("PPalettes.C"); TString opt = options; // More makeup Float_t margins[4] = {0.15,0.15,0.20,0.10}; gStyle->SetPadLeftMargin(margins[0]); // Margin left axis gStyle->SetPadRightMargin(margins[2]); gStyle->SetPadTopMargin(margins[3]); // Margin left axis gStyle->SetPadBottomMargin(margins[1]); gStyle->SetPadTickX(0); gStyle->SetPadTickY(0); if(opt.Contains("grid")) { gStyle->SetPadGridX(1); gStyle->SetPadGridY(1); } // Load first simulation data (for instance) PData *pData = PData::Get(sim.Data()); Double_t E0 = pData->GetPlasmaE0(); Float_t maxEcross = -999.; Float_t minEcross = 999.; Float_t maxEextr = -999.; Float_t minEextr = 999.; Float_t maxEdephas = -999.; Float_t minEdephas = 999.; const Int_t Nfields = 2; // E_z, E_x TH2F *hEvsTime[Nfields]; Int_t NCross[Nfields]; TGraph **gEcross[Nfields]; TGraph **gEextr[Nfields]; TGraph **gEdephas[Nfields]; TGraph *gTRatio; TH2F *hFvsTime; TGraph **gFcross = NULL; TGraph **gFextr = NULL; TH2F *hETvsTime; TGraph **gETcross = NULL; TGraph **gETextr = NULL; TH2F *hVvsTime; TGraph **gVcross = NULL; TGraph **gVextr = NULL; const Int_t NAtoms = 3; char atNames[NAtoms][4] = {"H","He","He2"}; TH2F *hIonProbvsTime[NAtoms]; // For H, He and He+. TGraph *gIonProb10[NAtoms]; TGraph *gIonProb100[NAtoms]; Float_t IonTh[NAtoms] = {33.8,92.75,234.96} ; // GV/m // if(!opt.Contains("units")) // for(Int_t i=0;i<NAtoms;i++) IonTh[i] /= ( E0 / (PUnits::GV/PUnits::m)); char hName[24]; char gName[24]; TString filename; filename = Form("./%s/Plots/Evolutions/Evolutions-%s.root",sim.Data(),sim.Data()); TFile *ifile = (TFile*) gROOT->GetListOfFiles()->FindObject(filename.Data()); if (!ifile) ifile = new TFile(filename,"READ"); TH2F *hDen1DvsTime = NULL; sprintf(hName,"hDenvsTime_1"); hDen1DvsTime = (TH2F*) ifile->Get(hName); TH2F *hRmsvsTime = NULL; sprintf(hName,"hRmsvsTime_1"); hRmsvsTime = (TH2F*) ifile->Get(hName); for(Int_t i=0;i<Nfields;i++) { sprintf(hName,"hEvsTime_%i",i); hEvsTime[i] = (TH2F*) ifile->Get(hName); if(!hEvsTime[i]) continue; cout << Form("ANALYZING FIELD %i ...",i) << endl; Int_t NTBins = hEvsTime[i]->GetNbinsX(); for(Int_t it=NTBins;it>0;it--) { // 1D field at certain timestep "it". TH1F *hE1D = (TH1F*) hEvsTime[i]->ProjectionY("_py",it,it); Int_t MAXCROSS = 2; Float_t *Cross = new Float_t[MAXCROSS]; Float_t *Extr = new Float_t[MAXCROSS]; memset(Cross,0,sizeof(Float_t)*MAXCROSS); memset(Extr,0,sizeof(Float_t)*MAXCROSS); Int_t auxNcross = PGlobals::HCrossings(hE1D,Cross,Extr,MAXCROSS,0.,0.); // cout << Form(" -> Number of crossings for histogram \"%s\" : %i ",hE1D->GetName(),auxNcross) << endl; // for(Int_t ic=0;ic<auxNcross;ic++) { // cout << Form(" %2i: cross = %6.4f extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; // } if(it==NTBins) { NCross[i] = auxNcross; gEcross[i] = new TGraph*[NCross[i]]; gEextr[i] = new TGraph*[NCross[i]]; for(Int_t ic = 0;ic<NCross[i];ic++) { gEcross[i][ic] = new TGraph(NTBins); sprintf(gName,"gEcross_%i_%i",i,ic); gEcross[i][ic]->SetName(gName); gEextr[i][ic] = new TGraph(NTBins); sprintf(gName,"gEextr_%i_%i",i,ic); gEextr[i][ic]->SetName(gName); } } Float_t time = hEvsTime[i]->GetXaxis()->GetBinCenter(it); // cout << Form("Time step %i (%.2f): %i crossings",it,time,NCross[i]) << endl; for(Int_t ic=0;ic<NCross[i];ic++) { // cout << Form(" - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl; gEcross[i][ic]->SetPoint(it-1,time,Cross[ic]); gEextr[i][ic]->SetPoint(it-1,time,Extr[ic]); } } // Calculate the max and min of every crossing. // Also calculates dephasing: gEdephas[i] = new TGraph*[NCross[i]]; for(Int_t ic = 0;ic<NCross[i];ic++) { Int_t Npoints = gEcross[i][ic]->GetN(); Double_t *yEcross = gEcross[i][ic]->GetY(); Double_t *yEextr = gEextr[i][ic]->GetY(); Double_t *xEextr = gEextr[i][ic]->GetX(); Double_t *yEdephas = new Double_t[Npoints]; for(Int_t j=0;j<Npoints;j++) { yEdephas[j] = yEcross[j] - yEcross[0]; } gEdephas[i][ic] = new TGraph(Npoints,xEextr,yEdephas); sprintf(gName,"gEdephas_%i_%i",i,ic); gEdephas[i][ic]->SetName(gName); for(Int_t j=0;j<Npoints;j++) { if(yEcross[j]>maxEcross) maxEcross = yEcross[j]; if(yEcross[j]<minEcross) minEcross = yEcross[j]; if(yEextr[j]>maxEextr) maxEextr = yEextr[j]; if(yEextr[j]<minEextr) minEextr = yEextr[j]; // Only takes into account the minimums of the accelerating field: if(ic%2 || i!=0) continue; if(yEdephas[j]>maxEdephas) maxEdephas = yEdephas[j]; if(yEdephas[j]<minEdephas) minEdephas = yEdephas[j]; } } } // Transformer ratio vs time: // Take the ratio of the minimum over the maximum of the first oscillation of the Ez. { Int_t Npoints = gEextr[0][1]->GetN(); Double_t *TR = new Double_t[Npoints]; Double_t *yExtrPrev = gEextr[0][0]->GetY(); Double_t *yExtr = gEextr[0][1]->GetY(); Double_t *xExtr = gEextr[0][1]->GetX(); for(Int_t j=0;j<Npoints;j++) { TR[j] = TMath::Abs(yExtr[j]/yExtrPrev[j]); } gTRatio = new TGraph(Npoints,xExtr,TR); sprintf(gName,"gTRatio"); gTRatio->SetName(gName); } sprintf(hName,"hVvsTime"); hVvsTime = (TH2F*) ifile->Get(hName); Int_t NVCross = 0; cout << Form("ANALYZING POTENTIAL") << endl; Int_t NTBins = hVvsTime->GetNbinsX(); for(Int_t it=NTBins;it>0;it--) { // 1D field at certain timestep "it". TH1F *hV1D = (TH1F*) hVvsTime->ProjectionY("_py",it,it); Int_t MAXCROSS = 2; Float_t *Cross = new Float_t[MAXCROSS]; Float_t *Extr = new Float_t[MAXCROSS]; memset(Cross,0,sizeof(Float_t)*MAXCROSS); memset(Extr,0,sizeof(Float_t)*MAXCROSS); Int_t auxNcross = PGlobals::HCrossings(hV1D,Cross,Extr,MAXCROSS,0.,20.); // cout << Form(" -> Number of crossings for histogram \"%s\" : %i ",hV1D->GetName(),auxNcross) << endl; // for(Int_t ic=0;ic<auxNcross;ic++) { // cout << Form(" %2i: cross = %6.4f extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; // } if(it==NTBins) { NVCross = auxNcross; gVcross = new TGraph*[NVCross]; gVextr = new TGraph*[NVCross]; for(Int_t ic = 0;ic<NVCross;ic++) { gVcross[ic] = new TGraph(NTBins); sprintf(gName,"gVcross_%i",ic); gVcross[ic]->SetName(gName); gVextr[ic] = new TGraph(NTBins); sprintf(gName,"gVextr_%i",ic); gVextr[ic]->SetName(gName); } } Float_t time = hVvsTime->GetXaxis()->GetBinCenter(it); // cout << Form("Time step %i (%.2f): %i crossings",it,time,NVCross) << endl; for(Int_t ic=0;ic<NVCross;ic++) { // cout << Form(" - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl; gVcross[ic]->SetPoint(it-1,time,Cross[ic]); gVextr[ic]->SetPoint(it-1,time,Extr[ic]); } } sprintf(hName,"hETotalvsTime"); hETvsTime = (TH2F*) ifile->Get(hName); Int_t NETCross = 0; cout << Form("ANALYZING TOTAL ELECTRIC FIELD") << endl; NTBins = hETvsTime->GetNbinsX(); for(Int_t it=NTBins;it>0;it--) { // 1D field at certain timestep "it". TH1F *hET1D = (TH1F*) hETvsTime->ProjectionY("_py",it,it); Int_t MAXCROSS = 2; Float_t *Cross = new Float_t[MAXCROSS]; Float_t *Extr = new Float_t[MAXCROSS]; memset(Cross,0,sizeof(Float_t)*MAXCROSS); memset(Extr,0,sizeof(Float_t)*MAXCROSS); Float_t baseline = 0.5; if(opt.Contains("units")) baseline *= E0 / (PUnits::GV/PUnits::m); Int_t auxNcross = PGlobals::HCrossings(hET1D,Cross,Extr,MAXCROSS,baseline,-999,-999,"cum"); // cout << Form(" -> Number of crossings for histogram \"%s\" : %i ",hET1D->GetName(),auxNcross) << endl; // for(Int_t ic=0;ic<auxNcross;ic++) { // cout << Form(" %2i: cross = %6.4f extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; // } if(it==NTBins) { NETCross = auxNcross; gETcross = new TGraph*[NETCross]; gETextr = new TGraph*[NETCross]; for(Int_t ic = 0;ic<NETCross;ic++) { gETcross[ic] = new TGraph(NTBins); sprintf(gName,"gETcross_%i",ic); gETcross[ic]->SetName(gName); gETextr[ic] = new TGraph(NTBins); sprintf(gName,"gETextr_%i",ic); gETextr[ic]->SetName(gName); } } Float_t time = hETvsTime->GetXaxis()->GetBinCenter(it); // if(it==1) // cout << Form("Time step %i (%.2f): %i crossings",it,time,NETCross) << endl; for(Int_t ic=0;ic<NETCross;ic++) { //if(it==1) // cout << Form(" - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl; gETcross[ic]->SetPoint(it-1,time,Cross[ic]); gETextr[ic]->SetPoint(it-1,time,Extr[ic]); } } sprintf(hName,"hFocusvsTime"); hFvsTime = (TH2F*) ifile->Get(hName); Int_t NFCross = 0; cout << Form("ANALYZING FOCUSING") << endl; NTBins = hFvsTime->GetNbinsX(); for(Int_t it=NTBins;it>0;it--) { // 1D field at certain timestep "it". TH1F *hF1D = (TH1F*) hFvsTime->ProjectionY("_py",it,it); Int_t MAXCROSS = 2; Float_t *Cross = new Float_t[MAXCROSS]; Float_t *Extr = new Float_t[MAXCROSS]; memset(Cross,0,sizeof(Float_t)*MAXCROSS); memset(Extr,0,sizeof(Float_t)*MAXCROSS); Int_t auxNcross = PGlobals::HCrossings(hF1D,Cross,Extr,MAXCROSS,0.,0.); // cout << Form(" -> Number of crossings for histogram \"%s\" : %i ",hF1D->GetName(),auxNcross) << endl; // for(Int_t ic=0;ic<auxNcross;ic++) { // cout << Form(" %2i: cross = %6.4f extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; // } if(it==NTBins) { NFCross = auxNcross; gFcross = new TGraph*[NFCross]; gFextr = new TGraph*[NFCross]; for(Int_t ic = 0;ic<NFCross;ic++) { gFcross[ic] = new TGraph(NTBins); sprintf(gName,"gFcross_%i",ic); gFcross[ic]->SetName(gName); gFextr[ic] = new TGraph(NTBins); sprintf(gName,"gFextr_%i",ic); gFextr[ic]->SetName(gName); } } Float_t time = hFvsTime->GetXaxis()->GetBinCenter(it); // cout << Form("Time step %i (%.2f): %i crossings",it,time,NFCross) << endl; for(Int_t ic=0;ic<NFCross;ic++) { // cout << Form(" - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl; gFcross[ic]->SetPoint(it-1,time,Cross[ic]); gFextr[ic]->SetPoint(it-1,time,Extr[ic]); } } for(Int_t i=0;i<NAtoms;i++) { sprintf(hName,"hIonProbvsTime_%s",atNames[i]); hIonProbvsTime[i] = (TH2F*) ifile->Get(hName); if(!hIonProbvsTime[i]) continue; cout << Form("ANALYZING Ionization probability %i ...",i) << endl; Int_t NTBins = hIonProbvsTime[i]->GetNbinsX(); for(Int_t it=NTBins;it>0;it--) { // 1D field at certain timestep "it". TH1F *hIonProb1D = (TH1F*) hIonProbvsTime[i]->ProjectionY("_py",it,it); Int_t MAXCROSS = 2; Float_t *Cross = new Float_t[MAXCROSS]; Float_t *Extr = new Float_t[MAXCROSS]; memset(Cross,0,sizeof(Float_t)*MAXCROSS); memset(Extr,0,sizeof(Float_t)*MAXCROSS); Int_t auxNcross = PGlobals::HCrossings(hIonProb1D,Cross,Extr,MAXCROSS,10.0); if(it==NTBins) { gIonProb10[i] = new TGraph(NTBins); sprintf(gName,"gIonProb10_%i",i); gIonProb10[i]->SetName(gName); } Float_t time = hIonProbvsTime[i]->GetXaxis()->GetBinCenter(it); gIonProb10[i]->SetPoint(it-1,time,Cross[0]); memset(Cross,0,sizeof(Float_t)*MAXCROSS); memset(Extr,0,sizeof(Float_t)*MAXCROSS); auxNcross = PGlobals::HCrossings(hIonProb1D,Cross,Extr,MAXCROSS,99.0); if(it==NTBins) { gIonProb100[i] = new TGraph(NTBins); sprintf(gName,"gIonProb100_%i",i); gIonProb100[i]->SetName(gName); } gIonProb100[i]->SetPoint(it-1,time,Cross[0]); } } // Set the color of the different evolutions according to a palette // UInt_t np = 50; // PPalette * colorPalette = (PPalette*) gROOT->FindObject("colorPalette"); // if(!colorPalette) { // const UInt_t Number = 3; // Double_t Red[Number] = { 1.00, 0.00, 0.00}; // Double_t Green[Number] = { 0.00, 1.00, 0.00}; // Double_t Blue[Number] = { 1.00, 0.00, 1.00}; // Double_t Length[Number] = { 0.00, 0.50, 1.00 }; // colorPalette = new PPalette("colorPalette"); // colorPalette->CreateGradientColorTable(Number,Length,Red,Green,Blue,np); // } // for(Int_t i=0;i<Nfields;i++) { // for(Int_t ic=0;ic<Ncross;ic++) { // Float_t step = (np/Nosc); // Int_t icolor = TMath::Nint( ((ic+1)/2) * step - 1 ); // gEextr[i][ic]->SetLineColor(colorPalette->GetColor(icolor)); // gEextr[i][ic]->SetLineWidth(2); // gEdephas[i][ic]->SetLineColor(colorPalette->GetColor(icolor)); // gEdephas[i][ic]->SetLineWidth(2); // } // } // -------------------------------------------------------------------------- // Manual coloring: const Int_t NCOLORS = 5; // Int_t colors[NCOLORS] = {kMagenta+2,kRed,kBlue,kYellow+2,kCyan+2}; Int_t colors[NCOLORS] = {kGray+3,kGray+2,kGray+1,kGray}; for(Int_t i=0;i<Nfields;i++) { for(Int_t ic=0;ic<NCross[i];ic++) { if( !gEcross[i][ic] || !gEextr[i][ic] ) continue; Int_t index = ic/2; if(index>=NCOLORS) index = NCOLORS-1; gEcross[i][ic]->SetLineColor(colors[index]); gEextr[i][ic]->SetLineColor(colors[index]); gEextr[i][ic]->SetLineWidth(1); gEdephas[i][ic]->SetLineColor(colors[index]); gEdephas[i][ic]->SetLineWidth(1); // cout << "EEEOOO" << endl; // if(ic%2) { // gEcross[i][ic]->SetLineStyle(2); // gEextr[i][ic]->SetLineStyle(2); // gEdephas[i][ic]->SetLineStyle(2); // } else { // gEcross[i][ic]->SetLineStyle(1); // gEextr[i][ic]->SetLineStyle(1); // gEdephas[i][ic]->SetLineStyle(1); // } } } for(Int_t ic = 0;ic<NFCross;ic++) { // Graph's attributes Int_t index = ic/2; if(index>=NCOLORS) index = NCOLORS-1; gFcross[ic]->SetLineColor(colors[index]); if(ic%2-1) { gFcross[ic]->SetLineStyle(2); gFextr[ic]->SetLineStyle(2); } else { gFcross[ic]->SetLineStyle(1); gFextr[ic]->SetLineStyle(1); } } for(Int_t ic = 0;ic<NVCross;ic++) { // Graph's attributes Int_t index = ic/2; if(index>=NCOLORS) index = NCOLORS-1; gVcross[ic]->SetLineColor(colors[index]); gVcross[ic]->SetLineStyle(3); gVextr[ic]->SetLineStyle(1); } for(Int_t ic = 0;ic<NETCross;ic++) { // Graph's attributes Int_t index = ic/2; if(index>=NCOLORS) index = NCOLORS-1; gETcross[ic]->SetLineColor(colors[index]); if(ic%2-1) { gETcross[ic]->SetLineStyle(2); gETextr[ic]->SetLineStyle(2); } else { gETcross[ic]->SetLineStyle(1); gETextr[ic]->SetLineStyle(1); } } for(Int_t i=0;i<NAtoms;i++) { gIonProb10[i]->SetLineStyle(2); gIonProb10[i]->SetLineColor(kGray+2); gIonProb100[i]->SetLineStyle(1); gIonProb100[i]->SetLineColor(kGray+2); } // Plotting // ------------------------------------------------------------ // Canvas setup UInt_t NPad = BitCounter(mask); if(NPad==0) NPad = 1; Float_t ypadsize = 250; Float_t ymarginsize = 200; if(NPad==1) ypadsize = 300; Float_t ysize = ypadsize * NPad + ymarginsize; Float_t boom = 1.2; if(opt.Contains("boom")) ysize *= boom; TCanvas *C = new TCanvas("C","Snapshot",1050,ysize); C->SetFillStyle(4000); UInt_t lineColor = kOrange+10; //UInt_t lineColor = TColor::GetColor(196,30,78); // Setup Pad layout: TPad **pad = new TPad*[NPad]; TH2F **hFrame = new TH2F*[NPad]; Float_t bMargin = 0.12 * (950/ysize); Float_t tMargin = 0.04 * (950/ysize); Float_t lMargin = 0.14; Float_t rMargin = 0.18; Float_t mMargin = 0.015 * (950/ysize); Float_t pfactor = 1.0; if(opt.Contains("nomar")) bMargin = tMargin = lMargin = rMargin = mMargin = 0.0; if(NPad==1) PGlobals::CanvasPartition(C,NPad,lMargin,rMargin,bMargin,tMargin,mMargin); else PGlobals::CanvasAsymPartition(C,NPad,lMargin,rMargin,bMargin,tMargin,pfactor,mMargin); // Define the frames for plotting Int_t fonttype = 43; Int_t fontsize = 32; Int_t tfontsize = 38; Int_t txsize = tfontsize+6; Int_t lxsize = fontsize; Int_t tysize = tfontsize; Int_t lysize = fontsize-2; Int_t tzsize = tfontsize-4; Int_t lzsize = fontsize-2; Float_t txoffset = (250/ypadsize) * 2.4 / (950/ysize); Float_t lxoffset = 0.015; Float_t tyoffset = 1.2 / (950/ysize); Float_t lyoffset = 0.01; Float_t tzoffset = 1.4 / (950/ysize); Float_t lzoffset = 0.01; Float_t tylength = 0.015; Float_t txlength = 0.04; for(Int_t i=NPad-1;i>=0;i--) { char name[16]; sprintf(name,"pad_%i",i); pad[i] = (TPad*) gROOT->FindObject(name); pad[i]->SetFrameLineWidth(2); pad[i]->SetTickx(1); pad[i]->SetTicky(1); if(opt.Contains("trans")) pad[i]->SetFillStyle(4000); pad[i]->SetFrameFillStyle(4000); sprintf(name,"hFrame_%i",i); hFrame[i] = (TH2F*) gROOT->FindObject(name); if(hFrame[i]) delete hFrame[i]; hFrame[i] = (TH2F*) hEvsTime[0]->Clone(name); hFrame[i]->Reset(); Float_t xFactor = pad[NPad-1]->GetAbsWNDC()/pad[i]->GetAbsWNDC(); Float_t yFactor = pad[NPad-1]->GetAbsHNDC()/pad[i]->GetAbsHNDC(); // Format for y axis hFrame[i]->GetYaxis()->SetLabelFont(fonttype); hFrame[i]->GetYaxis()->SetLabelSize(lysize); hFrame[i]->GetYaxis()->SetLabelOffset(lyoffset); hFrame[i]->GetYaxis()->SetTitleFont(fonttype); hFrame[i]->GetYaxis()->SetTitleSize(tysize); hFrame[i]->GetYaxis()->SetTitleOffset(tyoffset); hFrame[i]->GetYaxis()->SetTickLength(xFactor*tylength/yFactor); // Format for x axis hFrame[i]->GetXaxis()->SetLabelFont(fonttype); hFrame[i]->GetXaxis()->SetLabelSize(lxsize); hFrame[i]->GetXaxis()->SetLabelOffset(lxoffset); hFrame[i]->GetXaxis()->SetTitleFont(fonttype); hFrame[i]->GetXaxis()->SetTitleSize(txsize); hFrame[i]->GetXaxis()->SetTitleOffset(txoffset); hFrame[i]->GetXaxis()->SetTickLength(yFactor*txlength/xFactor); if(i>0) { // skip x axis labels except for the lowest one hFrame[i]->GetXaxis()->SetLabelSize(0.0); hFrame[i]->GetXaxis()->SetTitleSize(0.0); } if(opt.Contains("nomar")) { hFrame[i]->GetYaxis()->SetTickLength(0.0); hFrame[i]->GetXaxis()->SetTickLength(0.0); } // Labels for the frames } // Access to color Palettes TExec *exPlasma = new TExec("exPlasma","plasmaPalette->cd();"); TExec *exElec = new TExec("exElec","electron0Palette->cd();"); TExec *exHot = new TExec("exHot","hotPalette->cd();"); TExec *exField = new TExec("exField","rbowwhitePalette->cd();"); TExec *exFieldT = new TExec("exFieldT","red0Palette->cd();"); TExec *exIonP = new TExec("exIonP","redelectron0Palette->cd();"); TExec *exPot = new TExec("exPot","rbowinvPalette->cd();"); // Actual Plotting! // ------------------------------------------------------------ C->cd(0); Float_t x1,x2,y1,y2; Float_t gap = 0.01; TPaletteAxis *palette = NULL; UInt_t ip = NPad-1; if(mask & 0x1) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); // hDen1DvsTime->GetZaxis()->SetNdivisions(503); hDen1DvsTime->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hDen1DvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); exElec->Draw(); hDen1DvsTime->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hDen1DvsTime->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } pad[ip]->RedrawAxis(); ip--; C->cd(0); } if(mask & 0x2) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); // hRmsvsTime->GetZaxis()->SetNdivisions(503); hRmsvsTime->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hRmsvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); exElec->Draw(); hRmsvsTime->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hRmsvsTime->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } pad[ip]->RedrawAxis(); ip--; C->cd(0); } if(mask & 0x4) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); // hEvsTime[0]->GetZaxis()->SetNdivisions(503); hEvsTime[0]->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hEvsTime[0]->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); exField->Draw(); hEvsTime[0]->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hEvsTime[0]->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } if(!opt.Contains("nocross")) { for(Int_t ic=0;ic<NVCross;ic++) { if( gVcross[ic] ) gVcross[ic]->Draw("L"); } if(gEcross[1][0]) { gEcross[1][0]->SetLineStyle(4); gEcross[1][0]->Draw("L"); } } pad[ip]->RedrawAxis(); ip--; C->cd(0); } if(mask & 0x8) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); // hEvsTime[1]->GetZaxis()->SetNdivisions(503); hEvsTime[1]->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hEvsTime[1]->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); exField->Draw(); hEvsTime[1]->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hEvsTime[1]->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } pad[ip]->RedrawAxis(); ip--; C->cd(0); } if(mask & 0x10) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); // hETvsTime->GetZaxis()->SetNdivisions(503); hETvsTime->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hETvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); exFieldT->Draw(); hETvsTime->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hETvsTime->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } if(!opt.Contains("nocross")) { for(Int_t ic=0;ic<NVCross;ic++) { if( gVcross[ic] ) gVcross[ic]->Draw("L"); } if(gEcross[1][0]) { gEcross[1][0]->SetLineStyle(4); gEcross[1][0]->Draw("L"); } } pad[ip]->RedrawAxis(); ip--; C->cd(0); } if(mask & 0x20) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); // hVvsTime->GetZaxis()->SetNdivisions(503); hVvsTime->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hVvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); exPot->Draw(); hVvsTime->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hVvsTime->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } pad[ip]->RedrawAxis(); ip--; C->cd(0); } if(mask & 0x40) { pad[ip]->Draw(); pad[ip]->cd(); if(opt.Contains("logz")) { pad[ip]->SetLogz(1); } else { pad[ip]->SetLogz(0); } hFrame[ip]->Draw("col"); hIonProbvsTime[1]->GetZaxis()->SetNdivisions(503); hIonProbvsTime[1]->GetZaxis()->SetTitleFont(fonttype); Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC(); Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC(); hIonProbvsTime[1]->GetZaxis()->SetTickLength(xFactor*tylength/yFactor); hIonProbvsTime[1]->GetZaxis()->SetRangeUser(0.,0.12); // exFieldT->Draw(); // exPlasma->Draw(); exIonP->Draw(); hIonProbvsTime[1]->Draw("colz same"); pad[ip]->Update(); y1 = pad[ip]->GetBottomMargin(); y2 = 1 - pad[ip]->GetTopMargin(); x1 = pad[ip]->GetLeftMargin(); x2 = 1 - pad[ip]->GetRightMargin(); palette = (TPaletteAxis*) hIonProbvsTime[1]->GetListOfFunctions()->FindObject("palette"); if(palette) { palette->SetY2NDC(y2 - gap); palette->SetY1NDC(y1 + gap); palette->SetX1NDC(x2 + 0.005); palette->SetX2NDC(x2 + 0.03); palette->SetTitleOffset(tzoffset); palette->SetTitleSize(tzsize); palette->SetLabelFont(fonttype); palette->SetLabelSize(lzsize); palette->SetLabelOffset(lyoffset); palette->SetBorderSize(2); palette->SetLineColor(1); } if(!opt.Contains("nocross")) { for(Int_t ic=0;ic<NVCross;ic++) { if( gVcross[ic] ) gVcross[ic]->Draw("L"); } if(gEcross[1][0]) { gEcross[1][0]->SetLineStyle(4); gEcross[1][0]->Draw("L"); } } pad[ip]->RedrawAxis(); ip--; C->cd(0); } // Print to a file // Output file TString fOutName = Form("./%s/Plots/Evolutions/Evolutions%s-WII-%s",sim.Data(),imask.c_str(),sim.Data()); PGlobals::imgconv(C,fOutName,opt); // --------------------------------------------------------- ifile->Close(); cout << endl; }
void HistPdfTest(void) { using namespace RooFit; TFile *fin = TFile::Open("./stobg_high.root"); TTree *tin = (TTree*)fin->Get("stobg_data"); TCut Cut_SC = "eta < 0 && charge < 0"; TCut Cut_DCA = "Rpc1dca < 100 && Rpc3dca < 100"; TCut Cut_FVTX = "((fvtx_dr * fvtx_dtheta) < 150) && (TMath::Abs(fvtx_dphi) < 1.5)"; TCut Cut_Comb = (Cut_SC + Cut_DCA + Cut_FVTX); TH2F *TestH = new TH2F("DCA_r_chi2", "", 100, 0, 30, 100, 0, 20); tin->Project(TestH->GetName(), "chi2:DCA_r", Cut_Comb); RooRealVar DCA_r("DCA_r", "DCA_r", 0, 30.0); RooRealVar chi2 ("chi2", "chi2", 0, 20.0); RooArgSet *ASX = new RooArgSet(DCA_r); RooArgSet *ASY = new RooArgSet(chi2); RooArgSet *ASXY = new RooArgSet(DCA_r, chi2); //Projected into each direction RooDataHist *D1x = new RooDataHist("D1x", "", *ASX, TestH->ProjectionX()); RooDataHist *D1y = new RooDataHist("D1y", "", *ASY, TestH->ProjectionY()); RooHistPdf *P1x = new RooHistPdf ("P1x", "", *ASX, *D1x); RooHistPdf *P1y = new RooHistPdf ("P1y", "", *ASY, *D1y); RooAbsPdf *AP1 = new RooProdPdf ("AP1", "", RooArgSet(*P1x, *P1y)); //Whole 2D histogram RooDataHist *D2 = new RooDataHist("D2", "", *ASXY, TestH); RooHistPdf *P2 = new RooHistPdf ("P2", "", *ASXY, *D2); RooAbsPdf *AP2 = new RooProdPdf ("AP2", "", RooArgSet(*P2)); //! ------------------------------------------------------------------ //Draw RooPlot *f1_x = DCA_r.frame(); RooPlot *f1_y = chi2.frame(); AP1->plotOn(f1_x); AP1->plotOn(f1_y); RooPlot *f2_x = DCA_r.frame(); RooPlot *f2_y = chi2.frame(); //D2 ->plotOn(f2_x, LineColor(2), LineWidth(2)); //D2 ->plotOn(f2_y, LineColor(2), LineWidth(2)); AP2->plotOn(f2_x, LineColor(4), LineWidth(2)); AP2->plotOn(f2_y, LineColor(4), LineWidth(2)); //! ------------------------------------------------------------------ TCanvas *c1 = new TCanvas("c1", "", 1280, 800); c1->Divide(2, 2); c1->cd(1); f1_x->Draw(); c1->cd(2); f1_y->Draw(); c1->cd(3); f2_x->Draw(); c1->cd(4); f2_y->Draw(); DCA_r = 4.10000; double Val1 = AP1->getVal(DCA_r); double Val2 = AP2->getVal(DCA_r); cout <<endl <<Val1 <<" " <<Val2 <<endl; return; }
void readMCPerform(TString filename="QAresults_AOD.root", Int_t drawOnlyDzerDplus = 1, Int_t runNumber=-1) { const Int_t totTrending=5; Float_t vecForTrend[totTrending]; TString varForTrending[totTrending]={"nDzeroCandperEv","nDplusCandperEv","nDsCandperEv","nLcCandperEv","nDstarCandperEv"}; TTree* trtree=new TTree("trendingHF","tree of trending variables"); trtree->Branch("nrun",&runNumber,"nrun/I"); for(Int_t j=0; j<totTrending; j++){ trtree->Branch(varForTrending[j].Data(),&vecForTrend[j],Form("%s/F",varForTrending[j].Data())); vecForTrend[j]=-99.; } TFile *ff = new TFile(filename.Data()); Int_t color[5] = {kBlack, kRed, kGreen, kBlue, kOrange}; TDirectoryFile *dirD2H = (TDirectoryFile *)ff->Get("PWG3_D2H_QA"); if(!dirD2H){ printf("Directory PWG3_D2H_QA not found in file %s\n",filename.Data()); return; } TList *listD2H = (TList *)dirD2H->Get("nEntriesQA"); if(!listD2H){ printf("TList nEntriesQA not found in file %s\n",filename.Data()); return; } TH1F *hNentries = (TH1F *)listD2H->FindObject("hNentries"); TH2F *hHasSelBit = (TH2F *)listD2H->FindObject("HasSelBit"); TCanvas *cqa = new TCanvas("cqa", "cqa", 800, 500); cqa->Divide(2, 1); cqa->cd(1); hNentries->Draw(); cqa->cd(2); hHasSelBit->Draw("colz"); cqa->SaveAs("plot_D2HQA.png"); Double_t nEv=hNentries->GetBinContent(10); vecForTrend[0]=hHasSelBit->GetBinContent(1)/nEv; vecForTrend[1]=hHasSelBit->GetBinContent(2)/nEv; vecForTrend[2]=hHasSelBit->GetBinContent(3)/nEv; vecForTrend[3]=hHasSelBit->GetBinContent(4)/nEv; vecForTrend[4]=hHasSelBit->GetBinContent(5)/nEv; TDirectoryFile *dir = (TDirectoryFile *)ff->Get("PWGHF_D2H_MCPerform"); TList* list = 0x0; if (dir) { list = (TList *)dir->Get("coutputDperfQA"); if(list){ TH1F *hn = (TH1F *)list->FindObject("fHistNEvents"); TH1F *hnGenD = (TH1F *)list->FindObject("fHistNGenD"); Int_t entries = hn->GetBinContent(3); TH2F *fHistNCand = (TH2F *)list->FindObject("fHistNCand"); TH1F *fHistNCandDzero = (TH1F *)fHistNCand->ProjectionY("fHistNCandDzero", 1, 1); TH1F *fHistNCandDplus = (TH1F *)fHistNCand->ProjectionY("fHistNCandDplus", 2, 2); TH1F *fHistNCandDstar = (TH1F *)fHistNCand->ProjectionY("fHistNCandDstar", 3, 3); TH1F *fHistNCandDs = (TH1F *)fHistNCand->ProjectionY("fHistNCandDs", 4, 4); TH1F *fHistNCandLc = (TH1F *)fHistNCand->ProjectionY("fHistNCandLc", 5, 5); TString names[5] = {"Dzero", "Dplus", "Dstar", "Ds", "Lc2pkpi"}; TString type[2] = {"Prompt", "Feeddown"}; const Int_t nDecays = 5; TH2F *fHistXvtxResVsPt[2 * nDecays]; TH2F *fHistYvtxResVsPt[2 * nDecays]; TH2F *fHistZvtxResVsPt[2 * nDecays]; TH2F *fHistInvMassVsPt[2 * nDecays]; TH2F *fHistDecLenVsPt[2 * nDecays]; TH2F *fHistNormDLxyVsPt[2 * nDecays]; TH2F *fHistCosPointVsPt[2 * nDecays]; TH3F *fHistPtYMultGenDauInAcc[2 * nDecays]; TH3F *fHistPtYMultRecoFilt[2 * nDecays]; TProfile *fHistXvtxRes[2 * nDecays]; TProfile *fHistYvtxRes[2 * nDecays]; TProfile *fHistZvtxRes[2 * nDecays]; TProfile *fHistXvtxMean[2 * nDecays]; TProfile *fHistYvtxMean[2 * nDecays]; TProfile *fHistZvtxMean[2 * nDecays]; TH1F *fHistXvtxRes2[2 * nDecays]; TH1F *fHistYvtxRes2[2 * nDecays]; TH1F *fHistZvtxRes2[2 * nDecays]; TProfile *fHistInvMass[2 * nDecays]; TProfile *fHistDecLen[2 * nDecays]; TProfile *fHistCosp[2 * nDecays]; TH1F *fHistInvMassRes[2 * nDecays]; TH1F *hEffPt[2 * nDecays]; TH1F *htemp; for (Int_t j = 0; j < 5; j++) { //decays for (Int_t i = 0; i < 2; i++) { //prompt and fd Int_t index = j * 2 + i; fHistXvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hXvtxResVsPt%s%s", type[i].Data(), names[j].Data())); fHistYvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hYvtxResVsPt%s%s", type[i].Data(), names[j].Data())); fHistZvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hZvtxResVsPt%s%s", type[i].Data(), names[j].Data())); fHistInvMassVsPt[index] = (TH2F *)list->FindObject(Form("hInvMassVsPt%s%s", type[i].Data(), names[j].Data())); fHistDecLenVsPt[index] = (TH2F *)list->FindObject(Form("hDecLenVsPt%s%s", type[i].Data(), names[j].Data())); fHistCosPointVsPt[index] = (TH2F *)list->FindObject(Form("hCosPointVsPt%s%s", type[i].Data(), names[j].Data())); fHistPtYMultGenDauInAcc[index] = (TH3F *)list->FindObject(Form("hPtYMult%sGenDauInAcc%s", type[i].Data(), names[j].Data())); fHistPtYMultRecoFilt[index] = (TH3F *)list->FindObject(Form("hPtYMult%sRecoFilt%s", type[i].Data(), names[j].Data())); fHistXvtxMean[index] = (TProfile *)fHistXvtxResVsPt[index]->ProfileX(Form("hXvtxMean%s%s", type[i].Data(), names[j].Data())); fHistXvtxMean[index]->SetLineColor(color[j]); fHistXvtxMean[index]->SetLineWidth(2); fHistXvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistXvtxMean[index]->GetYaxis()->SetTitle("Xvtx (reco-true) mean (#mum)"); fHistXvtxMean[index]->SetTitle("Xvtx residual vs pT"); fHistYvtxMean[index] = (TProfile *)fHistYvtxResVsPt[index]->ProfileX(Form("hYvtxMean%s%s", type[i].Data(), names[j].Data())); fHistYvtxMean[index]->SetLineColor(color[j]); fHistYvtxMean[index]->SetLineWidth(2); fHistYvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistYvtxMean[index]->GetYaxis()->SetTitle("Yvtx (reco-true) mean (#mum)"); fHistYvtxMean[index]->SetTitle("Yvtx residual vs pT"); fHistZvtxMean[index] = (TProfile *)fHistZvtxResVsPt[index]->ProfileX(Form("hZvtxMean%s%s", type[i].Data(), names[j].Data())); fHistZvtxMean[index]->SetLineColor(color[j]); fHistZvtxMean[index]->SetLineWidth(2); fHistZvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistZvtxMean[index]->GetYaxis()->SetTitle("Zvtx (reco-true) mean (#mum)"); fHistZvtxMean[index]->SetTitle("Zvtx residual vs pT"); fHistXvtxRes[index] = (TProfile *)fHistXvtxResVsPt[index]->ProfileX(Form("hXvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s"); fHistYvtxRes[index] = (TProfile *)fHistYvtxResVsPt[index]->ProfileX(Form("hYvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s"); fHistZvtxRes[index] = (TProfile *)fHistZvtxResVsPt[index]->ProfileX(Form("hZvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s"); fHistXvtxRes2[index] = (TH1F *)fHistXvtxResVsPt[index]->ProjectionX(Form("hXvtxRes2%s%s", type[i].Data(), names[j].Data())); fHistYvtxRes2[index] = (TH1F *)fHistYvtxResVsPt[index]->ProjectionX(Form("hYvtxRes2%s%s", type[i].Data(), names[j].Data())); fHistZvtxRes2[index] = (TH1F *)fHistZvtxResVsPt[index]->ProjectionX(Form("hZvtxRes2%s%s", type[i].Data(), names[j].Data())); fHistXvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistXvtxRes[index]->GetYaxis()->SetTitle("Xvtx (reco-true) RMS (#mum)"); fHistXvtxRes[index]->SetTitle("Xvtx resolution vs pT"); fHistYvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistYvtxRes[index]->GetYaxis()->SetTitle("Yvtx (reco-true) RMS (#mum)"); fHistYvtxRes[index]->SetTitle("Yvtx resolution vs pT"); fHistZvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistZvtxRes[index]->GetYaxis()->SetTitle("Zvtx (reco-true) RMS (#mum)"); fHistZvtxRes[index]->SetTitle("Zvtx resolution vs pT"); fHistXvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistXvtxRes2[index]->GetYaxis()->SetTitle("Xvtx (reco-true) RMS (#mum)"); fHistXvtxRes2[index]->SetTitle("Xvtx resolution vs pT"); fHistYvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistYvtxRes2[index]->GetYaxis()->SetTitle("Yvtx (reco-true) RMS (#mum)"); fHistYvtxRes2[index]->SetTitle("Yvtx resolution vs pT"); fHistZvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistZvtxRes2[index]->GetYaxis()->SetTitle("Zvtx (reco-true) RMS (#mum)"); fHistZvtxRes2[index]->SetTitle("Zvtx resolution vs pT"); fHistXvtxRes2[index]->SetLineColor(color[j]); fHistYvtxRes2[index]->SetLineColor(color[j]); fHistZvtxRes2[index]->SetLineColor(color[j]); fHistXvtxRes2[index]->SetMarkerColor(color[j]); fHistXvtxRes2[index]->SetMarkerStyle(20); fHistYvtxRes2[index]->SetMarkerColor(color[j]); fHistYvtxRes2[index]->SetMarkerStyle(20); fHistZvtxRes2[index]->SetMarkerColor(color[j]); fHistZvtxRes2[index]->SetMarkerStyle(20); fHistXvtxRes2[index]->SetLineWidth(2); fHistYvtxRes2[index]->SetLineWidth(2); fHistZvtxRes2[index]->SetLineWidth(2); fHistXvtxRes2[index]->Sumw2(); fHistYvtxRes2[index]->Sumw2(); fHistZvtxRes2[index]->Sumw2(); fHistInvMass[index] = (TProfile *)fHistInvMassVsPt[index]->ProfileX(Form("hInvMassVsPt%s%s", type[i].Data(), names[j].Data())); fHistInvMass[index]->SetLineColor(color[j]); fHistInvMass[index]->SetLineWidth(2); fHistInvMass[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistInvMass[index]->GetYaxis()->SetTitle("Inv Mass (GeV/c2)"); fHistInvMass[index]->SetTitle("Inv Mass vs pT"); fHistDecLen[index] = (TProfile *)fHistDecLenVsPt[index]->ProfileX(Form("hDecLenVsPt%s%s", type[i].Data(), names[j].Data())); fHistDecLen[index]->SetLineColor(color[j]); fHistDecLen[index]->SetLineWidth(2); fHistDecLen[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistDecLen[index]->GetYaxis()->SetTitle("Dec Len (#mum)"); fHistDecLen[index]->SetTitle("Prompt Dec Len vs pT"); fHistCosp[index] = (TProfile *)fHistCosPointVsPt[index]->ProfileX(Form("hCosPVsPt%s%s", type[i].Data(), names[j].Data())); fHistCosp[index]->SetLineColor(color[j]); fHistCosp[index]->SetLineWidth(2); fHistCosp[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistCosp[index]->GetYaxis()->SetTitle("Cos Point"); fHistCosp[index]->SetTitle("Prompt CosPoint vs pT"); if (index % 2 == 1) fHistDecLen[index]->SetTitle("FeedDown Dec Len vs pT"); htemp = (TH1F *)fHistPtYMultGenDauInAcc[index]->ProjectionX(Form("hPtDen%s%s", type[i].Data(), names[j].Data())); hEffPt[index] = (TH1F *)fHistPtYMultRecoFilt[index]->ProjectionX(Form("hPtNum%s%s", type[i].Data(), names[j].Data())); fHistPtYMultGenDauInAcc[index]->Sumw2(); fHistPtYMultRecoFilt[index]->Sumw2(); hEffPt[index]->Sumw2(); hEffPt[index]->Divide(htemp); hEffPt[index]->SetLineColor(color[j]); hEffPt[index]->SetLineWidth(2); hEffPt[index]->GetXaxis()->SetTitle("pT (GeV/c)"); hEffPt[index]->GetYaxis()->SetTitle("Prompt Efficiency"); hEffPt[index]->SetTitle("Prompt Efficiency"); hEffPt[index]->SetStats(0); fHistCosp[index]->SetStats(0); fHistDecLen[index]->SetStats(0); if (index % 2 == 1) { hEffPt[index]->GetYaxis()->SetTitle("Feeddown Efficiency"); hEffPt[index]->SetTitle("Feeddown Efficiency"); } fHistInvMassRes[index] = new TH1F(*hEffPt[index]); for (Int_t jj = 1; jj < hEffPt[index]->GetNbinsX() + 1; jj++) { TH1F *hTemp = (TH1F *)fHistInvMassVsPt[index]->ProjectionY("htemp", jj, jj); fHistInvMassRes[index]->SetBinContent(jj, hTemp->GetRMS()); fHistInvMassRes[index]->SetBinError(jj, hTemp->GetRMSError()); fHistInvMassRes[index]->SetLineColor(color[j]); fHistInvMassRes[index]->SetLineWidth(2); fHistInvMassRes[index]->GetXaxis()->SetTitle("pT (GeV/c)"); fHistInvMassRes[index]->GetYaxis()->SetTitle("Inv Mass RMS (GeV/c2)"); fHistInvMassRes[index]->SetTitle("Inv Mass RMS vs pT"); if (index == 0) printf("D0: pt=%f, res=%f \n", fHistInvMassRes[index]->GetBinCenter(jj), fHistInvMassRes[index]->GetBinContent(jj)); TH1F *hTempX = (TH1F *)fHistXvtxResVsPt[index]->ProjectionY("htempX", jj, jj); TH1F *hTempY = (TH1F *)fHistYvtxResVsPt[index]->ProjectionY("htempY", jj, jj); TH1F *hTempZ = (TH1F *)fHistZvtxResVsPt[index]->ProjectionY("htempZ", jj, jj); fHistXvtxRes2[index]->SetBinContent(jj, hTempX->GetRMS()); fHistXvtxRes2[index]->SetBinError(jj, hTempX->GetRMSError()); fHistYvtxRes2[index]->SetBinContent(jj, hTempY->GetRMS()); fHistYvtxRes2[index]->SetBinError(jj, hTempY->GetRMSError()); fHistZvtxRes2[index]->SetBinContent(jj, hTempZ->GetRMS()); fHistZvtxRes2[index]->SetBinError(jj, hTempZ->GetRMSError()); } } } fHistNCandDplus->SetLineColor(2); fHistNCandDstar->SetLineColor(3); fHistNCandDs->SetLineColor(4); fHistNCandLc->SetLineColor(kOrange); fHistNCandDplus->SetLineWidth(2); fHistNCandDstar->SetLineWidth(2); fHistNCandDs->SetLineWidth(2); fHistNCandLc->SetLineWidth(2); fHistNCandDzero->GetXaxis()->SetTitle("pT (GeV/c)"); fHistNCandDzero->GetYaxis()->SetTitle("counts"); TLegend *leg = new TLegend(0.6, 0.7, 0.8, 0.9); leg->AddEntry(fHistNCandDzero, "Dzero", "l"); leg->AddEntry(fHistNCandDplus, "Dplus", "l"); leg->AddEntry(fHistNCandDstar, "Dstar", "l"); leg->AddEntry(fHistNCandDs, "Ds", "l"); leg->AddEntry(fHistNCandLc, "Lc", "l"); TLegend *leg1 = new TLegend(0.5, 0.7, 0.7, 0.9); leg1->AddEntry(fHistYvtxRes2[0], "Dzero", "pl"); leg1->AddEntry(fHistYvtxRes2[2], "Dplus", "pl"); if (drawOnlyDzerDplus == 0) leg1->AddEntry(fHistYvtxRes2[6], "Ds", "pl"); if (drawOnlyDzerDplus == 0) leg1->AddEntry(fHistYvtxRes2[8], "Lc", "pl"); TLegend *leg2 = new TLegend(0.5, 0.7, 0.7, 0.9); leg2->AddEntry(fHistYvtxMean[0], "Dzero", "l"); leg2->AddEntry(fHistYvtxMean[2], "Dplus", "l"); if (drawOnlyDzerDplus == 0) leg2->AddEntry(fHistYvtxMean[6], "Ds", "l"); if (drawOnlyDzerDplus == 0) leg2->AddEntry(fHistYvtxMean[8], "Lc", "l"); TLegend *leg3 = new TLegend(0.2, 0.7, 0.4, 0.9); leg3->AddEntry(fHistNCandDzero, "Dzero", "l"); leg3->AddEntry(fHistNCandDplus, "Dplus", "l"); if (drawOnlyDzerDplus == 0) leg3->AddEntry(fHistNCandDstar, "Dstar", "l"); if (drawOnlyDzerDplus == 0) leg3->AddEntry(fHistNCandDs, "Ds", "l"); if (drawOnlyDzerDplus == 0) leg3->AddEntry(fHistNCandLc, "Lc", "l"); TLegend *leg4 = new TLegend(0.7, 0.7, 0.9, 0.9); leg4->AddEntry(fHistNCandDzero, "Dzero", "l"); leg4->AddEntry(fHistNCandDplus, "Dplus", "l"); if (drawOnlyDzerDplus == 0) leg4->AddEntry(fHistNCandDstar, "Dstar", "l"); if (drawOnlyDzerDplus == 0) leg4->AddEntry(fHistNCandDs, "Ds", "l"); if (drawOnlyDzerDplus == 0) leg4->AddEntry(fHistNCandLc, "Lc", "l"); TCanvas *c0_1 = new TCanvas("c0_1", "c0_1", 500, 500); hnGenD->SetTitle("number of generated D mesons"); hnGenD->Draw(); c0_1->SaveAs("plotDgen.png"); TCanvas *c0_2 = new TCanvas("c0_2", "c0_2", 500, 500); c0_2->SetLogy(); fHistNCandDs->SetTitle("Candidates passing filtering cuts"); fHistNCandDs->Draw(""); c0_2->Update(); TPaveStats *stats = (TPaveStats *)c0_2->GetPrimitive("stats"); stats->SetName("h1stats"); stats->SetY1NDC(0.5); stats->SetY2NDC(0.35); c0_2->Update(); fHistNCandDplus->Draw("sames"); c0_2->Update(); TPaveStats *stats2 = (TPaveStats *)c0_2->GetPrimitive("stats"); stats2->SetName("h2stats"); stats2->SetY1NDC(0.8); stats2->SetY2NDC(.65); c0_2->Update(); fHistNCandDstar->Draw("sames"); c0_2->Update(); TPaveStats *stats3 = (TPaveStats *)c0_2->GetPrimitive("stats"); stats3->SetName("h3stats"); stats3->SetY1NDC(0.65); stats3->SetY2NDC(.5); c0_2->Update(); fHistNCandDzero->Draw("sames"); c0_2->Update(); TPaveStats *stats4 = (TPaveStats *)c0_2->GetPrimitive("stats"); stats4->SetName("h4stats"); stats4->SetY1NDC(0.95); stats4->SetY2NDC(.8); c0_2->Update(); fHistNCandLc->Draw("sames"); c0_2->Update(); TPaveStats *stats5 = (TPaveStats *)c0_2->GetPrimitive("stats"); stats5->SetName("h1stats"); stats5->SetY1NDC(0.35); stats5->SetY2NDC(.2); c0_2->Update(); leg->Draw(); c0_2->SaveAs("plotDcandpt.png"); TCanvas *c0_3 = new TCanvas("c0_3", "c0_3", 500, 500); fHistInvMass[0]->SetMinimum(1.6); fHistInvMass[0]->SetMaximum(2.4); fHistInvMass[0]->Draw(); fHistInvMass[2]->Draw("sames"); fHistInvMass[4]->Draw("sames"); fHistInvMass[6]->Draw("sames"); fHistInvMass[8]->Draw("sames"); leg->Draw(); c0_3->SaveAs("plotDcandInvMass.png"); TCanvas *c0_4 = new TCanvas("c0_4", "c0_4", 500, 500); //fHistInvMassRes[0]->SetMinimum(1.6); //fHistInvMassRes[0]->SetMaximum(2.4); fHistInvMassRes[0]->GetYaxis()->SetTitleOffset(1.4); fHistInvMassRes[0]->SetTitle("D0 Inv Mass RMS vs pT"); fHistInvMassRes[0]->Draw(""); // fHistInvMassRes[2]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistInvMassRes[4]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistInvMassRes[6]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistInvMassRes[8]->Draw("sames"); //leg->Draw(); c0_4->SaveAs("plotD0candInvMassWidth.png"); fHistXvtxMean[0]->SetStats(0); fHistYvtxMean[0]->SetStats(0); fHistZvtxMean[0]->SetStats(0); fHistXvtxMean[2]->SetStats(0); fHistYvtxMean[2]->SetStats(0); fHistZvtxMean[2]->SetStats(0); fHistXvtxRes2[0]->SetStats(0); fHistYvtxRes2[0]->SetStats(0); fHistZvtxRes2[0]->SetStats(0); fHistXvtxRes2[2]->SetStats(0); fHistYvtxRes2[2]->SetStats(0); fHistZvtxRes2[2]->SetStats(0); TCanvas *cc = new TCanvas("cc", "cc", 1200, 500); cc->Divide(3, 1); cc->cd(1); fHistXvtxMean[0]->GetYaxis()->SetTitleOffset(1.4); fHistXvtxMean[0]->SetMinimum(-300.); fHistXvtxMean[0]->SetMaximum(300.); fHistXvtxMean[0]->Draw(); fHistXvtxMean[2]->Draw("sames"); leg2->Draw(); cc->cd(2); fHistYvtxMean[0]->GetYaxis()->SetTitleOffset(1.4); fHistYvtxMean[0]->SetMinimum(-300.); fHistYvtxMean[0]->SetMaximum(300.); fHistYvtxMean[0]->Draw(); fHistYvtxMean[2]->Draw("sames"); leg2->Draw(); cc->cd(3); fHistZvtxMean[0]->GetYaxis()->SetTitleOffset(1.4); fHistZvtxMean[0]->SetMinimum(-300.); fHistZvtxMean[0]->SetMaximum(300.); fHistZvtxMean[0]->Draw(); fHistZvtxMean[2]->Draw("sames"); leg2->Draw(); cc->SaveAs("plotXYZVtxMean.png"); ///////// TCanvas *ccr = new TCanvas("ccr", "ccr", 1200, 500); ccr->Divide(3, 1); ccr->cd(1); fHistXvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4); fHistXvtxRes2[0]->SetMinimum(0.); fHistXvtxRes2[0]->SetMaximum(500.); fHistXvtxRes2[0]->Draw(); fHistXvtxRes2[2]->Draw("sames"); leg2->Draw(); ccr->cd(2); fHistYvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4); fHistYvtxRes2[0]->SetMinimum(0.); fHistYvtxRes2[0]->SetMaximum(500.); fHistYvtxRes2[0]->Draw(); fHistYvtxRes2[2]->Draw("sames"); leg2->Draw(); ccr->cd(3); fHistZvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4); fHistZvtxRes2[0]->SetMinimum(0.); fHistZvtxRes2[0]->SetMaximum(500.); fHistZvtxRes2[0]->Draw(); fHistZvtxRes2[2]->Draw("sames"); leg2->Draw(); ccr->SaveAs("plotXYZVtxRMS.png"); TCanvas *ccc = new TCanvas("ccc", "ccc", 1200, 800); ccc->Divide(3, 2); ccc->cd(1); fHistDecLen[0]->GetYaxis()->SetTitleOffset(1.45); fHistDecLen[0]->Draw(); fHistDecLen[2]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistDecLen[4]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistDecLen[6]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistDecLen[8]->Draw("sames"); leg3->Draw(); ccc->cd(2); fHistCosp[0]->GetYaxis()->SetTitleOffset(1.45); fHistCosp[0]->Draw(); fHistCosp[2]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistCosp[4]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistCosp[6]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistCosp[8]->Draw("sames"); leg4->Draw(); ccc->cd(3); hEffPt[0]->GetYaxis()->SetTitleOffset(1.45); hEffPt[0]->Draw(); hEffPt[2]->Draw("sames"); if (drawOnlyDzerDplus == 0) hEffPt[4]->Draw("sames"); if (drawOnlyDzerDplus == 0) hEffPt[6]->Draw("sames"); if (drawOnlyDzerDplus == 0) hEffPt[8]->Draw("sames"); leg3->Draw(); ccc->cd(4); fHistDecLen[1]->GetYaxis()->SetTitleOffset(1.45); fHistDecLen[1]->Draw(); fHistDecLen[3]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistDecLen[5]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistDecLen[7]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistDecLen[9]->Draw("sames"); leg3->Draw(); ccc->cd(5); fHistCosp[1]->GetYaxis()->SetTitleOffset(1.45); fHistCosp[1]->Draw(); fHistCosp[3]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistCosp[5]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistCosp[7]->Draw("sames"); if (drawOnlyDzerDplus == 0) fHistCosp[9]->Draw("sames"); leg4->Draw(); ccc->cd(6); hEffPt[1]->GetYaxis()->SetTitleOffset(1.45); hEffPt[1]->Draw(); hEffPt[3]->Draw("sames"); if (drawOnlyDzerDplus == 0) hEffPt[5]->Draw("sames"); if (drawOnlyDzerDplus == 0) hEffPt[7]->Draw("sames"); if (drawOnlyDzerDplus == 0) hEffPt[9]->Draw("sames"); leg3->Draw(); ccc->SaveAs("plot_DL_cosp_Eff_prompt_fd.png"); } } trtree->Fill(); if(runNumber>0){ TFile* foutfile=new TFile("trendingHF.root","recreate"); trtree->Write(); TDirectory* outdir=foutfile->mkdir(dirD2H->GetName()); outdir->cd(); listD2H->Write(listD2H->GetName(),1); foutfile->cd(); if(dir && list){ TDirectory* outdir2=foutfile->mkdir(dir->GetName()); outdir2->cd(); list->Write(list->GetName(),1); } foutfile->Close(); delete foutfile; } }
void plotHistHi() { gStyle->SetOptStat(0); set_plot_style(); TFile *f = new TFile("./../root_files/hists.root"); // sim-to-reco hists TH2F *hSim = (TH2F*) f->Get("hitrkEffAnalyzer/hsim"); hSim->GetYaxis()->SetRangeUser(0,10); TH2F *hAcc = (TH2F*) f->Get("hitrkEffAnalyzer/hacc"); hAcc->GetYaxis()->SetRangeUser(0,10); TH2F *hEff = (TH2F*) f->Get("hitrkEffAnalyzer/heff"); hEff->GetYaxis()->SetRangeUser(0,10); TH2F *hMul = (TH2F*) f->Get("hitrkEffAnalyzer/hmul"); hMul->GetYaxis()->SetRangeUser(0,10); // reco-to-sim hists TH2F *hRec = (TH2F*) f->Get("hitrkEffAnalyzer/hrec"); hRec->GetYaxis()->SetRangeUser(0,10); TH2F *hFak = (TH2F*) f->Get("hitrkEffAnalyzer/hfak"); hFak->GetYaxis()->SetRangeUser(0,10); TH2F *hSec = (TH2F*) f->Get("hitrkEffAnalyzer/hsec"); hSec->GetYaxis()->SetRangeUser(0,10); // ratio histograms TH2F *rAcc = (TH2F*) hAcc->Clone("rAcc"); TH2F *rEff = (TH2F*) hEff->Clone("rEff"); TH2F *rMul = (TH2F*) hMul->Clone("rMul"); TH2F *rFak = (TH2F*) hFak->Clone("rFak"); TH2F *rSec = (TH2F*) hSec->Clone("rSec"); //TH2F *rDec = (TH2F*) hDec->Clone("rDec"); //--------------------------------------------- // acceptance fraction TCanvas *c1 = new TCanvas("c1","Acceptance Fraction",600,500); gPad->SetRightMargin(0.15); rAcc->Divide(hAcc,hSim,1,1,"B"); rAcc->SetStats(0); rAcc->SetMaximum(1.0); rAcc->SetMinimum(0.0); rAcc->SetTitle("Geometrical Acceptance"); rAcc->Draw("colz"); // reco efficiency fraction TCanvas *c2 = new TCanvas("c2","Reco Efficiency Fraction",600,500); gPad->SetRightMargin(0.15); rEff->Divide(hEff,hAcc,1,1,"B"); rEff->SetStats(0); rEff->SetMaximum(1.0); rEff->SetMinimum(0.0); rEff->SetTitle("Algorithmic Efficiency"); rEff->Draw("colz"); // multiple reco fraction TCanvas *c3 = new TCanvas("c3","Multiple Reco Fraction",600,500); gPad->SetRightMargin(0.15); rMul->Divide(hMul,hAcc,1,1,"B"); rMul->SetStats(0); rMul->SetMaximum(0.00049); rMul->SetMinimum(0.0); rMul->SetTitle("Multiple Reconstruction Fraction"); rMul->Draw("colz"); // fake reco fraction TCanvas *c4 = new TCanvas("c4","Fake Reco Fraction",600,500); gPad->SetRightMargin(0.15); rFak->Divide(hFak,hRec,1,1,"B"); rFak->SetStats(0); rFak->SetMaximum(0.1); rFak->SetMinimum(0.0); rFak->SetTitle("Fake Reconstruction Fraction"); rFak->Draw("colz"); // secondary reco fraction TCanvas *c5 = new TCanvas("c5","Secondary Fraction",600,500); gPad->SetRightMargin(0.15); rSec->Divide(hSec,hRec,1,1,"B"); rSec->SetStats(0); rSec->SetMaximum(0.05); rSec->SetMinimum(0.0); rSec->SetTitle("Non-Primary Reconstruction Fraction"); rSec->Draw("colz"); //--------------------------------------------- // find bins corresponding to projections for below Int_t ptbin04=hSim->GetYaxis()->FindBin(0.91); Int_t ptbin20=hSim->GetYaxis()->FindBin(2.01); Int_t ptbins=hSim->GetYaxis()->GetNbins(); Int_t etabin24m=hSim->GetXaxis()->FindBin(-2.39); Int_t etabin24p=hSim->GetXaxis()->FindBin(2.39); Int_t etabin10m=hSim->GetXaxis()->FindBin(-0.99); Int_t etabin10p=hSim->GetXaxis()->FindBin(0.99); cout << "etabin10m: " << etabin10m << " etabin10p: " << etabin10p << endl; cout << "etabin10m: " << etabin24m << " etabin10p: " << etabin24p << endl; // projected hists: pt > 0.9 GeV/c TH1D* hSimEta = (TH1D*) hSim->ProjectionX("hSimEta",ptbin04,ptbins,"e"); TH1D* hAccEta = (TH1D*) hAcc->ProjectionX("hAccEta",ptbin04,ptbins,"e"); TH1D* hEffEta = (TH1D*) hEff->ProjectionX("hEffEta",ptbin04,ptbins,"e"); TH1D* hMulEta = (TH1D*) hMul->ProjectionX("hMulEta",ptbin04,ptbins,"e"); TH1D* hRecEta = (TH1D*) hRec->ProjectionX("hRecEta",ptbin04,ptbins,"e"); TH1D* hFakEta = (TH1D*) hFak->ProjectionX("hFakEta",ptbin04,ptbins,"e"); TH1D* hSecEta = (TH1D*) hSec->ProjectionX("hSecEta",ptbin04,ptbins,"e"); // projected hists: pt > 2.0 GeV/c TH1D* hSimEta2 = (TH1D*) hSim->ProjectionX("hSimEta2",ptbin20,ptbins,"e"); TH1D* hAccEta2 = (TH1D*) hAcc->ProjectionX("hAccEta2",ptbin20,ptbins,"e"); TH1D* hEffEta2 = (TH1D*) hEff->ProjectionX("hEffEta2",ptbin20,ptbins,"e"); TH1D* hMulEta2 = (TH1D*) hMul->ProjectionX("hMulEta2",ptbin20,ptbins,"e"); TH1D* hRecEta2 = (TH1D*) hRec->ProjectionX("hRecEta2",ptbin20,ptbins,"e"); TH1D* hFakEta2 = (TH1D*) hFak->ProjectionX("hFakEta2",ptbin20,ptbins,"e"); TH1D* hSecEta2 = (TH1D*) hSec->ProjectionX("hSecEta2",ptbin20,ptbins,"e"); TH1D* hDumEta = new TH1D("hDumEta",";#eta",60,-2.4,2.4); hDumEta->SetMaximum(1.0); hDumEta->GetXaxis()->CenterTitle(); hDumEta->GetYaxis()->SetTitleOffset(1.8); TH1D* hDumEta2 = (TH1D*) hDumEta->Clone("hDumEta2"); hDumEta2->SetMaximum(0.1); TH1D* hDumEta3 = (TH1D*) hDumEta->Clone("hDumEta3"); hDumEta3->SetMaximum(0.00049); // projected hists: abs(eta) < 1.0 TH1D* hSimPt = (TH1D*) hSim->ProjectionY("hSimPt",etabin10m,etabin10p,"e"); TH1D* hAccPt = (TH1D*) hAcc->ProjectionY("hAccPt",etabin10m,etabin10p,"e"); TH1D* hEffPt = (TH1D*) hEff->ProjectionY("hEffPt",etabin10m,etabin10p,"e"); TH1D* hMulPt = (TH1D*) hMul->ProjectionY("hMulPt",etabin10m,etabin10p,"e"); TH1D* hRecPt = (TH1D*) hRec->ProjectionY("hRecPt",etabin10m,etabin10p,"e"); TH1D* hFakPt = (TH1D*) hFak->ProjectionY("hFakPt",etabin10m,etabin10p,"e"); TH1D* hSecPt = (TH1D*) hSec->ProjectionY("hSecPt",etabin10m,etabin10p,"e"); // projected hists: abs(eta) < 2.4 TH1D* hSimPt2 = (TH1D*) hSim->ProjectionY("hSimPt2",etabin24m,etabin24p,"e"); TH1D* hAccPt2 = (TH1D*) hAcc->ProjectionY("hAccPt2",etabin24m,etabin24p,"e"); TH1D* hEffPt2 = (TH1D*) hEff->ProjectionY("hEffPt2",etabin24m,etabin24p,"e"); TH1D* hMulPt2 = (TH1D*) hMul->ProjectionY("hMulPt2",etabin24m,etabin24p,"e"); TH1D* hRecPt2 = (TH1D*) hRec->ProjectionY("hRecPt2",etabin24m,etabin24p,"e"); TH1D* hFakPt2 = (TH1D*) hFak->ProjectionY("hFakPt2",etabin24m,etabin24p,"e"); TH1D* hSecPt2 = (TH1D*) hSec->ProjectionY("hSecPt2",etabin24m,etabin24p,"e"); TH1D* hDumPt = new TH1D("hDumPt",";p_{T} [GeV/c]",80,0.0,10.0); hDumPt->SetMaximum(1.0); hDumPt->GetXaxis()->CenterTitle(); hDumPt->GetYaxis()->SetTitleOffset(1.8); TH1D* hDumPt2 = (TH1D*) hDumPt->Clone("hDumPt2"); hDumPt2->SetMaximum(0.1); TH1D* hDumPt3 = (TH1D*) hDumPt->Clone("hDumPt3"); hDumPt3->SetMaximum(0.00049); // Acceptance TGraphAsymmErrors *gAccEta = new TGraphAsymmErrors(); gAccEta->SetName("gAccEta"); gAccEta->BayesDivide(hAccEta,hSimEta); gAccEta->SetMarkerStyle(25); gAccEta->SetLineStyle(2); gAccEta->SetLineColor(2); gAccEta->SetMarkerColor(2); TGraphAsymmErrors *gAccPt = new TGraphAsymmErrors(); gAccPt->SetName("gAccPt"); gAccPt->BayesDivide(hAccPt,hSimPt); gAccPt->SetMarkerStyle(24); gAccPt->SetLineColor(4); gAccPt->SetMarkerColor(4); TGraphAsymmErrors *gAccEta2 = new TGraphAsymmErrors(); gAccEta2->SetName("gAccEta2"); gAccEta2->BayesDivide(hAccEta2,hSimEta2); gAccEta2->SetMarkerStyle(24); gAccEta2->SetLineColor(4); gAccEta2->SetMarkerColor(4); TGraphAsymmErrors *gAccPt2 = new TGraphAsymmErrors(); gAccPt2->SetName("gAccPt2"); gAccPt2->BayesDivide(hAccPt2,hSimPt2); gAccPt2->SetMarkerStyle(25); gAccPt2->SetLineStyle(2); gAccPt2->SetLineColor(2); gAccPt2->SetMarkerColor(2); TLegend *legEta = new TLegend(0.35,0.3,0.65,0.5); legEta->SetFillColor(0); legEta->SetBorderSize(0); legEta->AddEntry(gAccEta,"p_{T} > 0.9 GeV/c","lp"); legEta->AddEntry(gAccEta2,"p_{T} > 2.0 GeV/c","lp"); TLegend *legPt = new TLegend(0.4,0.3,0.6,0.5); legPt->SetFillColor(0); legPt->SetBorderSize(0); legPt->AddEntry(gAccPt2,"|#eta| < 2.4","lp"); legPt->AddEntry(gAccPt,"|#eta| < 1.0","lp"); TCanvas *c6 = new TCanvas("c6","Acceptance Fraction",900,500); c6->Divide(2,1); hDumEtaAcc=(TH1F*) hDumEta->Clone("hDumEtaAcc"); hDumEtaAcc->GetYaxis()->SetTitle("Geometrical acceptance"); hDumPtAcc=(TH1F*) hDumPt->Clone("hDumPtAcc"); hDumPtAcc->GetYaxis()->SetTitle("Geometrical acceptance"); c6->cd(1); hDumEtaAcc->Draw(); gAccEta->Draw("pc"); gAccEta2->Draw("pc"); legEta->Draw(); c6->cd(2); hDumPtAcc->Draw(); gAccPt->Draw("pc"); gAccPt2->Draw("pc"); legPt->Draw(); // Efficiency TGraphAsymmErrors *gEffEta = new TGraphAsymmErrors(); gEffEta->SetName("gEffEta"); gEffEta->BayesDivide(hEffEta,hAccEta); gEffEta->SetMarkerStyle(25); gEffEta->SetLineStyle(2); gEffEta->SetLineColor(2); gEffEta->SetMarkerColor(2); TGraphAsymmErrors *gEffPt = new TGraphAsymmErrors(); gEffPt->SetName("gEffPt"); gEffPt->BayesDivide(hEffPt,hAccPt); gEffPt->SetMarkerStyle(24); gEffPt->SetLineColor(4); gEffPt->SetMarkerColor(4); TGraphAsymmErrors *gEffEta2 = new TGraphAsymmErrors(); gEffEta2->SetName("gEffEta2"); gEffEta2->BayesDivide(hEffEta2,hAccEta2); gEffEta2->SetMarkerStyle(24); gEffEta2->SetLineColor(4); gEffEta2->SetMarkerColor(4); TGraphAsymmErrors *gEffPt2 = new TGraphAsymmErrors(); gEffPt2->SetName("gEffPt2"); gEffPt2->BayesDivide(hEffPt2,hAccPt2); gEffPt2->SetMarkerStyle(25); gEffPt2->SetLineStyle(2); gEffPt2->SetLineColor(2); gEffPt2->SetMarkerColor(2); TCanvas *c7 = new TCanvas("c7","Efficiency Fraction",900,500); c7->Divide(2,1); hDumEtaEff=(TH1F*) hDumEta->Clone("hDumEtaEff"); hDumEtaEff->GetYaxis()->SetTitle("Algorithmic efficiency"); hDumPtEff=(TH1F*) hDumPt->Clone("hDumPtEff"); hDumPtEff->GetYaxis()->SetTitle("Algorithmic efficiency"); c7->cd(1); hDumEtaEff->Draw(); gEffEta->Draw("pc"); gEffEta2->Draw("pc"); legEta->Draw(); c7->cd(2); hDumPtEff->Draw(); gEffPt->Draw("pc"); gEffPt2->Draw("pc"); legPt->Draw(); // Multiple Reco TGraphAsymmErrors *gMulEta = new TGraphAsymmErrors(); gMulEta->SetName("gMulEta"); gMulEta->BayesDivide(hMulEta,hAccEta); gMulEta->SetMarkerStyle(25); gMulEta->SetLineStyle(2); gMulEta->SetLineColor(2); gMulEta->SetMarkerColor(2); TGraphAsymmErrors *gMulPt = new TGraphAsymmErrors(); gMulPt->SetName("gMulPt"); gMulPt->BayesDivide(hMulPt,hAccPt); gMulPt->SetMarkerStyle(24); gMulPt->SetLineColor(4); gMulPt->SetMarkerColor(4); TGraphAsymmErrors *gMulEta2 = new TGraphAsymmErrors(); gMulEta2->SetName("gMulEta2"); gMulEta2->BayesDivide(hMulEta2,hAccEta2); gMulEta2->SetMarkerStyle(24); gMulEta2->SetLineColor(4); gMulEta2->SetMarkerColor(4); TGraphAsymmErrors *gMulPt2 = new TGraphAsymmErrors(); gMulPt2->SetName("gMulPt2"); gMulPt2->BayesDivide(hMulPt2,hAccPt2); gMulPt2->SetMarkerStyle(25); gMulPt2->SetLineStyle(2); gMulPt2->SetLineColor(2); gMulPt2->SetMarkerColor(2); TCanvas *c8 = new TCanvas("c8","Multiple Fraction",900,500); c8->Divide(2,1); hDumEtaMul=(TH1F*) hDumEta3->Clone("hDumEtaMul"); hDumEtaMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction"); hDumPtMul=(TH1F*) hDumPt3->Clone("hDumPtMul"); hDumPtMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction"); legEta2 = (TLegend*) legEta->Clone(); legEta2->SetY1(0.65); legEta2->SetY2(0.85); legPt2 = (TLegend*) legPt->Clone(); legPt2->SetY1(0.65); legPt2->SetY2(0.85); c8->cd(1); hDumEtaMul->Draw(); gMulEta->Draw("pc"); gMulEta2->Draw("pc"); legEta2->Draw(); c8->cd(2); hDumPtMul->Draw(); gMulPt->Draw("pc"); gMulPt2->Draw("pc"); legPt2->Draw(); // Fakes TGraphAsymmErrors *gFakEta = new TGraphAsymmErrors(); gFakEta->SetName("gFakEta"); gFakEta->BayesDivide(hFakEta,hRecEta); gFakEta->SetMarkerStyle(25); gFakEta->SetLineStyle(2); gFakEta->SetLineColor(2); gFakEta->SetMarkerColor(2); TGraphAsymmErrors *gFakPt = new TGraphAsymmErrors(); gFakPt->SetName("gFakPt"); gFakPt->BayesDivide(hFakPt,hRecPt); gFakPt->SetMarkerStyle(24); gFakPt->SetLineColor(4); gFakPt->SetMarkerColor(4); TGraphAsymmErrors *gFakEta2 = new TGraphAsymmErrors(); gFakEta2->SetName("gFakEta2"); gFakEta2->BayesDivide(hFakEta2,hRecEta2); gFakEta2->SetMarkerStyle(24); gFakEta2->SetLineColor(4); gFakEta2->SetMarkerColor(4); TGraphAsymmErrors *gFakPt2 = new TGraphAsymmErrors(); gFakPt2->SetName("gFakPt2"); gFakPt2->BayesDivide(hFakPt2,hRecPt2); gFakPt2->SetMarkerStyle(25); gFakPt2->SetLineStyle(2); gFakPt2->SetLineColor(2); gFakPt2->SetMarkerColor(2); TCanvas *c9 = new TCanvas("c9","Fake Fraction",900,500); c9->Divide(2,1); hDumEtaFak=(TH1F*) hDumEta2->Clone("hDumEtaMul"); hDumEtaFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction"); hDumPtFak=(TH1F*) hDumPt2->Clone("hDumPtMul"); hDumPtFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction"); c9->cd(1); hDumEtaFak->Draw(); gFakEta->Draw("pc"); gFakEta2->Draw("pc"); legEta2->Draw(); c9->cd(2); hDumPtFak->Draw(); gFakPt->Draw("pc"); gFakPt2->Draw("pc"); legPt2->Draw(); // Secondaries TGraphAsymmErrors *gSecEta = new TGraphAsymmErrors(); gSecEta->SetName("gSecEta"); gSecEta->BayesDivide(hSecEta,hRecEta); gSecEta->SetMarkerStyle(25); gSecEta->SetLineStyle(2); gSecEta->SetLineColor(2); gSecEta->SetMarkerColor(2); TGraphAsymmErrors *gSecPt = new TGraphAsymmErrors(); gSecPt->SetName("gSecPt"); gSecPt->BayesDivide(hSecPt,hRecPt); gSecPt->SetMarkerStyle(24); gSecPt->SetLineColor(4); gSecPt->SetMarkerColor(4); TGraphAsymmErrors *gSecEta2 = new TGraphAsymmErrors(); gSecEta2->SetName("gSecEta2"); gSecEta2->BayesDivide(hSecEta2,hRecEta2); gSecEta2->SetMarkerStyle(24); gSecEta2->SetLineColor(4); gSecEta2->SetMarkerColor(4); TGraphAsymmErrors *gSecPt2 = new TGraphAsymmErrors(); gSecPt2->SetName("gSecPt2"); gSecPt2->BayesDivide(hSecPt2,hRecPt2); gSecPt2->SetMarkerStyle(25); gSecPt2->SetLineStyle(2); gSecPt2->SetLineColor(2); gSecPt2->SetMarkerColor(2); TCanvas *c10 = new TCanvas("c10","Secondary Fraction",900,500); c10->Divide(2,1); hDumEtaSec=(TH1F*) hDumEta2->Clone("hDumEtaMul"); hDumEtaSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction"); hDumPtSec=(TH1F*) hDumPt2->Clone("hDumPtMul"); hDumPtSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction"); c10->cd(1); hDumEtaSec->Draw(); gSecEta->Draw("pc"); gSecEta2->Draw("pc"); legEta2->Draw(); c10->cd(2); hDumPtSec->Draw(); gSecPt->Draw("pc"); gSecPt2->Draw("pc"); legPt2->Draw(); /* printCanvases(c1,"hitrk_can1",0,1); printCanvases(c2,"hitrk_can2",0,1); printCanvases(c3,"hitrk_can3",0,1); printCanvases(c4,"hitrk_can4",0,1); printCanvases(c5,"hitrk_can5",0,1); printCanvases(c6,"hitrk_can6",0,1); printCanvases(c7,"hitrk_can7",0,1); printCanvases(c8,"hitrk_can8",0,1); printCanvases(c9,"hitrk_can9",0,1); printCanvases(c10,"hitrk_can10",0,1); */ /* TFile *f = new TFile("trkEffPY8.root","RECREATE"); gAccPt->Write(); gAccPt2->Write(); gAccEta->Write(); gAccEta2->Write(); gEffPt->Write(); gEffPt2->Write(); gEffEta->Write(); gEffEta2->Write(); gMulPt->Write(); gMulPt2->Write(); gMulEta->Write(); gMulEta2->Write(); gFakPt->Write(); gFakPt2->Write(); gFakEta->Write(); gFakEta2->Write(); gSecPt->Write(); gSecPt2->Write(); gSecEta->Write(); gSecEta2->Write(); f->Close(); */ }
//void electron_master(const char* file_list="checkP10ic/electrons.list",const char* output="checkP10ic/electroncalib.root", const char* dbDate="2009-04-10 00:11:00", const char* geantfile="geant_func.root", const char* gfname="checkP10ic/mip.gains", const char* ngname="checkP10ic/electron.gains", const char* rgname="matrel.gains",const char* ffname="checkP10ic/electron.fits"){ void electron_master(const char* file_list="checkP11id/electrons.list",const char* output="checkP11id/electroncalib2.root", const char* dbDate="2009-04-10 00:11:00", const char* gfname="checkP11id/mip.gains", const char* ngname="checkP11id/electron2.gains",const char* ffname="checkP11id/electron2.fits"){ //**********************************************// //Load Libraries // //**********************************************// gROOT->Macro("LoadLogger.C"); gROOT->Macro("loadMuDst.C"); gSystem->Load("StTpcDb"); gSystem->Load("StDaqLib"); gSystem->Load("StDetectorDbMaker"); gSystem->Load("St_db_Maker"); gSystem->Load("StDbUtilities"); gSystem->Load("StEmcRawMaker"); gSystem->Load("StMcEvent"); gSystem->Load("StMcEventMaker");//*** gSystem->Load("StEmcSimulatorMaker");//*** gSystem->Load("StEmcADCtoEMaker"); gSystem->Load("StEpcMaker"); gSystem->Load("StDbBroker"); gSystem->Load("StEEmcUtil"); gSystem->Load("StAssociationMaker"); gSystem->Load("StEmcTriggerMaker"); gSystem->Load("StTriggerUtilities"); gSystem->Load("StEmcOfflineCalibrationMaker"); cout<<"input filelist: "<<file_list<<endl; cout<<"output: "<<output<<endl; cout<<"db Date: "<<dbDate<<endl; //**********************************************// //Initialize Stuff // //**********************************************// CalibrationHelperFunctions *helper = new CalibrationHelperFunctions(); StBemcTablesWriter *bemctables = new StBemcTablesWriter(); bemctables->loadTables(dbDate,"sim"); StEmcDecoder* decoder = bemctables->getDecoder(); //chain all input files together char file[300]; TChain* tree = new TChain("skimTree"); ifstream filelist(file_list); while(1){ filelist >> file; if(!filelist.good()) break; cout<<file<<endl; tree->Add(file); } const int ntowers = 4800; const int nrings = 40; const int ncrates = 30; float gains[ntowers]; int status[ntowers]; float peaks[ntowers]; float peakerr[ntowers]; float gainerr[ntowers]; ifstream gainfile(gfname); while(1){ int id,stat; float peak,err,gain,eta,theta; gainfile >> id >> peak >> err >> stat; if(!gainfile.good())break; eta = helper->getEta(id); theta = helper->getTheta(id); gain = 0.264*(1+0.056*eta*eta)/(sin(theta)*peak); peaks[id-1] = peak; gains[id-1] = gain; if(status[id-1] != 1 || stat != 1) status[id-1] = stat; peakerr[id-1] = err; //cout<<id<<" "<<gain; } TFile* geant_file = new TFile("geant_fits.root","READ"); TF1* geant_fits[20]; for(int i = 0; i < 20; i++){ TString fname = "fit_"; fname += i; geant_fits[i] = (TF1*)geant_file->Get(fname); } TFile outfile(output,"RECREATE"); TH1 *crate_histo[ncrates]; TF1 *crate_fit[ncrates]; TH1 *electron_histo[ntowers]; TF1 *fit[ntowers]; TH1 *prs_histo[ntowers]; TH1 *ring_histo[nrings]; TH1 *ring2_histo[nrings/2]; TF1 *ring2fit[nrings/2]; TH1 *etacrate_histo[ncrates*20]; TH1 *etacrate_histo_p[ncrates*20]; TH1 *etacrate_histo_n[ncrates*20]; TH1 *bghisto[21]; TH2F* drvsep = new TH2F("drvsep","drvsep",60,0,3.0,100,0.0,0.03); TF1 *ringfit[nrings]; TH2F* ring_pve[nrings]; TH2F* jan_pve[6]; float eta; int etaindex; TH1F* ringprec = new TH1F("ringprec","",40,-1.0,1.0); TH1F* ringprec2 = new TH1F("ringprec2","",40,-1.0,1.0); ringprec->SetYTitle("E/p"); ringprec->SetXTitle("#eta"); ringprec2->SetYTitle("E/p"); ringprec2->SetXTitle("#eta"); TH1F* ring2prec = new TH1F("ring2prec","",nrings/2,-1.0,1.0); TH1F* ring2prec2 = new TH1F("ring2prec2","",nrings/2,-1.0,1.0); ring2prec->SetYTitle("E/p"); ring2prec->SetXTitle("#eta"); ring2prec2->SetYTitle("E/p"); ring2prec2->SetXTitle("#eta"); double ew[nrings]; TH2F* trgcheck = new TH2F("trgcheck","trgcheck",2,-0.5,1.5,3,-0.5,2.5); TH1F* crateprec = new TH1F("crateprec","",30,0.5,30.5); crateprec->SetXTitle("Crate"); crateprec->SetYTitle("E/p"); TH2F *energyleak = new TH2F("energyleak","",20,0.0,0.03,20,0.0,1.0); TH2F *findbg = new TH2F("findbg","",20,0.0,0.03,30,0.0,5.0); TH1F *energymean = new TH1F("energymean","",20,0.0,0.03); TH1F *leakmean = new TH1F("leakmean","",20,0.0,0.03); energyleak->SetXTitle("#DeltaR"); energyleak->SetYTitle("leaked energy / total energy"); findbg->SetXTitle("#DeltaR"); findbg->SetYTitle("Total energy / track momentum"); TH2F *tevsp = new TH2F("tevsp","",50,0.0,20.0,50,0.0,30.0); TH1F *pmean = new TH1F("pmean","",20,0.0,15.0); tevsp->SetXTitle("track momentum (GeV)"); tevsp->SetYTitle("Total Energy (GeV)"); TH2F *tevspcent = new TH2F("tevspcent","",20,0.0,15.0,20,0.0,15.0); tevspcent->SetXTitle("track momentum (GeV)"); tevspcent->SetYTitle("Energy in central tower (GeV)"); TH1F *cmean = new TH1F("cmain","",20,0.0,15.0); TH2F *sistertracks = new TH2F("sistertracks","",20,0.0,8.0,20,0.0,8.0); sistertracks->SetXTitle("Track momentum (GeV)"); sistertracks->SetYTitle("Neighbor momentum (GeV)"); TH2F* dEdxvsp = new TH2F("dEdxvsp","",100,0.15,1.3,100,-5.7,-5.); dEdxvsp->SetXTitle("Log(p)"); dEdxvsp->SetYTitle("Log(dE/dx)"); TH2F* dEdxvsp_east = new TH2F("dEdxvsp_east","",100,0.15,1.3,100,-5.7,-5.0); dEdxvsp_east->SetXTitle("Log(p)"); dEdxvsp_east->SetYTitle("Log(dE/dx)"); TH2F* dEdxvsp_west = new TH2F("dEdxvsp_west","",100,0.15,1.3,100,-5.7,-5.0); dEdxvsp_west->SetXTitle("Log(p)"); dEdxvsp_west->SetYTitle("Log(dE/dx)"); TH2F* energyleak2 = new TH2F("energyleak2","",20,0.0,0.03,20,0.0,1.0); TH1F* energymean2 = new TH1F("energymean2","",20,0.0,0.03); TH1F* towermult = new TH1F("towermult","",9,0.0,9.0); energyleak2->SetXTitle("#DeltaR"); energyleak2->SetYTitle("leaked energy/total energy"); towermult->SetXTitle("Neighbors with energy"); TH2F* multvsp = new TH2F("multvsp","",20,0.0,20.0,9,0.0,9.0); multvsp->SetXTitle("Track momentum (GeV)"); multvsp->SetYTitle("Neighbors with energy"); TH1F* multmean = new TH1F("multmean","",20,0.0,20.0); TH2F* tep3 = new TH2F("tep3","2 < p < 3",20,0.0,0.03,20,0.0,4.0); TH2F* tep5 = new TH2F("tep5","3 < p < 5",20,0.0,0.03,20,0.0,4.0); TH2F* tep10 = new TH2F("tep10","5 < p < 10",20,0.0,0.03,20,0.0,4.0); tep3->SetXTitle("DeltaR"); tep3->SetYTitle("Total energy / track momentum"); tep5->SetXTitle("DeltaR"); tep5->SetYTitle("Total energy / track momentum"); tep10->SetXTitle("DeltaR"); tep10->SetYTitle("Total energy / track momentum"); TH1F* tep3mean = new TH1F("tep3mean","",20,0,0.03); TH1F* tep5mean = new TH1F("tep5mean","",20,0,0.03); TH1F* tep10mean = new TH1F("tep10mean","",20,0,0.03); TH1F* multen = new TH1F("multen","",40,0.0,1.0); multen->SetXTitle("Energy in neighbor towers (GeV)"); TH1F* east_histo = new TH1F("east_histo","Electron E/p in East",40,0.0,2.0); TH1F* west_histo = new TH1F("west_histo","Electron E/p in West",40,0.0,2.0); TH1F* all_histo = new TH1F("all_histo","Electron E/p",40,0.0,2.0); TH1F* notrg = new TH1F("notrg","Electron E/p",40,0.0,2.0); TH2F* pvsep = new TH2F("pvsep","Electron p vs E/p",120,0,3.0,20,0,20.0); pvsep->SetYTitle("p (Gev)"); pvsep->SetXTitle("E/p"); TH2F* pvsep0 = new TH2F("pvsep0","Electron p vs E/p",120,0,3.0,20,0,20.0); pvsep0->SetYTitle("p (Gev)"); pvsep0->SetXTitle("E/p"); TH2F* evsep = new TH2F("evsep","Electron E vs E/p",120,0,3.0,20,0,20.0); evsep->SetYTitle("E (GeV)"); evsep->SetXTitle("E/p"); TH1F* bsmde = new TH1F("bsmde","BSMDE ADC TOT",1500,0,1500); TH1F* bsmdp = new TH1F("bsmdp","BSMDP ADC TOT",1500,0,1500); TH1F* bsmde_central = new TH1F("bsmde_central","BSMDE ADC TOT",100,0,1500); TH1F* bsmde_mid = new TH1F("bsmde_mid","BSMDE ADC TOT",100,0,1500); TH1F* bsmde_outer = new TH1F("bsmde_outer","BSMDE ADC TOT",100,0,1500); TH2F* bsmdep = new TH2F("bsmdep","BSMDE v BSMDP",100,0,1500,100,0,1500); TH2F* bsmdevp = new TH2F("bsmdevp","BSMDE v p",100,1.0,15.0,100,0,1500); TH2F* bsmdpvp = new TH2F("bsmdpvp","BSMDP v p",100,1.0,15.0,100,0,1500); TH2F* bsmdevep = new TH2F("bsmdevep","BSMDE v E/p",100,0.0,2.0,100,0,1500); TH2F* bsmdpvep = new TH2F("bsmdpvep","BSMDP v E/p",100,0.0,2.0,100,0,1500); TH2F* bsmdeve = new TH2F("bsmdeve","BSMDE v E",100,1.0,30.0,100,0,1500); TH2F* bsmdpve = new TH2F("bsmdpve","BSMDP v E",100,1.0,30.0,100,0,1500); TH1F* httrig = new TH1F("httrig","HT Trigger",5,-0.5,4.5); TH1F* pplus = new TH1F("pplus","e+ p",100,0,20); TH1F* pminus = new TH1F("pminus","e- p",100,0,20); TH1F* posep = new TH1F("posep","e+ E/p",60,0,3.0); TH1F* negep = new TH1F("negep","e- E/p",60,0,3.0); //create the tower histograms char name1[100]; for(int i = 0; i < ncrates; i++){ for(int j = 0; j < 20; j++){ TString ecname,ecnamep,ecnamen; ecname += "etacrate_"; int cr = i+1; int et = j; ecname += cr; ecname += "_"; ecname += et; ecnamep += ecname; ecnamen += ecname; ecnamep.ReplaceAll("te_","te_p_"); ecnamen.ReplaceAll("te_","te_n_"); etacrate_histo[i*20+j] = new TH1F(ecname.Data(),ecname.Data(),60,0.0,3.0); etacrate_histo_p[i*20+j] = new TH1F(ecnamep.Data(),ecnamep.Data(),60,0.0,3.0); etacrate_histo_n[i*20+j] = new TH1F(ecnamen.Data(),ecnamen.Data(),60,0.0,3.0); } } for(int i=0; i<ntowers; i++){ char nameeh[100]; sprintf(nameeh,"electron_histo_%i",i+1); electron_histo[i] = new TH1D(nameeh,"",60,0.,3.0); electron_histo[i]->SetXTitle("E/p"); //sprintf(name1,"prs_histo_%i",i+1); //prs_histo[i] = new TH1D(name1,"",60,0.,500.); //prs_histo[i]->SetXTitle("ADC"); } for(int i = 0; i < 21; i++){ TString namebg; namebg += "bg_"; namebg += i+25; bghisto[i] = new TH1F(namebg.Data(),namebg.Data(),60,0,3.0); } for(int i = 0; i < ncrates; i++){ char name[100]; char title[100]; sprintf(name,"crate_%i",i+1); sprintf(title,"E/p for Crate %i",i+1); crate_histo[i] = new TH1F(name,title,60,0.,3.0); crate_histo[i]->SetXTitle("E/p"); } for(int i = 0; i < nrings/2; i++){ char name[100]; sprintf(name,"ring2_histo_%i",i); ring2_histo[i] = new TH1F(name,"",60,0.,3.0); ring2_histo[i]->SetXTitle("E/p"); } char name2[100]; for(int i=0; i<nrings;i++) { sprintf(name2,"ring_histo_%i",i); //ring_histo[i] = new TH1D(name2,"",30,0.,140.0); //ring_histo[i]->SetXTitle("ADC / GeV Sin(#theta)"); ring_histo[i] = new TH1D(name2,"",60,0.,3.0); ring_histo[i]->SetXTitle("E/p"); char namerpve[100]; sprintf(namerpve,"ring_pve_%i",i); ring_pve[i] = new TH2F(namerpve,"",20,0,20.0,20,0,20.0); ring_pve[i]->SetXTitle("E (GeV)"); ring_pve[i]->SetYTitle("p (GeV)"); } for(int i = 0; i < 6; i++){ char jname[100]; sprintf(jname,"jan_pve_%i",i); jan_pve[i] = new TH2F(jname,"",120,0,3.0,20,0,20.0); jan_pve[i]->SetXTitle("E/p"); jan_pve[i]->SetYTitle("p (GeV)"); } //global graphics functions gStyle->SetOptStat("oue"); gStyle->SetOptFit(111); gStyle->SetCanvasColor(10); gStyle->SetCanvasBorderMode(0); gStyle->SetOptTitle(0); gStyle->SetPalette(1); gStyle->SetStatColor(0); StEmcOfflineCalibrationTrack* track = new StEmcOfflineCalibrationTrack(); StEmcOfflineCalibrationCluster* cluster = new StEmcOfflineCalibrationCluster(); tree->SetBranchAddress("clusters",&cluster); //**********************************************// //Loop Over Tracks, Fill Histograms // //**********************************************// int nentries = tree->GetEntries(); cout<<nentries<<endl; int ngoodhit = 0; int nplt10 = 0; int nnosis = 0; int nfinal = 0; int nbsmdgood = 0; int nnottrig = 0; int nfidu = 0; int nenterexit = 0; for(int j=0; j<nentries; j++){ tree->GetEntry(j); track = &(cluster->centralTrack); TClonesArray *tracks = cluster->tracks; if(j % 500000 == 0) cout<<"reading "<<j<<" of "<<nentries<<endl; httrig->Fill((float)track->htTrig); if(track->charge > 0)pplus->Fill(track->p); if(track->charge < 0)pminus->Fill(track->p); int bsmdeadctot = 0; int bsmdpadctot = 0; for(int i = 0; i < 11; i++){ if(track->smde_adc[i] > track->smde_pedestal[i])bsmdeadctot += track->smde_adc[i] - track->smde_pedestal[i]; if(track->smdp_adc[i] > track->smdp_pedestal[i])bsmdpadctot += track->smdp_adc[i] - track->smdp_pedestal[i]; } double dR = TMath::Sqrt(track->deta*track->deta + track->dphi*track->dphi); double scaled_adc = (track->tower_adc[0] - track->tower_pedestal[0]) / track->p; int index = track->tower_id[0]; //figure out eta and etaindex eta = helper->getEta(index); if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta; etaindex = ((TMath::Nint(eta * 1000.0) + 25)/50 + 19); int geantetaindex = ((TMath::Nint(fabs(eta) * 1000.0) + 25)/50 - 1); double geant_scale = geant_fits[geantetaindex]->Eval(dR); scaled_adc /= geant_scale; //double geant_scale = geant_fit->Eval(dR); //scaled_adc *= geant_scale; //cout<<scaled_adc<<endl; //now rescale dR for last ring to make cuts work if(geantetaindex == 19)dR *= 0.025/0.017; //double tgain = bemctables->calib(1,track->tower_id[0])*gains[index-1]; double tgain = gains[index-1]; if((track->tower_adc[0] - track->tower_pedestal[0]) < 2.5 * track->tower_pedestal_rms[0])continue; ngoodhit++; dEdxvsp->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); if(track->tower_id[0] <= 2400)dEdxvsp_west->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); if(track->tower_id[0] > 2400)dEdxvsp_east->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); trgcheck->Fill(track->nonhtTrig,track->htTrig); if(track->tower_id[0] != track->tower_id_exit)continue; nenterexit++; if(status[index-1]!=1)continue; pvsep0->Fill(scaled_adc*tgain,track->p); if(track->p > 10)continue; nplt10++; //if(track->p < 1.5)continue; //if(track->p < 3.0)continue; if(track->htTrig == 2 && track->nonhtTrig == 0)continue; nnottrig++; //change the fiducial cut to a square with diagonal = 0.06 in deta, dphi space float squarefid = 0.02;//0.03/TMath::Sqrt(2.0); //if(TMath::Abs(track->deta) > squarefid || TMath::Abs(track->dphi) > squarefid)continue; //calculate geant scaled, pedestal subtracted adc //if(dR > 0.0125)continue; int numsis = tracks->GetEntries(); float totalbtow = 0; float maxEt = 0; int maxId = -1; for(int i = 0; i < 9; i++){ if(track->tower_adc[i] - track->tower_pedestal[i] < 0)continue; float theta = helper->getTheta(track->tower_id[i]); float nextEt = (track->tower_adc[i] - track->tower_pedestal[i]) * bemctables->calib(1,track->tower_id[i])*sin(theta); totalbtow += nextEt; if(nextEt > maxEt){ maxEt = nextEt; maxId = i; } } if(track->dEdx > 3.5e-6 && track->dEdx <5.0e-6 && numsis ==0 &&maxId == 0)drvsep->Fill(scaled_adc*tgain,dR); if(dR > 0.02)continue; nfidu++; //if(track->p > 6.0)continue; //if(track->p > 15)continue; //cout<<track->dEdx<<endl; //if(track->dEdx*1000000 > 4.5 || track->dEdx*1000000 < 3.5)continue; //cout<<track->htTrig<<endl; for(int i = 0; i < 21; i++){ if(numsis > 0)break; if(maxId != 0)break; if(track->dEdx*1e7 > 25 + i && track->dEdx*1e7 < 26+i)bghisto[i]->Fill(scaled_adc*tgain); } //if(track->dEdx < 3.5e-6 || track->dEdx > 5.0e-6)continue; if(track->dEdx < 3.5e-6 || track->dEdx > 4.5e-6)continue; //if((bsmdeadctot > -1 && bsmdeadctot < 50) && (bsmdpadctot < 50 && bsmdpadctot > -1))continue; nbsmdgood++; //if(bsmdeadctot < 500) continue; //if(bsmdeadctot < 84.*track->p)continue; //if(bsmdeadctot > 200.*track->p + 1500)continue; //if(bsmdpadctot < 800)continue; if(numsis > 0)continue; nnosis++; if(maxId != 0) continue; nfinal++; if(track->htTrig!=2)notrg->Fill(scaled_adc*tgain); //if(!track->nonhtTrig)continue; //if(track->nHits < 25)continue; //if(status[index-1]==1)ring_histo[etaindex]->Fill(scaled_adc*gains[index-1]); //scaled_adc = totalbtow/track->p; //tgain = 1.0; float phi = helper->getPhi(index); int crate,sequence; decoder->GetCrateFromTowerId(index,crate,sequence); etacrate_histo[(crate-1)*20+geantetaindex]->Fill(scaled_adc*tgain); if(track->charge > 0)etacrate_histo_p[(crate-1)*20+geantetaindex]->Fill(scaled_adc*tgain); if(track->charge < 0)etacrate_histo_n[(crate-1)*20+geantetaindex]->Fill(scaled_adc*tgain); electron_histo[index-1]->Fill(scaled_adc*tgain); ring_histo[etaindex]->Fill(scaled_adc*tgain); if(etaindex == 0 || etaindex == 39){ //cout<<etaindex<<" "<<tgain<<" "<<track->p<<" "<<scaled_adc*tgain*track->p<<" "<<scaled_adc*tgain<<endl; } //cout<<index<<" "<<gains[index-1]<<" "<<scaled_adc*track->p<<" "<<track->p<<" "<<status[index-1]<<endl; ring_pve[etaindex]->Fill(scaled_adc*tgain*track->p,track->p); dEdxvsp->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); float abseta = TMath::Abs(eta); if(abseta > 0.95){ jan_pve[5]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.9){ jan_pve[4]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.6){ jan_pve[3]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.3){ jan_pve[2]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.05){ jan_pve[1]->Fill(scaled_adc*tgain,track->p); }else{ jan_pve[0]->Fill(scaled_adc*tgain,track->p); } all_histo->Fill(scaled_adc*tgain); pvsep->Fill(scaled_adc*tgain,track->p); evsep->Fill(scaled_adc*tgain,track->p*scaled_adc*tgain); tevsp->Fill(track->p,scaled_adc*tgain*track->p); if(track->charge > 0)posep->Fill(scaled_adc*tgain); if(track->charge < 0)negep->Fill(scaled_adc*tgain); //if(scaled_adc*tgain < 0.7 || scaled_adc*tgain > 5.0)continue; bsmde->Fill(bsmdeadctot); bsmdp->Fill(bsmdpadctot); bsmdep->Fill(bsmdeadctot,bsmdpadctot); if(abseta > 0.6){ bsmde_outer->Fill(bsmdeadctot); }else if(abseta > 0.3){ bsmde_mid->Fill(bsmdeadctot); }else{ bsmde_central->Fill(bsmdeadctot); } bsmdevp->Fill(track->p,bsmdeadctot); bsmdpvp->Fill(track->p,bsmdpadctot); bsmdevep->Fill(scaled_adc*tgain,bsmdeadctot); bsmdpvep->Fill(scaled_adc*tgain,bsmdpadctot); bsmdeve->Fill(scaled_adc*tgain*track->p,bsmdeadctot); bsmdpve->Fill(scaled_adc*tgain*track->p,bsmdpadctot); if(dR > 0.015)continue; if(track->tower_id[0] <= 2400){ west_histo->Fill(scaled_adc*tgain); } if(track->tower_id[0] > 2400){ east_histo->Fill(scaled_adc*tgain); } } cout<<"processed electron tree"<<endl; cout<<"ngoodhit: "<<ngoodhit<<endl; cout<<"nenterexit: "<<nenterexit<<endl; cout<<"n not trig: "<<nnottrig<<endl; cout<<"n p < 10: "<<nplt10<<endl; cout<<"n in fidu: "<<nfidu<<endl; cout<<"nbsmdhit: "<<nbsmdgood<<endl; cout<<"n no sis: "<<nnosis<<endl; cout<<"n final: "<<nfinal<<endl; //double ew[21]; for(int h=0;h<21;h++){ TH1D* projection = energyleak->ProjectionY("projection",h,h); float mean = projection->GetMean(); energymean->SetBinContent(h,mean); TH1D* projection1 = findbg->ProjectionY("projection1",h,h); float mean1 = projection1->GetMean(); leakmean->SetBinContent(h,mean1); TH1D* projection2 = tevsp->ProjectionY("projection2",h,h); float mean2 = projection2->GetMean(); pmean->SetBinContent(h,mean2); //ew[h] = projection2->GetRMS(); TH1D* projection3 = tevspcent->ProjectionY("projection3",h,h); float mean3 = projection3->GetMean(); cmean->SetBinContent(h,mean3); TH1D* projection4 = energyleak2->ProjectionY("projection4",h,h); float mean4 = projection4->GetMean(); energymean2->SetBinContent(h,mean4); TH1D* projection5 = multvsp->ProjectionY("projection5",h,h); float mean5 = projection5->GetMean(); multmean->SetBinContent(h,mean5); TH1D* projection6 = tep3->ProjectionY("projection6",h,h); float mean6 = projection6->GetMean(); tep3mean->SetBinContent(h,mean6); TH1D* projection7 = tep3->ProjectionY("projection7",h,h); float mean7 = projection7->GetMean(); tep5mean->SetBinContent(h,mean7); TH1D* projection8 = tep3->ProjectionY("projection8",h,h); float mean8 = projection8->GetMean(); tep10mean->SetBinContent(h,mean8); } TF1* fitleak = new TF1("fitleak","[0]",0,0.03); fitleak->SetLineWidth(0.1); leakmean->Fit(fitleak,"rq"); //**********************************************// //Fit Tower Histograms // //**********************************************// /* for(int i=0; i<ntowers; i++){ if(i%600 == 0) cout<<"fitting tower "<<i+1<<" of "<<ntowers<<endl; sprintf(name,"fit_%i",i+1); //this fit is for the electron tree fit[i] = new TF1(name,fit_function,0.,140.,6); fit[i]->SetParameter(1,65.); fit[i]->SetParameter(2,10.); fit[i]->SetParameter(3,10.); //relative height of peak to bg fit[i]->SetParameter(4,10.); fit[i]->SetParameter(5,3.); fit[i]->SetParNames("Constant","Mean","Sigma","Peak Ratio","Bg Mean","Bg Sigma"); fit[i]->SetLineColor(kGreen); fit[i]->SetLineWidth(0.6); electron_histo[i]->Fit(fit[i],"rq"); } */ //**********************************************// //Fit Ring Histograms // //**********************************************// for(int i=0; i<nrings; i++){ //cout<<"fitting ring "<<i+1<<" of "<<nrings<<endl; sprintf(name,"ring_fit_%i",i); /* ringfit[i] = new TF1(name,fit_function,0.,140.,6); ringfit[i]->SetParameter(1,1.); ringfit[i]->SetParameter(2,0.2); ringfit[i]->SetParameter(3,1.5); //relative height of peak to bg ringfit[i]->SetParameter(4,0.15); ringfit[i]->SetParameter(5,0.8); ringfit[i]->SetParNames("Constant","Mean","Sigma","Peak Ratio","Bg Mean","Bg Sigma"); */ //TF1* ffff = new TF1("ffff","expo(0) + gaus(2)",0.4,1.7); ring_histo[i]->Sumw2(); //ring_histo[i]->Rebin(3); ringfit[i] = new TF1(name,"pol1(0) + gaus(2)"); ringfit[i]->SetParLimits(0,0,10.0*ring_histo[i]->GetBinContent(1)); ringfit[i]->SetParLimits(1,-10000,0); ringfit[i]->SetParLimits(2,0,10.0*ring_histo[i]->GetMaximum()); ringfit[i]->SetParLimits(3,0,10); ringfit[i]->SetParameter(0,ring_histo[i]->GetBinContent(1)); ringfit[i]->SetParameter(1,-ring_histo[i]->GetBinContent(1)/6.0); ringfit[i]->SetParameter(2,ring_histo[i]->GetMaximum()); ringfit[i]->SetParameter(3,0.95); ringfit[i]->SetParameter(4,0.15); ringfit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); /* ringfit[i] = new TF1(name,fit_function2,0.1,2.5,8); ringfit[i]->SetParameter(1,1.); ringfit[i]->SetParameter(2,0.2); ringfit[i]->SetParameter(3,1.5); //relative height of peak to bg ringfit[i]->SetParameter(4,0.25); ringfit[i]->SetParameter(5,0.15); ringfit[i]->SetParameter(7,0.8); ringfit[i]->SetParNames("Constant","Mean","Sigma","Peak Ratio","Bg Mean","Bg Sigma","Bg2 constant","Bg2 decay"); */ ringfit[i]->SetLineColor(kBlue); ringfit[i]->SetLineWidth(0.6); ring_histo[i]->Fit(ringfit[i],"rql","",0.2,1.7); ringprec->SetBinContent(i+1,(ringfit[i]->GetParameter(3))); ringprec->SetBinError(i+1,ringfit[i]->GetParameter(4)); ringprec2->SetBinContent(i+1,(ringfit[i]->GetParameter(3))); ringprec2->SetBinError(i+1,ringfit[i]->GetParError(3)); //ew[i] = 4066/(60*(fit[i]->GetParameter(2))*(fit[i]->GetParameter(2))); float mean = ringfit[i]->GetParameter(3); float merr = ringfit[i]->GetParError(3); cout<<"ring "<<i<<" "<<mean<<" "<<merr/mean<<" "<<ring_histo[i]->GetEntries()<<endl; } for(int i = 0; i < nrings/2; i++){ ring2_histo[i]->Add(ring_histo[2*i]); ring2_histo[i]->Add(ring_histo[2*i+1]); sprintf(name,"ring2_fit_%i",i); ring2fit[i] = new TF1(name,"pol1(0) + gaus(2)",0.3,1.7); ring2_histo[i]->Rebin(3); ring2fit[i]->SetParLimits(0,0,10.0*ring2_histo[i]->GetBinContent(1)); ring2fit[i]->SetParLimits(1,-10000,0); ring2fit[i]->SetParLimits(2,0,10.0*ring2_histo[i]->GetMaximum()); ring2fit[i]->SetParLimits(3,0,10); ring2fit[i]->SetParLimits(4,0.17,0.175); ring2fit[i]->SetParameter(0,ring2_histo[i]->GetBinContent(1)); ring2fit[i]->SetParameter(1,-ring2_histo[i]->GetBinContent(1)/6.0); ring2fit[i]->SetParameter(2,ring2_histo[i]->GetMaximum()); ring2fit[i]->SetParameter(3,0.95); ring2fit[i]->SetParameter(4,0.11245); ring2fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); ring2_histo[i]->Fit(ring2fit[i],"rql","",0.3,1.7); ring2prec->SetBinContent(i+1,(ring2fit[i]->GetParameter(3))); ring2prec->SetBinError(i+1,ring2fit[i]->GetParameter(4)); ring2prec2->SetBinContent(i+1,(ring2fit[i]->GetParameter(3))); ring2prec2->SetBinError(i+1,ring2fit[i]->GetParError(3)); cout<<"ring2 "<<i<<" "<<ring2fit[i]->GetParameter(3)<<" "<<ring2fit[i]->GetParError(3)<<endl; } for(int i = 0; i < ntowers; i++){ char name[100]; sprintf(name,"electron_fit_%i",i+1); /* fit[i] = new TF1(name,"pol1(0)+gaus(2)"); fit[i]->SetParLimits(0,0,10.0*electron_histo[i]->GetBinContent(1)); fit[i]->SetParLimits(1,-10000,0); fit[i]->SetParLimits(2,0,10.0*electron_histo[i]->GetMaximum()); fit[i]->SetParLimits(3,0,10); fit[i]->SetParameter(0,electron_histo[i]->GetBinContent(1)); fit[i]->SetParameter(1,-electron_histo[i]->GetBinContent(1)/6.0); fit[i]->SetParameter(2,electron_histo[i]->GetMaximum()); fit[i]->SetParameter(3,0.95); fit[i]->SetParameter(4,0.15); fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); */ fit[i] = new TF1(name,"pol0(0)+gaus(1)"); fit[i]->SetParLimits(0,0,10.0*electron_histo[i]->GetBinContent(1)); fit[i]->SetParLimits(1,0,10.0*electron_histo[i]->GetMaximum()); fit[i]->SetParLimits(2,0,10); fit[i]->SetParameter(0,electron_histo[i]->GetBinContent(1)); fit[i]->SetParameter(1,electron_histo[i]->GetMaximum()); fit[i]->SetParameter(2,0.95); fit[i]->SetParameter(3,0.15); fit[i]->SetParNames("constant1","constant2","Mean","Sigma"); electron_histo[i]->Fit(fit[i],"rql","",0.3,1.7); } ofstream fitfile(ffname); TF1* etacrate_fit[ncrates*20]; for(int ii = 0; ii < ncrates; ii++){ for(int j = 0; j < 20; j++){ TString ecname; ecname += "fit"; int cr = ii+1; int et = j; int i = ii*20 + j; //ecname += cr; //ecname += "_"; //ecname += et; etacrate_fit[i] = new TF1(ecname.Data(),"pol1(0) + gaus(2)",0.25,1.6); //etacrate_fit[i]->SetParLimits(0,0,10.0*etacrate_histo[i]->GetBinContent(1)); etacrate_histo[i]->Rebin(); etacrate_fit[i]->SetParLimits(1,-10000,0); etacrate_fit[i]->SetParLimits(2,0,10.0*etacrate_histo[i]->GetMaximum()); etacrate_fit[i]->SetParLimits(3,0,10); etacrate_fit[i]->SetParameter(0,etacrate_histo[i]->GetBinContent(2)); etacrate_fit[i]->SetParameter(1,-etacrate_histo[i]->GetBinContent(2)/3.0); etacrate_fit[i]->SetParameter(2,etacrate_histo[i]->GetMaximum()); etacrate_fit[i]->SetParameter(3,0.96134); etacrate_fit[i]->SetParameter(4,0.141123); etacrate_fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); etacrate_histo[i]->Fit(etacrate_fit[i],"rql","",0.25,1.5); etacrate_histo_p[i]->Fit(etacrate_fit[i],"rql","",0.25,1.5); etacrate_histo_n[i]->Fit(etacrate_fit[i],"rql","",0.25,1.5); fitfile << i << " " << etacrate_histo[i]->GetFunction("fit")->GetParameter(3) << " " << etacrate_histo_p[i]->GetFunction("fit")->GetParameter(3) << " " << etacrate_histo_n[i]->GetFunction("fit")->GetParameter(3) << endl; } } ofstream newgain(ngname); float gains2[ntowers]; float gerr2[ntowers]; for(int i = 0; i < ntowers; i++){ float eta = helper->getEta(i+1); int crate,sequence; decoder->GetCrateFromTowerId(i+1,crate,sequence); int geantetaindex = ((TMath::Nint(fabs(eta) * 1000.0) + 25)/50 - 1); TString ecname; ecname += "fit"; //int cr = ii+1; //int et = j; //int i = ii*20 + j; //ecname += crate; //ecname += "_"; //ecname += geantetaindex; if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta; int etaindex = ((TMath::Nint(eta * 1000.0) + 25)/50 + 19); //float adjust = ring2fit[(int)etaindex/2]->GetParameter(3); //cout<<etaindex<<" "<<(int)etaindex/2<<" "<<adjust<<endl; //float adjust = fit[i]->GetParameter(3); float ng = 0; float ne = 0; if(status[i] == 1){ //float og = bemctables->calib(1,i+1)*gains[i]; float og = gains[i]; //float aerr = ring2fit[(int)etaindex/2]->GetParError(3); float adjust = etacrate_histo[(crate-1)*20+geantetaindex]->GetFunction("fit")->GetParameter(3); float aerr = etacrate_histo[(crate-1)*20+geantetaindex]->GetFunction("fit")->GetParError(3); if(geantetaindex == 19){ adjust = ringfit[etaindex]->GetParameter(3); aerr = ringfit[etaindex]->GetParError(3); } ng = og/adjust; float gerr = peakerr[i]*gains[i]/peaks[i]; ne = sqrt(pow(og*aerr/(adjust*adjust),2) + pow(gerr/adjust,2)); } newgain << i+1 << " " << ng << " " << ne << " " << status[i] << endl; gains2[i] = ng; gerr2[i] = ne; } newgain.close(); /////////////////////////////////////// //Using new gains regenerate by crate// /////////////////////////////////////// /* for(int j=0; j<nentries; j++){ tree->GetEntry(j); track = &(cluster->centralTrack); TClonesArray *tracks = cluster->tracks; int bsmdeadctot = 0; int bsmdpadctot = 0; for(int i = 0; i < 11; i++){ if(track->smde_adc[i] > track->smde_pedestal[i])bsmdeadctot += track->smde_adc[i] - track->smde_pedestal[i]; if(track->smdp_adc[i] > track->smdp_pedestal[i])bsmdpadctot += track->smdp_adc[i] - track->smdp_pedestal[i]; } double dR = TMath::Sqrt(track->deta*track->deta + track->dphi*track->dphi); double scaled_adc = (track->tower_adc[0] - track->tower_pedestal[0]) / track->p; double geant_scale = geant_fit->Eval(dR); scaled_adc *= geant_scale; //cout<<scaled_adc<<endl; int index = track->tower_id[0]; //figure out eta and etaindex eta = helper->getEta(index); if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta; etaindex = ((TMath::Nint(eta * 1000.0) + 25)/50 + 19); double tgain = bemctables->calib(1,track->tower_id[0])*gains[index-1]*gains2[index-1]; //double tgain = gains[index-1]; if((track->tower_adc[0] - track->tower_pedestal[0]) < 2.5 * track->tower_pedestal_rms[0])continue; if(track->tower_id[0] != track->tower_id_exit)continue; if(track->htTrig == 2)continue; if(track->p > 6)continue; if(dR > 0.025)continue; if(track->dEdx < 3.4e-6)continue; if((bsmdeadctot > -1 && bsmdeadctot < 50) && (bsmdpadctot < 50 && bsmdpadctot > -1))continue; int numsis = tracks->GetEntries(); if(numsis > 0)continue; float totalbtow = 0; float maxEt = 0; int maxId = -1; for(int i = 0; i < 9; i++){ if(track->tower_adc[i] - track->tower_pedestal[i] < 0)continue; float theta = helper->getTheta(track->tower_id[i]); float nextEt = (track->tower_adc[i] - track->tower_pedestal[i]) * bemctables->calib(1,track->tower_id[i])*sin(theta); totalbtow += nextEt; if(nextEt > maxEt){ maxEt = nextEt; maxId = i; } } if(maxId != 0) continue; eta = helper->getEta(index); float phi = helper->getPhi(index); int crate = lookup_crate(eta,phi); if(status[index-1]==1)crate_histo[crate-1]->Fill(scaled_adc*tgain); } for(int i = 0; i < ncrates; i++){ sprintf(name,"crate_fit_%i",i); crate_histo[i]->Sumw2(); crate_histo[i]->Rebin(4); crate_fit[i] = new TF1(name,"pol1(0) + gaus(2)",0.3,1.7); crate_fit[i]->SetParLimits(0,0,10.0*crate_histo[i]->GetBinContent(1)); crate_fit[i]->SetParLimits(1,-10000,0); crate_fit[i]->SetParLimits(2,0,10.0*crate_histo[i]->GetMaximum()); crate_fit[i]->SetParLimits(3,0,10); crate_fit[i]->SetParameter(0,crate_histo[i]->GetBinContent(1)); crate_fit[i]->SetParameter(1,-crate_histo[i]->GetBinContent(1)/6.0); crate_fit[i]->SetParameter(2,-crate_histo[i]->GetMaximum()); crate_fit[i]->SetParameter(3,0.929); crate_fit[i]->SetParameter(4,0.156); crate_fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); crate_fit[i]->SetLineColor(kBlue); crate_fit[i]->SetLineWidth(0.6); crate_histo[i]->Fit(crate_fit[i],"rql","",0.3,1.8); float mean = crate_histo[i]->GetFunction(name)->GetParameter(3); float merr = crate_histo[i]->GetFunction(name)->GetParError(3); crateprec->SetBinContent(i+1,mean); crateprec->SetBinError(i+1,merr); cout<<"crate "<<i+1<<" "<<mean<<" "<<merr/mean<<endl; } ofstream newgain(ngname); float gains3[ntowers]; float gerr3[ntowers]; for(int i = 0; i < ntowers; i++){ float eta = helper->getEta(i+1); float phi = helper->getPhi(i+1); int crate = lookup_crate(eta,phi); float adjust = crate_fit[crate-1]->GetParameter(3); float og = bemctables->calib(1,i)*gains[i]*gains2[i]; float ng = og; float aerr = crate_fit[crate-1]->GetParError(3); float ne = sqrt(pow(gains[i]*gerr2[i],2) + pow(gains2[i]*gainerr[i],2)); if(fabs(adjust-1)/aerr > 1.5){ ne = sqrt(pow(ne/(adjust),2)+pow(og*aerr/(adjust*adjust),2)); ng /= adjust; } newgain << i+1 << " " << ng << " " << ne << " " << status[i] << endl; gains3[i] = ng; gerr3[i] = ne; } newgain.close(); */ outfile.Write(); outfile.Close(); }
void toffit(){ gStyle->SetErrorX(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); TFile *f = TFile::Open("mergedFull.root"); TString charge; ofstream fout("Run15tofdphidzcalib.dat"); ofstream fouttmp("Run15tofdphidzcalibtmp.dat"); for(int iarm=0; iarm<2; iarm++){ for(int ich=0; ich<2; ich++){ if(iarm==0) TH2F *tofdphidz = (TH2F*)f->Get(Form("tofdphidz_%d",ich)); else TH2F *tofdphidz = (TH2F*)f->Get(Form("tofwdphidz_%d",ich)); if(tofdphidz->Integral()==0) continue; TH1F* tofdphi = (TH1F*)tofdphidz->ProjectionX(Form("tofdphi_%d_%d",iarm,ich),0,-1); TH1F* tofdz = (TH1F*)tofdphidz->ProjectionY(Form("tofdz_%d_%d",iarm,ich),0,-1); //tofdphi->Rebin(4); tofdz->Rebin(5); tofdphi->Scale(1./tofdphi->Integral()); tofdz->Scale(1./tofdz->Integral()); TF1 *fphi = new TF1("fphi","gaus(0)+gaus(3)",-0.1,0.1); fphi->SetNpx(10000); //TF1 *fphi = new TF1("fphi","[0]*([1]*exp(-(x-[2])**2/[3]/[3])+(1-[1])*exp(-(x-[4])**2/[5]/[5]))",-0.1,0.1); fphi->SetParameters(1e-1,0,1e-3,1e-3,0,1e-2); //fphi->SetParameters(4.79253e-02,9.25529e-01,-8.56488e-05,-7.46701e-03,-5.37828e-04,5.99178e-0); SetStyle(*tofdphi,1.2,1,20,0,0); tofdphi->Fit("fphi","RQ"); double par[6]; fphi->GetParameters(par); TF1 *fphi1 = new TF1("fphi1","gaus",-0.1,0.1); fphi1->SetNpx(10000); fphi1->SetParameters(par); TF1 *fphi2 = new TF1("fphi2","gaus",-0.1,0.1); fphi2->SetNpx(10000); fphi2->SetParameters(&par[3]); fphi1->SetLineColor(4); //fphi1->Draw("same"); fphi2->SetLineColor(6); //fphi2->Draw("same"); fout<<par[1]<<","; if(par[1]>1) cout<<"dphi "<<iarm<<"\t"<<ich<<"\t"<<ipt<<endl; TF1 *fz = new TF1("fz","gaus(0)+gaus(3)",-10,10); //fz->SetParameters(3.02349e+07,8.32462e-01,2.39187e+00,2.17631e+07,6.35460e-01,8.09821e+00); fz->SetParameters(1e-1,0,2,1e-3,0,8); SetStyle(*tofdz,1.2,1,20,0,0); tofdz->Fit("fz","RQ"); fz->GetParameters(par); TF1 *fz1 = new TF1("fz1","gaus",-10,10); fz1->SetNpx(10000); fz1->SetParameters(par); TF1 *fz2 = new TF1("fz2","gaus",-10,10); fz2->SetNpx(10000); fz2->SetParameters(&par[3]); fz1->SetLineColor(4); //fz1->Draw("same"); fz2->SetLineColor(6); //fz2->Draw("same"); if(par[1]>10) cout<<"dz"<<iarm<<"\t"<<ich<<"\t"<<ipt<<endl; fouttmp<<par[1]<<","; } fout<<endl; fouttmp<<endl; } }
void Getvn(){ TString str; TFile *fin; int nrun = GetTotalRun(); if(nrun<0) exit("Empty run list file!"); ofstream fout, fout1, fout2; int iharE=0; if(nhar==1) iharE=1; for(int icent=0;icent<ncent;icent++){ for(int ihar=0;ihar<nhar;ihar++){ for(int isub=0;isub<nsub;isub++){ int n = ihar+1.0+iharE; if(isub==1) str = "FVTX1S"; else if(isub==2) str = "FVTX2S"; else continue; fout1.open(Form("Run15pAu200MinBias/res%d_%d_%s.dat",n,icent,str.Data())); //using str as event plane detector fout2.open(Form("Run15pAu200MinBias/psi%d_%d_%s.dat",n,icent,str.Data())); //using str as event plane detector float reso = 1.;//GetReso(icent,ihar,isub); fout1<<reso<<endl; TH2F* hvobs = new TH2F(Form("hvobs_%d_%d_%d",icent,ihar,isub),Form("hvobs_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); TH2F* hvobssq = new TH2F(Form("hvobssq_%d_%d_%d",icent,ihar,isub),Form("hvobssq_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); for(int irun=0;irun<nrun;irun++){ fout2<<GetRun(irun)<<" "<<GoodRun(icent,ihar,isub,irun)<<endl; } for(int iphi=0;iphi<nphi;iphi++){ string phistr = (iphi==0)?"east":"west"; fout.open(Form("Run15pAu200MinBias/v%d_%d_%s_%s.dat",n,icent,phistr.c_str(),str.Data())); //using str as event plane detector for(int irun=0;irun<nrun;irun++){ // cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<endl; fin = TFile::Open(Form("Run15pAu200MinBias/output_fvtxwithcntEP_%d.root",GetRun(irun))); if(!(GoodRun(icent,ihar,isub,irun)>0.2 && GoodRun(icent,ihar,isub,irun)<3.0)){ cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<endl; continue; } TH2F* hvobstemp = (TH2F*)fin->Get(Form("vobs%s_%d_%d_%d",str.Data(),icent,ihar,iphi)); TH2F* hvobssqtemp = (TH2F*)fin->Get(Form("vobs%ssq_%d_%d_%d",str.Data(),icent,ihar,iphi)); hvobs->Add(hvobstemp); hvobssq->Add(hvobssqtemp); fin->Close(); } TH1F* ptProj = (TH1F*)hvobs->ProjectionX(Form("hptProj"),0,-1); for(int ipt=0;ipt<npt-1;ipt++){ TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),hvobs->GetXaxis()->FindBin(ptbin[ipt]),hvobs->GetXaxis()->FindBin(ptbin[ipt+1])); TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),hvobs->GetXaxis()->FindBin(ptbin[ipt]),hvobs->GetXaxis()->FindBin(ptbin[ipt+1])); float vobs = hvobsProj->GetMean(); float Ntracks = hvobsProj->GetEntries(); float vobssq = hvobsProj->GetMean(); float v = vobs/reso; float verr = sqrt(vobssq/reso/reso-(v*v))/sqrt(Ntracks); ptProj->GetXaxis()->SetRangeUser(ptbin[ipt],ptbin[ipt+1]); float pt = ptProj->GetMean(); fout<<pt<<" "<<v<<" "<<" "<<verr<<endl; } fout.close(); } fout1.close(); fout2.close(); } } } }
void cetaflatHEM3t(int nIterN=1, double Ethr1=4, double Ethr2=150) { gStyle->SetOptLogz(0); gStyle->SetMarkerSize(0.7); gStyle->SetMarkerStyle(20); gStyle->SetPadGridX(0); gStyle->SetPadGridY(0); gStyle->SetTitleOffset(1.7,"Y"); gStyle->SetTitleOffset(0.9,"X"); //gStyle->SetPadRightMargin(0.12); gStyle->SetPadTopMargin(0.06); gStyle->SetPadRightMargin(0.03); gStyle->SetPadLeftMargin(0.2); //gStyle->SetNdivisions(516); gStyle->SetStatH(0.09); gStyle->SetStatW(0.3); gStyle->SetTitleW(0.4); gStyle->SetTitleX(0.3); gStyle->SetOptStat(0); //gStyle->SetOptStat(1111111); gROOT->ForceStyle(); char ctit[145]; static const double theHBHEEtaBounds[] = { 0.000, 0.087, 0.087*2, 0.087*3, 0.087*4, 0.087*5, 0.087*6, 0.087*7, 0.087*8, 0.087*9, 0.087*10, 0.087*11, 0.087*12, 0.087*13, 0.087*14, 0.087*15, 0.087*16, 0.087*17, 0.087*18, 0.087*19, 1.74, 1.83, 1.93, 2.043, 2.172, 2.332, 2.5, 2.65, 2.868, 3.000 }; static const double theHFEtaBounds[] = { 2.853, 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191 }; // ---------------- Histos input -------------------------------------- char ftit[145]; //sprintf(ftit,"%s","phi43val2012A"); //sprintf(ftit,"%s","phi2012A_May"); //sprintf(ftit,"%s","phiSym524_2012AB"); //sprintf(ftit,"%s","phiSym524newGain_2012AB"); //sprintf(ftit,"%s","phiSym524newGain_2012ABC"); sprintf(ftit,"%s","phiSym533Corr45Gain507_2012D"); sprintf(ctit,"/home/vodib/beam12/intercal/%s.root",ftit); TFile *fila = new TFile (ctit); cout<<"File= "<<ctit<<endl; TH1F *hcounter = new TH1F(*((TH1F*)fila->Get("phaseHF/hcounter"))); cout<<"Stat= "<<hcounter->GetBinContent(2)<<endl; cout<<"E within: "<<Ethr1<<" - "<<Ethr2<<endl; TH2F* hmapP = new TH2F("hmapP","E HEM;i#eta;i#phi",14,-29.5,-15.5,72,0,72); TH2F* hmapP0 = new TH2F("hmapP0","E0 HEM;i#eta;i#phi",14,-29.5,-15.5,72,0,72); TH2F* hmapPc = new TH2F("hmapPc","corr HEM;i#eta;i#phi",14,-29.5,-15.5,72,0,72); hmapPc->Sumw2(); TH1F *hcorr1D = new TH1F("hcorr1D","Corr",150,0.5,2); TH1F *ht = new TH1F("ht","ht",20000,0,5e7); TH1F *htx = new TH1F("htx","htx",20000,0,5e5); TH1F *htr = new TH1F("htr","htr",5000,0,3); /* HE mapping: if (ieta==16 && depth<3) continue; if (ieta==17 && depth>1) continue; if (ieta>17 && ieta<27 && depth==3) continue; if (ieta==29 && depth==3) continue; if (ieta>20 && iphi%2==0) continue; */ TH1F *hdatP[14][72], *hdatPx[14][72]; for (int ii=0; ii<14; ii++) for (int jj=0; jj<72; jj++) { sprintf(ctit,"h%d_%d",ii+16,jj+1); hdatP[ii][jj] = new TH1F(ctit,ctit,10000,0,250); } TCanvas *cx[400]; TSpline5 *tt; Double_t x,y,rPL,rPS,mLE,mSE,ermean,rms; Double_t xx[4000],yy[4000]; Int_t nELP, nESP, nIter=0; Double_t mcorrL,scorrL,mcorrS,scorrS,erLP,erSP,rLP,drLP,rSP,corrL,corrS,dcorrL,dcorrS; double mLEphi[14]; TCanvas *ccxx = new TCanvas("ccxx","ccxx",0,400,800,400); ccxx->Divide(2,1); for (int ii=0; ii<14; ii++) { int ieta=-(ii+16); mLE=mSE=0; // ------------------for initial condition int nmLE=0, nmSE=0; ht->Reset(); htx->Reset(); for (int ll=0; ll<72; ll++) { int iphi=ll+1; if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue; if (abs(ieta)>20 && iphi%2==0) continue; hmapPc->SetBinContent(14-ii,ll+1,1); hmapPc->SetBinError(14-ii,ll+1,1.e-6); sprintf(ctit,"phaseHF/eHEspec/E_-%d_%d_3",abs(ieta),iphi); hdatPx[ii][ll] = new TH1F(*((TH1F*)fila->Get(ctit))); hdatPx[ii][ll]->SetAxisRange(Ethr1,Ethr2); rLP = hdatPx[ii][ll]->Integral()*hdatPx[ii][ll]->GetMean(); hmapP0->SetBinContent(14-ii,ll+1,rLP); if (skipHEChannel(iphi,ieta)) continue; if (rLP>0) { ht->Fill(rLP); htx->Fill(rLP); mLE += rLP; nmLE++; drLP=rLP*sqrt(pow(1./hdatPx[ii][ll]->Integral(),2)+ pow(hdatPx[ii][ll]->GetMeanError()/hdatPx[ii][ll]->GetMean(),2)); hmapP0->SetBinError(14-ii,ll+1,drLP); } else hmapP0->SetBinError(14-ii,ll+1,0); } if (nmLE>0) mLE /= nmLE; else mLE=0; ccxx->cd(1); ht->Draw("hist"); ccxx->cd(2); htx->Draw("hist"); ccxx->Update(); if (htx->GetBinContent(20001)>1) histspec(ht,mLE,ermean,rms,4,-5); else histspec(htx,mLE,ermean,rms,4,-5); //histspec(ht,mLE,ermean,rms); mLEphi[ii]=mLE; printf("ieta %2d : <E>= %8.1f \n",ieta,mLE); if (ht->GetMean()>0) htr->Fill(ht->GetRMS()/ht->GetMean()); for (int jj=0; jj<72; jj++) { int iphi=jj+1; if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue; if (abs(ieta)>20 && iphi%2==0) continue; if (skipHEChannel(iphi,ieta)) { hmapP->SetBinContent(14-ii,jj+1,hmapP0->GetBinContent(14-ii,jj+1,rLP)); continue; } for (nIter=1; nIter<nIterN; nIter++) { //cout<<nIter<<" | "; if (hmapP0->GetBinContent(14-ii,jj+1)<=0) continue; corrL=hmapPc->GetBinContent(14-ii,jj+1); hdatP[ii][jj]->Reset(); for (int kk=1; kk<=hdatPx[ii][jj]->GetNbinsX(); kk++) { xx[kk-1]=hdatPx[ii][jj]->GetBinCenter(kk); yy[kk-1]=hdatPx[ii][jj]->GetBinContent(kk); } tt = new TSpline5("tt",xx,yy,1000,"",10,20); for (int kk=1; kk<=hdatP[ii][jj]->GetNbinsX(); kk++) { x=hdatP[ii][jj]->GetBinCenter(kk); y=hdatP[ii][jj]->GetBinContent(kk); hdatP[ii][jj]->Fill(x*corrL,tt->Eval(x)/10.0); } tt->Delete(); hdatP[ii][jj]->SetAxisRange(Ethr1,Ethr2); rLP = hdatP[ii][jj]->Integral()*hdatP[ii][jj]->GetMean(); dcorrL=(rLP-mLE)/mLE; if (fabs(dcorrL)>0.5) dcorrL=0.5*dcorrL/fabs(dcorrL); if (rLP>0) drLP= sqrt(pow(hdatP[ii][jj]->GetMeanError()/hdatP[ii][jj]->GetMean(),2)+ 1.f/hdatP[ii][jj]->Integral()+ pow(dcorrL/(1.0+sqrt((float) nIter)),2)); else drLP=1.e-6; if (fabs(dcorrL)>0.001) { //corrL*=1-20*dcorrL/(40+nIter*nIter); //corrL*=1-dcorrL/(2+nIter); corrL*=1-dcorrL/(1.0+sqrt((float) nIter)); //printf("%2d : %2d / %2d / 1 %7.3f %7.3f\n",nIter,ieta,iphi,dcorrL,corrL); hmapPc->SetBinContent(14-ii,jj+1,corrL); hmapPc->SetBinError(14-ii,jj+1,corrL*drLP); hmapP->SetBinContent(14-ii,jj+1,rLP); } else { printf("%2d : %2d / %2d / 3 %7.3f %8.4f %8.4f\n", nIter,ieta,iphi,dcorrL,corrL,corrL*drLP); hmapP->SetBinContent(14-ii,jj+1,rLP); hmapPc->SetBinError(14-ii,jj+1,corrL*drLP); break; } if (nIter==nIterN-1) printf("%2d : %2d / %2d / 3 %8.4f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrL,corrL,corrL*drLP); } } } printf("\nieta eta width dE/dPhidEta\n"); double xeta[14], weta[14], yield[14]; int ind=0; for (int i=0; i<14; i++) { int ieta=-(i+16); if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue; xeta[ind]=-(theHBHEEtaBounds[i+15]+theHBHEEtaBounds[i+16])/2; weta[ind]=(theHBHEEtaBounds[i+16]-theHBHEEtaBounds[i+15]); yield[ind]=mLEphi[i]; if (abs(ieta)<21) yield[ind]*=72/weta[ind]; else yield[ind]*=36/weta[ind]; printf("%3d 3 %7.3f%7.3f %g\n",ieta,xeta[ind],weta[ind],yield[ind]); ind++; } TCanvas *cgL = new TCanvas("cgL","cgL",300,300,600,600); TGraphErrors *grL = new TGraphErrors(ind,xeta,yield,0,0); grL->SetTitle("HEM ;#eta;E / #Delta#eta , GeV"); grL->Draw("1+PAl"); cgL->Print("pictHEplot/phiProfHEM3.gif"); //cgL->Print("HEmc/phiProfM3.gif"); //TFile *histf = new TFile("HEM3mc.root","RECREATE"); FILE *ft1; sprintf(ctit,"corrHEM3_%s_%d_%d.txt",ftit,((int) Ethr1),((int) Ethr2)); //sprintf(ctit,"corrHEM3_MC_%d_%d.txt",((int) Ethr1),((int) Ethr2)); if ((ft1 = fopen(ctit,"w"))==NULL) { // Open new file printf("\nNo file %s open => EXIT\n\n",file); return; } printf("\n\n File '%s' open \n\n",ctit); TH1D *hprL[14],*hprL0[14],*hprcL[16]; TCanvas *cpr[14],*ccc[16]; TLine *lin1 = new TLine(0,1,71,1); lin1->SetLineWidth(1); int noff=0; for (int ii=0; ii<14; ii++) { int ieta=-(ii+16); if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue; sprintf(ctit,"HEMcorr_%d_3",ieta); // draw corrections hprcL[ii] = hmapPc->ProjectionY(ctit,14-ii,14-ii); hprcL[ii]->SetTitle(ctit); ccc[ii] = new TCanvas(ctit,ctit,800,100,500,500); hprcL[ii]->SetMinimum(0.41); hprcL[ii]->SetMaximum(hprcL[ii]->GetMaximum()*1.1); hprcL[ii]->SetTitleOffset(0.9,"X"); hprcL[ii]->Draw("e"); lin1->Draw(); sprintf(ctit,"pictHEplot/HEM3corr_%d.gif",ieta); //sprintf(ctit,"HEmc/HEM3c_4_100G_%d.gif",ieta); ccc[ii]->Print(ctit); //hprcL[ii]->Write(); sprintf(ctit,"HEM_E_%d_3;i#phi;GeV",ieta); hprL0[ii] = hmapP0->ProjectionY(ctit,14-ii,14-ii); hprL0[ii]->SetTitle(ctit); sprintf(ctit,"HEM__%d",ieta); hprL[ii] = hmapP->ProjectionY(ctit,14-ii,14-ii); if (abs(ieta)>20) { hprL[ii]->Rebin(); hprL0[ii]->Rebin(); } cpr[ii] = new TCanvas(ctit,ctit,800,100,500,500); hprL0[ii]->SetFillColor(3); hprL0[ii]->SetLineColor(3); hprL0[ii]->SetLineWidth(1); hprL0[ii]->SetTitleOffset(0.9,"X"); hprL0[ii]->SetMinimum(0); hprL0[ii]->Draw("hist"); hprL[ii]->Draw("samehist"); sprintf(ctit,"pictHEplot/HEM_E_%d_3.gif",ieta); //sprintf(ctit,"HEmc/HEM_E_%d_3.gif",ieta); cpr[ii]->Print(ctit); //hprL0[ii]->Write(); for (int jj=0; jj<72; jj++) { int ieta=-(ii+16); int iphi=jj+1; if (abs(ieta)>20 && iphi%2==0) continue; corrL=hmapPc->GetBinContent(14-ii,jj+1); dcorrL=hmapPc->GetBinError(14-ii,jj+1); hcorr1D->Fill(corrL); noff++; //printf("%2d : %2d / %2d / 3 %8.4f %8.4f\n",noff,ieta,iphi,corrL,dcorrL); fprintf(ft1,"%2d %2d 3 %8.4f %8.4f\n",ieta,iphi,corrL,dcorrL); } } fclose(ft1); TCanvas *c1corr =new TCanvas("c1corr","c1corr",30,30,600,600); hcorr1D->Draw("hist"); histStat(hcorr1D,1); c1corr->Print("pictHEplot/corrHEM3.gif"); //c1corr->Print("HEmc/corrHEM3.gif"); TCanvas *ctr = new TCanvas("ctr","ctr",0,0,650,600); htr->Draw("hist"); ctr->Update(); TCanvas *chmapP = new TCanvas("chmapP","chmapP",0,0,650,600); chmapP->cd(); chmapP->SetRightMargin(0.12); chmapP->SetLogz(); hmapP->SetAxisRange(hmapP->GetBinContent(14,1)/2,-1111,"Z"); hmapP->Draw("colz"); chmapP->Print("pictHEplot/hmapHEM3.gif"); chmapP->Update(); TCanvas *chmapP0 = new TCanvas("chmapP0","chmapP0",0,0,650,600); chmapP0->cd(); chmapP0->SetRightMargin(0.12); chmapP0->SetLogz(); hmapP0->SetAxisRange(hmapP0->GetBinContent(14,1)/2,-1111,"Z"); hmapP0->Draw("colz"); chmapP0->Print("pictHEplot/hmap0HEM3.gif"); chmapP0->Update(); TCanvas *chmapPc = new TCanvas("chmapPc","chmapPc",0,0,650,600); chmapPc->cd(); chmapPc->SetRightMargin(0.12); hmapPc->SetAxisRange(0.6,2,"Z"); hmapPc->Draw("colz"); chmapPc->Print("pictHEplot/hmapcHEM3.gif"); chmapPc->Update(); sprintf(ctit,"HEM3o_%s_%d_%d.root",ftit,((int) Ethr1),((int) Ethr2)); TFile *histf = new TFile(ctit,"RECREATE"); hmapP->Write(); hmapP0->Write(); hmapPc->Write(); histf->Close(); }
void cetaflatHFP12(int nIterN=1, double Ethr1=10, double Ethr2=150) { gStyle->SetOptLogz(0); gStyle->SetMarkerSize(0.7); gStyle->SetMarkerStyle(20); gStyle->SetPadGridX(0); gStyle->SetPadGridY(0); gStyle->SetTitleOffset(1.7,"Y"); gStyle->SetTitleOffset(0.9,"X"); //gStyle->SetPadRightMargin(0.12); gStyle->SetPadRightMargin(0.03); gStyle->SetPadLeftMargin(0.18); //gStyle->SetNdivisions(516); gStyle->SetStatH(0.025); gStyle->SetStatW(0.3); gStyle->SetTitleW(0.4); gStyle->SetTitleX(0.28); gStyle->SetOptStat(0); gROOT->ForceStyle(); char ctit[245],ftit[245]; float etaBounds[14] = {2.853,2.964,3.139,3.314,3.489,3.664,3.839,4.013,4.191,4.363,4.538,4.716,4.889,5.205}; // ------Histos input: spectra of all channels----------------------------------- //sprintf(ftit,"%s","phi43val2012A"); //sprintf(ftit,"%s","phi2012A_May"); //sprintf(ftit,"%s","phiSym524_2012AB"); //sprintf(ftit,"%s","phiSym524newGain_2012AB"); //sprintf(ftit,"%s","phiSym524newGain_2012ABC"); //sprintf(ftit,"%s","phisymNewCond2012Cval"); //sprintf(ftit,"%s","phisymOldCond2012Cval"); //sprintf(ftit,"%s","phiSym533Gain507_2012D"); sprintf(ftit,"%s","phiSym533Corr45Gain507_2012D"); sprintf(ctit,"/home/vodib/beam12/intercal/%s.root",ftit); TFile *fila = new TFile (ctit); cout<<"File= "<<ctit<<endl; TH1F *hcounter = new TH1F(*((TH1F*)fila->Get("phaseHF/hcounter"))); cout<<"Stat= "<<hcounter->GetBinContent(2)<<endl; cout<<"E within: "<<Ethr1<<" - "<<Ethr2<<endl; TH2F* hLmapP = new TH2F("hLmapP","E L HFP;i#eta;i#phi",13,28.5,41.5,36,0,72); TH2F* hSmapP = new TH2F("hSmapP","E S HFP;i#eta;i#phi",13,28.5,41.5,36,0,72); TH2F* hLmapP0 = new TH2F("hLmapP0","E0 L HFP;i#eta;i#phi",13,28.5,41.5,36,0,72); TH2F* hSmapP0 = new TH2F("hSmapP0","E0 S HFP;i#eta;i#phi",13,28.5,41.5,36,0,72); TH2F* hLmapPc = new TH2F("hLmapPc","corr L HFP;i#eta;i#phi",13,28.5,41.5,36,0,72); TH2F* hSmapPc = new TH2F("hSmapPc","corr S HFP;i#eta;i#phi",13,28.5,41.5,36,0,72); hLmapPc->Sumw2(); hSmapPc->Sumw2(); //TH1F *hLcorr1D = new TH1F("hLcorr1D","Corr L",300,0.5,2); //TH1F *hScorr1D = new TH1F("hScorr1D","Corr S",300,0.5,2); TH1F *hLcorr1D = new TH1F("hLcorr1D","Corr L",180,0.7,1.5); TH1F *hScorr1D = new TH1F("hScorr1D","Corr S",180,0.7,1.5); TH1F *hLdatP[13][36], *hSdatP[13][36], *hLdatPx[13][36], *hSdatPx[13][36]; for (int ii=0;ii<13;ii++) for (int jj=0;jj<36;jj++) { sprintf(ctit,"hL%d_%d",ii+29,2*jj+1); hLdatP[ii][jj] = new TH1F(ctit,ctit,8000,0,250); sprintf(ctit,"hS%d_%d",ii+29,2*jj+1); hSdatP[ii][jj] = new TH1F(ctit,ctit,8000,0,250); } TH1F *htL = new TH1F("htL","htL",20000,0,7e8/3.); TH1F *htS = new TH1F("htS","htS",20000,0,5e8/3.); //TH1F *htL = new TH1F("htL","htL",20000,0,4e8/40); //TH1F *htS = new TH1F("htS","htS",20000,0,2e8/40); TH1F *hLdatPx[13][36], *hSdatPx[13][36]; TCanvas *cLx[200],*cSx[200]; TSpline5 *ttL,*ttS; Double_t x,y,rPL,rPS,drPL,drPS,mLE,mSE,ermean,rms; Double_t xxL[1000],yyL[1000]; Double_t xxS[1000],yyS[1000]; Int_t nELP, nESP, nIter=0; Double_t mcorrL,scorrL,mcorrS,scorrS,erLP,erSP,rLP,drLP,rSP,drSP,corrL,corrS,dcorrL,dcorrS; double mLEphi[13],mSEphi[13],dmLEphi[13],dmSEphi[13]; TCanvas *ccxx = new TCanvas("ccxx","ccxx",100,300,900,500); ccxx->Divide(2,1); for (int ii=0;ii<13;ii++) { //for (int ii=1;ii<2;ii++) { int ieta=ii+29; mLE=mSE=0; // ------------------for initial condition int nmLE=0, nmSE=0; htL->Reset(); htS->Reset(); for (int ll=1;ll<=72;ll+=2) { int iphi=ll; if (abs(ieta)>39 && (iphi-1)%4==0) continue; hSmapPc->SetBinContent(ii+1,ll/2+1,1); hLmapPc->SetBinContent(ii+1,ll/2+1,1); hSmapPc->SetBinError(ii+1,ll/2+1,1.e-6); hLmapPc->SetBinError(ii+1,ll/2+1,1.e-6); sprintf(ctit,"phaseHF/espec/E_+%d_%d_1",ieta,iphi); hLdatPx[ii][ll/2] = new TH1F(*((TH1F*)fila->Get(ctit))); hLdatPx[ii][ll/2]->SetAxisRange(Ethr1,Ethr2); rLP = hLdatPx[ii][ll/2]->Integral()*hLdatPx[ii][ll/2]->GetMean(); hLmapP0->SetBinContent(ii+1,ll/2+1,rLP); sprintf(ctit,"phaseHF/espec/E_+%d_%d_2",ieta,iphi); hSdatPx[ii][ll/2] = new TH1F(*((TH1F*)fila->Get(ctit))); hSdatPx[ii][ll/2]->SetAxisRange(Ethr1,Ethr2); rSP = hSdatPx[ii][ll/2]->Integral()*hSdatPx[ii][ll/2]->GetMean(); hSmapP0->SetBinContent(ii+1,ll/2+1,rSP); if (ieta<=32 && iphi==67) continue; if (rLP>0) { htL->Fill(rLP); mLE += rLP; nmLE++; } if (rSP>0) { htS->Fill(rSP); mSE += rSP; nmSE++; } } if (nmLE>0) mLE /= nmLE; else continue; if (nmSE>0) mSE /= nmSE; else continue; ccxx->cd(1); htL->Draw("hist"); ccxx->cd(2); htS->Draw("hist"); ccxx->Update(); //histspec(htL,mLE,ermean,rms,4,3); //histspec(htS,mSE,ermean,rms,4,3); mLEphi[ii]=mLE; mSEphi[ii]=mSE; dmLEphi[ii]=htL->GetRMS(); dmSEphi[ii]=htS->GetRMS(); printf("ieta %2d : <E>L= %8.1f (%6.1f) x %d <E>S= %8.1f (%6.1f) x %d \n", ieta,mLE,dmLEphi[ii],nmLE,mSE,dmSEphi[ii],nmSE); for (int jj=1;jj<=72;jj+=2) { int iphi=jj; if (abs(ieta)>39 && (iphi-1)%4==0) continue; if (ieta<=32 && iphi==67) { hLmapP->SetBinContent(ii+1,jj/2+1,hLmapP0->GetBinContent(ii+1,jj/2+1)); hSmapP->SetBinContent(ii+1,jj/2+1,hSmapP0->GetBinContent(ii+1,jj/2+1)); continue; } for (nIter=1;nIter<nIterN;nIter++) { //cout<<nIter<<" | "; corrL=hLmapPc->GetBinContent(ii+1,jj/2+1); hLdatP[ii][jj/2]->Reset(); for (int kk=1;kk<=hLdatPx[ii][jj/2]->GetNbinsX();kk++) { xxL[kk-1]=hLdatPx[ii][jj/2]->GetBinCenter(kk); yyL[kk-1]=hLdatPx[ii][jj/2]->GetBinContent(kk); } ttL = new TSpline5("tt",xxL,yyL,1000,"",10,20); for (int kk=1;kk<=hLdatP[ii][jj/2]->GetNbinsX();kk++) { x=hLdatP[ii][jj/2]->GetBinCenter(kk); y=hLdatP[ii][jj/2]->GetBinContent(kk); hLdatP[ii][jj/2]->Fill(x*corrL,ttL->Eval(x)/8.0); } ttL->Delete(); hLdatP[ii][jj/2]->SetAxisRange(Ethr1,Ethr2); rLP = hLdatP[ii][jj/2]->Integral()*hLdatP[ii][jj/2]->GetMean(); dcorrL=(rLP-mLE)/mLE; if (rLP>0) drLP= sqrt(pow(hLdatP[ii][jj/2]->GetMeanError()/hLdatP[ii][jj/2]->GetMean(),2)+ 1.f/hLdatP[ii][jj/2]->Integral()+ pow(dcorrL/(1.0+sqrt((float) nIter)),2)); else drLP=1.e-6; if (fabs(dcorrL)>0.001) { corrL*=1-dcorrL/(1.0+sqrt((float) nIter)); //printf("%2d : %2d / %2d / 1 %7.3f %7.3f\n",nIter,ieta,iphi,dcorrL,corrL); hLmapPc->SetBinContent(ii+1,jj/2+1,corrL); hLmapPc->SetBinError(ii+1,jj/2+1,corrL*drLP); hLmapP->SetBinContent(ii+1,jj/2+1,rLP); } else { printf("%2d : %2d / %2d / 1 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrL,corrL,corrL*drLP); hLmapP->SetBinContent(ii+1,jj/2+1,rLP); hLmapPc->SetBinError(ii+1,jj/2+1,corrL*drLP); break; } if (nIter==nIterN-1) { printf("%2d : %2d / %2d / 1 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrL,corrL,corrL*drLP); } } for (nIter=1;nIter<nIterN;nIter++) { //cout<<nIter<<" | "; corrS=hSmapPc->GetBinContent(ii+1,jj/2+1); hSdatP[ii][jj/2]->Reset(); for (int kk=1;kk<=hSdatPx[ii][jj/2]->GetNbinsX();kk++) { xxS[kk-1]=hSdatPx[ii][jj/2]->GetBinCenter(kk); yyS[kk-1]=hSdatPx[ii][jj/2]->GetBinContent(kk); } ttS = new TSpline5("tt",xxS,yyS,1000,"",10,20); for (int kk=1;kk<=hSdatP[ii][jj/2]->GetNbinsX();kk++) { x=hSdatP[ii][jj/2]->GetBinCenter(kk); y=hSdatP[ii][jj/2]->GetBinContent(kk); hSdatP[ii][jj/2]->Fill(x*corrS,ttS->Eval(x)/8.0); } ttS->Delete(); hSdatP[ii][jj/2]->SetAxisRange(Ethr1,Ethr2); rSP = hSdatP[ii][jj/2]->Integral()*hSdatP[ii][jj/2]->GetMean(); dcorrS=(rSP-mSE)/mSE; if (rSP>0) drSP=sqrt(pow(hSdatP[ii][jj/2]->GetMeanError()/hSdatP[ii][jj/2]->GetMean(),2)+ 1.f/hSdatP[ii][jj/2]->Integral()+ pow(dcorrS/(1.0+sqrt((float) nIter)),2)); else drSP=1.e-6; if (fabs(dcorrS)>0.001) { corrS*=1-dcorrS/(1.0+sqrt((float) nIter)); //printf("%2d : %2d / %2d / 1 %7.3f %7.3f\n",nIter,ieta,iphi,dcorrS,corrS); hSmapPc->SetBinContent(ii+1,jj/2+1,corrS); hSmapPc->SetBinError(ii+1,jj/2+1,corrS*drSP); hSmapP->SetBinContent(ii+1,jj/2+1,rSP); } else { printf("%2d : %2d / %2d / 2 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrS,corrS,corrS*drSP); hSmapP->SetBinContent(ii+1,jj/2+1,rSP); hSmapPc->SetBinError(ii+1,jj/2+1,corrS*drSP); break; } if (nIter==nIterN-1) { printf("%2d : %2d / %2d / 2 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrS,corrS,corrS*drSP); } } } } //fila->Close(); cout<<endl<<"Rings : "<<endl; cout<<" E L "<<"E S "<<"eta "<<"delta eta"<<endl; double xeta[13], weta[13], reta[13]; for (int i=29;i<=41;i++) { xeta[i-29]=(etaBounds[i-28]+etaBounds[i-29])/2; weta[i-29]=(etaBounds[i-28]-etaBounds[i-29]); mLEphi[i-29]=mLEphi[i-29]*36/weta[i-29]; mSEphi[i-29]=mSEphi[i-29]*36/weta[i-29]; dmLEphi[i-29]=dmLEphi[i-29]*36/weta[i-29]; dmSEphi[i-29]=dmSEphi[i-29]*36/weta[i-29]; if (i>39) { mLEphi[i-29]/=2; mSEphi[i-29]/=2; dmLEphi[i-29]/=2; dmSEphi[i-29]/=2; } reta[i-29] = mSEphi[i-29]/mLEphi[i-29]; cout<<i<<" : "<<mLEphi[i-29]<<" "<<mSEphi[i-29]<<" "<<xeta[i-29]<<" "<<weta[i-29]<<endl; } TCanvas *cgL = new TCanvas("cgL","cgL",300,300,600,600); TGraphErrors *grL = new TGraphErrors(13,xeta,mLEphi,0,dmLEphi); grL->SetTitle("HFP L;#eta;E_{Ring} / #Delta#eta_{Ring} , GeV"); grL->SetMinimum(0); grL->SetMarkerStyle(20); grL->Draw("1+PAl"); cgL->Print("pictHFplot/etaProfHFPL.gif"); mSEphi[12]/=2; mSEphi[11]/=2; TCanvas *cgS = new TCanvas("cgS","cgS",300,300,600,600); TGraphErrors *grS = new TGraphErrors(13,xeta,mSEphi,0,dmSEphi); grS->SetTitle("HFP S;#eta;E_{Ring} / #Delta#eta_{Ring} , GeV"); grS->SetMinimum(0); grS->SetMarkerStyle(20); grS->Draw("1+PAl"); cgS->Print("pictHFplot/etaProfHFPS.gif"); TCanvas *crg = new TCanvas("crg","crg",300,300,600,600); TGraphErrors *rg = new TGraphErrors(13,xeta,reta,0,0); rg->SetTitle("HFP;#eta;E(S) / E(L)"); rg->SetMinimum(0); rg->Draw("1+PAl"); crg->Print("pictHFplot/SoverLetaHFP.gif"); TCanvas *cL0 = new TCanvas("cL0","cL0",0,0,650,600); hLmapP0->Draw("colz"); cL0->Update(); TCanvas *cS = new TCanvas("cS0","cS0",1000,0,650,600); hSmapP0->Draw("colz"); cS0->Update(); //TFile *histf = new TFile("HFPmc.root","RECREATE"); FILE *ft1; //sprintf(ctit,"corrHFPmc_%d_%d.txt",((int) Ethr1),((int) Ethr2)); sprintf(ctit,"corrHFP_%s_%d_%d.txt",ftit,((int) Ethr1),((int) Ethr2)); if ((ft1 = fopen(ctit,"w"))==NULL){ // Open new file printf("\nNo file %s open => EXIT\n\n",file); return; } printf("\n\n File '%s' open \n\n",ctit); TH1D *hprL[13],*hprS[13],*hprL0[13],*hprS0[13]; TH1D *hprcL[13],*hprcS[13]; TCanvas *cpr[13],*ccc[13]; TLine *lin1 = new TLine(0,1,71,1); lin1->SetLineWidth(1); int noff=0; for (int ii=0;ii<13;ii++) { sprintf(ctit,"HFPcorr_%d_L",ii+29); // draw corrections hprcL[ii] = hLmapPc->ProjectionY(ctit,ii+1,ii+1); hprcL[ii]->SetTitle(ctit); sprintf(ctit,"HFPcorr_%d_S",ii+29); hprcS[ii] = hSmapPc->ProjectionY(ctit,ii+1,ii+1); hprcS[ii]->SetTitle(ctit); ccc[ii] = new TCanvas(ctit,ctit,800,100,500,900); ccc[ii]->Divide(1,2); ccc[ii]->cd(1); if (ii+29>39) { hprcL[ii]->Rebin(2); hprcS[ii]->Rebin(2); } hprcL[ii]->SetMinimum(0); hprcL[ii]->SetTitleOffset(0.9,"X"); hprcL[ii]->Draw("e"); lin1->Draw(); ccc[ii]->cd(2); hprcS[ii]->SetMinimum(0); hprcS[ii]->SetTitleOffset(0.9,"X"); hprcS[ii]->Draw("e"); lin1->Draw(); sprintf(ctit,"pictHFplot/HFPcorr_%d.gif",ii+29); ccc[ii]->Update(); ccc[ii]->Print(ctit); //hprcL[ii]->Write(); //hprcS[ii]->Write(); sprintf(ctit,"HFP_%d_L",ii+29); // draw E depositions hprL0[ii] = hLmapP0->ProjectionY(ctit,ii+1,ii+1); sprintf(ctit,"HFP_%d_L;i#phi;GeV;",29+ii); // draw E depositions hprL0[ii]->SetTitle(ctit); sprintf(ctit,"HFP_L_%d",ii+29); hprL[ii] = hLmapP->ProjectionY(ctit,ii+1,ii+1); sprintf(ctit,"HFP_%d_S",ii+29); hprS0[ii] = hSmapP0->ProjectionY(ctit,ii+1,ii+1); sprintf(ctit,"HFP_%d_S;i#phi;GeV;",29+ii); // draw E depositions hprS0[ii]->SetTitle(ctit); sprintf(ctit,"HFP_S_%d",ii+29); hprS[ii] = hSmapP->ProjectionY(ctit,ii+1,ii+1); cpr[ii] = new TCanvas(ctit,ctit,800,100,500,900); cpr[ii]->Divide(1,2); cpr[ii]->cd(1); if (ii+29>39) { hprL0[ii]->Rebin(2); hprL[ii]->Rebin(2); hprS0[ii]->Rebin(2); hprS[ii]->Rebin(2); } hprL0[ii]->SetFillColor(3);hprL0[ii]->SetLineColor(3);hprL0[ii]->SetLineWidth(3); hprL0[ii]->SetMinimum(0); hprL0[ii]->SetTitleOffset(0.9,"X"); hprL0[ii]->Draw("hist"); hprL[ii]->Draw("samehist"); cpr[ii]->cd(2); hprS0[ii]->SetMinimum(0); hprS0[ii]->SetTitleOffset(0.9,"X"); hprS0[ii]->SetFillColor(3);hprS0[ii]->SetLineColor(3);hprS0[ii]->SetLineWidth(3); hprS0[ii]->Draw("hist"); hprS[ii]->Draw("samehist"); sprintf(ctit,"pictHFplot/HFP_%d.gif",ii+29); cpr[ii]->Print(ctit); //hprS0[ii]->Write(); //hprL0[ii]->Write(); cout<<"Results : "<<endl; for (int jj=1;jj<=72;jj+=2) { int ieta=ii+29; int iphi=jj; if (abs(ieta)>39 && (iphi-1)%4==0) continue; //if (ieta==29 && iphi==67) continue; corrL=hLmapPc->GetBinContent(ii+1,jj/2+1); corrS=hSmapPc->GetBinContent(ii+1,jj/2+1); dcorrL=hLmapPc->GetBinError(ii+1,jj/2+1); dcorrS=hSmapPc->GetBinError(ii+1,jj/2+1); hLcorr1D->Fill(corrL); hScorr1D->Fill(corrS); noff++; //printf("%2d : %2d / %2d / 1 %9.4f %9.4f\n",noff,ieta,iphi,corrL,dcorrL); fprintf(ft1,"%2d %2d 1 %9.4f %9.4f\n",ieta,iphi,corrL,dcorrL); noff++; //printf("%2d : %2d / %2d / 2 %9.4f %9.4f\n",noff,ieta,iphi,corrS,dcorrS); fprintf(ft1,"%2d %2d 2 %9.4f %9.4f\n",ieta,iphi,corrS,dcorrS); } } fclose(ft1); for (int ii=0;ii<13;ii++) for (int jj=1;jj<=72;jj+=2) { int ieta=ii+29; int iphi=jj; if (abs(ieta)>39 && (iphi-1)%4==0) continue; if (ieta==29 && iphi==67) continue; corrL=hLmapPc->GetBinContent(ii+1,jj/2+1); if (fabs(corrL-1)>0.16) printf("%2d / %2d / 1 %9.4f %9.4f\n",ieta,iphi,corrL,dcorrL); corrS=hSmapPc->GetBinContent(ii+1,jj/2+1); if (fabs(corrS-1)>0.16) printf("%2d / %2d / 2 %9.4f %9.4f\n",ieta,iphi,corrS,dcorrS); } TCanvas *cLcorr =new TCanvas("cLcorr","cLcorr",30,30,600,600); cLcorr->SetRightMargin(0.12); hLmapPc->SetAxisRange(0.6,1.6,"Z"); hLmapPc->Draw("colz"); TCanvas *cScorr =new TCanvas("cScorr","cScorr",30,300,600,600); cScorr->SetRightMargin(0.12); hSmapPc->SetAxisRange(0.6,1.6,"Z"); hSmapPc->Draw("colz"); TCanvas *cL = new TCanvas("cL","cL",0,0,650,600); hLmapP->Draw("colz"); cL->Update(); TCanvas *cS = new TCanvas("cS","cS",1000,0,650,600); hSmapP->Draw("colz"); cS->Update(); TCanvas *c1corr =new TCanvas("c1corr","c1corr",30,30,900,500); c1corr->Divide(2,1); c1corr->cd(1); hLcorr1D->Draw("hist"); histStat(hLcorr1D,1); c1corr->cd(2); hScorr1D->Draw("hist"); histStat(hScorr1D,1); //hLcorr1D->Write(); hScorr1D->Write(); c1corr->Print("pictHFplot/corrHFP.gif"); //c1corr->Print("pictHFmc/corrHFP.gif"); c1corr->Update(); //fila->Close(); //histf->Close(); sprintf(ctit,"HFPo_%s_%d_%d.root",ftit,((int) Ethr1),((int) Ethr2)); TFile *histf = new TFile(ctit,"RECREATE"); hLcorr1D->Write(); hScorr1D->Write(); hLmapP->Write(); hLmapP0->Write(); hLmapPc->Write(); hSmapP->Write(); hSmapP0->Write(); hSmapPc->Write(); grL->Write(); grS->Write(); histf->Close(); }
//================================================ void DeltaZVsPos(const Int_t save = 0) { THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType])); TList *list = new TList; // dz vs BL TH2F *hTrkDzVsBL = (TH2F*)hn->Projection(1,3); c = draw2D(hTrkDzVsBL,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_BL_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_BL_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } list->Clear(); TString legName[30]; TH1F *hTrkDzInBL[30]; Int_t counter = 0; for(Int_t i=0; i<30; i++) { hTrkDzInBL[i] = (TH1F*)hTrkDzVsBL->ProjectionY(Form("hDeltaZ_BL%d",i+1),i+1,i+1); if(hTrkDzInBL[i]->GetEntries()>0) { legName[counter] = Form("Module %d",i+1); hTrkDzInBL[i]->SetLineColor(color[counter]); list->Add(hTrkDzInBL[i]); counter ++; } } c = drawHistos(list,"TrkDzInBL",Form("%s: #Deltaz of matched track-hit pairs in backleg;#Deltaz (cm)",trigName[kTrigType]),kTRUE,-100,100,kTRUE,0,1.2*hTrkDzInBL[1]->GetMaximum(),kFALSE,kTRUE,legName,kTRUE,"",0.15,0.25,0.2,0.88,kFALSE,0.04,0.04,kFALSE,1,kTRUE,kFALSE); TLine *line = GetLine(0,0,0,1.1*hTrkDzInBL[1]->GetMaximum(),1); line->Draw(); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_BL_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_BL_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } // dz vs Mod TH2F *hTrkDzVsMod = (TH2F*)hn->Projection(1,4); c = draw2D(hTrkDzVsMod,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_Mod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_Mod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } TH1F *hMthMod = (TH1F*)hTrkDzVsMod->ProjectionX("hMthMod"); hMthMod->Sumw2(); hMthMod->Scale(1./hMthMod->Integral()); TH2F *hMtdHitMap = (TH2F*)f->Get(Form("mhMtdHitMap_%s",trigName[kTrigType])); TH1F *htmp = (TH1F*)hMtdHitMap->ProjectionY("hHitMod_finebin"); htmp->Rebin(12); TH1F *hMtdHitMod = new TH1F(Form("hMtdHitMod_%s",trigName[kTrigType]),"# of MTD hits per module;module",5,1,6); for(int i=0; i<hMtdHitMod->GetNbinsX(); i++) { hMtdHitMod->SetBinContent(i+1,htmp->GetBinContent(i+1)); hMtdHitMod->SetBinError(i+1,htmp->GetBinError(i+1)); } hMtdHitMod->Scale(1./hMtdHitMod->Integral()); list->Clear(); list->Add(hMthMod); list->Add(hMtdHitMod); TString legName3[2] = {"Matched good hits","All good hits"}; c = drawHistos(list,"MtdHitMod",Form("%s: MTD hits per module;module;probability",trigName[kTrigType]),kFALSE,0,5,kTRUE,0,0.5,kFALSE,kTRUE,legName3,kTRUE,"",0.15,0.25,0.6,0.88,kTRUE); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sCompMtdHitMod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sCompMtdHitMod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } list->Clear(); TString legName2[5]; TH1F *hTrkDzInMod[5]; for(Int_t i=0; i<5; i++) { hTrkDzInMod[i] = (TH1F*)hTrkDzVsMod->ProjectionY(Form("hDeltaZ_Mod%d",i+1),i+1,i+1); legName2[i] = Form("Module %d",i+1); list->Add(hTrkDzInMod[i]); } c = drawHistos(list,"TrkDzInMod",Form("%s: #Deltaz of matched track-hit pairs in module;#Deltaz (cm)",trigName[kTrigType]),kTRUE,-100,100,kTRUE,0,1.2*hTrkDzInMod[3]->GetMaximum(),kFALSE,kTRUE,legName2,kTRUE,"",0.15,0.25,0.6,0.88,kTRUE); TLine *line = GetLine(0,0,0,hTrkDzInMod[3]->GetMaximum()*1.05,1); line->Draw(); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_Mod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_Mod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } }