forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAliTOFReadRawData.C
240 lines (183 loc) · 6.51 KB
/
AliTOFReadRawData.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#if !defined(__CINT__) || defined(__MAKECINT__)
// Root include files
#include "TClonesArray.h"
// AliRoot include files
#include "AliDAQ.h"
#include "AliHitMap.h"
#include "AliRawReader.h"
#include "AliRawReaderFile.h"
#include "AliTOFrawData.h"
#include "AliTOFRawMap.h"
#include "AliTOFRawStream.h"
#endif
extern gBenchmark;
void AliTOFReadRawData(const char *input, const Int_t evIn, const Char_t *outFile, Int_t runNumber=137366,Int_t decoderVersion=2);
void AliTOFReadRawData(const char *input, const Int_t evIn, const Char_t *outFile, Int_t runNumber, Int_t decoderVersion)
{
//
// To read TOF raw data
//
AliCDBManager *cdb = AliCDBManager::Instance();
cdb->SetDefaultStorage("raw://");
cdb->SetRun(runNumber);
AliGeomManager::LoadGeometry();
AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF HMPID PHOS EMCAL T0 VZERO FMD PMD MUON ZDC");
AliTOFcalib *fTOFcalib = new AliTOFcalib();
fTOFcalib->Init();
Int_t Volume[5];
AliTOFHitData *HitData;
AliTOFHitDataBuffer *DataBuffer;
AliTOFHitDataBuffer *PackedDataBuffer;
/* create a tree for decoded data */
TTree DataTree("DataTree", "Decoded Data");
DataTree.Branch("HitData", "AliTOFHitData", &HitData);
/* create a tree for decoded packed data */
TTree PackedDataTree("PackedDataTree", "Decoded Packed Data");
PackedDataTree.Branch("HitData", "AliTOFHitData", &HitData);
AliRawReader *reader;
TString fileName(input);
if (fileName.EndsWith("/")) {
reader = new AliRawReaderFile(fileName);
} else if (fileName.EndsWith(".root")) {
reader = new AliRawReaderRoot(fileName);
} else if (!fileName.IsNull()) {
reader = new AliRawReaderDate(fileName);
reader->SelectEvents(7);
}
TClonesArray *clonesRawData = new TClonesArray("AliTOFrawData",1000);
AliTOFRawStream stream;
gBenchmark->Reset();
Int_t countNoise = 0;
/* loop over events */
for (Int_t iEvent = 0; reader->NextEvent(); iEvent++) {
if (iEvent!=evIn) continue;
printf("processing event %d\n", iEvent);
stream.Clear();
stream.SetRawReader(reader);
//reader->RewindEvents();
UInt_t timeStamp = reader->GetTimestamp();
gBenchmark->Start("time");
/* loop over DDLs */
for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
reader->Reset();
/* reset buffers (actually not needed)*/
stream.ResetBuffers();
switch(decoderVersion) {
case 1:
stream.LoadRawDataBuffers(iDDL,0);
break;
case 2:
stream.LoadRawDataBuffersV2(iDDL,0);
break;
case 0:
stream.LoadRawData(iDDL);
break;
}
clonesRawData = (TClonesArray*)stream.GetRawData();
for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
if (tofRawDatum->GetTOF()==-1) continue;
Int_t detectorIndex[5]={-1,-1,-1,-1,-1};
stream.EquipmentId2VolumeId(iDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
Int_t dummy = detectorIndex[3];
detectorIndex[3] = detectorIndex[4];
detectorIndex[4] = dummy;
/* check valid index */
if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
// Do not reconstruct anything in the holes
if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
if (detectorIndex[1]==2) { // plate with holes
inholes++;
continue;
}
}
Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
/* check channel enabled */
//if (!fTOFcalib->IsChannelEnabled(index)) continue; // bad channels
/* get cluster info */
Float_t tot = tofRawDatum->GetTOT() * AliTOFGeometry::ToTBinWidth() * 1.e-3; /* ns */
Float_t timeRaw = tofRawDatum->GetTOF() * AliTOFGeometry::TdcBinWidth(); /* ps */
Float_t time = tofRawDatum->GetTOF() * AliTOFGeometry::TdcBinWidth(); /* ps */
Float_t deltaBC = tofRawDatum->GetDeltaBC(); // deltaBC
Float_t l0l1 = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
Float_t xHit, yHit, zHit;
Int_t sector, strip, padx, padz;
ofstream ftxt;
/* get correction */
Float_t corr = fTOFcalib->GetTimeCorrection(index, tot, deltaBC, l0l1, timeStamp); /* ps */
/* apply time correction */
time -= corr;
//if (iEvent==12)
#if 0
cout << " " << index
<< " " << fTOFcalib->IsChannelEnabled(index)
<< " " << tot
<< " " << timeRaw
<< " " << time
<< endl;
#endif
/* geometry */
AliTOFGeometry geo;
for (Int_t j=0; j<5; j++) detectorIndex[j] = -1;
geo.GetVolumeIndices(index, detectorIndex);
xHit = geo.GetX(detectorIndex);
yHit = geo.GetY(detectorIndex);
zHit = geo.GetZ(detectorIndex);
//if (fTOFcalib->IsChannelEnabled(index) == 1) {
sector = detectorIndex[0];
strip = detectorIndex[2];
padx = detectorIndex[4];
padz = detectorIndex[3];
//printf("x %f, y %f, z %f\n",xHit,yHit,zHit);
//printf("sector %d, strip %d, padx %d, padz %d\n",sector,strip,padx,padz);
#if 1
ftxt.open(outFile,ios::app);
ftxt << time << " " << timeRaw << " " << tot << " " << sector
<< " " << strip << " " << padx << " " << padz
<< " " << xHit << " " << yHit << " " << zHit << endl;
ftxt.close();
#endif
//}
//else countNoise++;
} // closed loop on TOF raw data per current DDL file
clonesRawData->Clear();
/*
// read decoded data
DataBuffer = stream.GetDataBuffer(iDDL);
PackedDataBuffer = stream.GetPackedDataBuffer(iDDL);
// get buffer entries
Int_t nDBEntries = DataBuffer->GetEntries();
Int_t nPDBEntries = PackedDataBuffer->GetEntries();
// read data buffer hits
for (Int_t iHit = 0; iHit < nDBEntries; iHit++){
HitData = DataBuffer->GetHit(iHit);
HitData->SetDDLID(iDDL);
// add volume information to hit
stream.EquipmentId2VolumeId(HitData, HitData->GetVolume());
DataTree.Fill();
}
// reset buffer
DataBuffer->Reset();
// read data buffer hits
for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
HitData = PackedDataBuffer->GetHit(iHit);
HitData->SetDDLID(iDDL);
// add volume information to hit
stream.EquipmentId2VolumeId(HitData, HitData->GetVolume());
PackedDataTree.Fill();
}
// reset buffer
PackedDataBuffer->Reset();
*/
} // loop on DDLs
}
printf("noise %d\n",countNoise);
gBenchmark->Print("time");
/*
TFile fileOut("TOF_rawQA.root", "RECREATE");
DataTree.Write();
PackedDataTree.Write();
fileOut.Close();
*/
}