AliRoot Core  3dc7879 (3dc7879)
TestESD.C
Go to the documentation of this file.
1 #include <iomanip>
6 Float_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 }
10 Float_t MultValue(UShort_t d, Char_t r, UShort_t s, UShort_t t)
11 {
12  return (EtaValue(d, r, t) + s);
13 }
14 
15 void
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 
34 void
35 WriteESD(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 
50 Bool_t
51 PrintOne(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 
71 Bool_t
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 
94 void
95 ReadESD(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 
117 void
118 TestESD(const char* fileName=0)
119 {
120  if (!fileName) {
121  WriteESD("esd_test.root");
122  return;
123  }
124  ReadESD(fileName);
125 }
void WriteESD(const char *fileName)
Definition: TestESD.C:35
TFile * Open(const char *filename, Long64_t &nevents)
Bool_t PrintOne(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t m, Float_t e)
Definition: TestESD.C:51
TString fileName(const char *dir, int runNumber, const char *da, int i, const char *type)
void ReadESD(const char *fileName)
Definition: TestESD.C:95
TTree * tree
Float_t EtaValue(UShort_t d, Char_t r, UShort_t t)
Definition: TestESD.C:6
Bool_t PrintESD(AliESDFMD *esd)
Definition: TestESD.C:72
void SetMultiplicity(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip, Float_t mult)
Definition: AliESDFMD.cxx:268
void SetEta(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip, Float_t eta)
Definition: AliESDFMD.cxx:281
Float_t Multiplicity(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Definition: AliESDFMD.cxx:185
Float_t MultValue(UShort_t d, Char_t r, UShort_t s, UShort_t t)
Definition: TestESD.C:10
Float_t Eta(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Definition: AliESDFMD.cxx:198
Event Summary Data for the Forward Multiplicity Detector.This stores the psuedo-multiplicity and -rap...
Definition: AliESDFMD.h:30
void TestESD()
Definition: TestESD.C:54
void Clear(Option_t *option="")
Definition: AliESDFMD.cxx:176
void FillESD(AliESDFMD *esd)
Definition: TestESD.C:16