]>
Commit | Line | Data |
---|---|---|
1afce1ce | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ||
17 | // AliAnalysisMuMuSpectra : a class to encapsulate results from MuMu analysis | |
18 | // | |
19 | // Spectra can be merged and converted into histograms | |
20 | // | |
21 | // author: L. Aphecetche (Subatech) | |
22 | // | |
23 | ||
a58729a5 | 24 | #include "AliAnalysisMuMuSpectra.h" |
25 | ||
26 | #include "AliLog.h" | |
27 | #include "AliAnalysisMuMuBinning.h" | |
28 | #include "AliAnalysisMuMuResult.h" | |
29 | #include "Riostream.h" | |
30 | #include "TH1.h" | |
31 | #include "TList.h" | |
32 | #include "TObjArray.h" | |
33 | ||
34 | ClassImp(AliAnalysisMuMuSpectra) | |
35 | ||
36 | //______________________________________________________________________________ | |
37 | AliAnalysisMuMuSpectra::AliAnalysisMuMuSpectra(const char* name, const char* title) : | |
38 | TNamed(name,title), | |
39 | fBinning(0x0), | |
40 | fBins(0x0) | |
41 | { | |
1afce1ce | 42 | // default ctor |
43 | } | |
44 | ||
45 | //______________________________________________________________________________ | |
46 | AliAnalysisMuMuSpectra::AliAnalysisMuMuSpectra(const AliAnalysisMuMuSpectra& rhs) | |
47 | : TNamed(rhs.GetName(),rhs.GetTitle()), | |
48 | fBinning(0x0), | |
49 | fBins(0x0) | |
50 | { | |
51 | // copy ctor | |
52 | ||
53 | if ( rhs.fBinning ) | |
54 | { | |
55 | fBinning = new AliAnalysisMuMuBinning(*rhs.fBinning); | |
56 | } | |
57 | ||
58 | TIter next(rhs.fBins); | |
59 | AliAnalysisMuMuBinning::Range* bin; | |
60 | ||
61 | while ( ( bin = static_cast<AliAnalysisMuMuBinning::Range*>(next()) ) ) | |
62 | { | |
63 | if (!fBins) | |
64 | { | |
65 | fBins = new TObjArray; | |
66 | fBins->SetOwner(kTRUE); | |
67 | } | |
68 | fBins->Add(bin); | |
69 | } | |
70 | } | |
71 | ||
72 | //______________________________________________________________________________ | |
73 | AliAnalysisMuMuSpectra& | |
74 | AliAnalysisMuMuSpectra::operator=(const AliAnalysisMuMuSpectra& rhs) | |
75 | { | |
76 | // assignment operator | |
77 | ||
78 | if (this==&rhs) return *this; | |
79 | ||
80 | delete fBinning; | |
81 | fBinning = 0x0; | |
82 | delete fBins; | |
83 | fBins = 0x0; | |
84 | ||
85 | if ( rhs.fBinning ) | |
86 | { | |
87 | fBinning = new AliAnalysisMuMuBinning(*rhs.fBinning); | |
88 | } | |
89 | ||
90 | TIter next(rhs.fBins); | |
91 | AliAnalysisMuMuBinning::Range* bin; | |
a58729a5 | 92 | |
1afce1ce | 93 | while ( ( bin = static_cast<AliAnalysisMuMuBinning::Range*>(next()) ) ) |
94 | { | |
95 | if (!fBins) | |
96 | { | |
97 | fBins = new TObjArray; | |
98 | fBins->SetOwner(kTRUE); | |
99 | } | |
100 | fBins->Add(bin); | |
101 | } | |
102 | ||
103 | return *this; | |
a58729a5 | 104 | } |
105 | ||
106 | //______________________________________________________________________________ | |
107 | AliAnalysisMuMuSpectra::~AliAnalysisMuMuSpectra() | |
108 | { | |
1afce1ce | 109 | // dtor |
a58729a5 | 110 | delete fBinning; |
111 | delete fBins; | |
112 | } | |
113 | ||
114 | //______________________________________________________________________________ | |
115 | void AliAnalysisMuMuSpectra::AdoptResult(const AliAnalysisMuMuBinning::Range& bin, | |
116 | AliAnalysisMuMuResult* result) | |
117 | { | |
1afce1ce | 118 | // adopt (i.e. we are becoming the owner) a result for a given bin |
a58729a5 | 119 | if (!fBinning) |
120 | { | |
121 | fBinning = new AliAnalysisMuMuBinning; | |
122 | fBins = new TObjArray; | |
123 | fBins->SetOwner(kTRUE); | |
124 | } | |
125 | fBinning->AddBin(bin); | |
126 | fBins->Add(result); | |
127 | } | |
128 | ||
129 | //______________________________________________________________________________ | |
130 | Bool_t AliAnalysisMuMuSpectra::Correct(const AliAnalysisMuMuSpectra& accEff, const char* particle, const char* subResultName) | |
131 | { | |
132 | /// Correct this spectra by acceff one | |
133 | if (IsEmpty()) | |
134 | { | |
135 | AliError("Cannot correct an empty spectra !"); | |
136 | return kFALSE; | |
137 | } | |
138 | ||
139 | // check we have the same binning first | |
140 | AliAnalysisMuMuBinning* accEffBins = accEff.Binning(); | |
141 | ||
142 | if ( !fBinning->IsEqual(accEffBins) ) | |
143 | { | |
144 | AliError("Cannot correct with a spectra which does not have the same binning"); | |
145 | return kFALSE; | |
146 | } | |
147 | ||
148 | TObjArray* particles = fBinning->CreateParticleArray(); | |
149 | TObjArray* types = fBinning->CreateTypeArray(); | |
150 | ||
151 | if (particles->GetEntries()!=1 || types->GetEntries()!=1 ) | |
152 | { | |
153 | delete particles; | |
154 | delete types; | |
155 | return kFALSE; | |
156 | } | |
157 | ||
158 | TObjArray* bins = accEff.Bins(); | |
159 | ||
160 | ||
161 | for ( Int_t i = 0; i < bins->GetEntries(); ++i ) | |
162 | { | |
163 | AliAnalysisMuMuResult* thisResult = static_cast<AliAnalysisMuMuResult*>(fBins->At(i)); | |
164 | AliAnalysisMuMuResult* accResult = static_cast<AliAnalysisMuMuResult*>(bins->At(i)); | |
1afce1ce | 165 | // AliInfoClass(Form("i=%d",i )); |
166 | // StdoutToAliInfoClass(thisResult->Print("full"); | |
167 | // std::cout << "----" << std::endl; | |
168 | // accResult->Print("full")); | |
a58729a5 | 169 | |
170 | thisResult->Correct(*accResult,particle,subResultName); | |
171 | } | |
172 | ||
173 | delete particles; | |
174 | delete types; | |
175 | return kTRUE; | |
176 | } | |
177 | ||
1afce1ce | 178 | //______________________________________________________________________________ |
179 | AliAnalysisMuMuResult* | |
180 | AliAnalysisMuMuSpectra::GetResultForBin(const AliAnalysisMuMuBinning::Range& bin) const | |
181 | { | |
182 | /// Get result for a given bin | |
183 | /// Warning: this requires a loop on bins | |
184 | ||
185 | if ( IsEmpty() ) return 0x0; | |
186 | ||
187 | TObjArray* bins = fBinning->CreateBinObjArray(); | |
188 | ||
189 | Int_t j(-1); | |
190 | ||
191 | StdoutToAliDebug(1,std::cout << "searching for "; bin.Print()); | |
192 | ||
193 | for ( Int_t i = 0; i <= bins->GetLast() && j < 0 ; ++i ) | |
194 | { | |
195 | AliAnalysisMuMuBinning::Range* b = static_cast<AliAnalysisMuMuBinning::Range*>(bins->At(i)); | |
196 | ||
197 | StdoutToAliDebug(1,b->Print();); | |
198 | ||
199 | if ( bin == *b ) | |
200 | { | |
201 | j = i; | |
202 | } | |
203 | } | |
204 | ||
205 | delete bins; | |
206 | ||
207 | if (j>=0) | |
208 | { | |
209 | return static_cast<AliAnalysisMuMuResult*>(fBins->At(j)); | |
210 | } | |
211 | else | |
212 | { | |
213 | StdoutToAliDebug(1,std::cout << "Could not find result for bin:" << std::endl; bin.Print();); | |
214 | } | |
215 | return 0x0; | |
216 | } | |
217 | ||
218 | //______________________________________________________________________________ | |
219 | Bool_t AliAnalysisMuMuSpectra::HasValue(const char* what) const | |
220 | { | |
221 | // whether or not our result(s) has a given property | |
222 | if ( IsEmpty() ) return kFALSE; | |
223 | ||
224 | AliAnalysisMuMuResult* r = static_cast<AliAnalysisMuMuResult*>(fBins->First()); | |
225 | ||
226 | return r->HasValue(what); | |
227 | } | |
228 | ||
a58729a5 | 229 | //______________________________________________________________________________ |
230 | Bool_t AliAnalysisMuMuSpectra::IsEmpty() const | |
231 | { | |
1afce1ce | 232 | // whether this spectra is empty or not |
a58729a5 | 233 | return ( fBins==0x0 || fBins->GetEntries()<=0 ); |
234 | } | |
235 | ||
236 | //______________________________________________________________________________ | |
237 | Long64_t AliAnalysisMuMuSpectra::Merge(TCollection* list) | |
238 | { | |
239 | /// Merge method | |
240 | ||
241 | // Merge a list of AliAnalysisMuMuSpectra objects with this | |
242 | // Returns the number of merged objects (including this). | |
243 | ||
244 | if (!list) return 0; | |
245 | ||
246 | if (list->IsEmpty()) return 1; | |
247 | ||
248 | TIter next(list); | |
249 | TObject* currObj; | |
250 | Int_t count(0); | |
251 | ||
252 | TList binningList; | |
253 | ||
254 | for ( Int_t i = 0; i <= fBins->GetLast(); ++i ) | |
255 | { | |
256 | next.Reset(); | |
257 | ||
258 | TList binList; | |
259 | ||
260 | while ( ( currObj = next() ) ) | |
261 | { | |
262 | AliAnalysisMuMuSpectra* spectra = dynamic_cast<AliAnalysisMuMuSpectra*>(currObj); | |
263 | if (!spectra) | |
264 | { | |
265 | AliFatal(Form("object named \"%s\" is a %s instead of an AliAnalysisMuMuSpectra!", currObj->GetName(), currObj->ClassName())); | |
266 | continue; | |
267 | } | |
268 | ||
269 | if (i==0) | |
270 | { | |
271 | binningList.Add(spectra->Binning()); | |
272 | ||
273 | if ( !fBinning->IsEqual(spectra->Binning()) || spectra->Bins()->GetLast() != Bins()->GetLast() ) | |
274 | { | |
275 | AliError("Cannot merge spectra with different binning"); | |
276 | continue; | |
277 | } | |
278 | ||
279 | ++count; | |
280 | } | |
281 | ||
282 | binList.Add(fBins->At(i)); | |
283 | } | |
284 | ||
285 | AliAnalysisMuMuResult* r = static_cast<AliAnalysisMuMuResult*>(fBins->At(i)); | |
286 | r->Merge(&binList); | |
287 | ||
288 | } | |
289 | ||
290 | fBinning->Merge(&binningList); | |
291 | ||
292 | return count+1; | |
293 | } | |
294 | ||
295 | //_____________________________________________________________________________ | |
1afce1ce | 296 | TH1* AliAnalysisMuMuSpectra::Plot(const char* what, const char* subresult, Bool_t divideByBinWidth) const |
a58729a5 | 297 | { |
1afce1ce | 298 | // Convert the spectra into an histogram |
299 | ||
a58729a5 | 300 | TString swhat(what); |
301 | swhat.ToUpper(); | |
302 | ||
303 | Double_t* bins = fBinning->CreateBinArray(); | |
304 | ||
305 | TObjArray* binArray = fBinning->CreateBinObjArray(); | |
306 | ||
307 | TH1* h(0x0); | |
308 | ||
1afce1ce | 309 | AliDebug(1,Form("nbins=%d nresults=%d",binArray->GetEntries(),fBins->GetEntries())); |
a58729a5 | 310 | |
311 | for ( Int_t j = 0; j < TMath::Min(binArray->GetEntries(),fBins->GetEntries()); ++j ) | |
312 | { | |
313 | AliAnalysisMuMuResult* r = static_cast<AliAnalysisMuMuResult*>(fBins->At(j)); | |
314 | ||
1afce1ce | 315 | if ( strlen(subresult) > 0 && r->SubResults() ) |
a58729a5 | 316 | { |
a58729a5 | 317 | TString sub(subresult); |
318 | sub.ToUpper(); | |
1afce1ce | 319 | r = r->SubResult(sub.Data()); |
a58729a5 | 320 | if (!r) continue; |
321 | } | |
322 | ||
323 | const AliAnalysisMuMuBinning::Range& b = r->Bin(); | |
324 | ||
a58729a5 | 325 | if (!h) |
326 | { | |
327 | h = new TH1F(r->GetName(),r->GetName(),binArray->GetEntries(),bins); | |
328 | h->SetDirectory(0); | |
329 | } | |
330 | ||
331 | Double_t y = r->GetValue(what); | |
332 | Double_t yerr = r->GetErrorStat(what); | |
1afce1ce | 333 | |
334 | if ( divideByBinWidth && b.WidthX()>0 ) | |
a58729a5 | 335 | { |
336 | y /= (b.WidthX()); | |
337 | yerr /= (b.WidthX()); | |
338 | } | |
339 | ||
1afce1ce | 340 | std::cout << b.AsString(); |
341 | AliAnalysisMuMuResult::PrintValue(swhat.Data(),"",y,yerr); | |
342 | ||
a58729a5 | 343 | h->SetBinContent(j+1,y); |
344 | h->SetBinError(j+1,yerr); | |
345 | ||
a58729a5 | 346 | } |
347 | ||
348 | delete binArray; | |
349 | delete[] bins; | |
350 | ||
351 | return h; | |
352 | } | |
353 | ||
354 | ||
355 | //______________________________________________________________________________ | |
356 | void AliAnalysisMuMuSpectra::Print(Option_t* opt) const | |
357 | { | |
1afce1ce | 358 | // printout |
359 | ||
a58729a5 | 360 | if (!IsEmpty()) |
361 | { | |
362 | TString sopt(opt); | |
a58729a5 | 363 | Int_t nmax = sopt.Atoi(); |
364 | if ( nmax <= 0 ) nmax = fBins->GetEntries(); | |
365 | for ( Int_t i = 0; i < nmax; ++i ) | |
366 | { | |
1afce1ce | 367 | AliAnalysisMuMuResult* r = static_cast<AliAnalysisMuMuResult*>(fBins->At(i)); |
a58729a5 | 368 | if (r) r->Print(opt); |
369 | } | |
a58729a5 | 370 | } |
371 | } |