2 //____________________________________________________________________
4 // $Id: DrawHits.C 22496 2007-11-26 13:50:44Z cholm $
6 // Script that contains a class to draw hits, using the
7 // AliFMDInputHits class in the util library.
9 // Use the script `Compile.C' to compile this class using ACLic.
11 #include <AliCDBManager.h>
12 #include <AliFMDParameters.h>
13 #include <AliFMDHit.h>
14 #include <AliFMDDigit.h>
15 #include <AliFMDSDigit.h>
16 #include <AliFMDRecPoint.h>
17 #include <AliESDFMD.h>
18 #include <AliFMDPattern.h>
19 #include <AliFMDSpectraDisplay.h>
21 #include <TDirectory.h>
22 #include <TObjArray.h>
34 #include <TGListTree.h>
37 #include <KeySymbols.h>
39 #include <RQ_OBJECT.h>
41 #define NESTED(X) AliFMDSpectraDisplay::AliFMDSpectraDisplay # X
43 //==================================================================
44 void AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::MakeHistograms(TAxis* axis)
50 if (axis->IsVariableBinSize()) {
51 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
52 axis->GetXbins()->fN, axis->GetXbins()->fArray);
53 fCut = new TH1F(Form("c_%s", GetName()),
54 Form("%s restricted spectra", GetName()),
55 axis->GetXbins()->fN, axis->GetXbins()->fArray);
58 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
59 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
60 fCut = new TH1F(Form("c_%s", GetName()),
61 Form("%s restricted spectra", GetName()),
62 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
64 fFull->SetFillColor(kRed);
65 fFull->SetFillStyle(3001);
66 fCut->SetFillColor(kBlue);
67 fCut->SetFillStyle(3001);
69 //__________________________________________________________________
70 void AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::DoFill(Double_t v)
72 // Fill into histograms
73 if (fFull) fFull->Fill(v);
75 //__________________________________________________________________
76 void AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::Show(Option_t* option,
77 Double_t l, Double_t h)
82 gPad->SetLogy(fFull->GetMaximum() > 10);
84 Double_t lx = fFull->GetXaxis()->GetXmin();
85 Double_t hx = fFull->GetXaxis()->GetXmax();
86 Double_t rr = (hx-lx);
87 Double_t ll = rr * l + lx;
88 Double_t hh = rr * h + lx;
89 for (Int_t i = 1; i <= fFull->GetNbinsX(); i++) {
90 if (fFull->GetBinCenter(i) <= ll ||
91 fFull->GetBinCenter(i) > hh) {
92 fCut->SetBinContent(i, 0);
95 fCut->SetBinContent(i, fFull->GetBinContent(i));
97 fCut->Draw(Form("%s same", option));
100 //__________________________________________________________________
102 AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::Compare(const TObject*) const
108 //==================================================================
109 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::AliFMDSpectraDisplayTop(TGCompositeFrame& frame,
111 : AliFMDSpectraDisplayElement("All", "Everything"),
112 fHints(kLHintsExpandX|kLHintsExpandY,3, 3, 3, 3),
113 fContainer(&frame, 200, 350),
114 fList(&fContainer, kHorizontalFrame),
118 fkHist1DIcon(gClient->GetPicture("h1_t.xpm")),
119 fkHist2DIcon(gClient->GetPicture("h2_t.xpm")),
120 fkHist3DIcon(gClient->GetPicture("h3_t.xpm")),
121 fkGraphIcon(gClient->GetPicture("graph.xpm")),
123 fEntry(*(fList.AddItem(0, GetName(), this)))
127 // frame PArent frame
128 // canvas Canvas to draw in
129 fContainer.AddFrame(&fList, &fHints);
130 frame.AddFrame(&fContainer, &fHints);
132 fList.Connect("Clicked(TGListTreeItem*,Int_t)",
133 "AliFMDSpectraDisplay::AliFMDSpectraDisplayTop", this,
134 "HandleEntry(TGListTreeItem*,Int_t)");
135 fList.Connect("KeyPressed(TGListTreeItem*,ULong_t,ULong_t)",
136 "AliFMDSpectraDisplay::AliFMDSpectraDisplayTop", this,
137 "HandleKey(TGListTreeItem*,UInt_t,UInt_t)");
138 fList.Connect("ReturnPressed(TGListTreeItem*)",
139 "AliFMDSpectraDisplay::AliFMDSpectraDisplayTop", this,
140 "HandleReturn(TGListTreeItem*)");
142 //____________________________________________________________________
144 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::SetAxis(TAxis* axis)
146 // Set the axis of histograms
148 MakeHistograms(axis);
150 //____________________________________________________________________
152 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::ClearCanvas()
155 if (!fCanvas) return;
159 //____________________________________________________________________
161 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::ClearList()
164 fList.DeleteItem(fList.GetFirstItem());
169 //____________________________________________________________________
171 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::HandleReturn(TGListTreeItem * f)
173 // HAndle when return is pressed
175 fList.UnselectAll(kFALSE);
176 fList.SetSelected(0);
184 //____________________________________________________________________
186 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::HandleKey(TGListTreeItem * f, UInt_t keysym, UInt_t)
188 // Handle a key stroke
190 fList.UnselectAll(kFALSE);
191 fList.SetSelected(0);
194 TGListTreeItem* next = 0;
197 next = f->GetPrevSibling();
199 next = f->GetParent();
200 if (next) fList.CloseItem(next);
204 next = f->GetNextSibling();
205 if (!next && f->GetParent()) {
206 next = f->GetParent()->GetNextSibling();
207 fList.CloseItem(f->GetParent());
211 next = f->GetParent();
212 if (next) fList.CloseItem(next);
215 next = f->GetFirstChild();
216 if (next) fList.OpenItem(f);
220 next = fList.GetSelected();
223 fList.PageDown(kTRUE);
224 next = fList.GetSelected();
227 // if (next) gClient->NeedRedraw(&fList);
228 if (next && next != f) {
229 fList.ClearHighlighted();
230 fList.SetSelected(next);
233 if (next) gClient->NeedRedraw(&fList);
236 //____________________________________________________________________
238 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::HandleEntry(TGListTreeItem* entry, Int_t /*id*/)
240 // Handle selection of entries
241 TGListTreeItem* old = fCurrentEntry;
243 if (!entry->GetUserData()) return;
244 fCurrentEntry = entry;
250 if (old != fCurrentEntry && fCanvas) fCanvas->cd();
254 //____________________________________________________________________
256 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::UpdateList()
259 gClient->NeedRedraw(&fList);
262 //____________________________________________________________________
264 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::UpdateCanvas()
267 if (!fCanvas) return;
272 //____________________________________________________________________
273 TObject* AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::Current() const
275 // Get currently selected entry if any
276 if (!fCurrentEntry) return 0;
277 if (!fCurrentEntry->GetUserData()) return 0;
278 return static_cast<TObject*>(fCurrentEntry->GetUserData());
281 //__________________________________________________________________
282 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector&
283 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::GetOrAdd(UShort_t id)
285 // Get or add a sub-element
287 AliFMDSpectraDisplayDetector* d = 0;
288 if (fChildren.GetEntriesFast() <= idx ||
289 !(d = static_cast<AliFMDSpectraDisplayDetector*>(fChildren.At(idx)))) {
290 d = new AliFMDSpectraDisplayDetector(id, *this);
291 fChildren.AddAtAndExpand(d, idx);
292 // GetTop().GetList().SortChildren(&fEntry);
293 // GetTop().GetList().Sort(&(d->GetEntry()));
297 //__________________________________________________________________
299 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::Fill(UShort_t det, Char_t ring,
300 UShort_t sec, UShort_t str,
303 AliFMDSpectraDisplayDetector& d = GetOrAdd(det);
304 d.Fill(ring, sec, str, v);
307 //__________________________________________________________________
309 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::Compare(const TObject*) const
311 // Compare to another object
314 //==================================================================
315 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::AliFMDSpectraDisplayDetector(UShort_t det,
316 AliFMDSpectraDisplayTop& tree)
317 : AliFMDSpectraDisplayElement(Form("FMD%d", det), "FMD Sub-detector"),
321 fEntry(*(tree.GetList().AddItem(&(tree.GetEntry()), GetName())))
324 fEntry.SetUserData(this);
325 fEntry.SetText(GetName());
326 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
328 //__________________________________________________________________
329 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing&
330 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::GetOrAdd(Char_t id)
332 // Get or add an element
333 Int_t idx = (id == 'I' || id == 'i') ? 0 : 1;
334 AliFMDSpectraDisplayRing* r = 0;;
335 if (fChildren.GetEntriesFast() <= idx ||
336 !(r = static_cast<AliFMDSpectraDisplayRing*>(fChildren.At(idx)))) {
337 r = new AliFMDSpectraDisplayRing(id, *this);
338 fChildren.AddAtAndExpand(r, idx);
339 // GetTop().GetList().SortChildren(&fEntry);
340 // GetTop().GetList().Sort(&(r->GetEntry()));
344 //__________________________________________________________________
346 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::Fill(Char_t ring,
352 AliFMDSpectraDisplayRing& r = GetOrAdd(ring);
356 //__________________________________________________________________
358 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::Compare(const TObject* o) const
360 // Compare to other element
361 std::cout << "Comparing detector to a " << o->ClassName() << std::endl;
362 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::Class()) {
363 const AliFMDSpectraDisplayDetector* ro =
364 static_cast<const AliFMDSpectraDisplayDetector*>(o);
365 return (Id() < ro->Id() ? -1 :
366 Id() == ro->Id() ? 0 : 1);
370 //==================================================================
371 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::AliFMDSpectraDisplayRing(Char_t id,
372 AliFMDSpectraDisplayDetector& d)
373 : AliFMDSpectraDisplayElement(Form("FMD%d%c", d.Id(), id), "FMD Ring"),
377 fEntry(*(GetTop().GetList().AddItem(&(d.GetEntry()), GetName(), this)))
380 fEntry.SetText(GetName());
381 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
383 //__________________________________________________________________
384 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector&
385 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::GetOrAdd(UShort_t id)
387 // Get or add another element
388 AliFMDSpectraDisplaySector* s = 0;
389 if (fChildren.GetEntriesFast() <= id ||
390 !(s = static_cast<AliFMDSpectraDisplaySector*>(fChildren.At(id)))) {
391 s = new AliFMDSpectraDisplaySector(id, *this);
392 fChildren.AddAtAndExpand(s, id);
393 // GetTop().GetList().SortChildren(&fEntry);
394 // GetTop().GetList().Sort(&(s->GetEntry()));
398 //__________________________________________________________________
400 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::Fill(UShort_t sec,
405 AliFMDSpectraDisplaySector& s = GetOrAdd(sec);
409 //__________________________________________________________________
411 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::Compare(const TObject* o) const
413 // Compare to other element
414 std::cout << "Comparing ring to a " << o->ClassName() << std::endl;
415 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::Class()) {
416 const AliFMDSpectraDisplayRing* ro =
417 static_cast<const AliFMDSpectraDisplayRing*>(o);
418 return (Id() < ro->Id() ? -1 :
419 Id() == ro->Id() ? 0 : 1);
423 //==================================================================
424 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::AliFMDSpectraDisplaySector(UShort_t id,
425 AliFMDSpectraDisplayRing& r)
426 : AliFMDSpectraDisplayElement(Form("FMD%d%c_%02d",r.DetectorId(),r.Id(),id),
431 fEntry(*(GetTop().GetList().AddItem(&(r.GetEntry()), GetName(), this)))
434 fEntry.SetText(GetName());
435 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
437 //__________________________________________________________________
438 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip&
439 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::GetOrAdd(UShort_t id)
441 // Get or add another element
442 AliFMDSpectraDisplayStrip* s = 0;
443 if (fChildren.GetEntriesFast() <= id ||
444 !(s = static_cast<AliFMDSpectraDisplayStrip*>(fChildren.At(id)))) {
445 s = new AliFMDSpectraDisplayStrip(id, *this);
446 fChildren.AddAtAndExpand(s, id);
447 // GetTop().GetList().SortChildren(&fEntry);
448 // GetTop().GetList().Sort(&(s->GetEntry()));
452 //__________________________________________________________________
454 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::Fill(UShort_t str,
458 AliFMDSpectraDisplayStrip& s = GetOrAdd(str);
462 //__________________________________________________________________
464 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::Compare(const TObject* o) const
466 // Compare to another elemnt
467 std::cout << "Comparing sector to a " << o->ClassName() << std::endl;
468 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::Class()) {
469 const AliFMDSpectraDisplaySector* ro =
470 static_cast<const AliFMDSpectraDisplaySector*>(o);
471 return (Id() < ro->Id() ? -1 :
472 Id() == ro->Id() ? 0 : 1);
476 //==================================================================
477 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::AliFMDSpectraDisplayStrip(UShort_t id,
478 AliFMDSpectraDisplaySector& s)
479 : AliFMDSpectraDisplayElement(Form("FMD%d%c_%02d_%03d",
480 s.DetectorId(), s.RingId(),
481 s.Id(), id), "FMD Strip"),
484 fEntry(*(GetTop().GetList().AddItem(&(s.GetEntry()), GetName(), this)))
487 fEntry.SetText(GetName());
488 fEntry.SetPictures(GetTop().GetH1Pic(), GetTop().GetH1Pic());
489 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
491 //__________________________________________________________________
493 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::Fill(Double_t v)
498 //__________________________________________________________________
500 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::Compare(const TObject* o) const
502 // Compare to another element
503 std::cout << "Comparing strip to a " << o->ClassName() << std::endl;
504 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::Class()) {
505 const AliFMDSpectraDisplayStrip* ro =
506 static_cast<const AliFMDSpectraDisplayStrip*>(o);
507 return (Id() < ro->Id() ? -1 :
508 Id() == ro->Id() ? 0 : 1);
513 //==================================================================
514 AliFMDSpectraDisplay::AliFMDSpectraDisplay()
516 fSelector(gClient->GetRoot(), 100, 100),
517 fTop(fSelector, fAux)
520 // AddLoad(AliFMDInput::kRaw);
524 fTop.Connect("SelectionChanged()",
525 "AliFMDSpectraDisplay", this, "HandleDraw()");
527 fSelector.MapSubwindows();
528 fSelector.Resize(fSelector.GetDefaultSize());
529 fSelector.MapWindow();
532 //__________________________________________________________________
534 AliFMDSpectraDisplay::HandleDraw()
536 // Handle draw request
537 TObject* user = fTop.Current();
538 if (!user) return kFALSE;
539 if (!user->InheritsFrom(AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::Class())) {
540 Warning("HandleDraw", "%s does not inherit from Spectra::Element",
545 AliFMDSpectraDisplayElement* e
546 = static_cast<AliFMDSpectraDisplayElement*>(user);
547 e->Show("hist", fSlider->GetMinimum(), fSlider->GetMaximum());
553 //__________________________________________________________________
555 AliFMDSpectraDisplay::MakeAux()
557 // MAke auxilary canvas
558 AliFMDPattern::MakeAux();
560 fTop.SetAxis(fSpec->GetXaxis());
562 //__________________________________________________________________
564 AliFMDSpectraDisplay::DrawAux()
566 // Draw in the Aux the canvas
567 // For example draw the spectra
569 if (fTop.Current() != &fTop && HandleDraw()) return;
570 AliFMDPattern::DrawAux();
572 //__________________________________________________________________
574 AliFMDSpectraDisplay::ProcessHit(AliFMDHit* hit, TParticle* p)
577 fTop.Fill(hit->Detector(),
582 return AliFMDPattern::ProcessHit(hit, p);
584 //__________________________________________________________________
586 AliFMDSpectraDisplay::ProcessDigit(AliFMDDigit* digit)
589 fTop.Fill(digit->Detector(),
594 return AliFMDDisplay::ProcessDigit(digit);
596 //__________________________________________________________________
598 AliFMDSpectraDisplay::ProcessSDigit(AliFMDSDigit* sdigit)
600 // Process a summable digit
601 fTop.Fill(sdigit->Detector(),
606 return AliFMDDisplay::ProcessSDigit(sdigit);
608 //__________________________________________________________________
610 AliFMDSpectraDisplay::ProcessRawDigit(AliFMDDigit* digit)
612 // Process a raw digit
613 return ProcessDigit(digit);
615 //__________________________________________________________________
617 AliFMDSpectraDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
619 // Process a rec-point
620 fTop.Fill(recpoint->Detector(),
624 recpoint->Particles());
625 return AliFMDDisplay::ProcessRecPoint(recpoint);
627 //__________________________________________________________________
629 AliFMDSpectraDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec,
630 UShort_t str, Float_t x, Float_t mult)
633 fTop.Fill(det, rng, sec, str, mult);
634 return AliFMDDisplay::ProcessESD(det, rng, sec, str, x, mult);
636 //__________________________________________________________________