]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFClusterFinder.cxx
software update to include time corrections during reconstruction.
[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"
0275b7df 132//#include "AliTOFRawStream.h"
0e46b9ae 133
2bf4d9d6 134#include "AliTOFDeltaBCOffset.h"
135#include "AliTOFCTPLatency.h"
136#include "AliTOFT0Fill.h"
137
15ec34b9 138//extern TFile *gFile;
d08a92dd 139
140ClassImp(AliTOFClusterFinder)
141
94f5f8f2 142AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
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
d08a92dd 159}
2bf66a2d 160
d08a92dd 161//______________________________________________________________________________
162
94f5f8f2 163AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
d08a92dd 164 fRunLoader(runLoader),
165 fTOFLoader(runLoader->GetLoader("TOFLoader")),
166 fTreeD(0),
167 fTreeR(0),
168 fDigits(new TClonesArray("AliTOFdigit", 4000)),
169 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
15ec34b9 170 fNumberOfTofClusters(0),
7813bb1a 171 fVerbose(0),
94f5f8f2 172 fDecoderVersion(0),
0275b7df 173 fTOFcalib(calib),
174 fTOFRawStream(AliTOFRawStream())
d08a92dd 175{
176//
177// Constructor
178//
179
7aeeaf38 180}
181
182//------------------------------------------------------------------------
183AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
8a190ba2 184 :TObject(source),
58d8d9a3 185 fRunLoader(0),
186 fTOFLoader(0),
187 fTreeD(0),
188 fTreeR(0),
8a190ba2 189 fDigits(source.fDigits),
190 fRecPoints(source.fRecPoints),
15ec34b9 191 fNumberOfTofClusters(0),
94f5f8f2 192 fVerbose(0),
8a190ba2 193 fDecoderVersion(source.fDecoderVersion),
0275b7df 194 fTOFcalib(source.fTOFcalib),
195 fTOFRawStream(source.fTOFRawStream)
7aeeaf38 196{
197 // copy constructor
7aeeaf38 198}
199
200//------------------------------------------------------------------------
d0eb8f39 201AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
7aeeaf38 202{
203 // ass. op.
8a190ba2 204
205 if (this == &source)
206 return *this;
207
208 TObject::operator=(source);
209 fDigits=source.fDigits;
210 fRecPoints=source.fRecPoints;
211 fVerbose=source.fVerbose;
212 fDecoderVersion=source.fDecoderVersion;
213 fTOFcalib=source.fTOFcalib;
0275b7df 214 fTOFRawStream=source.fTOFRawStream;
7aeeaf38 215 return *this;
216
d08a92dd 217}
218//______________________________________________________________________________
219
220AliTOFClusterFinder::~AliTOFClusterFinder()
221{
222
223 //
224 // Destructor
225 //
226
227 if (fDigits)
228 {
229 fDigits->Delete();
230 delete fDigits;
231 fDigits=0;
232 }
233 if (fRecPoints)
234 {
235 fRecPoints->Delete();
236 delete fRecPoints;
237 fRecPoints=0;
238 }
239
d08a92dd 240}
241//______________________________________________________________________________
242
243void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
244{
245 //
246 // Converts digits to recpoints for TOF
247 //
248
515faf5d 249 TStopwatch stopwatch;
250 stopwatch.Start();
251
56483762 252 Int_t inholes = 0;
253
d08a92dd 254 fRunLoader->GetEvent(iEvent);
255
256 fTreeD = fTOFLoader->TreeD();
257 if (fTreeD == 0x0)
258 {
259 AliFatal("AliTOFClusterFinder: Can not get TreeD");
260 }
261
262 TBranch *branch = fTreeD->GetBranch("TOF");
263 if (!branch) {
264 AliError("can't get the branch with the TOF digits !");
265 return;
266 }
267
b24266ca 268 TClonesArray staticdigits("AliTOFdigit",10000);
269 staticdigits.Clear();
270 TClonesArray *digits =&staticdigits;
d08a92dd 271 branch->SetAddress(&digits);
272
273 ResetRecpoint();
274
275 fTreeR = fTOFLoader->TreeR();
276 if (fTreeR == 0x0)
277 {
278 fTOFLoader->MakeTree("R");
279 fTreeR = fTOFLoader->TreeR();
280 }
281
282 Int_t bufsize = 32000;
283 fTreeR->Branch("TOF", &fRecPoints, bufsize);
284
285 fTreeD->GetEvent(0);
286 Int_t nDigits = digits->GetEntriesFast();
287 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
288
ac359ffe 289 Int_t ii;
bf33f8f0 290 Int_t dig[5]; //cluster detector indeces
2bf4d9d6 291 Int_t parTOF[7]; //The TOF signal parameters
bf33f8f0 292 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
d08a92dd 293 for (ii=0; ii<nDigits; ii++) {
294 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
295 dig[0]=d->GetSector();
296 dig[1]=d->GetPlate();
297 dig[2]=d->GetStrip();
298 dig[3]=d->GetPadz();
299 dig[4]=d->GetPadx();
300
729f0d7f 301 /* check valid index */
302 if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
303
56483762 304 // Do not reconstruct anything in the holes
305 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
306 if (dig[1]==2) { // plate with holes
307 inholes++;
308 continue;
309 }
310 }
311
2bf66a2d 312 AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
d0eb8f39 313
bf33f8f0 314 parTOF[0] = d->GetTdc(); //the TDC signal
315 parTOF[1] = d->GetToT(); //the ToT signal
316 parTOF[2] = d->GetAdc(); // the adc charge
317 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
318 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
2bf4d9d6 319 parTOF[5] = 0; // deltaBC
320 parTOF[6] = 0; // L0-L1 latency
ac359ffe 321 Double_t posClus[3];
322 Double_t covClus[6];
323 UShort_t volIdClus=GetClusterVolIndex(dig);
324 GetClusterPars(dig, posClus,covClus);
325 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 326 InsertCluster(tofCluster);
bafe290d 327
d08a92dd 328 }
329
bafe290d 330 AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
d08a92dd 331
37879eed 332 CalibrateRecPoint();
d08a92dd 333 FillRecPoint();
334
335 fTreeR->Fill();
336 ResetRecpoint();
337
338 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
339 fTOFLoader->WriteRecPoints("OVERWRITE");
340
bafe290d 341 AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
342 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 343 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
515faf5d 344
94f5f8f2 345}
346
347//______________________________________________________________________________
348
349void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
350{
351 //
352 // Converts digits to recpoints for TOF
353 //
354
355 TStopwatch stopwatch;
356 stopwatch.Start();
357
56483762 358 Int_t inholes = 0;
359
94f5f8f2 360 /// fRunLoader->GetEvent(iEvent);
361
362 if (digitsTree == 0x0)
363 {
364 AliFatal("AliTOFClusterFinder: Can not get TreeD");
365 }
366
367 TBranch *branch = digitsTree->GetBranch("TOF");
368 if (!branch) {
369 AliError("can't get the branch with the TOF digits !");
370 return;
371 }
372
b24266ca 373 TClonesArray staticdigits("AliTOFdigit",10000);
374 staticdigits.Clear();
375 TClonesArray *digits = & staticdigits;
94f5f8f2 376 branch->SetAddress(&digits);
377
378 ResetRecpoint();
379
380 fTreeR=clusterTree;
381 Int_t bufsize = 32000;
382 fTreeR->Branch("TOF", &fRecPoints, bufsize);
383
384 digitsTree->GetEvent(0);
385 Int_t nDigits = digits->GetEntriesFast();
386 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
387
ac359ffe 388 Int_t ii;
94f5f8f2 389 Int_t dig[5]; //cluster detector indeces
2bf4d9d6 390 Int_t parTOF[7]; //The TOF signal parameters
94f5f8f2 391 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
392 for (ii=0; ii<nDigits; ii++) {
393 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
394 dig[0]=d->GetSector();
395 dig[1]=d->GetPlate();
396 dig[2]=d->GetStrip();
397 dig[3]=d->GetPadz();
398 dig[4]=d->GetPadx();
399
729f0d7f 400 /* check valid index */
401 if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
402
56483762 403 // Do not reconstruct anything in the holes
404 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
405 if (dig[1]==2) { // plate with holes
406 inholes++;
407 continue;
408 }
409 }
410
2bf66a2d 411 // AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
94f5f8f2 412
94f5f8f2 413 parTOF[0] = d->GetTdc(); //the TDC signal
414 parTOF[1] = d->GetToT(); //the ToT signal
415 parTOF[2] = d->GetAdc(); // the adc charge
416 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
417 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
2bf4d9d6 418 parTOF[5] = 0; // deltaBC
419 parTOF[6] = 0; // L0-L1 latency
ac359ffe 420
421 Double_t posClus[3];
422 Double_t covClus[6];
423 UShort_t volIdClus=GetClusterVolIndex(dig);
424 GetClusterPars(dig,posClus,covClus);
2bf66a2d 425 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 426 InsertCluster(tofCluster);
427
428 }
429
bafe290d 430 AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
94f5f8f2 431
432 CalibrateRecPoint();
433 FillRecPoint();
434
435 clusterTree->Fill();
436 ResetRecpoint();
437
bafe290d 438 AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
439 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 440 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
94f5f8f2 441
d08a92dd 442}
443//______________________________________________________________________________
444
445void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
446 TTree *clustersTree)
447{
448 //
449 // Converts RAW data to recpoints for TOF
450 //
451
515faf5d 452 TStopwatch stopwatch;
453 stopwatch.Start();
454
56483762 455 Int_t inholes = 0;
456
d0eb8f39 457 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
d08a92dd 458
459 ResetRecpoint();
460
461 Int_t bufsize = 32000;
462 clustersTree->Branch("TOF", &fRecPoints, bufsize);
463
15ec34b9 464 TClonesArray * clonesRawData;
465
15ec34b9 466 Int_t dummy = -1;
d08a92dd 467
468 Int_t detectorIndex[5];
2bf4d9d6 469 Int_t parTOF[7];
d08a92dd 470
15ec34b9 471 ofstream ftxt;
472 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
473
0275b7df 474 //AliTOFRawStream tofInput(rawReader);
475 fTOFRawStream.Clear();
476 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 477
bafe290d 478 if (fDecoderVersion)
479 AliInfo("Using New Decoder");
480
15ec34b9 481 Int_t indexDDL = 0;
482 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
483
484 rawReader->Reset();
bafe290d 485 if (fDecoderVersion)
0275b7df 486 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
0275b7df 487 else fTOFRawStream.LoadRawData(indexDDL);
15ec34b9 488
0275b7df 489 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
15ec34b9 490
491 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
492
493 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
494
c3891b7a 495 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
496 if (tofRawDatum->GetTOF()==-1) continue;
15ec34b9 497
498 if (fVerbose==2) {
499 if (indexDDL<10) ftxt << " " << indexDDL;
500 else ftxt << " " << indexDDL;
501 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
502 else ftxt << " " << tofRawDatum->GetTRM();
503 ftxt << " " << tofRawDatum->GetTRMchain();
504 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
505 else ftxt << " " << tofRawDatum->GetTDC();
506 ftxt << " " << tofRawDatum->GetTDCchannel();
507 }
508
0275b7df 509 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
510 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
15ec34b9 511 dummy = detectorIndex[3];
512 detectorIndex[3] = detectorIndex[4];
513 detectorIndex[4] = dummy;
514
515 if (fVerbose==2) {
516 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
517 else ftxt << " -> " << detectorIndex[0];
518 ftxt << " " << detectorIndex[1];
519 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
520 else ftxt << " " << detectorIndex[2];
521 ftxt << " " << detectorIndex[3];
522 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
523 else ftxt << " " << detectorIndex[4];
524 }
525
729f0d7f 526 /* check valid index */
527 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
528
56483762 529 // Do not reconstruct anything in the holes
530 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
531 if (detectorIndex[1]==2) { // plate with holes
532 inholes++;
533 continue;
534 }
535 }
536
bf33f8f0 537 parTOF[0] = tofRawDatum->GetTOF(); //TDC
538 parTOF[1] = tofRawDatum->GetTOT(); // TOT
539 parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
540 parTOF[3] = -1;//raw data: no track of undecalib sim time
541 parTOF[4] = tofRawDatum->GetTOF(); // RAW time
2bf4d9d6 542 parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
543 parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
ac359ffe 544 Double_t posClus[3];
545 Double_t covClus[6];
546 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
547 Int_t lab[3]={-1,-1,-1};
548 Bool_t status=kTRUE;
549 GetClusterPars(detectorIndex,posClus,covClus);
2bf66a2d 550 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 551 InsertCluster(tofCluster);
552
553 if (fVerbose==2) {
bf33f8f0 554 if (parTOF[1]<10)ftxt << " " << parTOF[1];
555 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
556 else ftxt << " " << parTOF[1];
557 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
558 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
559 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
560 else ftxt << " " << parTOF[3] << endl;
15ec34b9 561 }
562
563 } // closed loop on TOF raw data per current DDL file
564
565 clonesRawData->Clear();
566
567 } // closed loop on DDL index
568
15ec34b9 569 if (fVerbose==2) ftxt.close();
d08a92dd 570
bafe290d 571 AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
d08a92dd 572
37879eed 573 CalibrateRecPoint();
d08a92dd 574 FillRecPoint();
575
576 clustersTree->Fill();
37879eed 577
d08a92dd 578 ResetRecpoint();
579
515faf5d 580 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
581 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 582 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
515faf5d 583
d08a92dd 584}
585//______________________________________________________________________________
586
587void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
588{
589 //
590 // Converts RAW data to recpoints for TOF
591 //
592
515faf5d 593 TStopwatch stopwatch;
594 stopwatch.Start();
595
56483762 596 Int_t inholes = 0;
597
d0eb8f39 598 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
d08a92dd 599
600 fRunLoader->GetEvent(iEvent);
601
2bf66a2d 602 AliDebug(2,Form(" Event number %2d ", iEvent));
d08a92dd 603
604 fTreeR = fTOFLoader->TreeR();
605
606 if (fTreeR == 0x0){
607 fTOFLoader->MakeTree("R");
608 fTreeR = fTOFLoader->TreeR();
609 }
610
611 Int_t bufsize = 32000;
612 fTreeR->Branch("TOF", &fRecPoints, bufsize);
613
15ec34b9 614 TClonesArray * clonesRawData;
615
15ec34b9 616 Int_t dummy = -1;
d08a92dd 617
d0eb8f39 618 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2bf4d9d6 619 Int_t parTOF[7];
15ec34b9 620 ofstream ftxt;
621 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
622
0275b7df 623 //AliTOFRawStream tofInput(rawReader);
624 fTOFRawStream.Clear();
625 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 626
bafe290d 627 if (fDecoderVersion)
628 AliInfo("Using New Decoder");
629
15ec34b9 630 Int_t indexDDL = 0;
d08a92dd 631 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
632
633 rawReader->Reset();
bafe290d 634 if (fDecoderVersion)
0275b7df 635 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
0275b7df 636 else fTOFRawStream.LoadRawData(indexDDL);
15ec34b9 637
0275b7df 638 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
15ec34b9 639
640 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
641
642 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
643
c3891b7a 644 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
645 if (tofRawDatum->GetTOF()==-1) continue;
15ec34b9 646
647 if (fVerbose==2) {
648 if (indexDDL<10) ftxt << " " << indexDDL;
649 else ftxt << " " << indexDDL;
650 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
651 else ftxt << " " << tofRawDatum->GetTRM();
652 ftxt << " " << tofRawDatum->GetTRMchain();
653 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
654 else ftxt << " " << tofRawDatum->GetTDC();
655 ftxt << " " << tofRawDatum->GetTDCchannel();
656 }
657
0275b7df 658 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
659 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
15ec34b9 660 dummy = detectorIndex[3];
661 detectorIndex[3] = detectorIndex[4];
662 detectorIndex[4] = dummy;
663
664 if (fVerbose==2) {
665 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
666 else ftxt << " -> " << detectorIndex[0];
667 ftxt << " " << detectorIndex[1];
668 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
669 else ftxt << " " << detectorIndex[2];
670 ftxt << " " << detectorIndex[3];
671 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
672 else ftxt << " " << detectorIndex[4];
673 }
d0eb8f39 674
729f0d7f 675 /* check valid index */
676 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
677
56483762 678 // Do not reconstruct anything in the holes
679 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
680 if (detectorIndex[1]==2) { // plate with holes
681 inholes++;
682 continue;
683 }
684 }
685
bf33f8f0 686 parTOF[0] = tofRawDatum->GetTOF(); // TDC
687 parTOF[1] = tofRawDatum->GetTOT(); // TOT
688 parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
689 parTOF[3] = -1; //raw data: no track of the undecalib sim time
690 parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
2bf4d9d6 691 parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
692 parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
ac359ffe 693 Double_t posClus[3];
694 Double_t covClus[6];
695 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
696 Int_t lab[3]={-1,-1,-1};
697 Bool_t status=kTRUE;
698 GetClusterPars(detectorIndex,posClus,covClus);
699 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 700 InsertCluster(tofCluster);
701
15ec34b9 702 if (fVerbose==2) {
bf33f8f0 703 if (parTOF[1]<10)ftxt << " " << parTOF[1];
704 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
705 else ftxt << " " << parTOF[1];
706 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
707 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
708 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
709 else ftxt << " " << parTOF[3] << endl;
15ec34b9 710 }
d08a92dd 711
15ec34b9 712 } // closed loop on TOF raw data per current DDL file
713
714 clonesRawData->Clear();
715
716 } // closed loop on DDL index
717
718 if (fVerbose==2) ftxt.close();
d08a92dd 719
bafe290d 720 AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
d08a92dd 721
37879eed 722 CalibrateRecPoint();
d08a92dd 723 FillRecPoint();
724
725 fTreeR->Fill();
726 ResetRecpoint();
727
728 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
729 fTOFLoader->WriteRecPoints("OVERWRITE");
730
515faf5d 731 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
732 stopwatch.RealTime(),stopwatch.CpuTime()));
56483762 733 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
515faf5d 734
d08a92dd 735}
736//______________________________________________________________________________
737
738void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
739{
740 //
741 // Converts RAW data to MC digits for TOF
742 //
743 // (temporary solution)
744 //
745
515faf5d 746 TStopwatch stopwatch;
747 stopwatch.Start();
748
ba66add8 749 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
15ec34b9 750
d08a92dd 751 fRunLoader->GetEvent(iEvent);
752
753 fTreeD = fTOFLoader->TreeD();
754 if (fTreeD)
755 {
d0eb8f39 756 AliInfo("TreeD re-creation");
d08a92dd 757 fTreeD = 0x0;
758 fTOFLoader->MakeTree("D");
759 fTreeD = fTOFLoader->TreeD();
760 }
761
15ec34b9 762 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
d08a92dd 763 Int_t bufsize = 32000;
764 fTreeD->Branch("TOF", &tofDigits, bufsize);
765
d08a92dd 766 fRunLoader->GetEvent(iEvent);
767
2bf66a2d 768 AliDebug(2,Form(" Event number %2d ", iEvent));
d08a92dd 769
15ec34b9 770 TClonesArray * clonesRawData;
771
772 Int_t dummy = -1;
d08a92dd 773
774 Int_t detectorIndex[5];
bf33f8f0 775 Int_t digit[4];
d08a92dd 776
0275b7df 777 //AliTOFRawStream tofInput(rawReader);
778 fTOFRawStream.Clear();
779 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 780
bafe290d 781 if (fDecoderVersion)
782 AliInfo("Using New Decoder");
783
15ec34b9 784 Int_t indexDDL = 0;
d08a92dd 785 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
786
787 rawReader->Reset();
bafe290d 788 if (fDecoderVersion)
0275b7df 789 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
0275b7df 790 else fTOFRawStream.LoadRawData(indexDDL);
d08a92dd 791
0275b7df 792 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
d08a92dd 793
15ec34b9 794 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
d0eb8f39 795
15ec34b9 796 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
d0eb8f39 797
3e2f0097 798 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
799 if (tofRawDatum->GetTOF()==-1) continue;
15ec34b9 800
0275b7df 801 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
802 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
15ec34b9 803 dummy = detectorIndex[3];
804 detectorIndex[3] = detectorIndex[4];
805 detectorIndex[4] = dummy;
d0eb8f39 806
0275b7df 807 digit[0] = fTOFRawStream.GetTofBin();
808 digit[1] = fTOFRawStream.GetToTbin();
809 digit[2] = fTOFRawStream.GetToTbin();
bf33f8f0 810 digit[3] = -1;
d08a92dd 811
812 Int_t tracknum[3]={-1,-1,-1};
813
814 TClonesArray &aDigits = *tofDigits;
815 Int_t last=tofDigits->GetEntriesFast();
816 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
817
818 } // while loop
819
15ec34b9 820 clonesRawData->Clear();
821
d08a92dd 822 } // DDL Loop
823
824 fTreeD->Fill();
825
826 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
827 fTOFLoader->WriteDigits("OVERWRITE");
2bf66a2d 828
829 delete tofDigits;
830
515faf5d 831 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
832 stopwatch.RealTime(),stopwatch.CpuTime()));
833
94f5f8f2 834}
835
836//______________________________________________________________________________
837
838void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
839{
840 //
841 // Converts RAW data to MC digits for TOF for the current event
842 //
843 //
844
845 TStopwatch stopwatch;
846 stopwatch.Start();
847
ba66add8 848 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
94f5f8f2 849
850 if (!digitsTree)
851 {
852 AliError("No input digits Tree");
853 return;
854 }
855
856 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
857 Int_t bufsize = 32000;
858 digitsTree->Branch("TOF", &tofDigits, bufsize);
859
94f5f8f2 860 TClonesArray * clonesRawData;
861
862 Int_t dummy = -1;
863
864 Int_t detectorIndex[5];
865 Int_t digit[4];
866
0275b7df 867 //AliTOFRawStream tofInput(rawReader);
868 fTOFRawStream.Clear();
869 fTOFRawStream.SetRawReader(rawReader);
ef58b2af 870
bafe290d 871 if (fDecoderVersion)
872 AliInfo("Using New Decoder");
873
94f5f8f2 874 Int_t indexDDL = 0;
875 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
876
877 rawReader->Reset();
bafe290d 878 if (fDecoderVersion)
0275b7df 879 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
0275b7df 880 else fTOFRawStream.LoadRawData(indexDDL);
94f5f8f2 881
0275b7df 882 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
94f5f8f2 883
884 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
885
886 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
887
3e2f0097 888 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
889 if (tofRawDatum->GetTOF()==-1) continue;
94f5f8f2 890
0275b7df 891 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
892 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
94f5f8f2 893 dummy = detectorIndex[3];
894 detectorIndex[3] = detectorIndex[4];
895 detectorIndex[4] = dummy;
896
0275b7df 897 digit[0] = fTOFRawStream.GetTofBin();
898 digit[1] = fTOFRawStream.GetToTbin();
899 digit[2] = fTOFRawStream.GetToTbin();
94f5f8f2 900 digit[3] = -1;
901
902 Int_t tracknum[3]={-1,-1,-1};
903
904 TClonesArray &aDigits = *tofDigits;
905 Int_t last=tofDigits->GetEntriesFast();
906 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
907
908 } // while loop
909
910 clonesRawData->Clear();
911
912 } // DDL Loop
913
914 digitsTree->Fill();
915
2bf66a2d 916 delete tofDigits;
917
918 AliDebug(1, Form("Got %d digits: ", fDigits->GetEntries()));
94f5f8f2 919 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
920 stopwatch.RealTime(),stopwatch.CpuTime()));
921
d08a92dd 922}
923//______________________________________________________________________________
924
925Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
926 //---------------------------------------------------------------------------//
927 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
928 //---------------------------------------------------------------------------//
929 if (fNumberOfTofClusters==kTofMaxCluster) {
930 AliError("Too many clusters !");
931 return 1;
932 }
933
934 if (fNumberOfTofClusters==0) {
935 fTofClusters[fNumberOfTofClusters++] = tofCluster;
936 return 0;
937 }
938
939 Int_t ii = FindClusterIndex(tofCluster->GetZ());
940 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
941 fTofClusters[ii] = tofCluster;
942 fNumberOfTofClusters++;
943
944 return 0;
945
946}
947//_________________________________________________________________________
948
949Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
950 //--------------------------------------------------------------------
ac359ffe 951 // This function returns the index of the nearest cluster in z
d08a92dd 952 //--------------------------------------------------------------------
953 if (fNumberOfTofClusters==0) return 0;
954 if (z <= fTofClusters[0]->GetZ()) return 0;
955 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
956 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
957 for (; b<e; m=(b+e)/2) {
958 if (z > fTofClusters[m]->GetZ()) b=m+1;
959 else e=m;
960 }
961
962 return m;
963
964}
965//_________________________________________________________________________
966
967void AliTOFClusterFinder::FillRecPoint()
968{
969 //
970 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
971 // in Z) in the global TClonesArray of AliTOFcluster,
972 // i.e. fRecPoints.
973 //
974
975 Int_t ii, jj;
976
977 Int_t detectorIndex[5];
2bf4d9d6 978 Int_t parTOF[7];
d08a92dd 979 Int_t trackLabels[3];
980 Int_t digitIndex = -1;
bf33f8f0 981 Bool_t status=kTRUE;
d08a92dd 982
983 TClonesArray &lRecPoints = *fRecPoints;
984
985 for (ii=0; ii<fNumberOfTofClusters; ii++) {
986
987 digitIndex = fTofClusters[ii]->GetIndex();
988 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
989 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
bf33f8f0 990 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
991 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
992 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
993 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
994 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
2bf4d9d6 995 parTOF[5] = fTofClusters[ii]->GetDeltaBC();//deltaBC
996 parTOF[6] = fTofClusters[ii]->GetL0L1Latency();//L0-L1 latency
bf33f8f0 997 status=fTofClusters[ii]->GetStatus();
ac359ffe 998 Double_t posClus[3];
999 Double_t covClus[6];
1000 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
1001 GetClusterPars(detectorIndex,posClus,covClus);
1002 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 1003
2bf66a2d 1004 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 1005 ii, volIdClus, posClus[0], posClus[1], posClus[2],
1006 fTofClusters[ii]->GetSigmaX2(),
1007 fTofClusters[ii]->GetSigmaXY(),
1008 fTofClusters[ii]->GetSigmaXZ(),
1009 fTofClusters[ii]->GetSigmaY2(),
1010 fTofClusters[ii]->GetSigmaYZ(),
1011 fTofClusters[ii]->GetSigmaZ2(),
1012 trackLabels[0], trackLabels[1], trackLabels[2],
1013 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
1014 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
1015 status, digitIndex));
1016
d08a92dd 1017 } // loop on clusters
1018
1019}
37879eed 1020
1021//_________________________________________________________________________
1022void AliTOFClusterFinder::CalibrateRecPoint()
1023{
1024 //
1025 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1026 // in Z) in the global TClonesArray of AliTOFcluster,
1027 // i.e. fRecPoints.
1028 //
1029
1030 Int_t ii, jj;
1031
1032 Int_t detectorIndex[5];
1033 Int_t digitIndex = -1;
a33fec85 1034 Double_t tToT;
1035 Double_t timeCorr;
bf33f8f0 1036 Int_t tdcCorr;
2bf4d9d6 1037 Float_t tdcLatencyWindow;
bafe290d 1038 AliDebug(1," Calibrating TOF Clusters");
1039
17149e6b 1040 AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();
1041 AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();
ba66add8 1042 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
2bf4d9d6 1043
1044 AliTOFDeltaBCOffset *deltaBCOffsetObj = fTOFcalib->GetDeltaBCOffset();
1045 Int_t deltaBCOffset = deltaBCOffsetObj->GetDeltaBCOffset();
1046 AliTOFCTPLatency *ctpLatencyObj = fTOFcalib->GetCTPLatency();
1047 Float_t ctpLatency = ctpLatencyObj->GetCTPLatency();
1048 AliTOFT0Fill *t0FillObj = fTOFcalib->GetT0Fill();
1049 Float_t t0Fill = t0FillObj->GetT0Fill();
bafe290d 1050
ba66add8 1051 TString validity = (TString)fTOFcalib->GetOfflineValidity();
ba66add8 1052 Int_t calibration = -1;
1053 if (validity.CompareTo("valid")==0) {
bafe290d 1054 AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
ba66add8 1055 calibration = 1;
bafe290d 1056 } else {
1057 AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
ba66add8 1058 calibration = 0 ;
1059 }
bafe290d 1060
37879eed 1061 for (ii=0; ii<fNumberOfTofClusters; ii++) {
1062 digitIndex = fTofClusters[ii]->GetIndex();
1063 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1064
ba66add8 1065 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
37879eed 1066
17149e6b 1067 UChar_t statusPulser=calStatus->GetPulserStatus(index);
1068 UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1069 UChar_t statusHW=calStatus->GetHWStatus(index);
1070 UChar_t status=calStatus->GetStatus(index);
2bf4d9d6 1071 tdcLatencyWindow = calStatus->GetLatencyWindow(index) * 1.e3; /* ns -> ps */
1072
17149e6b 1073 //check the status, also unknown is fine!!!!!!!
1074
2bf66a2d 1075 AliDebug(2, Form(" Status for channel %d = %d",index, (Int_t)status));
17149e6b 1076 if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
2bf66a2d 1077 AliDebug(2, Form(" Bad Status for channel %d",index));
7fffa85b 1078 fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1079 }
1080 else {
2bf66a2d 1081 AliDebug(2, Form(" Good Status for channel %d",index));
7fffa85b 1082 }
58d8d9a3 1083 // Get Rough channel online equalization
17149e6b 1084 Double_t roughDelay=(Double_t)calDelay->GetDelay(index); // in ns
ba66add8 1085 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
58d8d9a3 1086 // Get Refined channel offline calibration parameters
ba66add8 1087 if (calibration ==1){
1088 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1089 Double_t par[6];
1090 for (Int_t j = 0; j<6; j++){
1091 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1092 }
bf33f8f0 1093 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
2bf66a2d 1094 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
ba66add8 1095 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
1096 tToT*=1.E-3; //ToT in ns
1097 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1098 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)
1099 }
1100 else {
1101 timeCorr = roughDelay; // correction in ns
1102 }
1103 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 1104 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
a33fec85 1105 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1106 timeCorr*=1.E3;
1107 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
2bf4d9d6 1108
1109 /* here timeCorr should be already corrected for calibration.
1110 * we now go into further corrections keeping in mind that timeCorr
1111 * is in ps.
1112 *
1113 * the following corrections are performed in this way:
1114 *
1115 * time = timeRaw - deltaBC + L0L1Latency + CTPLatency - TDCLatencyWindow - T0Fill
1116 *
1117 */
1118
1119 AliDebug(2, Form("applying further corrections (DeltaBC): DeltaBC=%d (BC bins), DeltaBCoffset=%d (BC bins)", fTofClusters[ii]->GetDeltaBC(), deltaBCOffset));
1120 AliDebug(2, Form("applying further corrections (L0L1Latency): L0L1Latency=%d (BC bins)", fTofClusters[ii]->GetL0L1Latency()));
1121 AliDebug(2, Form("applying further corrections (CTPLatency): CTPLatency=%f (ps)", ctpLatency));
1122 AliDebug(2, Form("applying further corrections (TDCLatencyWindow): TDCLatencyWindow=%f (ps)", tdcLatencyWindow));
1123 AliDebug(2, Form("applying further corrections (T0Fill): T0Fill=%f (ps)", t0Fill));
1124
1125 /* deltaBC correction */
1126 timeCorr -= (fTofClusters[ii]->GetDeltaBC() - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
1127 /* L0L1-latency correction */
1128 timeCorr += fTofClusters[ii]->GetL0L1Latency() * AliTOFGeometry::BunchCrossingBinWidth();
1129 /* CTP-latency correction (from OCDB) */
1130 timeCorr += ctpLatency;
1131 /* TDC latency-window correction (from OCDB) */
1132 timeCorr -= tdcLatencyWindow;
1133 /* T0Fill correction (from OCDB) */
1134 timeCorr -= t0Fill;
1135
1136 /*
1137 * end of furhter corrections
1138 */
1139
a33fec85 1140 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
340693af 1141 fTofClusters[ii]->SetTDC(tdcCorr);
37879eed 1142 } // loop on clusters
1143
37879eed 1144}
d08a92dd 1145//______________________________________________________________________________
1146
1147void AliTOFClusterFinder::ResetRecpoint()
1148{
1149 //
1150 // Clear the list of reconstructed points
1151 //
1152
1153 fNumberOfTofClusters = 0;
1154 if (fRecPoints) fRecPoints->Clear();
1155
1156}
1157//______________________________________________________________________________
1158
1159void AliTOFClusterFinder::Load()
1160{
1161 //
1162 // Load TOF.Digits.root and TOF.RecPoints.root files
1163 //
1164
1165 fTOFLoader->LoadDigits("READ");
1166 fTOFLoader->LoadRecPoints("recreate");
1167
1168}
1169//______________________________________________________________________________
1170
1171void AliTOFClusterFinder::LoadClusters()
1172{
1173 //
1174 // Load TOF.RecPoints.root file
1175 //
1176
1177 fTOFLoader->LoadRecPoints("recreate");
1178
1179}
1180//______________________________________________________________________________
1181
1182void AliTOFClusterFinder::UnLoad()
1183{
1184 //
1185 // Unload TOF.Digits.root and TOF.RecPoints.root files
1186 //
1187
1188 fTOFLoader->UnloadDigits();
1189 fTOFLoader->UnloadRecPoints();
1190
1191}
1192//______________________________________________________________________________
1193
1194void AliTOFClusterFinder::UnLoadClusters()
1195{
1196 //
1197 // Unload TOF.RecPoints.root file
1198 //
1199
1200 fTOFLoader->UnloadRecPoints();
1201
1202}
ac359ffe 1203//-------------------------------------------------------------------------
0e74c396 1204UShort_t AliTOFClusterFinder::GetClusterVolIndex(const Int_t * const ind) const {
ac359ffe 1205
1206 //First of all get the volume ID to retrieve the l2t transformation...
1207 //
1208 // Detector numbering scheme
1209 Int_t nSector = 18;
1210 Int_t nPlate = 5;
1211 Int_t nStripA = 15;
1212 Int_t nStripB = 19;
1213 Int_t nStripC = 19;
1214
1215 Int_t isector =ind[0];
1216 if (isector >= nSector)
1217 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1218 Int_t iplate = ind[1];
1219 if (iplate >= nPlate)
1220 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1221 Int_t istrip = ind[2];
1222
1223 Int_t stripOffset = 0;
1224 switch (iplate) {
1225 case 0:
1226 stripOffset = 0;
1227 break;
1228 case 1:
1229 stripOffset = nStripC;
1230 break;
1231 case 2:
1232 stripOffset = nStripC+nStripB;
1233 break;
1234 case 3:
1235 stripOffset = nStripC+nStripB+nStripA;
1236 break;
1237 case 4:
1238 stripOffset = nStripC+nStripB+nStripA+nStripB;
1239 break;
1240 default:
1241 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1242 break;
1243 };
1244
1245 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1246 stripOffset +
1247 istrip;
1248
1249 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1250 return volIndex;
1251}
1252//
1253//-------------------------------------------------------------------------
1254void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1255
1256 //First of all get the volume ID to retrieve the l2t transformation...
1257 //
1258 UShort_t volIndex = GetClusterVolIndex(ind);
1259 //
1260 //
1261 //we now go in the system of the strip: determine the local coordinates
1262 //
1263 //
1264 // 47---------------------------------------------------0 ^ z
1265 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1266 // ----------------------------------------------------- | y going outwards
1267 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1268
1269 // ----------------------------------------------------- |
1270 // x <-----------------------------------------------------
1271
b3e52baa 1272 /*
1273 Float_t localX = (ind[4]-23.5)*AliTOFGeometry::XPad();
1274 Float_t localY = 0;
1275 Float_t localZ = (ind[3]- 0.5)*AliTOFGeometry::ZPad();
1276 */
1277 Float_t localX = (ind[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.;
1278 Float_t localY = 0;
1279 Float_t localZ = (ind[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::ZPad()+AliTOFGeometry::ZPad()/2.;
ac359ffe 1280 //move to the tracking ref system
1281
1282 Double_t lpos[3];
b3e52baa 1283 lpos[0] = localX;
1284 lpos[1] = localY;
1285 lpos[2] = localZ;
ac359ffe 1286
1287 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1288 // Get The position in the track ref system
1289 Double_t tpos[3];
1290 l2t->MasterToLocal(lpos,tpos);
b3e52baa 1291 pos[0] = tpos[0];
1292 pos[1] = tpos[1];
1293 pos[2] = tpos[2];
ac359ffe 1294
1295 //Get The cluster covariance in the track ref system
1296 Double_t lcov[9];
1297
1298 //cluster covariance in the local system:
1299 // sx2 0 0
1300 // 0 0 0
1301 // 0 0 sz2
1302
b3e52baa 1303 lcov[0] = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1304 lcov[1] = 0;
1305 lcov[2] = 0;
1306 lcov[3] = 0;
1307 lcov[4] = 0;
1308 lcov[5] = 0;
1309 lcov[6] = 0;
1310 lcov[7] = 0;
1311 lcov[8] = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
ac359ffe 1312
1313 //cluster covariance in the tracking system:
1314 TGeoHMatrix m;
1315 m.SetRotation(lcov);
1316 m.Multiply(l2t);
1317 m.MultiplyLeft(&l2t->Inverse());
1318 Double_t *tcov = m.GetRotationMatrix();
1319 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1320 cov[3] = tcov[4]; cov[4] = tcov[5];
1321 cov[5] = tcov[8];
1322
1323 return;
1324
1325}