1 #if !defined(__CINT__) || defined(__MAKECINT__)
4 #include "TClonesArray.h"
6 // AliRoot include files
10 #include "AliRawReader.h"
11 #include "AliRawReaderFile.h"
13 #include "AliTOFrawData.h"
14 #include "AliTOFRawMap.h"
15 #include "AliTOFRawStream.h"
21 void AliTOFReadRawData(const char *input, const Int_t evIn, const Char_t *outFile, Int_t runNumber=137366,Int_t decoderVersion=2);
23 void AliTOFReadRawData(const char *input, const Int_t evIn, const Char_t *outFile, Int_t runNumber, Int_t decoderVersion)
27 // To read TOF raw data
30 AliCDBManager *cdb = AliCDBManager::Instance();
31 cdb->SetDefaultStorage("raw://");
32 cdb->SetRun(runNumber);
34 AliGeomManager::LoadGeometry();
35 AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF HMPID PHOS EMCAL T0 VZERO FMD PMD MUON ZDC");
37 AliTOFcalib *fTOFcalib = new AliTOFcalib();
41 AliTOFHitData *HitData;
42 AliTOFHitDataBuffer *DataBuffer;
43 AliTOFHitDataBuffer *PackedDataBuffer;
45 /* create a tree for decoded data */
46 TTree DataTree("DataTree", "Decoded Data");
47 DataTree.Branch("HitData", "AliTOFHitData", &HitData);
49 /* create a tree for decoded packed data */
50 TTree PackedDataTree("PackedDataTree", "Decoded Packed Data");
51 PackedDataTree.Branch("HitData", "AliTOFHitData", &HitData);
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);
64 TClonesArray *clonesRawData = new TClonesArray("AliTOFrawData",1000);
65 AliTOFRawStream stream;
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);
77 stream.SetRawReader(reader);
79 //reader->RewindEvents();
81 UInt_t timeStamp = reader->GetTimestamp();
83 gBenchmark->Start("time");
86 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
90 /* reset buffers (actually not needed)*/
91 stream.ResetBuffers();
93 switch(decoderVersion) {
95 stream.LoadRawDataBuffers(iDDL,0);
98 stream.LoadRawDataBuffersV2(iDDL,0);
101 stream.LoadRawData(iDDL);
105 clonesRawData = (TClonesArray*)stream.GetRawData();
106 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
108 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
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;
118 /* check valid index */
119 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
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
130 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
132 /* check channel enabled */
133 //if (!fTOFcalib->IsChannelEnabled(index)) continue; // bad channels
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;
146 Float_t corr = fTOFcalib->GetTimeCorrection(index, tot, deltaBC, l0l1, timeStamp); /* ps */
148 /* apply time correction */
154 << " " << fTOFcalib->IsChannelEnabled(index)
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);
169 //if (fTOFcalib->IsChannelEnabled(index) == 1) {
170 sector = detectorIndex[0];
171 strip = detectorIndex[2];
172 padx = detectorIndex[4];
173 padz = detectorIndex[3];
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);
178 ftxt.open(outFile,ios::app);
179 ftxt << time << " " << timeRaw << " " << tot << " " << sector
180 << " " << strip << " " << padx << " " << padz
181 << " " << xHit << " " << yHit << " " << zHit << endl;
187 } // closed loop on TOF raw data per current DDL file
189 clonesRawData->Clear();
196 DataBuffer = stream.GetDataBuffer(iDDL);
197 PackedDataBuffer = stream.GetPackedDataBuffer(iDDL);
199 // get buffer entries
200 Int_t nDBEntries = DataBuffer->GetEntries();
201 Int_t nPDBEntries = PackedDataBuffer->GetEntries();
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());
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();
224 PackedDataBuffer->Reset();
230 printf("noise %d\n",countNoise);
231 gBenchmark->Print("time");
234 TFile fileOut("TOF_rawQA.root", "RECREATE");
236 PackedDataTree.Write();