Added test scripts.
[u/mrichter/AliRoot.git] / FMD / scripts / TestESDCompat.C
CommitLineData
9c35f272 1#include <iomanip>
2/**
3 * Script to test for compatibility to read/write ESD information
4 */
5
6Float_t EtaValue(UShort_t d, Char_t r, UShort_t t)
7{
8 return (d * 1000 + (r == 'I' || r == 'i' ? 0 : 1) * 100 + 0.001 * t);
9}
10Float_t MultValue(UShort_t d, Char_t r, UShort_t s, UShort_t t)
11{
12 return (EtaValue(d, r, t) + s);
13}
14
15void
16FillESD(AliESDFMD* esd)
17{
18 for (UShort_t d = 1; d <= 3; d++) {
19 UShort_t nRng = (d == 1 ? 1 : 2);
20 for (UShort_t i = 0; i < nRng; i++) {
21 Char_t r = (i == 0 ? 'I' : 'O');
22 UShort_t nSec = (i == 0 ? 20 : 40);
23 UShort_t nStr = (i == 0 ? 512 : 256);
24 for (UShort_t s = 0; s < nSec; s++) {
25 for (UShort_t t = 0; t < nStr; t++) {
26 if (s == 0) esd->SetEta(d, r, 0, t, EtaValue(d, r, t));
27 esd->SetMultiplicity(d, r, s, t, MultValue(d, r, s, t));
28 }
29 } // for s
30 } // for i
31 } // for d
32}
33
34void
35WriteESD(const char* fileName)
36{
37 TFile* file = TFile::Open(fileName, "RECREATE");
38 TTree* tree = new TTree("T", "T");
39 AliESDFMD* fmd = new AliESDFMD();
40 tree->Branch("FMD", "AliESDFMD", &fmd);
41
42 for (UShort_t i = 0; i < 10; i++) {
43 FillESD(fmd);
44 tree->Fill();
45 }
46 file->Write();
47 file->Close();
48}
49
50Bool_t
51PrintOne(UShort_t d, Char_t r, UShort_t s, UShort_t t,
52 Float_t m, Float_t e)
53{
54 Float_t em = MultValue(d, r, s, t);
55 Float_t ee = EtaValue(d, r, t);
56 if (m != em || ee != e) {
57 std::cerr << "FMD" << d << r << '['
58 << std::setw(2) << s << ','
59 << std::setw(3) << t << "]: "
60 << std::setw(8) << m << " ("
61 << std::setw(8) << em << ' '
62 << (m == em ? "ok" : "bad") << ") @ "
63 << std::setw(8) << e << " ("
64 << std::setw(8) << ee << ' '
65 << (ee == e ? "ok" : "bad") << ')' << std::endl;
66 return kFALSE;
67 }
68 return kTRUE;
69}
70
71Bool_t
72PrintESD(AliESDFMD* esd)
73{
74
75 Bool_t ret = kTRUE;
76 for (UShort_t d = 1; d <= 3; d++) {
77 UShort_t nRng = (d == 1 ? 1 : 2);
78 for (UShort_t i = 0; i < nRng; i++) {
79 Char_t r = (i == 0 ? 'I' : 'O');
80 UShort_t nSec = (i == 0 ? 20 : 40);
81 UShort_t nStr = (i == 0 ? 512 : 256);
82 for (UShort_t s = 0; s < nSec; s++) {
83 for (UShort_t t = 0; t < nStr; t++) {
84 Float_t m = esd->Multiplicity(d, r, s, t);
85 Float_t e = esd->Eta(d, r, s, t);
86 if (!PrintOne(d, r, s, t, m, e)) ret = kFALSE;
87 }
88 }
89 }
90 }
91 return ret;
92}
93
94void
95ReadESD(const char* fileName)
96{
97 TFile* file = TFile::Open(fileName, "READ");
98 TTree* tree = static_cast<TTree*>(file->Get("T"));
99 AliESDFMD* fmd = new AliESDFMD();
100 tree->SetBranchAddress("FMD", &fmd);
101
102 Bool_t ret = kTRUE;
103 for (UShort_t i = 0; i < 10; i++) {
104 fmd->Clear();
105 tree->GetEntry(i);
106 if (!PrintESD(fmd)) ret = kFALSE;
107 }
108 file->Close();
109 if (!ret)
110 std::cerr << "There have been errors!" << std::endl;
111 else
112 std::cout << "All correct" << std::endl;
113
114}
115
116
117void
118TestESDCompat(const char* fileName=0)
119{
120 if (!fileName) {
121 WriteESD("esd_test.root");
122 return;
123 }
124 ReadESD(fileName);
125}