]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVENTMIX/AliMixInfo.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / EVENTMIX / AliMixInfo.cxx
CommitLineData
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
29ClassImp(AliMixInfo)
30
31//_________________________________________________________________________________________________
32AliMixInfo::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//_________________________________________________________________________________________________
43AliMixInfo::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//_________________________________________________________________________________________________
54AliMixInfo::~AliMixInfo()
55{
56 //
57 // Destructor
58 //
59}
60
61//_________________________________________________________________________________________________
62void 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//_________________________________________________________________________________________________
78void 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//_________________________________________________________________________________________________
98const 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//_________________________________________________________________________________________________
113const 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//_________________________________________________________________________________________________
128void 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//_________________________________________________________________________________________________
35e08f92 147void AliMixInfo::Draw(Option_t *option)
b425275c 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);
35e08f92 164 TPavesText *text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1);
b425275c 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();
150506ac 188 Int_t bufferSize = evPool->GetBufferSize();
b425275c 189// hOK = (TH1I *) hMain->Clone();
190// hBad = (TH1I *) hMain->Clone();
191 if (!hMixInfo2D) hMixInfo2D = new TH2I("hMixInfo2D", "hMixInfo2D", hMain->GetXaxis()->GetNbins() + 1, hMain->GetXaxis()->GetXmin() - 1, hMain->GetXaxis()->GetXmax(), 1, 0, 1);
192 for (Int_t iBin = 0; iBin < hMain->GetNbinsX() + 1; iBin++) {
193 if (!iBin) {
194 hMixInfo2D->SetBinContent(iBin + 1, 1, 1);
195 } else if (!hMain->GetBinContent(iBin) && !hMix->GetBinContent(iBin)) {
196 hMixInfo2D->SetBinContent(iBin + 1, 1, 2);
150506ac 197 } else if (hMix->GetBinContent(iBin) == mixNum * bufferSize * hMain->GetBinContent(iBin)) {
b425275c 198 hMixInfo2D->SetBinContent(iBin + 1, 1, 4);
199 } else {
200 hMixInfo2D->SetBinContent(iBin + 1, 1, 3);
201 }
202 }
203 }
204
205 TStyle *style = gStyle;
206 Int_t cols[4] = { kYellow, kViolet, kRed, kGreen };
207 style->SetPalette(4, cols);
208 cMain->cd(2);
781b6757 209// cMain->SetGrid();
a86b14f8 210 if (hMixInfo2D) {
211 hMixInfo2D->SetMaximum(4);
212 hMixInfo2D->SetStats(0);
213 hMixInfo2D->SetTitle("");
214 hMixInfo2D->GetXaxis()->SetNdivisions(510);
215 hMixInfo2D->GetYaxis()->SetNdivisions(0);
781b6757 216 }
b425275c 217
781b6757 218 if (hMixInfo2D) hMixInfo2D->Draw(Form("COL %s", option));
b425275c 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//_________________________________________________________________________________________________
229void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo)
230{
231 //
232 // Function which is run when user move mouse over mix info
233 //
234
a86b14f8 235 if (!mixInfo) return;
781b6757 236
b425275c 237 TObject *select = gPad->GetSelected();
238 if (!select) return;
239 if (!select->InheritsFrom(TH2I::Class())) {
240 gPad->SetUniqueID(0);
241 return;
242 }
243
244 TH2I *hSelected = (TH2I *) select;
245 gPad->GetCanvas()->FeedbackMode(kTRUE);
246
247 //erase old position and draw a line at current position
248 Int_t uid = gPad->GetUniqueID();
249// int pxold = gPad->GetUniqueID();
250 Int_t px = gPad->GetEventX();
251// Int_t py = gPad->GetEventY();
252// float uxmin = gPad->GetUxmin();
253// float uxmax = gPad->GetUxmax();
254// float uymin = gPad->GetUymin();
255// float uymax = gPad->GetUymax();
256 // Int_t pxmin = gPad->XtoAbsPixel ( uxmin );
257 // Int_t pxmax = gPad->XtoAbsPixel ( uxmax );
258 // Int_t pymin = gPad->YtoAbsPixel ( uymin );
259 // Int_t pymax = gPad->YtoAbsPixel ( uymax );
260// // if(pxold) gVirtualX->DrawLine(pxold,pymin,pxold,pymax);
261// // else gVirtualX->DrawLine(px,pymin,px,pymax);
262// gPad->SetUniqueID ( px );
263
264 Float_t upx = gPad->AbsPixeltoX(px);
265// Float_t upy = gPad->AbsPixeltoY(py);
266
267 Float_t x = gPad->PadtoX(upx);
268// Float_t y = gPad->PadtoY ( upy );
269
270 Int_t binX = hSelected->GetXaxis()->FindBin(x) - 1;
271// Int_t binY = hSelected->GetYaxis()->FindBin(y)-1;
272
273
274
275 // return in case of same bin
276 if (uid == binX) return;
277// Printf("%d %d",uid,binX);
278
279 //create or set the new canvas cInfo
280 TPaveText *text = 0;
281 TVirtualPad *padsav = gPad;
282 TCanvas *cInfo = (TCanvas *) gROOT->GetListOfCanvases()->FindObject("cMain");
283 if (cInfo) {
284 text = (TPaveText *)cInfo->GetPrimitive("mixInfoText");
285 if (!text) {
286 text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1);
287 } else {
288 text->DeleteText();
289 }
290
291 } else cInfo = new TCanvas("cInfo", "MixInfo Canvas", 510, 0, 350, 150);
292
293 TVirtualPad *upperPad = cInfo->cd(1);
294// TVirtualPad *upperPadL = upperPad->cd(1);
295// TVirtualPad *upperPadR = upperPad->cd(2);
296// TVirtualPad *upperPadR1 = upperPadR->cd(1);
297// TVirtualPad *upperPadR2 = upperPadR->cd(2);
298// TH1I *hMain = 0;
299// TH1I *hMix = 0;
300
301
302// mixInfo->Print();
303// return;
304
305 // gets corresponding histograms
306 TH1I *hMain = mixInfo->GetHistogramByType(kMainEvents);
307 if (!hMain) {
308 Printf("hMain is null");
309 return;
310 }
311 TH1I *hMix = mixInfo->GetHistogramByType(kMixedEvents);
312 if (!hMix) {
313 Printf("hMix is null");
314 return;
315 }
316
317 Double_t numMain = hMain->GetBinContent(binX);
318 Double_t numMix = hMix->GetBinContent(binX);
319 Int_t hist2DValue = (Int_t) hSelected->GetBinContent(binX + 1, 1);
320
3bcab622 321// Int_t mixNum = 1;
b425275c 322 if (text) {
b425275c 323 if (mixInfo) {
b425275c 324 AliMixEventPool *evPool = (AliMixEventPool *) mixInfo->GetEventPool("mixEventPool");
325 if (evPool) {
3bcab622 326// mixNum = evPool->GetMixNumber();
a9439e6d 327 if (binX - 1 >= 0) {
328 if (!evPool->SetCutValuesFromBinIndex(binX - 1)) return;
a9439e6d 329 }
330 text->SetName("mixInfoText");
331 text->SetTextAlign(12);
332 text->SetToolTipText("Mixing Info about current binX");
333 text->SetBorderSize(2);
334 text->AddText(Form("binX=%d", binX));
335 text->AddText(Form("numMain=%.0f", numMain));
336 text->AddText(Form("numMix=%.0f", numMix));
337 text->AddText(Form("BINCONTENT=%d", hist2DValue));
b425275c 338 TObjArray *eventCuts = evPool->GetListOfEventCuts();
339 if (eventCuts) {
b425275c 340 TObjArrayIter next(eventCuts);
341 AliMixEventCutObj *cut;
342 while ((cut = (AliMixEventCutObj *) next())) {
286cc142 343 if (hist2DValue > 1) text->AddText(Form("%s <%.2f,%.2f)", cut->GetCutName(), cut->GetCurrentMin(), cut->GetCurrentMax()));
b425275c 344 else text->AddText(Form("%s <Out of Range>", cut->GetCutName()));
345 }
346 }
b425275c 347 }
b425275c 348 }
349 switch (hist2DValue) {
350 case 1 :
351 text->SetFillColor(kYellow);
352 break;
353 case 2 :
354 text->SetFillColor(kViolet);
355 break;
356 case 3 :
357 text->SetFillColor(kRed);
358 break;
359 case 4 :
360 text->SetFillColor(kGreen);
361 break;
362 default:
363 text->SetFillColor(kWhite);
364 break;
365 }
366 upperPad->cd();
367 text->Draw();
368// upperPadR1->cd();
369// TH1D *proj1 = hSelected->ProjectionY("_xxx",binX);
370// proj1->Draw();
371// upperPadR2->cd();
372// TH1D *proj2 = hSelected->ProjectionY("_xxx",binX);
373// proj1->Draw();
374
375 }
376 cInfo->Update();
377 padsav->cd();
378
379 gPad->SetUniqueID(binX);
380}
381
382//_________________________________________________________________________________________________
383Long64_t AliMixInfo::Merge(TCollection *list)
384{
385 //
386 // Merge function
387 //
388 if (!list) return 0;
389 TIter nxfc(list);
390 AliMixInfo *mi = 0;
391 Long64_t counter = 0;
392 while ((mi = (AliMixInfo *) nxfc())) {
393 // Do not merge with ourself
394 if (mi == this) continue;
395 // Make sure that it is a AliMixInfo
396 if (!mi->InheritsFrom(AliMixInfo::Class())) {
397 Error("Merge", "attempt to add object of class: %s to a %s", mi->ClassName(), ClassName());
398 return -1;
399 }
400 // Merge now
401 Add(mi);
402 counter++;
403 }
404 // Done
405 return counter;
406}
407
408TH1I *AliMixInfo::GetHistogramByType(Int_t index) const
409{
410 //
411 // GetHistogramByType
412 //
413 return (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(index));
414}
415
416//_________________________________________________________________________________________________
417void AliMixInfo::Add(AliMixInfo *mi)
418{
419 //
420 // adds AliMixInfo
421 //
422
62e756a5 423// AliInfo(Form("Adding %p", mi));
b425275c 424 if (!mi) return;
425 if (!fHistogramList) return;
426 TH1I *hMain = GetHistogramByType(kMainEvents);
427 if (!hMain) {
428 AliError("hMain is null");
429 return;
430 }
431 TH1I *hMix = GetHistogramByType(kMixedEvents);
432 if (!hMix) {
433 AliError("hMain is null");
434 return;
435 }
436 hMain->Add(mi->GetHistogramByType(kMainEvents));
437 hMix->Add(mi->GetHistogramByType(kMixedEvents));
438}
439
440//_________________________________________________________________________________________________
441void AliMixInfo::SetEventPool(AliMixEventPool *evPool)
442{
443 //
444 // Sets event pool
445 //
446 if (!evPool) return;
447
448 if (!fHistogramList) return;
449
450 fHistogramList->Add(evPool);
451}
452
453//_________________________________________________________________________________________________
454AliMixEventPool *AliMixInfo::GetEventPool(const char *name)
455{
456 //
457 // Gets event pool
458 //
459 if (!fHistogramList) return 0;
460
461 return (AliMixEventPool *) fHistogramList->FindObject(name);
462}
463