]>
Commit | Line | Data |
---|---|---|
a58729a5 | 1 | #include "AliAnalysisMuMuSpectra.h" |
2 | ||
3 | #include "AliLog.h" | |
4 | #include "AliAnalysisMuMuBinning.h" | |
5 | #include "AliAnalysisMuMuResult.h" | |
6 | #include "Riostream.h" | |
7 | #include "TH1.h" | |
8 | #include "TList.h" | |
9 | #include "TObjArray.h" | |
10 | ||
11 | ClassImp(AliAnalysisMuMuSpectra) | |
12 | ||
13 | //______________________________________________________________________________ | |
14 | AliAnalysisMuMuSpectra::AliAnalysisMuMuSpectra(const char* name, const char* title) : | |
15 | TNamed(name,title), | |
16 | fBinning(0x0), | |
17 | fBins(0x0) | |
18 | { | |
19 | ||
20 | } | |
21 | ||
22 | //______________________________________________________________________________ | |
23 | AliAnalysisMuMuSpectra::~AliAnalysisMuMuSpectra() | |
24 | { | |
25 | delete fBinning; | |
26 | delete fBins; | |
27 | } | |
28 | ||
29 | //______________________________________________________________________________ | |
30 | void AliAnalysisMuMuSpectra::AdoptResult(const AliAnalysisMuMuBinning::Range& bin, | |
31 | AliAnalysisMuMuResult* result) | |
32 | { | |
33 | if (!fBinning) | |
34 | { | |
35 | fBinning = new AliAnalysisMuMuBinning; | |
36 | fBins = new TObjArray; | |
37 | fBins->SetOwner(kTRUE); | |
38 | } | |
39 | fBinning->AddBin(bin); | |
40 | fBins->Add(result); | |
41 | } | |
42 | ||
43 | //______________________________________________________________________________ | |
44 | Bool_t AliAnalysisMuMuSpectra::Correct(const AliAnalysisMuMuSpectra& accEff, const char* particle, const char* subResultName) | |
45 | { | |
46 | /// Correct this spectra by acceff one | |
47 | if (IsEmpty()) | |
48 | { | |
49 | AliError("Cannot correct an empty spectra !"); | |
50 | return kFALSE; | |
51 | } | |
52 | ||
53 | // check we have the same binning first | |
54 | AliAnalysisMuMuBinning* accEffBins = accEff.Binning(); | |
55 | ||
56 | if ( !fBinning->IsEqual(accEffBins) ) | |
57 | { | |
58 | AliError("Cannot correct with a spectra which does not have the same binning"); | |
59 | return kFALSE; | |
60 | } | |
61 | ||
62 | TObjArray* particles = fBinning->CreateParticleArray(); | |
63 | TObjArray* types = fBinning->CreateTypeArray(); | |
64 | ||
65 | if (particles->GetEntries()!=1 || types->GetEntries()!=1 ) | |
66 | { | |
67 | delete particles; | |
68 | delete types; | |
69 | return kFALSE; | |
70 | } | |
71 | ||
72 | TObjArray* bins = accEff.Bins(); | |
73 | ||
74 | ||
75 | for ( Int_t i = 0; i < bins->GetEntries(); ++i ) | |
76 | { | |
77 | AliAnalysisMuMuResult* thisResult = static_cast<AliAnalysisMuMuResult*>(fBins->At(i)); | |
78 | AliAnalysisMuMuResult* accResult = static_cast<AliAnalysisMuMuResult*>(bins->At(i)); | |
79 | AliInfoClass(Form("i=%d",i )); | |
80 | StdoutToAliInfoClass(thisResult->Print("full"); | |
81 | std::cout << "----" << std::endl; | |
82 | accResult->Print("full")); | |
83 | ||
84 | thisResult->Correct(*accResult,particle,subResultName); | |
85 | } | |
86 | ||
87 | delete particles; | |
88 | delete types; | |
89 | return kTRUE; | |
90 | } | |
91 | ||
92 | //______________________________________________________________________________ | |
93 | Bool_t AliAnalysisMuMuSpectra::IsEmpty() const | |
94 | { | |
95 | return ( fBins==0x0 || fBins->GetEntries()<=0 ); | |
96 | } | |
97 | ||
98 | //______________________________________________________________________________ | |
99 | Long64_t AliAnalysisMuMuSpectra::Merge(TCollection* list) | |
100 | { | |
101 | /// Merge method | |
102 | ||
103 | // Merge a list of AliAnalysisMuMuSpectra objects with this | |
104 | // Returns the number of merged objects (including this). | |
105 | ||
106 | if (!list) return 0; | |
107 | ||
108 | if (list->IsEmpty()) return 1; | |
109 | ||
110 | TIter next(list); | |
111 | TObject* currObj; | |
112 | Int_t count(0); | |
113 | ||
114 | TList binningList; | |
115 | ||
116 | for ( Int_t i = 0; i <= fBins->GetLast(); ++i ) | |
117 | { | |
118 | next.Reset(); | |
119 | ||
120 | TList binList; | |
121 | ||
122 | while ( ( currObj = next() ) ) | |
123 | { | |
124 | AliAnalysisMuMuSpectra* spectra = dynamic_cast<AliAnalysisMuMuSpectra*>(currObj); | |
125 | if (!spectra) | |
126 | { | |
127 | AliFatal(Form("object named \"%s\" is a %s instead of an AliAnalysisMuMuSpectra!", currObj->GetName(), currObj->ClassName())); | |
128 | continue; | |
129 | } | |
130 | ||
131 | if (i==0) | |
132 | { | |
133 | binningList.Add(spectra->Binning()); | |
134 | ||
135 | if ( !fBinning->IsEqual(spectra->Binning()) || spectra->Bins()->GetLast() != Bins()->GetLast() ) | |
136 | { | |
137 | AliError("Cannot merge spectra with different binning"); | |
138 | continue; | |
139 | } | |
140 | ||
141 | ++count; | |
142 | } | |
143 | ||
144 | binList.Add(fBins->At(i)); | |
145 | } | |
146 | ||
147 | AliAnalysisMuMuResult* r = static_cast<AliAnalysisMuMuResult*>(fBins->At(i)); | |
148 | r->Merge(&binList); | |
149 | ||
150 | } | |
151 | ||
152 | fBinning->Merge(&binningList); | |
153 | ||
154 | return count+1; | |
155 | } | |
156 | ||
157 | //_____________________________________________________________________________ | |
158 | TH1* AliAnalysisMuMuSpectra::Plot(const char* what, const char* subresult) const | |
159 | { | |
160 | TString swhat(what); | |
161 | swhat.ToUpper(); | |
162 | ||
163 | Double_t* bins = fBinning->CreateBinArray(); | |
164 | ||
165 | TObjArray* binArray = fBinning->CreateBinObjArray(); | |
166 | ||
167 | TH1* h(0x0); | |
168 | ||
169 | AliDebugClass(1,Form("nbins=%d nresults=%d",binArray->GetEntries(),fBins->GetEntries())); | |
170 | ||
171 | for ( Int_t j = 0; j < TMath::Min(binArray->GetEntries(),fBins->GetEntries()); ++j ) | |
172 | { | |
173 | AliAnalysisMuMuResult* r = static_cast<AliAnalysisMuMuResult*>(fBins->At(j)); | |
174 | ||
175 | if ( strlen(subresult) > 0 ) | |
176 | { | |
177 | TObjArray* sr = r->SubResults(); | |
178 | if (!sr) continue; | |
179 | TString sub(subresult); | |
180 | sub.ToUpper(); | |
181 | r = static_cast<AliAnalysisMuMuResult*>(sr->FindObject(sub.Data())); | |
182 | if (!r) continue; | |
183 | } | |
184 | ||
185 | const AliAnalysisMuMuBinning::Range& b = r->Bin(); | |
186 | ||
187 | r->Print(); | |
188 | b.Print(); | |
189 | ||
190 | if (!h) | |
191 | { | |
192 | h = new TH1F(r->GetName(),r->GetName(),binArray->GetEntries(),bins); | |
193 | h->SetDirectory(0); | |
194 | } | |
195 | ||
196 | Double_t y = r->GetValue(what); | |
197 | Double_t yerr = r->GetErrorStat(what); | |
198 | ||
199 | // if ( !swhat.BeginsWith("ACC") ) | |
200 | if ( swhat.Contains("NOF") ) | |
201 | { | |
202 | y /= (b.WidthX()); | |
203 | yerr /= (b.WidthX()); | |
204 | } | |
205 | ||
206 | h->SetBinContent(j+1,y); | |
207 | h->SetBinError(j+1,yerr); | |
208 | ||
209 | AliInfoClass(Form("%e +- %e",y,yerr)); | |
210 | } | |
211 | ||
212 | delete binArray; | |
213 | delete[] bins; | |
214 | ||
215 | return h; | |
216 | } | |
217 | ||
218 | ||
219 | //______________________________________________________________________________ | |
220 | void AliAnalysisMuMuSpectra::Print(Option_t* opt) const | |
221 | { | |
222 | if (!IsEmpty()) | |
223 | { | |
224 | TString sopt(opt); | |
225 | sopt.ToUpper(); | |
226 | if ( sopt.Contains("BINNING") ) | |
227 | { | |
228 | fBinning->Print(opt); | |
229 | } | |
230 | Int_t nmax = sopt.Atoi(); | |
231 | if ( nmax <= 0 ) nmax = fBins->GetEntries(); | |
232 | for ( Int_t i = 0; i < nmax; ++i ) | |
233 | { | |
234 | AliAnalysisMuMuBinning::Range* r = static_cast<AliAnalysisMuMuBinning::Range*>(fBins->At(i)); | |
235 | if (r) r->Print(opt); | |
236 | } | |
237 | ||
238 | } | |
239 | } |