/* $Id$ */ #include "dNdEtaAnalysis.h" #include #include #include #include #include #include #include #include #include #include #include #include "AlidNdEtaCorrection.h" #include #include #include #include //____________________________________________________________________ ClassImp(dNdEtaAnalysis) //____________________________________________________________________ dNdEtaAnalysis::dNdEtaAnalysis() : TNamed(), fData(0), fMult(0), fPtDist(0) { // default constructor for (Int_t i=0; i (fdNdEta[0]->Clone(Form("%s_corrected", fdNdEta[0]->GetName()))); for (Int_t i=1; i (fdNdEta[0]->Clone(Form("%s_%d", fdNdEta[0]->GetName(), i))); fdNdEtaPtCutOffCorrected[i] = dynamic_cast (fdNdEtaPtCutOffCorrected[0]->Clone(Form("%s_%d", fdNdEtaPtCutOffCorrected[0]->GetName(), i))); } fPtDist = new TH1F("Pt", "p_{T} distribution;p_{T} [GeV/c];#frac{dN}{d#eta dp_{T}} [c/GeV]", 28, binLimitsPt); TH1::AddDirectory(oldStatus); } //____________________________________________________________________ dNdEtaAnalysis::~dNdEtaAnalysis() { // destructor if (fData) { delete fData; fData = 0; } if (fMult) { delete fMult; fMult = 0; } for (Int_t i=0; i (fData->Clone()); target.fMult = dynamic_cast (fMult->Clone()); for (Int_t i=0; i (fdNdEta[i]->Clone()); target.fdNdEtaPtCutOffCorrected[i] = dynamic_cast (fdNdEtaPtCutOffCorrected[i]->Clone()); } target.fPtDist = dynamic_cast (fPtDist->Clone()); TNamed::Copy((TNamed &) c); } //____________________________________________________________________ void dNdEtaAnalysis::FillTrack(Float_t vtx, Float_t eta, Float_t pt) { // fills a track into the histograms fData->GetTrackCorrection()->FillMeas(vtx, eta, pt); } //____________________________________________________________________ void dNdEtaAnalysis::FillEvent(Float_t vtx, Float_t n) { // fills an event into the histograms fData->GetEventCorrection()->FillMeas(vtx, n); } //____________________________________________________________________ void dNdEtaAnalysis::FillTriggeredEvent(Float_t n) { // fills a triggered event into the histograms fMult->Fill(n); } //____________________________________________________________________ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, AlidNdEtaCorrection::CorrectionType correctionType, Int_t multCut) { // // correct with the given correction values and calculate dNdEta and pT distribution // the corrections that are applied can be steered by the flag correctionType // the measured result is not used up to a multiplicity of multCut (the bin at multCut is the first that is used!) // // TODO put tag somewhere which corrections have been applied if (multCut > 1) { Printf("ERROR: A bigger multiplicity cut than 1 is not possible in the current implementation"); return; } // set corrections to 1 fData->SetCorrectionToUnity(); if (correction && correctionType != AlidNdEtaCorrection::kNone) { TH3F* trackCorr = fData->GetTrackCorrection()->GetCorrectionHistogram(); TH2F* eventCorr = fData->GetEventCorrection()->GetCorrectionHistogram(); if (correctionType >= AlidNdEtaCorrection::kTrack2Particle) trackCorr->Multiply(correction->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetCorrectionHistogram()); if (correctionType >= AlidNdEtaCorrection::kVertexReco) { trackCorr->Multiply(correction->GetVertexRecoCorrection()->GetTrackCorrection()->GetCorrectionHistogram()); eventCorr->Multiply(correction->GetVertexRecoCorrection()->GetEventCorrection()->GetCorrectionHistogram()); // set bin with multiplicity 0 to 1 (correction has no meaning in this bin) for (Int_t i=0; i<=eventCorr->GetNbinsX()+1; i++) eventCorr->SetBinContent(i, 1, 1); } switch (correctionType) { case AlidNdEtaCorrection::kINEL : { trackCorr->Multiply(correction->GetTriggerBiasCorrectionINEL()->GetTrackCorrection()->GetCorrectionHistogram()); eventCorr->Multiply(correction->GetTriggerBiasCorrectionINEL()->GetEventCorrection()->GetCorrectionHistogram()); break; } case AlidNdEtaCorrection::kNSD : { trackCorr->Multiply(correction->GetTriggerBiasCorrectionNSD()->GetTrackCorrection()->GetCorrectionHistogram()); eventCorr->Multiply(correction->GetTriggerBiasCorrectionNSD()->GetEventCorrection()->GetCorrectionHistogram()); break; } case AlidNdEtaCorrection::kND : { trackCorr->Multiply(correction->GetTriggerBiasCorrectionND()->GetTrackCorrection()->GetCorrectionHistogram()); eventCorr->Multiply(correction->GetTriggerBiasCorrectionND()->GetEventCorrection()->GetCorrectionHistogram()); break; } default : break; } } else printf("INFO: No correction applied\n"); fData->Multiply(); if (correctionType >= AlidNdEtaCorrection::kVertexReco) { // There are no events with vertex that have 0 multiplicity, therefore // populate bin with 0 multiplicity with the following idea: // alpha = triggered events with vertex at a given vertex position / all triggered events with vertex // triggered events without vertex and 0 multiplicity at a given vertex position = alpha * all triggered events with 0 multiplicity // afterwards we still correct for the trigger efficiency TH2* measuredEvents = fData->GetEventCorrection()->GetMeasuredHistogram(); TH2* correctedEvents = fData->GetEventCorrection()->GetGeneratedHistogram(); //new TCanvas; correctedEvents->DrawCopy("TEXT"); // start above 0 mult. bin with integration TH1* vertexDist = measuredEvents->ProjectionX("vertexdist_measured", 2); //new TCanvas; vertexDist->DrawCopy(); Int_t allEventsWithVertex = (Int_t) vertexDist->Integral(0, vertexDist->GetNbinsX()+1); // include under/overflow! Int_t triggeredEventsWith0Mult = (Int_t) fMult->GetBinContent(1); Printf("%d triggered events with 0 mult. -- %d triggered events with vertex", triggeredEventsWith0Mult, allEventsWithVertex); for (Int_t i = 1; i <= measuredEvents->GetNbinsX(); i++) { Double_t alpha = vertexDist->GetBinContent(i) / allEventsWithVertex; Double_t events = alpha * triggeredEventsWith0Mult; // multiply with trigger correction if set above events *= fData->GetEventCorrection()->GetCorrectionHistogram()->GetBinContent(i, 1); Printf("Bin %d, alpha is %.2f, number of events with 0 mult. are %.2f", i, alpha, events); correctedEvents->SetBinContent(i, 1, events); } //new TCanvas; correctedEvents->DrawCopy("TEXT"); } fData->PrintInfo(ptCut); TH3F* dataHist = fData->GetTrackCorrection()->GetGeneratedHistogram(); // integrate multiplicity axis out (include under/overflow bins!!!) TH2F* tmp = fData->GetEventCorrection()->GetGeneratedHistogram(); TH1D* vertexHist = (TH1D*) tmp->ProjectionX("_px", 0, tmp->GetNbinsY() + 1, "e"); // create pt hist { // reset all ranges dataHist->GetXaxis()->SetRange(0, 0); dataHist->GetYaxis()->SetRange(0, 0); dataHist->GetZaxis()->SetRange(0, 0); // vtx cut Int_t vertexBinBegin = dataHist->GetXaxis()->FindBin(-5); Int_t vertexBinEnd = dataHist->GetXaxis()->FindBin(5); dataHist->GetXaxis()->SetRange(vertexBinBegin, vertexBinEnd); Float_t nEvents = vertexHist->Integral(vertexBinBegin, vertexBinEnd); if (nEvents > 0) { // eta cut dataHist->GetYaxis()->SetRange(dataHist->GetYaxis()->FindBin(-0.8), dataHist->GetYaxis()->FindBin(0.8)); Float_t etaWidth = 1.6; TH1D* ptHist = dynamic_cast (dataHist->Project3D("ze")); for (Int_t i=1; i<=fPtDist->GetNbinsX(); ++i) { Float_t binSize = fPtDist->GetBinWidth(i); fPtDist->SetBinContent(i, ptHist->GetBinContent(i) / binSize / nEvents / etaWidth); fPtDist->SetBinError(i, ptHist->GetBinError(i) / binSize / nEvents / etaWidth); } delete ptHist; } else printf("ERROR: nEvents is 0!\n"); } // reset all ranges dataHist->GetXaxis()->SetRange(0, 0); dataHist->GetYaxis()->SetRange(0, 0); dataHist->GetZaxis()->SetRange(0, 0); // integrate over pt (with pt cut) Int_t ptLowBin = 1; if (ptCut > 0) ptLowBin = dataHist->GetZaxis()->FindBin(ptCut); dataHist->GetZaxis()->SetRange(ptLowBin, dataHist->GetZaxis()->GetNbins()+1); printf("pt range %d %d\n", ptLowBin, dataHist->GetZaxis()->GetNbins()+1); TH2D* vtxVsEta = dynamic_cast (dataHist->Project3D("yx2e")); dataHist->GetZaxis()->SetRange(0, 0); vtxVsEta->GetXaxis()->SetTitle(dataHist->GetXaxis()->GetTitle()); vtxVsEta->GetYaxis()->SetTitle(dataHist->GetYaxis()->GetTitle()); if (vtxVsEta == 0) { printf("ERROR: pt integration failed\n"); return; } //new TCanvas; vtxVsEta->DrawCopy("COLZ"); //vtxVsEta->Rebin2D(1, 4); const Float_t vertexRange = 9.99; for (Int_t iEta=1; iEta<=vtxVsEta->GetNbinsY(); iEta++) { // do we have several histograms for different vertex positions? Int_t vertexBinGlobalBegin = vertexHist->GetXaxis()->FindBin(-vertexRange); Int_t vertexBinWidth = (vertexHist->GetXaxis()->FindBin(vertexRange) - vertexBinGlobalBegin + 1) / (kVertexBinning-1); //printf("vertexBinGlobalBegin = %d, vertexBinWidth = %d\n", vertexBinGlobalBegin, vertexBinWidth); for (Int_t vertexPos=0; vertexPos 0) { vertexBinBegin = vertexBinGlobalBegin + vertexBinWidth * (vertexPos-1); vertexBinEnd = vertexBinBegin + vertexBinWidth; } //printf("vertexBinBegin = %d, vertexBinEnd = %d\n", vertexBinBegin, vertexBinEnd); Float_t totalEvents = vertexHist->Integral(vertexBinBegin, vertexBinEnd - 1); if (totalEvents == 0) { printf("WARNING: No events for hist %d %d %d\n", vertexPos, vertexBinBegin, vertexBinEnd); continue; } Float_t sum = 0; Float_t sumError2 = 0; for (Int_t iVtx = vertexBinBegin; iVtx < vertexBinEnd; iVtx++) { if (vtxVsEta->GetBinContent(iVtx, iEta) != 0) { sum = sum + vtxVsEta->GetBinContent(iVtx, iEta); if (sumError2 > 10e30) printf("WARNING: sum of error2 is dangerously large - be prepared for crash... "); sumError2 = sumError2 + TMath::Power(vtxVsEta->GetBinError(iVtx, iEta),2); } } Float_t ptCutOffCorrection = 1; if (correction && ptCut > 0) ptCutOffCorrection = correction->GetMeasuredFraction(correctionType, ptCut, vtxVsEta->GetYaxis()->GetBinCenter(iEta)); if (ptCutOffCorrection <= 0) { printf("UNEXPECTED: ptCutOffCorrection is %f for hist %d %d %d\n", ptCutOffCorrection, vertexPos, vertexBinBegin, vertexBinEnd); continue; } //printf("Eta: %d Vertex Range: %d %d, Event Count %f, Track Sum: %f, Track Sum corrected: %f\n", iEta, vertexBinBegin, vertexBinEnd, totalEvents, sum, sum / ptCutOffCorrection); Int_t bin = fdNdEta[vertexPos]->FindBin(vtxVsEta->GetYaxis()->GetBinCenter(iEta)); if (bin > 0 && bin < fdNdEta[vertexPos]->GetNbinsX()) { Float_t dndeta = sum / totalEvents; Float_t error = TMath::Sqrt(sumError2) / totalEvents; dndeta = dndeta / fdNdEta[vertexPos]->GetBinWidth(bin); error = error / fdNdEta[vertexPos]->GetBinWidth(bin); fdNdEta[vertexPos]->SetBinContent(bin, dndeta); fdNdEta[vertexPos]->SetBinError(bin, error); dndeta /= ptCutOffCorrection; error /= ptCutOffCorrection; fdNdEtaPtCutOffCorrected[vertexPos]->SetBinContent(bin, dndeta); fdNdEtaPtCutOffCorrected[vertexPos]->SetBinError(bin, error); //Printf("Bin %d has dN/deta = %f", bin, dndeta); } } } //new TCanvas; fdNdEta[0]->DrawCopy(); } //____________________________________________________________________ void dNdEtaAnalysis::SaveHistograms() { // save the histograms to a directory with the name of this class (retrieved from TNamed) gDirectory->mkdir(GetName()); gDirectory->cd(GetName()); if (fData) { fData->SaveHistograms(); } else printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fData is 0\n"); if (fMult) { fMult->Write(); } else printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fMult is 0\n"); if (fPtDist) fPtDist ->Write(); else printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fPtDist is 0\n"); for (Int_t i=0; iWrite(); else printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEta[%d] is 0\n", i); if (fdNdEtaPtCutOffCorrected[i]) fdNdEtaPtCutOffCorrected[i]->Write(); else printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEtaPtCutOffCorrected[%d] is 0\n", i); } gDirectory->cd("../"); } void dNdEtaAnalysis::LoadHistograms(const Char_t* dir) { // loads the histograms from a directory with the name of this class (retrieved from TNamed) if (!dir) dir = GetName(); gDirectory->cd(dir); fData->LoadHistograms(); fMult = dynamic_cast (gDirectory->Get(fMult->GetName())); for (Int_t i=0; i (gDirectory->Get(fdNdEta[i]->GetName())); fdNdEtaPtCutOffCorrected[i] = dynamic_cast (gDirectory->Get(fdNdEtaPtCutOffCorrected[i]->GetName())); } fPtDist = dynamic_cast (gDirectory->Get(fPtDist->GetName())); gDirectory->cd("../"); } //____________________________________________________________________ void dNdEtaAnalysis::DrawHistograms(Bool_t simple) { // draws the histograms if (!simple) { if (fData) fData->DrawHistograms(GetName()); TCanvas* canvas = new TCanvas(Form("%s_dNdEtaAnalysis", GetName()), Form("%s_dNdEtaAnalysis", GetName()), 800, 400); canvas->Divide(2, 1); canvas->cd(1); if (fdNdEtaPtCutOffCorrected[0]) fdNdEtaPtCutOffCorrected[0]->DrawCopy(); if (fdNdEta[0]) { fdNdEta[0]->SetLineColor(kRed); fdNdEta[0]->DrawCopy("SAME"); } canvas->cd(2); if (fPtDist) fPtDist->DrawCopy(); } // histograms for different vertices? if (kVertexBinning > 0) { // doesnt work, but i dont get it, giving up... TCanvas* canvas2 = new TCanvas(Form("%s_dNdEtaAnalysisVtx", GetName()), Form("%s_dNdEtaAnalysisVtx", GetName()), 450, 450); TCanvas* canvas3 = 0; if (!simple) canvas3 = new TCanvas(Form("%s_dNdEtaAnalysisVtx_noptcutoff", GetName()), Form("%s_dNdEtaAnalysisVtx_noptcutoff", GetName()), 450, 450); //Int_t yPads = (Int_t) TMath::Ceil(((Double_t) kVertexBinning - 1) / 2); //printf("%d\n", yPads); //canvas2->Divide(2, yPads); TLegend* legend = new TLegend(0.4, 0.2, 0.6, 0.4); for (Int_t i=0; icd(); fdNdEtaPtCutOffCorrected[i]->SetLineColor(i+1); fdNdEtaPtCutOffCorrected[i]->DrawCopy((i == 0) ? "" : "SAME"); legend->AddEntry(fdNdEtaPtCutOffCorrected[i], (i == 0) ? "Vtx All" : Form("Vtx Bin %d", i-1)); } if (canvas3 && fdNdEta[i]) { canvas3->cd(); fdNdEta[i]->SetLineColor(i+1); fdNdEta[i]->DrawCopy((i == 0) ? "" : "SAME"); } } canvas2->cd(); legend->Draw(); canvas2->SaveAs(Form("%s_%s.gif", canvas2->GetName(), GetName())); if (canvas3) { canvas3->cd(); legend->Draw(); } } if (kVertexBinning == 3) { TH1* clone = dynamic_cast (fdNdEtaPtCutOffCorrected[1]->Clone("clone")); TH1* clone2 = dynamic_cast (fdNdEtaPtCutOffCorrected[2]->Clone("clone2")); if (clone && clone2) { TCanvas* canvas4 = new TCanvas(Form("%s_dNdEtaAnalysisVtxRatios", GetName()), Form("%s_dNdEtaAnalysisVtxRatios", GetName()), 450, 450); clone->Divide(fdNdEtaPtCutOffCorrected[0]); clone->GetYaxis()->SetRangeUser(0.95, 1.05); clone->DrawCopy(); clone2->Divide(fdNdEtaPtCutOffCorrected[0]); clone2->DrawCopy("SAME"); TLine* line = new TLine(-1, 1, 1, 1); line->Draw(); canvas4->SaveAs(Form("%s_%s.gif", canvas4->GetName(), GetName())); } } } Long64_t dNdEtaAnalysis::Merge(TCollection* list) { // Merges a list of dNdEtaAnalysis objects with this one. // This is needed for PROOF. // Returns the number of merged objects (including this) if (!list) return 0; if (list->IsEmpty()) return 1; TIterator* iter = list->MakeIterator(); TObject* obj; // sub collections const Int_t nCollections = 2 * kVertexBinning + 3; // 3 standalone hists, 3 arrays of size kVertexBinning TList* collections[nCollections]; for (Int_t i=0; iNext())) { dNdEtaAnalysis* entry = dynamic_cast (obj); if (entry == 0) continue; collections[0]->Add(entry->fData); collections[2]->Add(entry->fMult); collections[3]->Add(entry->fPtDist); for (Int_t i=0; iAdd(entry->fdNdEta[i]); collections[3+kVertexBinning+i]->Add(entry->fdNdEtaPtCutOffCorrected[i]); } ++count; } fData->Merge(collections[0]); fMult->Merge(collections[1]); fPtDist->Merge(collections[2]); for (Int_t i=0; iMerge(collections[3+i]); fdNdEtaPtCutOffCorrected[i]->Merge(collections[3+kVertexBinning+i]); } for (Int_t i=0; i