]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFClusterFinder.cxx
Bug fix in the bin0 loop
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinder.cxx
CommitLineData
d08a92dd 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/*
7fffa85b 17$Log: AliTOFClusterFinder.cxx,v $
18Revision 1.31 2007/11/24 14:53:19 zampolli
19Status flag implemented as UChar_t
20
98f5acd7 21Revision 1.30 2007/10/04 13:08:52 arcelli
22updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
23
ba66add8 24Revision 1.29 2007/10/03 10:42:33 arcelli
25updates to handle new AliTOFcluster, inheriting form AliCluster3D
26
ac359ffe 27Revision 1.28 2007/05/31 16:06:05 arcelli
28move instance of AliRawStream outside loop on DDL
29
ef58b2af 30Revision 1.27 2007/05/02 16:31:49 arcelli
c3891b7a 31Add methods to handle single event reconstruction. retrieval of Calib
32info moved to AliTOFReconstructor ctor, and passed via a pointer to
33AliTOFcalib
ef58b2af 34
94f5f8f2 35Revision 1.26 2007/04/30 19:02:24 arcelli
36hopefully the last refinements for correct type conversion in calibration
37
a33fec85 38Revision 1.25 2007/04/30 15:22:17 arcelli
39Change TOF digit Time, Tot etc to int type
40
bf33f8f0 41Revision 1.24 2007/04/27 11:19:31 arcelli
42updates for the new decoder
43
7813bb1a 44Revision 1.23 2007/04/23 16:51:39 decaro
c3891b7a 45Digits-to-raw_data conversion: correction for a more real description
46(A.De Caro, R.Preghenella)
7813bb1a 47
515faf5d 48Revision 1.22 2007/04/19 17:26:32 arcelli
49Fix a bug (add some debug printout
50
0451c2e6 51Revision 1.21 2007/04/18 17:28:12 arcelli
52Set the ToT bin width to the one actually used...
53
605370db 54Revision 1.20 2007/03/09 09:57:23 arcelli
55 Remove a forgotten include of Riostrem
56
c77771e2 57Revision 1.19 2007/03/08 15:41:20 arcelli
58set uncorrected times when filling RecPoints
59
3432ebfa 60Revision 1.18 2007/03/06 16:31:20 arcelli
61Add Uncorrected TOF Time signal
62
aa5476d8 63Revision 1.17 2007/02/28 18:09:11 arcelli
c3891b7a 64Add protection against failed retrieval of the CDB cal object,
65now Reconstruction exits with AliFatal
aa5476d8 66
a1cab04c 67Revision 1.16 2007/02/20 15:57:00 decaro
68Raw data update: to read the TOF raw data defined in UNPACKED mode
69
d08a92dd 70
71Revision 0.03 2005/07/28 A. De Caro
72 Implement public method
73 Raw2Digits(Int_t, AliRawReader *)
74 to convert digits from raw data in MC digits
75 (temporary solution)
76
77Revision 0.02 2005/07/27 A. De Caro
78 Implement public method
79 Digits2RecPoint(Int_t)
80 to convert digits in clusters
81
82Revision 0.02 2005/07/26 A. De Caro
83 Implement private methods
84 InsertCluster(AliTOFcluster *)
85 FindClusterIndex(Double_t)
86 originally implemented in AliTOFtracker
87 by S. Arcelli and C. Zampolli
88
89Revision 0.01 2005/07/25 A. De Caro
90 Implement public methods
91 Digits2RecPoint(AliRawReader *, TTree *)
92 Digits2RecPoint(Int_t, AliRawReader *)
93 to convert raw data in clusters
94 */
95
96////////////////////////////////////////////////////////////////
97// //
98// Class for TOF cluster finder //
99// //
100// Starting from Raw Data, create rec points, //
101// fill TreeR for TOF, //
102// write TOF.RecPoints.root file //
103// //
104////////////////////////////////////////////////////////////////
105
5c7c93fa 106#include "Riostream.h"
15ec34b9 107
0e46b9ae 108#include "TClonesArray.h"
515faf5d 109#include "TStopwatch.h"
0e46b9ae 110#include "TTree.h"
5c7c93fa 111//#include <TGeoManager.h>
ac359ffe 112#include <TGeoMatrix.h>
5c7c93fa 113//#include <TGeoPhysicalNode.h>
d08a92dd 114
d0eb8f39 115#include "AliDAQ.h"
0e46b9ae 116#include "AliLoader.h"
d08a92dd 117#include "AliLog.h"
0e46b9ae 118#include "AliRawReader.h"
d08a92dd 119#include "AliRunLoader.h"
5c7c93fa 120//#include "AliAlignObj.h"
121#include <AliGeomManager.h>
d08a92dd 122
15ec34b9 123#include "AliTOFcalib.h"
17149e6b 124#include "AliTOFChannelOnlineArray.h"
125#include "AliTOFChannelOnlineStatusArray.h"
ba66add8 126#include "AliTOFChannelOffline.h"
d08a92dd 127#include "AliTOFClusterFinder.h"
0e46b9ae 128#include "AliTOFcluster.h"
129#include "AliTOFdigit.h"
0e46b9ae 130#include "AliTOFGeometry.h"
15ec34b9 131#include "AliTOFrawData.h"
0e46b9ae 132
2bf4d9d6 133#include "AliTOFDeltaBCOffset.h"
134#include "AliTOFCTPLatency.h"
f04b3a69 135#include "AliTOFRunParams.h"
2bf4d9d6 136
15ec34b9 137//extern TFile *gFile;
d08a92dd 138
139ClassImp(AliTOFClusterFinder)
140
94f5f8f2 141AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
97986e79 142 TTask("AliTOFClusterFinder",""),
d08a92dd 143 fRunLoader(0),
144 fTOFLoader(0),
145 fTreeD(0),
146 fTreeR(0),
147 fDigits(new TClonesArray("AliTOFdigit", 4000)),
148 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
15ec34b9 149 fNumberOfTofClusters(0),
7813bb1a 150 fVerbose(0),
94f5f8f2 151 fDecoderVersion(0),
0275b7df 152 fTOFcalib(calib),
153 fTOFRawStream(AliTOFRawStream())
d08a92dd 154{
155//
156// Constructor
157//
158
1d834a1e 159 for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=0x0;
160
87e6e016 161 TString validity = (TString)fTOFcalib->GetOfflineValidity();
162 if (validity.CompareTo("valid")==0) {
163 AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
164 } else {
165 AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
166 }
167
d08a92dd 168}
2bf66a2d 169
d08a92dd 170//______________________________________________________________________________
171
94f5f8f2 172AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
97986e79 173 TTask("AliTOFClusterFinder",""),
d08a92dd 174 fRunLoader(runLoader),
175 fTOFLoader(runLoader->GetLoader("TOFLoader")),
176 fTreeD(0),
177 fTreeR(0),
178 fDigits(new TClonesArray("AliTOFdigit", 4000)),
179 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
15ec34b9 180 fNumberOfTofClusters(0),
7813bb1a 181 fVerbose(0),
94f5f8f2 182 fDecoderVersion(0),
0275b7df 183 fTOFcalib(calib),
184 fTOFRawStream(AliTOFRawStream())
d08a92dd 185{
186//
187// Constructor
188//
189
1d834a1e 190 for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=0x0;
191
87e6e016 192 TString validity = (TString)fTOFcalib->GetOfflineValidity();
193 if (validity.CompareTo("valid")==0) {
194 AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
195 } else {
196 AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
197 }
198
7aeeaf38 199}
200
201//------------------------------------------------------------------------
23afbd81 202AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source) :
203 TTask(source),
58d8d9a3 204 fRunLoader(0),
205 fTOFLoader(0),
206 fTreeD(0),
207 fTreeR(0),
8a190ba2 208 fDigits(source.fDigits),
209 fRecPoints(source.fRecPoints),
15ec34b9 210 fNumberOfTofClusters(0),
94f5f8f2 211 fVerbose(0),
8a190ba2 212 fDecoderVersion(source.fDecoderVersion),
0275b7df 213 fTOFcalib(source.fTOFcalib),
214 fTOFRawStream(source.fTOFRawStream)
7aeeaf38 215{
216 // copy constructor
1d834a1e 217
218 for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=source.fTofClusters[ii];
219
7aeeaf38 220}
221
222//------------------------------------------------------------------------
d0eb8f39 223AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
7aeeaf38 224{
225 // ass. op.
8a190ba2 226
227 if (this == &source)
228 return *this;
229
97986e79 230 TTask::operator=(source);
8a190ba2 231 fDigits=source.fDigits;
232 fRecPoints=source.fRecPoints;
233 fVerbose=source.fVerbose;
234 fDecoderVersion=source.fDecoderVersion;
235 fTOFcalib=source.fTOFcalib;
0275b7df 236 fTOFRawStream=source.fTOFRawStream;
1d834a1e 237 for (Int_t ii=0; ii<kTofMaxCluster; ii++) fTofClusters[ii]=source.fTofClusters[ii];
238
7aeeaf38 239 return *this;
240
d08a92dd 241}
242//______________________________________________________________________________
243
244AliTOFClusterFinder::~AliTOFClusterFinder()
245{
246
247 //
248 // Destructor
249 //
250
251 if (fDigits)
252 {
253 fDigits->Delete();
254 delete fDigits;
255 fDigits=0;
256 }
257 if (fRecPoints)
258 {
259 fRecPoints->Delete();
260 delete fRecPoints;
261 fRecPoints=0;
262 }
263
8ba211c3 264 if (fTofClusters || fNumberOfTofClusters) {
265 for (Int_t ii=0; ii<fNumberOfTofClusters; ii++)
fd6c5c3d 266 if (fTofClusters[ii]) fTofClusters[ii]->Delete();
8ba211c3 267 fNumberOfTofClusters=0;
268 }
269
d08a92dd 270}
271//______________________________________________________________________________
272
273void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
274{
275 //
276 // Converts digits to recpoints for TOF
277 //
278
515faf5d 279 TStopwatch stopwatch;
280 stopwatch.Start();
281
56483762 282 Int_t inholes = 0;
283
d08a92dd 284 fRunLoader->GetEvent(iEvent);
285
286 fTreeD = fTOFLoader->TreeD();
287 if (fTreeD == 0x0)
288 {
289 AliFatal("AliTOFClusterFinder: Can not get TreeD");
290 }
291
23afbd81 292 fDigits->Clear();
293 fTreeD->GetBranch("TOF")->SetAutoDelete(kFALSE);
294 fTreeD->SetBranchAddress("TOF",&fDigits);
d08a92dd 295
296 ResetRecpoint();
297
298 fTreeR = fTOFLoader->TreeR();
299 if (fTreeR == 0x0)
300 {
301 fTOFLoader->MakeTree("R");
302 fTreeR = fTOFLoader->TreeR();
303 }
304
305 Int_t bufsize = 32000;
306 fTreeR->Branch("TOF", &fRecPoints, bufsize);
307
308 fTreeD->GetEvent(0);
23afbd81 309 Int_t nDigits = fDigits->GetEntriesFast();
d08a92dd 310 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
311
ac359ffe 312 Int_t ii;
3495d79c 313 Int_t dig[5]={-1,-1,-1,-1,-1}; //cluster detector indeces
314 Int_t parTOF[7]={0,0,0,0,0,0,0}; //The TOF signal parameters
bf33f8f0 315 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
d08a92dd 316 for (ii=0; ii<nDigits; ii++) {
23afbd81 317 AliTOFdigit *d = (AliTOFdigit*)fDigits->UncheckedAt(ii);
d08a92dd 318 dig[0]=d->GetSector();
319 dig[1]=d->GetPlate();
320 dig[2]=d->GetStrip();
321 dig[3]=d->GetPadz();
322 dig[4]=d->GetPadx();
323
729f0d7f 324 /* check valid index */
325 if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
326
56483762 327 // Do not reconstruct anything in the holes
328 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
329 if (dig[1]==2) { // plate with holes
330 inholes++;
331 continue;
332 }
333 }
334
2bf66a2d 335 AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
d0eb8f39 336
bf33f8f0 337 parTOF[0] = d->GetTdc(); //the TDC signal
338 parTOF[1] = d->GetToT(); //the ToT signal
339 parTOF[2] = d->GetAdc(); // the adc charge
340 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
341 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
2bf4d9d6 342 parTOF[5] = 0; // deltaBC
343 parTOF[6] = 0; // L0-L1 latency
ac359ffe 344 Double_t posClus[3];
345 Double_t covClus[6];
346 UShort_t volIdClus=GetClusterVolIndex(dig);
347 GetClusterPars(dig, posClus,covClus);
348 AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
d08a92dd 349 InsertCluster(tofCluster);
bafe290d 350
d08a92dd 351 }
352
bafe290d 353 AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
d08a92dd 354
37879eed 355 CalibrateRecPoint();
d08a92dd 356 FillRecPoint();
357
358 fTreeR->Fill();
359 ResetRecpoint();
360
361 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
362 fTOFLoader->WriteRecPoints("OVERWRITE");
363
bafe290d 364 AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
365 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 366 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
515faf5d 367
94f5f8f2 368}
369
370//______________________________________________________________________________
371
372void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
373{
374 //
375 // Converts digits to recpoints for TOF
376 //
377
378 TStopwatch stopwatch;
379 stopwatch.Start();
380
56483762 381 Int_t inholes = 0;
382
94f5f8f2 383 if (digitsTree == 0x0)
384 {
385 AliFatal("AliTOFClusterFinder: Can not get TreeD");
386 }
387
23afbd81 388 fDigits->Clear();
389 digitsTree->GetBranch("TOF")->SetAutoDelete(kFALSE);
390 digitsTree->SetBranchAddress("TOF",&fDigits);
94f5f8f2 391
392 ResetRecpoint();
94f5f8f2 393 Int_t bufsize = 32000;
23afbd81 394 clusterTree->Branch("TOF", &fRecPoints, bufsize);
94f5f8f2 395
396 digitsTree->GetEvent(0);
23afbd81 397 Int_t nDigits = fDigits->GetEntriesFast();
94f5f8f2 398 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
399
ac359ffe 400 Int_t ii;
3495d79c 401 Int_t dig[5]={-1,-1,-1,-1,-1}; //cluster detector indeces
402 Int_t parTOF[7]={0,0,0,0,0,0,0}; //The TOF signal parameters
94f5f8f2 403 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
404 for (ii=0; ii<nDigits; ii++) {
23afbd81 405 AliTOFdigit *d = (AliTOFdigit*)fDigits->UncheckedAt(ii);
94f5f8f2 406 dig[0]=d->GetSector();
407 dig[1]=d->GetPlate();
408 dig[2]=d->GetStrip();
409 dig[3]=d->GetPadz();
410 dig[4]=d->GetPadx();
411
729f0d7f 412 /* check valid index */
413 if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
414
56483762 415 // Do not reconstruct anything in the holes
416 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
417 if (dig[1]==2) { // plate with holes
418 inholes++;
419 continue;
420 }
421 }
422
2bf66a2d 423 // AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
94f5f8f2 424
94f5f8f2 425 parTOF[0] = d->GetTdc(); //the TDC signal
426 parTOF[1] = d->GetToT(); //the ToT signal
427 parTOF[2] = d->GetAdc(); // the adc charge
428 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
429 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
2bf4d9d6 430 parTOF[5] = 0; // deltaBC
431 parTOF[6] = 0; // L0-L1 latency
ac359ffe 432
433 Double_t posClus[3];
434 Double_t covClus[6];
435 UShort_t volIdClus=GetClusterVolIndex(dig);
436 GetClusterPars(dig,posClus,covClus);
2bf66a2d 437 AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
94f5f8f2 438 InsertCluster(tofCluster);
439
440 }
441
bafe290d 442 AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
94f5f8f2 443
444 CalibrateRecPoint();
445 FillRecPoint();
446
447 clusterTree->Fill();
448 ResetRecpoint();
449
bafe290d 450 AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
451 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 452 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
94f5f8f2 453
d08a92dd 454}
455//______________________________________________________________________________
456
457void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
458 TTree *clustersTree)
459{
460 //
461 // Converts RAW data to recpoints for TOF
462 //
463
515faf5d 464 TStopwatch stopwatch;
465 stopwatch.Start();
466
56483762 467 Int_t inholes = 0;
468
d0eb8f39 469 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
d08a92dd 470
471 ResetRecpoint();
472
473 Int_t bufsize = 32000;
474 clustersTree->Branch("TOF", &fRecPoints, bufsize);
475
15ec34b9 476 TClonesArray * clonesRawData;
15ec34b9 477 Int_t dummy = -1;
d08a92dd 478
479 Int_t detectorIndex[5];
2bf4d9d6 480 Int_t parTOF[7];
d08a92dd 481
15ec34b9 482 ofstream ftxt;
483 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
484
0275b7df 485 fTOFRawStream.Clear();
486 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 487
5b4ed716 488 if (fDecoderVersion == 1) {
bafe290d 489 AliInfo("Using New Decoder");
5b4ed716 490 }
491 else if (fDecoderVersion == 2) {
492 AliInfo("Using Enhanced Decoder");
493 }
494 else {
495 AliInfo("Using Old Decoder");
496 }
bafe290d 497
15ec34b9 498 Int_t indexDDL = 0;
499 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
500
501 rawReader->Reset();
5b4ed716 502 if (fDecoderVersion == 1) {
0275b7df 503 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
5b4ed716 504 }
505 else if (fDecoderVersion == 2) {
506 fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
507 }
508 else {
509 fTOFRawStream.LoadRawData(indexDDL);
510 }
511
0275b7df 512 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
23afbd81 513
15ec34b9 514 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
515
516 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
517
c3891b7a 518 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
519 if (tofRawDatum->GetTOF()==-1) continue;
15ec34b9 520
521 if (fVerbose==2) {
522 if (indexDDL<10) ftxt << " " << indexDDL;
523 else ftxt << " " << indexDDL;
524 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
525 else ftxt << " " << tofRawDatum->GetTRM();
526 ftxt << " " << tofRawDatum->GetTRMchain();
527 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
528 else ftxt << " " << tofRawDatum->GetTDC();
529 ftxt << " " << tofRawDatum->GetTDCchannel();
530 }
531
0275b7df 532 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
533 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
15ec34b9 534 dummy = detectorIndex[3];
535 detectorIndex[3] = detectorIndex[4];
536 detectorIndex[4] = dummy;
537
538 if (fVerbose==2) {
539 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
540 else ftxt << " -> " << detectorIndex[0];
541 ftxt << " " << detectorIndex[1];
542 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
543 else ftxt << " " << detectorIndex[2];
544 ftxt << " " << detectorIndex[3];
545 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
546 else ftxt << " " << detectorIndex[4];
547 }
548
729f0d7f 549 /* check valid index */
550 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
551
56483762 552 // Do not reconstruct anything in the holes
553 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
554 if (detectorIndex[1]==2) { // plate with holes
555 inholes++;
556 continue;
557 }
558 }
559
bf33f8f0 560 parTOF[0] = tofRawDatum->GetTOF(); //TDC
561 parTOF[1] = tofRawDatum->GetTOT(); // TOT
562 parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
3495d79c 563 parTOF[3] = 0;//raw data: no track of undecalib sim time
bf33f8f0 564 parTOF[4] = tofRawDatum->GetTOF(); // RAW time
2bf4d9d6 565 parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
566 parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
ac359ffe 567 Double_t posClus[3];
568 Double_t covClus[6];
569 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
570 Int_t lab[3]={-1,-1,-1};
571 Bool_t status=kTRUE;
572 GetClusterPars(detectorIndex,posClus,covClus);
2bf66a2d 573 AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],lab,detectorIndex,parTOF,status,-1);
15ec34b9 574 InsertCluster(tofCluster);
575
576 if (fVerbose==2) {
bf33f8f0 577 if (parTOF[1]<10)ftxt << " " << parTOF[1];
578 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
579 else ftxt << " " << parTOF[1];
580 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
581 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
582 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
583 else ftxt << " " << parTOF[3] << endl;
15ec34b9 584 }
585
586 } // closed loop on TOF raw data per current DDL file
587
23afbd81 588 clonesRawData->Clear("C");
15ec34b9 589
590 } // closed loop on DDL index
591
15ec34b9 592 if (fVerbose==2) ftxt.close();
d08a92dd 593
bafe290d 594 AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
d08a92dd 595
f04b3a69 596 CalibrateRecPoint(rawReader->GetTimestamp());
d08a92dd 597 FillRecPoint();
598
599 clustersTree->Fill();
37879eed 600
d08a92dd 601 ResetRecpoint();
602
515faf5d 603 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
604 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 605 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
515faf5d 606
d08a92dd 607}
608//______________________________________________________________________________
609
610void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
611{
612 //
613 // Converts RAW data to recpoints for TOF
614 //
615
515faf5d 616 TStopwatch stopwatch;
617 stopwatch.Start();
618
56483762 619 Int_t inholes = 0;
620
d0eb8f39 621 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
d08a92dd 622
623 fRunLoader->GetEvent(iEvent);
624
2bf66a2d 625 AliDebug(2,Form(" Event number %2d ", iEvent));
d08a92dd 626
627 fTreeR = fTOFLoader->TreeR();
628
629 if (fTreeR == 0x0){
630 fTOFLoader->MakeTree("R");
631 fTreeR = fTOFLoader->TreeR();
632 }
633
634 Int_t bufsize = 32000;
635 fTreeR->Branch("TOF", &fRecPoints, bufsize);
636
15ec34b9 637 TClonesArray * clonesRawData;
638
15ec34b9 639 Int_t dummy = -1;
d08a92dd 640
d0eb8f39 641 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2bf4d9d6 642 Int_t parTOF[7];
15ec34b9 643 ofstream ftxt;
644 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
645
0275b7df 646 fTOFRawStream.Clear();
647 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 648
5b4ed716 649 if (fDecoderVersion == 1) {
bafe290d 650 AliInfo("Using New Decoder");
5b4ed716 651 }
652 else if (fDecoderVersion == 2) {
653 AliInfo("Using Enhanced Decoder");
654 }
655 else {
656 AliInfo("Using Old Decoder");
657 }
bafe290d 658
15ec34b9 659 Int_t indexDDL = 0;
d08a92dd 660 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
661
662 rawReader->Reset();
5b4ed716 663 if (fDecoderVersion == 1) {
0275b7df 664 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
5b4ed716 665 }
666 else if (fDecoderVersion == 2) {
667 fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
668 }
669 else {
670 fTOFRawStream.LoadRawData(indexDDL);
671 }
15ec34b9 672
0275b7df 673 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
15ec34b9 674
675 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
676
677 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
678
c3891b7a 679 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
680 if (tofRawDatum->GetTOF()==-1) continue;
15ec34b9 681
682 if (fVerbose==2) {
683 if (indexDDL<10) ftxt << " " << indexDDL;
684 else ftxt << " " << indexDDL;
685 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
686 else ftxt << " " << tofRawDatum->GetTRM();
687 ftxt << " " << tofRawDatum->GetTRMchain();
688 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
689 else ftxt << " " << tofRawDatum->GetTDC();
690 ftxt << " " << tofRawDatum->GetTDCchannel();
691 }
692
0275b7df 693 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
694 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
15ec34b9 695 dummy = detectorIndex[3];
696 detectorIndex[3] = detectorIndex[4];
697 detectorIndex[4] = dummy;
698
699 if (fVerbose==2) {
700 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
701 else ftxt << " -> " << detectorIndex[0];
702 ftxt << " " << detectorIndex[1];
703 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
704 else ftxt << " " << detectorIndex[2];
705 ftxt << " " << detectorIndex[3];
706 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
707 else ftxt << " " << detectorIndex[4];
708 }
d0eb8f39 709
729f0d7f 710 /* check valid index */
711 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
712
56483762 713 // Do not reconstruct anything in the holes
714 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
715 if (detectorIndex[1]==2) { // plate with holes
716 inholes++;
717 continue;
718 }
719 }
720
bf33f8f0 721 parTOF[0] = tofRawDatum->GetTOF(); // TDC
722 parTOF[1] = tofRawDatum->GetTOT(); // TOT
723 parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
3495d79c 724 parTOF[3] = 0; //raw data: no track of the undecalib sim time
bf33f8f0 725 parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
2bf4d9d6 726 parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
727 parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
ac359ffe 728 Double_t posClus[3];
729 Double_t covClus[6];
730 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
731 Int_t lab[3]={-1,-1,-1};
732 Bool_t status=kTRUE;
733 GetClusterPars(detectorIndex,posClus,covClus);
734 AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],lab,detectorIndex,parTOF,status,-1);
d08a92dd 735 InsertCluster(tofCluster);
736
15ec34b9 737 if (fVerbose==2) {
bf33f8f0 738 if (parTOF[1]<10)ftxt << " " << parTOF[1];
739 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
740 else ftxt << " " << parTOF[1];
741 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
742 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
743 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
744 else ftxt << " " << parTOF[3] << endl;
15ec34b9 745 }
d08a92dd 746
15ec34b9 747 } // closed loop on TOF raw data per current DDL file
748
23afbd81 749 clonesRawData->Clear("C");
15ec34b9 750
751 } // closed loop on DDL index
752
753 if (fVerbose==2) ftxt.close();
d08a92dd 754
bafe290d 755 AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
d08a92dd 756
f04b3a69 757 CalibrateRecPoint(rawReader->GetTimestamp());
d08a92dd 758 FillRecPoint();
759
760 fTreeR->Fill();
761 ResetRecpoint();
762
763 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
764 fTOFLoader->WriteRecPoints("OVERWRITE");
765
515faf5d 766 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
767 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 768 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
515faf5d 769
d08a92dd 770}
771//______________________________________________________________________________
772
773void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
774{
775 //
776 // Converts RAW data to MC digits for TOF
777 //
778 // (temporary solution)
779 //
780
515faf5d 781 TStopwatch stopwatch;
782 stopwatch.Start();
783
ba66add8 784 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
15ec34b9 785
d08a92dd 786 fRunLoader->GetEvent(iEvent);
787
788 fTreeD = fTOFLoader->TreeD();
789 if (fTreeD)
790 {
d0eb8f39 791 AliInfo("TreeD re-creation");
d08a92dd 792 fTreeD = 0x0;
793 fTOFLoader->MakeTree("D");
794 fTreeD = fTOFLoader->TreeD();
795 }
796
d08a92dd 797 Int_t bufsize = 32000;
23afbd81 798 fDigits->Clear();
799 fTreeD->Branch("TOF", &fDigits, bufsize);
d08a92dd 800
d08a92dd 801 fRunLoader->GetEvent(iEvent);
802
2bf66a2d 803 AliDebug(2,Form(" Event number %2d ", iEvent));
d08a92dd 804
15ec34b9 805 TClonesArray * clonesRawData;
806
807 Int_t dummy = -1;
d08a92dd 808
809 Int_t detectorIndex[5];
bf33f8f0 810 Int_t digit[4];
d08a92dd 811
0275b7df 812 fTOFRawStream.Clear();
813 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 814
5b4ed716 815 if (fDecoderVersion == 1) {
bafe290d 816 AliInfo("Using New Decoder");
5b4ed716 817 }
818 else if (fDecoderVersion == 2) {
819 AliInfo("Using Enhanced Decoder");
820 }
821 else {
822 AliInfo("Using Old Decoder");
823 }
bafe290d 824
15ec34b9 825 Int_t indexDDL = 0;
d08a92dd 826 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
827
828 rawReader->Reset();
5b4ed716 829 if (fDecoderVersion == 1) {
0275b7df 830 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
5b4ed716 831 }
832 else if (fDecoderVersion == 2) {
833 fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
834 }
835 else {
836 fTOFRawStream.LoadRawData(indexDDL);
837 }
d08a92dd 838
0275b7df 839 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
d08a92dd 840
15ec34b9 841 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
d0eb8f39 842
15ec34b9 843 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
d0eb8f39 844
3e2f0097 845 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
846 if (tofRawDatum->GetTOF()==-1) continue;
15ec34b9 847
0275b7df 848 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
849 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
15ec34b9 850 dummy = detectorIndex[3];
851 detectorIndex[3] = detectorIndex[4];
852 detectorIndex[4] = dummy;
d0eb8f39 853
0275b7df 854 digit[0] = fTOFRawStream.GetTofBin();
855 digit[1] = fTOFRawStream.GetToTbin();
856 digit[2] = fTOFRawStream.GetToTbin();
3495d79c 857 digit[3] = 0;
d08a92dd 858
859 Int_t tracknum[3]={-1,-1,-1};
860
23afbd81 861 TClonesArray &aDigits = *fDigits;
862 Int_t last=fDigits->GetEntriesFast();
d08a92dd 863 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
864
865 } // while loop
866
23afbd81 867 clonesRawData->Clear("C");
15ec34b9 868
d08a92dd 869 } // DDL Loop
870
871 fTreeD->Fill();
872
873 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
874 fTOFLoader->WriteDigits("OVERWRITE");
2bf66a2d 875
515faf5d 876 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
877 stopwatch.RealTime(),stopwatch.CpuTime()));
878
94f5f8f2 879}
880
881//______________________________________________________________________________
882
883void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
884{
885 //
886 // Converts RAW data to MC digits for TOF for the current event
887 //
888 //
889
890 TStopwatch stopwatch;
891 stopwatch.Start();
892
ba66add8 893 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
94f5f8f2 894
895 if (!digitsTree)
896 {
897 AliError("No input digits Tree");
898 return;
899 }
900
94f5f8f2 901 Int_t bufsize = 32000;
23afbd81 902 digitsTree->Branch("TOF", &fDigits, bufsize);
94f5f8f2 903
94f5f8f2 904 TClonesArray * clonesRawData;
94f5f8f2 905 Int_t dummy = -1;
906
907 Int_t detectorIndex[5];
908 Int_t digit[4];
909
0275b7df 910 fTOFRawStream.Clear();
911 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 912
5b4ed716 913 if (fDecoderVersion == 1) {
bafe290d 914 AliInfo("Using New Decoder");
5b4ed716 915 }
916 else if (fDecoderVersion == 2) {
917 AliInfo("Using Enhanced Decoder");
918 }
919 else {
920 AliInfo("Using Old Decoder");
921 }
bafe290d 922
94f5f8f2 923 Int_t indexDDL = 0;
924 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
925
926 rawReader->Reset();
5b4ed716 927 if (fDecoderVersion == 1) {
0275b7df 928 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
5b4ed716 929 }
930 else if (fDecoderVersion == 2) {
931 fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
932 }
933 else {
934 fTOFRawStream.LoadRawData(indexDDL);
935 }
94f5f8f2 936
0275b7df 937 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
94f5f8f2 938
939 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
940
941 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
942
3e2f0097 943 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
944 if (tofRawDatum->GetTOF()==-1) continue;
94f5f8f2 945
0275b7df 946 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
947 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
94f5f8f2 948 dummy = detectorIndex[3];
949 detectorIndex[3] = detectorIndex[4];
950 detectorIndex[4] = dummy;
951
0275b7df 952 digit[0] = fTOFRawStream.GetTofBin();
953 digit[1] = fTOFRawStream.GetToTbin();
954 digit[2] = fTOFRawStream.GetToTbin();
3495d79c 955 digit[3] = 0;
94f5f8f2 956
957 Int_t tracknum[3]={-1,-1,-1};
958
23afbd81 959 TClonesArray &aDigits = *fDigits;
960 Int_t last=fDigits->GetEntriesFast();
94f5f8f2 961 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
962
963 } // while loop
964
23afbd81 965 clonesRawData->Clear("C");
94f5f8f2 966
967 } // DDL Loop
968
969 digitsTree->Fill();
970
2bf66a2d 971 AliDebug(1, Form("Got %d digits: ", fDigits->GetEntries()));
94f5f8f2 972 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
973 stopwatch.RealTime(),stopwatch.CpuTime()));
974
d08a92dd 975}
976//______________________________________________________________________________
977
978Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
979 //---------------------------------------------------------------------------//
980 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
981 //---------------------------------------------------------------------------//
982 if (fNumberOfTofClusters==kTofMaxCluster) {
983 AliError("Too many clusters !");
984 return 1;
985 }
986
987 if (fNumberOfTofClusters==0) {
988 fTofClusters[fNumberOfTofClusters++] = tofCluster;
989 return 0;
990 }
991
992 Int_t ii = FindClusterIndex(tofCluster->GetZ());
993 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
994 fTofClusters[ii] = tofCluster;
995 fNumberOfTofClusters++;
996
997 return 0;
998
999}
1000//_________________________________________________________________________
1001
1002Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
1003 //--------------------------------------------------------------------
ac359ffe 1004 // This function returns the index of the nearest cluster in z
d08a92dd 1005 //--------------------------------------------------------------------
1006 if (fNumberOfTofClusters==0) return 0;
1007 if (z <= fTofClusters[0]->GetZ()) return 0;
1008 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
1009 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
1010 for (; b<e; m=(b+e)/2) {
1011 if (z > fTofClusters[m]->GetZ()) b=m+1;
1012 else e=m;
1013 }
1014
1015 return m;
1016
1017}
1018//_________________________________________________________________________
1019
1020void AliTOFClusterFinder::FillRecPoint()
1021{
1022 //
1023 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1024 // in Z) in the global TClonesArray of AliTOFcluster,
1025 // i.e. fRecPoints.
1026 //
1027
1028 Int_t ii, jj;
1029
1030 Int_t detectorIndex[5];
2bf4d9d6 1031 Int_t parTOF[7];
d08a92dd 1032 Int_t trackLabels[3];
1033 Int_t digitIndex = -1;
bf33f8f0 1034 Bool_t status=kTRUE;
d08a92dd 1035
1036 TClonesArray &lRecPoints = *fRecPoints;
1037
1038 for (ii=0; ii<fNumberOfTofClusters; ii++) {
1039
1040 digitIndex = fTofClusters[ii]->GetIndex();
1041 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1042 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
bf33f8f0 1043 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
1044 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
1045 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
1046 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
1047 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
2bf4d9d6 1048 parTOF[5] = fTofClusters[ii]->GetDeltaBC();//deltaBC
1049 parTOF[6] = fTofClusters[ii]->GetL0L1Latency();//L0-L1 latency
bf33f8f0 1050 status=fTofClusters[ii]->GetStatus();
ac359ffe 1051 Double_t posClus[3];
1052 Double_t covClus[6];
1053 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
1054 GetClusterPars(detectorIndex,posClus,covClus);
1055 new(lRecPoints[ii]) AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],trackLabels,detectorIndex, parTOF,status,digitIndex);
d08a92dd 1056
2bf66a2d 1057 AliDebug(2, Form(" %4d %4d %f %f %f %f %f %f %f %f %f %3d %3d %3d %2d %1d %2d %1d %2d %4d %3d %3d %4d %4d %1d %4d",
3e2f0097 1058 ii, volIdClus, posClus[0], posClus[1], posClus[2],
1059 fTofClusters[ii]->GetSigmaX2(),
1060 fTofClusters[ii]->GetSigmaXY(),
1061 fTofClusters[ii]->GetSigmaXZ(),
1062 fTofClusters[ii]->GetSigmaY2(),
1063 fTofClusters[ii]->GetSigmaYZ(),
1064 fTofClusters[ii]->GetSigmaZ2(),
1065 trackLabels[0], trackLabels[1], trackLabels[2],
1066 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
1067 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
1068 status, digitIndex));
1069
d08a92dd 1070 } // loop on clusters
1071
1072}
37879eed 1073
1074//_________________________________________________________________________
5b4ed716 1075
1076/*
1077 * OLD CALIBRATE REC POINTS FUNCTION
1078 */
1079
1080#if 0
f04b3a69 1081void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
37879eed 1082{
1083 //
1084 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1085 // in Z) in the global TClonesArray of AliTOFcluster,
1086 // i.e. fRecPoints.
1087 //
1088
1089 Int_t ii, jj;
1090
1091 Int_t detectorIndex[5];
1092 Int_t digitIndex = -1;
a33fec85 1093 Double_t tToT;
1094 Double_t timeCorr;
bf33f8f0 1095 Int_t tdcCorr;
2bf4d9d6 1096 Float_t tdcLatencyWindow;
bafe290d 1097 AliDebug(1," Calibrating TOF Clusters");
1098
17149e6b 1099 AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();
1100 AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();
ba66add8 1101 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
2bf4d9d6 1102
1103 AliTOFDeltaBCOffset *deltaBCOffsetObj = fTOFcalib->GetDeltaBCOffset();
1104 Int_t deltaBCOffset = deltaBCOffsetObj->GetDeltaBCOffset();
1105 AliTOFCTPLatency *ctpLatencyObj = fTOFcalib->GetCTPLatency();
1106 Float_t ctpLatency = ctpLatencyObj->GetCTPLatency();
f04b3a69 1107 AliTOFRunParams *runParamsObj = fTOFcalib->GetRunParams();
1108 Float_t t0 = runParamsObj->EvalT0(timestamp);
bafe290d 1109
ba66add8 1110 TString validity = (TString)fTOFcalib->GetOfflineValidity();
ba66add8 1111 Int_t calibration = -1;
1112 if (validity.CompareTo("valid")==0) {
87e6e016 1113 //AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
ba66add8 1114 calibration = 1;
bafe290d 1115 } else {
87e6e016 1116 //AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
ba66add8 1117 calibration = 0 ;
1118 }
bafe290d 1119
37879eed 1120 for (ii=0; ii<fNumberOfTofClusters; ii++) {
1121 digitIndex = fTofClusters[ii]->GetIndex();
1122 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1123
ba66add8 1124 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
37879eed 1125
17149e6b 1126 UChar_t statusPulser=calStatus->GetPulserStatus(index);
1127 UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1128 UChar_t statusHW=calStatus->GetHWStatus(index);
1129 UChar_t status=calStatus->GetStatus(index);
2bf4d9d6 1130 tdcLatencyWindow = calStatus->GetLatencyWindow(index) * 1.e3; /* ns -> ps */
1131
17149e6b 1132 //check the status, also unknown is fine!!!!!!!
1133
2bf66a2d 1134 AliDebug(2, Form(" Status for channel %d = %d",index, (Int_t)status));
17149e6b 1135 if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
2bf66a2d 1136 AliDebug(2, Form(" Bad Status for channel %d",index));
7fffa85b 1137 fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1138 }
1139 else {
2bf66a2d 1140 AliDebug(2, Form(" Good Status for channel %d",index));
7fffa85b 1141 }
58d8d9a3 1142 // Get Rough channel online equalization
17149e6b 1143 Double_t roughDelay=(Double_t)calDelay->GetDelay(index); // in ns
ba66add8 1144 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
58d8d9a3 1145 // Get Refined channel offline calibration parameters
ba66add8 1146 if (calibration ==1){
1147 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1148 Double_t par[6];
1149 for (Int_t j = 0; j<6; j++){
1150 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1151 }
bf33f8f0 1152 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
2bf66a2d 1153 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
3495d79c 1154 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
ba66add8 1155 tToT*=1.E-3; //ToT in ns
104ba366 1156
1157 /* check TOT limits and set new TOT in case */
1158 if (tToT < AliTOFGeometry::SlewTOTMin()) tToT = AliTOFGeometry::SlewTOTMin();
1159 if (tToT > AliTOFGeometry::SlewTOTMax()) tToT = AliTOFGeometry::SlewTOTMax();
1160
ba66add8 1161 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1162 timeCorr=par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT; // the time correction (ns)
1163 }
1164 else {
1165 timeCorr = roughDelay; // correction in ns
1166 }
1167 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
bf33f8f0 1168 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
a33fec85 1169 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1170 timeCorr*=1.E3;
1171 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
2bf4d9d6 1172
1173 /* here timeCorr should be already corrected for calibration.
1174 * we now go into further corrections keeping in mind that timeCorr
1175 * is in ps.
1176 *
1177 * the following corrections are performed in this way:
1178 *
f04b3a69 1179 * time = timeRaw - deltaBC + L0L1Latency + CTPLatency - TDCLatencyWindow - T0
2bf4d9d6 1180 *
1181 */
1182
1183 AliDebug(2, Form("applying further corrections (DeltaBC): DeltaBC=%d (BC bins), DeltaBCoffset=%d (BC bins)", fTofClusters[ii]->GetDeltaBC(), deltaBCOffset));
1184 AliDebug(2, Form("applying further corrections (L0L1Latency): L0L1Latency=%d (BC bins)", fTofClusters[ii]->GetL0L1Latency()));
1185 AliDebug(2, Form("applying further corrections (CTPLatency): CTPLatency=%f (ps)", ctpLatency));
1186 AliDebug(2, Form("applying further corrections (TDCLatencyWindow): TDCLatencyWindow=%f (ps)", tdcLatencyWindow));
f04b3a69 1187 AliDebug(2, Form("applying further corrections (T0): T0=%f (ps)", t0));
2bf4d9d6 1188
f04b3a69 1189 /* deltaBC correction (inhibited for the time being) */
1190 // timeCorr -= (fTofClusters[ii]->GetDeltaBC() - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
2bf4d9d6 1191 /* L0L1-latency correction */
1192 timeCorr += fTofClusters[ii]->GetL0L1Latency() * AliTOFGeometry::BunchCrossingBinWidth();
1193 /* CTP-latency correction (from OCDB) */
1194 timeCorr += ctpLatency;
1195 /* TDC latency-window correction (from OCDB) */
1196 timeCorr -= tdcLatencyWindow;
f04b3a69 1197 /* T0 correction (from OCDB) */
1198 timeCorr -= t0;
2bf4d9d6 1199
1200 /*
1201 * end of furhter corrections
1202 */
1203
a33fec85 1204 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
340693af 1205 fTofClusters[ii]->SetTDC(tdcCorr);
37879eed 1206 } // loop on clusters
1207
37879eed 1208}
5b4ed716 1209#endif
1210
1211//_________________________________________________________________________
1212
1213void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
1214{
1215 //
1216 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1217 // in Z) in the global TClonesArray of AliTOFcluster,
1218 // i.e. fRecPoints.
1219 //
1220
1221 Int_t detectorIndex[5];
1222 Double_t time, tot, corr;
1223 Int_t deltaBC, l0l1, tdcBin;
1224 for (Int_t ii = 0; ii < fNumberOfTofClusters; ii++) {
1225 for(Int_t jj = 0; jj < 5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1226
1227 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1228
1229 /* check channel enabled */
1230 if (!fTOFcalib->IsChannelEnabled(index)) fTofClusters[ii]->SetStatus(kFALSE);
1231
1232 /* get cluster info */
1233 time = fTofClusters[ii]->GetTDC() * AliTOFGeometry::TdcBinWidth(); /* ps */
1234 tot = fTofClusters[ii]->GetToT() * AliTOFGeometry::ToTBinWidth() * 1.e-3; /* ns */
1235 deltaBC = fTofClusters[ii]->GetDeltaBC();
1236 l0l1 = fTofClusters[ii]->GetL0L1Latency();
1237
1238 /* get correction */
1239 corr = fTOFcalib->GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp); /* ps */
1240 AliDebug(2, Form("calibrate index %d: time=%f (ps) tot=%f (ns) deltaBC=%d l0l1=%d timestamp=%d corr=%f (ps)", index, time, tot, deltaBC, l0l1, timestamp, corr));
1241
1242 /* apply time correction */
1243 time -= corr;
1244
1245 /* convert in TDC bins and set cluster */
3495d79c 1246 //tdcBin = (Int_t)(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1247 tdcBin = TMath::Nint(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
5b4ed716 1248 fTofClusters[ii]->SetTDC(tdcBin);
1249
1250 } // loop on clusters
1251
1252}
1253
d08a92dd 1254//______________________________________________________________________________
1255
1256void AliTOFClusterFinder::ResetRecpoint()
1257{
1258 //
1259 // Clear the list of reconstructed points
1260 //
1261
1262 fNumberOfTofClusters = 0;
1263 if (fRecPoints) fRecPoints->Clear();
1264
1265}
1266//______________________________________________________________________________
1267
1268void AliTOFClusterFinder::Load()
1269{
1270 //
1271 // Load TOF.Digits.root and TOF.RecPoints.root files
1272 //
1273
1274 fTOFLoader->LoadDigits("READ");
1275 fTOFLoader->LoadRecPoints("recreate");
1276
1277}
1278//______________________________________________________________________________
1279
1280void AliTOFClusterFinder::LoadClusters()
1281{
1282 //
1283 // Load TOF.RecPoints.root file
1284 //
1285
1286 fTOFLoader->LoadRecPoints("recreate");
1287
1288}
1289//______________________________________________________________________________
1290
1291void AliTOFClusterFinder::UnLoad()
1292{
1293 //
1294 // Unload TOF.Digits.root and TOF.RecPoints.root files
1295 //
1296
1297 fTOFLoader->UnloadDigits();
1298 fTOFLoader->UnloadRecPoints();
1299
1300}
1301//______________________________________________________________________________
1302
1303void AliTOFClusterFinder::UnLoadClusters()
1304{
1305 //
1306 // Unload TOF.RecPoints.root file
1307 //
1308
1309 fTOFLoader->UnloadRecPoints();
1310
1311}
ac359ffe 1312//-------------------------------------------------------------------------
0e74c396 1313UShort_t AliTOFClusterFinder::GetClusterVolIndex(const Int_t * const ind) const {
ac359ffe 1314
1315 //First of all get the volume ID to retrieve the l2t transformation...
1316 //
1317 // Detector numbering scheme
1318 Int_t nSector = 18;
1319 Int_t nPlate = 5;
1320 Int_t nStripA = 15;
1321 Int_t nStripB = 19;
1322 Int_t nStripC = 19;
1323
1324 Int_t isector =ind[0];
1325 if (isector >= nSector)
1326 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1327 Int_t iplate = ind[1];
1328 if (iplate >= nPlate)
1329 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1330 Int_t istrip = ind[2];
1331
1332 Int_t stripOffset = 0;
1333 switch (iplate) {
1334 case 0:
1335 stripOffset = 0;
1336 break;
1337 case 1:
1338 stripOffset = nStripC;
1339 break;
1340 case 2:
1341 stripOffset = nStripC+nStripB;
1342 break;
1343 case 3:
1344 stripOffset = nStripC+nStripB+nStripA;
1345 break;
1346 case 4:
1347 stripOffset = nStripC+nStripB+nStripA+nStripB;
1348 break;
1349 default:
1350 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1351 break;
1352 };
1353
1354 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1355 stripOffset +
1356 istrip;
1357
1358 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1359 return volIndex;
1360}
1361//
1362//-------------------------------------------------------------------------
1363void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1364
1365 //First of all get the volume ID to retrieve the l2t transformation...
1366 //
1367 UShort_t volIndex = GetClusterVolIndex(ind);
1368 //
1369 //
1370 //we now go in the system of the strip: determine the local coordinates
1371 //
1372 //
1373 // 47---------------------------------------------------0 ^ z
1374 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1375 // ----------------------------------------------------- | y going outwards
1376 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1377
1378 // ----------------------------------------------------- |
1379 // x <-----------------------------------------------------
1380
b3e52baa 1381 /*
1382 Float_t localX = (ind[4]-23.5)*AliTOFGeometry::XPad();
1383 Float_t localY = 0;
1384 Float_t localZ = (ind[3]- 0.5)*AliTOFGeometry::ZPad();
1385 */
1386 Float_t localX = (ind[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.;
1387 Float_t localY = 0;
1388 Float_t localZ = (ind[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::ZPad()+AliTOFGeometry::ZPad()/2.;
ac359ffe 1389 //move to the tracking ref system
1390
1391 Double_t lpos[3];
b3e52baa 1392 lpos[0] = localX;
1393 lpos[1] = localY;
1394 lpos[2] = localZ;
ac359ffe 1395
1396 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1397 // Get The position in the track ref system
1398 Double_t tpos[3];
1399 l2t->MasterToLocal(lpos,tpos);
b3e52baa 1400 pos[0] = tpos[0];
1401 pos[1] = tpos[1];
1402 pos[2] = tpos[2];
ac359ffe 1403
1404 //Get The cluster covariance in the track ref system
1405 Double_t lcov[9];
1406
1407 //cluster covariance in the local system:
1408 // sx2 0 0
1409 // 0 0 0
1410 // 0 0 sz2
1411
b3e52baa 1412 lcov[0] = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1413 lcov[1] = 0;
1414 lcov[2] = 0;
1415 lcov[3] = 0;
1416 lcov[4] = 0;
1417 lcov[5] = 0;
1418 lcov[6] = 0;
1419 lcov[7] = 0;
1420 lcov[8] = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
ac359ffe 1421
1422 //cluster covariance in the tracking system:
1423 TGeoHMatrix m;
1424 m.SetRotation(lcov);
1425 m.Multiply(l2t);
1426 m.MultiplyLeft(&l2t->Inverse());
1427 Double_t *tcov = m.GetRotationMatrix();
1428 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1429 cov[3] = tcov[4]; cov[4] = tcov[5];
1430 cov[5] = tcov[8];
1431
1432 return;
1433
1434}