]>
Commit | Line | Data |
---|---|---|
d440e2c5 | 1 | #include "AliAnalysisMuMuBinning.h" |
2 | ||
3 | // | |
4 | // AliAnalysisMuMuBinning.h : a class to hold bins of various sizes | |
5 | // | |
6 | // The idea behind this class is to store it together with | |
7 | // the histograms (corresponding to the bins) | |
8 | // so we can then loop easily on all bins afterwards. | |
9 | // | |
10 | // author: L. Aphecetche (Subatech) | |
11 | // | |
12 | ||
13 | #include "AliLog.h" | |
14 | #include "Riostream.h" | |
15 | #include "TMap.h" | |
16 | #include "TMath.h" | |
17 | #include "TObjArray.h" | |
18 | #include "TObjString.h" | |
1afce1ce | 19 | #include <cassert> |
d440e2c5 | 20 | |
21 | ClassImp(AliAnalysisMuMuBinning::Range) | |
22 | ClassImp(AliAnalysisMuMuBinning) | |
23 | ||
24 | //______________________________________________________________________________ | |
25 | AliAnalysisMuMuBinning::AliAnalysisMuMuBinning(const char* name, const char* title) | |
26 | : TNamed(name,title), fBins(0x0) | |
27 | { | |
28 | // default ctor | |
29 | } | |
30 | ||
31 | //______________________________________________________________________________ | |
32 | AliAnalysisMuMuBinning::AliAnalysisMuMuBinning(const AliAnalysisMuMuBinning& rhs) | |
33 | : TNamed(), fBins(0x0) | |
34 | { | |
35 | // copy ctor | |
36 | TObjArray* bins = rhs.CreateBinObjArray(); | |
37 | TIter next(bins); | |
38 | AliAnalysisMuMuBinning::Range* b; | |
39 | ||
40 | while ( ( b = static_cast<AliAnalysisMuMuBinning::Range*>(next()) ) ) | |
41 | { | |
42 | AddBin(*b); | |
43 | } | |
44 | } | |
45 | ||
46 | //______________________________________________________________________________ | |
47 | AliAnalysisMuMuBinning& AliAnalysisMuMuBinning::operator=(const AliAnalysisMuMuBinning& rhs) | |
48 | { | |
49 | // assignment operator | |
50 | ||
51 | if ( this != &rhs ) | |
52 | { | |
53 | delete fBins; | |
54 | fBins = 0x0; | |
55 | TObjArray* bins = rhs.CreateBinObjArray(); | |
56 | TIter next(bins); | |
57 | AliAnalysisMuMuBinning::Range* b; | |
58 | ||
59 | while ( ( b = static_cast<AliAnalysisMuMuBinning::Range*>(next()) ) ) | |
60 | { | |
61 | AddBin(*b); | |
62 | } | |
63 | } | |
64 | return *this; | |
65 | } | |
66 | ||
67 | //______________________________________________________________________________ | |
68 | AliAnalysisMuMuBinning::~AliAnalysisMuMuBinning() | |
69 | { | |
70 | // dtor | |
71 | delete fBins; | |
72 | } | |
73 | ||
74 | //______________________________________________________________________________ | |
75 | void AliAnalysisMuMuBinning::AddBin(const AliAnalysisMuMuBinning::Range& bin) | |
76 | { | |
77 | /// add one bin | |
5376e016 | 78 | AddBin(bin.What().Data(),bin.Quantity().Data(), |
d440e2c5 | 79 | bin.Xmin(),bin.Xmax(), |
1afce1ce | 80 | bin.Ymin(),bin.Ymax(),bin.Flavour()); |
d440e2c5 | 81 | } |
1afce1ce | 82 | |
d440e2c5 | 83 | //______________________________________________________________________________ |
5376e016 | 84 | void AliAnalysisMuMuBinning::AddBin(const char* what, const char* quantity, |
d440e2c5 | 85 | Double_t xmin, Double_t xmax, |
86 | Double_t ymin, Double_t ymax, | |
1afce1ce | 87 | const char* flavour) |
d440e2c5 | 88 | { |
89 | /// Add a bin | |
5376e016 | 90 | /// Note that what and Quantity are not case sensitive. |
d440e2c5 | 91 | if (!fBins) |
92 | { | |
93 | fBins = new TMap; | |
94 | fBins->SetOwnerKeyValue(kTRUE,kTRUE); | |
95 | } | |
96 | ||
5376e016 CP |
97 | TString swhat(what); |
98 | swhat.ToUpper(); | |
d440e2c5 | 99 | |
5376e016 CP |
100 | TString sQuantity(quantity); |
101 | sQuantity.ToUpper(); | |
d440e2c5 | 102 | |
5376e016 | 103 | TObjArray* b = static_cast<TObjArray*>(fBins->GetValue(swhat.Data())); |
d440e2c5 | 104 | if (!b) |
105 | { | |
106 | b = new TObjArray; | |
107 | b->SetOwner(kTRUE); | |
5376e016 | 108 | fBins->Add(new TObjString(swhat),b); |
d440e2c5 | 109 | } |
110 | ||
5376e016 | 111 | Range* r = new Range(swhat.Data(),sQuantity.Data(),xmin,xmax,ymin,ymax,flavour); |
d440e2c5 | 112 | |
113 | if ( b->FindObject(r) ) | |
114 | { | |
5376e016 | 115 | AliDebug(1,Form("Trying to add an already existing bin : %s. Not doing it.",r->AsString().Data())); |
d440e2c5 | 116 | delete r; |
117 | } | |
118 | else | |
119 | { | |
120 | b->Add(r); | |
121 | ||
5376e016 | 122 | TString bQuantity(Form("%s-%s",swhat.Data(),sQuantity.Data())); |
d440e2c5 | 123 | |
124 | TString name(GetName()); | |
125 | ||
5376e016 | 126 | if ( !name.Contains(bQuantity) ) |
d440e2c5 | 127 | { |
128 | if (name.Length()>0) | |
129 | { | |
130 | name += " "; | |
131 | } | |
132 | ||
5376e016 | 133 | name += bQuantity; |
d440e2c5 | 134 | SetName(name); |
135 | } | |
136 | } | |
137 | ||
138 | b->Sort(); | |
139 | } | |
140 | ||
141 | //______________________________________________________________________________ | |
142 | Double_t* AliAnalysisMuMuBinning::CreateBinArray() const | |
143 | { | |
144 | /// Create a (variable) bin array suitable for TH1 constructor | |
145 | /// The returned array must be deleted by the user | |
146 | /// (using delete[] ) | |
147 | ||
148 | TObjArray* binArray = CreateBinObjArray(); | |
149 | if (!binArray) return 0x0; | |
150 | Double_t* bins = new Double_t[binArray->GetEntries()+1]; | |
151 | TIter next(binArray); | |
152 | AliAnalysisMuMuBinning::Range* b; | |
153 | Int_t i(0); | |
154 | while ( ( b = static_cast<AliAnalysisMuMuBinning::Range*>(next()) ) ) | |
155 | { | |
156 | bins[i] = b->Xmin(); | |
157 | ++i; | |
158 | } | |
159 | ||
160 | b = static_cast<AliAnalysisMuMuBinning::Range*>(binArray->At(binArray->GetEntries()-1)); | |
161 | ||
162 | bins[i] = b->Xmax(); | |
163 | ||
164 | delete binArray; | |
165 | return bins; | |
166 | } | |
167 | ||
168 | //______________________________________________________________________________ | |
169 | TObjArray* AliAnalysisMuMuBinning::CreateBinObjArray() const | |
170 | { | |
171 | /// Get the list of all the bins | |
172 | /// The returned array must be deleted by the user | |
173 | ||
174 | TObjArray* a = new TObjArray; | |
175 | a->SetOwner(kTRUE); | |
176 | ||
5376e016 CP |
177 | TIter nextwhat(fBins); |
178 | TObjString* what; | |
d440e2c5 | 179 | |
5376e016 | 180 | while ( ( what = static_cast<TObjString*>(nextwhat()) ) ) |
d440e2c5 | 181 | { |
5376e016 | 182 | TObjArray* b = static_cast<TObjArray*>(fBins->GetValue(what->String().Data())); |
d440e2c5 | 183 | TIter next(b); |
184 | Range* r; | |
185 | ||
186 | while ( ( r = static_cast<Range*>(next()) ) ) | |
187 | { | |
188 | a->Add(r->Clone()); | |
189 | } | |
190 | } | |
191 | ||
192 | if ( a->GetLast() < 0 ) | |
193 | { | |
194 | delete a; | |
195 | a = 0x0; | |
196 | } | |
197 | return a; | |
198 | } | |
199 | ||
200 | //______________________________________________________________________________ | |
5376e016 | 201 | TObjArray* AliAnalysisMuMuBinning::CreateBinObjArray(const char* what) const |
d440e2c5 | 202 | { |
5376e016 | 203 | /// Get the list of bins for a given what |
d440e2c5 | 204 | /// The returned array must be deleted by the user |
205 | ||
206 | if (!fBins) return 0x0; | |
207 | ||
208 | TObjArray* a = new TObjArray; | |
209 | a->SetOwner(kTRUE); | |
210 | ||
5376e016 CP |
211 | TString swhat(what); |
212 | swhat.ToUpper(); | |
d440e2c5 | 213 | |
5376e016 | 214 | TObjArray* b = static_cast<TObjArray*>(fBins->GetValue(swhat.Data())); |
d440e2c5 | 215 | if (!b) return 0x0; |
216 | ||
217 | TIter next(b); | |
218 | Range* r; | |
219 | ||
220 | while ( ( r = static_cast<Range*>(next()) ) ) | |
221 | { | |
222 | a->Add(r->Clone()); | |
223 | } | |
224 | ||
225 | if ( a->GetLast() < 0 ) | |
226 | { | |
227 | delete a; | |
228 | a = 0x0; | |
229 | } | |
230 | return a; | |
231 | } | |
232 | ||
233 | ||
234 | //______________________________________________________________________________ | |
5376e016 | 235 | TObjArray* AliAnalysisMuMuBinning::CreateBinObjArray(const char* what, const char* quantity, const char* flavour) const |
d440e2c5 | 236 | { |
5376e016 | 237 | /// Get the list of bins for a given what and given Quantity |
d440e2c5 | 238 | /// The returned array must be deleted by the user |
5376e016 | 239 | /// Quantity can be a single Quantity or several Quantitys separated by comma |
d440e2c5 | 240 | |
241 | TObjArray* a = new TObjArray; | |
242 | a->SetOwner(kTRUE); | |
243 | ||
5376e016 CP |
244 | TString swhat(what); |
245 | swhat.ToUpper(); | |
d440e2c5 | 246 | |
5376e016 | 247 | TObjArray* b = static_cast<TObjArray*>(fBins->GetValue(swhat.Data())); |
d440e2c5 | 248 | if (!b) return 0x0; |
249 | ||
250 | TIter next(b); | |
251 | Range* r; | |
252 | ||
5376e016 CP |
253 | TString sQuantity(quantity); |
254 | sQuantity.ToUpper(); | |
d440e2c5 | 255 | |
1afce1ce | 256 | TString sflavour(flavour); |
257 | ||
5376e016 CP |
258 | TObjArray* Quantitys = sQuantity.Tokenize(","); |
259 | TObjString* oneQuantity; | |
260 | TIter nextQuantity(Quantitys); | |
d440e2c5 | 261 | |
262 | while ( ( r = static_cast<Range*>(next()) ) ) | |
263 | { | |
5376e016 CP |
264 | nextQuantity.Reset(); |
265 | while ( ( oneQuantity = static_cast<TObjString*>(nextQuantity()) ) ) | |
d440e2c5 | 266 | { |
5376e016 | 267 | if ( r->Quantity() == oneQuantity->String() && |
1afce1ce | 268 | ( ( sflavour.Length() > 0 && r->Flavour() == sflavour.Data() ) || sflavour.Length()==0 ) ) |
d440e2c5 | 269 | { |
270 | a->Add(r->Clone()); | |
271 | } | |
272 | } | |
273 | } | |
274 | ||
275 | if ( a->GetLast() < 0 ) | |
276 | { | |
277 | delete a; | |
278 | a = 0x0; | |
279 | } | |
280 | ||
5376e016 | 281 | delete Quantitys; |
d440e2c5 | 282 | return a; |
283 | } | |
284 | ||
285 | //______________________________________________________________________________ | |
5376e016 CP |
286 | void AliAnalysisMuMuBinning::CreateMesh(const char* what, |
287 | const char* quantity1, const char* quantity2, | |
1afce1ce | 288 | const char* flavour, |
d440e2c5 | 289 | Bool_t remove12) |
290 | { | |
5376e016 CP |
291 | /// Create 2D bins from existing 1d ones of Quantity1 and Quantity2 |
292 | TObjArray* a1 = CreateBinObjArray(what,quantity1,flavour); | |
d440e2c5 | 293 | if (!a1) |
294 | { | |
5376e016 | 295 | AliError(Form("No bin for Quantity %s. Done nothing.",quantity1)); |
d440e2c5 | 296 | return; |
297 | } | |
5376e016 | 298 | TObjArray* a2 = CreateBinObjArray(what,quantity2,flavour); |
d440e2c5 | 299 | if (!a2) |
300 | { | |
5376e016 | 301 | AliError(Form("No bin for Quantity %s. Done nothing.",quantity2)); |
d440e2c5 | 302 | return; |
303 | } | |
304 | ||
5376e016 | 305 | TString meshQuantity(Form("%s VS %s - %s",quantity1,quantity2,flavour)); |
d440e2c5 | 306 | |
307 | for ( Int_t i1 = 0; i1 <= a1->GetLast(); ++i1 ) | |
308 | { | |
309 | Range* r1 = static_cast<Range*>(a1->At(i1)); | |
310 | ||
311 | for ( Int_t i2 = 0; i2 <= a2->GetLast(); ++i2 ) | |
312 | { | |
313 | Range* r2 = static_cast<Range*>(a2->At(i2)); | |
314 | ||
5376e016 | 315 | AddBin(what,meshQuantity,r2->Xmin(),r2->Xmax(),r1->Xmin(),r1->Xmax(),Form("%s VS %s",r1->Flavour().Data(),r2->Flavour().Data())); |
d440e2c5 | 316 | } |
317 | } | |
318 | ||
319 | delete a1; | |
320 | delete a2; | |
321 | ||
322 | if ( remove12 ) | |
323 | { | |
5376e016 | 324 | TObjArray* b = static_cast<TObjArray*>(fBins->GetValue(what)); |
d440e2c5 | 325 | TIter next(b); |
326 | Range* r; | |
5376e016 CP |
327 | TString sQuantity1(quantity1); |
328 | TString sQuantity2(quantity2); | |
d440e2c5 | 329 | |
5376e016 CP |
330 | sQuantity1.ToUpper(); |
331 | sQuantity2.ToUpper(); | |
d440e2c5 | 332 | |
333 | while ( ( r = static_cast<Range*>(next())) ) | |
334 | { | |
5376e016 CP |
335 | if ( r->Quantity() == quantity1 || |
336 | r->Quantity() == quantity2 ) | |
d440e2c5 | 337 | { |
338 | b->Remove(r); | |
339 | } | |
340 | } | |
341 | } | |
342 | } | |
343 | ||
344 | //______________________________________________________________________________ | |
5376e016 | 345 | TObjArray* AliAnalysisMuMuBinning::CreateWhatArray() const |
d440e2c5 | 346 | { |
5376e016 | 347 | /// Create a TObjString array with the names of the what we're holding results for |
d440e2c5 | 348 | /// Returned array must be delete by user |
349 | ||
5376e016 | 350 | TObjArray* whatArray(0x0); |
d440e2c5 | 351 | |
5376e016 CP |
352 | TIter nextwhat(fBins); |
353 | TObjString* what; | |
d440e2c5 | 354 | |
5376e016 | 355 | while ( ( what = static_cast<TObjString*>(nextwhat()) ) ) |
d440e2c5 | 356 | { |
5376e016 | 357 | if (!whatArray) |
d440e2c5 | 358 | { |
5376e016 CP |
359 | whatArray = new TObjArray; |
360 | whatArray->SetOwner(kTRUE); | |
d440e2c5 | 361 | } |
5376e016 | 362 | whatArray->Add(new TObjString(*what)); |
d440e2c5 | 363 | } |
5376e016 | 364 | return whatArray; |
d440e2c5 | 365 | } |
366 | ||
367 | //______________________________________________________________________________ | |
5376e016 | 368 | TObjArray* AliAnalysisMuMuBinning::CreateQuantityArray() const |
d440e2c5 | 369 | { |
5376e016 | 370 | /// Create a TObjString array with the names of the binning Quantitys |
d440e2c5 | 371 | /// Returned array must be delete by user |
372 | ||
5376e016 | 373 | TObjArray* QuantityArray(0x0); |
d440e2c5 | 374 | |
5376e016 CP |
375 | TIter nextwhat(fBins); |
376 | TObjString* what; | |
d440e2c5 | 377 | |
5376e016 | 378 | while ( ( what = static_cast<TObjString*>(nextwhat()) ) ) |
d440e2c5 | 379 | { |
5376e016 | 380 | TObjArray* whats = static_cast<TObjArray*>(fBins->GetValue(what->String())); |
d440e2c5 | 381 | |
5376e016 | 382 | TIter next(whats); |
d440e2c5 | 383 | Range* r; |
384 | ||
385 | while ( ( r = static_cast<Range*>(next())) ) | |
386 | { | |
5376e016 | 387 | if (!QuantityArray) |
d440e2c5 | 388 | { |
5376e016 CP |
389 | QuantityArray = new TObjArray; |
390 | QuantityArray->SetOwner(kTRUE); | |
d440e2c5 | 391 | } |
5376e016 | 392 | if ( !QuantityArray->FindObject(r->Quantity()) ) |
d440e2c5 | 393 | { |
5376e016 | 394 | QuantityArray->Add(new TObjString(r->Quantity())); |
d440e2c5 | 395 | } |
396 | } | |
397 | } | |
5376e016 | 398 | return QuantityArray; |
d440e2c5 | 399 | } |
400 | ||
401 | //______________________________________________________________________________ | |
402 | Bool_t AliAnalysisMuMuBinning::IsEqual(const TObject* obj) const | |
403 | { | |
404 | /// Return kTRUE if obj is an AliAnalysisMuMuBinning object and is | |
405 | /// equal to *this | |
406 | ||
407 | if ( obj->IsA() == AliAnalysisMuMuBinning::Class() ) | |
408 | { | |
409 | const AliAnalysisMuMuBinning* other = static_cast<const AliAnalysisMuMuBinning*>(obj); | |
410 | ||
411 | TIter nextOther(other->fBins); | |
412 | TObjString* str; | |
413 | ||
414 | while ( ( str = static_cast<TObjString*>(nextOther()) ) ) | |
415 | { | |
416 | TObject* o = fBins->GetValue(str->String()); | |
417 | if (!o) return kFALSE; | |
418 | if (o->IsA() != TObjArray::Class()) return kFALSE; | |
419 | ||
420 | TObjArray* thisArray = static_cast<TObjArray*>(o); | |
421 | ||
422 | o = other->fBins->GetValue(str->String()); | |
423 | if (!o) return kFALSE; | |
424 | if (o->IsA() != TObjArray::Class()) return kFALSE; | |
425 | ||
426 | TObjArray* otherArray = static_cast<TObjArray*>(o); | |
427 | ||
428 | Int_t n = thisArray->GetEntries(); | |
429 | ||
430 | if ( n != otherArray->GetEntries() ) return kFALSE; | |
431 | ||
432 | for ( Int_t i = 0; i < n; ++i ) | |
433 | { | |
434 | Range* thisRange = static_cast<Range*>(thisArray->At(i)); | |
435 | Range* otherRange = static_cast<Range*>(otherArray->At(i)); | |
436 | ||
437 | if ( !thisRange->IsEqual(otherRange) ) return kFALSE; | |
438 | } | |
439 | } | |
440 | return kTRUE; | |
441 | } | |
442 | ||
443 | return kFALSE; | |
444 | } | |
445 | ||
446 | ||
447 | //______________________________________________________________________________ | |
448 | Long64_t AliAnalysisMuMuBinning::Merge(TCollection* list) | |
449 | { | |
450 | /// Merge method | |
451 | ||
452 | // Merge a list of AliAnalysisMuMuBinning objects with this | |
453 | // Returns the number of merged objects (including this). | |
454 | ||
455 | if (!list) return 0; | |
456 | ||
457 | if (list->IsEmpty()) return 1; | |
458 | ||
459 | TIter next(list); | |
460 | TObject* currObj; | |
461 | Int_t count(0); | |
462 | ||
463 | while ( ( currObj = next() ) ) | |
464 | { | |
465 | AliAnalysisMuMuBinning* binning = dynamic_cast<AliAnalysisMuMuBinning*>(currObj); | |
466 | if (!binning) | |
467 | { | |
468 | AliFatal(Form("object named \"%s\" is a %s instead of an AliAnalysisMuMuBinning!", currObj->GetName(), currObj->ClassName())); | |
469 | continue; | |
470 | } | |
471 | ||
472 | if ( IsEqual(binning) ) | |
473 | { | |
474 | // nothing to do if we have the same binning already ;-) | |
475 | } | |
476 | else | |
477 | { | |
478 | AliWarning("Implement me!"); | |
479 | std::cout << ">>>> this=" << std::endl; | |
480 | Print(); | |
481 | std::cout << ">>>> other=" << std::endl; | |
482 | binning->Print(); | |
483 | } | |
484 | ++count; | |
485 | } | |
486 | ||
487 | return count+1; | |
488 | } | |
489 | ||
490 | //______________________________________________________________________________ | |
491 | AliAnalysisMuMuBinning* | |
5376e016 | 492 | AliAnalysisMuMuBinning::Project(const char* what, const char* quantity, const char* flavour) const |
d440e2c5 | 493 | { |
5376e016 | 494 | /// Create a sub-binning object with only the bins pertaining to (what,Quantity) |
d440e2c5 | 495 | |
5376e016 | 496 | TObjArray* bins = CreateBinObjArray(what,quantity,flavour); |
d440e2c5 | 497 | if (!bins) return 0x0; |
498 | AliAnalysisMuMuBinning* p = new AliAnalysisMuMuBinning; | |
499 | TIter next(bins); | |
500 | AliAnalysisMuMuBinning::Range* bin; | |
5376e016 CP |
501 | TString sQuantity(quantity); |
502 | sQuantity.ToUpper(); | |
d440e2c5 | 503 | |
504 | while ( ( bin = static_cast<AliAnalysisMuMuBinning::Range*>(next())) ) | |
505 | { | |
5376e016 | 506 | if (bin->Quantity()!=sQuantity || bin->Flavour()!=flavour) |
d440e2c5 | 507 | { |
5376e016 CP |
508 | AliDebug(1,Form("sQuantity=%s flavour=%s bin=%s => skip",sQuantity.Data(),flavour,bin->AsString().Data())); |
509 | continue; | |
510 | } | |
511 | { | |
512 | p->AddBin(what,bin->Quantity(),bin->Xmin(),bin->Xmax(),bin->Ymin(),bin->Ymax(),bin->Flavour().Data()); | |
d440e2c5 | 513 | } |
514 | } | |
515 | ||
516 | delete bins; | |
517 | ||
518 | return p; | |
519 | } | |
520 | ||
521 | //______________________________________________________________________________ | |
522 | void AliAnalysisMuMuBinning::Print(Option_t* /*opt*/) const | |
523 | { | |
524 | /// Print the bins | |
525 | ||
526 | if (!fBins) | |
527 | { | |
528 | std::cout << "Empty object. No bin defined. " << std::endl; | |
529 | return; | |
530 | } | |
531 | ||
5376e016 | 532 | TIter nextwhat(fBins); |
d440e2c5 | 533 | TObjString* str; |
534 | ||
5376e016 | 535 | while ( ( str = static_cast<TObjString*>(nextwhat()) ) ) |
d440e2c5 | 536 | { |
5376e016 | 537 | std::cout << "what : " << str->String().Data() << std::endl; |
d440e2c5 | 538 | TObjArray* b = static_cast<TObjArray*>(fBins->GetValue(str->String())); |
539 | TIter next(b); | |
540 | Range* r(0x0); | |
541 | next.Reset(); | |
542 | Int_t i(1); | |
543 | while ( ( r = static_cast<Range*>(next()) ) ) | |
544 | { | |
545 | std::cout << Form("BIN %3d ",i++); | |
546 | r->Print(); | |
547 | } | |
548 | } | |
549 | } | |
550 | ||
551 | //______________________________________________________________________________ | |
552 | //______________________________________________________________________________ | |
553 | //______________________________________________________________________________ | |
554 | //______________________________________________________________________________ | |
555 | ||
556 | //______________________________________________________________________________ | |
5376e016 | 557 | AliAnalysisMuMuBinning::Range::Range(const char* what, const char* quantity, |
d440e2c5 | 558 | Double_t xmin, Double_t xmax, |
1afce1ce | 559 | Double_t ymin, Double_t ymax, |
560 | const char* flavour) | |
5376e016 | 561 | : TObject(), fWhat(what), fQuantity(quantity), |
1afce1ce | 562 | fXmin(xmin), fXmax(xmax), fYmin(ymin), fYmax(ymax), |
563 | fFlavour(flavour) | |
d440e2c5 | 564 | { |
565 | /// ctor | |
5376e016 CP |
566 | fWhat.ToUpper(); |
567 | fQuantity.ToUpper(); | |
d440e2c5 | 568 | } |
569 | ||
570 | //______________________________________________________________________________ | |
571 | TString AliAnalysisMuMuBinning::Range::AsString() const | |
572 | { | |
573 | /// Return a string representation of this range | |
574 | ||
5376e016 | 575 | if ( IsIntegrated()) return Quantity().Data(); |
d440e2c5 | 576 | |
577 | TString s; | |
578 | ||
1afce1ce | 579 | if ( fFlavour.Length() > 0 ) |
580 | { | |
5376e016 | 581 | s.Form("%s_%s_%05.2f_%05.2f",Quantity().Data(),Flavour().Data(),Xmin(),Xmax()); |
1afce1ce | 582 | } |
583 | else | |
584 | { | |
5376e016 | 585 | s.Form("%s_%05.2f_%05.2f",Quantity().Data(),Xmin(),Xmax()); |
1afce1ce | 586 | } |
d440e2c5 | 587 | |
588 | if (Is2D()) | |
589 | { | |
590 | s += TString::Format("_%06.2f_%06.2f",Ymin(),Ymax()); | |
591 | } | |
592 | ||
593 | s.ReplaceAll(" ",""); | |
594 | s.ReplaceAll("+",""); | |
595 | s.ReplaceAll("-","m"); | |
596 | ||
597 | return s; | |
598 | } | |
599 | ||
600 | //______________________________________________________________________________ | |
601 | Int_t AliAnalysisMuMuBinning::Range::Compare(const TObject* obj) const | |
602 | { | |
603 | // Must return -1 if this is smaller | |
604 | // than obj, 0 if objects are equal and 1 if this is larger than obj. | |
605 | const Range* other = static_cast<const Range*>(obj); | |
606 | ||
5376e016 | 607 | int s = strcmp(What().Data(),other->What().Data()); |
d440e2c5 | 608 | |
609 | if ( s ) return s; | |
610 | ||
5376e016 | 611 | s = strcmp(Quantity().Data(),other->Quantity().Data()); |
d440e2c5 | 612 | |
613 | if (s) return s; | |
614 | ||
1afce1ce | 615 | s = strcmp(Flavour().Data(),other->Flavour().Data()); |
616 | ||
617 | if (s) return s; | |
618 | ||
5376e016 | 619 | // if ( IsIntegrated() && other->IsIntegrated() ) return 0; |
1afce1ce | 620 | |
d440e2c5 | 621 | if ( Xmin() < other->Xmin() ) |
622 | { | |
623 | return -1; | |
624 | } | |
625 | else if ( Xmin() > other->Xmin() ) | |
626 | { | |
627 | return 1; | |
628 | } | |
629 | else | |
630 | { | |
631 | if ( Xmax() < other->Xmax() ) | |
632 | { | |
633 | return -1; | |
634 | } | |
635 | else if ( Xmax() > other->Xmax() ) | |
636 | { | |
637 | return 1; | |
638 | } | |
639 | else { | |
640 | if ( Ymin() < other->Ymin() ) | |
641 | { | |
642 | return -1; | |
643 | } | |
644 | else if ( Ymin() > other->Ymin() ) | |
645 | { | |
646 | return 1; | |
647 | } | |
648 | else | |
649 | { | |
650 | if ( Ymax() < other->Ymax() ) | |
651 | { | |
652 | return -1; | |
653 | } | |
654 | else if ( Ymax() > other->Ymax() ) | |
655 | { | |
656 | return 1; | |
657 | } | |
5376e016 | 658 | } |
d440e2c5 | 659 | } |
660 | } | |
661 | return 0; | |
662 | } | |
663 | ||
664 | //______________________________________________________________________________ | |
665 | Bool_t AliAnalysisMuMuBinning::Range::IsInRange(Double_t x, Double_t y) const | |
666 | { | |
667 | /// If Range is 1D, returns true if x is in range | |
668 | /// If Range is 2D, returns true if (x,y) is in range | |
669 | ||
5376e016 | 670 | if ( IsIntegrated() ) |
d440e2c5 | 671 | { |
672 | return kTRUE; | |
673 | } | |
674 | else | |
675 | { | |
676 | if ( Is2D() ) | |
677 | { | |
5376e016 | 678 | return ( x >= Xmin() && x < Xmax() && y >= Ymin() && y < Ymax()); |
d440e2c5 | 679 | } |
680 | else | |
681 | { | |
5376e016 | 682 | return ( x >= Xmin() && x < Xmax() ); |
d440e2c5 | 683 | } |
684 | } | |
685 | } | |
686 | ||
687 | //______________________________________________________________________________ | |
5376e016 | 688 | Bool_t AliAnalysisMuMuBinning::Range::IsIntegrated() const |
d440e2c5 | 689 | { |
5376e016 | 690 | /// Whether we're a null object (aka integrated) or not |
d440e2c5 | 691 | return |
692 | Xmin() >= TMath::Limits<Double_t>::Max() && | |
693 | Ymin() >= TMath::Limits<Double_t>::Max() && | |
694 | Xmax() >= TMath::Limits<Double_t>::Max() && | |
695 | Ymax() >= TMath::Limits<Double_t>::Max() ; | |
696 | } | |
697 | ||
698 | ||
699 | //______________________________________________________________________________ | |
700 | void AliAnalysisMuMuBinning::Range::Print(Option_t* /*opt*/) const | |
701 | { | |
702 | /// Output to stdout | |
703 | ||
5376e016 | 704 | if (IsIntegrated()) |
d440e2c5 | 705 | { |
5376e016 | 706 | std::cout << Form("%s : %s : INTEGRATED",What().Data(),Quantity().Data()) << std::endl; |
d440e2c5 | 707 | |
708 | return; | |
709 | } | |
710 | ||
5376e016 | 711 | std::cout << Form("%s : %s : %5.2f : %5.2f",What().Data(),Quantity().Data(),Xmin(),Xmax()); |
d440e2c5 | 712 | |
713 | if (Is2D()) | |
714 | { | |
715 | std::cout << Form(" ; %5.2f : %5.2f",Ymin(),Ymax()); | |
716 | } | |
717 | ||
1afce1ce | 718 | if (Flavour().Length()>0) |
719 | { | |
720 | std::cout << " - " << Flavour().Data(); | |
721 | } | |
722 | ||
d440e2c5 | 723 | std::cout << "->" << AsString().Data() << std::endl; |
724 | ||
725 | } | |
726 | ||
727 |