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