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