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