]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFRawStream.cxx
c Version 1.38
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.cxx
CommitLineData
571dda3d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
d0eb8f39 17$Log$
08d6922f 18
19Added lookup tables for
20 TRM number 3 in the left crates (TOF OR signals)
21 and detector elements (A.Silenzi)
22
dd824655 23Revision 1.19.1 2008/09/19 preghenella
24 Decode method updated:
25 it reads the CDH from the rawReader and sends it to the decoder;
26 LoadRawDataBuffers modified:
27 it corrects tof hit infos per ddlBC and deltaBC offsets
28 (in case of the static member fgApplyBCCorrections
29 has been setted to kTRUE);
30 Added static member fgApplyBCCorrections (kTRUE by default)
31 and the related static method ApplyBCCorrections;
32
96f01799 33Revision 1.19 2007/05/18 13:07:53 decaro
34Error messages stored in the global raw-reader error log (Cvetan, Chiara)
35
019f6101 36Revision 1.18 2007/05/08 11:53:29 arcelli
37Improved class flexibility for further use (R.Preghenella)
38
2fd622fa 39Revision 1.17 2007/05/03 08:53:50 decaro
40Coding convention: RS3 violation -> suppression
41
19eefa2b 42Revision 1.16 2007/05/03 08:22:22 decaro
43Coding convention: RN17 violation -> suppression
44
dfcee998 45Revision 1.15 2007/04/30 15:22:06 arcelli
46Change TOF digit Time, Tot etc to int type
47
bf33f8f0 48Revision 1.14 2007/04/27 11:11:53 arcelli
49updates for the new decoder
50
dfcee998 51Revision 1.13 2007/03/16 11:46:35 decaro
52Coding convention: RN17 rule violation -> suppression
53
8994284f 54Revision 1.12 2007/02/22 09:43:45 decaro
55Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
56
740f0695 57Revision 1.11 2007/02/20 15:57:00 decaro
58Raw data update: to read the TOF raw data defined in UNPACKED mode
59
15ec34b9 60Revision 1.10 2006/12/15 14:01:38 cvetan
61Memory leak fixed
62
f1aa96cc 63Revision 1.9 2006/10/13 11:22:27 arcelli
64remove warnings due to uninitialized AliTOFtdcDigit data members
65
36f66fad 66Revision 1.8 2006/08/22 13:30:17 arcelli
67removal of effective c++ warnings (C.Zampolli)
68
655e379f 69Revision 1.7 2006/08/10 14:46:54 decaro
70TOF raw data format: updated version
71
d0eb8f39 72Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
73 Update TOF raw data format
74 according to the final version
75 (see the ALICE internal note in preparation
76 'ALICE TOF raw data format')
77 Added the methods for the correspoonding numbering
78 between the equipment IDs and the volume IDs:
79 Equip2VolNPlate(...)
80 Equip2VolNStrip(...)
81 Equip2VolNPad(...)
82
571dda3d 83Revision 0.02 2005/07/28 A. De Caro:
84 Update format TOF raw data
85 (temporary solution)
86 Correction of few wrong corrispondences
87 between 'software' and 'hardware' numberings
88
89Revision 0.01 2005/07/22 A. De Caro
90 Implement methods Next()
91 GetSector(),
92 GetPlate(),
93 GetStrip(),
94 GetPadZ(),
95 GetPadX()
96*/
97
0e46b9ae 98////////////////////////////////////////////////////////////////////////
99// //
100// This class provides access to TOF raw data in DDL files. //
101// //
102// It loops over all TOF raw data given by the AliRawReader. //
103// //
104////////////////////////////////////////////////////////////////////////
571dda3d 105
15ec34b9 106
13d6bff9 107#include "Riostream.h"
108
15ec34b9 109#include "TClonesArray.h"
f472295e 110#include "TStopwatch.h"
15ec34b9 111
112#include "AliDAQ.h"
d0eb8f39 113#include "AliLog.h"
571dda3d 114#include "AliRawReader.h"
115
116#include "AliTOFGeometry.h"
15ec34b9 117#include "AliTOFrawData.h"
118#include "AliTOFRawMap.h"
571dda3d 119#include "AliTOFRawStream.h"
f472295e 120#include "AliTOFdigit.h"
121#include "AliTOFSDigit.h"
32ead898 122//#include "AliTOFCableLengthMap.h"
571dda3d 123
5c7c93fa 124#include "AliTOFHitData.h"
d0eb8f39 125
32ead898 126#include "AliRawEventHeaderBase.h"
143cfc81 127#include "AliRawDataHeader.h"
32ead898 128
571dda3d 129ClassImp(AliTOFRawStream)
130
32ead898 131const Int_t AliTOFRawStream::fgkddlBCshift[72] =
132{
e7f49164 133 0, 0, 0, 0,
134 0, 0, 0, 0,
135 0, 0, 0, 0,
136 0, 0, 0, 0,
137 0, 0, 0, 0,
138 0, 0, 0, 0,
139 0, 0, 0, 0,
140 0, 0, 0, 0,
141 0, 0, 0, 0,
142 0, 0, 0, 0,
143 0, 0, 0, 0,
144 0, 0, 0, 0,
145 0, 0, 0, 0,
146 0, 0, 0, 0,
147 0, 0, 0, 0,
148 0, 0, 0, 0,
149 0, 0, 0, 0,
150 0, 0, 0, 0
32ead898 151};
152
08d6922f 153const Int_t AliTOFRawStream::fgkStrip0MapCrate0[]=
4306fa22 154 {1,3,5,7,9,11,13,15,17,0,2,4,6,8,10,12,14,16,18,1,3,5,7,-1};
08d6922f 155const Int_t AliTOFRawStream::fgkStrip1MapCrate0[]=
4306fa22 156 {0,2,4,6,8,10,12,14,16,18,1,3,5,7,9,11,13,15,17,0,2,4,6,-1};
08d6922f 157const Int_t AliTOFRawStream::fgkStrip0MapCrate1[]=
4306fa22 158 {1,3,5,7,9,11,13,15,17,0,2,4,6,8,10,12,14,16,18,1,3,5,7,-1};
08d6922f 159const Int_t AliTOFRawStream::fgkStrip1MapCrate1[]=
4306fa22 160 {0,2,4,6,8,10,12,14,16,18,1,3,5,7,9,11,13,15,17,0,2,4,6,-1};
08d6922f 161const Int_t AliTOFRawStream::fgkStrip0MapCrate2[]=
4306fa22 162 {17,15,13,11, 9,7,5,3,1,18,16,14,12,10,8,6,4,2, 0,13,11, 9,7,-1};
08d6922f 163const Int_t AliTOFRawStream::fgkStrip1MapCrate2[]=
4306fa22 164 {18,16,14,12,10,8,6,4,2, 0,17,15,13,11,9,7,5,3, 1,14,12,10,8,-1};
08d6922f 165const Int_t AliTOFRawStream::fgkStrip0MapCrate3[]=
4306fa22 166 {17,15,13,11, 9,7,5,3,1,18,16,14,12,10,8,6,4,2, 0,13,11, 9,7,-1};
08d6922f 167const Int_t AliTOFRawStream::fgkStrip1MapCrate3[]=
4306fa22 168 {18,16,14,12,10,8,6,4,2, 0,17,15,13,11,9,7,5,3, 1,14,12,10,8,-1};
08d6922f 169
170
171const Int_t AliTOFRawStream::fgkModule0MapCrate0[]=
4306fa22 172 {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
08d6922f 173const Int_t AliTOFRawStream::fgkModule1MapCrate0[]=
4306fa22 174 {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
08d6922f 175const Int_t AliTOFRawStream::fgkModule0MapCrate1[]=
4306fa22 176 {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
08d6922f 177const Int_t AliTOFRawStream::fgkModule1MapCrate1[]=
4306fa22 178 {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
179
08d6922f 180const Int_t AliTOFRawStream::fgkModule0MapCrate2[]=
4306fa22 181 {4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
08d6922f 182const Int_t AliTOFRawStream::fgkModule1MapCrate2[]=
4306fa22 183 {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
08d6922f 184const Int_t AliTOFRawStream::fgkModule0MapCrate3[]=
4306fa22 185 {4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
08d6922f 186const Int_t AliTOFRawStream::fgkModule1MapCrate3[]=
4306fa22 187 {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
08d6922f 188
189const Int_t AliTOFRawStream::fgkChannelMap0[5][19]=
4306fa22 190 {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
191 {9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18},
192 {19,19,20,20,21,21,22,22,22,21,21,20,20,19,19,-1,-1,-1,-1},
193 {18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9},
08d6922f 194 {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
195 };
196
197const Int_t AliTOFRawStream::fgkChainMap0[5][19]=
4306fa22 198 {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
199 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
200 {0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,-1,-1,-1,-1},
201 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
202 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
203 };
08d6922f 204
205const Int_t AliTOFRawStream::fgkChannelMap24[5][19]=
4306fa22 206 {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
207 {9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18},
208 {19,19,20,20,21,21,22,22,22,21,21,20,20,19,19,-1,-1,-1,-1},
209 {18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9},
210 {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
211 };
08d6922f 212
213const Int_t AliTOFRawStream::fgkChainMap24[5][19]=
4306fa22 214 {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
215 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
216 {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,-1,-1,-1,-1},
217 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
218 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
219 };
08d6922f 220
dd824655 221Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
571dda3d 222//_____________________________________________________________________________
655e379f 223AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
15ec34b9 224 fRawReader(rawReader),
2bf66a2d 225 fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
7813bb1a 226 fDecoder(new AliTOFDecoder()),
655e379f 227 fDDL(-1),
228 fTRM(-1),
655e379f 229 fTRMchain(-1),
15ec34b9 230 fTDC(-1),
655e379f 231 fTDCchannel(-1),
15ec34b9 232 fTime(-1),
655e379f 233 fToT(-1),
15ec34b9 234 fLeadingEdge(-1),
235 fTrailingEdge(-1),
655e379f 236 fErrorFlag(-1),
655e379f 237 fSector(-1),
238 fPlate(-1),
239 fStrip(-1),
240 fPadX(-1),
241 fPadZ(-1),
15ec34b9 242 fPackedDigits(0),
655e379f 243 fWordType(-1),
244 fSlotID(-1),
245 fACQ(-1),
246 fPSbit(-1),
655e379f 247 fTDCerrorFlag(-1),
248 fInsideDRM(kFALSE),
249 fInsideTRM(kFALSE),
250 fInsideLTM(kFALSE),
251 fInsideTRMchain0(kFALSE),
38f24f3f 252 fInsideTRMchain1(kFALSE),
5042b04a 253 //fDataBuffer(),
254 //fPackedDataBuffer(),
38f24f3f 255 fLocalEventCounterDRM(-1),
256 fLocalEventCounterLTM(-1),
5042b04a 257 //fLocalEventCounterTRM(),
258 //fLocalEventCounterChain(),
259 //fChainBunchID(),
04bacbd9 260 //fCableLengthMap(new AliTOFCableLengthMap()),
f472295e 261 fEventID(0),
262 fNewDecoderVersion(0)
571dda3d 263{
264 //
265 // create an object to read TOF raw digits
266 //
267
7813bb1a 268 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
d35d0ea0 269 ResetDataBuffer(i);
270 ResetPackedDataBuffer(i);
7813bb1a 271 }
272
2bf66a2d 273 //fTOFrawData = new TClonesArray("AliTOFrawData",1000);
7813bb1a 274 fTOFrawData->SetOwner();
275
15ec34b9 276 fRawReader->Reset();
362c9d61 277 fRawReader->Select("TOF");
38f24f3f 278
e1d95075 279 for (Int_t jj=0;jj<13;jj++) {
280 fLocalEventCounterTRM[jj] = -1;
281 for (Int_t ii=0;ii<2;ii++) {
282 fLocalEventCounterChain[jj][ii] = -1;
283 fChainBunchID[jj][ii] = -1;
ca6d7f17 284 }
285 }
38f24f3f 286
571dda3d 287}
288
289//_____________________________________________________________________________
655e379f 290AliTOFRawStream::AliTOFRawStream():
2bf66a2d 291 fRawReader(0x0),
292 fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
7813bb1a 293 fDecoder(new AliTOFDecoder()),
655e379f 294 fDDL(-1),
295 fTRM(-1),
655e379f 296 fTRMchain(-1),
15ec34b9 297 fTDC(-1),
655e379f 298 fTDCchannel(-1),
15ec34b9 299 fTime(-1),
655e379f 300 fToT(-1),
15ec34b9 301 fLeadingEdge(-1),
302 fTrailingEdge(-1),
655e379f 303 fErrorFlag(-1),
655e379f 304 fSector(-1),
305 fPlate(-1),
306 fStrip(-1),
307 fPadX(-1),
308 fPadZ(-1),
15ec34b9 309 fPackedDigits(0),
655e379f 310 fWordType(-1),
311 fSlotID(-1),
312 fACQ(-1),
313 fPSbit(-1),
655e379f 314 fTDCerrorFlag(-1),
315 fInsideDRM(kFALSE),
316 fInsideTRM(kFALSE),
317 fInsideLTM(kFALSE),
318 fInsideTRMchain0(kFALSE),
38f24f3f 319 fInsideTRMchain1(kFALSE),
5042b04a 320 //fDataBuffer(),
321 //fPackedDataBuffer(),
38f24f3f 322 fLocalEventCounterDRM(-1),
323 fLocalEventCounterLTM(-1),
5042b04a 324 //fLocalEventCounterTRM(),
325 //fLocalEventCounterChain(),
326 //fChainBunchID(),
04bacbd9 327 //fCableLengthMap(new AliTOFCableLengthMap()),
f472295e 328 fEventID(0),
329 fNewDecoderVersion(0)
571dda3d 330{
331 //
d0eb8f39 332 // default ctr
571dda3d 333 //
7813bb1a 334 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
d35d0ea0 335 ResetDataBuffer(i);
336 ResetPackedDataBuffer(i);
7813bb1a 337 }
15ec34b9 338
2bf66a2d 339 //fTOFrawData = new TClonesArray("AliTOFrawData",1000);
7813bb1a 340 fTOFrawData->SetOwner();
38f24f3f 341
ca6d7f17 342 for (Int_t j=0;j<13;j++){
343 fLocalEventCounterTRM[j] = -1;
ca6d7f17 344 for (Int_t k=0;k<2;k++){
345 fLocalEventCounterChain[j][k] = -1;
346 fChainBunchID[j][k] = -1;
347 }
348 }
38f24f3f 349
d0eb8f39 350}
351
352//_____________________________________________________________________________
353AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
655e379f 354 TObject(stream),
8a190ba2 355 fRawReader(stream.fRawReader),
356 fTOFrawData(stream.fTOFrawData),
7813bb1a 357 fDecoder(new AliTOFDecoder()),
8a190ba2 358 fDDL(stream.fDDL),
359 fTRM(stream.fTRM),
360 fTRMchain(stream.fTRMchain),
361 fTDC(stream.fTDC),
362 fTDCchannel(stream.fTDCchannel),
363 fTime(stream.fTime),
364 fToT(-stream.fToT),
365 fLeadingEdge(stream.fLeadingEdge),
366 fTrailingEdge(stream.fTrailingEdge),
367 fErrorFlag(stream.fErrorFlag),
368 fSector(stream.fSector),
369 fPlate(stream.fPlate),
370 fStrip(stream.fStrip),
371 fPadX(stream.fPadX),
372 fPadZ(stream.fPadZ),
373 fPackedDigits(stream.fPackedDigits),
374 fWordType(stream.fWordType),
375 fSlotID(stream.fSlotID),
376 fACQ(stream.fACQ),
377 fPSbit(stream.fPSbit),
378 fTDCerrorFlag(stream.fTDCerrorFlag),
379 fInsideDRM(stream.fInsideDRM),
380 fInsideTRM(stream.fInsideTRM),
381 fInsideLTM(stream.fInsideLTM),
382 fInsideTRMchain0(stream.fInsideTRMchain0),
383 fInsideTRMchain1(stream.fInsideTRMchain1),
5042b04a 384 //fDataBuffer(),
385 //fPackedDataBuffer(),
8a190ba2 386 fLocalEventCounterDRM(stream.fLocalEventCounterDRM),
387 fLocalEventCounterLTM(stream.fLocalEventCounterLTM),
5042b04a 388 //fLocalEventCounterTRM(),
389 //fLocalEventCounterChain(),
390 //fChainBunchID(),
04bacbd9 391 //fCableLengthMap(stream.fCableLengthMap),
f472295e 392 fEventID(stream.fEventID),
393 fNewDecoderVersion(stream.fNewDecoderVersion)
d0eb8f39 394{
395 //
396 // copy constructor
397 //
398
7813bb1a 399 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
d35d0ea0 400 fDataBuffer[i] = stream.fDataBuffer[i];
401 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
7813bb1a 402 }
403
404 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
38f24f3f 405
ca6d7f17 406 for (Int_t j=0;j<13;j++){
407 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
408 for (Int_t k=0;k<2;k++){
409 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
410 fChainBunchID[j][k] = stream.fChainBunchID[j][k];
411 }
412 }
38f24f3f 413
571dda3d 414}
415
416//_____________________________________________________________________________
417AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
418{
419 //
420 // assignment operator
421 //
422
8a190ba2 423 if (this == &stream)
424 return *this;
425
426 TObject::operator=(stream);
427
571dda3d 428 fRawReader = stream.fRawReader;
15ec34b9 429
430 fTOFrawData = stream.fTOFrawData;
431
571dda3d 432 fDDL = stream.fDDL;
433 fTRM = stream.fTRM;
d0eb8f39 434 fTRMchain = stream.fTRMchain;
15ec34b9 435 fTDC = stream.fTDC;
d0eb8f39 436 fTDCchannel = stream.fTDCchannel;
15ec34b9 437 fTime = stream.fTime;
d0eb8f39 438 fToT = stream.fToT;
15ec34b9 439 fLeadingEdge = stream.fLeadingEdge;
440 fTrailingEdge = stream.fTrailingEdge;
571dda3d 441 fErrorFlag = stream.fErrorFlag;
d0eb8f39 442
443 fSector = stream.fSector;
444 fPlate = stream.fPlate;
445 fStrip = stream.fStrip;
446 fPadX = stream.fPadX;
447 fPadZ = stream.fPadZ;
571dda3d 448
15ec34b9 449 fPackedDigits = stream.fPackedDigits;
450
d0eb8f39 451 fWordType = stream.fWordType;
452 fSlotID = stream.fSlotID;
453 fACQ = stream.fACQ;
454 fPSbit = stream.fPSbit;
d0eb8f39 455 fTDCerrorFlag = stream.fTDCerrorFlag;
456 fInsideDRM = stream.fInsideDRM;
457 fInsideTRM = stream.fInsideTRM;
458 fInsideLTM = stream.fInsideLTM;
459 fInsideTRMchain0 = stream.fInsideTRMchain0;
460 fInsideTRMchain1 = stream.fInsideTRMchain1;
4306fa22 461
7813bb1a 462 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
463 fDataBuffer[i] = stream.fDataBuffer[i];
464 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
465 }
466
467 fTOFrawData = stream.fTOFrawData;
38f24f3f 468
ca6d7f17 469 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;
470 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;
471 for (Int_t j=0;j<13;j++){
472 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
473 for (Int_t k=0;k<2;k++){
474 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
475 fChainBunchID[j][k] = stream.fChainBunchID[j][k];
476 }
477 }
38f24f3f 478
04bacbd9 479 //fCableLengthMap = stream.fCableLengthMap;
32ead898 480
481 fEventID = stream.fEventID;
f472295e 482 fNewDecoderVersion = stream.fNewDecoderVersion;
32ead898 483
571dda3d 484 return *this;
485
486}
487
488//_____________________________________________________________________________
489AliTOFRawStream::~AliTOFRawStream()
490{
4306fa22 491 // destructor
571dda3d 492
15ec34b9 493 fPackedDigits = 0;
494
7813bb1a 495 delete fDecoder;
15ec34b9 496
7813bb1a 497 fTOFrawData->Clear();
498 delete fTOFrawData;
38f24f3f 499
04bacbd9 500 //delete fCableLengthMap;
38f24f3f 501
571dda3d 502}
503
504
15ec34b9 505//_____________________________________________________________________________
506
507void AliTOFRawStream::LoadRawData(Int_t indexDDL)
508{
0192b95f 509 //
510 // To load raw data
511 //
15ec34b9 512
e7f49164 513 fEventID = (Int_t)fRawReader->GetBCID(); //bunch crossing
514
74cd22f8 515 fTOFrawData->Clear();
0192b95f 516
74cd22f8 517 TClonesArray &arrayTofRawData = *fTOFrawData;
518
15ec34b9 519 fPackedDigits = 0;
520
521 // create raw data map
66eae3f0 522 AliTOFRawMap rawMap(fTOFrawData);
523 rawMap.Clear();
15ec34b9 524
525 Int_t slot[4] = {-1, -1, -1, -1};
526
415c84fa 527 fLocalEventCounterDRM = -1;
528 fLocalEventCounterLTM = -1;
529 for (Int_t ii=0; ii<13; ii++)
530 fLocalEventCounterTRM[ii] = -1;
531 for (Int_t ii=0; ii<13; ii++)
5042b04a 532 for (Int_t jj=0; jj<2; jj++) {
415c84fa 533 fLocalEventCounterChain[ii][jj] = -1;
5042b04a 534 fChainBunchID[ii][jj] = -1;
535 }
415c84fa 536
15ec34b9 537 fRawReader->Reset();
538 fRawReader->Select("TOF", indexDDL, indexDDL);
539
540 Bool_t signal = kFALSE;
541
74cd22f8 542 AliTOFrawData *rawDigit = NULL;
7813bb1a 543
15ec34b9 544 while(Next()) {
545
546 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
547 if (signal) {
38f24f3f 548 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
15ec34b9 549
550 slot[0] = fTRM;
551 slot[1] = fTRMchain;
552 slot[2] = fTDC;
553 slot[3] = fTDCchannel;
554
66eae3f0 555 if (rawMap.TestHit(slot) != kEmpty) {
15ec34b9 556
66eae3f0 557 rawDigit = static_cast<AliTOFrawData*>(rawMap.GetHit(slot));
15ec34b9 558
559 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
560 fLeadingEdge==-1 && fTrailingEdge!=-1) {
561
562 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
563 }
564 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
565 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
566
0192b95f 567 )
15ec34b9 568 {
569
74cd22f8 570 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
15ec34b9 571
66eae3f0 572 rawMap.SetHit(slot);
15ec34b9 573
74cd22f8 574 }
15ec34b9 575
576
577 }
578 else {
579
15ec34b9 580 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
581
66eae3f0 582 rawMap.SetHit(slot);
15ec34b9 583
66eae3f0 584 } // else if (rawMap.TestHit(slot) == kEmpty)
15ec34b9 585
586 } // if (signal)
587
588 } // closed -> while (Next())
589
15ec34b9 590}
591
571dda3d 592//_____________________________________________________________________________
593Bool_t AliTOFRawStream::Next()
594{
d0eb8f39 595 //
596 // Read next 32-bit word in TOF raw data files
597 // returns kFALSE if there is no word left
598 //
571dda3d 599
600 UInt_t data;
601
38f24f3f 602 Int_t dummy = 0;
603
571dda3d 604 if (!fRawReader->ReadNextInt(data)) return kFALSE;
605
d0eb8f39 606 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
607 fSector = -1;
15ec34b9 608 fPlate = -1;
609 fStrip = -1;
610 fPadZ = -1;
611 fPadX = -1;
612 fTime = -1;
613 fToT = -1;
614 fLeadingEdge = -1;
615 fTrailingEdge = -1;
d0eb8f39 616 }
571dda3d 617
571dda3d 618 fDDL = fRawReader->GetDDLID();
619
d0eb8f39 620 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
621
622 switch (fWordType) { // switch word type
623
624 case GLOBAL_HEADER_TYPE: // global header
625 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
626 fTRM = fSlotID;
627
628
629 switch (fSlotID) { // switch global header slot ID
630
631 case DRM_ID_NUMBER: //DRM global header
632 if (fInsideDRM) { // unexpected DRM global headers -> exit
633 break;
634 }
635 fInsideDRM = kTRUE; // DRM global header accepted
636 break;
637
638 case LTM_ID_NUMBER: // LTM global header
639 if (fInsideLTM) { // unexpected LTM global headers -> exit
640 break;
641 }
642 fInsideLTM = kTRUE; // LTM global header accepted
643 break;
644
645 case 3: //TRM header
646 case 4: //TRM header
647 case 5: //TRM header
648 case 6: //TRM header
649 case 7: //TRM header
650 case 8: //TRM header
651 case 9: //TRM header
652 case 10: //TRM header
653 case 11: //TRM header
654 case 12: //TRM header
655 if (fInsideTRM) { // unexpected TRM global headers -> exit
656 break;
657 }
658 fInsideTRM = kTRUE; // TRM global header accepted
659 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
660 break;
661
662 default: // unexpected global header slot ID
663 break;
664
665 } //end switch global header slot id
666
667 break;
668
669
670 case GLOBAL_TRAILER_TYPE: // global trailer
671 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
d0eb8f39 672
673 switch (fSlotID) { // switch global trailer slot ID
674
675 case DRM_ID_NUMBER: // DRM global trailer
676 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
677 break;
678 }
38f24f3f 679 dummy = 0x0000fff0;
680 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
ca6d7f17 681 fLocalEventCounterDRM = GetField(data,dummy,4);
d0eb8f39 682 fInsideDRM = kFALSE; // DRM global trailer accepted
683 fInsideTRM = kFALSE;
684 fInsideLTM = kFALSE;
685 fInsideTRMchain0 = kFALSE;
686 fInsideTRMchain1 = kFALSE;
d0eb8f39 687 fSector = -1;
15ec34b9 688 fPlate = -1;
689 fStrip = -1;
690 fPadZ = -1;
691 fPadX = -1;
692 fDDL = -1;
693 fTRM = -1;
694 fTDC = -1;
695 fTRMchain = -1;
d0eb8f39 696 fTDCchannel = -1;
15ec34b9 697 fTime = -1;
698 fToT = -1;
699 fLeadingEdge = -1;
700 fTrailingEdge = -1;
d0eb8f39 701 fErrorFlag = -1;
15ec34b9 702 fACQ = -1;
d0eb8f39 703 fPSbit = -1;
d0eb8f39 704 fTDCerrorFlag = -1;
705 break;
706 case LTM_ID_NUMBER: // LTM global trailer
707 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
708 break;
709 }
38f24f3f 710 dummy = 0x0fff0000;
711 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 712 fLocalEventCounterLTM = GetField(data,dummy,16);
d0eb8f39 713 fInsideLTM = kFALSE; // LTM global trailer accepted
714 break;
715 case 15: //TRM global trailer
716 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
717 break;
718 }
38f24f3f 719 dummy = 0x0fff0000;
720 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 721 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);
d0eb8f39 722 fInsideTRM = kFALSE; // TRM global trailer accepted
723 break;
724 default: // unexpected global trailer slot ID
725 break;
726 } //end switch global trailer slot id
727
728
729 break;
730
731
732 case ERROR_TYPE: // TDC error
15ec34b9 733 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
d0eb8f39 734 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
735 break;
736
737
738 case FILLER_TYPE: // filler
739 break;
740
741
742 default: // other word types
743
744 if (fInsideTRM) { // inside TRM
745
746 switch (fWordType) { // switch word type inside TRM
747 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
748 if (fInsideTRMchain0) { // unexpected TRM chain0 header
749 break;
750 }
751 fInsideTRMchain0 = kTRUE;
752 fTRMchain = 0;
ca6d7f17 753 dummy = 0x0000fff0;
754 //AliInfo(Form(" chain bunch ID = %i", GetField(data,dummy,4)));
755 fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
d0eb8f39 756 break;
757 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
758 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
759 break;
760 }
38f24f3f 761 dummy = 0x0fff0000;
762 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 763 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
d0eb8f39 764 fInsideTRMchain0 = kFALSE;
765 fTRMchain = -1;
766 break;
767 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
768 if (fInsideTRMchain1) { // unexpected TRM chain1 header
769 break;
770 }
771 fInsideTRMchain1 = kTRUE;
772 fTRMchain = 1;
ca6d7f17 773 dummy = 0x0000fff0;
774 //AliInfo(Form(" chain bunch ID = %i", GetField(data,dummy,4)));
775 fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
d0eb8f39 776 break;
777 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
778 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
779 break;
780 }
38f24f3f 781 dummy = 0x0fff0000;
782 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
ca6d7f17 783 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
d0eb8f39 784 fInsideTRMchain1 = kFALSE;
785 fTRMchain = -1;
786 break;
787 } // end switch word type inside TRM
788
789 } // end if (fInsideTRM)
790
791
792 if (
793 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
794 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
795 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
796 ){ // inside TRM chains
15ec34b9 797
798 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
799 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
d0eb8f39 800 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
15ec34b9 801 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
802
803 SetSector();
804 SetPlate();
805 SetStrip();
806 SetPadZ();
807 SetPadX();
808
d0eb8f39 809
810 switch (fPSbit) { // switch fPSbit bits inside TRM chains
15ec34b9 811
812 case 0: // packing ok, digit time and TOT
813 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
32ead898 814 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
cfceaf15 815 /*-
816 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 817 ;
143cfc81 818 if (fgApplyBCCorrections) {
ca6d7f17 819 AliDebug(2,"Apply nominal DDL BC time-shift correction");
820 AliDebug(2,"Apply deltaBC time-shift correction");
821 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
e7f49164 822 fTime += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
143cfc81 823 }
d0eb8f39 824 break;
825
826 case 1: // leading edge digit, long digit time, no TOT
15ec34b9 827 //fToT = -1;
828 //fTime = -1;
32ead898 829 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
cfceaf15 830 /*-
831 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 832 ;
143cfc81 833 if (fgApplyBCCorrections) {
ca6d7f17 834 AliDebug(2,"Apply nominal DDL BC time-shift correction");
835 AliDebug(2,"Apply deltaBC time-shift correction");
836 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
e7f49164 837 fLeadingEdge += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
143cfc81 838 }
d0eb8f39 839 break;
840
841 case 2: // trailing edge digit, long digit time, no TOT
15ec34b9 842 //fToT = -1;
843 //fTime = -1;
32ead898 844 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
cfceaf15 845 /*-
846 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 847 ;
143cfc81 848 if (fgApplyBCCorrections) {
ca6d7f17 849 AliDebug(2,"Apply nominal DDL BC time-shift correction");
850 AliDebug(2,"Apply deltaBC time-shift correction");
851 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
e7f49164 852 fTrailingEdge += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
143cfc81 853 }
d0eb8f39 854 break;
15ec34b9 855
d0eb8f39 856 case 3: // TOT overflow
15ec34b9 857 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
32ead898 858 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
cfceaf15 859 /*-
860 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
32ead898 861 ;
143cfc81 862 if (fgApplyBCCorrections) {
ca6d7f17 863 AliDebug(2,"Apply nominal DDL BC time-shift correction");
864 AliDebug(2,"Apply deltaBC time-shift correction");
865 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
e7f49164 866 fTime += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
143cfc81 867 }
d0eb8f39 868 break;
d0eb8f39 869
15ec34b9 870 } // end switch PS bits inside TRM chains
d0eb8f39 871
872 } // end if is inside TRM chains
873
874 } // end switch on fWordType
571dda3d 875
15ec34b9 876
571dda3d 877 return kTRUE;
7813bb1a 878
571dda3d 879}
880//_____________________________________________________________________________
881
d0eb8f39 882void AliTOFRawStream::SetSector()
571dda3d 883{
884 //
d0eb8f39 885 // Evaluate the TOF sector number -> [ 0;17]
886 // corresponding to the TOF equipment IDs:
887 // fDDL -> [ 0;71]
888 // fTRM -> [ 3;12]
15ec34b9 889 // fTRMchain -> [ 0; 1]
d0eb8f39 890 // fTDC -> [ 0;14]
891 // fTDCchannel -> [ 0; 7]
571dda3d 892 //
893
894 Int_t iSector = -1;
571dda3d 895
d0eb8f39 896 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
897
898 fSector = iSector;
571dda3d 899
900}
901//_____________________________________________________________________________
902
d0eb8f39 903
904void AliTOFRawStream::SetPlate()
571dda3d 905{
906 //
d0eb8f39 907 // Evaluate the TOF plate number ->[ 0; 4]
908 // corresponding to the TOF equipment IDs:
909 // fDDL -> [ 0;71]
910 // fTRM -> [ 3;12]
15ec34b9 911 // fTRMchain -> [ 0; 1]
d0eb8f39 912 // fTDC -> [ 0;14]
913 // fTDCchannel -> [ 0; 7]
571dda3d 914 //
915
916 Int_t iPlate = -1;
d0eb8f39 917 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
918 || fSector==-1))
919 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 920
d0eb8f39 921 fPlate = iPlate;
571dda3d 922
923}
924//_____________________________________________________________________________
925
d0eb8f39 926void AliTOFRawStream::SetStrip()
571dda3d 927{
928 //
d0eb8f39 929 // Evaluate the TOF strip number per module -> [ 0; 14/18]
930 // corresponding to the TOF equipment IDs:
931 // fDDL -> [ 0;71]
932 // fTRM -> [ 3;12]
15ec34b9 933 // fTRMchain -> [ 0; 1]
d0eb8f39 934 // fTDC -> [ 0;14]
935 // fTDCchannel -> [ 0; 7]
571dda3d 936 //
937
938 Int_t iStrip = -1;
939
d0eb8f39 940 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
941 || fSector==-1 || fPlate==-1))
942 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 943
d0eb8f39 944 fStrip = iStrip;
571dda3d 945
946}
947//_____________________________________________________________________________
948
d0eb8f39 949void AliTOFRawStream::SetPadZ()
571dda3d 950{
951 //
d0eb8f39 952 // Evaluate the TOF padRow number per strip -> [ 0; 1]
953 // corresponding to the TOF equipment IDs:
954 // fDDL -> [ 0;71]
955 // fTRM -> [ 3;12]
15ec34b9 956 // fTRMchain -> [ 0; 1]
d0eb8f39 957 // fTDC -> [ 0;14]
958 // fTDCchannel -> [ 0; 7]
571dda3d 959 //
960
961 Int_t iPadZ = -1;
962
d0eb8f39 963 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
964 || fSector==-1 || fPlate==-1 || fStrip==-1))
965 {
966 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
967 if (iPadAlongTheStrip!=-1)
968 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
969 }
571dda3d 970
38f24f3f 971 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
972 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
973
d0eb8f39 974 fPadZ = iPadZ;
571dda3d 975
d0eb8f39 976}
977//_____________________________________________________________________________
978
979void AliTOFRawStream::SetPadX()
980{
981 //
982 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
983 // corresponding to the TOF equipment IDs:
984 // fDDL -> [ 0;71]
985 // fTRM -> [ 3;12]
15ec34b9 986 // fTRMchain -> [ 0; 1]
d0eb8f39 987 // fTDC -> [ 0;14]
988 // fTDCchannel -> [ 0; 7]
989 //
571dda3d 990
d0eb8f39 991 Int_t iPadX = -1;
571dda3d 992
d0eb8f39 993 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
994 || fSector==-1 || fPlate==-1 || fStrip==-1))
995 {
996 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
997 if (iPadAlongTheStrip!=-1)
998 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
999 }
1000
38f24f3f 1001 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
1002 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
1003
d0eb8f39 1004 fPadX = iPadX;
571dda3d 1005
1006}
571dda3d 1007
d0eb8f39 1008//----------------------------------------------------------------------------
1009Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
1010{
1011 //
a3ed3947 1012 // Returns 'word' masked by 'fieldMask' and shifted by 'fieldPosition'
d0eb8f39 1013 //
1014
1015 return ((word & fieldMask) >> fieldPosition);
1016}
1017
1018//----------------------------------------------------------------------------
13d6bff9 1019Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
571dda3d 1020{
1021 //
d0eb8f39 1022 // Returns the TOF plate number [0;4]
1023 // corresponding to the TOF equipment ID numbers:
1024 // iDDL -> DDL number per sector [0;3]
1025 // nTRM -> TRM number [3;12]
1026 // nTDC -> TDC number [0;14]
571dda3d 1027 //
1028
d0eb8f39 1029 Int_t iPlate = -1;
5f72a2bf 1030
d0eb8f39 1031 if (iDDL==0) {
1032
1033 if (nTRM>=4 && nTRM<7) {
1034 iPlate = 0;
1035 } else if (nTRM==7) {
1036 if (nTDC<12) iPlate = 0;
1037 else iPlate = 1;
1038 } else if (nTRM>=8 && nTRM<11) {
1039 iPlate = 1;
1040 } else if (nTRM==11) {
1041 if (nTDC<9) iPlate = 1;
1042 else iPlate = 2;
1043 }else if (nTRM==12) {
1044 iPlate = 2;
1045 }
1046
1047 } else if (iDDL==1) {
1048
1049 if (nTRM==3) {
1050 if (nTDC<3) iPlate = 0;
1051 } else if (nTRM>=4 && nTRM<7) {
1052 iPlate = 0;
1053 } else if (nTRM==7) {
1054 if (nTDC<6) iPlate = 1;
1055 else iPlate = 0;
1056 } else if (nTRM>=8 && nTRM<11) {
1057 iPlate = 1;
1058 } else if (nTRM==11) {
1059 if (nTDC<9) iPlate = 2;
1060 else iPlate = 1;
1061 } else if (nTRM==12) {
1062 iPlate = 2;
1063 }
1064
1065 } else if (iDDL==2) {
1066
1067 if (nTRM>=4 && nTRM<7) {
1068 iPlate = 4;
1069 } else if (nTRM==7) {
1070 if (nTDC<12) iPlate = 4;
1071 else iPlate = 3;
1072 } else if (nTRM>=8 && nTRM<11) {
1073 iPlate = 3;
1074 } else if (nTRM==11) {
1075 if (nTDC<9) iPlate = 3;
1076 else iPlate = 2;
1077 }else if (nTRM==12) {
1078 iPlate = 2;
1079 }
1080
1081 } else if (iDDL==3) {
1082
1083 if (nTRM==3) {
1084 if (nTDC<3) iPlate = 4;
1085 } else if (nTRM>=4 && nTRM<7) {
1086 iPlate = 4;
1087 } else if (nTRM==7) {
1088 if (nTDC<6) iPlate = 3;
1089 else iPlate = 4;
1090 } else if (nTRM>=8 && nTRM<11) {
1091 iPlate = 3;
1092 } else if (nTRM==11) {
1093 if (nTDC<9) iPlate = 2;
1094 else iPlate = 3;
1095 } else if (nTRM==12) {
1096 iPlate = 2;
1097 }
571dda3d 1098
d0eb8f39 1099 }
571dda3d 1100
d0eb8f39 1101 return iPlate;
571dda3d 1102
d0eb8f39 1103}
571dda3d 1104
d0eb8f39 1105//----------------------------------------------------------------------------
13d6bff9 1106Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
d0eb8f39 1107{
1108 //
1109 // Returns the TOF strip number per module:
1110 // [0;14], in the central plates,
1111 // [0;18], in the intermediate and external plates
1112 // corresponding to the TOF equipment ID numbers:
1113 // iDDL -> DDL number per sector [0;3]
1114 // nTRM -> TRM number [3;12]
1115 // nTDC -> TDC number [0;14]
1116 //
571dda3d 1117
d0eb8f39 1118 Int_t iStrip = -1;
571dda3d 1119
d0eb8f39 1120 if (iDDL==0) {
1121
1122 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
1123 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
1124 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1125 else if (nTRM== 7) {
1126 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
1127 else iStrip = (Int_t)(nTDC/3.) - 4;
1128 }
1129 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
1130 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
1131 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1132 else if (nTRM==11) {
1133 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1134 else iStrip = (Int_t)(nTDC/3.) - 3;
1135 }
1136 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1137
1138 } else if (iDDL==1) {
1139
1140 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1141 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1142 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1143 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1144 else if (nTRM== 7) {
1145 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1146 else iStrip = 20 - (Int_t)(nTDC/3.);
1147 }
1148 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1149 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1150 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1151 else if (nTRM==11) {
1152 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1153 else iStrip = 21 - (Int_t)(nTDC/3.);
1154 }
1155 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1156
1157 } else if (iDDL==2) {
1158
1159 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1160 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1161 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1162 else if (nTRM== 7) {
1163 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1164 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1165 }
1166 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1167 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1168 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1169 else if (nTRM==11) {
1170 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1171 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1172 }
1173 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1174
1175 } else if (iDDL==3) {
1176
1177 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1178 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1179 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1180 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1181 else if (nTRM== 7) {
1182 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1183 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1184 }
1185 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1186 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1187 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1188 else if (nTRM==11) {
1189 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1190 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1191 }
1192 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1193
1194 }
1195
1196 return iStrip;
1197
1198}
1199
1200//----------------------------------------------------------------------------
1201Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
13d6bff9 1202 Int_t iCH)
d0eb8f39 1203{
1204 //
1205 // Returns the TOF pad number per strip [0;95]
1206 // corresponding to the TOF equipment ID numbers:
1207 // iDDL -> DDL number per sector [0;3]
1208 // iChain -> TRM chain number [0;1]
1209 // nTDC -> TDC number [0;14]
1210 // iCH -> TDC channel number [0;7]
1211 //
1212
1213 Int_t iPadAlongTheStrip = -1;
1214
38f24f3f 1215 // wrong
1216 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1217 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1218 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
d0eb8f39 1219
38f24f3f 1220 // right
1221 Int_t iTDClocal = -1;
1222 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1223 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1224 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1225 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
d0eb8f39 1226
1227 Int_t iCHlocal = iCH;
1228 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1229
1230 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1231
1232 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
019f6101 1233 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
a3ed3947 1234 std::cerr << "Warning -> AliTOFRawStream::Equip2VolNpad: Problems with the padX number!\n";
13d6bff9 1235 //AliWarning("Problems with the padX number!");
019f6101 1236 }
d0eb8f39 1237 return iPadAlongTheStrip;
1238
1239}
1240
38f24f3f 1241//----------------------------------------------------------------------------
1242Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1243 Int_t iCH)
1244{
1245 //
1246 // Returns the TOF padX number [0;47]
1247 // corresponding to the TOF equipment ID numbers:
1248 // iDDL -> DDL number per sector [0;3]
1249 // iChain -> TRM chain number [0;1]
1250 // nTDC -> TDC number [0;14]
1251 // iCH -> TDC channel number [0;7]
1252 //
1253
1254 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1255 (Float_t(AliTOFGeometry::NpadZ())));
1256
1257 return iPadX;
1258
1259}
1260
1261//----------------------------------------------------------------------------
1262Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1263 Int_t iCH)
1264{
1265 //
1266 // Returns the TOF padZ number [0;1]
1267 // corresponding to the TOF equipment ID numbers:
1268 // iDDL -> DDL number per sector [0;3]
1269 // iChain -> TRM chain number [0;1]
1270 // nTDC -> TDC number [0;14]
1271 // iCH -> TDC channel number [0;7]
1272 //
1273
1274 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1275
1276 return iPadZ;
1277
1278}
1279
d0eb8f39 1280//----------------------------------------------------------------------------
5f72a2bf 1281Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL)
d0eb8f39 1282{
1283 //
1284 // Returns the sector number [0;17]
1285 // corresponing to the assigned DRM/DDL number [0;71]
1286 //
1287
1288 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1289
1290 return iSector;
1291
1292}
1293//----------------------------------------------------------------------------
5f72a2bf 1294Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL)
d0eb8f39 1295{
1296 //
1297 // Return the DRM/DDL number per sector [0;3]
1298 // corresponing to the assigned DRM/DDL number [0;71]
1299 //
1300
1301 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1302
1303 return iDDL;
1304
1305}
1306
7813bb1a 1307//----------------------------------------------------------------------------
1308void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1309{
1310 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1311}
d0eb8f39 1312//----------------------------------------------------------------------------
1313void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
a3ed3947 1314 Int_t nTDC, Int_t iCH,
1315 Int_t *volume)
d0eb8f39 1316{
1317 //
1318 // To convert:
1319 // nDDL (variable in [0;71]) -> number of the DDL file
1320 // nTRM (variable in [3;12]) -> number of the TRM slot
1321 // iChain (variable in [0; 1]) -> number of the TRM chain
1322 // nTDC (variable in [0;14]) -> number of the TDC
1323 // iCH (variable in [0; 7]) -> number of the TDC channel
1324 //
1325 // in:
1326 // sector number, i.e. volume[0] (variable in [0,17])
1327 // plate number, i.e. volume[1] (variable in [0, 5])
1328 // strip number, i.e. volume[2] (variable in [0,14/18])
1329 // padX number, i.e. volume[3] (variable in [0,47])
1330 // padZ number, i.e. volume[4] (variable in [0, 1])
1331 //
1332
125f7e0b 1333 for (Int_t ii=0; ii<5; ii++) volume[ii] = -1;
1334
d0eb8f39 1335 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1336
125f7e0b 1337 if (iDDL%2==1 && nTRM==3 && nTDC/3>0) { // Signal not coming from a TOF pad but -probably- from a TOF OR signal
1338 //printf("Info -> AliTOFRawStream::EquipmentId2VolumeId: Signal not coming from a TOF pad but -probably- from a TOF OR signal (%2d %2d %2d)\n", nDDL, nTRM, nTDC);
1339 return;
1340 }
1341
d0eb8f39 1342 Int_t iSector = GetSectorNumber(nDDL);
1343
1344 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
019f6101 1345 if (iPlate==-1) {
a9137e31 1346 /*if (fRawReader)
1347 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");*/
125f7e0b 1348 printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the plate number (%2d %2d %2d)!\n",
1349 nDDL, nTRM, nTDC);
019f6101 1350 }
d0eb8f39 1351
1352 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
019f6101 1353 if (iStrip==-1) {
a9137e31 1354 /*if (fRawReader)
1355 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");*/
125f7e0b 1356 printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the strip number (%2d %2d %2d)!\n",
1357 nDDL, nTRM, nTDC);
019f6101 1358 }
d0eb8f39 1359
1360 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
a9137e31 1361 if (iPadAlongTheStrip==-1) {
1362 /*if (fRawReader)
1363 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");*/
125f7e0b 1364 printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the pad number along the strip (%2d %1d %2d %1d)!\n",
1365 nDDL, iChain, nTDC, iCH);
019f6101 1366 }
13d6bff9 1367
d0eb8f39 1368 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1369 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
38f24f3f 1370
1371 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1372 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1373
1374 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1375 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1376
d0eb8f39 1377 volume[0] = iSector;
1378 volume[1] = iPlate;
1379 volume[2] = iStrip;
1380 volume[3] = iPadX;
1381 volume[4] = iPadZ;
571dda3d 1382
1383}
7813bb1a 1384//-----------------------------------------------------------------------------
019f6101 1385Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1386 //
1387 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1388 //
1389
7813bb1a 1390 //check and fix valid DDL range
019f6101 1391 if (nDDLMin < 0){
1392 nDDLMin = 0;
1393 fRawReader->AddMinorErrorLog(kDDLMinError);
1394 AliWarning("Wrong DDL range: setting first DDL ID to 0");
7813bb1a 1395 }
019f6101 1396 if (nDDLMax > 71){
1397 nDDLMax = 71;
1398 fRawReader->AddMinorErrorLog(kDDLMaxError);
1399 AliWarning("Wrong DDL range: setting last DDL ID to 71");
7813bb1a 1400 }
1401
1402 //select required DDLs
019f6101 1403 fRawReader->Select("TOF", nDDLMin, nDDLMax);
7813bb1a 1404
1405 if (verbose)
019f6101 1406 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
7813bb1a 1407
2fd622fa 1408 return(Decode(verbose));
1409}
1410//-----------------------------------------------------------------------------
019f6101 1411Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1412 //
1413 // New decoder method
1414 //
1415
2fd622fa 1416 Int_t currentEquipment;
1417 Int_t currentDDL;
dd824655 1418 const AliRawDataHeader *currentCDH;
2fd622fa 1419
1420 //pointers
1421 UChar_t *data = 0x0;
1422
7813bb1a 1423 //loop and read DDL headers
1424 while(fRawReader->ReadHeader()){
1425
1426 //memory leak prevention (actually data should be always 0x0 here)
1427 if (data != 0x0)
1428 delete [] data;
1429
1430 //get equipment infos
1431 currentEquipment = fRawReader->GetEquipmentId();
1432 currentDDL = fRawReader->GetDDLID();
dd824655 1433 currentCDH = fRawReader->GetDataHeader();
7813bb1a 1434 const Int_t kDataSize = fRawReader->GetDataSize();
1435 const Int_t kDataWords = kDataSize / 4;
1436 data = new UChar_t[kDataSize];
1437
1438 if (verbose)
1439 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1440
1441 if (verbose)
1442 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1443
1444 //read equipment payload
1445 if (!fRawReader->ReadNext(data, kDataSize))
1446 {
019f6101 1447 fRawReader->AddMajorErrorLog(kDDLdataReading);
7813bb1a 1448 if (verbose)
019f6101 1449 AliWarning("Error while reading DDL data. Go to next equipment");
7813bb1a 1450 delete [] data;
1451 data = 0x0;
1452 continue;
1453 }
1454
1455 if (verbose)
1456 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1457
1458
1459 //set up the decoder
1460 fDecoder->SetVerbose(verbose);
d35d0ea0 1461 fDecoder->SetDataBuffer(&fDataBuffer[currentDDL]);
1462 fDecoder->SetPackedDataBuffer(&fPackedDataBuffer[currentDDL]);
7813bb1a 1463
1464 //start decoding
dd824655 1465 if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
019f6101 1466 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1467 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
f02e90a6 1468 ResetDataBuffer(currentDDL);
1469 ResetPackedDataBuffer(currentDDL);
019f6101 1470 }
7813bb1a 1471
1472 delete [] data;
1473 data = 0x0;
1474 }
1475
1476 //reset reader
1477 fRawReader->Reset();
1478
1479 if (verbose)
1480 AliInfo("All done");
1481
1482 return kFALSE;
1483
1484}
1485//---------------------------------------------------------------------------
1486void
1487AliTOFRawStream::ResetBuffers()
1488{
19eefa2b 1489 //
1490 // To reset the buffers
1491 //
1492
7813bb1a 1493 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1494 ResetDataBuffer(iDDL);
1495 ResetPackedDataBuffer(iDDL);
1496 }
1497}
1498
1499//---------------------------------------------------------------------------
1500Bool_t
1501AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1502{
19eefa2b 1503 //
1504 // To load the buffers
1505 //
1506
7813bb1a 1507 fTOFrawData->Clear();
1508 fPackedDigits = 0;
1509
1510 if (verbose > 0)
1511 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1512
1513 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
019f6101 1514 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1515 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
7813bb1a 1516 return kTRUE;
1517 }
1518
1519 if (verbose > 0)
d35d0ea0 1520 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL].GetEntries(), fPackedDataBuffer[indexDDL].GetEntries() > 1 ? "hits have" : "hit has"));
7813bb1a 1521
1522 AliTOFHitData *hitData; //hit data pointer
1523
1524 if (verbose > 0)
1525 AliInfo("Filling TClonesArray ...");
1526
dd824655 1527 if (verbose > 0)
1528 if (fgApplyBCCorrections) {
1529 AliInfo("Apply nominal DDL BC time-shift correction");
1530 AliInfo("Apply deltaBC time-shift correction");
1531 }
1532
7813bb1a 1533 //loop over DDL packed hits
d35d0ea0 1534 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL].GetEntries(); iHit++){
1535 hitData = fPackedDataBuffer[indexDDL].GetHit(iHit); //get hit data
7813bb1a 1536 Int_t hitACQ = hitData->GetACQ();
1537 Int_t hitPS = hitData->GetPS();
1538 Int_t hitSlotID = hitData->GetSlotID();
1539 Int_t hitChain = hitData->GetChain();
1540 Int_t hitTDC = hitData->GetTDC();
1541 Int_t hitChan = hitData->GetChan();
7813bb1a 1542 Int_t hitTimeBin = hitData->GetTimeBin();
7813bb1a 1543 Int_t hitTOTBin = hitData->GetTOTBin();
2bf4d9d6 1544 Int_t hitDeltaBC = hitData->GetDeltaBunchID();
1545 Int_t hitL0L1Latency = hitData->GetL0L1Latency();
dd824655 1546
1547 Int_t hitLeading = hitData->GetTimeBin();
bf33f8f0 1548 Int_t hitTrailing = -1;
1549 Int_t hitError = -1;
7813bb1a 1550
1551 TClonesArray &arrayTofRawData = *fTOFrawData;
2bf4d9d6 1552 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError, hitDeltaBC, hitL0L1Latency);
7813bb1a 1553 }
1554
1555 if (verbose > 0)
1556 AliInfo("Done.");
1557
1558 if (verbose > 0)
1559 AliInfo("Resetting buffers ...");
1560
d35d0ea0 1561 fDataBuffer[indexDDL].Reset();
1562 fPackedDataBuffer[indexDDL].Reset();
7813bb1a 1563
1564 if (verbose > 0)
1565 AliInfo("Done.");
1566
1567 return kFALSE;
1568}
1569
5f72a2bf 1570//---------------------------------------------------------------------------
1571void AliTOFRawStream::Geant2EquipmentId(Int_t vol[], Int_t eqId[])
1572{
1573 //
1574 // To convert:
1575 // nSector number -vol[0]- (variable in [0,17])
1576 // nPlate number -vol[1]- (variable in [0, 5])
1577 // nStrip number -vol[2]- (variable in [0,14/18])
1578 // nPadZ number -vol[3]- (variable in [0, 1])
1579 // nPadX number -vol[4]- (variable in [0,47])
1580 // in:
e1d95075 1581 // nDDL -eqId[0]- (variable in [0;71]) -> number of the DDL
1582 // nTRM -eqId[1]- (variable in [3;12]) -> number of the TRM
1583 // nTDC -eqId[2]- (variable in [0;14]) -> number of the TDC
1584 // nChain -eqId[3]- (variable in [0; 1]) -> number of the chain
1585 // nChannel -eqId[4]- (variable in [0; 8]) -> number of the channel
5f72a2bf 1586 //
1587
1588 eqId[0] = Geant2DDL(vol);
1589 eqId[1] = Geant2TRM(vol);
1590 eqId[2] = Geant2TDC(vol);
1591 eqId[3] = Geant2Chain(vol);
1592 eqId[4] = Geant2Channel(vol);
1593
1594}
1595
1596//---------------------------------------------------------------------------
1597Int_t AliTOFRawStream::Geant2DDL(Int_t vol[])
1598{
1599 //
1600 // To convert:
1601 // nSector number -vol[0]- (variable in [0,17])
1602 // nPlate number -vol[1]- (variable in [0, 5])
1603 // nStrip number -vol[2]- (variable in [0,14/18])
1604 // nPadZ number -vol[3]- (variable in [0, 1])
1605 // nPadX number -vol[4]- (variable in [0,47])
1606 // in:
e1d95075 1607 // nDDL (variable in [0;71]) -> number of the DDL
5f72a2bf 1608 //
1609
1610
1611 Int_t iDDL = -1;
1612
1613 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1614 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1615 return iDDL;
1616 }
1617 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1618 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1619 return iDDL;
1620 }
1621 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1622 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1623 return iDDL;
1624 }
1625 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1626 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1627 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1628 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1629 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1630 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1631 return iDDL;
1632 }
1633
1634 Int_t nSector = vol[0];
1635 Int_t nPlate = vol[1];
1636 Int_t nStrip = vol[2];
1637 Int_t nPadX = vol[4];
1638
1639 if ( nPadX<24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<7) ) )
1640 iDDL = 0;
1641 else if ( nPadX>=24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<8) ) )
1642 iDDL = 1;
1643 else if ( nPadX>=24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>7) ) )
1644 iDDL = 2;
1645 else if ( nPadX<24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>6) ) )
1646 iDDL = 3;
1647
1648 return 4*nSector+iDDL;
1649
1650}
1651
1652//---------------------------------------------------------------------------
1653Int_t AliTOFRawStream::Geant2TRM(Int_t vol[])
1654{
1655 //
1656 // To convert:
1657 // nSector number -vol[0]- (variable in [0,17])
1658 // nPlate number -vol[1]- (variable in [0, 5])
1659 // nStrip number -vol[2]- (variable in [0,14/18])
1660 // nPadZ number -vol[3]- (variable in [0, 1])
1661 // nPadX number -vol[4]- (variable in [0,47])
1662 // in:
1663 // nTRM (variable in [3;12]) -> number of the TRM slot
1664 //
1665
1666 Int_t nTRM = -1;
1667
1668 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1669 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1670 return nTRM;
1671 }
1672 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1673 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1674 return nTRM;
1675 }
1676 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1677 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1678 return nTRM;
1679 }
1680 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ()) {
1681 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1682 return nTRM;
1683 }
1684 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX()) {
1685 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1686 return nTRM;
1687 }
1688
1689 if ( vol[3]>=AliTOFGeometry::NpadZ() )
1690 {
1691 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1692 return nTRM;
1693 }
1694
1695 Int_t nPlate = vol[1];
1696 Int_t nStrip = vol[2];
1697
1698 Int_t iDDL = Geant2DDL(vol)%4;
1699
1700 switch (iDDL) {
1701
1702 case 0:
1703
1704 if (nPlate==0) {
1705 if (nStrip<= 4) nTRM = 4;
1706 else if (nStrip> 4 && nStrip<= 9) nTRM = 5;
1707 else if (nStrip> 9 && nStrip<=14) nTRM = 6;
1708 else if (nStrip>14) nTRM = 7;
1709 }
1710 else if (nPlate==1) {
1711 if (nStrip== 0) nTRM = 7;
1712 else if (nStrip> 0 && nStrip<= 5) nTRM = 8;
1713 else if (nStrip> 5 && nStrip<=10) nTRM = 9;
1714 else if (nStrip>10 && nStrip<=15) nTRM = 10;
1715 else if (nStrip>15) nTRM = 11;
1716 }
1717 else if (nPlate==2) {
1718 if (nStrip<= 1) nTRM = 11;
1719 else if (nStrip> 1 && nStrip< 7) nTRM = 12;
1720 }
1721
1722 break;
1723 case 1:
1724
1725 if (nPlate==0) {
1726 if (nStrip== 0) nTRM = 3;
1727 else if (nStrip> 0 && nStrip<= 5) nTRM = 4;
1728 else if (nStrip> 5 && nStrip<=10) nTRM = 5;
1729 else if (nStrip>10 && nStrip<=15) nTRM = 6;
1730 else if (nStrip>15) nTRM = 7;
1731 }
1732 else if (nPlate==1) {
1733 if (nStrip<=1) nTRM = 7;
1734 else if (nStrip> 1 && nStrip<= 6) nTRM = 8;
1735 else if (nStrip> 6 && nStrip<=11) nTRM = 9;
1736 else if (nStrip>11 && nStrip<=16) nTRM = 10;
1737 else if (nStrip>16) nTRM = 11;
1738 }
1739 else if (nPlate==2) {
1740 if (nStrip<= 2) nTRM = 11;
1741 else if (nStrip> 2 && nStrip<= 7) nTRM = 12;
1742 }
1743
1744 break;
1745 case 2:
1746
1747 if (nPlate==4) {
1748 if (nStrip>=14) nTRM = 4;
1749 else if (nStrip<14 && nStrip>= 9) nTRM = 5;
1750 else if (nStrip< 9 && nStrip>= 4) nTRM = 6;
1751 else if (nStrip< 4) nTRM = 7;
1752 }
1753 else if (nPlate==3) {
1754 if (nStrip==18) nTRM = 7;
1755 else if (nStrip<18 && nStrip>=13) nTRM = 8;
1756 else if (nStrip<13 && nStrip>= 8) nTRM = 9;
1757 else if (nStrip< 8 && nStrip>= 3) nTRM = 10;
1758 else if (nStrip< 3) nTRM = 11;
1759 }
1760 else if (nPlate==2) {
1761 if (nStrip>=13) nTRM = 11;
1762 else if (nStrip<13 && nStrip>= 8) nTRM = 12;
1763 }
1764
1765 break;
1766 case 3:
1767
1768 if (nPlate==4) {
1769 if (nStrip==18) nTRM = 3;
1770 else if (nStrip<18 && nStrip>=13) nTRM = 4;
1771 else if (nStrip<13 && nStrip>= 8) nTRM = 5;
1772 else if (nStrip< 8 && nStrip>= 3) nTRM = 6;
1773 else if (nStrip< 3) nTRM = 7;
1774 }
1775 else if (nPlate==3) {
1776 if (nStrip>=17) nTRM = 7;
1777 else if (nStrip<17 && nStrip>=12) nTRM = 8;
1778 else if (nStrip<12 && nStrip>= 7) nTRM = 9;
1779 else if (nStrip< 7 && nStrip>= 2) nTRM = 10;
1780 else if (nStrip< 2) nTRM = 11;
1781 }
1782 else if (nPlate==2) {
1783 if (nStrip>=12) nTRM = 11;
1784 else if (nStrip <12 && nStrip>= 7) nTRM = 12;
1785 }
1786
1787 break;
1788
1789 }
1790
1791 return nTRM;
1792
1793}
1794
1795//---------------------------------------------------------------------------
1796Int_t AliTOFRawStream::Geant2TDC(Int_t vol[])
1797{
1798 //
1799 // To convert:
1800 // nSector number -vol[0]- (variable in [0,17])
1801 // nPlate number -vol[1]- (variable in [0, 5])
1802 // nStrip number -vol[2]- (variable in [0,14/18])
1803 // nPadZ number -vol[3]- (variable in [0, 1])
1804 // nPadX number -vol[4]- (variable in [0,47])
1805 // in:
1806 // nTDC (variable in [0;14]) -> number of the TDC
1807 //
1808
1809 Int_t nTDC = -1;
1810
1811 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1812 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1813 return nTDC;
1814 }
1815 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1816 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1817 return nTDC;
1818 }
1819 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1820 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1821 return nTDC;
1822 }
1823 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1824 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1825 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1826 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1827 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1828 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1829 return nTDC;
1830 }
1831
1832 Int_t nPlate = vol[1];
1833 Int_t nStrip = vol[2];
1834 Int_t iPadX = vol[4];
1835
1836 Int_t iDDL = Geant2DDL(vol)%4;
1837
1838 switch (iDDL) {
1839
1840 case 0:
1841
1842 if (nPlate==0) {
1843 if (nStrip<= 4) nTDC = (3*(nStrip)+2-(iPadX/4)%3);
1844 else if (nStrip> 4 && nStrip<= 9) nTDC = (3*(nStrip- 5)+2-(iPadX/4)%3);
1845 else if (nStrip> 9 && nStrip<=14) nTDC = (3*(nStrip-10)+2-(iPadX/4)%3);
1846 else if (nStrip>14) nTDC = (3*(nStrip-15)+2-(iPadX/4)%3);
1847 }
1848 else if (nPlate==1) {
1849 if (nStrip== 0) nTDC = (3*(nStrip+ 4)+2-(iPadX/4)%3);
1850 else if (nStrip> 0 && nStrip<= 5) nTDC = (3*(nStrip- 1)+2-(iPadX/4)%3);
1851 else if (nStrip> 5 && nStrip<=10) nTDC = (3*(nStrip- 6)+2-(iPadX/4)%3);
1852 else if (nStrip>10 && nStrip<=15) nTDC = (3*(nStrip-11)+2-(iPadX/4)%3);
1853 else if (nStrip>15) nTDC = (3*(nStrip-16)+2-(iPadX/4)%3);
1854 }
1855 else if (nPlate==2) {
1856 if (nStrip<= 1) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
1857 else if (nStrip> 1 && nStrip< 7) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
1858 }
1859
1860 break;
1861 case 1:
1862
1863 if (nPlate==0) {
1864 if (nStrip== 0) nTDC = (3*(nStrip)+(iPadX/4)%3);
1865 else if (nStrip> 0 && nStrip<= 5) nTDC = (3*( 5-nStrip)+(iPadX/4)%3);
1866 else if (nStrip> 5 && nStrip<=10) nTDC = (3*(10-nStrip)+(iPadX/4)%3);
1867 else if (nStrip>10 && nStrip<=15) nTDC = (3*(15-nStrip)+(iPadX/4)%3);
1868 else if (nStrip>15) nTDC = (3*(20-nStrip)+(iPadX/4)%3);
1869 }
1870 else if (nPlate==1) {
1871 if (nStrip<= 1) nTDC = (3*( 1-nStrip)+(iPadX/4)%3);
1872 else if (nStrip> 1 && nStrip<= 6) nTDC = (3*( 6-nStrip)+(iPadX/4)%3);
1873 else if (nStrip> 6 && nStrip<=11) nTDC = (3*(11-nStrip)+(iPadX/4)%3);
1874 else if (nStrip>11 && nStrip<=16) nTDC = (3*(16-nStrip)+(iPadX/4)%3);
1875 else if (nStrip>16) nTDC = (3*(21-nStrip)+(iPadX/4)%3);
1876 }
1877 else if (nPlate==2) {
1878 if (nStrip<= 2) nTDC = (3*( 2-nStrip)+(iPadX/4)%3);
1879 else if (nStrip> 2 && nStrip<= 7) nTDC = (3*( 7-nStrip)+(iPadX/4)%3);
1880 }
1881
1882 break;
1883 case 2:
1884
1885 if (nPlate==4) {
1886 if (nStrip>=14) nTDC = (3*(18-nStrip)+((iPadX/4)%3));
1887 else if (nStrip<14 && nStrip>= 9) nTDC = (3*(13-nStrip)+((iPadX/4)%3));
1888 else if (nStrip< 9 && nStrip>= 4) nTDC = (3*( 8-nStrip)+((iPadX/4)%3));
1889 else if (nStrip< 4) nTDC = (3*( 3-nStrip)+((iPadX/4)%3));
1890 }
1891 else if (nPlate==3) {
1892 if (nStrip==18) nTDC = (3*(22-nStrip)+((iPadX/4)%3));
1893 else if (nStrip<18 && nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
1894 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
1895 else if (nStrip< 8 && nStrip>= 3) nTDC = (3*( 7-nStrip)+((iPadX/4)%3));
1896 else if (nStrip< 3) nTDC = (3*( 2-nStrip)+((iPadX/4)%3));
1897 }
1898 else if (nPlate==2) {
1899 if (nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
1900 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
1901 }
1902
1903 break;
1904 case 3:
1905
1906 if (nPlate==4) {
1907 if (nStrip==18) nTDC = (3*(nStrip-18)+2-(iPadX/4)%3);
1908 else if (nStrip<18 && nStrip>=13) nTDC = (3*(nStrip-13)+2-(iPadX/4)%3);
1909 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(nStrip- 8)+2-(iPadX/4)%3);
1910 else if (nStrip< 8 && nStrip>= 3) nTDC = (3*(nStrip- 3)+2-(iPadX/4)%3);
1911 else if (nStrip< 3) nTDC = (3*(nStrip+ 2)+2-(iPadX/4)%3);
1912 }
1913 else if (nPlate==3) {
1914 if (nStrip>=17) nTDC = (3*(nStrip-17)+2-(iPadX/4)%3);
1915 else if (nStrip<17 && nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
1916 else if (nStrip<12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
1917 else if (nStrip< 7 && nStrip>= 2) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
1918 else if (nStrip< 2) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
1919 }
1920 else if (nPlate==2) {
1921 if (nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
1922 else if (nStrip <12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
1923 }
1924
1925 break;
1926
1927 }
1928
1929 return nTDC;
1930
1931}
1932
1933//---------------------------------------------------------------------------
1934Int_t AliTOFRawStream::Geant2Chain(Int_t vol[])
1935{
1936 //
1937 // To convert:
1938 // nSector number -vol[0]- (variable in [0,17])
1939 // nPlate number -vol[1]- (variable in [0, 5])
1940 // nStrip number -vol[2]- (variable in [0,14/18])
1941 // nPadZ number -vol[3]- (variable in [0, 1])
1942 // nPadX number -vol[4]- variable in [0,47])
1943 // in:
1944 // nChain (variable in [0; 1]) -> number of the TRM chain
1945 //
1946
1947 Int_t nChain = -1;
1948
1949 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1950 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1951 return nChain;
1952 }
1953 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1954 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1955 return nChain;
1956 }
1957 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1958 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1959 return nChain;
1960 }
1961 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1962 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1963 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1964 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1965 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1966 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1967 return nChain;
1968 }
1969
1970 Int_t iPadX = vol[4];
1971
1972 if (iPadX<12 || iPadX>=36) nChain = 0;
1973 else nChain = 1;
1974
1975 return nChain;
1976
1977}
1978
1979//---------------------------------------------------------------------------
1980Int_t AliTOFRawStream::Geant2Channel(Int_t vol[])
1981{
1982 //
1983 // To convert:
1984 // nSector number -vol[0]- (variable in [0,17])
1985 // nPlate number -vol[1]- (variable in [0, 5])
1986 // nStrip number -vol[2]- (variable in [0,14/18])
1987 // nPadZ number -vol[3]- (variable in [0, 1])
1988 // nPadX number -vol[4]- (variable in [0,47])
1989 // in:
1990 // nChannel (variable in [0; 7]) -> number of the TDC channel
1991 //
1992
1993 Int_t nChannel = -1;
1994
1995 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1996 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1997 return nChannel;
1998 }
1999 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
2000 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
2001 return nChannel;
2002 }
2003 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
2004 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
2005 return nChannel;
2006 }
2007 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
2008 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
2009 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
2010 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
2011 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
2012 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
2013 return nChannel;
2014 }
2015
2016 Int_t iPadZ = vol[3];
2017 Int_t iPadX = vol[4];
2018
2019 Int_t iDDL = Geant2DDL(vol)%4;
2020
2021 switch (iDDL) {
2022
2023 case 0:
2024 nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2025 break;
2026 case 1:
2027 nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2028 break;
2029 case 2:
2030 nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2031 break;
2032 case 3:
2033 nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2034 break;
2035 }
2036
2037 return nChannel;
2038
2039}
f472295e 2040
2041//____________________________________________________________________________
a3ed3947 2042void AliTOFRawStream::Raw2Digits(AliRawReader* rawReader, TClonesArray * const digitsArray)
f472295e 2043{
2044 //
2045 // Converts raw data to digits for TOF
2046 //
2047
2048 TStopwatch stopwatch;
2049 stopwatch.Start();
2050
2051 //TClonesArray *fDigits = new TClonesArray("AliTOFdigit", 4000);
2052 //digitsTree->Branch("TOF", &fDigits);
2053 TClonesArray &aDigits = *digitsArray;
2054
2055 Int_t inholes = 0;
2056
2057 Clear();
2058 SetRawReader(rawReader);
2059
2060 //ofstream ftxt;
2061 //if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
2062
2063 TClonesArray staticRawData("AliTOFrawData",10000);
2064 staticRawData.Clear();
2065 TClonesArray * clonesRawData = &staticRawData;
2066
2067 Int_t dummy = -1;
2068 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2069 Int_t digit[4];
2070
2071 const Int_t kMaxNumberOfTracksPerDigit = 3;
2072 Int_t tracks[kMaxNumberOfTracksPerDigit];
2073 for (Int_t ii=0; ii<kMaxNumberOfTracksPerDigit; ii++)
2074 tracks[ii] = -1;
2075 Int_t last = -1;
2076
2077 Int_t indexDDL = 0;
2078 Int_t iRawData = 0;
2079 AliTOFrawData *tofRawDatum = 0;
2080 for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
2081
2082 rawReader->Reset();
2083 if (fNewDecoderVersion) {
2084 AliInfo("Using New Decoder \n");
2085 LoadRawDataBuffers(indexDDL, 0);
2086 }
2087 else
2088 LoadRawData(indexDDL);
2089
2090 clonesRawData = GetRawData();
2091 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
2092 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
2093
2094 tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
2095
2096 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
2097 if (tofRawDatum->GetTOF()==-1) continue;
2098
2099 EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
2100 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
2101
2102 dummy = detectorIndex[3];
2103 detectorIndex[3] = detectorIndex[4];//padz
2104 detectorIndex[4] = dummy;//padx
2105
2106 digit[0] = tofRawDatum->GetTOF();
2107 digit[1] = tofRawDatum->GetTOT();
2108 digit[2] = tofRawDatum->GetTOT();
2109 digit[3] = -1;//tofRawDatum->GetTOF(); //tofND
2110
2111 dummy = detectorIndex[3];
2112 detectorIndex[3] = detectorIndex[4];//padx
2113 detectorIndex[4] = dummy;//padz
2114
2115 // Do not reconstruct anything in the holes
2116 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
2117 if (detectorIndex[1]==2) { // plate with holes
2118 inholes++;
2119 continue;
2120 }
2121 }
2122
2123 last = digitsArray->GetEntriesFast();
2124 new (aDigits[last]) AliTOFdigit(tracks, detectorIndex, digit);
2125 /*
2126 if (fVerbose==2) {
2127 if (indexDDL<10) ftxt << " " << indexDDL;
2128 else ftxt << " " << indexDDL;
2129 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
2130 else ftxt << " " << tofRawDatum->GetTRM();
2131 ftxt << " " << tofRawDatum->GetTRMchain();
2132 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
2133 else ftxt << " " << tofRawDatum->GetTDC();
2134 ftxt << " " << tofRawDatum->GetTDCchannel();
2135
2136 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
2137 else ftxt << " -> " << detectorIndex[0];
2138 ftxt << " " << detectorIndex[1];
2139 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
2140 else ftxt << " " << detectorIndex[2];
2141 ftxt << " " << detectorIndex[4];
2142 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
2143 else ftxt << " " << detectorIndex[3];
2144
2145 if (digit[1]<10)ftxt << " " << digit[1];
2146 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
2147 else ftxt << " " << digit[1];
2148 if (digit[0]<10) ftxt << " " << digit[0] << endl;
2149 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
2150 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
2151 else ftxt << " " << digit[3] << endl;
2152 }
2153 */
2154 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
2155 last,
2156 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
2157 digit[0], digit[1], digit[3]));
2158
2159 tofRawDatum = 0;
2160 } // loop on tofRawData array
2161
2162 clonesRawData->Clear();
2163
2164 } // DDL Loop
2165
2166 //if (fVerbose==2) ftxt.close();
2167
2168
2169 if (inholes) AliWarning(Form("Raw data in the TOF holes: %d",inholes));
2170
2171 Int_t nDigits = digitsArray->GetEntries();
2172 AliDebug(1, Form("Got %d TOF digits", nDigits));
2173 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
2174 stopwatch.RealTime(),stopwatch.CpuTime()));
2175
2176}
2177
2178//____________________________________________________________________________
a3ed3947 2179void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray * const sdigitsArray)
f472295e 2180{
2181 //
2182 // Converts raw data to sdigits for TOF
2183 //
2184
2185 TStopwatch stopwatch;
2186 stopwatch.Start();
2187
2188 Int_t inholes = 0;
2189
2190 //if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
2191 TClonesArray &aSDigits = *sdigitsArray;
2192
2193 Clear();
2194 SetRawReader(rawReader);
2195
2196 //ofstream ftxt;
2197 //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
2198
2199 TClonesArray staticRawData("AliTOFrawData",10000);
2200 staticRawData.Clear();
2201 TClonesArray * clonesRawData = &staticRawData;
2202
2203 Int_t dummy = -1;
2204 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2205 Int_t digit[2];
2206 Int_t track = -1;
2207 Int_t last = -1;
2208
2209 Int_t indexDDL = 0;
2210 Int_t iRawData = 0;
2211 AliTOFrawData *tofRawDatum = 0;
2212 for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
2213
2214 rawReader->Reset();
2215 if (fNewDecoderVersion) {
2216 AliInfo("Using New Decoder \n");
2217 LoadRawDataBuffers(indexDDL, 0);
2218 }
2219 else
2220 LoadRawData(indexDDL);
2221
2222 clonesRawData = GetRawData();
2223 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
2224 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
2225
2226 tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
2227
2228 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
2229 if (tofRawDatum->GetTOF()==-1) continue;
2230
2231 EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
2232 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
2233
2234 dummy = detectorIndex[3];
2235 detectorIndex[3] = detectorIndex[4];//padz
2236 detectorIndex[4] = dummy;//padx
2237
2238 digit[0] = tofRawDatum->GetTOF();
2239 digit[1] = tofRawDatum->GetTOT();
2240
2241 dummy = detectorIndex[3];
2242 detectorIndex[3] = detectorIndex[4];//padx
2243 detectorIndex[4] = dummy;//padz
2244
2245 // Do not reconstruct anything in the holes
2246 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
2247 if (detectorIndex[1]==2) { // plate with holes
2248 inholes++;
2249 continue;
2250 }
2251 }
2252
2253 last = sdigitsArray->GetEntriesFast();
2254 new (aSDigits[last]) AliTOFSDigit(track, detectorIndex, digit);
2255 /*
2256 if (fVerbose==2) {
2257 if (indexDDL<10) ftxt << " " << indexDDL;
2258 else ftxt << " " << indexDDL;
2259 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
2260 else ftxt << " " << tofRawDatum->GetTRM();
2261 ftxt << " " << tofRawDatum->GetTRMchain();
2262 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
2263 else ftxt << " " << tofRawDatum->GetTDC();
2264 ftxt << " " << tofRawDatum->GetTDCchannel();
2265
2266 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
2267 else ftxt << " -> " << detectorIndex[0];
2268 ftxt << " " << detectorIndex[1];
2269 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
2270 else ftxt << " " << detectorIndex[2];
2271 ftxt << " " << detectorIndex[4];
2272 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
2273 else ftxt << " " << detectorIndex[3];
2274
2275 if (digit[1]<10)ftxt << " " << digit[1];
2276 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
2277 else ftxt << " " << digit[1];
2278 if (digit[0]<10) ftxt << " " << digit[0] << endl;
2279 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
2280 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
2281 else ftxt << " " << digit[3] << endl;
2282 }
2283 */
2284 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
2285 last,
2286 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
2287 digit[0], digit[1], digit[3]));
2288
2289 tofRawDatum = 0;
2290 } // while loop
2291
2292 clonesRawData->Clear();
2293
2294 } // DDL Loop
2295
2296 //if (fVerbose==2) ftxt.close();
2297
2298 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
2299
2300 Int_t nSDigits = sdigitsArray->GetEntries();
2301 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
2302 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
2303 stopwatch.RealTime(),stopwatch.CpuTime()));
2304
2305}
08d6922f 2306
a3ed3947 2307void AliTOFRawStream::VolumeID2LTM(Int_t detind[],
2308 Int_t iDDL,
2309 Int_t iTRM,
2310 Int_t iChain,
2311 Int_t iTDC,
2312 Int_t iChannel) const {
08d6922f 2313 //
2314 // To convert the TOF trigger macropad ID (i.e. detind)
2315 // into TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
2316 //
2317
a3ed3947 2318 const Int_t kFirstTDCnumber = 12;
08d6922f 2319
a3ed3947 2320 iDDL=-1, iTRM = 3 , iChain=-1, iTDC=-1, iChannel=-1;
08d6922f 2321 if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
a3ed3947 2322 if (detind[4]<24)
2323 iDDL = detind[0]*4;
2324 else
2325 iDDL = detind[0]*4;
08d6922f 2326 }
2327 else {
a3ed3947 2328 if (detind[4]<24)
2329 iDDL = detind[0]*4+2;
2330 else
2331 iDDL = detind[0]*4+2;
08d6922f 2332 }
a3ed3947 2333
2334 iChain=fgkChainMap24[detind[1]][detind[2]];
2335 iTDC=(Int_t)(fgkChannelMap24[detind[1]][detind[2]]/8)+kFirstTDCnumber;
2336 iChannel=fgkChannelMap24[detind[1]][detind[2]]%8;
08d6922f 2337
2338}
2339
a3ed3947 2340void AliTOFRawStream::LTM2VolumeID(Int_t iDDL,
2341 Int_t iTRM,
2342 Int_t iChain,
2343 Int_t iTDC,
08d6922f 2344 Int_t iChannel,
a3ed3947 2345 Int_t detind0[], Int_t detind1[]) const {
08d6922f 2346 //
2347 // To convert the TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
2348 // into TOF trigger macropad IDs (i.e. detind0 and detind1).
2349 // In general, a couple of neighbouring TOF semi-strip represents a TOF trigger macropad.
2350 //
2351
a3ed3947 2352 const Int_t kFirstTDCnumber = 12;
2353
08d6922f 2354 Int_t iSector0=-1, iModule0=-1, iStrip0=-1, iPadX0=-1; // Le variabili del Volume ID
2355 Int_t iSector1=-1, iModule1=-1, iStrip1=-1, iPadX1=-1; // Le variabili del Volume ID
2356
a3ed3947 2357 if( iDDL%2==1 && iTRM==3 && iTDC-kFirstTDCnumber>=0 && iTDC-kFirstTDCnumber<3 ) {
08d6922f 2358 iSector0 = (Int_t)(iDDL/4);
2359 iSector1 = (Int_t)(iDDL/4);
a3ed3947 2360 Int_t iChan= iChannel+(iTDC-kFirstTDCnumber)*8;
4306fa22 2361 if( iDDL%4 == 1 ){
08d6922f 2362 if(iChain==0){ //CRATE 0
2363 iPadX0=0;
2364 iPadX1=0;
2365 iStrip0=fgkStrip0MapCrate0[iChan];
2366 iStrip1=fgkStrip1MapCrate0[iChan];
2367 iModule0=fgkModule0MapCrate0[iChan];
2368 iModule1=fgkModule1MapCrate0[iChan];
2369 }
2370 if(iChain==1){// CRATE 1
2371 iPadX0=24;
2372 iPadX1=24;
2373 iStrip0=fgkStrip0MapCrate1[iChan];
2374 iStrip1=fgkStrip1MapCrate1[iChan];
2375 iModule0=fgkModule0MapCrate1[iChan];
2376 iModule1=fgkModule1MapCrate1[iChan];
2377 }
2378
2379 }
4306fa22 2380 if( iDDL%4 == 3 ){
08d6922f 2381 if(iChain==1){// CRATE 3
2382 iPadX0=0;
2383 iPadX1=0;
2384 iStrip0=fgkStrip0MapCrate3[iChan];
2385 iStrip1=fgkStrip1MapCrate3[iChan];
2386 iModule0=fgkModule0MapCrate3[iChan];
2387 iModule1=fgkModule1MapCrate3[iChan];
2388 }
2389 if(iChain==0){// CRATE 2
2390 iPadX0=24;
2391 iPadX1=24;
2392 iStrip0=fgkStrip0MapCrate2[iChan];
2393 iStrip1=fgkStrip1MapCrate2[iChan];
2394 iModule0=fgkModule0MapCrate2[iChan];
2395 iModule1=fgkModule1MapCrate2[iChan];
2396 }
2397 }
2398 }
4306fa22 2399
2400 if(iStrip1==-1 || iModule1==-1){
2401 detind1[0]=-1;
2402 detind1[1]=-1;
2403 detind1[2]=-1;
2404 detind1[3]=-1;
2405 detind1[4]=-1;
2406 }
2407 else{
2408 detind1[0]=iSector1;
2409 detind1[1]=iModule1;
2410 detind1[2]=iStrip1;
2411 detind1[3]=iPadX1;
2412 detind1[4]=0;
2413 }
2414
2415 if(iStrip0==-1 || iModule0==-1){
2416 detind0[0]=-1;
2417 detind0[1]=-1;
2418 detind0[2]=-1;
2419 detind0[3]=-1;
2420 detind0[4]=-1;
2421 }
2422 else{
2423 detind0[0]=iSector0;
2424 detind0[1]=iModule0;
2425 detind0[2]=iStrip0;
2426 detind0[3]=iPadX0;
2427 detind0[4]=0;
2428 }
08d6922f 2429}