// ----------------------------------------------------------------------
-// AliBWTools
+// AliPWGHistoTools
//
// This class provides some tools which can be useful in the analsis
// of spectra, to fit or transform histograms. See the comments of the
// Author: M. Floris (CERN)
// ----------------------------------------------------------------------
-#include "AliBWTools.h"
+#include "AliPWGHistoTools.h"
#include "TH1D.h"
#include "TF1.h"
#include "TH1.h"
using namespace std;
-ClassImp(AliBWTools)
+ClassImp(AliPWGHistoTools)
-TF1 * AliBWTools::fdNdptForETCalc = 0;
+TF1 * AliPWGHistoTools::fdNdptForETCalc = 0;
-AliBWTools::AliBWTools() {
+AliPWGHistoTools::AliPWGHistoTools() {
// ctor
}
-AliBWTools::~AliBWTools(){
+AliPWGHistoTools::~AliPWGHistoTools(){
// dtor
}
-TH1 * AliBWTools::GetdNdmtFromdNdpt(const TH1 * hpt, Double_t mass) {
+TH1 * AliPWGHistoTools::GetdNdmtFromdNdpt(const TH1 * hpt, Double_t mass) {
// convert the x axis from pt to mt. Assumes you have 1/pt dNdpt in the histo you start with
Int_t nbins = hpt->GetNbinsX();
}
-TH1 * AliBWTools::GetdNdptFromdNdmt(const TH1 * hmt, Double_t mass) {
+TH1 * AliPWGHistoTools::GetdNdptFromdNdmt(const TH1 * hmt, Double_t mass) {
// convert the x axis from mt to pt. Assumes you have 1/mt dNdmt in the histo you start with
Int_t nbins = hmt->GetNbinsX();
}
-TH1 * AliBWTools::GetdNdPtFromOneOverPt(const TH1 * h1Pt) {
+TH1 * AliPWGHistoTools::GetdNdPtFromOneOverPt(const TH1 * h1Pt) {
// convert an histo from 1/pt dNdpt to dNdpt, using the pt at the center of the bin
-TH1 * AliBWTools::GetOneOverPtdNdPt(const TH1 * hPt) {
+TH1 * AliPWGHistoTools::GetOneOverPtdNdPt(const TH1 * hPt) {
// convert an histo from dNdpt to 1/pt dNdpt, using the pt at the center of the bin
}
-TGraphErrors * AliBWTools::GetGraphFromHisto(const TH1F * h, Bool_t binWidth) {
+TGraphErrors * AliPWGHistoTools::GetGraphFromHisto(const TH1F * h, Bool_t binWidth) {
// Convert a histo to a graph
// if binWidth is true ex is set to the bin width of the histos, otherwise it is set to zero
Int_t nbin = h->GetNbinsX();
}
-TH1F * AliBWTools::GetHistoFromGraph(const TGraphErrors * g, const TH1F* hTemplate) {
+TH1F * AliPWGHistoTools::GetHistoFromGraph(const TGraphErrors * g, const TH1F* hTemplate) {
// convert a graph to histo with the binning of hTemplate.
// Warning: the template should be chosen
for(Int_t ipoint = 0; ipoint < npoint; ipoint++){
Float_t x = g->GetX() [ipoint];
Float_t y = g->GetY() [ipoint];
- Float_t ey = g->GetEY()[ipoint];
+ Float_t ey = 0;
+ if(g->InheritsFrom("TGraphErrors"))
+ ey = g->GetEY()[ipoint];
Int_t bin = h->FindBin(x);
// cout << "bin: "<< bin << " -> " << x << ", "<< y <<", " << ey << endl;
return h;
}
-TGraphErrors * AliBWTools::ConcatenateGraphs(const TGraphErrors * g1,const TGraphErrors * g2){
+TGraphErrors * AliPWGHistoTools::ConcatenateGraphs(const TGraphErrors * g1,const TGraphErrors * g2){
// concatenates two graphs
}
-TH1F * AliBWTools::Combine3HistosWithErrors(const TH1 * h1, const TH1 * h2, const TH1* h3,
+TH1F * AliPWGHistoTools::Combine3HistosWithErrors(const TH1 * h1, const TH1 * h2, const TH1* h3,
TH1 * he1, TH1 * he2, TH1 * he3,
const TH1* htemplate, Int_t statFrom,
Float_t renorm1, Float_t renorm2, Float_t renorm3,
else if (statFrom == 1) hStatError = h2;
else if (statFrom == 2) hStatError = h3;
else {
- Printf("AliBWTools::Combine3HistosWithErrors: wrong value of the statFrom parameter");
+ Printf("AliPWGHistoTools::Combine3HistosWithErrors: wrong value of the statFrom parameter");
return NULL;
}
- Printf("AliBWTools::Combine3HistosWithErrors: improve error on combined");
+ Printf("AliPWGHistoTools::Combine3HistosWithErrors: improve error on combined");
// Loop over all bins and take weighted mean of all points
Int_t nBinComb = hcomb->GetNbinsX();
for(Int_t ibin = 1; ibin <= nBinComb; ibin++){
if (statFrom == 0) ibinError = ibin1;
else if (statFrom == 1) ibinError = ibin2;
else if (statFrom == 2) ibinError = ibin3;
- else Printf("AliBWTools::Combine3HistosWithErrors: wrong value of the statFrom parameter");
+ else Printf("AliPWGHistoTools::Combine3HistosWithErrors: wrong value of the statFrom parameter");
Double_t y[3];
}
-void AliBWTools::GetMeanDataAndExtrapolation(const TH1 * hData, TF1 * fExtrapolation, Double_t &mean, Double_t &error, Float_t min, Float_t max){
+void AliPWGHistoTools::GetMeanDataAndExtrapolation(const TH1 * hData, TF1 * fExtrapolation, Double_t &mean, Double_t &error, Float_t min, Float_t max){
// Computes the mean of the combined data and extrapolation in a
// given range, use data where they are available and the function
// where data are not available
// ERROR from DATA ONLY is returned in this version!
//
- Printf("AliBWTools::GetMeanDataAndExtrapolation: WARNING from data only");
+ Printf("AliPWGHistoTools::GetMeanDataAndExtrapolation: WARNING from data only");
Float_t minData = GetLowestNotEmptyBinEdge (hData);
Int_t minDataBin = GetLowestNotEmptyBin (hData);
Float_t maxData = GetHighestNotEmptyBinEdge(hData);
}
-TH1F * AliBWTools::CombineHistos(const TH1 * h1, TH1 * h2, const TH1* htemplate, Float_t renorm1){
+TH1F * AliPWGHistoTools::CombineHistos(const TH1 * h1, TH1 * h2, const TH1* htemplate, Float_t renorm1){
// Combine two histos. This assumes the histos have the same binning
// in the overlapping region. It computes the arithmetic mean in the
// overlapping region and assigns as an error the relative error
}
-void AliBWTools::GetFromHistoGraphDifferentX(const TH1F * h, TF1 * f, TGraphErrors ** gBarycentre, TGraphErrors ** gXlw) {
+void AliPWGHistoTools::GetFromHistoGraphDifferentX(const TH1F * h, TF1 * f, TGraphErrors ** gBarycentre, TGraphErrors ** gXlw) {
// Computes the baycentre in each bin and the xlw as defined in NIMA
// 355 - 541 using f. Returs 2 graphs with the same y content of h
}
-Float_t AliBWTools::GetMean(TH1F * h, Float_t min, Float_t max, Float_t * error) {
+Float_t AliPWGHistoTools::GetMean(TH1F * h, Float_t min, Float_t max, Float_t * error) {
// Get the mean of histo in a range; root is not reliable in sub
// ranges with variable binning.
}
-void AliBWTools::GetMean(TF1 * func, Float_t &mean, Float_t &error, Float_t min, Float_t max, Int_t normPar) {
+void AliPWGHistoTools::GetMean(TF1 * func, Float_t &mean, Float_t &error, Float_t min, Float_t max, Int_t normPar) {
// Get the mean of function in a range; If normPar is >= 0, it means
// that the function is defined such that par[normPar] is its
}
-void AliBWTools::GetMeanSquare(TF1 * func, Float_t &mean, Float_t &error, Float_t min, Float_t max, Int_t normPar) {
+void AliPWGHistoTools::GetMeanSquare(TF1 * func, Float_t &mean, Float_t &error, Float_t min, Float_t max, Int_t normPar) {
// Get the mean2 of function in a range; If normPar is >= 0, it means
// that the function is defined such that par[normPar] is its
}
-void AliBWTools::GetMoment(TString name, TString var, TF1 * func, Float_t &mean, Float_t &error, Float_t min, Float_t max, Int_t normPar) {
+void AliPWGHistoTools::GetMoment(TString name, TString var, TF1 * func, Float_t &mean, Float_t &error, Float_t min, Float_t max, Int_t normPar) {
// returns the integral of a function derived from func by prefixing some operation.
// the derived function MUST have the same parameter in the same order
// - this version assumes that func is defined using a
// TFormula. Generalize to the case of a C++ function
- if (normPar<0) Printf("AliBWTools::GetMoment: Warning: If normalization is required, the error may bot be correct");
- if (!strcmp(func->GetExpFormula(),"")) Printf("AliBWTools::GetMoment: Warning: Empty formula in the base function");
+ if (normPar<0) Printf("AliPWGHistoTools::GetMoment: Warning: If normalization is required, the error may bot be correct");
+ if (!strcmp(func->GetExpFormula(),"")) Printf("AliPWGHistoTools::GetMoment: Warning: Empty formula in the base function");
Int_t npar = func->GetNpar();
// Definition changes according to the value of normPar
-Bool_t AliBWTools::Fit (TH1 * h1, TF1* func, Float_t min, Float_t max) {
+Bool_t AliPWGHistoTools::Fit (TH1 * h1, TF1* func, Float_t min, Float_t max) {
// Fits h1 with func, preforms several checks on the quality of the
// fit and tries to improve it. If the fit is not good enough, it
if( gMinuit->fLimset ) {
- Printf("ERROR: AliBWTools: Parameters at limits");
+ Printf("ERROR: AliPWGHistoTools: Parameters at limits");
return kFALSE;
}
TString(gMinuit->fCstatu) != "SUCCESSFUL" &&
TString(gMinuit->fCstatu) != "CONVERGED " ) {
if(fitStat < 3 && gMinuit->fCstatu != "UNCHANGED ") {
- Printf("WARNING: AliBWTools: Cannot properly compute errors");
+ Printf("WARNING: AliPWGHistoTools: Cannot properly compute errors");
if (fitStat == 0) Printf(" not calculated at all");
if (fitStat == 1) Printf(" approximation only, not accurate");
if (fitStat == 2) Printf(" full matrix, but forced positive-definite");
if (edm > 1e6) {
- Printf("WARNING: AliBWTools: Huge EDM (%f): Fit probably failed!", edm);
+ Printf("WARNING: AliPWGHistoTools: Huge EDM (%f): Fit probably failed!", edm);
}
if (fitResult != 0) {
- Printf("WARNING: AliBWTools: Fit Result (%d)", fitResult);
+ Printf("WARNING: AliPWGHistoTools: Fit Result (%d)", fitResult);
}
- Printf ("AliBWTools: Trying Again with Strategy = 2");
+ Printf ("AliPWGHistoTools: Trying Again with Strategy = 2");
gMinuit->Command("SET STRATEGY 2"); // more effort
fitResult = 0;
fitStat = fitter->GetStats(amin, edm, errdef, nvpar, nparx);
if(fitStat < 3 && gMinuit->fCstatu != "UNCHANGED ") {
- Printf("ERROR: AliBWTools: Cannot properly compute errors");
+ Printf("ERROR: AliPWGHistoTools: Cannot properly compute errors");
if (fitStat == 0) Printf(" not calculated at all");
if (fitStat == 1) Printf(" approximation only, not accurate");
if (fitStat == 2) Printf(" full matrix, but forced positive-definite");
}
if (edm > 1e6) {
- Printf("ERROR: AliBWTools: Huge EDM (%f): Fit probably failed!", edm);
+ Printf("ERROR: AliPWGHistoTools: Huge EDM (%f): Fit probably failed!", edm);
return kFALSE;
}
if (fitResult != 0) {
- Printf("ERROR: AliBWTools: Fit Result (%d)", fitResult);
+ Printf("ERROR: AliPWGHistoTools: Fit Result (%d)", fitResult);
return kFALSE;
}
}
-Int_t AliBWTools::GetLowestNotEmptyBin(const TH1*h) {
+Int_t AliPWGHistoTools::GetLowestNotEmptyBin(const TH1*h) {
// Return the index of the lowest non empty bin in the histo h
}
-Int_t AliBWTools::GetHighestNotEmptyBin(const TH1*h) {
+Int_t AliPWGHistoTools::GetHighestNotEmptyBin(const TH1*h) {
// Return the index of the highest non empty bin in the histo h
}
-void AliBWTools::GetResiduals(const TGraphErrors * gdata, const TF1 * func, TH1F ** hres, TGraphErrors ** gres) {
+void AliPWGHistoTools::GetResiduals(const TGraphErrors * gdata, const TF1 * func, TH1F ** hres, TGraphErrors ** gres) {
// Returns a graph of residuals vs point and the res/err distribution
}
-void AliBWTools::GetResiduals(const TH1F* hdata, const TF1 * func, TH1F ** hres, TH1F ** hresVsBin) {
+void AliPWGHistoTools::GetResiduals(const TH1F* hdata, const TF1 * func, TH1F ** hres, TH1F ** hresVsBin) {
// Returns an histo of residuals bin by bin and the res/err distribution
if (!func) {
- Printf("AliBWTools::GetResiduals: No function provided");
+ Printf("AliPWGHistoTools::GetResiduals: No function provided");
return;
}
if (!hdata) {
- Printf("AliBWTools::GetResiduals: No data provided");
+ Printf("AliPWGHistoTools::GetResiduals: No data provided");
return;
}
}
-void AliBWTools::GetYield(TH1* h, TF1 * f, Double_t &yield, Double_t &yieldError, Float_t min, Float_t max,
+void AliPWGHistoTools::GetYield(TH1* h, TF1 * f, Double_t &yield, Double_t &yieldError, Float_t min, Float_t max,
Double_t *partialYields, Double_t *partialYieldsErrors){
// Returns the yield extracted from the data in the histo where
}
-TGraphErrors * AliBWTools::DivideGraphByFunc(const TGraphErrors * g, const TF1 * f, Bool_t invert){
+TGraphErrors * AliPWGHistoTools::DivideGraphByFunc(const TGraphErrors * g, const TF1 * f, Bool_t invert){
// Divides g/f. If invert == true => f/g
}
-TGraphErrors * AliBWTools::Divide2Graphs(const TGraphErrors * g1, const TGraphErrors * g2){
+TGraphErrors * AliPWGHistoTools::Divide2Graphs(const TGraphErrors * g1, const TGraphErrors * g2){
// Divides g1/g2, looks for point with very close centers
Int_t ipoint=0;
Double_t x2 = g2->GetX()[ipoint2];
if((TMath::Abs(x1-x2)/(x1+x2)*2)<0.01) {
Double_t ratio = g2->GetY()[ipoint2] ? g1->GetY()[ipoint1]/g2->GetY()[ipoint2] : 0;
- Double_t eratio = g2->GetY()[ipoint2] ?
- TMath::Sqrt(g1->GetEY()[ipoint1]*g1->GetEY()[ipoint1]/g1->GetY()[ipoint1]/g1->GetY()[ipoint1] +
- g2->GetEY()[ipoint2]/g2->GetY()[ipoint2]/g2->GetY()[ipoint2] ) * ratio
- : 0;
+ Double_t eratio = 0;
+ if(g1->InheritsFrom("TGraphErrors") && g2->InheritsFrom("TGraphErrors")) {
+ eratio = g2->GetY()[ipoint2] ?
+ TMath::Sqrt(g1->GetEY()[ipoint1]*g1->GetEY()[ipoint1]/g1->GetY()[ipoint1]/g1->GetY()[ipoint1] +
+ g2->GetEY()[ipoint2]/g2->GetY()[ipoint2]/g2->GetY()[ipoint2] ) * ratio
+ : 0;
+ }
gRatio->SetPoint (ipoint, x1, ratio);
gRatio->SetPointError(ipoint, 0, eratio);
ipoint++;
//gRatio->Print();
return gRatio;
+}
+TGraphErrors * AliPWGHistoTools::Add2Graphs(const TGraphErrors * g1, const TGraphErrors * g2){
+
+ // Sums g1/g2, looks for point with very close centers
+ Int_t ipoint=0;
+ TGraphErrors * gSum = new TGraphErrors();
+ Int_t npoint1 = g1->GetN();
+ Int_t npoint2 = g2->GetN();
+ for(Int_t ipoint1 = 0; ipoint1 < npoint1; ipoint1++){
+ Double_t x1 = g1->GetX()[ipoint1];
+ for(Int_t ipoint2 = 0; ipoint2 < npoint2; ipoint2++){
+ Double_t x2 = g2->GetX()[ipoint2];
+ if((TMath::Abs(x1-x2)/(x1+x2)*2)<0.01) {
+ Double_t sum = g1->GetY()[ipoint1]+g2->GetY()[ipoint2];
+ Double_t esum = 0;
+ if(g1->InheritsFrom("TGraphErrors") && g2->InheritsFrom("TGraphErrors")) {
+ esum =
+ TMath::Sqrt(g1->GetEY()[ipoint1]*g1->GetEY()[ipoint1] +
+ g2->GetEY()[ipoint2]*g2->GetEY()[ipoint2] ) ;
+
+ }
+ gSum->SetPoint (ipoint, x1, sum);
+ gSum->SetPointError(ipoint, 0, esum);
+ ipoint++;
+ cout << ipoint << " [" << x1 << "] " << g1->GetY()[ipoint1] << "+" << g2->GetY()[ipoint2] << " = " << sum <<"+-"<<esum<< endl;
+
+ // cout << x << " " << g->GetY()[ipoint] << " " << f->Eval(x) << endl;
+ }
+
+ }
+ }
+ gSum->SetMarkerStyle(20);
+ //gSum->Print();
+ return gSum;
+
}
-TGraphErrors * AliBWTools::DivideGraphByHisto(const TGraphErrors * g, TH1 * h, Bool_t invert){
+TGraphErrors * AliPWGHistoTools::DivideGraphByHisto(const TGraphErrors * g, TH1 * h, Bool_t invert){
// Divides g/h. If invert == true => h/g
}
-TH1F * AliBWTools::DivideHistoByFunc(TH1F * h, TF1 * f, Bool_t invert){
+TH1F * AliPWGHistoTools::DivideHistoByFunc(TH1F * h, TF1 * f, Bool_t invert){
// Divides h/f. If invert == true => f/g
// Performs the integral of f on the bin range to perform the ratio
}
-void AliBWTools::WeightedMean(Int_t npoints, const Double_t *x, const Double_t *xerr, Double_t &mean, Double_t &meanerr){
+void AliPWGHistoTools::WeightedMean(Int_t npoints, const Double_t *x, const Double_t *xerr, Double_t &mean, Double_t &meanerr){
// Performs the weighted mean of npoints numbers in x with errors in xerr
}
-TH1 * AliBWTools::GetRelativeError(TH1 * h){
+TH1 * AliPWGHistoTools::GetRelativeError(TH1 * h){
// Returns an histogram with the same binning as h, filled with the relative error bin by bin
TH1 * hrel = (TH1*) h->Clone(TString(h->GetName())+"_rel");
hrel->Reset();
}
-void AliBWTools::GetValueAndError(TH1 * hdest, const TH1 * hvalue, const TH1 * herror, Bool_t isPercentError) {
+void AliPWGHistoTools::GetValueAndError(TH1 * hdest, const TH1 * hvalue, const TH1 * herror, Bool_t isPercentError) {
// Put into source, bin-by-bin, the values from hvalue and the
// errors from content from herror.
// Set isPercentError to kTRUE if the error is given in %
if(hdest == NULL){
- Printf("AliBWTools::GetValueAndError Errror: hdest is null");
+ Printf("AliPWGHistoTools::GetValueAndError Errror: hdest is null");
return;
}
}
}
// if (!foundValue){
- // Printf("AliBWTools::GetValueAndError: Error: cannot find matching value source bin for destination %d",iBinDest);
+ // Printf("AliPWGHistoTools::GetValueAndError: Error: cannot find matching value source bin for destination %d",iBinDest);
// }
// Error
}
}
// if (!foundError ){
- // Printf("AliBWTools::GetValueAndError: Error: cannot find matching error source bin for destination %d",iBinDest);
+ // Printf("AliPWGHistoTools::GetValueAndError: Error: cannot find matching error source bin for destination %d",iBinDest);
// }
}
}
-void AliBWTools::AddHisto(TH1 * hdest, const TH1* hsource, Bool_t getMirrorBins) {
+void AliPWGHistoTools::AddHisto(TH1 * hdest, const TH1* hsource, Bool_t getMirrorBins) {
// Adds hsource to hdest bin by bin, even if they have a different
// binning If getMirrorBins is true, it takes the negative bins
}
-void AliBWTools::GetHistoCombinedErrors(TH1 * hdest, const TH1 * h1) {
+void AliPWGHistoTools::GetHistoCombinedErrors(TH1 * hdest, const TH1 * h1) {
// Combine the errors of hdest with the errors of h1, summing in
// quadrature. Results are put in hdest. Histograms are assumed to
}
-TH1F * AliBWTools::DivideHistosDifferentBins(const TH1F* h1, const TH1F* h2) {
+TH1F * AliPWGHistoTools::DivideHistosDifferentBins(const TH1F* h1, const TH1F* h2) {
// Divides 2 histos even if they have a different binning. Finds
// overlapping bins and divides them
return hRatio;
}
-Double_t AliBWTools::DoIntegral(TH1* h, Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Int_t binz1, Int_t binz2, Double_t & error ,
+Double_t AliPWGHistoTools::DoIntegral(TH1* h, Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Int_t binz1, Int_t binz2, Double_t & error ,
Option_t *option, Bool_t doError)
{
// function to compute integral and optionally the error between the limits
return integral;
}
-Double_t AliBWTools::dMtdptFunction(Double_t *x, Double_t *p) {
+Double_t AliPWGHistoTools::dMtdptFunction(Double_t *x, Double_t *p) {
// Computes the dmt/dptdeta function using the dN/dpt function
// This is a protected function used internally by GetdMtdy to integrate dN/dpt function using mt as a weight
Double_t mt = TMath::Sqrt(pt*pt + mass*mass);
Double_t jacobian = pt/mt;
if(!fdNdptForETCalc){
- Printf("AliBWTools::dMtdptFunction: ERROR: fdNdptForETCalc not defined");
+ Printf("AliPWGHistoTools::dMtdptFunction: ERROR: fdNdptForETCalc not defined");
return 0;
}
Double_t dNdpt = fdNdptForETCalc->Eval(pt);
}
-Double_t AliBWTools::GetdMtdEta(TH1 *hData, TF1 * fExtrapolation, Double_t mass) {
+Double_t AliPWGHistoTools::GetdMtdEta(TH1 *hData, TF1 * fExtrapolation, Double_t mass) {
// Computes dMtdEta integrating dN/dptdy with the proper weights and jacobian.
Printf("WARNING ALIBWTOOLS::GetdMtdEta: ONLY USING FUNCTION FOR THE TIME BEING, hData");
if(!hData) {