Fixes for reading zero-suppressed data. These should be propagated to
[u/mrichter/AliRoot.git] / FMD / scripts / TestShaping.C
CommitLineData
2aeec17d 1#include <TMath.h>
2#include <TGraph.h>
3#include <TCanvas.h>
4#include <TArrayI.h>
5#include <TRandom.h>
6#include <TLegend.h>
7#include <iostream>
8#include <TH1.h>
9
10void
11convert(UShort_t rate, Int_t adc, Int_t last, TArrayI& counts)
12{
13 if (rate == 1) {
14 Float_t a = adc;
15 if (a < 0) a = 0;
16 counts[0] = UShort_t(TMath::Min(a, 1023.F));
17 return;
18 }
19 Float_t b = 6;
20 for (Ssiz_t i = 0; i < rate; i++) {
21 Float_t t = Float_t(i) / rate + 1./rate;
22 Float_t s = adc + (last - adc) * TMath::Exp(-b * t);
23 Float_t a = s;
24 if (a < 0) a = 0;
25 counts[i] = UShort_t(TMath::Min(a, 1023.F));
26 std::cout << " rate=" << rate << "\tadc=" << adc
27 << "\tcount[" << i << "]=" << counts[i]
28 << "\ts=" << adc << " + (" << last << " - "
29 << adc << ") * exp(-" << b << " * " << t
30 << ")=" << s << std::endl;
31 }
32 return;
33}
34
35TGraph*
36makeGraph(const TArrayI& adcs, Int_t rate)
37{
38 Int_t last = adcs.fArray[0];
39 TArrayI counts(4);
40 TGraph* graph = new TGraph(rate * adcs.fN);
41 graph->SetLineColor(rate);
42 graph->SetMarkerColor(rate);
43 graph->SetMarkerStyle(20+rate);
44 graph->SetLineStyle(rate);
45 graph->SetName(Form("rate%d", rate));
46 graph->SetTitle(Form("Rate %d", rate));
47 for (Int_t i = 0; i < adcs.fN; i++) {
48 counts.Reset(-1);
49 convert(rate, adcs.fArray[i], last, counts);
50
51 for (Int_t j = 0; j < rate; j++) {
52 Int_t idx = (i * rate + j);
53 Double_t x = (i + (rate > 1 ? Float_t(j+1) / rate-1 : 0));
54 graph->SetPoint(idx, x, counts[j]);
55 }
56 last = counts[rate - 1];
57 }
58 return graph;
59}
60
61void
62TestShaping(int max=4)
63{
64 TArrayI adcs(10);
65 TGraph* orig = new TGraph(adcs.fN);
66 orig->SetName("Original");
67 orig->SetTitle("Original");
68 orig->SetMarkerStyle(25);
69 orig->SetMarkerColor(1);
70 orig->SetMarkerSize(2);
71 orig->SetLineColor(1);
72 for (Int_t i = 0; i < adcs.fN; i++) {
73 adcs.fArray[i] = Int_t(gRandom->Uniform(0, 1023));
74 orig->SetPoint(i, i, adcs.fArray[i]);
75 }
76
77 TCanvas* c = new TCanvas("c", "c");
78 c->SetFillColor(0);
79 c->SetTopMargin(.02);
80 c->SetRightMargin(.02);
81
82 TH1* h = new TH1F("frame","frame", adcs.fN+1, -2, adcs.fN);
83 h->SetMinimum(0);
84 h->SetMaximum(1300);
85 h->SetStats(0);
86 h->Draw("");
87 orig->Draw("pl same");
88
89 TLegend* l = new TLegend(adcs.fN*3./4, 1023, adcs.fN, 1300, "", "");
90 l->SetFillColor(0);
91 l->SetBorderSize(1);
92 l->AddEntry(orig, orig->GetTitle(), "lp");
93
94 for (int i = 1; i <= max; i++) {
95 TGraph* g = makeGraph(adcs, i);
96 g->Draw("pl same");
97 l->AddEntry(g, g->GetTitle(), "lp");
98 }
99 l->Draw();
100
101 c->Modified();
102 c->Update();
103 c->cd();
104}
105
106
107
108
109
110