]>
Commit | Line | Data |
---|---|---|
b425275c | 1 | // |
2 | // Class AliMixInfo | |
3 | // | |
4 | // AliMixInfo object contains information about one cut on for event mixing | |
5 | // available for users containing mixing information | |
6 | // | |
7 | // authors: | |
8 | // Martin Vala (martin.vala@cern.ch) | |
9 | // | |
10 | ||
11 | #include <TList.h> | |
12 | #include <TPad.h> | |
13 | #include <TROOT.h> | |
14 | #include <TFile.h> | |
15 | #include <TH1.h> | |
16 | #include <TH2.h> | |
17 | #include <TProfile.h> | |
18 | #include <TStyle.h> | |
19 | #include <TLegend.h> | |
20 | #include <TPavesText.h> | |
21 | #include <TCanvas.h> | |
22 | ||
23 | #include "AliLog.h" | |
24 | ||
25 | #include "AliMixInfo.h" | |
26 | #include "AliMixEventPool.h" | |
27 | #include "AliMixEventCutObj.h" | |
28 | ||
29 | ClassImp(AliMixInfo) | |
30 | ||
31 | //_________________________________________________________________________________________________ | |
32 | AliMixInfo::AliMixInfo(const char *name, const char *title) : | |
33 | TNamed(name, title), | |
34 | fHistogramList(0) | |
35 | { | |
36 | // | |
37 | // Default constructor. | |
38 | // | |
39 | AliDebug(AliLog::kDebug + 5, "<-"); | |
40 | AliDebug(AliLog::kDebug + 5, "->"); | |
41 | } | |
42 | //_________________________________________________________________________________________________ | |
43 | AliMixInfo::AliMixInfo(const AliMixInfo &obj) : | |
44 | TNamed(obj), | |
45 | fHistogramList(obj.fHistogramList) | |
46 | { | |
47 | // | |
48 | // Copy constructor. | |
49 | // | |
50 | AliDebug(AliLog::kDebug + 5, "<-"); | |
51 | AliDebug(AliLog::kDebug + 5, "->"); | |
52 | } | |
53 | //_________________________________________________________________________________________________ | |
54 | AliMixInfo::~AliMixInfo() | |
55 | { | |
56 | // | |
57 | // Destructor | |
58 | // | |
59 | } | |
60 | ||
61 | //_________________________________________________________________________________________________ | |
62 | void AliMixInfo::CreateHistogram(AliMixInfo::EInfoHistorgramType type, Int_t nbins, Int_t min, Int_t max) | |
63 | { | |
64 | // | |
65 | // Create mix info histograms | |
66 | // | |
67 | if (!fHistogramList) { | |
68 | fHistogramList = new TList; | |
69 | fHistogramList->SetOwner(kTRUE); | |
70 | } | |
71 | TH1I *hist = (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(type)); | |
72 | if (hist) return; | |
73 | hist = new TH1I(GetNameHistogramByType(type), GetTitleHistogramByType(type), nbins, min, max); | |
74 | fHistogramList->Add(hist); | |
75 | } | |
76 | ||
77 | //_________________________________________________________________________________________________ | |
78 | void AliMixInfo::FillHistogram(AliMixInfo::EInfoHistorgramType type, Int_t value) | |
79 | { | |
80 | // | |
81 | // Create mix info histograms | |
82 | // | |
83 | if (type == kMixedEvents && value < 0) return; | |
84 | if (!fHistogramList) { | |
85 | AliError("fHistogramList is null"); | |
86 | return; | |
87 | } | |
88 | TH1I *hist = (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(type)); | |
89 | if (hist) { | |
90 | hist->Fill(value); | |
91 | AliDebug(AliLog::kDebug, Form("%s was filled with %d sum is %.0f", GetNameHistogramByType(type), value, hist->GetBinContent(value))); | |
92 | } else { | |
93 | AliError(Form("Problem filling histogram %s", GetNameHistogramByType(type))); | |
94 | } | |
95 | } | |
96 | ||
97 | //_________________________________________________________________________________________________ | |
98 | const char *AliMixInfo::GetNameHistogramByType(Int_t index) const | |
99 | { | |
100 | // | |
101 | // Retruns name of cut | |
102 | // | |
103 | switch (index) { | |
104 | case kMainEvents: | |
105 | return "hMainEvents"; | |
106 | case kMixedEvents: | |
107 | return "hMixedEvents"; | |
108 | } | |
109 | return ""; | |
110 | } | |
111 | ||
112 | //_________________________________________________________________________________________________ | |
113 | const char *AliMixInfo::GetTitleHistogramByType(Int_t index) const | |
114 | { | |
115 | // | |
116 | // Retruns name of cut | |
117 | // | |
118 | switch (index) { | |
119 | case kMainEvents: | |
120 | return "Main Events"; | |
121 | case kMixedEvents: | |
122 | return "Mixed Events"; | |
123 | } | |
124 | return ""; | |
125 | } | |
126 | ||
127 | //_________________________________________________________________________________________________ | |
128 | void AliMixInfo::Print(Option_t *option) const | |
129 | { | |
130 | // | |
131 | // Print Mix info | |
132 | // | |
133 | if (!fHistogramList) return; | |
134 | if (option) | |
135 | AliInfo(Form("Name %s with option is %s", GetName(), option)); | |
136 | TIter next(fHistogramList); | |
137 | TH1I *h = 0; | |
138 | for (Int_t i = 0; i < fHistogramList->GetEntries(); i++) { | |
139 | h = dynamic_cast<TH1I *>(fHistogramList->At(i)); | |
140 | if (h) { | |
141 | h->Print(); | |
142 | continue; | |
143 | } | |
144 | } | |
145 | } | |
146 | //_________________________________________________________________________________________________ | |
147 | void AliMixInfo::Draw(Option_t* option) | |
148 | { | |
149 | // | |
150 | // Drwas mixi info canvas | |
151 | // | |
152 | if (!fHistogramList) return; | |
153 | ||
154 | // creating main canvas | |
155 | TCanvas *cMain = new TCanvas("cMain", "Mixing Info", 500, 500); | |
156 | if (!cMain) return; | |
157 | cMain->Divide(1, 2, 0.001, 0.001); | |
158 | cMain->cd(1); | |
159 | // TVirtualPad *upperPad = cMain->cd(1); | |
160 | // upperPad->Divide(2,1); | |
161 | // TVirtualPad *upperPad1 = gPad->cd(2); | |
162 | // upperPad1->Divide(1,2); | |
163 | // upperPad1->cd(1); | |
164 | TPavesText*text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1); | |
165 | text->SetName("mixInfoText"); | |
166 | text->AddText("Help:"); | |
167 | text->AddText("Move over histogram to see mix info for different bins"); | |
168 | text->Draw(); | |
169 | ||
170 | // gets corresponding histograms | |
171 | TH1I *hMain = GetHistogramByType(kMainEvents); | |
172 | if (!hMain) { | |
173 | AliError("hMain is null"); | |
174 | return; | |
175 | } | |
176 | TH1I *hMix = GetHistogramByType(kMixedEvents); | |
177 | if (!hMix) { | |
178 | AliError("hMix is null"); | |
179 | return; | |
180 | } | |
181 | ||
182 | ||
183 | TH2I *hMixInfo2D = 0; | |
184 | // TH1I *hOK=0,*hBad=0; | |
185 | AliMixEventPool *evPool = (AliMixEventPool *) GetEventPool("mixEventPool"); | |
186 | if (evPool) { | |
187 | Int_t mixNum = evPool->GetMixNumber(); | |
188 | // hOK = (TH1I *) hMain->Clone(); | |
189 | // hBad = (TH1I *) hMain->Clone(); | |
190 | if (!hMixInfo2D) hMixInfo2D = new TH2I("hMixInfo2D", "hMixInfo2D", hMain->GetXaxis()->GetNbins() + 1, hMain->GetXaxis()->GetXmin() - 1, hMain->GetXaxis()->GetXmax(), 1, 0, 1); | |
191 | for (Int_t iBin = 0; iBin < hMain->GetNbinsX() + 1; iBin++) { | |
192 | if (!iBin) { | |
193 | hMixInfo2D->SetBinContent(iBin + 1, 1, 1); | |
194 | } else if (!hMain->GetBinContent(iBin) && !hMix->GetBinContent(iBin)) { | |
195 | hMixInfo2D->SetBinContent(iBin + 1, 1, 2); | |
196 | } else if (hMix->GetBinContent(iBin) == mixNum * hMain->GetBinContent(iBin)) { | |
197 | hMixInfo2D->SetBinContent(iBin + 1, 1, 4); | |
198 | } else { | |
199 | hMixInfo2D->SetBinContent(iBin + 1, 1, 3); | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
204 | TStyle *style = gStyle; | |
205 | Int_t cols[4] = { kYellow, kViolet, kRed, kGreen }; | |
206 | style->SetPalette(4, cols); | |
207 | cMain->cd(2); | |
208 | hMixInfo2D->SetMaximum(4); | |
209 | hMixInfo2D->SetStats(0); | |
210 | hMixInfo2D->SetTitle(""); | |
211 | hMixInfo2D->GetXaxis()->SetNdivisions(510); | |
212 | hMixInfo2D->GetYaxis()->SetNdivisions(0); | |
213 | ||
214 | cMain->SetGrid(); | |
215 | // hMixInfo2D->SetBarWidth(1); | |
216 | // hMixInfo2D->SetLineColor(kBlack); | |
217 | // hMixInfo2D->SetLineWidth(11); | |
218 | hMixInfo2D->Draw(Form("COL %s", option)); | |
219 | // | |
220 | // TLegend *legend = new TLegend(0.55,0.65,0.76,0.82); | |
221 | // legend->AddEntry(hOK,"OK","f"); | |
222 | // legend->AddEntry(hBad,"NOT OK","f"); | |
223 | // legend->Draw(); | |
224 | ||
225 | cMain->cd(2)->AddExec("dynamic", Form("AliMixInfo::DynamicExec((AliMixInfo*)0x%lx)", (ULong_t)this)); | |
226 | } | |
227 | ||
228 | //_________________________________________________________________________________________________ | |
229 | void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo) | |
230 | { | |
231 | // | |
232 | // Function which is run when user move mouse over mix info | |
233 | // | |
234 | ||
235 | TObject *select = gPad->GetSelected(); | |
236 | if (!select) return; | |
237 | if (!select->InheritsFrom(TH2I::Class())) { | |
238 | gPad->SetUniqueID(0); | |
239 | return; | |
240 | } | |
241 | ||
242 | TH2I *hSelected = (TH2I *) select; | |
243 | gPad->GetCanvas()->FeedbackMode(kTRUE); | |
244 | ||
245 | //erase old position and draw a line at current position | |
246 | Int_t uid = gPad->GetUniqueID(); | |
247 | // int pxold = gPad->GetUniqueID(); | |
248 | Int_t px = gPad->GetEventX(); | |
249 | // Int_t py = gPad->GetEventY(); | |
250 | // float uxmin = gPad->GetUxmin(); | |
251 | // float uxmax = gPad->GetUxmax(); | |
252 | // float uymin = gPad->GetUymin(); | |
253 | // float uymax = gPad->GetUymax(); | |
254 | // Int_t pxmin = gPad->XtoAbsPixel ( uxmin ); | |
255 | // Int_t pxmax = gPad->XtoAbsPixel ( uxmax ); | |
256 | // Int_t pymin = gPad->YtoAbsPixel ( uymin ); | |
257 | // Int_t pymax = gPad->YtoAbsPixel ( uymax ); | |
258 | // // if(pxold) gVirtualX->DrawLine(pxold,pymin,pxold,pymax); | |
259 | // // else gVirtualX->DrawLine(px,pymin,px,pymax); | |
260 | // gPad->SetUniqueID ( px ); | |
261 | ||
262 | Float_t upx = gPad->AbsPixeltoX(px); | |
263 | // Float_t upy = gPad->AbsPixeltoY(py); | |
264 | ||
265 | Float_t x = gPad->PadtoX(upx); | |
266 | // Float_t y = gPad->PadtoY ( upy ); | |
267 | ||
268 | Int_t binX = hSelected->GetXaxis()->FindBin(x) - 1; | |
269 | // Int_t binY = hSelected->GetYaxis()->FindBin(y)-1; | |
270 | ||
271 | ||
272 | ||
273 | // return in case of same bin | |
274 | if (uid == binX) return; | |
275 | // Printf("%d %d",uid,binX); | |
276 | ||
277 | //create or set the new canvas cInfo | |
278 | TPaveText *text = 0; | |
279 | TVirtualPad *padsav = gPad; | |
280 | TCanvas *cInfo = (TCanvas *) gROOT->GetListOfCanvases()->FindObject("cMain"); | |
281 | if (cInfo) { | |
282 | text = (TPaveText *)cInfo->GetPrimitive("mixInfoText"); | |
283 | if (!text) { | |
284 | text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1); | |
285 | } else { | |
286 | text->DeleteText(); | |
287 | } | |
288 | ||
289 | } else cInfo = new TCanvas("cInfo", "MixInfo Canvas", 510, 0, 350, 150); | |
290 | ||
291 | TVirtualPad *upperPad = cInfo->cd(1); | |
292 | // TVirtualPad *upperPadL = upperPad->cd(1); | |
293 | // TVirtualPad *upperPadR = upperPad->cd(2); | |
294 | // TVirtualPad *upperPadR1 = upperPadR->cd(1); | |
295 | // TVirtualPad *upperPadR2 = upperPadR->cd(2); | |
296 | // TH1I *hMain = 0; | |
297 | // TH1I *hMix = 0; | |
298 | ||
299 | ||
300 | // mixInfo->Print(); | |
301 | // return; | |
302 | ||
303 | // gets corresponding histograms | |
304 | TH1I *hMain = mixInfo->GetHistogramByType(kMainEvents); | |
305 | if (!hMain) { | |
306 | Printf("hMain is null"); | |
307 | return; | |
308 | } | |
309 | TH1I *hMix = mixInfo->GetHistogramByType(kMixedEvents); | |
310 | if (!hMix) { | |
311 | Printf("hMix is null"); | |
312 | return; | |
313 | } | |
314 | ||
315 | Double_t numMain = hMain->GetBinContent(binX); | |
316 | Double_t numMix = hMix->GetBinContent(binX); | |
317 | Int_t hist2DValue = (Int_t) hSelected->GetBinContent(binX + 1, 1); | |
318 | ||
319 | Int_t mixNum = 1; | |
320 | if (text) { | |
321 | text->SetName("mixInfoText"); | |
322 | text->SetTextAlign(12); | |
323 | text->SetToolTipText("Mixing Info about current binX"); | |
324 | // text->SetTextSize(0.1); | |
325 | // text->SetTextColor(3); | |
326 | text->SetBorderSize(2); | |
327 | text->AddText(Form("binX=%d", binX)); | |
328 | text->AddText(Form("numMain=%.0f", numMain)); | |
329 | text->AddText(Form("numMix=%.0f", numMix)); | |
330 | text->AddText(Form("BINCONTENT=%d", hist2DValue)); | |
331 | ||
332 | if (mixInfo) { | |
333 | ||
334 | AliMixEventPool *evPool = (AliMixEventPool *) mixInfo->GetEventPool("mixEventPool"); | |
335 | if (evPool) { | |
336 | mixNum = evPool->GetMixNumber(); | |
337 | if (binX - 1 > 0) | |
338 | evPool->SetCutValuesFromBinIndex(binX - 1); | |
339 | TObjArray *eventCuts = evPool->GetListOfEventCuts(); | |
340 | if (eventCuts) { | |
341 | ||
342 | TObjArrayIter next(eventCuts); | |
343 | AliMixEventCutObj *cut; | |
344 | while ((cut = (AliMixEventCutObj *) next())) { | |
345 | if (hist2DValue > 1) text->AddText(Form("%s <%.2f,%.2f)", cut->GetCutName(), cut->GetMin(), cut->GetMax())); | |
346 | else text->AddText(Form("%s <Out of Range>", cut->GetCutName())); | |
347 | } | |
348 | } | |
349 | ||
350 | } | |
351 | ||
352 | } | |
353 | switch (hist2DValue) { | |
354 | case 1 : | |
355 | text->SetFillColor(kYellow); | |
356 | break; | |
357 | case 2 : | |
358 | text->SetFillColor(kViolet); | |
359 | break; | |
360 | case 3 : | |
361 | text->SetFillColor(kRed); | |
362 | break; | |
363 | case 4 : | |
364 | text->SetFillColor(kGreen); | |
365 | break; | |
366 | default: | |
367 | text->SetFillColor(kWhite); | |
368 | break; | |
369 | } | |
370 | upperPad->cd(); | |
371 | text->Draw(); | |
372 | // upperPadR1->cd(); | |
373 | // TH1D *proj1 = hSelected->ProjectionY("_xxx",binX); | |
374 | // proj1->Draw(); | |
375 | // upperPadR2->cd(); | |
376 | // TH1D *proj2 = hSelected->ProjectionY("_xxx",binX); | |
377 | // proj1->Draw(); | |
378 | ||
379 | } | |
380 | cInfo->Update(); | |
381 | padsav->cd(); | |
382 | ||
383 | gPad->SetUniqueID(binX); | |
384 | } | |
385 | ||
386 | //_________________________________________________________________________________________________ | |
387 | Long64_t AliMixInfo::Merge(TCollection *list) | |
388 | { | |
389 | // | |
390 | // Merge function | |
391 | // | |
392 | if (!list) return 0; | |
393 | TIter nxfc(list); | |
394 | AliMixInfo *mi = 0; | |
395 | Long64_t counter = 0; | |
396 | while ((mi = (AliMixInfo *) nxfc())) { | |
397 | // Do not merge with ourself | |
398 | if (mi == this) continue; | |
399 | // Make sure that it is a AliMixInfo | |
400 | if (!mi->InheritsFrom(AliMixInfo::Class())) { | |
401 | Error("Merge", "attempt to add object of class: %s to a %s", mi->ClassName(), ClassName()); | |
402 | return -1; | |
403 | } | |
404 | // Merge now | |
405 | Add(mi); | |
406 | counter++; | |
407 | } | |
408 | // Done | |
409 | return counter; | |
410 | } | |
411 | ||
412 | TH1I *AliMixInfo::GetHistogramByType(Int_t index) const | |
413 | { | |
414 | // | |
415 | // GetHistogramByType | |
416 | // | |
417 | return (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(index)); | |
418 | } | |
419 | ||
420 | //_________________________________________________________________________________________________ | |
421 | void AliMixInfo::Add(AliMixInfo *mi) | |
422 | { | |
423 | // | |
424 | // adds AliMixInfo | |
425 | // | |
426 | ||
427 | AliInfo(Form("Adding %p", mi)); | |
428 | if (!mi) return; | |
429 | if (!fHistogramList) return; | |
430 | TH1I *hMain = GetHistogramByType(kMainEvents); | |
431 | if (!hMain) { | |
432 | AliError("hMain is null"); | |
433 | return; | |
434 | } | |
435 | TH1I *hMix = GetHistogramByType(kMixedEvents); | |
436 | if (!hMix) { | |
437 | AliError("hMain is null"); | |
438 | return; | |
439 | } | |
440 | hMain->Add(mi->GetHistogramByType(kMainEvents)); | |
441 | hMix->Add(mi->GetHistogramByType(kMixedEvents)); | |
442 | } | |
443 | ||
444 | //_________________________________________________________________________________________________ | |
445 | void AliMixInfo::SetEventPool(AliMixEventPool *evPool) | |
446 | { | |
447 | // | |
448 | // Sets event pool | |
449 | // | |
450 | if (!evPool) return; | |
451 | ||
452 | if (!fHistogramList) return; | |
453 | ||
454 | fHistogramList->Add(evPool); | |
455 | } | |
456 | ||
457 | //_________________________________________________________________________________________________ | |
458 | AliMixEventPool *AliMixInfo::GetEventPool(const char *name) | |
459 | { | |
460 | // | |
461 | // Gets event pool | |
462 | // | |
463 | if (!fHistogramList) return 0; | |
464 | ||
465 | return (AliMixEventPool *) fHistogramList->FindObject(name); | |
466 | } | |
467 |