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