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/OCDB",
18 gSystem->Load("libANALYSIS.so");
19 gSystem->Load("libFMDanalysis.so");
20 gSystem->Load("libFMDutil.so");
21 // AliLog::SetModuleDebugLevel("FMD", 8);
23 if (fname.CompareTo("help", TString::kIgnoreCase) == 0) {
24 std::cout << "Usage: RunSpectraMonitor(<src>[,<runno>[,<cdb>[,<over>]]])\n"
27 << " <src> Is a data source (online, file)\n"
28 << " <runno> Is the (optional) run number\n"
29 << " <cdb> Is the (optional) CDB storage\n"
30 << " <over> Is the (optional) over sampling rate\n\n"
31 << "Defaults are <runno>=0 and cdb=\"local://$ALICE_ROOT/OCDB\"\n"
32 << "<over> allows one to override the CDB setting. Default\n"
33 << "is to use the CDB setting.\n\n"
34 << "Note: This script _must_ be compiled with ACLic"
38 AliCDBManager* cdb = AliCDBManager::Instance();
39 cdb->SetDefaultStorage(cdbSrc);
41 UInt_t what = (AliFMDParameters::kPulseGain |
42 AliFMDParameters::kPedestal |
43 AliFMDParameters::kDeadMap |
44 AliFMDParameters::kZeroSuppression|
45 AliFMDParameters::kAltroMap |
46 AliFMDParameters::kStripRange);
47 if (over != 0) what |= AliFMDParameters::kSampleRate;
48 AliFMDParameters::Instance()->Init(kFALSE, what);
49 if (over != 0) AliFMDParameters::Instance()->SetSampleRate(over);
51 AliFMDSpectraDisplay* d = new AliFMDSpectraDisplay;
52 // d->AddLoad(AliFMDInput::kRaw);
53 d->AddLoad(AliFMDInput::kDigits);
54 // d->SetRawFile(file);
59 #include <AliCDBManager.h>
60 #include <AliFMDParameters.h>
61 #include <AliFMDHit.h>
62 #include <AliFMDDigit.h>
63 #include <AliFMDSDigit.h>
64 #include <AliFMDRecPoint.h>
65 #include <AliESDFMD.h>
66 #include <AliFMDPattern.h>
68 #include <TDirectory.h>
69 #include <TObjArray.h>
81 #include <TGListTree.h>
84 #include <KeySymbols.h>
86 #include <RQ_OBJECT.h>
96 //__________________________________________________________________
97 struct Element : public TNamed
100 virtual void Draw(Option_t* option, Double_t l, Double_t h);
101 virtual Top& GetTop() = 0;
102 virtual void MakeHistograms(TAxis* axis);
104 Element(const char* name, const char* title)
105 : TNamed(name, title), fFull(0), fCut(0)
107 void DoFill(Double_t v);
112 //__________________________________________________________________
113 struct Top : public Element
115 RQ_OBJECT("Spectra::Top")
117 Top(TGCompositeFrame& frame, TCanvas* canvas);
118 TGListTree& GetList() { return fList; }
119 Detector& GetOrAdd(UShort_t id);
120 void Fill(UShort_t d, Char_t ring,
121 UShort_t sec, UShort_t str, Double_t v);
122 TAxis* GetAxis() { return fAxis; }
123 void SetAxis(TAxis* a);
124 Top& GetTop() { return *this; }
127 @param e selected entry, if any
128 @param id Id of entry */
129 virtual void HandleEntry(TGListTreeItem* e, Int_t id);
130 /** Handle key strokes
131 @param f Item selected, if any
132 @param keysym Key symbol
133 @param mask Modifier mask */
134 virtual void HandleKey(TGListTreeItem* f, UInt_t keysym, UInt_t mask);
136 @param f Selected item, if any */
137 virtual void HandleReturn(TGListTreeItem* f);
138 /** Clear the list */
139 virtual void ClearList();
140 /** Clear the canvas */
141 virtual void ClearCanvas();
143 virtual void UpdateCanvas();
145 virtual void UpdateList();
146 /** Return the currently selected entry */
147 TGListTreeItem* CurrentEntry() const { return fCurrentEntry; }
148 /** @return the currently selected user data (possibly 0) */
149 TObject* Current() const;
150 /** Selection changed signal */
151 void SelectionChanged() { Emit("SelectionChanged()"); }//*SIGNAL*
152 /** Get Picture for 1D histogram */
153 const TGPicture* GetH1Pic() { return fHist1DIcon; }
154 /** 2D Histogram Icon */
155 const TGPicture* GetH2Pic() { return fHist2DIcon; }
156 /** 3D Histogram Icon */
157 const TGPicture* GetH3Pic() { return fHist3DIcon; }
159 const TGPicture* GetGPic() { return fGraphIcon; }
160 TGListTreeItem& GetEntry() { return fEntry; }
162 TGLayoutHints fHints;
166 TGListTreeItem* fCurrentEntry;
168 /** 1D Histogram Icon */
169 const TGPicture* fHist1DIcon;
170 /** 2D Histogram Icon */
171 const TGPicture* fHist2DIcon;
172 /** 3D Histogram Icon */
173 const TGPicture* fHist3DIcon;
175 const TGPicture* fGraphIcon;
176 /** The axis to use */
179 TGListTreeItem& fEntry;
182 //__________________________________________________________________
183 struct Detector : public Element
185 Detector(UShort_t det, Top& top);
186 UShort_t Id() const { return fId; }
187 Top& GetTop() { return fParent; }
188 Top& GetParent() { return fParent; }
189 Ring& GetOrAdd(Char_t id);
190 void Fill(Char_t ring, UShort_t sec, UShort_t str, Double_t v);
191 TGListTreeItem& GetEntry() { return fEntry; }
196 TGListTreeItem& fEntry;
199 //__________________________________________________________________
200 struct Ring : public Element
202 Ring(Char_t id, Detector& d);
203 Char_t Id() const { return fId; }
204 UShort_t DetectorId() { return fParent.Id(); }
205 Top& GetTop() { return fParent.GetTop(); }
206 Detector& GetDetector() { return GetParent(); }
207 Detector& GetParent() { return fParent; }
208 Sector& GetOrAdd(UShort_t id);
209 void Fill(UShort_t sec, UShort_t str, Double_t v);
210 TGListTreeItem& GetEntry() { return fEntry; }
215 TGListTreeItem& fEntry;
218 //__________________________________________________________________
219 struct Sector : public Element
221 Sector(UShort_t id, Ring& r);
222 UShort_t Id() const { return fId; }
223 UShort_t DetectorId() { return fParent.DetectorId(); }
224 Char_t RingId() { return fParent.Id(); }
225 Top& GetTop() { return fParent.GetTop(); }
226 Detector& GetDetector() { return fParent.GetDetector(); }
227 Ring& GetRing() { return fParent; }
228 Ring& GetParent() { return fParent; }
229 Strip& GetOrAdd(UShort_t id);
230 void Fill(UShort_t str, Double_t v);
231 TGListTreeItem& GetEntry() { return fEntry; }
236 TGListTreeItem& fEntry;
239 //__________________________________________________________________
240 struct Strip : public Element
242 Strip(UShort_t id, Sector& s);
243 UShort_t Id() const { return fId; }
244 UShort_t DetectorId() { return fParent.DetectorId(); }
245 Char_t RingId() { return fParent.RingId(); }
246 UShort_t SectorId() { return fParent.Id(); }
247 Top& GetTop() { return fParent.GetTop(); }
248 Detector& GetDetector() { return fParent.GetDetector(); }
249 Ring& GetRing() { return fParent.GetRing(); }
250 Sector& GetSector() { return fParent; }
251 Sector& GetParent() { return fParent; }
252 void Fill(Double_t v);
253 TGListTreeItem& GetEntry() { return fEntry; }
257 TGListTreeItem& fEntry;
260 //==================================================================
261 void Element::MakeHistograms(TAxis* axis)
264 if (axis->IsVariableBinSize()) {
265 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
266 axis->GetXbins()->fN, axis->GetXbins()->fArray);
267 fCut = new TH1F(Form("c_%s", GetName()),
268 Form("%s restricted spectra", GetName()),
269 axis->GetXbins()->fN, axis->GetXbins()->fArray);
272 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
273 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
274 fCut = new TH1F(Form("c_%s", GetName()),
275 Form("%s restricted spectra", GetName()),
276 axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
278 fFull->SetFillColor(kRed);
279 fFull->SetFillStyle(3001);
280 fCut->SetFillColor(kBlue);
281 fCut->SetFillStyle(3001);
283 //__________________________________________________________________
284 void Element::DoFill(Double_t v)
286 if (fFull) fFull->Fill(v);
288 //__________________________________________________________________
289 void Element::Draw(Option_t* option, Double_t l, Double_t h)
292 if (fFull->GetMinimum() < 0) gPad->SetLogy(kFALSE);
294 Double_t lx = fFull->GetXaxis()->GetXmin();
295 Double_t hx = fFull->GetXaxis()->GetXmax();
296 Double_t rr = (hx-lx);
297 Double_t ll = rr * l + lx;
298 Double_t hh = rr * h + lx;
299 for (Int_t i = 1; i <= fFull->GetNbinsX(); i++) {
300 if (fFull->GetBinCenter(i) <= ll ||
301 fFull->GetBinCenter(i) > hh) {
302 fCut->SetBinContent(i, 0);
305 fCut->SetBinContent(i, fFull->GetBinContent(i));
307 fCut->Draw(Form("%s same", option));
309 //==================================================================
310 Top::Top(TGCompositeFrame& frame, TCanvas* canvas)
311 : Element("All", "Everything"),
312 fHints(kLHintsExpandX|kLHintsExpandY,3, 3, 3, 3),
313 fContainer(&frame, 200, 350),
314 fList(&fContainer, kHorizontalFrame),
318 fHist1DIcon(gClient->GetPicture("h1_t.xpm")),
319 fHist2DIcon(gClient->GetPicture("h2_t.xpm")),
320 fHist3DIcon(gClient->GetPicture("h3_t.xpm")),
321 fGraphIcon(gClient->GetPicture("graph.xpm")),
322 fEntry(*(fList.AddItem(0, GetName(), this)))
324 fContainer.AddFrame(&fList, &fHints);
325 frame.AddFrame(&fContainer, &fHints);
327 fList.Connect("Clicked(TGListTreeItem*,Int_t)", "Spectra::Top", this,
328 "HandleEntry(TGListTreeItem*,Int_t)");
329 fList.Connect("KeyPressed(TGListTreeItem*,ULong_t,ULong_t)",
330 "Spectra::Top", this,
331 "HandleKey(TGListTreeItem*,UInt_t,UInt_t)");
332 fList.Connect("ReturnPressed(TGListTreeItem*)", "Spectra::Top", this,
333 "HandleReturn(TGListTreeItem*)");
335 //____________________________________________________________________
337 Top::SetAxis(TAxis* axis)
340 MakeHistograms(axis);
342 //____________________________________________________________________
346 if (!fCanvas) return;
350 //____________________________________________________________________
354 fList.DeleteItem(fList.GetFirstItem());
359 //____________________________________________________________________
361 Top::HandleReturn(TGListTreeItem * f)
365 fList.UnselectAll(kFALSE);
366 fList.SetSelected(0);
374 //____________________________________________________________________
376 Top::HandleKey(TGListTreeItem * f, UInt_t keysym, UInt_t /*mask*/)
379 fList.UnselectAll(kFALSE);
380 fList.SetSelected(0);
383 TGListTreeItem* next = 0;
386 next = f->GetPrevSibling();
388 next = f->GetParent();
389 if (next) fList.CloseItem(next);
393 next = f->GetNextSibling();
394 if (!next && f->GetParent()) {
395 next = f->GetParent()->GetNextSibling();
396 fList.CloseItem(f->GetParent());
400 next = f->GetParent();
401 if (next) fList.CloseItem(next);
404 next = f->GetFirstChild();
405 if (next) fList.OpenItem(f);
409 next = fList.GetSelected();
412 fList.PageDown(kTRUE);
413 next = fList.GetSelected();
416 if (next) gClient->NeedRedraw(&fList);
417 if (next && next != f) {
418 fList.ClearHighlighted();
419 fList.SetSelected(next);
424 //____________________________________________________________________
426 Top::HandleEntry(TGListTreeItem* entry, Int_t /*id*/)
428 TGListTreeItem* old = fCurrentEntry;
430 if (!entry->GetUserData()) return;
431 fCurrentEntry = entry;
437 if (old != fCurrentEntry && fCanvas) fCanvas->cd();
441 //____________________________________________________________________
445 gClient->NeedRedraw(&fList);
448 //____________________________________________________________________
452 if (!fCanvas) return;
457 //____________________________________________________________________
458 TObject* Top::Current() const
460 if (!fCurrentEntry) return 0;
461 if (!fCurrentEntry->GetUserData()) return 0;
462 return static_cast<TObject*>(fCurrentEntry->GetUserData());
465 //__________________________________________________________________
466 Detector& Top::GetOrAdd(UShort_t id)
470 if (fChildren.GetEntriesFast() <= idx ||
471 !(d = static_cast<Detector*>(fChildren.At(idx)))) {
472 d = new Detector(id, *this);
473 fChildren.AddAtAndExpand(d, idx);
474 // fList.SortChildren(&fEntry);
478 //__________________________________________________________________
479 void Top::Fill(UShort_t det, Char_t ring,
480 UShort_t sec, UShort_t str, Double_t v)
482 Detector& d = GetOrAdd(det);
483 d.Fill(ring, sec, str, v);
486 //==================================================================
487 Detector::Detector(UShort_t det, Top& tree)
488 : Element(Form("FMD%d", det), "FMD Sub-detector"),
492 fEntry(*(tree.GetList().AddItem(&(tree.GetEntry()), GetName())))
494 fEntry.SetUserData(this);
495 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
497 //__________________________________________________________________
498 Ring& Detector::GetOrAdd(Char_t id)
500 Int_t idx = (id == 'I' || id == 'i') ? 0 : 1;
502 if (fChildren.GetEntriesFast() <= idx ||
503 !(r = static_cast<Ring*>(fChildren.At(idx)))) {
504 r = new Ring(id, *this);
505 fChildren.AddAtAndExpand(r, idx);
506 // GetTop().GetList().SortChildren(&fEntry);
510 //__________________________________________________________________
511 void Detector::Fill(Char_t ring, UShort_t sec, UShort_t str, Double_t v)
513 Ring& r = GetOrAdd(ring);
517 //==================================================================
518 Ring::Ring(Char_t id, Detector& d)
519 : Element(Form("FMD%d%c", d.Id(), id), "FMD Ring"),
523 fEntry(*(GetTop().GetList().AddItem(&(d.GetEntry()), GetName(), this)))
525 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
527 //__________________________________________________________________
528 Sector& Ring::GetOrAdd(UShort_t id)
531 if (fChildren.GetEntriesFast() <= id ||
532 !(s = static_cast<Sector*>(fChildren.At(id)))) {
533 s = new Sector(id, *this);
534 fChildren.AddAtAndExpand(s, id);
535 // GetTop().GetList().SortChildren(&fEntry);
539 //__________________________________________________________________
540 void Ring::Fill(UShort_t sec, UShort_t str, Double_t v)
542 Sector& s = GetOrAdd(sec);
546 //==================================================================
547 Sector::Sector(UShort_t id, Ring& r)
548 : Element(Form("FMD%d%c_%02d", r.DetectorId(), r.Id(), id), "FMD Sector"),
552 fEntry(*(GetTop().GetList().AddItem(&(r.GetEntry()), GetName(), this)))
554 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
556 //__________________________________________________________________
557 Strip& Sector::GetOrAdd(UShort_t id)
560 if (fChildren.GetEntriesFast() <= id ||
561 !(s = static_cast<Strip*>(fChildren.At(id)))) {
562 s = new Strip(id, *this);
563 fChildren.AddAtAndExpand(s, id);
564 // GetTop().GetList().SortChildren(&fEntry);
568 //__________________________________________________________________
569 void Sector::Fill(UShort_t str, Double_t v)
571 Strip& s = GetOrAdd(str);
575 //==================================================================
576 Strip::Strip(UShort_t id, Sector& s)
577 : Element(Form("FMD%d%c_%02d_%03d", s.DetectorId(), s.RingId(),
578 s.Id(), id), "FMD Strip"),
581 fEntry(*(GetTop().GetList().AddItem(&(s.GetEntry()), GetName(), this)))
583 fEntry.SetPictures(GetTop().GetH1Pic(), GetTop().GetH1Pic());
584 if (GetTop().GetAxis()) MakeHistograms(GetTop().GetAxis());
586 //__________________________________________________________________
587 void Strip::Fill(Double_t v)
594 //====================================================================
595 class SpectraMonitor : public AliFMDPattern
598 TGMainFrame fSelector;
603 fSelector(gClient->GetRoot(), 100, 100),
604 fTop(fSelector, fAux)
606 AddLoad(AliFMDInput::kRaw);
610 fTop.Connect("SelectionChanged()", "SpectraMonitor", this, "HandleDraw()");
612 fSelector.MapSubwindows();
613 fSelector.Resize(fSelector.GetDefaultSize());
614 fSelector.MapWindow();
616 // void SetAxis(TAxis* axis) { fTop.SetAxis(axis); }
619 TObject* user = fTop.Current();
620 if (!user) return kFALSE;
621 if (!user->InheritsFrom(Spectra::Element::Class())) {
622 Warning("HandleDraw", "%s does not inherit from Spectra::Element",
627 Spectra::Element* e = static_cast<Spectra::Element*>(user);
628 e->Draw("hist", fSlider->GetMinimum(), fSlider->GetMaximum());
636 AliFMDPattern::MakeAux();
638 fTop.SetAxis(fSpec->GetXaxis());
642 // Draw in the Aux the canvas
643 // For example draw the spectra
645 if (fTop.Current() != &fTop && HandleDraw()) return;
646 AliFMDPattern::DrawAux();
648 Bool_t ProcessHit(AliFMDHit* hit, TParticle* p)
650 fTop.Fill(hit->Detector(),
655 return AliFMDPattern::ProcessHit(hit, p);
657 Bool_t ProcessDigit(AliFMDDigit* digit)
659 fTop.Fill(digit->Detector(),
664 return AliFMDDisplay::ProcessDigit(digit);
666 Bool_t ProcessSDigit(AliFMDSDigit* sdigit)
668 fTop.Fill(sdigit->Detector(),
673 return AliFMDDisplay::ProcessSDigit(sdigit);
675 Bool_t ProcessRawDigit(AliFMDDigit* digit)
677 return ProcessDigit(digit);
679 Bool_t ProcessRecPoint(AliFMDRecPoint* recpoint)
681 fTop.Fill(recpoint->Detector(),
685 recpoint->Particles());
686 return AliFMDDisplay::ProcessRecPoint(recpoint);
688 Bool_t ProcessESD(UShort_t det, Char_t rng, UShort_t sec, UShort_t str,
689 Float_t x, Float_t mult)
691 fTop.Fill(det, rng, sec, str, mult);
692 return AliFMDDisplay::ProcessESD(det, rng, sec, str, x, mult);
697 RunSpectraMonitor(const char* file="",
699 const char* cdbSrc="local://$ALICE_ROOT/OCDB",
702 // AliLog::SetModuleDebugLevel("FMD", 8);
704 if (fname.CompareTo("help", TString::kIgnoreCase) == 0) {
705 std::cout << "Usage: RunSpectraMonitor(<src>[,<runno>[,<cdb>[,<over>]]])\n"
708 << " <src> Is a data source (online, file)\n"
709 << " <runno> Is the (optional) run number\n"
710 << " <cdb> Is the (optional) CDB storage\n"
711 << " <over> Is the (optional) over sampling rate\n\n"
712 << "Defaults are <runno>=0 and cdb=\"local://$ALICE_ROOT/OCDB\"\n"
713 << "<over> allows one to override the CDB setting. Default\n"
714 << "is to use the CDB setting.\n\n"
715 << "Note: This script _must_ be compiled with ACLic"
719 AliCDBManager* cdb = AliCDBManager::Instance();
720 cdb->SetDefaultStorage(cdbSrc);
722 UInt_t what = (AliFMDParameters::kPulseGain |
723 AliFMDParameters::kPedestal |
724 AliFMDParameters::kDeadMap |
725 AliFMDParameters::kZeroSuppression|
726 AliFMDParameters::kAltroMap |
727 AliFMDParameters::kStripRange);
728 if (over != 0) what |= AliFMDParameters::kSampleRate;
729 AliFMDParameters::Instance()->Init(kFALSE, what);
730 if (over != 0) AliFMDParameters::Instance()->SetSampleRate(over);
732 SpectraMonitor* d = new SpectraMonitor;
733 d->AddLoad(AliFMDInput::kRaw);
741 //____________________________________________________________________