X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=CORRFW%2FAliCFGridSparse.cxx;h=a5b975a8354f0bfb3e06384057c928aea6d2376e;hb=96daf49c354b5c48c12f968c4591cbd75fcd3f3b;hp=1c4f31232032362146a26e7e4fd4fe5a2d299679;hpb=b12ab49166fc18f92088c1428baba1f8b08f94f1;p=u%2Fmrichter%2FAliRoot.git diff --git a/CORRFW/AliCFGridSparse.cxx b/CORRFW/AliCFGridSparse.cxx index 1c4f3123203..a5b975a8354 100755 --- a/CORRFW/AliCFGridSparse.cxx +++ b/CORRFW/AliCFGridSparse.cxx @@ -33,6 +33,7 @@ #include "TH2D.h" #include "TH3D.h" #include "TAxis.h" +#include "AliCFUnfolding.h" //____________________________________________________________________ ClassImp(AliCFGridSparse) @@ -131,74 +132,7 @@ void AliCFGridSparse::Fill(const Double_t *var, Double_t weight) } //___________________________________________________________________ -TH1D *AliCFGridSparse::Project(Int_t ivar) const -{ - // - // Make a 1D projection along variable ivar - // - - TH1D *hist=fData->Projection(ivar); - hist->SetXTitle(GetVarTitle(ivar)); - hist->SetName(Form("%s_proj-%s",GetName(),GetVarTitle(ivar))); - hist->SetTitle(Form("%s: projection on %s",GetTitle(),GetVarTitle(ivar))); - for (Int_t iBin=1; iBin<=GetNBins(ivar); iBin++) { - TString binLabel = GetAxis(ivar)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) hist->GetXaxis()->SetBinLabel(iBin,binLabel); - } - return hist; -} -//___________________________________________________________________ -TH2D *AliCFGridSparse::Project(Int_t ivar1, Int_t ivar2) const -{ - // - // Make a 2D projection along variables ivar1 & ivar2 - // - - TH2D *hist=fData->Projection(ivar2,ivar1); //notice inverted axis (THnSparse uses TH3 2d-projection convention...) - hist->SetXTitle(GetVarTitle(ivar1)); - hist->SetYTitle(GetVarTitle(ivar2)); - hist->SetName(Form("%s_proj-%s,%s",GetName(),GetVarTitle(ivar1),GetVarTitle(ivar2))); - hist->SetTitle(Form("%s: projection on %s-%s",GetTitle(),GetVarTitle(ivar1),GetVarTitle(ivar2))); - for (Int_t iBin=1; iBin<=GetNBins(ivar1); iBin++) { - TString binLabel = GetAxis(ivar1)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) hist->GetXaxis()->SetBinLabel(iBin,binLabel); - } - for (Int_t iBin=1; iBin<=GetNBins(ivar2); iBin++) { - TString binLabel = GetAxis(ivar2)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) hist->GetYaxis()->SetBinLabel(iBin,binLabel); - } - return hist; -} -//___________________________________________________________________ -TH3D *AliCFGridSparse::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const -{ - // - // Make a 3D projection along variables ivar1 & ivar2 & ivar3 - // - - TH3D *hist=fData->Projection(ivar1,ivar2,ivar3); - hist->SetXTitle(GetVarTitle(ivar1)); - hist->SetYTitle(GetVarTitle(ivar2)); - hist->SetZTitle(GetVarTitle(ivar3)); - hist->SetName(Form("%s_proj-%s,%s,%s",GetName(),GetVarTitle(ivar1),GetVarTitle(ivar2),GetVarTitle(ivar3))); - hist->SetTitle(Form("%s: projection on %s-%s-%s",GetTitle(),GetVarTitle(ivar1),GetVarTitle(ivar2),GetVarTitle(ivar3))); - for (Int_t iBin=1; iBin<=GetNBins(ivar1); iBin++) { - TString binLabel = GetAxis(ivar1)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) hist->GetXaxis()->SetBinLabel(iBin,binLabel); - } - for (Int_t iBin=1; iBin<=GetNBins(ivar2); iBin++) { - TString binLabel = GetAxis(ivar2)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) hist->GetYaxis()->SetBinLabel(iBin,binLabel); - } - for (Int_t iBin=1; iBin<=GetNBins(ivar3); iBin++) { - TString binLabel = GetAxis(ivar3)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) hist->GetZaxis()->SetBinLabel(iBin,binLabel); - } - return hist; -} - -//___________________________________________________________________ -AliCFGridSparse* AliCFGridSparse::Project(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const +AliCFGridSparse* AliCFGridSparse::MakeSlice(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const { // // projects the grid on the nVars dimensions defined in vars. @@ -219,14 +153,14 @@ AliCFGridSparse* AliCFGridSparse::Project(Int_t nVars, const Int_t* vars, const THnSparse* clone = ((THnSparse*)fData->Clone()); if (varMin && varMax) { for (Int_t iAxis=0; iAxisGetAxis(iAxis)->SetRange((Int_t)varMin[iAxis],(Int_t)varMax[iAxis]); - else clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); + SetAxisRange(clone->GetAxis(iAxis),varMin[iAxis],varMax[iAxis],useBins); } } else AliInfo("Keeping same axis ranges"); out->SetGrid(clone->Projection(nVars,vars)); delete [] bins; + delete clone; return out; } @@ -298,7 +232,7 @@ Float_t AliCFGridSparse::GetElementError(Long_t index) const // Returns the error on the content // - return fData->GetBinContent(index); + return fData->GetBinError(index); } //____________________________________________________________________ Float_t AliCFGridSparse::GetElementError(const Int_t *bin) const @@ -600,47 +534,6 @@ Long_t AliCFGridSparse::GetEmptyBins() const { return (GetNBinsTotal() - GetNFilledBins()) ; } -//_____________________________________________________________________ -// Int_t AliCFGridSparse::GetEmptyBins( Double_t *varMin, Double_t* varMax ) const -// { -// // -// // Get empty bins in a range specified by varMin and varMax -// // - -// Int_t *indexMin = new Int_t[GetNVar()]; -// Int_t *indexMax = new Int_t[GetNVar()]; - -// //Find out the min and max bins - -// for (Int_t i=0;iGetAxis(i)->GetNbins()+1; -// Double_t *bins=new Double_t[nbins]; -// for(Int_t ibin =0;ibin=indexMin[j] && fIndex[j]<=indexMax[j]))isIn=kFALSE; -// } -// if(isIn && GetElement(i)<=0)val++; -// } -// AliInfo(Form(" the empty bins = %i ",val)); - -// delete [] indexMin; -// delete [] indexMax; -// return val; -// } - //____________________________________________________________________ Int_t AliCFGridSparse::CheckStats(Double_t thr) const { @@ -663,91 +556,6 @@ Double_t AliCFGridSparse::GetIntegral() const return fData->ComputeIntegral(); } -//_____________________________________________________________________ -// Double_t AliCFGridSparse::GetIntegral(Int_t *binMin, Int_t* binMax ) const -// { -// // -// // Get Integral in a range of bin indeces (extremes included) -// // - -// Double_t val=0; - -// for(Int_t i=0;ifNVarBins[i])binMax[i]=fNVarBins[i]; -// if((binMin[i]>binMax[i])){ -// AliInfo(Form(" Bin indices in variable %i in reverse order, please check!", i)); -// return val; -// } -// } -// val=GetSum(0,binMin,binMax); - -// return val; -// } - -//_____________________________________________________________________ -// Double_t AliCFGridSparse::GetIntegral(Double_t *varMin, Double_t* varMax ) const -// { -// // -// // Get Integral in a range (extremes included) -// // - -// Int_t *indexMin=new Int_t[GetNVar()]; -// Int_t *indexMax=new Int_t[GetNVar()]; - -// //Find out the min and max bins - -// for(Int_t i=0;iClone(); - for (Int_t iAxis=0; iAxisGetAxis(iAxis)->SetRange((Int_t)varMin[iAxis],(Int_t)varMax[iAxis]); - else clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); + if (varMin != 0x0 && varMax != 0x0) { + for (Int_t iAxis=0; iAxisGetAxis(iAxis),varMin[iAxis],varMax[iAxis],useBins); } - TH1D* projection = 0x0 ; + TH1* projection = 0x0 ; + TString name,title; + GetProjectionName (name ,iVar1,iVar2,iVar3); + GetProjectionTitle(title,iVar1,iVar2,iVar3); - TObject* objInMem = gROOT->FindObject(Form("%s_proj_%d",clone->GetName(),iVar)) ; - if (objInMem) { - TString name(objInMem->ClassName()); - if (name.CompareTo("TH1D")==0) projection = (TH1D*) objInMem ; - else projection = clone->Projection(iVar); + if (iVar3<0) { + if (iVar2<0) { + if (iVar1 >= GetNVar() || iVar1 < 0 ) { + AliError("Non-existent variable, return NULL"); + return 0x0; + } + projection = (TH1D*)clone->Projection(iVar1); + projection->SetTitle(Form("%s_proj-%s",GetTitle(),GetVarTitle(iVar1))); + for (Int_t iBin=1; iBin<=projection->GetNbinsX(); iBin++) { + Int_t origBin = GetAxis(iVar1)->GetFirst()+iBin-1; + TString binLabel = GetAxis(iVar1)->GetBinLabel(origBin) ; + if (binLabel.CompareTo("") != 0) projection->GetXaxis()->SetBinLabel(iBin,binLabel); + } + } + else { + if (iVar1 >= GetNVar() || iVar1 < 0 || + iVar2 >= GetNVar() || iVar2 < 0 ) { + AliError("Non-existent variable, return NULL"); + return 0x0; + } + projection = (TH2D*)clone->Projection(iVar2,iVar1); + for (Int_t iBin=1; iBin<=projection->GetNbinsX(); iBin++) { + Int_t origBin = GetAxis(iVar1)->GetFirst()+iBin-1; + TString binLabel = GetAxis(iVar1)->GetBinLabel(origBin) ; + if (binLabel.CompareTo("") != 0) projection->GetXaxis()->SetBinLabel(iBin,binLabel); + } + for (Int_t iBin=1; iBin<=projection->GetNbinsY(); iBin++) { + Int_t origBin = GetAxis(iVar2)->GetFirst()+iBin-1; + TString binLabel = GetAxis(iVar2)->GetBinLabel(origBin) ; + if (binLabel.CompareTo("") != 0) projection->GetYaxis()->SetBinLabel(iBin,binLabel); + } + } } - else projection = clone->Projection(iVar); - delete clone; - for (Int_t iBin=1; iBin<=GetNBins(iVar); iBin++) { - TString binLabel = GetAxis(iVar)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) projection->GetXaxis()->SetBinLabel(iBin,binLabel); + else { + if (iVar1 >= GetNVar() || iVar1 < 0 || + iVar2 >= GetNVar() || iVar2 < 0 || + iVar3 >= GetNVar() || iVar3 < 0 ) { + AliError("Non-existent variable, return NULL"); + return 0x0; + } + projection = (TH3D*)clone->Projection(iVar1,iVar2,iVar3); + for (Int_t iBin=1; iBin<=projection->GetNbinsX(); iBin++) { + Int_t origBin = GetAxis(iVar1)->GetFirst()+iBin-1; + TString binLabel = GetAxis(iVar1)->GetBinLabel(origBin) ; + if (binLabel.CompareTo("") != 0) projection->GetXaxis()->SetBinLabel(iBin,binLabel); + } + for (Int_t iBin=1; iBin<=projection->GetNbinsY(); iBin++) { + Int_t origBin = GetAxis(iVar2)->GetFirst()+iBin-1; + TString binLabel = GetAxis(iVar2)->GetBinLabel(origBin) ; + if (binLabel.CompareTo("") != 0) projection->GetYaxis()->SetBinLabel(iBin,binLabel); + } + for (Int_t iBin=1; iBin<=projection->GetNbinsZ(); iBin++) { + Int_t origBin = GetAxis(iVar3)->GetFirst()+iBin-1; + TString binLabel = GetAxis(iVar3)->GetBinLabel(origBin) ; + if (binLabel.CompareTo("") != 0) projection->GetZaxis()->SetBinLabel(iBin,binLabel); + } } - return projection ; -} - -//____________________________________________________________________ -TH2D* AliCFGridSparse::Slice(Int_t iVar1, Int_t iVar2, const Double_t *varMin, const Double_t *varMax, Bool_t useBins) const -{ - // - // return a slice (2D-projection) on variables iVar1 and iVar2 while axis ranges are defined with varMin,varMax - // arrays varMin and varMax contain the min and max values of each variable. - // therefore varMin and varMax must have their dimensions equal to GetNVar() - // If useBins=true, varMin and varMax are taken as bin numbers - THnSparse* clone = (THnSparse*)fData->Clone(); - for (Int_t iAxis=0; iAxisGetAxis(iAxis)->SetRange((Int_t)varMin[iAxis],(Int_t)varMax[iAxis]); - else clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); - } - - TH2D* projection = 0x0 ; + projection->SetName (name .Data()); + projection->SetTitle(title.Data()); - TObject* objInMem = gROOT->FindObject(Form("%s_proj_%d_%d",clone->GetName(),iVar2,iVar1)) ; - if (objInMem) { - TString name(objInMem->ClassName()); - if (name.CompareTo("TH2D")==0) projection = (TH2D*) objInMem ; - else projection = clone->Projection(iVar1,iVar2); - } - else projection = clone->Projection(iVar1,iVar2); delete clone; - for (Int_t iBin=1; iBin<=GetNBins(iVar1); iBin++) { - TString binLabel = GetAxis(iVar1)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) projection->GetXaxis()->SetBinLabel(iBin,binLabel); - } - for (Int_t iBin=1; iBin<=GetNBins(iVar2); iBin++) { - TString binLabel = GetAxis(iVar2)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) projection->GetYaxis()->SetBinLabel(iBin,binLabel); - } return projection ; } //____________________________________________________________________ -TH3D* AliCFGridSparse::Slice(Int_t iVar1, Int_t iVar2, Int_t iVar3, const Double_t *varMin, const Double_t *varMax, Bool_t useBins) const -{ +void AliCFGridSparse::SetAxisRange(TAxis* axis, Double_t min, Double_t max, Bool_t useBins) const { // - // return a slice (3D-projection) on variables iVar1, iVar2 and iVar3 while axis ranges are defined with varMin,varMax - // arrays varMin and varMax contain the min and max values of each variable. - // therefore varMin and varMax must have their dimensions equal to GetNVar() - // If useBins=true, varMin and varMax are taken as bin numbers - - THnSparse* clone = (THnSparse*)fData->Clone(); - for (Int_t iAxis=0; iAxisGetAxis(iAxis)->SetRange((Int_t)varMin[iAxis],(Int_t)varMax[iAxis]); - else clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); - } - - TH3D* projection = 0x0 ; - - TObject* objInMem = gROOT->FindObject(Form("%s_proj_%d_%d_%d",clone->GetName(),iVar1,iVar2,iVar3)) ; - if (objInMem) { - TString name(objInMem->ClassName()); - if (name.CompareTo("TH3D")==0) projection = (TH3D*) objInMem ; - else projection = clone->Projection(iVar1,iVar2,iVar3); - } - else projection = clone->Projection(iVar1,iVar2,iVar3); - delete clone; - for (Int_t iBin=1; iBin<=GetNBins(iVar1); iBin++) { - TString binLabel = GetAxis(iVar1)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) projection->GetXaxis()->SetBinLabel(iBin,binLabel); - } - for (Int_t iBin=1; iBin<=GetNBins(iVar2); iBin++) { - TString binLabel = GetAxis(iVar2)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) projection->GetYaxis()->SetBinLabel(iBin,binLabel); - } - for (Int_t iBin=1; iBin<=GetNBins(iVar3); iBin++) { - TString binLabel = GetAxis(iVar3)->GetBinLabel(iBin) ; - if (binLabel.CompareTo("") != 0) projection->GetZaxis()->SetBinLabel(iBin,binLabel); - } - return projection ; + // sets axis range, and forces bit TAxis::kAxisRange + // + + if (useBins) axis->SetRange ((Int_t)min,(Int_t)max); + else axis->SetRangeUser( min, max); + //axis->SetBit(TAxis::kAxisRange); // uncomment when ROOT TAxis is fixed } //____________________________________________________________________ -void AliCFGridSparse::SetRangeUser(Int_t iVar, Double_t varMin, Double_t varMax) { +void AliCFGridSparse::SetRangeUser(Int_t iVar, Double_t varMin, Double_t varMax, Bool_t useBins) const { // // set range of axis iVar. // - fData->GetAxis(iVar)->SetRangeUser(varMin,varMax); - AliWarning(Form("THnSparse axis %d range has been modified",iVar)); + SetAxisRange(fData->GetAxis(iVar),varMin,varMax,useBins); + //AliInfo(Form("AliCFGridSparse axis %d range has been modified",iVar)); + TAxis* currAxis = fData->GetAxis(iVar); + TString outString = Form("%s new range: %.1f < %s < %.1f", GetName(), currAxis->GetBinLowEdge(currAxis->GetFirst()), currAxis->GetTitle(), currAxis->GetBinUpEdge(currAxis->GetLast())); + TString binLabel = currAxis->GetBinLabel(currAxis->GetFirst()); + if ( ! binLabel.IsNull() ) { + outString += " ( "; + for ( Int_t ibin = currAxis->GetFirst(); ibin <= currAxis->GetLast(); ibin++ ) { + outString += Form("%s ", currAxis->GetBinLabel(ibin)); + } + outString += ")"; + } + AliWarning(outString.Data()); + } //____________________________________________________________________ -void AliCFGridSparse::SetRangeUser(const Double_t *varMin, const Double_t *varMax) { +void AliCFGridSparse::SetRangeUser(const Double_t *varMin, const Double_t *varMax, Bool_t useBins) const { // // set range of every axis. varMin and varMax must be of dimension GetNVar() // for (Int_t iAxis=0; iAxisGetAxis(iAxis)->SetBit(TAxis::kAxisRange,b); + AliInfo("AliCFGridSparse axes ranges have been modified"); } //____________________________________________________________________ @@ -988,3 +791,15 @@ Float_t AliCFGridSparse::GetUnderFlows(Int_t ivar, Bool_t exclusive) const return unfl; } + +//____________________________________________________________________ +void AliCFGridSparse::Smooth() { + // + // smoothing function: TO USE WITH CARE + // + + AliInfo("Your GridSparse is going to be smoothed"); + AliInfo(Form("N TOTAL BINS : %li",GetNBinsTotal())); + AliInfo(Form("N FILLED BINS : %li",GetNFilledBins())); + AliCFUnfolding::SmoothUsingNeighbours(fData); +}