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