]>
Commit | Line | Data |
---|---|---|
e678600d | 1 | #include "AliOADBPWG2Spectra.h" |
2 | #include "TNamed.h" | |
3 | #include "TString.h" | |
4 | #include "TH1D.h" | |
5 | #include "TObject.h" | |
6 | #include "TList.h" | |
7 | #include "AliAnalysisManager.h" | |
8 | #include "TBrowser.h" | |
9 | #include "AliLog.h" | |
10 | ||
11 | ClassImp(AliOADBPWG2Spectra) | |
12 | ||
e3c81f72 | 13 | const char * AliOADBPWG2Spectra::fgkDetectorNames[] = {"ITS", "ITSTPC", "TPC", "TOF", "TOFTPC", "Dummy", "Dummy"}; |
14 | const char * AliOADBPWG2Spectra::fgkPidTypeNames[] = {"GaussFit", "NSigma", "Bayes", "Kinks"}; | |
15 | const char * AliOADBPWG2Spectra::fgkChargeTags[] = {"Pos", "Neg"}; | |
16 | const char * AliOADBPWG2Spectra::fgkParticleNames[] = {"Pion", "Kaon", "Proton"}; | |
e678600d | 17 | |
18 | ||
19 | AliOADBPWG2Spectra::AliOADBPWG2Spectra(): | |
20 | TNamed("Dummy", "OADB Object for PWG2 Spectra" ), fHistos(0) | |
21 | { | |
22 | // ctor | |
23 | ||
24 | ||
25 | ||
26 | } | |
e3c81f72 | 27 | AliOADBPWG2Spectra::AliOADBPWG2Spectra(const char* name) : |
e678600d | 28 | TNamed(name, "OADB Object for PWG2 Spectra" ), fHistos(0) |
29 | ||
30 | { | |
31 | // ctor | |
32 | // name is appended to all histos (e.g. "Corrected") | |
33 | ||
34 | Init(); | |
35 | ||
36 | } | |
37 | ||
38 | AliOADBPWG2Spectra::~AliOADBPWG2Spectra() { | |
39 | // dtor | |
40 | if(fHistos) delete fHistos; | |
41 | } | |
42 | ||
43 | void AliOADBPWG2Spectra::Init() { | |
44 | fHistos = new TList(); | |
45 | } | |
46 | ||
47 | ||
48 | const char * AliOADBPWG2Spectra::GetOADBPWG2SpectraFileName() { | |
49 | // get file name to the OADB | |
50 | static TString filename; | |
51 | filename.Form("%s/PWG2/SPECTRA/spectraResults.root", AliAnalysisManager::GetOADBPath()); | |
52 | return filename.Data(); | |
53 | ||
54 | } | |
e3c81f72 | 55 | const char * AliOADBPWG2Spectra::GetHistoName(Int_t det, Int_t pidType, Int_t part, |
56 | Int_t charge, const char * centrTag, Int_t centrBin) { | |
e678600d | 57 | |
58 | // Returns histogram name | |
59 | // h[Name]_[Detector(s)]_[PIDType]_[Particle]_[Pos|Neg]_[MultiplicityOrCentralityIndex] | |
60 | // where "name" is the name of this container | |
61 | ||
68037533 | 62 | |
e678600d | 63 | static TString histoName; |
e3c81f72 | 64 | if (centrTag) { |
65 | if(!strcmp(centrTag,"MB")){ | |
66 | // don't put a index for MB spectra | |
67 | histoName.Form("h%s_%s_%s_%s_%s_%s", GetName(), fgkDetectorNames[det], fgkPidTypeNames[pidType], fgkParticleNames[part], fgkChargeTags[charge], centrTag); | |
68 | } | |
69 | else { | |
70 | histoName.Form("h%s_%s_%s_%s_%s_%s_%d", GetName(), fgkDetectorNames[det], fgkPidTypeNames[pidType], fgkParticleNames[part], fgkChargeTags[charge], centrTag, centrBin); | |
71 | } | |
72 | } | |
e678600d | 73 | else |
e3c81f72 | 74 | histoName.Form("h%s_%s_%s_%s_%s", GetName(), fgkDetectorNames[det], fgkPidTypeNames[pidType], fgkParticleNames[part], fgkChargeTags[charge]); |
e678600d | 75 | |
76 | return histoName.Data(); | |
77 | } | |
78 | ||
e3c81f72 | 79 | TH1D * AliOADBPWG2Spectra::GetHisto(Int_t det, Int_t pidType, Int_t part, |
80 | Int_t charge, const char * centrTag, Int_t centrBin){ | |
e678600d | 81 | |
82 | // Get an histogram from the list | |
83 | const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin); | |
84 | TH1D * h = (TH1D*) fHistos->FindObject(name); | |
85 | return h; | |
86 | ||
87 | } | |
88 | ||
e3c81f72 | 89 | void AliOADBPWG2Spectra::AddHisto(TH1D * h, Int_t det, Int_t pidType, Int_t part, |
90 | Int_t charge, const char * centrTag, Int_t centrBin) { | |
e678600d | 91 | // Add a histogram to the list |
68037533 | 92 | // Rename and rebinn it if necessary |
93 | ||
94 | if(!h) { | |
95 | AliWarning("Empty pointer to histogram"); | |
96 | return; | |
97 | } | |
98 | ||
68037533 | 99 | static TH1D * htest = BookHisto(kDetDummy, kGaussFit,kPion, kPos); |
e3c81f72 | 100 | const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin); |
68037533 | 101 | if(!CompareBinning(h,htest)){ |
102 | AliWarning("Histo have different binning! Rebinning to standard"){ | |
103 | h = GetHistoStandardBinning(h,det,pidType,part,charge,centrTag,centrBin); | |
104 | } | |
105 | } | |
e3c81f72 | 106 | if(!fHistos) { |
107 | AliError("fHistos not allocated!!"); | |
108 | return; | |
109 | } | |
110 | ||
e678600d | 111 | TH1D * hold = (TH1D*) fHistos->FindObject(name); |
112 | if (hold) fHistos->Remove(hold); | |
113 | delete hold; | |
114 | if(strcmp(h->GetName(),name)){ | |
e3c81f72 | 115 | AliWarning(Form("Histogram names are not consinstent %s-%s, resetting", h->GetName(),name)); |
e678600d | 116 | h->SetName(name); |
117 | } | |
118 | fHistos->Add(h); | |
119 | ||
120 | ||
121 | } | |
122 | ||
e3c81f72 | 123 | TH1D * AliOADBPWG2Spectra::BookHisto(Int_t det, Int_t pidType, Int_t part, |
124 | Int_t charge, const char * centrTag, Int_t centrBin) { | |
e678600d | 125 | |
126 | // book a histogram according to the template. All the histograms | |
127 | // should have the same binning (if possible/reasonable) to | |
128 | // facilitate the compoarison and the combination | |
129 | ||
e3c81f72 | 130 | 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}; |
131 | Int_t nbinsTempl=52; | |
e678600d | 132 | const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin); |
133 | TH1D * h = new TH1D(name, name, nbinsTempl, templBins); | |
134 | return h; | |
135 | ||
136 | } | |
137 | ||
138 | void AliOADBPWG2Spectra::Browse(TBrowser *b) | |
139 | { | |
140 | // Browse this object. | |
141 | // If b=0, there is no Browse call TObject::Browse(0) instead. | |
142 | // This means TObject::Inspect() will be invoked indirectly | |
143 | ||
144 | ||
145 | if (b) { | |
146 | b->Add(fHistos); | |
147 | } | |
148 | else | |
149 | TObject::Browse(b); | |
150 | } | |
68037533 | 151 | |
e3c81f72 | 152 | TH1D * AliOADBPWG2Spectra::GetHistoStandardBinning(const TH1D* h, Int_t det, Int_t pidType, Int_t part, |
153 | Int_t charge, const char * centrTag, Int_t centrBin) { | |
68037533 | 154 | // Returns a histo with the standard binning and the same content of h |
155 | // if the bins of h are not a subset of the standard binning, it crashes with a fatal error | |
156 | // under and overflows are ignored | |
157 | ||
158 | // 1. Create a histogram with the standard binning | |
159 | TH1D * hStd = BookHisto(det, pidType, part, charge, centrTag, centrBin); | |
160 | Int_t nBinsH1=hStd->GetNbinsX(); | |
161 | Int_t nBinsH2=h->GetNbinsX(); | |
162 | // Loop over standard bins, | |
163 | for(Int_t iBin=1; iBin<=nBinsH1; iBin++){ | |
164 | Float_t lowPtH1 =hStd->GetBinLowEdge(iBin); | |
165 | Float_t binWidH1=hStd->GetBinWidth(iBin); | |
166 | // Loop over H2 bins and find overlapping bins to H1 | |
167 | for(Int_t jBin=1; jBin<=nBinsH2; jBin++){ | |
168 | Float_t lowPtH2=h->GetBinLowEdge(jBin); | |
169 | Float_t binWidH2=h->GetBinWidth(jBin); | |
170 | if(TMath::Abs(lowPtH1-lowPtH2)<0.001 && TMath::Abs(binWidH2-binWidH1)<0.001){ | |
e3c81f72 | 171 | hStd->SetBinContent(iBin, h->GetBinContent(jBin)); |
172 | hStd->SetBinError (iBin, h->GetBinError (jBin)); | |
68037533 | 173 | break; |
174 | } | |
175 | if(TMath::Abs(lowPtH1-lowPtH2)<0.001){ | |
e3c81f72 | 176 | AliError(Form("Found partially overlapping bins! [(%f,%f)(%f,%f)]",lowPtH1,binWidH1,lowPtH2,binWidH2)); |
177 | continue; | |
68037533 | 178 | } |
179 | } | |
180 | } | |
181 | return hStd; | |
182 | } | |
183 | ||
184 | Bool_t AliOADBPWG2Spectra::CompareBinning(TH1 * h1, TH1 * h2) { | |
185 | ||
186 | // returns true if h1 and h2 have the same binning | |
187 | Int_t nbins1 = h1->GetNbinsX(); | |
188 | Int_t nbins2 = h2->GetNbinsX(); | |
189 | ||
190 | if(nbins1 != nbins2) return kFALSE; | |
191 | ||
192 | for(Int_t ibin = 1; ibin <= nbins1; ibin++){ | |
e3c81f72 | 193 | if(TMath::Abs(h1->GetBinLowEdge(ibin) - h2->GetBinLowEdge(ibin))>0.001) return kFALSE; |
194 | if(TMath::Abs(h1->GetBinWidth(ibin) - h2->GetBinWidth(ibin))>0.001) return kFALSE; | |
68037533 | 195 | } |
196 | ||
197 | return kTRUE; | |
198 | } |