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.
13 SpectraMonitor(const char* file="",
15 const char* cdbSrc="local://$ALICE_ROOT",
18 gSystem->Load("libFMDutil.so");
19 // AliLog::SetModuleDebugLevel("FMD", 8);
21 if (fname.CompareTo("help", TString::kIgnoreCase) == 0) {
22 std::cout << "Usage: RunSpectraMonitor(<src>[,<runno>[,<cdb>[,<over>]]])\n"
25 << " <src> Is a data source (online, file)\n"
26 << " <runno> Is the (optional) run number\n"
27 << " <cdb> Is the (optional) CDB storage\n"
28 << " <over> Is the (optional) over sampling rate\n\n"
29 << "Defaults are <runno>=0 and cdb=\"local://$ALICE_ROOT\"\n"
30 << "<over> allows one to override the CDB setting. Default\n"
31 << "is to use the CDB setting.\n\n"
32 << "Note: This script _must_ be compiled with ACLic"
36 AliCDBManager* cdb = AliCDBManager::Instance();
37 cdb->SetDefaultStorage(cdbSrc);
39 UInt_t what = (AliFMDParameters::kPulseGain |
40 AliFMDParameters::kPedestal |
41 AliFMDParameters::kDeadMap |
42 AliFMDParameters::kZeroSuppression|
43 AliFMDParameters::kAltroMap |
44 AliFMDParameters::kStripRange);
45 if (over != 0) what |= AliFMDParameters::kSampleRate;
46 AliFMDParameters::Instance()->Init(kFALSE, what);
47 if (over != 0) AliFMDParameters::Instance()->SetSampleRate(over);
49 AliFMDSpectraDisplay* d = new AliFMDSpectraDisplay;
50 d->AddLoad(AliFMDInput::kRaw);
56 #include <AliCDBManager.h>
57 #include <AliFMDParameters.h>
58 #include <AliFMDHit.h>
59 #include <AliFMDDigit.h>
60 #include <AliFMDSDigit.h>
61 #include <AliFMDRecPoint.h>
62 #include <AliESDFMD.h>
63 #include <AliFMDPattern.h>
65 #include <TDirectory.h>
66 #include <TObjArray.h>
78 #include <TGListTree.h>
81 #include <KeySymbols.h>
83 #include <RQ_OBJECT.h>
93 //__________________________________________________________________
94 struct Element : public TNamed
97 virtual void Draw(Option_t* option, Double_t l, Double_t h);
98 virtual Top& GetTop() = 0;
99 virtual void MakeHistograms(TAxis* axis);
101 Element(const char* name, const char* title)
102 : TNamed(name, title), fFull(0), fCut(0)
104 void DoFill(Double_t v);
109 //__________________________________________________________________
110 struct Top : public Element
112 RQ_OBJECT("Spectra::Top")
114 Top(TGCompositeFrame& frame, TCanvas* canvas);
115 TGListTree& GetList() { return fList; }
116 Detector& GetOrAdd(UShort_t id);
117 void Fill(UShort_t d, Char_t ring,
118 UShort_t sec, UShort_t str, Double_t v);
119 TAxis* GetAxis() { return fAxis; }
120 void SetAxis(TAxis* a);
121 Top& GetTop() { return *this; }
124 @param e selected entry, if any
125 @param id Id of entry */
126 virtual void HandleEntry(TGListTreeItem* e, Int_t id);
127 /** Handle key strokes
128 @param f Item selected, if any
129 @param keysym Key symbol
130 @param mask Modifier mask */
131 virtual void HandleKey(TGListTreeItem* f, UInt_t keysym, UInt_t mask);
133 @param f Selected item, if any */
134 virtual void HandleReturn(TGListTreeItem* f);
135 /** Clear the list */
136 virtual void ClearList();
137 /** Clear the canvas */
138 virtual void ClearCanvas();
140 virtual void UpdateCanvas();
142 virtual void UpdateList();
143 /** Return the currently selected entry */
144 TGListTreeItem* CurrentEntry() const { return fCurrentEntry; }
145 /** @return the currently selected user data (possibly 0) */
146 TObject* Current() const;
147 /** Selection changed signal */
148 void SelectionChanged() { Emit("SelectionChanged()"); }//*SIGNAL*
149 /** Get Picture for 1D histogram */
150 const TGPicture* GetH1Pic() { return fHist1DIcon; }
151 /** 2D Histogram Icon */
152 const TGPicture* GetH2Pic() { return fHist2DIcon; }
153 /** 3D Histogram Icon */
154 const TGPicture* GetH3Pic() { return fHist3DIcon; }
156 const TGPicture* GetGPic() { return fGraphIcon; }
157 TGListTreeItem& GetEntry() { return fEntry; }
159 TGLayoutHints fHints;
163 TGListTreeItem* fCurrentEntry;
165 /** 1D Histogram Icon */
166 const TGPicture* fHist1DIcon;
167 /** 2D Histogram Icon */
168 const TGPicture* fHist2DIcon;
169 /** 3D Histogram Icon */
170 const TGPicture* fHist3DIcon;
172 const TGPicture* fGraphIcon;
173 /** The axis to use */
176 TGListTreeItem& fEntry;
179 //__________________________________________________________________
180 struct Detector : public Element
182 Detector(UShort_t det, Top& top);
183 UShort_t Id() const { return fId; }
184 Top& GetTop() { return fParent; }
185 Top& GetParent() { return fParent; }
186 Ring& GetOrAdd(Char_t id);
187 void Fill(Char_t ring, UShort_t sec, UShort_t str, Double_t v);
188 TGListTreeItem& GetEntry() { return fEntry; }
193 TGListTreeItem& fEntry;
196 //__________________________________________________________________
197 struct Ring : public Element
199 Ring(Char_t id, Detector& d);
200 Char_t Id() const { return fId; }
201 UShort_t DetectorId() { return fParent.Id(); }
202 Top& GetTop() { return fParent.GetTop(); }
203 Detector& GetDetector() { return GetParent(); }
204 Detector& GetParent() { return fParent; }
205 Sector& GetOrAdd(UShort_t id);
206 void Fill(UShort_t sec, UShort_t str, Double_t v);
207 TGListTreeItem& GetEntry() { return fEntry; }
212 TGListTreeItem& fEntry;
215 //__________________________________________________________________
216 struct Sector : public Element
218 Sector(UShort_t id, Ring& r);
219 UShort_t Id() const { return fId; }
220 UShort_t DetectorId() { return fParent.DetectorId(); }
221 Char_t RingId() { return fParent.Id(); }
222 Top& GetTop() { return fParent.GetTop(); }
223 Detector& GetDetector() { return fParent.GetDetector(); }
224 Ring& GetRing() { return fParent; }
225 Ring& GetParent() { return fParent; }
226 Strip& GetOrAdd(UShort_t id);
227 void Fill(UShort_t str, Double_t v);
228 TGListTreeItem& GetEntry() { return fEntry; }
233 TGListTreeItem& fEntry;
236 //__________________________________________________________________
237 struct Strip : public Element
239 Strip(UShort_t id, Sector& s);
240 UShort_t Id() const { return fId; }
241 UShort_t DetectorId() { return fParent.DetectorId(); }
242 Char_t RingId() { return fParent.RingId(); }
243 UShort_t SectorId() { return fParent.Id(); }
244 Top& GetTop() { return fParent.GetTop(); }
245 Detector& GetDetector() { return fParent.GetDetector(); }
246 Ring& GetRing() { return fParent.GetRing(); }
247 Sector& GetSector() { return fParent; }
248 Sector& GetParent() { return fParent; }
249 void Fill(Double_t v);
250 TGListTreeItem& GetEntry() { return fEntry; }
254 TGListTreeItem& fEntry;
257 //==================================================================
258 void Element::MakeHistograms(TAxis* axis)
261 if (axis->IsVariableBinSize()) {
262 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
263 axis->GetXbins()->fN, axis->GetXbins()->fArray);
264 fCut = new TH1F(Form("c_%s", GetName()),
265 Form("%s restricted spectra", GetName()),
266 axis->GetXbins()->fN, axis->GetXbins()->fArray);
269 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
270 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
271 fCut = new TH1F(Form("c_%s", GetName()),
272 Form("%s restricted spectra", GetName()),
273 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
275 fFull->SetFillColor(kRed);
276 fFull->SetFillStyle(3001);
277 fCut->SetFillColor(kBlue);
278 fCut->SetFillStyle(3001);
280 //__________________________________________________________________
281 void Element::DoFill(Double_t v)
283 if (fFull) fFull->Fill(v);
285 //__________________________________________________________________
286 void Element::Draw(Option_t* option, Double_t l, Double_t h)
289 if (fFull->GetMinimum() < 0) gPad->SetLogy(kFALSE);
291 Double_t lx = fFull->GetXaxis()->GetXmin();
292 Double_t hx = fFull->GetXaxis()->GetXmax();
293 Double_t rr = (hx-lx);
294 Double_t ll = rr * l + lx;
295 Double_t hh = rr * h + lx;
296 for (Int_t i = 1; i <= fFull->GetNbinsX(); i++) {
297 if (fFull->GetBinCenter(i) <= ll ||
298 fFull->GetBinCenter(i) > hh) {
299 fCut->SetBinContent(i, 0);
302 fCut->SetBinContent(i, fFull->GetBinContent(i));
304 fCut->Draw(Form("%s same", option));
306 //==================================================================
307 Top::Top(TGCompositeFrame& frame, TCanvas* canvas)
308 : Element("All", "Everything"),
309 fHints(kLHintsExpandX|kLHintsExpandY,3, 3, 3, 3),
310 fContainer(&frame, 200, 350),
311 fList(&fContainer, kHorizontalFrame),
315 fHist1DIcon(gClient->GetPicture("h1_t.xpm")),
316 fHist2DIcon(gClient->GetPicture("h2_t.xpm")),
317 fHist3DIcon(gClient->GetPicture("h3_t.xpm")),
318 fGraphIcon(gClient->GetPicture("graph.xpm")),
319 fEntry(*(fList.AddItem(0, GetName(), this)))
321 fContainer.AddFrame(&fList, &fHints);
322 frame.AddFrame(&fContainer, &fHints);
324 fList.Connect("Clicked(TGListTreeItem*,Int_t)", "Spectra::Top", this,
325 "HandleEntry(TGListTreeItem*,Int_t)");
326 fList.Connect("KeyPressed(TGListTreeItem*,ULong_t,ULong_t)",
327 "Spectra::Top", this,
328 "HandleKey(TGListTreeItem*,UInt_t,UInt_t)");
329 fList.Connect("ReturnPressed(TGListTreeItem*)", "Spectra::Top", this,
330 "HandleReturn(TGListTreeItem*)");
332 //____________________________________________________________________
334 Top::SetAxis(TAxis* axis)
337 MakeHistograms(axis);
339 //____________________________________________________________________
343 if (!fCanvas) return;
347 //____________________________________________________________________
351 fList.DeleteItem(fList.GetFirstItem());
356 //____________________________________________________________________
358 Top::HandleReturn(TGListTreeItem * f)
362 fList.UnselectAll(kFALSE);
363 fList.SetSelected(0);
371 //____________________________________________________________________
373 Top::HandleKey(TGListTreeItem * f, UInt_t keysym, UInt_t /*mask*/)
376 fList.UnselectAll(kFALSE);
377 fList.SetSelected(0);
380 TGListTreeItem* next = 0;
383 next = f->GetPrevSibling();
385 next = f->GetParent();
386 if (next) fList.CloseItem(next);
390 next = f->GetNextSibling();
391 if (!next && f->GetParent()) {
392 next = f->GetParent()->GetNextSibling();
393 fList.CloseItem(f->GetParent());
397 next = f->GetParent();
398 if (next) fList.CloseItem(next);
401 next = f->GetFirstChild();
402 if (next) fList.OpenItem(f);
406 next = fList.GetSelected();
409 fList.PageDown(kTRUE);
410 next = fList.GetSelected();
413 if (next) gClient->NeedRedraw(&fList);
414 if (next && next != f) {
415 fList.ClearHighlighted();
416 fList.SetSelected(next);
421 //____________________________________________________________________
423 Top::HandleEntry(TGListTreeItem* entry, Int_t /*id*/)
425 TGListTreeItem* old = fCurrentEntry;
427 if (!entry->GetUserData()) return;
428 fCurrentEntry = entry;
434 if (old != fCurrentEntry && fCanvas) fCanvas->cd();
438 //____________________________________________________________________
442 gClient->NeedRedraw(&fList);
445 //____________________________________________________________________
449 if (!fCanvas) return;
454 //____________________________________________________________________
455 TObject* Top::Current() const
457 if (!fCurrentEntry) return 0;
458 if (!fCurrentEntry->GetUserData()) return 0;
459 return static_cast<TObject*>(fCurrentEntry->GetUserData());
462 //__________________________________________________________________
463 Detector& Top::GetOrAdd(UShort_t id)
467 if (fChildren.GetEntriesFast() <= idx ||
468 !(d = static_cast<Detector*>(fChildren.At(idx)))) {
469 d = new Detector(id, *this);
470 fChildren.AddAtAndExpand(d, idx);
471 // fList.SortChildren(&fEntry);
475 //__________________________________________________________________
476 void Top::Fill(UShort_t det, Char_t ring,
477 UShort_t sec, UShort_t str, Double_t v)
479 Detector& d = GetOrAdd(det);
480 d.Fill(ring, sec, str, v);
483 //==================================================================
484 Detector::Detector(UShort_t det, Top& tree)
485 : Element(Form("FMD%d", det), "FMD Sub-detector"),
489 fEntry(*(tree.GetList().AddItem(&(tree.GetEntry()), GetName())))
491 fEntry.SetUserData(this);
492 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
494 //__________________________________________________________________
495 Ring& Detector::GetOrAdd(Char_t id)
497 Int_t idx = (id == 'I' || id == 'i') ? 0 : 1;
499 if (fChildren.GetEntriesFast() <= idx ||
500 !(r = static_cast<Ring*>(fChildren.At(idx)))) {
501 r = new Ring(id, *this);
502 fChildren.AddAtAndExpand(r, idx);
503 // GetTop().GetList().SortChildren(&fEntry);
507 //__________________________________________________________________
508 void Detector::Fill(Char_t ring, UShort_t sec, UShort_t str, Double_t v)
510 Ring& r = GetOrAdd(ring);
514 //==================================================================
515 Ring::Ring(Char_t id, Detector& d)
516 : Element(Form("FMD%d%c", d.Id(), id), "FMD Ring"),
520 fEntry(*(GetTop().GetList().AddItem(&(d.GetEntry()), GetName(), this)))
522 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
524 //__________________________________________________________________
525 Sector& Ring::GetOrAdd(UShort_t id)
528 if (fChildren.GetEntriesFast() <= id ||
529 !(s = static_cast<Sector*>(fChildren.At(id)))) {
530 s = new Sector(id, *this);
531 fChildren.AddAtAndExpand(s, id);
532 // GetTop().GetList().SortChildren(&fEntry);
536 //__________________________________________________________________
537 void Ring::Fill(UShort_t sec, UShort_t str, Double_t v)
539 Sector& s = GetOrAdd(sec);
543 //==================================================================
544 Sector::Sector(UShort_t id, Ring& r)
545 : Element(Form("FMD%d%c_%02d", r.DetectorId(), r.Id(), id), "FMD Sector"),
549 fEntry(*(GetTop().GetList().AddItem(&(r.GetEntry()), GetName(), this)))
551 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
553 //__________________________________________________________________
554 Strip& Sector::GetOrAdd(UShort_t id)
557 if (fChildren.GetEntriesFast() <= id ||
558 !(s = static_cast<Strip*>(fChildren.At(id)))) {
559 s = new Strip(id, *this);
560 fChildren.AddAtAndExpand(s, id);
561 // GetTop().GetList().SortChildren(&fEntry);
565 //__________________________________________________________________
566 void Sector::Fill(UShort_t str, Double_t v)
568 Strip& s = GetOrAdd(str);
572 //==================================================================
573 Strip::Strip(UShort_t id, Sector& s)
574 : Element(Form("FMD%d%c_%02d_%03d", s.DetectorId(), s.RingId(),
575 s.Id(), id), "FMD Strip"),
578 fEntry(*(GetTop().GetList().AddItem(&(s.GetEntry()), GetName(), this)))
580 fEntry.SetPictures(GetTop().GetH1Pic(), GetTop().GetH1Pic());
581 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
583 //__________________________________________________________________
584 void Strip::Fill(Double_t v)
591 //====================================================================
592 class SpectraMonitor : public AliFMDPattern
595 TGMainFrame fSelector;
600 fSelector(gClient->GetRoot(), 100, 100),
601 fTop(fSelector, fAux)
603 AddLoad(AliFMDInput::kRaw);
607 fTop.Connect("SelectionChanged()", "SpectraMonitor", this, "HandleDraw()");
609 fSelector.MapSubwindows();
610 fSelector.Resize(fSelector.GetDefaultSize());
611 fSelector.MapWindow();
613 // void SetAxis(TAxis* axis) { fTop.SetAxis(axis); }
616 TObject* user = fTop.Current();
617 if (!user) return kFALSE;
618 if (!user->InheritsFrom(Spectra::Element::Class())) {
619 Warning("HandleDraw", "%s does not inherit from Spectra::Element",
624 Spectra::Element* e = static_cast<Spectra::Element*>(user);
625 e->Draw("hist", fSlider->GetMinimum(), fSlider->GetMaximum());
633 AliFMDPattern::MakeAux();
635 fTop.SetAxis(fSpec->GetXaxis());
639 // Draw in the Aux the canvas
640 // For example draw the spectra
642 if (fTop.Current() != &fTop && HandleDraw()) return;
643 AliFMDPattern::DrawAux();
645 Bool_t ProcessHit(AliFMDHit* hit, TParticle* p)
647 fTop.Fill(hit->Detector(),
652 return AliFMDPattern::ProcessHit(hit, p);
654 Bool_t ProcessDigit(AliFMDDigit* digit)
656 fTop.Fill(digit->Detector(),
661 return AliFMDDisplay::ProcessDigit(digit);
663 Bool_t ProcessSDigit(AliFMDSDigit* sdigit)
665 fTop.Fill(sdigit->Detector(),
670 return AliFMDDisplay::ProcessSDigit(sdigit);
672 Bool_t ProcessRawDigit(AliFMDDigit* digit)
674 return ProcessDigit(digit);
676 Bool_t ProcessRecPoint(AliFMDRecPoint* recpoint)
678 fTop.Fill(recpoint->Detector(),
682 recpoint->Particles());
683 return AliFMDDisplay::ProcessRecPoint(recpoint);
685 Bool_t ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
686 Float_t x, Float_t mult)
688 fTop.Fill(det, rng, sec, str, mult);
689 return AliFMDDisplay::ProcessESD(det, rng, sec, str, x, mult);
694 RunSpectraMonitor(const char* file="",
696 const char* cdbSrc="local://$ALICE_ROOT",
699 // AliLog::SetModuleDebugLevel("FMD", 8);
701 if (fname.CompareTo("help", TString::kIgnoreCase) == 0) {
702 std::cout << "Usage: RunSpectraMonitor(<src>[,<runno>[,<cdb>[,<over>]]])\n"
705 << " <src> Is a data source (online, file)\n"
706 << " <runno> Is the (optional) run number\n"
707 << " <cdb> Is the (optional) CDB storage\n"
708 << " <over> Is the (optional) over sampling rate\n\n"
709 << "Defaults are <runno>=0 and cdb=\"local://$ALICE_ROOT\"\n"
710 << "<over> allows one to override the CDB setting. Default\n"
711 << "is to use the CDB setting.\n\n"
712 << "Note: This script _must_ be compiled with ACLic"
716 AliCDBManager* cdb = AliCDBManager::Instance();
717 cdb->SetDefaultStorage(cdbSrc);
719 UInt_t what = (AliFMDParameters::kPulseGain |
720 AliFMDParameters::kPedestal |
721 AliFMDParameters::kDeadMap |
722 AliFMDParameters::kZeroSuppression|
723 AliFMDParameters::kAltroMap |
724 AliFMDParameters::kStripRange);
725 if (over != 0) what |= AliFMDParameters::kSampleRate;
726 AliFMDParameters::Instance()->Init(kFALSE, what);
727 if (over != 0) AliFMDParameters::Instance()->SetSampleRate(over);
729 SpectraMonitor* d = new SpectraMonitor;
730 d->AddLoad(AliFMDInput::kRaw);
738 //____________________________________________________________________