4 // AliMixInfo object contains information about one cut on for event mixing
5 // available for users containing mixing information
8 // Martin Vala (martin.vala@cern.ch)
20 #include <TPavesText.h>
25 #include "AliMixInfo.h"
26 #include "AliMixEventPool.h"
27 #include "AliMixEventCutObj.h"
31 //_________________________________________________________________________________________________
32 AliMixInfo::AliMixInfo(const char *name, const char *title) :
37 // Default constructor.
39 AliDebug(AliLog::kDebug + 5, "<-");
40 AliDebug(AliLog::kDebug + 5, "->");
42 //_________________________________________________________________________________________________
43 AliMixInfo::AliMixInfo(const AliMixInfo &obj) :
45 fHistogramList(obj.fHistogramList)
50 AliDebug(AliLog::kDebug + 5, "<-");
51 AliDebug(AliLog::kDebug + 5, "->");
53 //_________________________________________________________________________________________________
54 AliMixInfo::~AliMixInfo()
61 //_________________________________________________________________________________________________
62 void AliMixInfo::CreateHistogram(AliMixInfo::EInfoHistorgramType type, Int_t nbins, Int_t min, Int_t max)
65 // Create mix info histograms
67 if (!fHistogramList) {
68 fHistogramList = new TList;
69 fHistogramList->SetOwner(kTRUE);
71 TH1I *hist = (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(type));
73 hist = new TH1I(GetNameHistogramByType(type), GetTitleHistogramByType(type), nbins, min, max);
74 fHistogramList->Add(hist);
77 //_________________________________________________________________________________________________
78 void AliMixInfo::FillHistogram(AliMixInfo::EInfoHistorgramType type, Int_t value)
81 // Create mix info histograms
83 if (type == kMixedEvents && value < 0) return;
84 if (!fHistogramList) {
85 AliError("fHistogramList is null");
88 TH1I *hist = (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(type));
91 AliDebug(AliLog::kDebug, Form("%s was filled with %d sum is %.0f", GetNameHistogramByType(type), value, hist->GetBinContent(value)));
93 AliError(Form("Problem filling histogram %s", GetNameHistogramByType(type)));
97 //_________________________________________________________________________________________________
98 const char *AliMixInfo::GetNameHistogramByType(Int_t index) const
101 // Retruns name of cut
105 return "hMainEvents";
107 return "hMixedEvents";
112 //_________________________________________________________________________________________________
113 const char *AliMixInfo::GetTitleHistogramByType(Int_t index) const
116 // Retruns name of cut
120 return "Main Events";
122 return "Mixed Events";
127 //_________________________________________________________________________________________________
128 void AliMixInfo::Print(Option_t *option) const
133 if (!fHistogramList) return;
135 AliInfo(Form("Name %s with option is %s", GetName(), option));
136 TIter next(fHistogramList);
138 for (Int_t i = 0; i < fHistogramList->GetEntries(); i++) {
139 h = dynamic_cast<TH1I *>(fHistogramList->At(i));
146 //_________________________________________________________________________________________________
147 void AliMixInfo::Draw(Option_t* option)
150 // Drwas mixi info canvas
152 if (!fHistogramList) return;
154 // creating main canvas
155 TCanvas *cMain = new TCanvas("cMain", "Mixing Info", 500, 500);
157 cMain->Divide(1, 2, 0.001, 0.001);
159 // TVirtualPad *upperPad = cMain->cd(1);
160 // upperPad->Divide(2,1);
161 // TVirtualPad *upperPad1 = gPad->cd(2);
162 // upperPad1->Divide(1,2);
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");
170 // gets corresponding histograms
171 TH1I *hMain = GetHistogramByType(kMainEvents);
173 AliError("hMain is null");
176 TH1I *hMix = GetHistogramByType(kMixedEvents);
178 AliError("hMix is null");
183 TH2I *hMixInfo2D = 0;
184 // TH1I *hOK=0,*hBad=0;
185 AliMixEventPool *evPool = (AliMixEventPool *) GetEventPool("mixEventPool");
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++) {
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);
199 hMixInfo2D->SetBinContent(iBin + 1, 1, 3);
204 TStyle *style = gStyle;
205 Int_t cols[4] = { kYellow, kViolet, kRed, kGreen };
206 style->SetPalette(4, cols);
210 hMixInfo2D->SetMaximum(4);
211 hMixInfo2D->SetStats(0);
212 hMixInfo2D->SetTitle("");
213 hMixInfo2D->GetXaxis()->SetNdivisions(510);
214 hMixInfo2D->GetYaxis()->SetNdivisions(0);
217 if (hMixInfo2D) hMixInfo2D->Draw(Form("COL %s", option));
219 // TLegend *legend = new TLegend(0.55,0.65,0.76,0.82);
220 // legend->AddEntry(hOK,"OK","f");
221 // legend->AddEntry(hBad,"NOT OK","f");
224 cMain->cd(2)->AddExec("dynamic", Form("AliMixInfo::DynamicExec((AliMixInfo*)0x%lx)", (ULong_t)this));
227 //_________________________________________________________________________________________________
228 void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo)
231 // Function which is run when user move mouse over mix info
234 if (!mixInfo) return;
236 TObject *select = gPad->GetSelected();
238 if (!select->InheritsFrom(TH2I::Class())) {
239 gPad->SetUniqueID(0);
243 TH2I *hSelected = (TH2I *) select;
244 gPad->GetCanvas()->FeedbackMode(kTRUE);
246 //erase old position and draw a line at current position
247 Int_t uid = gPad->GetUniqueID();
248 // int pxold = gPad->GetUniqueID();
249 Int_t px = gPad->GetEventX();
250 // Int_t py = gPad->GetEventY();
251 // float uxmin = gPad->GetUxmin();
252 // float uxmax = gPad->GetUxmax();
253 // float uymin = gPad->GetUymin();
254 // float uymax = gPad->GetUymax();
255 // Int_t pxmin = gPad->XtoAbsPixel ( uxmin );
256 // Int_t pxmax = gPad->XtoAbsPixel ( uxmax );
257 // Int_t pymin = gPad->YtoAbsPixel ( uymin );
258 // Int_t pymax = gPad->YtoAbsPixel ( uymax );
259 // // if(pxold) gVirtualX->DrawLine(pxold,pymin,pxold,pymax);
260 // // else gVirtualX->DrawLine(px,pymin,px,pymax);
261 // gPad->SetUniqueID ( px );
263 Float_t upx = gPad->AbsPixeltoX(px);
264 // Float_t upy = gPad->AbsPixeltoY(py);
266 Float_t x = gPad->PadtoX(upx);
267 // Float_t y = gPad->PadtoY ( upy );
269 Int_t binX = hSelected->GetXaxis()->FindBin(x) - 1;
270 // Int_t binY = hSelected->GetYaxis()->FindBin(y)-1;
274 // return in case of same bin
275 if (uid == binX) return;
276 // Printf("%d %d",uid,binX);
278 //create or set the new canvas cInfo
280 TVirtualPad *padsav = gPad;
281 TCanvas *cInfo = (TCanvas *) gROOT->GetListOfCanvases()->FindObject("cMain");
283 text = (TPaveText *)cInfo->GetPrimitive("mixInfoText");
285 text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1);
290 } else cInfo = new TCanvas("cInfo", "MixInfo Canvas", 510, 0, 350, 150);
292 TVirtualPad *upperPad = cInfo->cd(1);
293 // TVirtualPad *upperPadL = upperPad->cd(1);
294 // TVirtualPad *upperPadR = upperPad->cd(2);
295 // TVirtualPad *upperPadR1 = upperPadR->cd(1);
296 // TVirtualPad *upperPadR2 = upperPadR->cd(2);
304 // gets corresponding histograms
305 TH1I *hMain = mixInfo->GetHistogramByType(kMainEvents);
307 Printf("hMain is null");
310 TH1I *hMix = mixInfo->GetHistogramByType(kMixedEvents);
312 Printf("hMix is null");
316 Double_t numMain = hMain->GetBinContent(binX);
317 Double_t numMix = hMix->GetBinContent(binX);
318 Int_t hist2DValue = (Int_t) hSelected->GetBinContent(binX + 1, 1);
322 text->SetName("mixInfoText");
323 text->SetTextAlign(12);
324 text->SetToolTipText("Mixing Info about current binX");
325 // text->SetTextSize(0.1);
326 // text->SetTextColor(3);
327 text->SetBorderSize(2);
328 text->AddText(Form("binX=%d", binX));
329 text->AddText(Form("numMain=%.0f", numMain));
330 text->AddText(Form("numMix=%.0f", numMix));
331 text->AddText(Form("BINCONTENT=%d", hist2DValue));
335 AliMixEventPool *evPool = (AliMixEventPool *) mixInfo->GetEventPool("mixEventPool");
337 mixNum = evPool->GetMixNumber();
339 evPool->SetCutValuesFromBinIndex(binX - 1);
340 TObjArray *eventCuts = evPool->GetListOfEventCuts();
343 TObjArrayIter next(eventCuts);
344 AliMixEventCutObj *cut;
345 while ((cut = (AliMixEventCutObj *) next())) {
346 if (hist2DValue > 1) text->AddText(Form("%s <%.2f,%.2f)", cut->GetCutName(), cut->GetMin(), cut->GetMax()));
347 else text->AddText(Form("%s <Out of Range>", cut->GetCutName()));
354 switch (hist2DValue) {
356 text->SetFillColor(kYellow);
359 text->SetFillColor(kViolet);
362 text->SetFillColor(kRed);
365 text->SetFillColor(kGreen);
368 text->SetFillColor(kWhite);
374 // TH1D *proj1 = hSelected->ProjectionY("_xxx",binX);
377 // TH1D *proj2 = hSelected->ProjectionY("_xxx",binX);
384 gPad->SetUniqueID(binX);
387 //_________________________________________________________________________________________________
388 Long64_t AliMixInfo::Merge(TCollection *list)
396 Long64_t counter = 0;
397 while ((mi = (AliMixInfo *) nxfc())) {
398 // Do not merge with ourself
399 if (mi == this) continue;
400 // Make sure that it is a AliMixInfo
401 if (!mi->InheritsFrom(AliMixInfo::Class())) {
402 Error("Merge", "attempt to add object of class: %s to a %s", mi->ClassName(), ClassName());
413 TH1I *AliMixInfo::GetHistogramByType(Int_t index) const
416 // GetHistogramByType
418 return (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(index));
421 //_________________________________________________________________________________________________
422 void AliMixInfo::Add(AliMixInfo *mi)
428 // AliInfo(Form("Adding %p", mi));
430 if (!fHistogramList) return;
431 TH1I *hMain = GetHistogramByType(kMainEvents);
433 AliError("hMain is null");
436 TH1I *hMix = GetHistogramByType(kMixedEvents);
438 AliError("hMain is null");
441 hMain->Add(mi->GetHistogramByType(kMainEvents));
442 hMix->Add(mi->GetHistogramByType(kMixedEvents));
445 //_________________________________________________________________________________________________
446 void AliMixInfo::SetEventPool(AliMixEventPool *evPool)
453 if (!fHistogramList) return;
455 fHistogramList->Add(evPool);
458 //_________________________________________________________________________________________________
459 AliMixEventPool *AliMixInfo::GetEventPool(const char *name)
464 if (!fHistogramList) return 0;
466 return (AliMixEventPool *) fHistogramList->FindObject(name);