8 #include <TDirectory.h>
14 //__________________________________________________________________
19 struct Element : public TNamed
26 if (fFull) delete fFull;
27 if (fFull) delete fCut;
31 * Draw this element. Draws the full histogram and the selected
34 * @param option Drawing option
38 virtual void DrawIt(Option_t* option="", Double_t l=-1, Double_t h=-1) //*MENU*
41 if (fFull->GetMinimum() < 0) gPad->SetLogy(kFALSE);
43 if (!fCut || l == h) return;
44 Double_t lx = fFull->GetXaxis()->GetXmin();
45 Double_t hx = fFull->GetXaxis()->GetXmax();
46 Double_t rr = (hx-lx);
47 Double_t ll = rr * l + lx;
48 Double_t hh = rr * h + lx;
49 for (Int_t i = 1; i <= fFull->GetNbinsX(); i++) {
50 if (fFull->GetBinCenter(i) <= ll ||
51 fFull->GetBinCenter(i) > hh) {
52 fCut->SetBinContent(i, 0);
55 fCut->SetBinContent(i, fFull->GetBinContent(i));
57 fCut->Draw(Form("%s same", option));
67 virtual void Draw(Option_t* option="")
70 if (fFull->GetMinimum() < 0) gPad->SetLogy(kFALSE);
77 * Get the top-level node
79 * @return Top-level node
81 virtual Element& GetParent() { return *fParent; }
85 * @param axis Axis to use
87 virtual void MakeHistograms(const TAxis& axis)
90 if (axis.GetNbins() <= 1) return;
91 if (axis.IsVariableBinSize())
92 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
93 axis.GetXbins()->fN, axis.GetXbins()->fArray);
95 fFull = new TH1F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
96 axis.GetNbins(), axis.GetXmin(), axis.GetXmax());
97 fCut = static_cast<TH1F*>(fFull->Clone(Form("c_%s", GetName())));
98 fCut->SetTitle(Form("%s restricted spectra", GetName()));
99 fFull->SetDirectory(0);
100 fFull->SetFillColor(kRed);
101 fFull->SetFillStyle(3001);
102 fCut->SetDirectory(0);
103 fCut->SetFillColor(kBlue);
104 fCut->SetFillStyle(3001);
109 * @return Array of children
111 TObjArray& Children() { return fChildren; }
115 * @return Array of children
117 const TObjArray& Children() const { return fChildren; }
119 * Write to a directory
121 * @param d Directory to write to
123 void WriteOut(TDirectory* d)
125 TDirectory* dd = d->mkdir(GetName());
127 if (fFull) fFull->Write();
128 if (fCut) fCut->Write();
130 TIter next(&fChildren);
132 while ((e = static_cast<Element*>(next())))
139 * @return Always true
141 virtual Bool_t IsFolder() const { return kTRUE; }
143 * Browse this element
145 * @param b Brower to use
147 virtual void Browse(TBrowser* b)
149 if (fFull) b->Add(fFull);
150 if (fCut) b->Add(fCut);
152 TIter next(&fChildren);
154 while ((o = next())) b->Add(o);
155 // if (fChildren.GetEntriesFast() > 0) b->Add(&fChildren);
158 Element() : TNamed(), fFull(0), fCut(0), fParent(0), fChildren(0) {}
165 Element(const char* name, const char* title, Element& parent)
166 : TNamed(name, title), fFull(0), fCut(0),
167 fParent(&parent), fChildren(0)
169 fChildren.SetOwner();
170 fChildren.SetName("children");
175 * @param v Value to fill
177 void DoFill(Double_t v) { if (fFull) fFull->Fill(v); }
179 * Get a child or null
181 * @param id Id of child
183 * @return Pointer to child, or null
185 Element* GetChild(UShort_t id) const
187 if (id >= fChildren.GetEntriesFast()) return 0;
188 return static_cast<Element*>(fChildren.At(id));
190 TH1* fFull; // Full histogram
191 TH1* fCut; // Selected data
198 //__________________________________________________________________
204 struct Top : public Element
209 Top() : Element("top", "Top", *this), fAxis(1,0,1) {}
211 * Get or add a detector
213 * @param d Detector (1-3)
215 * @return Reference to detector
217 Detector& GetOrAdd(UShort_t d);
227 void Fill(UShort_t d, Char_t r, UShort_t s, UShort_t t, Double_t v);
229 * Get the axis to use
231 * @return Reference to axis
233 const TAxis& GetAxis() const { return fAxis; }
235 * Set the axis to use
239 void SetAxis(const TAxis& a)
241 fAxis.Set(a.GetNbins(),a.GetXmin(),a.GetXmax());
243 void SetAxis(Int_t n, Double_t l, Double_t h) { fAxis.Set(n, l, h); }
245 TAxis fAxis; // The axis
250 //__________________________________________________________________
256 struct Detector : public Element
258 Detector() : Element(), fId(0) {}
263 * @param top PArent node
266 Detector(UShort_t d, Top& top)
267 : Element(Form("FMD%d", d), Form("FMD%d",d), top), fId(d)
274 UShort_t Id() const { return fId; }
276 * Get or add a sub element
278 * @param id Id of sub-element
280 * @return Sub element
282 Ring& GetOrAdd(Char_t id);
291 void Fill(Char_t r, UShort_t s, UShort_t t, Double_t v);
298 Top& M() { return static_cast<Top&>(*fParent); }
304 const Top& M() const { return static_cast<Top&>(*fParent); }
306 UShort_t R2Id(Char_t r) { return (r == 'I' || r == 'i') ? 0 : 1; }
309 ClassDef(Detector,1);
312 //__________________________________________________________________
318 struct Ring : public Element
320 Ring() : Element(), fId('\0') {}
321 Ring(UShort_t r, Detector& d)
322 : Element(Form("%s%c", d.GetName(), r),
323 Form("%s%c", d.GetName(), r), d), fId(r)
330 Char_t Id() const { return fId; }
332 * Get or add a sub element
334 * @param id Id of sub-element
336 * @return Sub element
338 Sector& GetOrAdd(UShort_t id);
346 void Fill(UShort_t s, UShort_t t, Double_t v);
349 * Get parent detector
351 * @return Parent detector
353 Detector& D() { return static_cast<Detector&>(*fParent); }
355 * Get parent detector
357 * @return Parent detector
359 const Detector& D() const { return static_cast<Detector&>(*fParent); }
365 Top& M() { return D().M(); }
371 const Top& M() const { return D().M(); }
378 virtual void Draw(Option_t* option="lego2z")
381 gPad->SetLogy(fFull->GetMinimum() > 0);
385 void MakeHistograms(const TAxis& axis)
388 if (axis.GetNbins() <= 1) return;
389 Int_t nSec = (fId == 'I' || fId == 'i' ? 20 : 40);
390 if (axis.IsVariableBinSize())
391 fFull = new TH2F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
393 axis.GetXbins()->fN, axis.GetXbins()->fArray);
395 fFull = new TH2F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
397 axis.GetNbins(), axis.GetXmin(), axis.GetXmax());
406 //__________________________________________________________________
412 struct Sector : public Element
414 Sector() : Element(), fId(1024) {}
415 Sector(UShort_t s, Ring& r)
416 : Element(Form("%s[%02d]", r.GetName(), s),
417 Form("%s[%02d]", r.GetName(), s), r), fId(s)
425 UShort_t Id() const { return fId; }
427 * Get or add a sub element
429 * @param id Id of sub-element
431 * @return Sub element
433 Strip& GetOrAdd(UShort_t id);
440 void Fill(UShort_t t, Double_t v);
447 virtual void Draw(Option_t* option="lego2z")
450 gPad->SetLogy(fFull->GetMinimum() > 0);
454 void MakeHistograms(const TAxis& axis)
457 if (axis.GetNbins() <= 1) return;
458 Int_t nStr = (R().Id() == 'I' || fId == 'i' ? 512 : 256);
459 if (axis.IsVariableBinSize())
460 fFull = new TH2F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
462 axis.GetXbins()->fN, axis.GetXbins()->fArray);
464 fFull = new TH2F(Form("f_%s", GetName()), Form("%s spectra", GetName()),
466 axis.GetNbins(), axis.GetXmin(), axis.GetXmax());
472 * @return Parent ring
474 Ring& R() { return static_cast<Ring&>(*fParent); }
478 * @return Parent ring
480 const Ring& R() const { return static_cast<Ring&>(*fParent); }
482 * Get parent detector
484 * @return Parent detector
486 Detector& D() { return R().D(); }
488 * Get parent detector
490 * @return Parent detector
492 const Detector& D() const { return R().D(); }
498 Top& M() { return D().M(); }
504 const Top& M() const { return D().M(); }
511 //__________________________________________________________________
516 struct Strip : public Element
518 Strip() : Element(), fId(1024) {}
519 Strip(UShort_t t, Sector& s)
520 : Element(Form("%s[%03d]", s.GetName(), t),
521 Form("%s[%03d]", s.GetName(), t), s), fId(t) {}
527 UShort_t Id() const { return fId; }
533 void Fill(Double_t v)
535 // Info("Fill", "%s: Filling with %f", GetName(), v);
538 Bool_t IsFolder() const { return 0; }
539 void Browse(TBrowser* b) { Draw(b->GetDrawOption()); }
543 * @return Parent sector
545 Sector& S() { return static_cast<Sector&>(*fParent); }
549 * @return Parent sector
551 const Sector& S() const { return static_cast<Sector&>(*fParent); }
555 * @return Parent ring
557 Ring& R() { return S().R(); }
561 * @return Parent ring
563 const Ring& R() const { return S().R(); }
565 * Get parent detector
567 * @return Parent detector
569 Detector& D() { return R().D(); }
571 * Get parent detector
573 * @return Parent detector
575 const Detector& D() const { return R().D(); }
581 Top& M() { return D().M(); }
587 const Top& M() const { return D().M(); }
594 //==================================================================
595 Strip& Sector::GetOrAdd(UShort_t id)
597 Strip* t = static_cast<Strip*>(GetChild(id));
599 t = new Strip(id, *this);
600 t->MakeHistograms(M().GetAxis());
601 // Info("GetOrAdd", "%s: Adding strip @ %d", GetName(), id);
602 fChildren.AddAtAndExpand(t, id);
606 //__________________________________________________________________
607 Sector& Ring::GetOrAdd(UShort_t id)
609 Sector* s = static_cast<Sector*>(GetChild(id));
611 s = new Sector(id, *this);
612 s->MakeHistograms(M().GetAxis());
613 // Info("GetOrAdd", "%s: Adding sector @ %d", GetName(), id);
614 fChildren.AddAtAndExpand(s, id);
618 //__________________________________________________________________
619 Ring& Detector::GetOrAdd(Char_t id)
621 UShort_t idd = R2Id(id);
622 Ring* r = static_cast<Ring*>(GetChild(idd));
624 r = new Ring(id, *this);
625 r->MakeHistograms(M().GetAxis());
626 // Info("GetOrAdd", "%s: Adding ring @ %d", GetName(), idd);
627 fChildren.AddAtAndExpand(r, idd);
631 //__________________________________________________________________
632 Detector& Top::GetOrAdd(UShort_t id)
635 Detector* d = static_cast<Detector*>(fChildren.At(idx));
637 d = new Detector(id, *this);
638 d->MakeHistograms(fAxis);
639 // Info("GetOrAdd", "%s: Adding detector @ %d", GetName(), id);
640 fChildren.AddAtAndExpand(d, idx);
644 //__________________________________________________________________
645 void Top::Fill(UShort_t d, Char_t r, UShort_t s, UShort_t t, Double_t v)
648 Detector& sub = GetOrAdd(d);
649 //Info("Fill", "%s: Filling %d,%c,%d,%d with %f", GetName(), d, r, s, t, v);
650 sub.Fill(r, s, t, v);
652 //__________________________________________________________________
653 void Detector::Fill(Char_t r, UShort_t s, UShort_t t, Double_t v)
656 Ring& sub = GetOrAdd(r);
657 //Info("Fill", "%s: Filling %c,%d,%d with %f", GetName(), r, s, t, v);
660 //__________________________________________________________________
661 void Ring::Fill(UShort_t s, UShort_t t, Double_t v)
664 Sector& sub = GetOrAdd(s);
665 //Info("Fill", "%s: Filling %d,%d with %f", GetName(), s, t, v);
668 //__________________________________________________________________
669 void Sector::Fill(UShort_t t, Double_t v)
672 Strip& sub = GetOrAdd(t);
673 //Info("Fill", "%s: Filling %d with %f", GetName(), t, v);
677 //======================================================================
678 #include <AliFMDDigit.h>
679 #include <AliFMDSDigit.h>
680 #include <AliFMDRecPoint.h>
681 #include <AliFMDHit.h>
682 #include <AliESDFMD.h>
683 #include <AliFMDInput.h>
684 #include <AliFMDRawReader.h>
685 #include <AliFMDParameters.h>
687 struct SpectraCollector : public AliFMDInput
689 //__________________________________________________________________
690 SpectraCollector(UShort_t what, const char* src=0)
691 : AliFMDInput("galice.root")
695 //__________________________________________________________________
696 SpectraCollector(const char* what, const char* src=0)
697 : AliFMDInput("galice.root")
699 Setup(ParseLoad(what), src);
701 //__________________________________________________________________
702 void Setup(UShort_t what, const char* src)
705 case kHits: AddLoad(kHits); break;
706 case kDigits: AddLoad(kDigits); break;
707 case kSDigits: AddLoad(kSDigits); break;
708 case kRaw: AddLoad(kRaw); break;
709 case kRawCalib: AddLoad(kRawCalib); break;
710 case kRecPoints: AddLoad(kRecPoints); break;
711 case kESD: AddLoad(kESD); break;
713 Fatal("Spectra", "Unknown type %d reguested", what);
716 if ((what == kRaw || what == kRawCalib)) {
717 if (!src || src[0] == '\0')
718 Fatal("Spectra", "No raw input specified!");
723 case kHits: fTop.SetAxis(500, 0, 1000); break;
724 case kDigits: // Fall-through
725 case kSDigits: // Fall-through
726 case kRaw: // Fall-through
727 case kRawCalib: // This is the same for all kinds of digits
728 fTop.SetAxis(1024, -.5, 1023.5);
730 case kRecPoints: // Fall-through
731 case kESD: // This is the same for ESD and rec-points
732 fTop.SetAxis(200, -.05, 19.95);
736 //____________________________________________________________________
737 Bool_t ProcessHit(AliFMDHit* h, TParticle* /* p */)
740 fTop.Fill(h->Detector(), h->Ring(), h->Sector(), h->Strip(), h->Edep());
743 //__________________________________________________________________
744 Bool_t ProcessSDigit(AliFMDSDigit* d)
747 fTop.Fill(d->Detector(), d->Ring(), d->Sector(), d->Strip(), d->Counts());
750 //__________________________________________________________________
751 Bool_t ProcessRawDigit(AliFMDDigit* digit)
753 return ProcessDigit(digit);
755 //__________________________________________________________________
756 Bool_t ProcessDigit(AliFMDDigit* d)
759 fTop.Fill(d->Detector(), d->Ring(), d->Sector(),d->Strip(), d->Counts());
762 //__________________________________________________________________
763 Bool_t ProcessRawCalibDigit(AliFMDDigit* digit)
765 AliFMDParameters* parm = AliFMDParameters::Instance();
766 UShort_t d = digit->Detector();
767 Char_t r = digit->Ring();
768 UShort_t s = digit->Sector();
769 UShort_t t = digit->Strip();
770 Double_t g = parm->GetPulseGain(d, r, s, t);
771 Double_t p = parm->GetPedestal(d, r, s, t);
772 Double_t w = parm->GetPedestalWidth(d, r, s, t);
773 UShort_t c = digit->Counts();
775 if (fFMDReader && fFMDReader->IsZeroSuppressed(d-1))
776 x = c + fFMDReader->NoiseFactor(d-1) * w;
780 Double_t m = x / (g * parm->GetDACPerMIP());
781 if (g < 0.1 || g > 10) m = 0;
783 fTop.Fill(d, r, s, t, m);
786 //__________________________________________________________________
787 Bool_t ProcessRecPoint(AliFMDRecPoint* r)
790 fTop.Fill(r->Detector(),r->Ring(),r->Sector(),r->Strip(),r->Particles());
793 //__________________________________________________________________
794 Bool_t ProcessESD(UShort_t d, Char_t r, UShort_t s, UShort_t t,
797 if (m != AliESDFMD::kInvalidMult)
798 fTop.Fill(d,r,s,t,m);
802 //__________________________________________________________________
805 TBrowser* b = new TBrowser("b", "b");
809 TFile* file = TFile::Open("spectra.root", "RECREATE");
810 // fTop.WriteOut(file);
818 ClassDef(SpectraCollector,0);
822 //======================================================================
824 MakeSpectra(UShort_t what, Int_t n=1000, const char* src=0)
826 gROOT->LoadMacro("$ALICE_ROOT.trunk/FMD/scripts/Compile.C");
827 gSystem->AddIncludePath("-DSPECTRA_BUILD");
828 const char* script = "$ALICE_ROOT.trunk/FMD/scripts/MakeSpectra.C";
829 const char* here = gSystem->BaseName(script);
831 if ((ret = gSystem->CopyFile(gSystem->ExpandPathName(script), here, true))) {
832 Error("MakeSpectra", "Failed to copy %s to %s: %d", script, here, ret);
836 SpectraCollector* sd = new SpectraCollector(what, src);
840 #endif // SPECTRA_BUILD