]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/scripts/RawTest.C
Setting raw digits flag
[u/mrichter/AliRoot.git] / FMD / scripts / RawTest.C
CommitLineData
d389af40 1//
2// Small script to test consistency of writing and reading raw data.
3//
4void
5RawTest()
6{
7 gRandom->SetSeed(12345);
8 Int_t sampleRate = 3;
9 Int_t channelWidth = 128;
10 Float_t shapingTime = 5;
11 UInt_t maxAdc = (1 << 10);
12 UInt_t threshold = (1 << 8);
13 TArrayI outData(sampleRate * channelWidth);
14
15 Float_t lastTotalCharge = 0;
16 Int_t ok = 0;
17 for (Int_t channel = 0; channel < channelWidth; channel++) {
18 Float_t totalCharge = gRandom->Uniform(0, 1);
19
20 for (Int_t sample = 0; sample < sampleRate; sample++) {
21 Float_t time = Float_t(sample) / sampleRate;
22 Float_t charge = (totalCharge + (lastTotalCharge - totalCharge)
23 * TMath::Exp(-shapingTime * time));
24 UInt_t adc = UInt_t(maxAdc * charge);
25 outData[channel * sampleRate + sample] = adc;
26 if (adc > threshold) ok++;
27 }
28 lastTotalCharge = totalCharge;
29 }
30 std::cout << "Total of " << outData.fN << " samples of which "
31 << ok << " of them are above threshold (" << threshold
32 << ")" << std::endl;
33
34 {
35 AliAltroBuffer buffer("FMD_4096.ddl", 1);
36 buffer.WriteDataHeader(kTRUE, kFALSE);
37 buffer.WriteChannel(0, 0, 0, outData.fN, outData.fArray, threshold);
38 buffer.Flush();
39 buffer.WriteDataHeader(kFALSE, kFALSE);
40 }
41
42 AliRawReader* reader = new AliRawReaderFile(-1);
43 if (!reader) {
44 std::cerr << "Failed to make AliRawReader" << endl;
45 return 0;
46 }
47 AliFMDRawStream input(reader, sampleRate);
48 reader->Select(AliFMD::kBaseDDL >> 8);
49
50 Int_t oldDDL = -1;
51 Int_t count = 0;
52 UShort_t detector = 1; // Must be one here
53 UShort_t oldDetector = 0;
54 // Loop over data in file
55 Bool_t next = kTRUE;
56
57 // local Cache
58 TArrayI counts(10);
59 counts.Reset(-1);
60 Int_t offset = 0;
61
62 TArrayI inputData(sampleRate * channelWidth);
63 while (next) {
64 next = input.Next();
65
66 if (!next) break;
67
68 Int_t channel = input.Strip();
69 Int_t sample = input.Sample();
70 inputData[channel * sampleRate + sample] = input.Count();
71 count++;
72
73 Int_t in = inputData[channel * sampleRate + sample];
74 Int_t out = outData[channel * sampleRate + sample];
75 std::cout << "[\t" << channel << ",\t" << sample << "]\t"
76 << out << "\t" << in << std::flush;
77 if (out >= threshold && in != out) std::cout << "\tBad" << std::flush;
78 std::cout << std::endl;
79 }
80
81 std::cout << "Read " << count << " values" << std::endl;
82#if 1
83 for (Int_t channel = channelWidth - 1; channel > 0; channel--) {
84 for (Int_t sample = sampleRate - 1; sample > 0; sample--) {
85 Int_t in = inputData[channel * sampleRate + sample];
86 Int_t out = outData[channel * sampleRate + sample];
87 std::cout << "[\t" << channel << ",\t" << sample << "]\t"
88 << out << "\t" << in << std::flush;
89 if (out >= threshold && in != out) std::cout << "\tBad" << std::flush;
90 std::cout << std::endl;
91 }
92 }
93#endif
94}
95
96
97
98
99
100
101
102
103