bool PlotManager::saveResolution(const string& histName, const string& histTitle, const string& srcHistName, const char sliceDirection) { if ( ! isSetup_ ) return false; TH2F* srcHist = dynamic_cast<TH2F*>(theSrcFile_->Get(srcHistName.c_str())); // Check validity of objects if ( srcHist == NULL ) { cerr << "Cannot get object : " << histName << endl; return false; } if ( srcHist->IsA()->InheritsFrom("TH2") ) return false; // Push to base directory string pwd(gDirectory->GetPath()); string newHistPath = dirname(histName); string newHistName = basename(histName); if ( newHistPath.empty() ) { theOutFile_->cd(); } else if ( theOutFile_->cd(newHistPath.c_str()) == kFALSE ) { cout << "Cannot find directory, do mkdirs" << endl; mkdirs(theOutFile_, newHistPath)->cd(); } // Create a function for resolution model TF1 gaus("gaus", "gaus"); gaus.SetParameters(1.0, 0.0, 0.1); //gaus.SetRange(yMin, yMax); // Do FitSlices. if ( sliceDirection == 'X' ) srcHist->FitSlicesX(&gaus); else srcHist->FitSlicesY(&gaus); TH1F* meanHist = dynamic_cast<TH1F*>(theOutFile_->Get((srcHistName+"_1").c_str())); TH1F* widthHist = dynamic_cast<TH1F*>(theOutFile_->Get((srcHistName+"_2").c_str())); TH1F* chi2Hist = dynamic_cast<TH1F*>(theOutFile_->Get((srcHistName+"_chi2").c_str())); // Cosmetics meanHist ->SetName((newHistName+"_Mean" ).c_str()); widthHist->SetName((newHistName+"_Width").c_str()); chi2Hist ->SetName((newHistName+"_Chi2" ).c_str()); meanHist ->SetTitle((histTitle+" Mean" ).c_str()); widthHist->SetTitle((histTitle+" Width").c_str()); chi2Hist ->SetTitle((histTitle+" Chi2" ).c_str()); meanHist ->GetYaxis()->SetTitle("Gaussian mean" ); widthHist->GetYaxis()->SetTitle("Gaussian width" ); chi2Hist ->GetYaxis()->SetTitle("Gaussian fit #Chi^{2}"); // Save histograms meanHist ->Write(); widthHist->Write(); chi2Hist ->Write(); // Pop directory gDirectory->cd(pwd.c_str()); return true; }
void plot_1411() { gROOT->Reset(); gStyle->SetOptStat(0); gStyle->SetTitleOffset(1.,"Y"); gStyle->SetTitleOffset(.7,"X"); gStyle->SetLabelSize(0.04,"XY"); gStyle->SetTitleSize(0.06,"XY"); gStyle->SetPadLeftMargin(0.12); TFile *fsimc = new TFile("rootfiles/shms_20cmtarg_20deg_wc_mscat.root"); TTree *tsimc = (TTree*)fsimc->Get("h1411"); //Declaration of leaves types Float_t hsxfp; // position at focal plane ,+X is pointing down Float_t hsyfp; // X x Y = Z so +Y pointing central ray left Float_t hsxpfp; // dx/dz at focal plane Float_t hsypfp; // dy/dz at focal plane Float_t hsztari; // thrown position along the beam direction Float_t hsytari; //thrown horizontal position X x Y = Z so +Y pointing central ray left at plane perpendicular to SHMS at z=0 Float_t hsdeltai; // thrown 100*(p - pc)/pc with pc = central SHMS momentum Float_t hsyptari; // thrown target dy/dz horizontal slope Float_t hsxptari; // thrown target dx/dz vertical slope Float_t hsztar; // reconstructed position along the beam directio Float_t hsytar; //reconstructed horizontal position Float_t hsdelta;//reconstructed Float_t hsyptar;//reconstructed Float_t hsxptar;//reconstructed Float_t hsxtari;// from thrown kinematics , the calculated vertical position at plane perpendicular to SHMS at z=0 Float_t yrast;// vertical raster position // Set branch addresses. tsimc->SetBranchAddress("hsxfp",&hsxfp); tsimc->SetBranchAddress("hsyfp",&hsyfp); tsimc->SetBranchAddress("hsxpfp",&hsxpfp); tsimc->SetBranchAddress("hsypfp",&hsypfp); tsimc->SetBranchAddress("hsztari",&hsztari); tsimc->SetBranchAddress("hsytari",&hsytari); tsimc->SetBranchAddress("hsdeltai",&hsdeltai); tsimc->SetBranchAddress("hsyptari",&hsyptari); tsimc->SetBranchAddress("hsxptari",&hsxptari); tsimc->SetBranchAddress("hsztar",&hsztar); tsimc->SetBranchAddress("hsytar",&hsytar); tsimc->SetBranchAddress("hsdelta",&hsdelta); tsimc->SetBranchAddress("hsyptar",&hsyptar); tsimc->SetBranchAddress("hsxptar",&hsxptar); tsimc->SetBranchAddress("hsxtari",&hsxtari); // TH1F *hxptari = new TH1F("hxptari",";Initial xptar ",100,-.1,.1); TH1F *hxptarf = new TH1F("hxptarf",";Recon xptar ",100,-.1,.1); TH1F *difxptar = new TH1F("difxptar",";Xptar diff (mr) ",50,-5,5.); TH2F *difxptarVxptari = new TH2F("difxptarVxptari",";Init xptar (rad);Xptar diff (mr)",25,-.05,.05,50,-5,5.); TH2F *difxptarVyptari = new TH2F("difxptarVyptari",";Init yptar (rad);Xptar diff (mr)",30,-.03,.03,50,-5,5.); TH2F *difxptarVxfp = new TH2F("difxptarVxfp",";xfp (cm);Xptar diff (mr)",100,-40.,40.,50,-5,5.); TH2F *difxptarVyfp = new TH2F("difxptarVyfp",";yfp (cm);Xptar diff (mr)",100,-30.,30.,50,-5,5.); TH2F *difxptarVxpfp = new TH2F("difxptarVxpfp",";xpfp (cm);Xptar diff (mr)",100,-.1,.1,50,-5,5.); TH2F *difxptarVypfp = new TH2F("difxptarVypfp",";ypfp (cm);Xptar diff (mr)",100,-.05,.05,50,-5,5.); TH2F *difxptarVdeltai = new TH2F("difxptarVdeltai",";Init delta ;Xptar diff (mr)",16,-.1,.22,50,-5,5.); TH1F *hyptari = new TH1F("hyptari",";Initial yptar ",100,-.05,.05); TH1F *hyptarf = new TH1F("hyptarf",";Recon yptar ",100,-.05,.05); // TH1F *difyptar = new TH1F("difyptar",";Yptar diff (mr) ",50,-5,5.); TH2F *difyptarVxptari = new TH2F("difyptarVxptari",";Init xptar (rad);Yptar diff (mr)",25,-.05,.05,50,-5,5.); TH2F *difyptarVyptari = new TH2F("difyptarVyptari",";Init yptar (rad);Yptar diff (mr)",30,-.03,.03,50,-5,5.); TH2F *difyptarVxfp = new TH2F("difyptarVxfp",";xfp (cm);Yptar diff (mr)",100,-40.,40.,50,-5,5.); TH2F *difyptarVyfp = new TH2F("difyptarVyfp",";yfp (cm);Yptar diff (mr)",100,-30.,30.,50,-5,5.); TH2F *difyptarVxpfp = new TH2F("difyptarVxpfp",";xpfp (cm);Yptar diff (mr)",100,-.1,.1,50,-5,5.); TH2F *difyptarVypfp = new TH2F("difyptarVypfp",";ypfp (cm);Yptar diff (mr)",100,-.05,.05,50,-5,5.); TH2F *difyptarVdeltai = new TH2F("difyptarVdeltai",";Init delta ;Yptar diff (mr)",16,-.1,.22,50,-5,5.); // TH1F *difytar = new TH1F("difytar",";Ytar diff (cm) ",40,-2.,2.); TH2F *difytarVxptari = new TH2F("difytarVxptari",";Init xptar (rad);Ytar diff (cm)",25,-.05,.05,40,-2.,2.); TH2F *difytarVyptari = new TH2F("difytarVyptari",";Init yptar (rad);Ytar diff (cm)",30,-.03,.03,40,-2.,2.); TH2F *difytarVxfp = new TH2F("difytarVxfp",";xfp (cm);Ytar diff (cm)",100,-40.,40.,40,-2.,2.); TH2F *difytarVyfp = new TH2F("difytarVyfp",";yfp (cm);Ytar diff (cm)",100,-30.,30.,40,-2.,2.); TH2F *difytarVxpfp = new TH2F("difytarVxpfp",";xpfp (cm);Ytar diff (cm)",100,-.1,.1,40,-2.,2.); TH2F *difytarVypfp = new TH2F("difytarVypfp",";ypfp (cm);Ytar diff (cm)",100,-.05,.05,40,-2.,2.); TH2F *difytarVdeltai = new TH2F("difytarVdeltai",";Init delta ;Ytar diff (cm)",16,-.1,.22,40,-2.,2.); // TH1F *difdelta = new TH1F("difdelta",";Delta diff (%) ",40,-.1,.1); TH2F *difdeltaVxptari = new TH2F("difdeltaVxptari",";Init xptar (rad);Delta diff (%)",25,-.05,.05,40,-.1,.1); TH2F *difdeltaVyptari = new TH2F("difdeltaVyptari",";Init yptar (rad);Delta diff (%)",30,-.03,.03,40,-.1,.1); TH2F *difdeltaVxfp = new TH2F("difdeltaVxfp",";xfp (cm);Delta diff (%)",100,-40.,40.,40,-.1,.1); TH2F *difdeltaVyfp = new TH2F("difdeltaVyfp",";yfp (cm);Delta diff (%)",100,-30.,30.,40,-.1,.1); TH2F *difdeltaVxpfp = new TH2F("difdeltaVxpfp",";xpfp (cm);Delta diff (%)",100,-.1,.1,40,-.1,.1); TH2F *difdeltaVypfp = new TH2F("difdeltaVypfp",";ypfp (cm);Delta diff (%)",100,-.05,.05,40,-.1,.1); TH2F *difdeltaVdeltai = new TH2F("difdeltaVdeltai",";Init delta ;Delta diff (%)",16,-.1,.22,40,-.1,.1); // Long64_t nentries = tsimc->GetEntries(); for (int i = 0; i < nentries; i++) { tsimc->GetEntry(i); hxptari->Fill(hsxptari); hxptarf->Fill(hsxptar); difxptar->Fill(1000*(hsxptar-hsxptari)); difxptarVxptari->Fill(hsxptari,1000*(hsxptar-hsxptari)); difxptarVyptari->Fill(hsyptari,1000*(hsxptar-hsxptari)); difxptarVxfp->Fill(hsxfp,1000*(hsxptar-hsxptari)); difxptarVyfp->Fill(hsyfp,1000*(hsxptar-hsxptari)); difxptarVxpfp->Fill(hsxpfp,1000*(hsxptar-hsxptari)); difxptarVypfp->Fill(hsypfp,1000*(hsxptar-hsxptari)); difxptarVdeltai->Fill(hsdeltai/100.,1000*(hsxptar-hsxptari)); // difyptar->Fill(1000*(hsyptar-hsyptari)); difyptarVxptari->Fill(hsxptari,1000*(hsyptar-hsyptari)); difyptarVyptari->Fill(hsyptari,1000*(hsyptar-hsyptari)); difyptarVxfp->Fill(hsxfp,1000*(hsyptar-hsyptari)); difyptarVyfp->Fill(hsyfp,1000*(hsyptar-hsyptari)); difyptarVxpfp->Fill(hsxpfp,1000*(hsyptar-hsyptari)); difyptarVypfp->Fill(hsypfp,1000*(hsyptar-hsyptari)); difyptarVdeltai->Fill(hsdeltai/100.,1000*(hsyptar-hsyptari)); // difdelta->Fill((hsdelta-hsdeltai)); difdeltaVxptari->Fill(hsxptari,(hsdelta-hsdeltai)); difdeltaVyptari->Fill(hsyptari,(hsdelta-hsdeltai)); difdeltaVxfp->Fill(hsxfp,(hsdelta-hsdeltai)); difdeltaVyfp->Fill(hsyfp,(hsdelta-hsdeltai)); difdeltaVxpfp->Fill(hsxpfp,(hsdelta-hsdeltai)); difdeltaVypfp->Fill(hsypfp,(hsdelta-hsdeltai)); difdeltaVdeltai->Fill(hsdeltai/100.,(hsdelta-hsdeltai)); // difytar->Fill((hsytar-hsytari)); difytarVxptari->Fill(hsxptari,(hsytar-hsytari)); difytarVyptari->Fill(hsyptari,(hsytar-hsytari)); difytarVxfp->Fill(hsxfp,(hsytar-hsytari)); difytarVyfp->Fill(hsyfp,(hsytar-hsytari)); difytarVxpfp->Fill(hsxpfp,(hsytar-hsytari)); difytarVypfp->Fill(hsypfp,(hsytar-hsytari)); difytarVdeltai->Fill(hsdeltai/100.,(hsytar-hsytari)); } // TCanvas *cxptar = new TCanvas("cxptar"," Compare Recon/Inital xptar 8 GeV, point target, no wire ch, no mscat",1400,1000); cxptar->Divide(4,3); cxptar->cd(4); difxptar->Draw(); cxptar->cd(1); difxptarVdeltai->Draw("colz"); cxptar->cd(5); difxptarVdeltai->FitSlicesY(); TH1D *difxptarVdeltai_2 = (TH1D*)gDirectory->Get("difxptarVdeltai_2"); difxptarVdeltai_2->SetTitle(";Init Delta; Fitted Sigma of Xptar diff (mr)"); difxptarVdeltai_2->Draw(); cxptar->cd(2); difxptarVxptari->Draw("colz"); cxptar->cd(6); difxptarVxptari->FitSlicesY(); TH1D *difxptarVxptari_2 = (TH1D*)gDirectory->Get("difxptarVxptari_2"); difxptarVxptari_2->SetTitle(";Init Xptar; Fitted Sigma of Xptar diff (mr)"); difxptarVxptari_2->Draw(); cxptar->cd(3); difxptarVyptari->Draw("colz"); cxptar->cd(7); difxptarVyptari->FitSlicesY(); TH1D *difxptarVyptari_2 = (TH1D*)gDirectory->Get("difxptarVyptari_2"); difxptarVyptari_2->SetTitle(";Init Yptar; Fitted Sigma of Xptar diff (mr)"); difxptarVyptari_2->Draw(); cxptar->cd(9); difxptarVxfp->Draw("colz"); cxptar->cd(10); difxptarVyfp->Draw("colz"); cxptar->cd(11); difxptarVxpfp->Draw("colz"); cxptar->cd(12); difxptarVypfp->Draw("colz"); // TCanvas *cyptar = new TCanvas("cyptar"," Compare Recon/Inital yptar 8 GeV, point target, no wire ch, no mscat",1400,1000); cyptar->Divide(4,3); cyptar->cd(4); difyptar->Draw(); cyptar->cd(1); difyptarVdeltai->Draw("colz"); cyptar->cd(5); difyptarVdeltai->FitSlicesY(); TH1D *difyptarVdeltai_2 = (TH1D*)gDirectory->Get("difyptarVdeltai_2"); difyptarVdeltai_2->SetTitle(";Init Delta; Fitted Sigma of Yptar diff (mr)"); difyptarVdeltai_2->Draw(); cyptar->cd(2); difyptarVxptari->Draw("colz"); cyptar->cd(6); difyptarVxptari->FitSlicesY(); TH1D *difyptarVxptari_2 = (TH1D*)gDirectory->Get("difyptarVxptari_2"); difyptarVxptari_2->SetTitle(";Init Xptar; Fitted Sigma of Yptar diff (mr)"); difyptarVxptari_2->Draw(); cyptar->cd(3); difyptarVyptari->Draw("colz"); cyptar->cd(7); difyptarVyptari->FitSlicesY(); TH1D *difyptarVyptari_2 = (TH1D*)gDirectory->Get("difyptarVyptari_2"); difyptarVyptari_2->SetTitle(";Init Yptar; Fitted Sigma of Yptar diff (mr)"); difyptarVyptari_2->Draw(); cyptar->cd(9); difyptarVxfp->Draw("colz"); cyptar->cd(10); difyptarVyfp->Draw("colz"); cyptar->cd(11); difyptarVxpfp->Draw("colz"); cyptar->cd(12); difyptarVypfp->Draw("colz"); // TCanvas *cdelta = new TCanvas("cdelta"," Compare Recon/Inital delta 8 GeV, point target, no wire ch, no mscat",1400,1000); cdelta->Divide(4,3); cdelta->cd(4); difdelta->Draw(); cdelta->cd(1); difdeltaVdeltai->Draw("colz"); cdelta->cd(5); difdeltaVdeltai->FitSlicesY(); TH1D *difdeltaVdeltai_2 = (TH1D*)gDirectory->Get("difdeltaVdeltai_2"); difdeltaVdeltai_2->SetTitle(";Init Delta; Fitted Sigma of Delta diff (%)"); difdeltaVdeltai_2->Draw(); cdelta->cd(2); difdeltaVxptari->Draw("colz"); cdelta->cd(6); difdeltaVxptari->FitSlicesY(); TH1D *difdeltaVxptari_2 = (TH1D*)gDirectory->Get("difdeltaVxptari_2"); difdeltaVxptari_2->SetTitle(";Init Xptar; Fitted Sigma of Delta diff (%)"); difdeltaVxptari_2->Draw(); cdelta->cd(3); difdeltaVyptari->Draw("colz"); cdelta->cd(7); difdeltaVyptari->FitSlicesY(); TH1D *difdeltaVyptari_2 = (TH1D*)gDirectory->Get("difdeltaVyptari_2"); difdeltaVyptari_2->SetTitle(";Init Yptar; Fitted Sigma of Delta diff (%)"); difdeltaVyptari_2->Draw(); cdelta->cd(9); difdeltaVxfp->Draw("colz"); cdelta->cd(10); difdeltaVyfp->Draw("colz"); cdelta->cd(11); difdeltaVxpfp->Draw("colz"); cdelta->cd(12); difdeltaVypfp->Draw("colz"); // TCanvas *cytar = new TCanvas("cytar"," Compare Recon/Inital ytar 8 GeV, point target, no wire ch, no mscat",1400,1000); cytar->Divide(4,3); cytar->cd(4); difytar->Draw(); cytar->cd(1); difytarVdeltai->Draw("colz"); cytar->cd(5); difytarVdeltai->FitSlicesY(); TH1D *difytarVdeltai_2 = (TH1D*)gDirectory->Get("difytarVdeltai_2"); difytarVdeltai_2->SetTitle(";Init Delta; Fitted Sigma of Ytar diff (cm)"); difytarVdeltai_2->Draw(); cytar->cd(2); difytarVxptari->Draw("colz"); cytar->cd(6); difytarVxptari->FitSlicesY(); TH1D *difytarVxptari_2 = (TH1D*)gDirectory->Get("difytarVxptari_2"); difytarVxptari_2->SetTitle(";Init Xptar; Fitted Sigma of Ytar diff (cm)"); difytarVxptari_2->Draw(); cytar->cd(3); difytarVyptari->Draw("colz"); cytar->cd(7); difytarVyptari->FitSlicesY(); TH1D *difytarVyptari_2 = (TH1D*)gDirectory->Get("difytarVyptari_2"); difytarVyptari_2->SetTitle(";Init Yptar; Fitted Sigma of Ytar diff (cm)"); difytarVyptari_2->Draw(); cytar->cd(9); difytarVxfp->Draw("colz"); cytar->cd(10); difytarVyfp->Draw("colz"); cytar->cd(11); difytarVxpfp->Draw("colz"); cytar->cd(12); difytarVypfp->Draw("colz"); }
void checkRsnPIDqa(TString filename, TString foldername, Bool_t savePng, TString plotTPCpi, TString plotTPCka, TString plotTPCpro, TString plotTTOFpi, TString plotTOFka, TString plotTOFpro) { //Open input file TFile * fin = TFile::Open(filename.Data()); if (!fin) return 0x0; //Access output of specific wagon TList * list = (TList*) fin->Get(foldername.Data()); if (!list) return 0x0; //Set range for fit Float_t RangeFitMomMin = 0.1; //range in momentum where to check the mean and pull Float_t RangeFitMomMax = 2.0; Int_t xbinFitMin = 0; Int_t xbinFitMax = -1; Float_t RangeFitNsigmaPIDmin = -2.0; //range in Nsigma where the fit is to be performed Float_t RangeFitNsigmaPIDmax = 2.0; //Set range for visualisation Float_t RangeShowTPC[2] = {0.1, 2.0}; Float_t RangeShowTOF[2] = {0.25, 2.0}; //-------------------------- // TPC PID Nsigma // fit with simple gaussian //-------------------------- //Gaussian function TF1 *fGaus = new TF1("f","gaus", -7.0, 7.0); //--- pions TH2F * hTPCsigmaPi = (TH2F*)list->FindObject(plotTPCpi.Data()); hTPCsigmaPi->RebinX(2); hTPCsigmaPi->SetTitle("TPC Pions"); MakeUpHisto(hTPCsigmaPi,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2); hTPCsigmaPi->GetYaxis()->SetRangeUser(-5.1,5.1); hTPCsigmaPi->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]); xbinFitMin = hTPCsigmaPi->GetXaxis()->FindBin(RangeFitMomMin); xbinFitMax = hTPCsigmaPi->GetXaxis()->FindBin(RangeFitMomMax); hTPCsigmaPi->FitSlicesY(fGaus, xbinFitMin, xbinFitMax ); TH1D * hTPCsigmaPi_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCpi.Data())))->Clone("hNsigmaTPCpi_mean"); TH1D * hTPCsigmaPi_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCpi.Data())))->Clone("hNsigmaTPCpi_pull"); MakeUpHisto(hTPCsigmaPi_mean, "", "", 1, kBlack, 2); MakeUpHisto(hTPCsigmaPi_pull, "", "", 1, kRed+2, 2); //--- kaons TH2F * hTPCsigmaKa = (TH2F*)list->FindObject(plotTPCka.Data()); hTPCsigmaKa->RebinX(2); hTPCsigmaKa->SetTitle("TPC Kaons"); hTPCsigmaKa->GetYaxis()->SetRangeUser(-5.1,5.1); hTPCsigmaKa->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]); hTPCsigmaKa->FitSlicesY(fGaus, xbinFitMin, xbinFitMax ); MakeUpHisto(hTPCsigmaKa,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2); TH1D * hTPCsigmaKa_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCka.Data())))->Clone("hNsigmaTPCka_mean"); TH1D * hTPCsigmaKa_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCka.Data())))->Clone("hNsigmaTPCka_pull"); MakeUpHisto(hTPCsigmaKa_mean, "", "", 1, kBlack, 2); MakeUpHisto(hTPCsigmaKa_pull, "", "", 1, kRed+2, 2); //--- protons TH2F * hTPCsigmaPro = (TH2F*)list->FindObject(plotTPCpro.Data()); hTPCsigmaPro->RebinX(2); hTPCsigmaPro->SetTitle("TPC Protons"); MakeUpHisto(hTPCsigmaPro,"p_{TPC} (GeV/c)", "N#sigma_{TPC}", 1, kBlack, 2); hTPCsigmaPro->GetYaxis()->SetRangeUser(-5.1,5.1); hTPCsigmaPro->GetXaxis()->SetRangeUser(RangeShowTPC[0], RangeShowTPC[1]); hTPCsigmaPro->FitSlicesY(fGaus, xbinFitMin, xbinFitMax ); TH1D * hTPCsigmaPro_mean = ((TH1D*)gDirectory->FindObject(Form("%s_1", plotTPCpro.Data())))->Clone("hNsigmaTPCpro_mean"); TH1D * hTPCsigmaPro_pull = ((TH1D*)gDirectory->FindObject(Form("%s_2", plotTPCpro.Data())))->Clone("hNsigmaTPCpro_pull"); MakeUpHisto(hTPCsigmaPro_mean, "", "", 1, kBlack, 2); MakeUpHisto(hTPCsigmaPro_pull, "", "", 1, kRed+2, 2); //--- plot TPC TLine *l11=new TLine(RangeShowTPC[0],0.,RangeShowTPC[1],0.); l11->SetLineWidth(1); l11->SetLineStyle(7); TLine *l12=new TLine(RangeShowTPC[0],1.,RangeShowTPC[1],1.); l12->SetLineWidth(1); l12->SetLineStyle(7); gStyle->SetOptStat(0); TCanvas *cPidPerformance4 = new TCanvas("cPIDperformance4","TPC PID",1200,500); cPidPerformance4->Divide(3,1); cPidPerformance4->cd(1); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTPCsigmaPi->DrawCopy("colz"); hTPCsigmaPi_mean->DrawCopy("same"); hTPCsigmaPi_pull->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance4->cd(2); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTPCsigmaKa->DrawCopy("colz"); hTPCsigmaKa_mean->DrawCopy("same"); hTPCsigmaKa_pull->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance4->cd(3); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTPCsigmaPro->DrawCopy("colz"); hTPCsigmaPro_mean->DrawCopy("same"); hTPCsigmaPro_pull->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); TLegend * pidLegTPC = new TLegend(0.15,0.8,0.88,0.88); pidLegTPC->SetBorderSize(0); pidLegTPC->SetFillStyle(1001); pidLegTPC->SetFillColor(kWhite); pidLegTPC->SetTextSize(0.04); pidLegTPC->SetNColumns(2); pidLegTPC->AddEntry(hTPCsigmaPro_mean,"Mean","lp"); pidLegTPC->AddEntry(hTPCsigmaPro_pull,Form("#sigma, Gaus fit (%2.1f,%2.1f)",RangeFitNsigmaPIDmin,RangeFitNsigmaPIDmax),"lp"); pidLegTPC->Draw("same"); if (savePng) cPidPerformance4->SaveAs("RsnQA_TPC_Nsigma.png"); //---------------------------------------------------- // TOF // fit with signal model = gaussian + exponential tail //---------------------------------------------------- //Signal model for TOF signal = gaus + exp tail const Int_t npars = 6; TF1 *fSignalModel = new TF1("fSignalModel", TOFsignal, -7.0, 7.0, npars); fSignalModel->SetTitle("TOF Signal"); fSignalModel->SetParameter(0, 1.); fSignalModel->SetParameter(1, 0.); fSignalModel->SetParLimits(1, -2., 1.); fSignalModel->SetParameter(2, 1.); fSignalModel->SetParLimits(2, 0.5, 2.); fSignalModel->SetParameter(3, 1.); fSignalModel->SetParLimits(3, 0.5, 1.5); fSignalModel->SetParameter(4, 1.); fSignalModel->SetParLimits(4, 0., 1.e8); fSignalModel->SetParameter(5, 0.); fSignalModel->SetParLimits(5, -10., 10.); fSignalModel->SetNpx(2000); fSignalModel->SetParNames("Norm", "Mean", "Sigma", "Tail", "Shift", "Slope"/*, "Square"*/); fSignalModel->SetLineColor(kRed+1); //results TObjArray *results[3]; for(Int_t i = 0; i < 3; i++){ results[i] = new TObjArray(10); } TH1D * par[3][npars]; //--- pions TH2F * hTOFsigmaPi = (TH2F*)list->FindObject(plotTOFpi.Data()); hTOFsigmaPi->SetTitle("TOF Pions"); hTOFsigmaPi->RebinX(2); MakeUpHisto(hTOFsigmaPi,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2); hTOFsigmaPi->GetYaxis()->SetRangeUser(-5.1,5.1); hTOFsigmaPi->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]); fSignalModel->SetParLimits(4, 0., hTOFsigmaPi->GetMaximum()*0.5); fSignalModel->SetParLimits(0, 0., hTOFsigmaPi->GetMaximum()*1.2); hTOFsigmaPi->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] ); for(Int_t cc = 0; cc < npars ; cc++) { par[0][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFpi.Data(), cc)); } MakeUpHisto(par[0][1], "", "", 1, kBlue, 2); MakeUpHisto(par[0][2], "", "", 1, kMagenta+2, 2); //--- KAONS TH2F * hTOFsigmaKa = (TH2F*)list->FindObject(plotTOFka.Data()); hTOFsigmaKa->SetTitle("TOF Kaons"); hTOFsigmaKa->RebinX(2); MakeUpHisto(hTOFsigmaKa,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2); hTOFsigmaKa->GetYaxis()->SetRangeUser(-5.1,5.1); hTOFsigmaKa->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]); fSignalModel->SetParLimits(4, 0., hTOFsigmaKa->GetMaximum()*0.5); fSignalModel->SetParLimits(0, 0., hTOFsigmaKa->GetMaximum()*1.2); hTOFsigmaKa->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] ); for(Int_t cc = 0; cc < npars ; cc++) { par[1][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFka.Data(), cc)); } MakeUpHisto(par[1][1], "", "", 1, kBlue, 2); MakeUpHisto(par[1][2], "", "", 1, kMagenta+2, 2); //--- protons TH2F * hTOFsigmaPro = (TH2F*)list->FindObject(plotTOFpro.Data()); hTOFsigmaPro->SetTitle("TOF Protons"); hTOFsigmaPro->RebinX(2); MakeUpHisto(hTOFsigmaPro,"p (GeV/c)", "N#sigma_{TOF}", 1, kBlack, 2); hTOFsigmaPro->GetYaxis()->SetRangeUser(-5.1,5.1); hTOFsigmaPro->GetXaxis()->SetRangeUser(RangeShowTOF[0], RangeShowTOF[1]); fSignalModel->SetParLimits(4, 0., hTOFsigmaPro->GetMaximum()*0.5); fSignalModel->SetParLimits(0, 0., hTOFsigmaPro->GetMaximum()*1.2); hTOFsigmaPro->FitSlicesY(fSignalModel, xbinFitMin, xbinFitMax, 0, "QR", results[0] ); for(Int_t cc = 0; cc < npars ; cc++) { par[2][cc] = (TH1D*)gDirectory->FindObject(Form("%s_%i", plotTOFpro.Data(), cc)); } MakeUpHisto(par[2][1], "", "", 1, kBlue, 2); MakeUpHisto(par[2][2], "", "", 1, kMagenta+2, 2); //--- plot TOF gStyle->SetOptStat(0); TCanvas *cPidPerformance3 = new TCanvas("cPidPerformance3","TOF PID performance",1200,500); cPidPerformance3->Divide(3,1); cPidPerformance3->cd(1); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTOFsigmaPi->DrawCopy("colz"); if(par[0][1]) par[0][1]->DrawCopy("same"); if(par[0][2]) par[0][2]->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance3->cd(2); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTOFsigmaKa->DrawCopy("colz"); if(par[1][1]) par[1][1]->DrawCopy("same"); if(par[1][2]) par[1][2]->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); cPidPerformance3->cd(3); gPad->SetLogz(); gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy(); hTOFsigmaPro->DrawCopy("colz"); if(par[2][1]) par[2][1]->DrawCopy("same"); if(par[2][2]) par[2][2]->DrawCopy("same"); l11->Draw("same"); l12->Draw("same"); TLegend * pidLegTOF = new TLegend(0.15,0.8,0.88,0.88); pidLegTOF->SetBorderSize(0); pidLegTOF->SetFillStyle(1001); pidLegTOF->SetFillColor(kWhite); pidLegTOF->SetTextSize(0.04); pidLegTOF->SetNColumns(2); pidLegTOF->AddEntry(par[0][1],"Mean","lp"); pidLegTOF->AddEntry(par[0][2], Form("#sigma, Gaus+Tail fit (%2.1f,%2.1f)",RangeFitNsigmaPIDmin, RangeFitNsigmaPIDmax),"lp"); pidLegTOF->Draw("same"); if (savePng) cPidPerformance3->Print("RsnQA_TOF_Nsigma.png"); return; }
int main(int argc, char * argv[]) { TFile *f = new TFile(argv[1]); TFile *f2 = new TFile(argv[2]); TTree *tree = (TTree*) f->Get("adc"); // TCut CutXYZ = TCut; // TCut CutTrigger; TCutG *CutZX = (TCutG*) f2->Get("cutg_0_3_B2"); TCutG *CutZY = (TCutG*) f2->Get("cutg_1_3_B2"); TCut broadCut = "ch6 > 1100"; TCut crystal = "FloodX > -1.5 && FloodX < -1 && FloodY > -1.45 &&FloodY < -0.9"; // TCut crystal = "FloodX > -4 && FloodX < -3.6 && FloodY > -1.28 &&FloodY < -1.02"; TCut photopeak = "ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 > 9500 && ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 < 12500"; // TCut photopeak = "ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 > 8500 && ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 < 11000"; TCut trigger = "TriggerChannel == 6"; // TCut trigger = "TriggerChannel == 2"; std::string w = "ch6/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15)"; // std::string w = "ch2/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15)"; TCut wCut = "FloodZ > 0.3 && FloodZ < 0.5"; TH1F *h = new TH1F("h","h",1000,0,35000); TH1F *hSum = new TH1F("hSum","hSum",1000,0,35000); TH1F *hCorrSig = new TH1F("hCorrSig","hCorrSig",1000,0,35000); TH1F *hCorrLinear = new TH1F("hCorrLinear","hCorrLinear",1000,0,35000); TH2F *h2 =new TH2F ("h2","h2",1000,-7,7,1000,-7,7); TH3I *h3 = new TH3I("h3","h3",100,-3,0,100,-3,0,100,0,1); TH1F *hAll = new TH1F("hAll","hAll",500,0,1); TH1F *hNear = new TH1F("hNear","hNear",500,0,1); TH1F *hFloodZ = new TH1F("hFloodZ","hFloodZ",500,0,1); TH2F *scatter = new TH2F("scatter","scatter",500,0,1,500,0,1); TH2F *correction = new TH2F("correction","correction",500,0,1,1000,0,35000); TCanvas *multi = new TCanvas("multi","multi",1800,1200); multi->Divide(3,3); multi->cd(1); // h2->GetXaxis()->SetRangeUser(-4.1,-3.5); // h2->GetYaxis()->SetRangeUser(-1.3,-1.0); // std::cout << "quiiiiiiiiiiiiiiiiii" << std::endl; tree->Draw("FloodZ:FloodY:FloodX >> h3",broadCut+trigger+CutZX->GetName()+CutZY->GetName()); // std::cout << "dopo" << std::endl; h2->GetXaxis()->SetRangeUser(-1.5,-1); h2->GetYaxis()->SetRangeUser(-1.45,-0.9); h3->GetXaxis()->SetRangeUser(-3,0); h3->GetYaxis()->SetRangeUser(-3,0); // tree->Draw("FloodY:FloodX >> h2","","COLZ"); // multi->cd(2); // tree->Draw("ch1+ch2+ch3+ch5+ch6+ch7+ch9+ch10+ch11 >> h",crystal); multi->cd(2); tree->Draw("ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 >> hSum",broadCut+trigger+CutZX->GetName()+CutZY->GetName()); multi->cd(3); // tree->Draw("ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 : ch2/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) >> correction",crystal+photopeak,"COLZ"); tree->Draw("ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 : FloodZ >> correction",trigger+photopeak+broadCut+CutZX->GetName()+CutZY->GetName(),"COLZ"); multi->cd(4); correction->FitSlicesY(0, 0, -1, 0, "RQ"); TH1D *spectrum2d_1 = (TH1D*)gDirectory->Get("correction_1"); // _1 is the TH1D automatically created by ROOT when FitSlicesX is called, holding the TH1F of the mean values spectrum2d_1->GetYaxis()->SetRangeUser(10200,11400); TF1 *sig1 = new TF1("sig1", sigmoid,0,1,4); sig1->SetParameter( 0, 10500); sig1->SetParameter( 1, 700); sig1->SetParameter( 2, 30); sig1->SetParameter( 3, 0.4); double a = sig1->GetParameter(0); double b = sig1->GetParameter(1); double c = sig1->GetParameter(2); double d = sig1->GetParameter(3); spectrum2d_1->Fit(sig1,"QR"); double medianPoint = d - (1/c)*TMath::Log(3); medianPoint = 0.3966; std::cout << "medianPoint = " << medianPoint << std::endl; multi->cd(5); std::stringstream baseVar,var; std::stringstream sSig0,sSigw; sSig0 << "(" << a << " + (" << b << " * ( 0.5 - 1/(1 + TMath::Exp( -" << c << " * ( " << medianPoint << " - " << d << ") ) ) ) ) ) "; sSigw << "(" << a << " + (" << b << " * ( 0.5 - 1/(1 + TMath::Exp( -" << c << " * ( " << "FloodZ" << " - " << d << ") ) ) ) ) )"; baseVar << "((ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) * (" << sSig0.str() << " / " << sSigw.str() << "))"; // baseVar << "((ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) + ( " // << b // << " * ( 0.5 - 1/(1 + TMath::Exp( -" // << c // << " * ( " // << "FloodZ" // << " - " // << d // << ") ) ) ) )) "; var << baseVar.str() << ">> hCorrSig"; tree->Draw(var.str().c_str(),broadCut+trigger+CutZX->GetName()+CutZY->GetName()); TF1 *gauss = new TF1("gauss","[0]*exp(-0.5*((x-[1])/[2])**2)",10000,12000); gauss->SetParameter(0,1600); gauss->SetParameter(1,10000); gauss->SetParameter(2,600); hCorrSig->Fit(gauss,"RQ"); std::stringstream cutPeakSig ; cutPeakSig << baseVar.str() << ">" << gauss->GetParameter(1) - 4.0*gauss->GetParameter(2) << " && " << baseVar.str() << "<" << gauss->GetParameter(1) + 4.0*gauss->GetParameter(2) ; TCut photopeakCorrSig = cutPeakSig.str().c_str(); TH1F *clone = new TH1F("clone","clone",1000,0,35000); clone->SetFillStyle(3001); clone->SetFillColor(3); var.str(""); var << baseVar.str() << ">> clone"; tree->Draw(var.str().c_str(),broadCut+trigger+CutZX->GetName()+CutZY->GetName()+photopeakCorrSig,"same"); // clone->Draw("same"); var.str(""); multi->cd(7); TH1D* spectrum2d_1_copy = (TH1D*) spectrum2d_1->Clone(); spectrum2d_1_copy->Draw(); spectrum2d_1_copy->GetYaxis()->SetRangeUser(10200,11400); TF1 *linearCrystal = new TF1("linearCrystal", "[0]*x + [1]",0.35,0.42); spectrum2d_1_copy->Fit(linearCrystal,"RQ"); multi->cd(8); baseVar.str(""); baseVar << "(( ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 ) * ( (" << linearCrystal->GetParameter(0) * medianPoint + linearCrystal->GetParameter(1) << ") / (" << linearCrystal->GetParameter(0) << "* FloodZ + "<< linearCrystal->GetParameter(1) << " ))) >> hCorrLinear"; // baseVar << "(( ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 ) - ( (" << w << " - " << d - (1/c)*TMath::Log(1 + (b/(a+(b/2) -a))) << " ) * ( " << linearCrystal->GetParameter(0) << ") )) >> hCorrLinear"; tree->Draw(baseVar.str().c_str(),broadCut+trigger+CutZX->GetName()+CutZY->GetName()); // TF1 *gauss2 = new TF1("gauss2","[0]*exp(-0.5*((x-[1])/[2])**2)",10000,12000); // gauss2->SetParameter(0,1600); // gauss2->SetParameter(1,10000); // gauss2->SetParameter(2,600); // hCorrLinear->Fit(gauss2,"RQ"); // multi->cd(7); // tree->Draw("FloodZ >> hFloodZ",crystal+photopeak); // TF1 *fit1 = new TF1("fit1",thetaFunction,0,1,3); // fit1->SetParameter( 0, 0.36); // on this w histo, the first bin above 20% max // fit1->SetParameter( 1, 0.54); // on this w histo, the last bin above 20% max // fit1->SetParameter( 2, 1200); // hFloodZ->Fit(fit1,"R"); multi->cd(6); tree->Draw("ch6/(ch1+ch2+ch3+ch5+ch6+ch7+ch9+ch10+ch11) >> hNear",broadCut+ photopeakCorrSig+CutZX->GetName()+CutZY->GetName()); TF1 *fit2 = new TF1("fit2",thetaFunction,0,1,3); fit2->SetParameter( 0, 0.36); // on this w histo, the first bin above 20% max fit2->SetParameter( 1, 0.54); // on this w histo, the last bin above 20% max fit2->SetParameter( 2, 1200); hNear->Fit(fit2,"RQ"); multi->cd(9); tree->Draw("ch6/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) >> hAll",broadCut+photopeakCorrSig+CutZX->GetName()+CutZY->GetName()); TF1 *fit3 = new TF1("fit1",thetaFunction,0,1,3); fit3->SetParameter( 0, 0.1); // on this w histo, the first bin above 20% max fit3->SetParameter( 1, 0.8); // on this w histo, the last bin above 20% max fit3->SetParameter( 2, 1200); hAll->Fit(fit3,"RQ"); std::cout << linearCrystal->GetParameter(0) << " " << linearCrystal->GetParameter(1) << std::endl; std::cout << fit2->GetParameter(0) << " " << fit2->GetParameter(1) << std::endl; std::cout << fit3->GetParameter(0) << " " << fit3->GetParameter(1) << std::endl; std::cout << "Energy Resolution Corrected (Sigmoid) = " << gauss->GetParameter(2)*2.355 / gauss->GetParameter(1) << std::endl; std::cout << "Near Channels - Delta w = " << fit2->GetParameter(1) - fit2->GetParameter(0) << std::endl; std::cout << "All Channels - Delta w = " << fit3->GetParameter(1) - fit3->GetParameter(0) << std::endl; TFile *fOut= new TFile("afile.root","RECREATE"); fOut->cd(); multi->Write(); fOut->Close(); return 0; }