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 //==================================================================
45 AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::MakeHistograms(const
53 if (axis->IsVariableBinSize()) {
54 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
55 axis->GetXbins()->fN, axis->GetXbins()->fArray);
56 fCut = new TH1F(Form("c_%s", GetName()),
57 Form("%s restricted spectra", GetName()),
58 axis->GetXbins()->fN, axis->GetXbins()->fArray);
61 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
62 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
63 fCut = new TH1F(Form("c_%s", GetName()),
64 Form("%s restricted spectra", GetName()),
65 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
67 fFull->SetFillColor(kRed);
68 fFull->SetFillStyle(3001);
69 fCut->SetFillColor(kBlue);
70 fCut->SetFillStyle(3001);
72 //__________________________________________________________________
73 void AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::DoFill(Double_t v)
75 // Fill into histograms
76 if (fFull) fFull->Fill(v);
78 //__________________________________________________________________
79 void AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::Show(Option_t* option,
80 Double_t l, Double_t h)
85 gPad->SetLogy(fFull->GetMaximum() > 10);
87 Double_t lx = fFull->GetXaxis()->GetXmin();
88 Double_t hx = fFull->GetXaxis()->GetXmax();
89 Double_t rr = (hx-lx);
90 Double_t ll = rr * l + lx;
91 Double_t hh = rr * h + lx;
92 for (Int_t i = 1; i <= fFull->GetNbinsX(); i++) {
93 if (fFull->GetBinCenter(i) <= ll ||
94 fFull->GetBinCenter(i) > hh) {
95 fCut->SetBinContent(i, 0);
98 fCut->SetBinContent(i, fFull->GetBinContent(i));
100 fCut->Draw(Form("%s same", option));
103 //__________________________________________________________________
105 AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::Compare(const TObject*) const
111 //==================================================================
112 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::AliFMDSpectraDisplayTop(TGCompositeFrame& frame,
114 : AliFMDSpectraDisplayElement("All", "Everything"),
115 fHints(kLHintsExpandX|kLHintsExpandY,3, 3, 3, 3),
116 fContainer(&frame, 200, 350),
117 fList(&fContainer, kHorizontalFrame),
121 fkHist1DIcon(gClient->GetPicture("h1_t.xpm")),
122 fkHist2DIcon(gClient->GetPicture("h2_t.xpm")),
123 fkHist3DIcon(gClient->GetPicture("h3_t.xpm")),
124 fkGraphIcon(gClient->GetPicture("graph.xpm")),
126 fEntry(*(fList.AddItem(0, GetName(), this)))
130 // frame PArent frame
131 // canvas Canvas to draw in
132 fContainer.AddFrame(&fList, &fHints);
133 frame.AddFrame(&fContainer, &fHints);
135 fList.Connect("Clicked(TGListTreeItem*,Int_t)",
136 "AliFMDSpectraDisplay::AliFMDSpectraDisplayTop", this,
137 "HandleEntry(TGListTreeItem*,Int_t)");
138 fList.Connect("KeyPressed(TGListTreeItem*,ULong_t,ULong_t)",
139 "AliFMDSpectraDisplay::AliFMDSpectraDisplayTop", this,
140 "HandleKey(TGListTreeItem*,UInt_t,UInt_t)");
141 fList.Connect("ReturnPressed(TGListTreeItem*)",
142 "AliFMDSpectraDisplay::AliFMDSpectraDisplayTop", this,
143 "HandleReturn(TGListTreeItem*)");
145 //____________________________________________________________________
147 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::SetAxis(TAxis* axis)
149 // Set the axis of histograms
151 MakeHistograms(axis);
153 //____________________________________________________________________
155 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::ClearCanvas()
158 if (!fCanvas) return;
162 //____________________________________________________________________
164 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::ClearList()
167 fList.DeleteItem(fList.GetFirstItem());
172 //____________________________________________________________________
174 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::HandleReturn(TGListTreeItem * f)
176 // HAndle when return is pressed
178 fList.UnselectAll(kFALSE);
179 fList.SetSelected(0);
187 //____________________________________________________________________
189 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::HandleKey(TGListTreeItem * f, UInt_t keysym, UInt_t)
191 // Handle a key stroke
193 fList.UnselectAll(kFALSE);
194 fList.SetSelected(0);
197 TGListTreeItem* next = 0;
200 next = f->GetPrevSibling();
202 next = f->GetParent();
203 if (next) fList.CloseItem(next);
207 next = f->GetNextSibling();
208 if (!next && f->GetParent()) {
209 next = f->GetParent()->GetNextSibling();
210 fList.CloseItem(f->GetParent());
214 next = f->GetParent();
215 if (next) fList.CloseItem(next);
218 next = f->GetFirstChild();
219 if (next) fList.OpenItem(f);
223 next = fList.GetSelected();
226 fList.PageDown(kTRUE);
227 next = fList.GetSelected();
230 // if (next) gClient->NeedRedraw(&fList);
231 if (next && next != f) {
232 fList.ClearHighlighted();
233 fList.SetSelected(next);
236 if (next) gClient->NeedRedraw(&fList);
239 //____________________________________________________________________
241 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::HandleEntry(TGListTreeItem* entry, Int_t /*id*/)
243 // Handle selection of entries
244 TGListTreeItem* old = fCurrentEntry;
246 if (!entry->GetUserData()) return;
247 fCurrentEntry = entry;
253 if (old != fCurrentEntry && fCanvas) fCanvas->cd();
257 //____________________________________________________________________
259 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::UpdateList()
262 gClient->NeedRedraw(&fList);
265 //____________________________________________________________________
267 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::UpdateCanvas()
270 if (!fCanvas) return;
275 //____________________________________________________________________
276 TObject* AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::Current() const
278 // Get currently selected entry if any
279 if (!fCurrentEntry) return 0;
280 if (!fCurrentEntry->GetUserData()) return 0;
281 return static_cast<TObject*>(fCurrentEntry->GetUserData());
284 //__________________________________________________________________
285 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector&
286 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::GetOrAdd(UShort_t id)
288 // Get or add a sub-element
290 AliFMDSpectraDisplayDetector* d = 0;
291 if (fChildren.GetEntriesFast() <= idx ||
292 !(d = static_cast<AliFMDSpectraDisplayDetector*>(fChildren.At(idx)))) {
293 d = new AliFMDSpectraDisplayDetector(id, *this);
294 fChildren.AddAtAndExpand(d, idx);
295 // GetTop().GetList().SortChildren(&fEntry);
296 // GetTop().GetList().Sort(&(d->GetEntry()));
300 //__________________________________________________________________
302 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::Fill(UShort_t det, Char_t ring,
303 UShort_t sec, UShort_t str,
306 AliFMDSpectraDisplayDetector& d = GetOrAdd(det);
307 d.Fill(ring, sec, str, v);
310 //__________________________________________________________________
312 AliFMDSpectraDisplay::AliFMDSpectraDisplayTop::Compare(const TObject*) const
314 // Compare to another object
317 //==================================================================
318 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::AliFMDSpectraDisplayDetector(UShort_t det,
319 AliFMDSpectraDisplayTop& tree)
320 : AliFMDSpectraDisplayElement(Form("FMD%d", det), "FMD Sub-detector"),
324 fEntry(*(tree.GetList().AddItem(&(tree.GetEntry()), GetName())))
327 fEntry.SetUserData(this);
328 fEntry.SetText(GetName());
329 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
331 //__________________________________________________________________
332 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing&
333 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::GetOrAdd(Char_t id)
335 // Get or add an element
336 Int_t idx = (id == 'I' || id == 'i') ? 0 : 1;
337 AliFMDSpectraDisplayRing* r = 0;;
338 if (fChildren.GetEntriesFast() <= idx ||
339 !(r = static_cast<AliFMDSpectraDisplayRing*>(fChildren.At(idx)))) {
340 r = new AliFMDSpectraDisplayRing(id, *this);
341 fChildren.AddAtAndExpand(r, idx);
342 // GetTop().GetList().SortChildren(&fEntry);
343 // GetTop().GetList().Sort(&(r->GetEntry()));
347 //__________________________________________________________________
349 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::Fill(Char_t ring,
355 AliFMDSpectraDisplayRing& r = GetOrAdd(ring);
359 //__________________________________________________________________
361 AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::Compare(const TObject* o) const
363 // Compare to other element
364 std::cout << "Comparing detector to a " << o->ClassName() << std::endl;
365 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplayDetector::Class()) {
366 const AliFMDSpectraDisplayDetector* ro =
367 static_cast<const AliFMDSpectraDisplayDetector*>(o);
368 return (Id() < ro->Id() ? -1 :
369 Id() == ro->Id() ? 0 : 1);
373 //==================================================================
374 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::AliFMDSpectraDisplayRing(Char_t id,
375 AliFMDSpectraDisplayDetector& d)
376 : AliFMDSpectraDisplayElement(Form("FMD%d%c", d.Id(), id), "FMD Ring"),
380 fEntry(*(GetTop().GetList().AddItem(&(d.GetEntry()), GetName(), this)))
383 fEntry.SetText(GetName());
384 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
386 //__________________________________________________________________
387 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector&
388 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::GetOrAdd(UShort_t id)
390 // Get or add another element
391 AliFMDSpectraDisplaySector* s = 0;
392 if (fChildren.GetEntriesFast() <= id ||
393 !(s = static_cast<AliFMDSpectraDisplaySector*>(fChildren.At(id)))) {
394 s = new AliFMDSpectraDisplaySector(id, *this);
395 fChildren.AddAtAndExpand(s, id);
396 // GetTop().GetList().SortChildren(&fEntry);
397 // GetTop().GetList().Sort(&(s->GetEntry()));
401 //__________________________________________________________________
403 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::Fill(UShort_t sec,
408 AliFMDSpectraDisplaySector& s = GetOrAdd(sec);
412 //__________________________________________________________________
414 AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::Compare(const TObject* o) const
416 // Compare to other element
417 std::cout << "Comparing ring to a " << o->ClassName() << std::endl;
418 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplayRing::Class()) {
419 const AliFMDSpectraDisplayRing* ro =
420 static_cast<const AliFMDSpectraDisplayRing*>(o);
421 return (Id() < ro->Id() ? -1 :
422 Id() == ro->Id() ? 0 : 1);
426 //==================================================================
427 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::AliFMDSpectraDisplaySector(UShort_t id,
428 AliFMDSpectraDisplayRing& r)
429 : AliFMDSpectraDisplayElement(Form("FMD%d%c_%02d",r.DetectorId(),r.Id(),id),
434 fEntry(*(GetTop().GetList().AddItem(&(r.GetEntry()), GetName(), this)))
437 fEntry.SetText(GetName());
438 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
440 //__________________________________________________________________
441 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip&
442 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::GetOrAdd(UShort_t id)
444 // Get or add another element
445 AliFMDSpectraDisplayStrip* s = 0;
446 if (fChildren.GetEntriesFast() <= id ||
447 !(s = static_cast<AliFMDSpectraDisplayStrip*>(fChildren.At(id)))) {
448 s = new AliFMDSpectraDisplayStrip(id, *this);
449 fChildren.AddAtAndExpand(s, id);
450 // GetTop().GetList().SortChildren(&fEntry);
451 // GetTop().GetList().Sort(&(s->GetEntry()));
455 //__________________________________________________________________
457 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::Fill(UShort_t str,
461 AliFMDSpectraDisplayStrip& s = GetOrAdd(str);
465 //__________________________________________________________________
467 AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::Compare(const TObject* o) const
469 // Compare to another elemnt
470 std::cout << "Comparing sector to a " << o->ClassName() << std::endl;
471 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplaySector::Class()) {
472 const AliFMDSpectraDisplaySector* ro =
473 static_cast<const AliFMDSpectraDisplaySector*>(o);
474 return (Id() < ro->Id() ? -1 :
475 Id() == ro->Id() ? 0 : 1);
479 //==================================================================
480 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::AliFMDSpectraDisplayStrip(UShort_t id,
481 AliFMDSpectraDisplaySector& s)
482 : AliFMDSpectraDisplayElement(Form("FMD%d%c_%02d_%03d",
483 s.DetectorId(), s.RingId(),
484 s.Id(), id), "FMD Strip"),
487 fEntry(*(GetTop().GetList().AddItem(&(s.GetEntry()), GetName(), this)))
490 fEntry.SetText(GetName());
491 fEntry.SetPictures(GetTop().GetH1Pic(), GetTop().GetH1Pic());
492 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
494 //__________________________________________________________________
496 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::Fill(Double_t v)
501 //__________________________________________________________________
503 AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::Compare(const TObject* o) const
505 // Compare to another element
506 std::cout << "Comparing strip to a " << o->ClassName() << std::endl;
507 if (o->IsA() == AliFMDSpectraDisplay::AliFMDSpectraDisplayStrip::Class()) {
508 const AliFMDSpectraDisplayStrip* ro =
509 static_cast<const AliFMDSpectraDisplayStrip*>(o);
510 return (Id() < ro->Id() ? -1 :
511 Id() == ro->Id() ? 0 : 1);
516 //==================================================================
517 AliFMDSpectraDisplay::AliFMDSpectraDisplay()
519 fSelector(gClient->GetRoot(), 100, 100),
520 fTop(fSelector, fAux)
523 // AddLoad(AliFMDInput::kRaw);
527 fTop.Connect("SelectionChanged()",
528 "AliFMDSpectraDisplay", this, "HandleDraw()");
530 fSelector.MapSubwindows();
531 fSelector.Resize(fSelector.GetDefaultSize());
532 fSelector.MapWindow();
535 //__________________________________________________________________
537 AliFMDSpectraDisplay::HandleDraw()
539 // Handle draw request
540 TObject* user = fTop.Current();
541 if (!user) return kFALSE;
542 if (!user->InheritsFrom(AliFMDSpectraDisplay::AliFMDSpectraDisplayElement::Class())) {
543 Warning("HandleDraw", "%s does not inherit from Spectra::Element",
548 AliFMDSpectraDisplayElement* e
549 = static_cast<AliFMDSpectraDisplayElement*>(user);
550 e->Show("hist", fSlider->GetMinimum(), fSlider->GetMaximum());
556 //__________________________________________________________________
558 AliFMDSpectraDisplay::MakeAux()
560 // MAke auxilary canvas
561 AliFMDPattern::MakeAux();
563 fTop.SetAxis(fSpec->GetXaxis());
565 //__________________________________________________________________
567 AliFMDSpectraDisplay::DrawAux()
569 // Draw in the Aux the canvas
570 // For example draw the spectra
572 if (fTop.Current() != &fTop && HandleDraw()) return;
573 AliFMDPattern::DrawAux();
575 //__________________________________________________________________
577 AliFMDSpectraDisplay::ProcessHit(AliFMDHit* hit, TParticle* p)
580 fTop.Fill(hit->Detector(),
585 return AliFMDPattern::ProcessHit(hit, p);
587 //__________________________________________________________________
589 AliFMDSpectraDisplay::ProcessDigit(AliFMDDigit* digit)
592 fTop.Fill(digit->Detector(),
597 return AliFMDDisplay::ProcessDigit(digit);
599 //__________________________________________________________________
601 AliFMDSpectraDisplay::ProcessSDigit(AliFMDSDigit* sdigit)
603 // Process a summable digit
604 fTop.Fill(sdigit->Detector(),
609 return AliFMDDisplay::ProcessSDigit(sdigit);
611 //__________________________________________________________________
613 AliFMDSpectraDisplay::ProcessRawDigit(AliFMDDigit* digit)
615 // Process a raw digit
616 return ProcessDigit(digit);
618 //__________________________________________________________________
620 AliFMDSpectraDisplay::ProcessRecPoint(AliFMDRecPoint* recpoint)
622 // Process a rec-point
623 fTop.Fill(recpoint->Detector(),
627 recpoint->Particles());
628 return AliFMDDisplay::ProcessRecPoint(recpoint);
630 //__________________________________________________________________
632 AliFMDSpectraDisplay::ProcessESD(UShort_t det, Char_t rng, UShort_t sec,
633 UShort_t str, Float_t x, Float_t mult)
636 fTop.Fill(det, rng, sec, str, mult);
637 return AliFMDDisplay::ProcessESD(det, rng, sec, str, x, mult);
639 //__________________________________________________________________