1 #include "AliOADBPWG2Spectra.h"
2 #include "AliOADBContainer.h"
8 #include "AliAnalysisManager.h"
12 ClassImp(AliOADBPWG2Spectra)
14 const char * AliOADBPWG2Spectra::fgkDetectorNames[] = {"ITS", "ITSTPC", "TPC", "TOF", "TOFTPC", "Dummy", "Dummy"};
15 const char * AliOADBPWG2Spectra::fgkPidTypeNames[] = {"GaussFit", "NSigma", "Bayes", "Kinks"};
16 const char * AliOADBPWG2Spectra::fgkChargeTags[] = {"Pos", "Neg"};
17 const char * AliOADBPWG2Spectra::fgkParticleNames[] = {"Pion", "Kaon", "Proton"};
20 AliOADBPWG2Spectra::AliOADBPWG2Spectra():
21 TNamed("Dummy", "OADB Object for PWG2 Spectra" ), fHistos(0)
28 AliOADBPWG2Spectra::AliOADBPWG2Spectra(const char* name) :
29 TNamed(name, "OADB Object for PWG2 Spectra" ), fHistos(0)
33 // name is appended to all histos (e.g. "Corrected")
39 AliOADBPWG2Spectra::~AliOADBPWG2Spectra() {
41 if(fHistos) delete fHistos;
44 void AliOADBPWG2Spectra::Init() {
45 fHistos = new TList();
49 const char * AliOADBPWG2Spectra::GetOADBPWG2SpectraFileName() {
50 // get file name to the OADB
51 static TString filename;
52 filename.Form("%s/PWG2/SPECTRA/spectraResults.root", AliOADBContainer::GetOADBPath());
53 return filename.Data();
56 const char * AliOADBPWG2Spectra::GetHistoName(Int_t det, Int_t pidType, Int_t part,
57 Int_t charge, const char * centrTag, Int_t centrBin) {
59 // Returns histogram name
60 // h[Name]_[Detector(s)]_[PIDType]_[Particle]_[Pos|Neg]_[MultiplicityOrCentralityIndex]
61 // where "name" is the name of this container
64 static TString histoName;
66 if(!strcmp(centrTag,"MB")){
67 // don't put a index for MB spectra
68 histoName.Form("h%s_%s_%s_%s_%s_%s", GetName(), fgkDetectorNames[det], fgkPidTypeNames[pidType], fgkParticleNames[part], fgkChargeTags[charge], centrTag);
71 histoName.Form("h%s_%s_%s_%s_%s_%s_%d", GetName(), fgkDetectorNames[det], fgkPidTypeNames[pidType], fgkParticleNames[part], fgkChargeTags[charge], centrTag, centrBin);
75 histoName.Form("h%s_%s_%s_%s_%s", GetName(), fgkDetectorNames[det], fgkPidTypeNames[pidType], fgkParticleNames[part], fgkChargeTags[charge]);
77 return histoName.Data();
80 TH1D * AliOADBPWG2Spectra::GetHisto(Int_t det, Int_t pidType, Int_t part,
81 Int_t charge, const char * centrTag, Int_t centrBin){
83 // Get an histogram from the list
84 const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
85 TH1D * h = (TH1D*) fHistos->FindObject(name);
90 void AliOADBPWG2Spectra::AddHisto(TH1D * h, Int_t det, Int_t pidType, Int_t part,
91 Int_t charge, const char * centrTag, Int_t centrBin) {
92 // Add a histogram to the list
93 // Rename and rebinn it if necessary
96 AliWarning("Empty pointer to histogram");
100 static TH1D * htest = BookHisto(kDetDummy, kGaussFit,kPion, kPos);
101 const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
102 if(!CompareBinning(h,htest)){
103 AliWarning("Histo have different binning! Rebinning to standard");
105 h = GetHistoStandardBinning(h,det,pidType,part,charge,centrTag,centrBin);
109 AliError("fHistos not allocated!!");
113 TH1D * hold = (TH1D*) fHistos->FindObject(name);
114 if (hold) fHistos->Remove(hold);
116 if(strcmp(h->GetName(),name)){
117 AliWarning(Form("Histogram names are not consinstent %s-%s, resetting", h->GetName(),name));
125 TH1D * AliOADBPWG2Spectra::BookHisto(Int_t det, Int_t pidType, Int_t part,
126 Int_t charge, const char * centrTag, Int_t centrBin) {
128 // book a histogram according to the template. All the histograms
129 // should have the same binning (if possible/reasonable) to
130 // facilitate the compoarison and the combination
132 const Float_t templBins[] = {0.05,0.1,0.12,0.14,0.16,0.18,0.20,0.25,0.30,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8,5.0};
134 const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
135 TH1D * h = new TH1D(name, name, nbinsTempl, templBins);
140 void AliOADBPWG2Spectra::Browse(TBrowser *b)
142 // Browse this object.
143 // If b=0, there is no Browse call TObject::Browse(0) instead.
144 // This means TObject::Inspect() will be invoked indirectly
154 TH1D * AliOADBPWG2Spectra::GetHistoStandardBinning(const TH1D* h, Int_t det, Int_t pidType, Int_t part,
155 Int_t charge, const char * centrTag, Int_t centrBin) {
156 // Returns a histo with the standard binning and the same content of h
157 // if the bins of h are not a subset of the standard binning, it crashes with a fatal error
158 // under and overflows are ignored
160 // 1. Create a histogram with the standard binning
161 TH1D * hStd = BookHisto(det, pidType, part, charge, centrTag, centrBin);
162 Int_t nBinsH1=hStd->GetNbinsX();
163 Int_t nBinsH2=h->GetNbinsX();
164 // Loop over standard bins,
165 for(Int_t iBin=1; iBin<=nBinsH1; iBin++){
166 Float_t lowPtH1 =hStd->GetBinLowEdge(iBin);
167 Float_t binWidH1=hStd->GetBinWidth(iBin);
168 // Loop over H2 bins and find overlapping bins to H1
169 for(Int_t jBin=1; jBin<=nBinsH2; jBin++){
170 Float_t lowPtH2=h->GetBinLowEdge(jBin);
171 Float_t binWidH2=h->GetBinWidth(jBin);
172 if(TMath::Abs(lowPtH1-lowPtH2)<0.001 && TMath::Abs(binWidH2-binWidH1)<0.001){
173 hStd->SetBinContent(iBin, h->GetBinContent(jBin));
174 hStd->SetBinError (iBin, h->GetBinError (jBin));
177 if(TMath::Abs(lowPtH1-lowPtH2)<0.001){
178 AliError(Form("Found partially overlapping bins! [(%f,%f)(%f,%f)]",lowPtH1,binWidH1,lowPtH2,binWidH2));
186 Bool_t AliOADBPWG2Spectra::CompareBinning(TH1 * h1, TH1 * h2) {
188 // returns true if h1 and h2 have the same binning
189 Int_t nbins1 = h1->GetNbinsX();
190 Int_t nbins2 = h2->GetNbinsX();
192 if(nbins1 != nbins2) return kFALSE;
194 for(Int_t ibin = 1; ibin <= nbins1; ibin++){
195 if(TMath::Abs(h1->GetBinLowEdge(ibin) - h2->GetBinLowEdge(ibin))>0.001) return kFALSE;
196 if(TMath::Abs(h1->GetBinWidth(ibin) - h2->GetBinWidth(ibin))>0.001) return kFALSE;