void CheckMerge(TH3* h, THnSparse* sparse) { // check merging of three THnSparse TList h3_clones; h3_clones.SetOwner(); for (int i = 0; i < 4; ++i) { h3_clones.AddLast(h->Clone()); ((TH3*)h3_clones.Last())->Scale(i); } TList hs_clones; hs_clones.SetOwner(); for (int i = 0; i < 4; ++i) { hs_clones.AddLast(sparse->Clone()); ((THnSparse*)hs_clones.Last())->Scale(i); } TH3* h3Merge = (TH3*) h->Clone(); THnSparse* hsMerge = (THnSparse*) sparse->Clone(); h3Merge->Merge(&h3_clones); hsMerge->Merge(&hs_clones); TH3* proj = hsMerge->Projection(0, 1, 2); Test(h3Merge, proj, "Merging histograms"); delete proj; delete h3Merge; delete hsMerge; }
//______________________________________________________________________________ void drawsparse() { // create a THnSparse and draw it. #ifdef __CINT__ printf("For performance reasons we advise to run \".x drawsparse.C+\"\n"); #endif const Int_t ndims = 8; Int_t bins[ndims] = {10, 10, 5, 30, 10, 4, 18, 12}; Double_t xmin[ndims] = {-5., -10., -1000., -3., 0., 0., 0., 0.}; Double_t xmax[ndims] = {10., 70., 3000., 3., 5., 2., 2., 5.}; THnSparse* hs = new THnSparseD("hs", "Sparse Histogram", ndims, bins, xmin, xmax); // fill it Double_t x[ndims]; for (Long_t i = 0; i < 100000; ++i) { for (Int_t d = 0; d < ndims; ++d) { switch (d) { case 0: x[d] = gRandom->Gaus()*2 + 3.; break; case 1: case 2: case 3: x[d] = (x[d-1]*x[d-1] - 1.5)/1.5 + (0.5*gRandom->Rndm()); break; default: x[d] = sin(gRandom->Gaus()*i/1000.) + 1.; } } hs->Fill(x); } TFile* f = new TFile("drawsparse.root","RECREATE"); TCanvas* canv = new TCanvas("hDrawSparse", "Drawing a sparse hist"); canv->Divide(2); // draw it canv->cd(1); drawsparse_draw(hs); // project it canv->cd(2); TH3D* h3proj = hs->Projection(2, 3, 6); h3proj->SetLineColor(kOrange); h3proj->SetDirectory(0); h3proj->Draw("lego1"); // save everything to a file canv->Write(); hs->Write(); h3proj->Write(); delete f; }
void CheckClone(TH3* h, THnSparse* sparse) { // Check cloning of a THnSparse if (h) {} THnSparse* clone = (THnSparse*)sparse->Clone("clone"); TH3* proj = sparse->Projection(0, 1, 2); TH3* projclone = clone->Projection(0, 1, 2); Test(proj, projclone, "Cloning of THnSparse"); delete clone; delete proj; delete projclone; }
void CheckSubtract(TH3* h, THnSparse* sparse) { // Check subtracting THnSparse from THnSparse TH3* h42 = (TH3*)h->Clone("h42"); h42->Scale(.42); THnSparse* clone = (THnSparse*)sparse->Clone("clone"); clone->Scale(1.42); clone->Add(sparse, -1.); TH3* proj = clone->Projection(0, 1, 2); Test(h42, proj, "Subtracting two THnSparse"); delete proj; delete clone; delete h42; }
TH1 *PullHisto(const TList *list, const char *name, Int_t min, Int_t max, Double_t &mean) { THnSparse *hs = list->FindObject(name); if (!hs) return 0; TAxis *atmp = hs->GetAxis(1); atmp->SetRange(min, max); // !!!!!!!!!!!!!!!!!!!! hs->GetAxis(2)->SetRangeUser(-0.5, 0.5); TH1 *hfin = hs->Projection(0); hfin->SetTitle(Form("p_{t} #in (%4.2f, %4.2f) GeV/c", atmp->GetBinLowEdge(min), atmp->GetBinLowEdge(max) + atmp->GetBinWidth(max))); mean = atmp->GetBinLowEdge(min) + (atmp->GetBinLowEdge(max) + atmp->GetBinWidth(max) - atmp->GetBinLowEdge(min))/2.0; // !!!!!!!!!!!!!!!!!!!! return hfin;//->Rebin(); }
//___________________________________________________________________ Int_t studyBinZero(TString pathData, TString fileNameData, TString listName = "", Double_t etaLow = -0.9, Double_t etaUp = 0.9, Double_t lowerCentrality = -2, Double_t upperCentrality = -2) { PrintSettingsAxisRangeForMultiplicityAxisForMB(); TString pathNameData = Form("%s/%s", pathData.Data(), fileNameData.Data()); if (listName == "") { listName = pathNameData; listName.Replace(0, listName.Last('/') + 1, ""); listName.ReplaceAll(".root", ""); } TObjArray* histList = 0x0; TFile* f = TFile::Open(pathNameData.Data()); if (!f) { std::cout << std::endl; std::cout << "Failed to open file \"" << pathNameData.Data() << "\"!" << std::endl; return -1; } histList = (TObjArray*)(f->Get(listName.Data())); if (!histList) { std::cout << std::endl; std::cout << "Failed to load list \"" << listName.Data() << "\"!" << std::endl; return -1; } // Extract the data histograms TH1* hNumEventsTriggerSel = dynamic_cast<TH1*>(histList->FindObject("fhEventsTriggerSel")); TH1* hNumEventsTriggerSelVtxCut = dynamic_cast<TH1*>(histList->FindObject("fhEventsTriggerSelVtxCut")); TH1* hNumEventsTriggerSelVtxCutZ= dynamic_cast<TH1*>(histList->FindObject("fhEventsProcessedNoPileUpRejection")); TH1* hNumEventsTriggerSelVtxCutZPileUpRej= dynamic_cast<TH1*>(histList->FindObject("fhEventsProcessed")); THnSparse* hDataTriggerSel = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSel")); THnSparse* hDataTriggerSelVtxCut = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCut")); THnSparse* hDataTriggerSelVtxCutZ = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCutZ")); THnSparse* hDataTriggerSelVtxCutZPileUpRej = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCutZPileUpRej")); setSparseErrors(hDataTriggerSel); setSparseErrors(hDataTriggerSelVtxCut); setSparseErrors(hDataTriggerSelVtxCutZ); setSparseErrors(hDataTriggerSelVtxCutZPileUpRej); // Set multiplicity range, if desired. Note that mult and pT axes are the same for all histos Int_t lowerCentralityBinLimit = -1; Int_t upperCentralityBinLimit = -2; Bool_t restrictCentralityAxis = kFALSE; Double_t actualLowerCentrality = -1.; Double_t actualUpperCentrality = -1.; if (lowerCentrality >= -1 && upperCentrality >= -1) { // Add subtract a very small number to avoid problems with values right on the border between to bins lowerCentralityBinLimit = hNumEventsTriggerSel->GetXaxis()->FindFixBin(lowerCentrality + 0.001); upperCentralityBinLimit = hNumEventsTriggerSel->GetXaxis()->FindFixBin(upperCentrality - 0.001); // Check if the values look reasonable if (lowerCentralityBinLimit <= upperCentralityBinLimit && lowerCentralityBinLimit >= 1 && upperCentralityBinLimit <= hNumEventsTriggerSel->GetXaxis()->GetNbins()) { actualLowerCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinLowEdge(lowerCentralityBinLimit); actualUpperCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinUpEdge(upperCentralityBinLimit); restrictCentralityAxis = kTRUE; } else { std::cout << std::endl; std::cout << "Requested centrality range out of limits or upper and lower limit are switched!" << std::endl; return -1; } } if (!restrictCentralityAxis) GetAxisRangeForMultiplicityAxisForMB(hNumEventsTriggerSel->GetXaxis(), lowerCentralityBinLimit, upperCentralityBinLimit); hNumEventsTriggerSel->GetXaxis()->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); actualLowerCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinLowEdge(hNumEventsTriggerSel->GetXaxis()->GetFirst()); actualUpperCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinUpEdge(hNumEventsTriggerSel->GetXaxis()->GetLast()); std::cout << "centrality: "; if (restrictCentralityAxis) { std::cout << actualLowerCentrality << " - " << actualUpperCentrality << std::endl; std::cout << "WARNING: Does it really make sense to restrict the centrality? Usually, centrality estimators imply centrality >= 0!" << std::endl; } else std::cout << "MB (" << actualLowerCentrality << " - " << actualUpperCentrality << ")" << std::endl; if (restrictCentralityAxis) { hDataTriggerSel->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); hDataTriggerSelVtxCut->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); hDataTriggerSelVtxCutZ->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); hDataTriggerSelVtxCutZPileUpRej->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit); } // Restrict eta range const Int_t lowerEtaBinLimit = hDataTriggerSel->GetAxis(iEta)->FindFixBin(etaLow + 0.0001); const Int_t upperEtaBinLimit = hDataTriggerSel->GetAxis(iEta)->FindFixBin(etaUp - 0.0001); const Double_t actualLowerEta = hDataTriggerSel->GetAxis(iEta)->GetBinLowEdge(lowerEtaBinLimit); const Double_t actualUpperEta = hDataTriggerSel->GetAxis(iEta)->GetBinUpEdge(upperEtaBinLimit); std::cout << "Eta: "; std::cout << actualLowerEta << " - " << actualUpperEta << std::endl; Bool_t symmetricInEta = TMath::Abs(TMath::Abs(actualLowerEta) - TMath::Abs(actualUpperEta)) < 1e-6; TString etaRange = symmetricInEta ? Form("|#it{#eta}| < %.1f", TMath::Abs(actualLowerEta)) : Form("%.1f < #it{#eta} < %.1f", actualLowerEta, actualUpperEta); hDataTriggerSel->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); hDataTriggerSelVtxCut->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); hDataTriggerSelVtxCutZ->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); hDataTriggerSelVtxCutZPileUpRej->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit); // Obtain number of events for each class // Note: Under- and overflow automatically taken into account for unrestricted axis by using -1 and -2 for limits const Double_t numEvtsTriggerSel = hNumEventsTriggerSel->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); const Double_t numEvtsTriggerSelVtxCut = hNumEventsTriggerSelVtxCut->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); const Double_t numEvtsTriggerSelVtxCutZ = hNumEventsTriggerSelVtxCutZ->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); const Double_t numEvtsTriggerSelVtxCutZPileUpRej = hNumEventsTriggerSelVtxCutZPileUpRej->Integral(lowerCentralityBinLimit, upperCentralityBinLimit); // Project pT spectra TH1D* hSpectraTriggerSel = (TH1D*)hDataTriggerSel->Projection(iPt, "e"); TH1D* hSpectraTriggerSelVtxCut = (TH1D*)hDataTriggerSelVtxCut->Projection(iPt, "e"); TH1D* hSpectraTriggerSelVtxCutZ = (TH1D*)hDataTriggerSelVtxCutZ->Projection(iPt, "e"); TH1D* hSpectraTriggerSelVtxCutZPileUpRej = (TH1D*)hDataTriggerSelVtxCutZPileUpRej->Projection(iPt, "e"); // Normalise histos to 1/Nevt dN/dPt normaliseHist(hSpectraTriggerSel, numEvtsTriggerSel); normaliseHist(hSpectraTriggerSelVtxCut, numEvtsTriggerSelVtxCut); normaliseHist(hSpectraTriggerSelVtxCutZ, numEvtsTriggerSelVtxCutZ); normaliseHist(hSpectraTriggerSelVtxCutZPileUpRej, numEvtsTriggerSelVtxCutZPileUpRej); setupHist(hSpectraTriggerSel, kBlack, "Trigger selection"); setupHist(hSpectraTriggerSelVtxCut, kRed, "& vertex cut"); setupHist(hSpectraTriggerSelVtxCutZ, kBlue, "& vertex #it{z} cut"); setupHist(hSpectraTriggerSelVtxCutZPileUpRej, kGreen, "& pile-up rejection"); TCanvas* canvSpectra = new TCanvas("canvSpectra", "Spectra", 760, 420); canvSpectra->SetLogx(); canvSpectra->SetLogy(); canvSpectra->SetGrid(0, 0); SetCanvasMargins(canvSpectra); TLegend* leg = new TLegend(0.14, 0.26, 0.62, 0.55); leg->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data())); leg->AddEntry(hSpectraTriggerSel, "", "l"); leg->AddEntry(hSpectraTriggerSelVtxCut, "", "l"); leg->AddEntry(hSpectraTriggerSelVtxCutZ, "", "l"); if (drawPileUp) leg->AddEntry(hSpectraTriggerSelVtxCutZPileUpRej, "", "l"); SetupLegend(leg); leg->SetMargin(0.15); hSpectraTriggerSel->Draw(); hSpectraTriggerSelVtxCut->Draw("same"); hSpectraTriggerSelVtxCutZ->Draw("same"); if (drawPileUp) hSpectraTriggerSelVtxCutZPileUpRej->Draw("same"); leg->Draw("same"); // Ratios (take binomial errors, since real sub-samples) TH1D* hRatioVtxCut = new TH1D(*hSpectraTriggerSelVtxCut); hRatioVtxCut->SetName("hRatioVtxCut"); setupHist(hRatioVtxCut, kBlack, "MB & vtx / MB"); hRatioVtxCut->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio"); hRatioVtxCut->Divide(hRatioVtxCut, hSpectraTriggerSel, 1., 1., "B"); hRatioVtxCut->GetYaxis()->SetRangeUser(1.08, 1.14); // Mean ratio of spectra and of Nevt TF1* funcRatioVtxCut = new TF1("funcRatioVtxCut", "pol0", 0.15, hRatioVtxCut->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCut->FindLastBinAbove(0))); funcRatioVtxCut->SetLineWidth(2); funcRatioVtxCut->SetLineColor(kRed); hRatioVtxCut->Fit(funcRatioVtxCut, "N"); const Double_t meanRatioVtxCut = funcRatioVtxCut->GetParameter(0); const Double_t ratioNevtVtxCut = numEvtsTriggerSelVtxCut > 0 ? numEvtsTriggerSel / numEvtsTriggerSelVtxCut : -1.; const Double_t doubleRatioMinusOne = meanRatioVtxCut > 0 ? (ratioNevtVtxCut / meanRatioVtxCut - 1.) : -999.; TH1D* hRatioVtxCutZ = new TH1D(*hSpectraTriggerSelVtxCutZ); hRatioVtxCutZ->SetName("hRatioVtxCutZ"); setupHist(hRatioVtxCutZ, kBlack, "MB & vtx & #it{z} vtx / MB & vtx"); hRatioVtxCutZ->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio"); hRatioVtxCutZ->Divide(hRatioVtxCutZ, hSpectraTriggerSelVtxCut, 1., 1., "B"); hRatioVtxCutZ->GetYaxis()->SetRangeUser(0.95, 1.05); // Mean ratio of spectra and of Nevt TF1* funcRatioVtxCutZ = new TF1("funcRatioVtxCutZ", "pol0", 0.15, hRatioVtxCutZ->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZ->FindLastBinAbove(0))); hRatioVtxCutZ->Fit(funcRatioVtxCutZ, "N"); funcRatioVtxCutZ->SetLineWidth(2); funcRatioVtxCutZ->SetLineColor(kRed); const Double_t meanRatioVtxCutZ = funcRatioVtxCutZ->GetParameter(0); const Double_t ratioNevtVtxCutZ = numEvtsTriggerSelVtxCutZ > 0 ? numEvtsTriggerSelVtxCut / numEvtsTriggerSelVtxCutZ : -1.; TH1D* hRatioPileUp = new TH1D(*hSpectraTriggerSelVtxCutZPileUpRej); hRatioPileUp->SetName("hRatioPileUp"); setupHist(hRatioPileUp, kBlack, "MB & vtx & #it{z} vtx & pile-up / MB & vtx & #it{z} vtx"); hRatioPileUp->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio"); hRatioPileUp->Divide(hRatioPileUp, hSpectraTriggerSelVtxCutZ, 1., 1., "B"); /* TF1* funcRatioPileUp = new TF1("funcRatioPileUp", "pol0", 0.15, hRatioPileUp->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZPileUpRej->FindLastBinAbove(0))); hRatioPileUp->Fit(funcRatioPileUp, "N");*/ ClearTitleFromHistoInCanvas(canvSpectra); TCanvas* canvRatioVtx = new TCanvas("canvRatioVtx", "Ratio vertex", 760, 420); canvRatioVtx->SetLogx(); canvRatioVtx->SetGrid(0, 1); SetCanvasMargins(canvRatioVtx); hRatioVtxCut->Draw(); funcRatioVtxCut->Draw("same"); TLegend* leg2 = new TLegend(0.22, 0.7, drawPileUp ? 0.87 : 0.72, 0.9); leg2->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data())); leg2->AddEntry(hRatioVtxCut, "", "l"); SetupLegend(leg2); leg2->SetMargin(0.1); leg2->Draw("same"); ClearTitleFromHistoInCanvas(canvRatioVtx); TCanvas* canvRatioOther = new TCanvas("canvRatioOther", "Ratio others", 760, 420); canvRatioOther->SetLogx(); canvRatioOther->SetGrid(0, 1); SetCanvasMargins(canvRatioOther); hRatioVtxCutZ->Draw(); if (drawPileUp) hRatioPileUp->Draw("same"); TLegend* leg3 = new TLegend(0.22, drawPileUp ? 0.63 : 0.7, drawPileUp ? 0.87 : 0.72, 0.9); leg3->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data())); leg3->AddEntry(hRatioVtxCutZ, "", "l"); if (drawPileUp) leg3->AddEntry(hRatioPileUp, "", "l"); SetupLegend(leg3); leg3->SetMargin(0.1); leg3->Draw("same"); ClearTitleFromHistoInCanvas(canvRatioOther); printf("meanRatioVtxCut %f <-> ratioNevtVtxCut %f => meanRatioVtxCutZ/ratioNevtVtxCutZ - 1 = %f\nmeanRatioVtxCutZ %f <-> ratioNevtVtxCutZ %f\n", meanRatioVtxCut, ratioNevtVtxCut, doubleRatioMinusOne, meanRatioVtxCutZ, ratioNevtVtxCutZ); TNamed* settings = new TNamed( Form("Settings: Data file \"%s\", lowerEta %.2f, uppEta %.2f, lowerCentrality %.3f, upperCentrality %.3f, doubleRatioMinusOne %.4f\n", pathNameData.Data(), etaLow, etaUp, lowerCentrality, upperCentrality, doubleRatioMinusOne), ""); // Save results to file TString saveFileName = pathNameData; saveFileName = Form("%s_binZeroStudy.root", saveFileName.ReplaceAll(".root", "").Data()); TFile *saveFile = TFile::Open(saveFileName.Data(), "RECREATE"); saveFile->cd(); hSpectraTriggerSel->Write(); hSpectraTriggerSelVtxCut->Write(); hSpectraTriggerSelVtxCutZ->Write(); hSpectraTriggerSelVtxCutZPileUpRej->Write(); hRatioVtxCut->Write(); hRatioVtxCutZ->Write(); hRatioPileUp->Write(); funcRatioVtxCut->Write(); funcRatioVtxCutZ->Write(); canvSpectra->Write(); canvRatioVtx->Write(); canvRatioOther->Write(); settings->Write(); saveFile->Close(); TString temp = saveFileName; canvRatioVtx->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioVtx.pdf").Data())); temp = saveFileName; canvRatioOther->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioOther.pdf").Data())); PrintSettingsAxisRangeForMultiplicityAxisForMB(); return 0; }
void RebinCFContainer(const char *infile="AnalysisResults.root",Int_t rebinVar=0, Int_t myEff=3, const char * name="Nch"){ gSystem->SetIncludePath("-I. -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_PHYSICS -I$ALICE_PHYSICS/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/RAW -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/STEER/STEERBase -I$ALICE_ROOT/STEER/ESD -I$ALICE_ROOT/STEER/AOD -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -I$ALICE_PHYSICS/PWGPP -g"); // gROOT->LoadMacro("AliSingleTrackEffCuts.cxx++g"); // gROOT->LoadMacro("AliCFSingleTrackEfficiencyTask.cxx++g"); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetOptStat(0); gStyle->SetPalette(1); gStyle->SetCanvasColor(0); gStyle->SetFrameFillColor(0); gStyle->SetOptTitle(0); TFile* file = TFile::Open(infile,"read"); TDirectoryFile *d = 0; AliCFContainer *dataIni = 0; d = (TDirectoryFile*)file->Get(Form("PWGPP_CFSingleTrack")); if(!d) { cout<<" no directory "<<endl; return; } dataIni = (AliCFContainer*) (d->Get(Form("container%s",name))); if(!dataIni){ cout <<" no container"<<endl; } // // Do an slice of the container to make sure to remove outliers // const UInt_t ipt = 0; const UInt_t ieta = 1; const UInt_t iphi = 2; const UInt_t itheta = 3; const UInt_t izvtx = 4; const UInt_t imult = 5; const UInt_t icent = 6; Int_t nvars = 7; Int_t* ivarSlice = new Int_t[nvars]; ivarSlice[0]= ipt; ivarSlice[1] = ieta; ivarSlice[2] = iphi; ivarSlice[3] = itheta; ivarSlice[4]= izvtx; ivarSlice[5] = imult; ivarSlice[6] = icent; Double_t *mins = new Double_t[nvars]; Double_t *maxs = new Double_t[nvars]; mins[ipt] = ptmin; maxs[ipt] = ptmax; mins[ieta] = etamin; maxs[ieta] = etamax; mins[iphi] = phimin; maxs[iphi] = phimax; mins[itheta] = thetamin; maxs[itheta] = thetamax; mins[izvtx] = zvtxmin; maxs[izvtx] = zvtxmax; mins[imult] = multmin; maxs[imult] = multmax; mins[icent] = centmin; maxs[icent] = centmax; AliCFContainer *data = (AliCFContainer*)dataIni->MakeSlice(nvars,ivarSlice,mins,maxs); cout<< " ... slice done"<<endl; cout<< " the new container has "<< data->GetNStep() << " steps"<<endl; // // *********** NUMERATOR // AliCFGridSparse* gridSparse = 0; if( myEff == 1 ) gridSparse = (AliCFGridSparse*)data->GetGrid(1); // GenAcc else if( myEff == 2 ) gridSparse = (AliCFGridSparse*)data->GetGrid(6); // Rec (acc + cuts) draw reco properties else if( myEff == 3 ) gridSparse = (AliCFGridSparse*)data->GetGrid(7); // RecPID else if( myEff == 4 ) gridSparse = (AliCFGridSparse*)data->GetGrid(3); // Rec (no cuts) else if( myEff == 5 ) gridSparse = (AliCFGridSparse*)data->GetGrid(4); // RecAcc else if( myEff == 6 ) gridSparse = (AliCFGridSparse*)data->GetGrid(5); // Rec (acc + cuts) draw kine properties THnSparse* numData = (THnSparse*)gridSparse->GetGrid(); // method 2: defining a new THnSparse changing only the axis of interest Printf("Method 2 "); THnSparse* newnumData = (THnSparse*)numData->Clone("numNew"); newnumData->Reset(); Int_t nLimits=0; Double_t* newLimits =0; TString varname=""; if(rebinVar==0) { varname="pt"; nLimits = 17; newLimits = new Double_t[nLimits+1]; newLimits[0]=0; newLimits[1]=0.25; newLimits[2]=0.5; newLimits[3]=0.75; newLimits[4]=1; newLimits[5]=1.5; newLimits[6]=2; newLimits[7]=2.5; newLimits[8]=3; newLimits[9]=4; newLimits[10]=5; newLimits[11]=6; newLimits[12]=7; newLimits[13]=8; newLimits[14]=10; newLimits[15]=12; newLimits[16]=14; newLimits[17]=16; } else if (rebinVar==1) { varname="eta"; nLimits = 9; newLimits = new Double_t[nLimits+1]; newLimits[0]=-0.9; newLimits[1]=-0.7; newLimits[2]=-0.5; newLimits[3]=-0.3; newLimits[4]=-0.1; newLimits[5]=0.1; newLimits[6]=0.3; newLimits[7]=0.5; newLimits[8]=0.7; newLimits[9]=0.9; } else if (rebinVar==2) { varname="phi"; nLimits = 9; newLimits = new Double_t[nLimits+1]; for(Int_t i=0; i<=nLimits; i++) newLimits[i]=(Double_t)phimin + (phimax-phimin)/nLimits*(Double_t)i ; } const Int_t nnewLimits = nLimits; TAxis* axis = (TAxis*)newnumData->GetAxis(rebinVar); axis->Set(nnewLimits,newLimits); newnumData->SetBinEdges(rebinVar,newLimits); newnumData->RebinnedAdd(numData, 1); // checking the bin contents TH1D* h1 = (TH1D*)numData->Projection(rebinVar); Float_t sum = 0; Float_t sumnew = 0; Printf("Original THnSparse"); for (Int_t ibin = 1; ibin<=h1->GetNbinsX(); ibin++){ Printf("ibin = %d, low edge = %f, content = %f",ibin,h1->GetBinLowEdge(ibin),h1->GetBinContent(ibin)); sum+=h1->GetBinContent(ibin); } Printf("THnSparse changing only one axis"); TH1D* h2num = (TH1D*)newnumData->Projection(rebinVar); for (Int_t ibin = 1; ibin<=h2num->GetNbinsX(); ibin++){ Printf("ibin = %d, low edge = %f, content = %f",ibin,h2num->GetBinLowEdge(ibin),h2num->GetBinContent(ibin)); sumnew+=h2num->GetBinContent(ibin); } Printf("sum = %f, sumnew = %f",sum, sumnew); // // *********** DENOMINATOR RECPID // Printf("DENOMINATOR"); AliCFGridSparse* gridSparse2 = 0; if( myEff == 1 ) gridSparse2 = (AliCFGridSparse*)data->GetGrid(0); // LimAcc else gridSparse2 = (AliCFGridSparse*)data->GetGrid(1); // GenAcc THnSparse* denData = (THnSparse*)gridSparse2->GetGrid(); // method 2: defining a new THnSparse changing only the axis of interest Printf("Method 2 "); THnSparse* newdenData = (THnSparse*)denData->Clone("denNew"); newdenData->Reset(); TAxis* axis2 = (TAxis*)newdenData->GetAxis(rebinVar); axis2->Set(nnewLimits,newLimits); newdenData->SetBinEdges(rebinVar,newLimits); newdenData->RebinnedAdd(denData, 1); // checking the bin contents TH1D* h1d = (TH1D*)denData->Projection(rebinVar); sum = 0; sumnew = 0; Printf("Original THnSparse"); for (Int_t ibin = 1; ibin<=h1d->GetNbinsX(); ibin++){ Printf("ibin = %d, low edge = %f, content = %f",ibin,h1d->GetBinLowEdge(ibin),h1d->GetBinContent(ibin)); sum+=h1d->GetBinContent(ibin); } Printf("THnSparse changing only one axis"); TH1D* h2 = (TH1D*)newdenData->Projection(rebinVar); for (Int_t ibin = 1; ibin<=h2->GetNbinsX(); ibin++){ Printf("ibin = %d, low edge = %f, content = %f",ibin,h2->GetBinLowEdge(ibin),h2->GetBinContent(ibin)); sumnew+=h2->GetBinContent(ibin); } Printf("sum = %f, sumnew = %f",sum, sumnew); TH1D* heff = (TH1D*)h2num->Clone("heff"); heff->Divide(h2num, h2,1,1,"B"); // heff->GetXaxis()->SetRangeUser(0,23.5); TFile* fout = NULL; if( myEff == 1 ) { fout = new TFile(Form("efficiency_STE_GenAcc_over_LimAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE"); heff->Write(Form("h_%s_effCFLimAccGenAcc",varname.Data())); h2num->Write(Form("h_%s_LimAcc",varname.Data())); h2->Write(Form("h_%s_GenAcc",varname.Data())); } else if( myEff == 2 ) { fout = new TFile(Form("efficiency_STE_RecPPR_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE"); heff->Write(Form("h_%s_effCFRecPPRGenAcc",varname.Data())); h2num->Write(Form("h_%s_RecPPR",varname.Data())); h2->Write(Form("h_%s_GenAcc",varname.Data())); } else if( myEff == 3 ) { fout = new TFile(Form("efficiency_STE_RecPID_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE"); heff->Write(Form("h_%s_effCFRecPIDGenAcc",varname.Data())); h2num->Write(Form("h_%s_RecPID",varname.Data())); h2->Write(Form("h_%s_GenAcc",varname.Data())); } else if( myEff == 4 ) { fout = new TFile(Form("efficiency_STE_Rec_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE"); heff->Write(Form("h_%s_effCFRecGenAcc",varname.Data())); h2num->Write(Form("h_%s_Rec",varname.Data())); h2->Write(Form("h_%s_GenAcc",varname.Data())); } else if( myEff == 5 ) { fout = new TFile(Form("efficiency_STE_RecAcc_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE"); heff->Write(Form("h_%s_effCFRecAccGenAcc",varname.Data())); h2num->Write(Form("h_%s_RecAcc",varname.Data())); h2->Write(Form("h_%s_GenAcc",varname.Data())); } else if( myEff == 6 ) { fout = new TFile(Form("efficiency_STE_RecPPRKine_over_GenAcc_rebinned_%d_%s.root",rebinVar,name),"RECREATE"); heff->Write(Form("h_%s_effCFRecPPRKineGenAcc",varname.Data())); h2num->Write(Form("h_%s_RecPPRKine",varname.Data())); h2->Write(Form("h_%s_GenAcc",varname.Data())); } fout->Close(); }