void GaussianProfile::getTruncatedMeanRMS(TH1* hist, float& mean, float& mean_error, float& rms, float& rms_error) { int nBins = hist->GetNbinsX(); double xMin = hist->GetXaxis()->GetXmin(); double xMax = hist->GetXaxis()->GetXmax(); //double binWidth = (xMax - xMin) / (double) nBins; //WARNING: this works only if bins are of the same size double integral = hist->Integral(); int maxBin = 0; TF1* gaussian = new TF1("gaussian", "gaus"); fitProjection(hist, gaussian, 1.5, "RQN"); //maxBin = (int) ceil((gaussian->GetParameter(1) - xMin) / binWidth); maxBin = hist->FindBin(gaussian->GetParameter(1)); delete gaussian; TH1D* newHisto = new TH1D("newHisto", "", nBins, xMin, xMax); newHisto->SetBinContent(maxBin, hist->GetBinContent(maxBin)); newHisto->SetBinError(maxBin, hist->GetBinError(maxBin)); int iBin = maxBin; int delta_iBin = 1; int sign = 1; while (newHisto->Integral() < 0.99 * integral) { iBin += sign * delta_iBin; newHisto->SetBinContent(iBin, hist->GetBinContent(iBin)); newHisto->SetBinError(iBin, hist->GetBinError(iBin)); delta_iBin += 1; sign *= -1; } rms = newHisto->GetRMS(); rms_error = newHisto->GetRMSError(); while (newHisto->Integral() < 0.99 * integral) { iBin += sign * delta_iBin; newHisto->SetBinContent(iBin, hist->GetBinContent(iBin)); newHisto->SetBinError(iBin, hist->GetBinError(iBin)); delta_iBin += 1; sign *= -1; } mean = newHisto->GetMean(); mean_error = newHisto->GetMeanError(); delete newHisto; }
void fitTools::getTruncatedMeanAndRMS(TH1D* h1_projection, Float_t& mean, Float_t& mean_err, Float_t& rms, Float_t& rms_err, Double_t percentIntegral_MEAN, Double_t percentIntegral_RMS) { //TCanvas* getTruncatedMeanAndRMS(TH1D* h1_projection, Float_t& mean, Float_t& mean_err, Float_t& rms, Float_t& rms_err, Double_t percentIntegral_MEAN=0.9, Double_t percentIntegral_RMS=0.68) { bool useMode = false; if( percentIntegral_MEAN<0. || percentIntegral_MEAN>1. ) { std::cout << "WARNING! percentIntegral_MEAN is " << percentIntegral_MEAN << "!! Setting it to 90%." << std::endl; percentIntegral_MEAN = 0.9; } if( percentIntegral_RMS<0. || percentIntegral_RMS>1. ) { std::cout << "WARNING! percentIntegral_RMS is " << percentIntegral_RMS << "!! Setting it to 68%." << std::endl; percentIntegral_RMS = 0.68; } Int_t nBins = h1_projection->GetNbinsX(); Double_t xMin = h1_projection->GetXaxis()->GetXmin(); Double_t xMax = h1_projection->GetXaxis()->GetXmax(); Double_t binWidth = (xMax-xMin)/(Double_t)nBins; //WARNING: this works only if bins are of the same size Double_t integral = h1_projection->Integral(); // std::cout << "xmax: " << xMax << "\txMin: " << xMin << std::endl; //first: find maximum // std::cout << "N: " << gaussian->GetParameter(0) << "\tmu: " << gaussian->GetParameter(1) << "\tsigma: " << gaussian->GetParameter(2) << std::endl; Int_t maxBin; if( useMode ) { maxBin = h1_projection->GetMaximumBin(); } else { TF1* gaussian = new TF1("gaussian", "gaus"); gaussian->SetLineColor(kGreen); fitProjection(h1_projection, gaussian, 1.5, "RQN"); maxBin = (Int_t)ceil((gaussian->GetParameter(1)-xMin)/binWidth); delete gaussian; } // std::cout << "maxBin: " << maxBin << "\tbin center: " << h1_projection->GetXaxis()->GetBinCenter(maxBin) << "\t gauss mu: " << gaussian->GetParameter(1) << std::endl; TH1D* newHisto = new TH1D("newHisto", "", nBins, xMin, xMax); newHisto->SetBinContent( maxBin, h1_projection->GetBinContent(maxBin) ); newHisto->SetBinError( maxBin, h1_projection->GetBinError(maxBin) ); Int_t iBin = maxBin; Int_t delta_iBin = 1; Int_t sign = 1; // std::cout << "iBin: " << iBin << "\tint: " << newHisto->Integral()/integral << std::endl; while( newHisto->Integral() < percentIntegral_RMS*integral ) { iBin += sign*delta_iBin; // std::cout << "iBin: " << iBin << "\tint: " << newHisto->Integral()/integral << std::endl; newHisto->SetBinContent( iBin, h1_projection->GetBinContent(iBin) ); newHisto->SetBinError( iBin, h1_projection->GetBinError(iBin) ); delta_iBin += 1; sign *= -1; } // std::cout << "done with rms." << std::endl; // TCanvas* c1 = new TCanvas("c1", "c1", 800, 600); // c1->cd(); // h1_projection->Draw(); // newHisto->SetFillColor(kRed); // newHisto->DrawClone("HISTO same"); rms = newHisto->GetRMS(); rms_err = newHisto->GetRMSError(); //std::cout << "rms: " << rms << std::endl; while( newHisto->Integral() < percentIntegral_MEAN*integral ) { // std::cout << "iBin: " << iBin << "\tint: " << newHisto->Integral()/integral << std::endl; iBin += sign*delta_iBin; newHisto->SetBinContent( iBin, h1_projection->GetBinContent(iBin) ); newHisto->SetBinError( iBin, h1_projection->GetBinError(iBin) ); delta_iBin += 1; sign *= -1; } // newHisto->SetFillStyle(3004); // newHisto->SetFillColor(kBlue); // newHisto->DrawClone("HISTO same"); mean = newHisto->GetMean(); mean_err = newHisto->GetMeanError(); delete newHisto; // return c1; }
int makeGraphMC(){ TGraphErrors * graph; double x[7],y[7],xErr[7],yErr[7]; TH2D* histo2D; TFile *file = TFile::Open("PhotonPtNVtx_2d_PF_mc.root"); file->GetObject("Photon Pt against Number of Vertices",histo2D); TH1D * histoVtx = (TH1D*)histo2D->ProjectionY("histoVtx",0,1200); TH1D* histo1D = (TH1D*)histo2D->ProjectionX("histo1D",1,5); TH1D* histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histoVtxPart->SetBinContent(1,histoVtx->GetBinContent(1)); histoVtxPart->SetBinContent(2,histoVtx->GetBinContent(2)); histoVtxPart->SetBinContent(3,histoVtx->GetBinContent(3)); histoVtxPart->SetBinContent(4,histoVtx->GetBinContent(4)); histoVtxPart->SetBinContent(5,histoVtx->GetBinContent(5)); y[0] = histo1D->GetMean(); yErr[0] = histo1D->GetMeanError(); x[0] = histoVtxPart->GetMean(); xErr[0] = histoVtxPart->GetMeanError(); cout<<"x0 = "<<x[0]<<endl; cout<<"x0Err = "<<xErr[0]<<endl; delete histoVtxPart; histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histo1D = (TH1D*)histo2D->ProjectionX("bla",6,10); histoVtxPart->SetBinContent(6,histoVtx->GetBinContent(6)); histoVtxPart->SetBinContent(7,histoVtx->GetBinContent(7)); histoVtxPart->SetBinContent(8,histoVtx->GetBinContent(8)); histoVtxPart->SetBinContent(9,histoVtx->GetBinContent(9)); histoVtxPart->SetBinContent(10,histoVtx->GetBinContent(10)); y[1] = histo1D->GetMean(); yErr[1] = histo1D->GetMeanError(); x[1] = histoVtxPart->GetMean(); xErr[1] = histoVtxPart->GetMeanError(); delete histoVtxPart; histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histo1D = (TH1D*)histo2D->ProjectionX("bla",11,15); histoVtxPart->SetBinContent(11,histoVtx->GetBinContent(11)); histoVtxPart->SetBinContent(12,histoVtx->GetBinContent(12)); histoVtxPart->SetBinContent(13,histoVtx->GetBinContent(13)); histoVtxPart->SetBinContent(14,histoVtx->GetBinContent(14)); histoVtxPart->SetBinContent(15,histoVtx->GetBinContent(15)); y[2] = histo1D->GetMean(); yErr[2] = histo1D->GetMeanError(); x[2] = histoVtxPart->GetMean(); xErr[2] = histoVtxPart->GetMeanError(); delete histoVtxPart; histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histo1D = (TH1D*)histo2D->ProjectionX("bla",16,20); histoVtxPart->SetBinContent(16,histoVtx->GetBinContent(16)); histoVtxPart->SetBinContent(17,histoVtx->GetBinContent(17)); histoVtxPart->SetBinContent(18,histoVtx->GetBinContent(18)); histoVtxPart->SetBinContent(19,histoVtx->GetBinContent(19)); histoVtxPart->SetBinContent(20,histoVtx->GetBinContent(20)); y[3] = histo1D->GetMean(); yErr[3] = histo1D->GetMeanError(); x[3] = histoVtxPart->GetMean(); xErr[3] = histoVtxPart->GetMeanError(); delete histoVtxPart; histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histo1D = (TH1D*)histo2D->ProjectionX("bla",21,25); histoVtxPart->SetBinContent(21,histoVtx->GetBinContent(21)); histoVtxPart->SetBinContent(22,histoVtx->GetBinContent(22)); histoVtxPart->SetBinContent(23,histoVtx->GetBinContent(23)); histoVtxPart->SetBinContent(24,histoVtx->GetBinContent(24)); histoVtxPart->SetBinContent(25,histoVtx->GetBinContent(25)); y[4] = histo1D->GetMean(); yErr[4] = histo1D->GetMeanError(); x[4] = histoVtxPart->GetMean(); xErr[4] = histoVtxPart->GetMeanError(); delete histoVtxPart; histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histo1D = (TH1D*)histo2D->ProjectionX("bla",26,30); histoVtxPart->SetBinContent(26,histoVtx->GetBinContent(26)); histoVtxPart->SetBinContent(27,histoVtx->GetBinContent(27)); histoVtxPart->SetBinContent(28,histoVtx->GetBinContent(28)); histoVtxPart->SetBinContent(29,histoVtx->GetBinContent(29)); histoVtxPart->SetBinContent(30,histoVtx->GetBinContent(30)); y[5] = histo1D->GetMean(); yErr[5] = histo1D->GetMeanError(); x[5] = histoVtxPart->GetMean(); xErr[5] = histoVtxPart->GetMeanError(); delete histoVtxPart; histoVtxPart = new TH1D("vtx","vtx_part",60,1,60); histo1D = (TH1D*)histo2D->ProjectionX("bla",31,35); histoVtxPart->SetBinContent(31,histoVtx->GetBinContent(31)); histoVtxPart->SetBinContent(32,histoVtx->GetBinContent(32)); histoVtxPart->SetBinContent(33,histoVtx->GetBinContent(33)); histoVtxPart->SetBinContent(34,histoVtx->GetBinContent(34)); histoVtxPart->SetBinContent(35,histoVtx->GetBinContent(35)); y[6] = histo1D->GetMean(); yErr[6] = histo1D->GetMeanError(); x[6] = histoVtxPart->GetMean(); xErr[6] = histoVtxPart->GetMeanError(); graph = new TGraphErrors(7,x,y,xErr,yErr); TF1* f1 = new TF1("pol1","pol1"); graph -> Fit(f1,"Q","",5.0,35.0); char legEntry[100]; cout<<"par0 = "<<f1->GetParameter(0)<<endl; cout<<"par1 = "<<f1->GetParameter(1)<<endl; sprintf(legEntry,"%4.2f + %4.2f (#pm %4.2f) * x",f1->GetParameter(0),f1->GetParameter(1),f1->GetParError(1)); TLegend* leg_hist = 0 ; leg_hist = new TLegend(0.5,0.75,0.9,0.9); leg_hist->SetTextSize(0.033); leg_hist->SetHeader(legEntry); leg_hist -> SetFillColor(0); graph -> SetTitle("Pile-up dependence of Photon pT (MC)"); graph -> GetXaxis() -> SetTitle("#Vtx"); graph -> GetYaxis() -> SetTitle("Photon pT"); graph -> SetMaximum(230); graph -> GetYaxis() -> SetTitleOffset(1.3); TCanvas* canvas = new TCanvas("c","c",0,0,500,500); canvas ->cd(); graph->Draw("AP"); leg_hist->Draw("same"); canvas->SaveAs("PUDependence_MC.pdf"); return 0; }
void recenter() { TFile* f = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/chargedepcorr_cent4050_pttrg033_ptassallweight_etaass445_eff0_bin03_v20.root"); // TFile* f = new TFile("/net/hisrv0001/home/davidlw/OSG_CMSSW/CMSSW_5_3_20/src/FlowCorrAna/DiHadronCorrelationAnalyzer/cfg/chargedepcorr_recenter.root"); // TFile* f = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/chargedepcorr_recenter_mc_cent080_pttrg033_ptassallweight_etaass445_eff0_v16.root"); const int ntrg = 1; const int MAXETATRGBINSPT = 16; TString dirname("chargedepcorr_ana_HI"); TH1D* hSumNTrgPos[ntrg]; TH1D* hSumNTrgNeg[ntrg]; TH1D* hSumNCosTrgPos[ntrg]; TH1D* hSumNCosTrgNeg[ntrg]; TH1D* hSumNSinTrgPos[ntrg]; TH1D* hSumNSinTrgNeg[ntrg]; TH1D* hSumNCos2TrgPos[ntrg]; TH1D* hSumNCos2TrgNeg[ntrg]; TH1D* hSumNSin2TrgPos[ntrg]; TH1D* hSumNSin2TrgNeg[ntrg]; TH1D* hSumTrgPos[MAXETATRGBINSPT][ntrg]; TH1D* hSumTrgNeg[MAXETATRGBINSPT][ntrg]; TH1D* hSumCosTrgPos[MAXETATRGBINSPT][ntrg]; TH1D* hSumSinTrgPos[MAXETATRGBINSPT][ntrg]; TH1D* hSumCosTrgNeg[MAXETATRGBINSPT][ntrg]; TH1D* hSumSinTrgNeg[MAXETATRGBINSPT][ntrg]; TH1D* hSumCos2TrgPos[MAXETATRGBINSPT][ntrg]; TH1D* hSumSin2TrgPos[MAXETATRGBINSPT][ntrg]; TH1D* hSumCos2TrgNeg[MAXETATRGBINSPT][ntrg]; TH1D* hSumSin2TrgNeg[MAXETATRGBINSPT][ntrg]; TH1D* hSumAssFor = (TH1D*)f->Get(Form("%s/sumassfor",dirname.Data())); TH1D* hSumAssBak = (TH1D*)f->Get(Form("%s/sumassbak",dirname.Data())); TH1D* hSumCosAssFor = (TH1D*)f->Get(Form("%s/sumcosassfor",dirname.Data())); TH1D* hSumSinAssFor = (TH1D*)f->Get(Form("%s/sumsinassfor",dirname.Data())); TH1D* hSumCosAssBak = (TH1D*)f->Get(Form("%s/sumcosassbak",dirname.Data())); TH1D* hSumSinAssBak = (TH1D*)f->Get(Form("%s/sumsinassbak",dirname.Data())); TH1D* hSumCos2AssFor = (TH1D*)f->Get(Form("%s/sumcos2assfor",dirname.Data())); TH1D* hSumSin2AssFor = (TH1D*)f->Get(Form("%s/sumsin2assfor",dirname.Data())); TH1D* hSumCos2AssBak = (TH1D*)f->Get(Form("%s/sumcos2assbak",dirname.Data())); TH1D* hSumSin2AssBak = (TH1D*)f->Get(Form("%s/sumsin2assbak",dirname.Data())); for(int itrg=0;itrg<ntrg;itrg++) { hSumNTrgPos[itrg] = new TH1D(Form("sumntrgpos_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNTrgNeg[itrg] = new TH1D(Form("sumntrgneg_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNCosTrgPos[itrg] = new TH1D(Form("sumncostrgpos_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNCosTrgNeg[itrg] = new TH1D(Form("sumncostrgneg_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNSinTrgPos[itrg] = new TH1D(Form("sumnsintrgpos_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNSinTrgNeg[itrg] = new TH1D(Form("sumnsintrgneg_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNCos2TrgPos[itrg] = new TH1D(Form("sumncos2trgpos_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNCos2TrgNeg[itrg] = new TH1D(Form("sumncos2trgneg_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNSin2TrgPos[itrg] = new TH1D(Form("sumnsin2trgpos_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); hSumNSin2TrgNeg[itrg] = new TH1D(Form("sumnsin2trgneg_pt%d",itrg),";#eta",MAXETATRGBINSPT+2,-2.4-4.8/MAXETATRGBINSPT,2.4+4.8/MAXETATRGBINSPT); for(int ll=0;ll<MAXETATRGBINSPT;ll++) { hSumTrgPos[ll][itrg] = (TH1D*)f->Get(Form("%s/sumtrgpos_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumTrgNeg[ll][itrg] = (TH1D*)f->Get(Form("%s/sumtrgneg_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumCosTrgPos[ll][itrg] = (TH1D*)f->Get(Form("%s/sumcostrgpos_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumSinTrgPos[ll][itrg] = (TH1D*)f->Get(Form("%s/sumsintrgpos_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumCosTrgNeg[ll][itrg] = (TH1D*)f->Get(Form("%s/sumcostrgneg_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumSinTrgNeg[ll][itrg] = (TH1D*)f->Get(Form("%s/sumsintrgneg_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumCos2TrgPos[ll][itrg] = (TH1D*)f->Get(Form("%s/sumcos2trgpos_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumSin2TrgPos[ll][itrg] = (TH1D*)f->Get(Form("%s/sumsin2trgpos_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumCos2TrgNeg[ll][itrg] = (TH1D*)f->Get(Form("%s/sumcos2trgneg_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumSin2TrgNeg[ll][itrg] = (TH1D*)f->Get(Form("%s/sumsin2trgneg_eta%d_pt%d",dirname.Data(),ll,itrg)); hSumNTrgPos[itrg]->SetBinContent(ll+2,hSumTrgPos[ll][itrg]->GetMean()); hSumNTrgPos[itrg]->SetBinError(ll+2,hSumTrgPos[ll][itrg]->GetMeanError()); hSumNTrgNeg[itrg]->SetBinContent(ll+2,hSumTrgNeg[ll][itrg]->GetMean()); hSumNTrgNeg[itrg]->SetBinError(ll+2,hSumTrgNeg[ll][itrg]->GetMeanError()); hSumNCosTrgPos[itrg]->SetBinContent(ll+2,hSumCosTrgPos[ll][itrg]->GetMean()); hSumNCosTrgPos[itrg]->SetBinError(ll+2,hSumCosTrgPos[ll][itrg]->GetMeanError()); hSumNSinTrgPos[itrg]->SetBinContent(ll+2,hSumSinTrgPos[ll][itrg]->GetMean()); hSumNSinTrgPos[itrg]->SetBinError(ll+2,hSumSinTrgPos[ll][itrg]->GetMeanError()); hSumNCosTrgNeg[itrg]->SetBinContent(ll+2,hSumCosTrgNeg[ll][itrg]->GetMean()); hSumNCosTrgNeg[itrg]->SetBinError(ll+2,hSumCosTrgNeg[ll][itrg]->GetMeanError()); hSumNSinTrgNeg[itrg]->SetBinContent(ll+2,hSumSinTrgNeg[ll][itrg]->GetMean()); hSumNSinTrgNeg[itrg]->SetBinError(ll+2,hSumSinTrgNeg[ll][itrg]->GetMeanError()); hSumNCos2TrgPos[itrg]->SetBinContent(ll+2,hSumCos2TrgPos[ll][itrg]->GetMean()); hSumNCos2TrgPos[itrg]->SetBinError(ll+2,hSumCos2TrgPos[ll][itrg]->GetMeanError()); hSumNSin2TrgPos[itrg]->SetBinContent(ll+2,hSumSin2TrgPos[ll][itrg]->GetMean()); hSumNSin2TrgPos[itrg]->SetBinError(ll+2,hSumSin2TrgPos[ll][itrg]->GetMeanError()); hSumNCos2TrgNeg[itrg]->SetBinContent(ll+2,hSumCos2TrgNeg[ll][itrg]->GetMean()); hSumNCos2TrgNeg[itrg]->SetBinError(ll+2,hSumCos2TrgNeg[ll][itrg]->GetMeanError()); hSumNSin2TrgNeg[itrg]->SetBinContent(ll+2,hSumSin2TrgNeg[ll][itrg]->GetMean()); hSumNSin2TrgNeg[itrg]->SetBinError(ll+2,hSumSin2TrgNeg[ll][itrg]->GetMeanError()); } hSumNTrgPos[itrg]->SetBinContent(1,hSumAssFor->GetMean()); hSumNTrgPos[itrg]->SetBinError(1,hSumAssFor->GetMeanError()); hSumNTrgNeg[itrg]->SetBinContent(1,hSumAssFor->GetMean()); hSumNTrgNeg[itrg]->SetBinError(1,hSumAssFor->GetMeanError()); hSumNTrgPos[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumAssBak->GetMean()); hSumNTrgPos[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumAssBak->GetMeanError()); hSumNTrgNeg[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumAssBak->GetMean()); hSumNTrgNeg[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumAssBak->GetMeanError()); hSumNCosTrgPos[itrg]->SetBinContent(1,hSumCosAssFor->GetMean()); hSumNCosTrgPos[itrg]->SetBinError(1,hSumCosAssFor->GetMeanError()); hSumNCosTrgPos[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumCosAssBak->GetMean()); hSumNCosTrgPos[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumCosAssBak->GetMeanError()); hSumNSinTrgPos[itrg]->SetBinContent(1,hSumSinAssFor->GetMean()); hSumNSinTrgPos[itrg]->SetBinError(1,hSumSinAssFor->GetMeanError()); hSumNSinTrgPos[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumSinAssBak->GetMean()); hSumNSinTrgPos[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumSinAssBak->GetMeanError()); hSumNCosTrgNeg[itrg]->SetBinContent(1,hSumCosAssFor->GetMean()); hSumNCosTrgNeg[itrg]->SetBinError(1,hSumCosAssFor->GetMeanError()); hSumNCosTrgNeg[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumCosAssBak->GetMean()); hSumNCosTrgNeg[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumCosAssBak->GetMeanError()); hSumNSinTrgNeg[itrg]->SetBinContent(1,hSumSinAssFor->GetMean()); hSumNSinTrgNeg[itrg]->SetBinError(1,hSumSinAssFor->GetMeanError()); hSumNSinTrgNeg[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumSinAssBak->GetMean()); hSumNSinTrgNeg[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumSinAssBak->GetMeanError()); hSumNCos2TrgPos[itrg]->SetBinContent(1,hSumCos2AssFor->GetMean()); hSumNCos2TrgPos[itrg]->SetBinError(1,hSumCos2AssFor->GetMeanError()); hSumNCos2TrgPos[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumCos2AssBak->GetMean()); hSumNCos2TrgPos[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumCos2AssBak->GetMeanError()); hSumNSin2TrgPos[itrg]->SetBinContent(1,hSumSin2AssFor->GetMean()); hSumNSin2TrgPos[itrg]->SetBinError(1,hSumSin2AssFor->GetMeanError()); hSumNSin2TrgPos[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumSin2AssBak->GetMean()); hSumNSin2TrgPos[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumSin2AssBak->GetMeanError()); hSumNCos2TrgNeg[itrg]->SetBinContent(1,hSumCos2AssFor->GetMean()); hSumNCos2TrgNeg[itrg]->SetBinError(1,hSumCos2AssFor->GetMeanError()); hSumNCos2TrgNeg[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumCos2AssBak->GetMean()); hSumNCos2TrgNeg[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumCos2AssBak->GetMeanError()); hSumNSin2TrgNeg[itrg]->SetBinContent(1,hSumSin2AssFor->GetMean()); hSumNSin2TrgNeg[itrg]->SetBinError(1,hSumSin2AssFor->GetMeanError()); hSumNSin2TrgNeg[itrg]->SetBinContent(MAXETATRGBINSPT+2,hSumSin2AssBak->GetMean()); hSumNSin2TrgNeg[itrg]->SetBinError(MAXETATRGBINSPT+2,hSumSin2AssBak->GetMeanError()); } return; TFile* fout = new TFile("recenter_cent4050_pttrg033_etaass445_eff0_bin03.root","recreate"); // TFile* fout = new TFile("recenter_mc_cent080_pttrg033_etaass445_eff0_bin03.root","recreate"); for(int itrg=0;itrg<ntrg;itrg++) { hSumNTrgPos[itrg]->Write(); hSumNTrgNeg[itrg]->Write(); hSumNCosTrgPos[itrg]->Write(); hSumNCosTrgNeg[itrg]->Write(); hSumNSinTrgPos[itrg]->Write(); hSumNSinTrgNeg[itrg]->Write(); hSumNCos2TrgPos[itrg]->Write(); hSumNCos2TrgNeg[itrg]->Write(); hSumNSin2TrgPos[itrg]->Write(); hSumNSin2TrgNeg[itrg]->Write(); } fout->Close(); }
void makePlots_vdm_ls(double skip = 10.*11246.) { gROOT->ProcessLine(" .L style.cc+"); #ifdef __CINT__ style(); #endif TFile* file = TFile::Open("histos_vdmpp.root"); TH1D* h_rate = (TH1D*)file->Get((string("pp/h_rate_ls")).c_str()); h_rate->Scale(1./h_rate->GetBinWidth(1)); h_rate->SetTitle(";orbitNb;dN/dT_{Orbit}"); h_rate->GetXaxis()->SetNdivisions(505); h_rate->GetYaxis()->SetTitleOffset(h_rate->GetYaxis()->GetTitleOffset()*0.7); canFind = new TCanvas; canFind->Divide(1,2); vector<string> type; type.push_back("X"); type.push_back("Y"); vector<double> sectionXBegin; vector<double> sectionXEnd; vector<double> sectionXTruth; vector<double> sectionXMean; vector<double> sectionXMeanE; vector<TGraphErrors*> sectionXChi; // sectionXTruth.push_back(100); //0 // sectionXTruth.push_back(50); //1 // sectionXTruth.push_back(0); //2 // sectionXTruth.push_back(-50); //3 // sectionXTruth.push_back(-100);//4 // sectionXTruth.push_back(-50); //5 // sectionXTruth.push_back(0); //6 // sectionXTruth.push_back(50); //7 // sectionXTruth.push_back(100); //8 // sectionXTruth.push_back(0); //9 //sectionXTruth.push_back(-70); //0 sectionXTruth.push_back(-370); //1 sectionXTruth.push_back(-220); //2 sectionXTruth.push_back(-70); //3 sectionXTruth.push_back(80);//4 sectionXTruth.push_back(230); //5 sectionXTruth.push_back(80); //6 sectionXTruth.push_back(-70); //7 sectionXTruth.push_back(-220); //8 sectionXTruth.push_back(-370); //9 canFind->cd(1); FindSections(h_rate,sectionXBegin, sectionXEnd, BEGINX,ENDX,3.*11246.,skip); //FindSections(h_rate,sectionXBegin, sectionXEnd, 1.932e8,2.025e8,3.*11246.,skip); #ifdef __CINT__ CMSText(1,1,1,string("#DeltaX length scale"),"","pp, #sqrt{s}=2.76 TeV"); #endif if(sectionXTruth.size() != sectionXBegin.size()) { cerr << "Sections error: not same size. Truth/Found: " << sectionXTruth.size() << " " << sectionXBegin.size() << endl; //exit(-1); } vector<double> sectionYBegin; vector<double> sectionYEnd; vector<double> sectionYTruth; vector<double> sectionYMean; vector<double> sectionYMeanE; vector<TGraphErrors*> sectionYChi; // sectionYTruth.push_back(100); // sectionYTruth.push_back(50); // sectionYTruth.push_back(0); // sectionYTruth.push_back(-50); // sectionYTruth.push_back(-100); // sectionYTruth.push_back(-50); // sectionYTruth.push_back(0); // sectionYTruth.push_back(50); // sectionYTruth.push_back(100); // sectionYTruth.push_back(0); //sectionYTruth.push_back(70); //0 sectionYTruth.push_back(-370); //1 sectionYTruth.push_back(-220); //2 sectionYTruth.push_back(-70); //3 sectionYTruth.push_back(80);//4 sectionYTruth.push_back(230); //5 sectionYTruth.push_back(80); //6 sectionYTruth.push_back(-70); //7 sectionYTruth.push_back(-220); //8 sectionYTruth.push_back(-370); //9 canFind->cd(2); //FindSections(h_rate,sectionYBegin, sectionYEnd, 2.038e8,2.12e8,3.*11246.,skip); FindSections(h_rate,sectionYBegin, sectionYEnd, BEGINY,ENDY,3.*11246.,skip); #ifdef __CINT__ CMSText(1,1,1,string("#DeltaY length scale"),"","pp, #sqrt{s}=2.76 TeV"); #endif if(sectionYTruth.size() != sectionYBegin.size()) { cerr << "Sections error: not same size. Truth/Found: " << sectionYTruth.size() << " " << sectionYBegin.size() << endl; //exit(-1); } TCanvas* can1 = new TCanvas; can1->Divide(1,2); //GENERAL LOOP OVER SECTIONS for(int n=0; n<int(type.size()); n++) { can1->cd(type[n]=="X"?1:2); vector<double>& sectionBegin = type[n]=="X"?sectionXBegin:sectionYBegin; vector<double>& sectionEnd = type[n]=="X"?sectionXEnd:sectionYEnd; vector<double>& sectionTruth = type[n]=="X"?sectionXTruth:sectionYTruth; vector<double>& sectionMean = type[n]=="X"?sectionXMean:sectionYMean; vector<double>& sectionMeanE = type[n]=="X"?sectionXMeanE:sectionYMeanE; vector<TGraphErrors*>& sectionChi = type[n]=="X"?sectionXChi:sectionYChi; const int nSec = int(sectionBegin.size()); sectionMean.resize(nSec); sectionMeanE.resize(nSec); TH2D* h_length_scale = (TH2D*)file->Get((string("pp/h_length_scale_") + type[n]).c_str()); // for(int i= 0; i<h_length_scale->GetNbinsX()+1;i++) cout << h_length_scale->Print TGraphErrors* h_truth_fit_up = new TGraphErrors(0); TGraphErrors* h_truth_fit_down = new TGraphErrors(0); TGraphErrors* h_truth_fit_crosscheck_up = new TGraphErrors(0); TGraphErrors* h_truth_fit_crosscheck_down = new TGraphErrors(0); ostringstream profiletitle; profiletitle << "truth_fit_" << type[n]; ostringstream crosschecktitle; crosschecktitle << "truth_fit_crosscheck_" << type[n]; h_truth_fit_down->SetName(profiletitle.str().c_str()); h_truth_fit_crosscheck_down->SetName(crosschecktitle.str().c_str()); profiletitle << "_down"; crosschecktitle << "_down"; h_truth_fit_up->SetName(profiletitle.str().c_str()); h_truth_fit_crosscheck_up->SetName(crosschecktitle.str().c_str()); vector<TF1*> sectionFunc; sectionFunc.resize(nSec); vector<TFitResultPtr> sectionFuncPtr; sectionFuncPtr.resize(nSec); ostringstream histotitle; histotitle << ";orbit number; vertex " << type[n] << " position [cm]"; h_length_scale->SetTitle(histotitle.str().c_str()); h_length_scale->SetMarkerSize(0.5); h_length_scale->GetXaxis()->SetNdivisions(505); h_length_scale->GetYaxis()->SetTitleOffset(h_length_scale->GetYaxis()->GetTitleOffset()*0.7); if(type[n]=="X") h_length_scale->GetXaxis()->SetRangeUser(BEGINX,ENDX); else h_length_scale->GetXaxis()->SetRangeUser(BEGINY,ENDY); // if(type[n]=="X") // h_length_scale->GetXaxis()->SetRangeUser(193000000,202000000); // else // h_length_scale->GetXaxis()->SetRangeUser(203000000,211000000); // h_length_scale->GetYaxis()->SetRangeUser(0.00,0.15); h_length_scale->Draw("COLZ"); #ifdef __CINT__ CMSText(1,1,1,string("#Delta")+type[n]+string(" length scale"),"","pp, #sqrt{s}=2.76 TeV"); #endif //FIT EACH SECTION TCanvas* canFit = new TCanvas; canFit->Divide(TMath::Nint(nSec/2.),2); for (int i=0; i<nSec; i++) { int binStartNotSkipped,binStart, binEnd, helper; double x1,x2,xend; h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionBegin[i]),binStartNotSkipped,helper,helper); binStartNotSkipped++; h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionBegin[i]+skip),binStart,helper,helper); binStart++; h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionEnd[i]),binEnd,helper,helper); binEnd--; x1=h_length_scale->GetBinLowEdge(binStartNotSkipped); x2=h_length_scale->GetBinLowEdge(binStart); xend=h_length_scale->GetBinLowEdge(binEnd+1); if(binStart >= binEnd) { cerr << "MAJOR WARNING Chosen skipping value too large for section " << i << "(" << binStart << "," << binEnd << ")" << endl; } ostringstream funcTitle; funcTitle << "section" << type[n] << "Func_" << i; sectionFunc[i] = new TF1(funcTitle.str().c_str(),"gaus"); sectionFunc[i]->SetLineWidth(2); sectionFunc[i]->SetLineColor(kRed); sectionFunc[i]->SetLineStyle(1); funcTitle << "_Prof"; TH1D* helperProfile = h_length_scale->ProjectionY(funcTitle.str().c_str(),binStart,binEnd); canFit->cd(i+1); helperProfile->Draw(); sectionFuncPtr[i] = helperProfile->Fit(sectionFunc[i],"QS"); if(Int_t(sectionFuncPtr[i]) !=0) { cerr << " !!! MAJOR WARNING." << endl << "in section " << i << " fit did not converge: " << gMinuit->fCstatu.Data() << endl; } sectionFunc[i]->SetLineWidth(2); sectionFunc[i]->Draw("SAME"); sectionMean[i] = helperProfile->GetMean(); sectionMeanE[i] = helperProfile->GetMeanError(); if(x1<x2) { //can1->cd(); TBox* box1 = new TBox(x1,0.1,x2,0.105); box1->SetFillColor(kRed); box1->SetFillStyle(3001); box1->DrawClone(); TBox* box2 = new TBox(x2,0.1,xend,0.105); box2->SetFillColor(kGreen); box2->SetFillStyle(3001); box2->DrawClone(); } } // //DETERMINE THE MEAN WHERE TRUTH IS AT NOMINAL POSITION -> now done below // double xw = 0; // double w = 0; // for(int i=0; i<nSec; i++) // { // if(sectionTruth[i]==70 || sectionTruth[i]==-70) // { // double weight = 1./pow(sectionFuncPtr[i]->ParError(1),2); // xw += sectionFuncPtr[i]->Parameter(1) * weight; // w += weight; // //cout << sectionFuncPtr[i]->Parameter(1) << " weight: " << weight << endl; // } // } // double sigma = sqrt(1./w); // double y0 = xw/w; // cout << "y0 = " << y0 << "+-" << sigma << endl; //CHECK CHI2 OPTIMISATION TCanvas* can3 = new TCanvas; sectionChi.resize(nSec); string drawoption("AL"); TLegend* legchi = new TLegend(0.55,0.5,0.85,0.9); for(int i=0; i<nSec; i++) { if(i<1 || i >8) continue; const int nSkipBins=10; ostringstream graphTitle; graphTitle << "section_" << type[n] << "_chi2_Graph_" << i; sectionChi[i] = (new TGraphErrors(0)); sectionChi[i]->SetName(graphTitle.str().c_str()); for (int skipBin=0; skipBin<nSkipBins; skipBin++) { int binStart, binEnd, helper; h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionBegin[i]),binStart,helper,helper); binStart++; h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionEnd[i]),binEnd,helper,helper); binEnd--; binStart += skipBin; if(binStart >= binEnd) continue; double x = double(h_length_scale->GetBinLowEdge(binStart) - h_length_scale->GetBinLowEdge(binStart-skipBin)) / 11246.; //cout << "skip bin: " << skipBin << "(" << binStart << ")" << endl; ostringstream funcTitle; funcTitle << "section" << type[n] << "Func_" << i << "_" << skipBin; TF1* helperFunc = new TF1(funcTitle.str().c_str(),"gaus"); funcTitle << "_Prof"; TH1D* helperProfile = h_length_scale->ProjectionY(funcTitle.str().c_str(),binStart,binEnd); TFitResultPtr helperPtr = helperProfile->Fit(helperFunc,"QSN"); if(Int_t(helperPtr) !=0) { cout << "fit failed" << endl; cout << "skip bin: " << skipBin << "(" << binStart << ")" << endl; continue; } double chi2 = helperPtr->Chi2()/double(helperPtr->Ndf()); sectionChi[i]->SetPoint(sectionChi[i]->GetN(),x,chi2); //cout << skipBin << " " << x << " " << chi2 << endl; } //sectionChi[i]->Print("ALL"); sectionChi[i]->SetTitle(";skip interval [s]; #chi^{2}/NDF"); sectionChi[i]->GetYaxis()->SetRangeUser(0,6); sectionChi[i]->GetXaxis()->SetLimits(0,30); sectionChi[i]->SetLineWidth(2); sectionChi[i]->SetLineColor(i); sectionChi[i]->Draw(drawoption.c_str()); drawoption = string("L"); ostringstream legtext ; legtext << "Section " << i << " (" << sectionTruth[i] << " µm)"; legchi->AddEntry(sectionChi[i],legtext.str().c_str(),"l"); } #ifdef __CINT__ CMSText(1,1,1,string("#Delta")+type[n]+string(" length scale"),"","pp, #sqrt{s}=2.76 TeV"); SetLegAtt(legchi); #endif legchi->Draw("SAME"); TLine* line = new TLine(skip/11246.,0,skip/11246.,2.5); line->SetLineWidth(2); line->SetLineStyle(2); line->Draw("SAME"); can3->SaveAs((string("plots/vdm_length_scale_")+type[n]+string("_3_pp.pdf")).c_str()); //Determine reference value y0 to subtract from plotting TGraph helperGraph(nSec); double y0=0; for (int i=0; i<nSec; i++) { double y = sectionFuncPtr[i]->Parameter(1); helperGraph.SetPoint(i,sectionTruth[i]*(type[n]=="X"?-1:1), y); y0 = helperGraph.Eval(0); } cout << "y0 = " << y0 << endl; //TRUTH VS TRACKER PLOT for (int i=0; i<nSec; i++) { ostringstream text; double size = 0.01; double y = sectionFuncPtr[i]->Parameter(1); double y_cc = sectionMean[i]; //just used for cross checking (cc) the gaussian fit double yum = (y-y0)*1e4; //cm -> µm => 1e-2 -> 1e-6 => 1e4 double yum_cc = (y_cc-y0)*1e4; //cm -> µm => 1e-2 -> 1e-6 => 1e4 double yumerror = (sectionFuncPtr[i]->ParError(1))*10000.; double yumerror_cc = sectionMeanE[i] * 10000; text << "#Delta" << type[n] << "_{Fit}=" << fixed << setprecision(1) << yum; TPaveText* txt = new TPaveText(sectionBegin[i],y+1.5*size,sectionEnd[i],y+2.5*size,"b t l"); txt->SetTextFont(62); txt->SetFillStyle(0); txt->SetTextColor(kRed); txt->SetTextSize(0.04); txt->SetBorderSize(0); txt->AddText(text.str().c_str()); txt->Draw("SAME"); if(i>=1 && i<=4) //WARNING also setpoint needs to be changed { cout << "up " << i << " " << sectionTruth[i]*(type[n]=="X"?-1:1) << " " << yum << "+-" << yumerror << endl; h_truth_fit_up->SetPoint(i-1,sectionTruth[i]*(type[n]=="X"?-1:1), yum); // Coordinate Sys different z? X has to be inverted. h_truth_fit_up->SetPointError(i-1,0, yumerror); h_truth_fit_crosscheck_up->SetPoint(i-1,sectionTruth[i]*(type[n]=="X"?-1:1), yum_cc); // Coordinate Sys different z? X has to be inverted. h_truth_fit_crosscheck_up->SetPointError(i-1,0, yumerror_cc); } if(i>=5 && i<=8) //anti hysteresis //WARNING also setpoint needs to be changed { cout << "down " << i << " " << sectionTruth[i]*(type[n]=="X"?-1:1) << " " << yum << "+-" << yumerror << endl; h_truth_fit_down->SetPoint(i-5,sectionTruth[i]*(type[n]=="X"?-1:1), yum); // Coordinate Sys different z? X has to be inverted. h_truth_fit_down->SetPointError(i-5,0, yumerror); h_truth_fit_crosscheck_down->SetPoint(i-5,sectionTruth[i]*(type[n]=="X"?-1:1), yum_cc); // Coordinate Sys different z? X has to be inverted. h_truth_fit_crosscheck_down->SetPointError(i-5,0, yumerror_cc); } } canFit->SaveAs((string("plots/vdm_length_scale_")+type[n]+string("_Fits_pp.pdf")).c_str()); TCanvas* can2 = new TCanvas; ostringstream titleup; titleup << ";#Delta" << type[n] << " (LHC) [#mum]; #Delta" << type[n] << " (CMS) [#mum]"; h_truth_fit_up->SetTitle(titleup.str().c_str()); h_truth_fit_up->SetMarkerSize(1.3); h_truth_fit_up->SetMarkerColor(kRed); h_truth_fit_up->SetLineColor(kRed); h_truth_fit_up->SetLineWidth(2); h_truth_fit_up->GetXaxis()->SetLimits(-400,400); h_truth_fit_up->GetYaxis()->SetRangeUser(-400,400); h_truth_fit_up->Draw("AP"); TFitResultPtr fit_up = h_truth_fit_up->Fit("pol1","QS"); TFitResultPtr fit_crosscheck_up = h_truth_fit_crosscheck_up->Fit("pol1","QNS"); h_truth_fit_up->GetFunction("pol1")->SetLineWidth(2); h_truth_fit_up->GetFunction("pol1")->SetLineColor(kRed); h_truth_fit_down->SetMarkerColor(kBlue); h_truth_fit_down->SetMarkerStyle(25); h_truth_fit_down->SetMarkerSize(1.3); h_truth_fit_down->SetLineColor(kBlue); h_truth_fit_down->SetLineWidth(2); h_truth_fit_down->Draw("P"); TFitResultPtr fit_down = h_truth_fit_down->Fit("pol1","QS"); TFitResultPtr fit_crosscheck_down = h_truth_fit_crosscheck_down->Fit("pol1","QNS"); h_truth_fit_down->GetFunction("pol1")->SetLineWidth(2); h_truth_fit_down->GetFunction("pol1")->SetLineColor(kBlue); TLegend* leg = new TLegend(0.22,0.72,0.6,0.82); ostringstream legup,legdown; legup << "#Delta" << type[n] << " low-to-high (Slope:" << fixed << setprecision(3) << fit_up ->Parameter(1) << " )"; legdown << "#Delta" << type[n] << " high-to-low (Slope:" << fixed << setprecision(3) << fit_down->Parameter(1) << " )"; leg->AddEntry(h_truth_fit_up ,legup .str().c_str(),"lp"); leg->AddEntry(h_truth_fit_down,legdown.str().c_str(),"lp"); #ifdef __CINT__ SetLegAtt(leg); CMSText(1,1,1,"","","pp, #sqrt{s}=2.76 TeV"); #endif leg->Draw("SAME"); can2->SaveAs((string("plots/vdm_length_scale_")+type[n]+string("_2_pp.pdf")).c_str()); double average = (fit_up->Parameter(1) + fit_down->Parameter(1)) / 2.; double average_cc = (fit_crosscheck_up->Parameter(1) + fit_crosscheck_down->Parameter(1)) / 2.; double stat = sqrt( pow(fit_up->Parameter(1)/2.,2) * pow(fit_down->ParError(1),2) + pow(fit_down->Parameter(1)/2.,2) * pow(fit_up->ParError(1),2)); double sysupdown = fabs(fit_up->Parameter(1) - fit_down->Parameter(1))/ 2.; double sysfit = fabs(average_cc - average) / 2.; double sysskip = (type[n]=="X"?0.001:0.003); double sys = sqrt ( sysfit*sysfit + sysupdown*sysupdown + sysskip*sysskip); cout << endl << endl << endl; cout << fixed << setprecision(3) << " Δ" << type[n] << endl << "--Correction Factor: " << average << endl << "up: " << fit_up->Parameter(1) << endl << "down: " << fit_down->Parameter(1) << endl << "--Stat: " << stat << endl << "--Sys Combined: " << sys << endl << "Sys. Up Down: " << sysupdown << endl << "Sys. Fitting: " << sysfit << endl << "Sys. Skipping: " << sysskip << endl; cout << endl << endl << endl; } can1->SaveAs((string("plots/vdm_length_scale")+string("_1_pp.pdf")).c_str()); canFind->SaveAs((string("plots/vdm_length_scale")+string("_sections_pp.pdf")).c_str()); }
// ============================================================================ /// finalize the algorithm // ============================================================================ StatusCode Aida2Root::finalize() { always() << "Get the native ROOT representation of histograms!" << endmsg ; { // loop over all 1D-histograms for ( List::const_iterator ipath = m_1Ds.begin() ; m_1Ds.end() != ipath ; ++ipath ) { /// retrieve the historam by full path: AIDA::IHistogram1D* aida = 0 ; StatusCode sc = histoSvc()->retrieveObject( *ipath , aida ) ; if ( sc.isFailure() || 0 == aida ) { return Error ( "Unable to retrieve 1D-histogram '" + (*ipath) + "'" ) ; } /// convert it to ROOT TH1D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ; if ( 0 == root ) { return Error ( "Unable to convert to ROOT the 1D-histogram '"+(*ipath)+"'") ; } /// use the native printout from ROOT info() << "The native ROOT printout for 1D-histogram '" << (*ipath) << "':" << endmsg ; root->Print() ; info () << " | Compare | AIDA/HistoStats | ROOT/TH1 | Delta | " << endmsg ; const std::string format = " | %1$-14.14s | %2$ 15.8g | %3$- 15.8g | %4$= 15.8g | " ; info () << print ( Gaudi::Utils::HistoStats::mean ( aida ) , root->GetMean () , "'mean'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::meanErr ( aida ) , root->GetMeanError () , "'meanErr'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::rms ( aida ) , root->GetRMS () , "'rms'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::rmsErr ( aida ) , root->GetRMSError () , "'rmsErr'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::skewness ( aida ) , root->GetSkewness () , "'skewness'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::skewnessErr ( aida ) , root->GetSkewness ( 11 ) , "'skewnessErr'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::kurtosis ( aida ) , root->GetKurtosis () , "'kurtosis'" , format ) << endmsg ; info () << print ( Gaudi::Utils::HistoStats::kurtosisErr ( aida ) , root->GetKurtosis ( 11 ) , "'kurtosisErr'" , format ) << endmsg ; } } { // loop over all 2D-histograms for ( List::const_iterator ipath = m_2Ds.begin() ; m_2Ds.end() != ipath ; ++ipath ) { /// retrieve the historam by full path: AIDA::IHistogram2D* aida = 0 ; StatusCode sc = histoSvc()->retrieveObject( *ipath , aida ) ; if ( sc.isFailure() || 0 == aida ) { return Error ( "Unable to retrieve 2D-histogram '" + (*ipath) + "'" ) ; } /// convert it to ROOT TH2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ; if ( 0 == root ) { return Error ( "Unable to convert to ROOT the 2D-histogram '"+(*ipath)+"'") ; } /// use the native printout from ROOT info() << "The native ROOT printout for 2D-histogram '" << (*ipath) << "':" << endmsg ; root->Print() ; } } { // loop over all 3D-histograms for ( List::const_iterator ipath = m_3Ds.begin() ; m_3Ds.end() != ipath ; ++ipath ) { /// retrieve the historam by full path: AIDA::IHistogram3D* aida = 0 ; StatusCode sc = histoSvc()->retrieveObject( *ipath , aida ) ; if ( sc.isFailure() || 0 == aida ) { return Error ( "Unable to retrieve 3D-histogram '" + (*ipath) + "'" ) ; } /// convert it to ROOT TH3D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ; if ( 0 == root ) { return Error ( "Unable to convert to ROOT the 3D-histogram '"+(*ipath)+"'") ; } /// use the native printout from ROOT info() << "The native ROOT printout for 3D-histogram '" << (*ipath) << "':" << endmsg ; root->Print() ; } } { // loop over all 1D-profiles for ( List::const_iterator ipath = m_1Ps.begin() ; m_1Ps.end() != ipath ; ++ipath ) { /// retrieve the historam by full path: AIDA::IProfile1D* aida = 0 ; StatusCode sc = histoSvc()->retrieveObject( *ipath , aida ) ; if ( sc.isFailure() || 0 == aida ) { return Error ( "Unable to retrieve 1D-profile '" + (*ipath) + "'" ) ; } /// convert it to ROOT TProfile* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ; if ( 0 == root ) { return Error ( "Unable to convert to ROOT the 1D-profile '"+(*ipath)+"'") ; } /// use the native printout from ROOT info() << "The native ROOT printout for 1D-profile '" << (*ipath) << "':" << endmsg ; root->Print() ; } } { // loop over all 2D-profiles for ( List::const_iterator ipath = m_2Ps.begin() ; m_2Ps.end() != ipath ; ++ipath ) { /// retrieve the historam by full path: AIDA::IProfile2D* aida = 0 ; StatusCode sc = histoSvc()->retrieveObject( *ipath , aida ) ; if ( sc.isFailure() || 0 == aida ) { Error ( "Unable to retrieve 2D-profile '" + (*ipath) + "'" ) ; } /// convert it to ROOT TProfile2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ; if ( 0 == root ) { Error ( "Unable to convert to ROOT the 2D-profile '"+(*ipath)+"'") ; } /// use the native printout from ROOT info() << "The native ROOT printout for 2D-profile '" << (*ipath) << "':" << endmsg ; root->Print() ; } } return GaudiHistoAlg::finalize() ; }