]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFClusterFinder.cxx
object for storing TOF decoded RAW data
[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/*
15ec34b9 17$Log$
515faf5d 18Revision 1.22 2007/04/19 17:26:32 arcelli
19Fix a bug (add some debug printout
20
0451c2e6 21Revision 1.21 2007/04/18 17:28:12 arcelli
22Set the ToT bin width to the one actually used...
23
605370db 24Revision 1.20 2007/03/09 09:57:23 arcelli
25 Remove a forgotten include of Riostrem
26
c77771e2 27Revision 1.19 2007/03/08 15:41:20 arcelli
28set uncorrected times when filling RecPoints
29
3432ebfa 30Revision 1.18 2007/03/06 16:31:20 arcelli
31Add Uncorrected TOF Time signal
32
aa5476d8 33Revision 1.17 2007/02/28 18:09:11 arcelli
34Add protection against failed retrieval of the CDB cal object, now Reconstruction exits with AliFatal
35
a1cab04c 36Revision 1.16 2007/02/20 15:57:00 decaro
37Raw data update: to read the TOF raw data defined in UNPACKED mode
38
d08a92dd 39
40Revision 0.03 2005/07/28 A. De Caro
41 Implement public method
42 Raw2Digits(Int_t, AliRawReader *)
43 to convert digits from raw data in MC digits
44 (temporary solution)
45
46Revision 0.02 2005/07/27 A. De Caro
47 Implement public method
48 Digits2RecPoint(Int_t)
49 to convert digits in clusters
50
51Revision 0.02 2005/07/26 A. De Caro
52 Implement private methods
53 InsertCluster(AliTOFcluster *)
54 FindClusterIndex(Double_t)
55 originally implemented in AliTOFtracker
56 by S. Arcelli and C. Zampolli
57
58Revision 0.01 2005/07/25 A. De Caro
59 Implement public methods
60 Digits2RecPoint(AliRawReader *, TTree *)
61 Digits2RecPoint(Int_t, AliRawReader *)
62 to convert raw data in clusters
63 */
64
65////////////////////////////////////////////////////////////////
66// //
67// Class for TOF cluster finder //
68// //
69// Starting from Raw Data, create rec points, //
70// fill TreeR for TOF, //
71// write TOF.RecPoints.root file //
72// //
73////////////////////////////////////////////////////////////////
74
15ec34b9 75
0e46b9ae 76#include "TClonesArray.h"
15ec34b9 77//#include "TFile.h"
515faf5d 78#include "TStopwatch.h"
0e46b9ae 79#include "TTree.h"
d08a92dd 80
d0eb8f39 81#include "AliDAQ.h"
0e46b9ae 82#include "AliLoader.h"
d08a92dd 83#include "AliLog.h"
0e46b9ae 84#include "AliRawReader.h"
d08a92dd 85#include "AliRunLoader.h"
d08a92dd 86
37879eed 87#include "AliTOFCal.h"
15ec34b9 88#include "AliTOFcalib.h"
37879eed 89#include "AliTOFChannel.h"
d08a92dd 90#include "AliTOFClusterFinder.h"
0e46b9ae 91#include "AliTOFcluster.h"
92#include "AliTOFdigit.h"
0e46b9ae 93#include "AliTOFGeometry.h"
15ec34b9 94#include "AliTOFGeometryV5.h"
95#include "AliTOFrawData.h"
0e46b9ae 96#include "AliTOFRawStream.h"
3432ebfa 97#include "Riostream.h"
0e46b9ae 98
15ec34b9 99//extern TFile *gFile;
d08a92dd 100
101ClassImp(AliTOFClusterFinder)
102
103AliTOFClusterFinder::AliTOFClusterFinder():
104 fRunLoader(0),
105 fTOFLoader(0),
106 fTreeD(0),
107 fTreeR(0),
58d8d9a3 108 fTOFGeometry(new AliTOFGeometryV5()),
d08a92dd 109 fDigits(new TClonesArray("AliTOFdigit", 4000)),
110 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
15ec34b9 111 fNumberOfTofClusters(0),
112 fVerbose(0)
d08a92dd 113{
114//
115// Constructor
116//
117
3bbdf45d 118 AliInfo("V5 TOF Geometry is taken as the default");
37879eed 119
d08a92dd 120}
121//______________________________________________________________________________
122
123AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader):
124 fRunLoader(runLoader),
125 fTOFLoader(runLoader->GetLoader("TOFLoader")),
126 fTreeD(0),
127 fTreeR(0),
58d8d9a3 128 fTOFGeometry(new AliTOFGeometryV5()),
d08a92dd 129 fDigits(new TClonesArray("AliTOFdigit", 4000)),
130 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
15ec34b9 131 fNumberOfTofClusters(0),
132 fVerbose(0)
d08a92dd 133{
134//
135// Constructor
136//
137
0f49d1bc 138// runLoader->CdGAFile();
139// TFile *in=(TFile*)gFile;
140// in->cd();
141// fTOFGeometry = (AliTOFGeometry*)in->Get("TOFgeometry");
d08a92dd 142
7aeeaf38 143}
144
145//------------------------------------------------------------------------
146AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
58d8d9a3 147 :TObject(),
148 fRunLoader(0),
149 fTOFLoader(0),
150 fTreeD(0),
151 fTreeR(0),
152 fTOFGeometry(new AliTOFGeometryV5()),
153 fDigits(new TClonesArray("AliTOFdigit", 4000)),
154 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
15ec34b9 155 fNumberOfTofClusters(0),
156 fVerbose(0)
7aeeaf38 157{
158 // copy constructor
159 this->fDigits=source.fDigits;
160 this->fRecPoints=source.fRecPoints;
161 this->fTOFGeometry=source.fTOFGeometry;
162
163}
164
165//------------------------------------------------------------------------
d0eb8f39 166AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
7aeeaf38 167{
168 // ass. op.
169 this->fDigits=source.fDigits;
170 this->fRecPoints=source.fRecPoints;
171 this->fTOFGeometry=source.fTOFGeometry;
15ec34b9 172 this->fVerbose=source.fVerbose;
7aeeaf38 173 return *this;
174
d08a92dd 175}
176//______________________________________________________________________________
177
178AliTOFClusterFinder::~AliTOFClusterFinder()
179{
180
181 //
182 // Destructor
183 //
184
185 if (fDigits)
186 {
187 fDigits->Delete();
188 delete fDigits;
189 fDigits=0;
190 }
191 if (fRecPoints)
192 {
193 fRecPoints->Delete();
194 delete fRecPoints;
195 fRecPoints=0;
196 }
197
198 delete fTOFGeometry;
199
200}
201//______________________________________________________________________________
202
203void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
204{
205 //
206 // Converts digits to recpoints for TOF
207 //
208
515faf5d 209 TStopwatch stopwatch;
210 stopwatch.Start();
211
d08a92dd 212 fRunLoader->GetEvent(iEvent);
213
214 fTreeD = fTOFLoader->TreeD();
215 if (fTreeD == 0x0)
216 {
217 AliFatal("AliTOFClusterFinder: Can not get TreeD");
218 }
219
220 TBranch *branch = fTreeD->GetBranch("TOF");
221 if (!branch) {
222 AliError("can't get the branch with the TOF digits !");
223 return;
224 }
225
15ec34b9 226 TClonesArray *digits = new TClonesArray("AliTOFdigit",10000);
d08a92dd 227 branch->SetAddress(&digits);
228
229 ResetRecpoint();
230
231 fTreeR = fTOFLoader->TreeR();
232 if (fTreeR == 0x0)
233 {
234 fTOFLoader->MakeTree("R");
235 fTreeR = fTOFLoader->TreeR();
236 }
237
238 Int_t bufsize = 32000;
239 fTreeR->Branch("TOF", &fRecPoints, bufsize);
240
241 fTreeD->GetEvent(0);
242 Int_t nDigits = digits->GetEntriesFast();
243 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
244
245 Int_t ii, jj;
246 Int_t dig[5];
247 Float_t g[3];
248 Double_t h[5];
340693af 249 Float_t tToT;
250 Double_t tTdcND;
d08a92dd 251 for (ii=0; ii<nDigits; ii++) {
252 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
253 dig[0]=d->GetSector();
254 dig[1]=d->GetPlate();
255 dig[2]=d->GetStrip();
256 dig[3]=d->GetPadz();
257 dig[4]=d->GetPadx();
258
d0eb8f39 259 //AliInfo(Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
260
d08a92dd 261 for (jj=0; jj<3; jj++) g[jj] = 0.;
262 fTOFGeometry->GetPos(dig,g);
263
264 h[0] = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
265 h[1] = TMath::ATan2(g[1],g[0]);
266 h[2] = g[2];
267 h[3] = d->GetTdc();
268 h[4] = d->GetAdc();
340693af 269 tToT = d->GetToT();
270 tTdcND = d->GetTdcND();
d08a92dd 271
340693af 272 AliTOFcluster *tofCluster = new AliTOFcluster(h,d->GetTracks(),dig,ii,tToT, tTdcND);
aa5476d8 273 tofCluster->SetTDCRAW(d->GetTdc());
d08a92dd 274 InsertCluster(tofCluster);
275
276 }
277
278 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
279
37879eed 280 CalibrateRecPoint();
d08a92dd 281 FillRecPoint();
282
283 fTreeR->Fill();
284 ResetRecpoint();
285
286 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
287 fTOFLoader->WriteRecPoints("OVERWRITE");
288
515faf5d 289 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
290 stopwatch.RealTime(),stopwatch.CpuTime()));
291
d08a92dd 292}
293//______________________________________________________________________________
294
295void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
296 TTree *clustersTree)
297{
298 //
299 // Converts RAW data to recpoints for TOF
300 //
301
515faf5d 302 TStopwatch stopwatch;
303 stopwatch.Start();
304
d0eb8f39 305 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
306 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
d08a92dd 307
308 ResetRecpoint();
309
310 Int_t bufsize = 32000;
311 clustersTree->Branch("TOF", &fRecPoints, bufsize);
312
15ec34b9 313 TClonesArray * clonesRawData;
314
d08a92dd 315 Int_t ii = 0;
15ec34b9 316 Int_t dummy = -1;
d08a92dd 317
318 Int_t detectorIndex[5];
319 Float_t position[3];
320 Double_t cylindricalPosition[5];
340693af 321 Float_t tToT;
322 Double_t tTdcND;
d08a92dd 323
15ec34b9 324 ofstream ftxt;
325 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
326
327 Int_t indexDDL = 0;
328 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
329
330 rawReader->Reset();
331 AliTOFRawStream tofInput(rawReader);
332 tofInput.LoadRawData(indexDDL);
333
334 clonesRawData = (TClonesArray*)tofInput.GetRawData();
335
336 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
337
338 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
339
340 if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
341
342 if (fVerbose==2) {
343 if (indexDDL<10) ftxt << " " << indexDDL;
344 else ftxt << " " << indexDDL;
345 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
346 else ftxt << " " << tofRawDatum->GetTRM();
347 ftxt << " " << tofRawDatum->GetTRMchain();
348 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
349 else ftxt << " " << tofRawDatum->GetTDC();
350 ftxt << " " << tofRawDatum->GetTDCchannel();
351 }
352
353 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
354 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
355 dummy = detectorIndex[3];
356 detectorIndex[3] = detectorIndex[4];
357 detectorIndex[4] = dummy;
358
359 if (fVerbose==2) {
360 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
361 else ftxt << " -> " << detectorIndex[0];
362 ftxt << " " << detectorIndex[1];
363 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
364 else ftxt << " " << detectorIndex[2];
365 ftxt << " " << detectorIndex[3];
366 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
367 else ftxt << " " << detectorIndex[4];
368 }
369
370 for (ii=0; ii<3; ii++) position[ii] = 0.;
371 fTOFGeometry->GetPos(detectorIndex, position);
372
373 cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
374 cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
375 cylindricalPosition[2] = position[2];
376 cylindricalPosition[3] = tofRawDatum->GetTOF();
377 cylindricalPosition[4] = tofRawDatum->GetTOT();
378 tToT = tofRawDatum->GetTOT();
379 tTdcND = -1.;
380 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
381 tofCluster->SetToT(tToT);
382 tofCluster->SetTDCND(tTdcND);
aa5476d8 383 tofCluster->SetTDCRAW(tofRawDatum->GetTOF());
15ec34b9 384 InsertCluster(tofCluster);
385
386 if (fVerbose==2) {
387 if (cylindricalPosition[4]<10) ftxt << " " << cylindricalPosition[4];
388 else if (cylindricalPosition[4]>=10 && cylindricalPosition[4]<100) ftxt << " " << cylindricalPosition[4];
389 else ftxt << " " << cylindricalPosition[4];
390 if (cylindricalPosition[3]<10) ftxt << " " << cylindricalPosition[3] << endl;
391 else if (cylindricalPosition[3]>=10 && cylindricalPosition[3]<100) ftxt << " " << cylindricalPosition[3] << endl;
392 else if (cylindricalPosition[3]>=100 && cylindricalPosition[3]<1000) ftxt << " " << cylindricalPosition[3] << endl;
393 else ftxt << " " << cylindricalPosition[3] << endl;
394 }
395
396 } // closed loop on TOF raw data per current DDL file
397
398 clonesRawData->Clear();
399
400 } // closed loop on DDL index
401
402 /*
403 Int_t indexDDL = 0;
d08a92dd 404 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
405
406 rawReader->Reset();
407 AliTOFRawStream tofInput(rawReader);
362c9d61 408 rawReader->Select("TOF", indexDDL, indexDDL);
d08a92dd 409
410 while(tofInput.Next()) {
411
d0eb8f39 412 for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
413
d08a92dd 414 detectorIndex[0] = tofInput.GetSector();
415 detectorIndex[1] = tofInput.GetPlate();
416 detectorIndex[2] = tofInput.GetStrip();
417 detectorIndex[3] = tofInput.GetPadZ();
418 detectorIndex[4] = tofInput.GetPadX();
419
d0eb8f39 420 //AliInfo(Form(" %2i %1i %2i %1i %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
421
422 if (detectorIndex[0]==-1 ||
423 detectorIndex[1]==-1 ||
424 detectorIndex[2]==-1 ||
425 detectorIndex[3]==-1 ||
426 detectorIndex[4]==-1) continue;
427
d08a92dd 428 for (ii=0; ii<3; ii++) position[ii] = 0.;
429
430 fTOFGeometry->GetPos(detectorIndex, position);
431
432 cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
433 cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
434 cylindricalPosition[2] = position[2];
435 cylindricalPosition[3] = tofInput.GetTofBin();
d0eb8f39 436 cylindricalPosition[4] = tofInput.GetToTbin();
437 tToT = tofInput.GetToTbin();
340693af 438 tTdcND = -1.;
d08a92dd 439 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
340693af 440 tofCluster->SetToT(tToT);
441 tofCluster->SetTDCND(tTdcND);
d08a92dd 442 InsertCluster(tofCluster);
443
444 } // while loop
445
446 } // loop on DDL files
15ec34b9 447 */
448
449 if (fVerbose==2) ftxt.close();
d08a92dd 450
451 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
452
37879eed 453 CalibrateRecPoint();
d08a92dd 454 FillRecPoint();
455
456 clustersTree->Fill();
37879eed 457
d08a92dd 458 ResetRecpoint();
459
515faf5d 460 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
461 stopwatch.RealTime(),stopwatch.CpuTime()));
462
d08a92dd 463}
464//______________________________________________________________________________
465
466void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
467{
468 //
469 // Converts RAW data to recpoints for TOF
470 //
471
515faf5d 472 TStopwatch stopwatch;
473 stopwatch.Start();
474
d0eb8f39 475 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
476 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
d08a92dd 477
478 fRunLoader->GetEvent(iEvent);
479
480 AliDebug(2,Form(" Event number %2i ", iEvent));
481
482 fTreeR = fTOFLoader->TreeR();
483
484 if (fTreeR == 0x0){
485 fTOFLoader->MakeTree("R");
486 fTreeR = fTOFLoader->TreeR();
487 }
488
489 Int_t bufsize = 32000;
490 fTreeR->Branch("TOF", &fRecPoints, bufsize);
491
15ec34b9 492 TClonesArray * clonesRawData;
493
d08a92dd 494 Int_t ii = 0;
15ec34b9 495 Int_t dummy = -1;
d08a92dd 496
d0eb8f39 497 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
d08a92dd 498 Float_t position[3];
499 Double_t cylindricalPosition[5];
340693af 500 Float_t tToT;
501 Double_t tTdcND;
d08a92dd 502
15ec34b9 503 ofstream ftxt;
504 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
505
506 Int_t indexDDL = 0;
d08a92dd 507 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
508
509 rawReader->Reset();
510 AliTOFRawStream tofInput(rawReader);
15ec34b9 511 tofInput.LoadRawData(indexDDL);
512
513 clonesRawData = (TClonesArray*)tofInput.GetRawData();
514
515 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
516
517 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
518
519 if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
520
521 if (fVerbose==2) {
522 if (indexDDL<10) ftxt << " " << indexDDL;
523 else ftxt << " " << indexDDL;
524 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
525 else ftxt << " " << tofRawDatum->GetTRM();
526 ftxt << " " << tofRawDatum->GetTRMchain();
527 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
528 else ftxt << " " << tofRawDatum->GetTDC();
529 ftxt << " " << tofRawDatum->GetTDCchannel();
530 }
531
532 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
533 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
534 dummy = detectorIndex[3];
535 detectorIndex[3] = detectorIndex[4];
536 detectorIndex[4] = dummy;
537
538 if (fVerbose==2) {
539 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
540 else ftxt << " -> " << detectorIndex[0];
541 ftxt << " " << detectorIndex[1];
542 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
543 else ftxt << " " << detectorIndex[2];
544 ftxt << " " << detectorIndex[3];
545 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
546 else ftxt << " " << detectorIndex[4];
547 }
d0eb8f39 548
d08a92dd 549 for (ii=0; ii<3; ii++) position[ii] = 0.;
d08a92dd 550 fTOFGeometry->GetPos(detectorIndex, position);
15ec34b9 551
552 cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
553 cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
554 cylindricalPosition[2] = position[2];
555 cylindricalPosition[3] = tofRawDatum->GetTOF();
556 cylindricalPosition[4] = tofRawDatum->GetTOT();
557 tToT = tofRawDatum->GetTOT();
340693af 558 tTdcND = -1.;
d08a92dd 559 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
340693af 560 tofCluster->SetToT(tToT);
561 tofCluster->SetTDCND(tTdcND);
aa5476d8 562 tofCluster->SetTDCRAW(tofRawDatum->GetTOF());
d08a92dd 563 InsertCluster(tofCluster);
564
15ec34b9 565 if (fVerbose==2) {
566 if (cylindricalPosition[4]<10) ftxt << " " << cylindricalPosition[4];
567 else if (cylindricalPosition[4]>=10 && cylindricalPosition[4]<100) ftxt << " " << cylindricalPosition[4];
568 else ftxt << " " << cylindricalPosition[4];
569 if (cylindricalPosition[3]<10) ftxt << " " << cylindricalPosition[3] << endl;
570 else if (cylindricalPosition[3]>=10 && cylindricalPosition[3]<100) ftxt << " " << cylindricalPosition[3] << endl;
571 else if (cylindricalPosition[3]>=100 && cylindricalPosition[3]<1000) ftxt << " " << cylindricalPosition[3] << endl;
572 else ftxt << " " << cylindricalPosition[3] << endl;
573 }
d08a92dd 574
15ec34b9 575 } // closed loop on TOF raw data per current DDL file
576
577 clonesRawData->Clear();
578
579 } // closed loop on DDL index
580
581 if (fVerbose==2) ftxt.close();
d08a92dd 582
583 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
584
37879eed 585 CalibrateRecPoint();
d08a92dd 586 FillRecPoint();
587
588 fTreeR->Fill();
589 ResetRecpoint();
590
591 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
592 fTOFLoader->WriteRecPoints("OVERWRITE");
593
515faf5d 594 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
595 stopwatch.RealTime(),stopwatch.CpuTime()));
596
d08a92dd 597}
598//______________________________________________________________________________
599
600void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
601{
602 //
603 // Converts RAW data to MC digits for TOF
604 //
605 // (temporary solution)
606 //
607
515faf5d 608 TStopwatch stopwatch;
609 stopwatch.Start();
610
15ec34b9 611 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
612 const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
613
d08a92dd 614 fRunLoader->GetEvent(iEvent);
615
616 fTreeD = fTOFLoader->TreeD();
617 if (fTreeD)
618 {
d0eb8f39 619 AliInfo("TreeD re-creation");
d08a92dd 620 fTreeD = 0x0;
621 fTOFLoader->MakeTree("D");
622 fTreeD = fTOFLoader->TreeD();
623 }
624
15ec34b9 625 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
d08a92dd 626 Int_t bufsize = 32000;
627 fTreeD->Branch("TOF", &tofDigits, bufsize);
628
d08a92dd 629 fRunLoader->GetEvent(iEvent);
630
631 AliDebug(2,Form(" Event number %2i ", iEvent));
632
15ec34b9 633 TClonesArray * clonesRawData;
634
635 Int_t dummy = -1;
d08a92dd 636
637 Int_t detectorIndex[5];
d0eb8f39 638 Float_t digit[4];
d08a92dd 639
15ec34b9 640 Int_t indexDDL = 0;
d08a92dd 641 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
642
643 rawReader->Reset();
644 AliTOFRawStream tofInput(rawReader);
15ec34b9 645 tofInput.LoadRawData(indexDDL);
d08a92dd 646
15ec34b9 647 clonesRawData = (TClonesArray*)tofInput.GetRawData();
d08a92dd 648
15ec34b9 649 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
d0eb8f39 650
15ec34b9 651 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
d0eb8f39 652
15ec34b9 653 if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
654
655 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
656 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
657 dummy = detectorIndex[3];
658 detectorIndex[3] = detectorIndex[4];
659 detectorIndex[4] = dummy;
d0eb8f39 660
d08a92dd 661 digit[0] = (Float_t)tofInput.GetTofBin();
d0eb8f39 662 digit[1] = (Float_t)tofInput.GetToTbin();
663 digit[2] = (Float_t)tofInput.GetToTbin();
664 digit[3] = -1.;
d08a92dd 665
666 Int_t tracknum[3]={-1,-1,-1};
667
668 TClonesArray &aDigits = *tofDigits;
669 Int_t last=tofDigits->GetEntriesFast();
670 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
671
672 } // while loop
673
15ec34b9 674 clonesRawData->Clear();
675
d08a92dd 676 } // DDL Loop
677
678 fTreeD->Fill();
679
680 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
681 fTOFLoader->WriteDigits("OVERWRITE");
682
515faf5d 683 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
684 stopwatch.RealTime(),stopwatch.CpuTime()));
685
d08a92dd 686}
687//______________________________________________________________________________
688
689Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
690 //---------------------------------------------------------------------------//
691 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
692 //---------------------------------------------------------------------------//
693 if (fNumberOfTofClusters==kTofMaxCluster) {
694 AliError("Too many clusters !");
695 return 1;
696 }
697
698 if (fNumberOfTofClusters==0) {
699 fTofClusters[fNumberOfTofClusters++] = tofCluster;
700 return 0;
701 }
702
703 Int_t ii = FindClusterIndex(tofCluster->GetZ());
704 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
705 fTofClusters[ii] = tofCluster;
706 fNumberOfTofClusters++;
707
708 return 0;
709
710}
711//_________________________________________________________________________
712
713Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
714 //--------------------------------------------------------------------
715 // This function returns the index of the nearest cluster
716 //--------------------------------------------------------------------
717 if (fNumberOfTofClusters==0) return 0;
718 if (z <= fTofClusters[0]->GetZ()) return 0;
719 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
720 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
721 for (; b<e; m=(b+e)/2) {
722 if (z > fTofClusters[m]->GetZ()) b=m+1;
723 else e=m;
724 }
725
726 return m;
727
728}
729//_________________________________________________________________________
730
731void AliTOFClusterFinder::FillRecPoint()
732{
733 //
734 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
735 // in Z) in the global TClonesArray of AliTOFcluster,
736 // i.e. fRecPoints.
737 //
738
739 Int_t ii, jj;
740
741 Int_t detectorIndex[5];
742 Double_t cylindricalPosition[5];
743 Int_t trackLabels[3];
744 Int_t digitIndex = -1;
58d8d9a3 745 Float_t tToT=0.;
746 Double_t tTdcND=0.;
3432ebfa 747 Double_t tTdcRAW=0.;
58d8d9a3 748 Bool_t cStatus = kTRUE;
d08a92dd 749
750 TClonesArray &lRecPoints = *fRecPoints;
751
752 for (ii=0; ii<fNumberOfTofClusters; ii++) {
753
754 digitIndex = fTofClusters[ii]->GetIndex();
755 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
756 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
757 cylindricalPosition[0] = fTofClusters[ii]->GetR();
758 cylindricalPosition[1] = fTofClusters[ii]->GetPhi();
759 cylindricalPosition[2] = fTofClusters[ii]->GetZ();
760 cylindricalPosition[3] = fTofClusters[ii]->GetTDC();
761 cylindricalPosition[4] = fTofClusters[ii]->GetADC();
340693af 762 tToT = fTofClusters[ii]->GetToT();
763 tTdcND = fTofClusters[ii]->GetTDCND();
58d8d9a3 764 cStatus=fTofClusters[ii]->GetStatus();
3432ebfa 765 tTdcRAW=fTofClusters[ii]->GetTDCRAW();
766 new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, trackLabels, detectorIndex, digitIndex, tToT, tTdcND, tTdcRAW,cStatus);
d08a92dd 767
768 //AliInfo(Form("%3i %3i %f %f %f %f %f %2i %2i %2i %1i %2i",ii,digitIndex, cylindricalPosition[2],cylindricalPosition[0],cylindricalPosition[1],cylindricalPosition[3],cylindricalPosition[4],detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
769
770 } // loop on clusters
771
772}
37879eed 773
774//_________________________________________________________________________
775void AliTOFClusterFinder::CalibrateRecPoint()
776{
777 //
778 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
779 // in Z) in the global TClonesArray of AliTOFcluster,
780 // i.e. fRecPoints.
781 //
782
783 Int_t ii, jj;
784
785 Int_t detectorIndex[5];
786 Int_t digitIndex = -1;
340693af 787 Float_t tToT;
788 Float_t tdcCorr;
37879eed 789 AliInfo(" Calibrating TOF Clusters: ")
790 AliTOFcalib *calib = new AliTOFcalib(fTOFGeometry);
3f2bddfa 791 // calib->ReadParFromCDB("TOF/Calib",0); // original
a1cab04c 792 // Use AliCDBManager's run number
793 if(!calib->ReadParFromCDB("TOF/Calib",-1)) {AliFatal("Exiting, no CDB object found!!!");exit(0);}
794
340693af 795 AliTOFCal *calTOFArray = calib->GetTOFCalArray();
37879eed 796
797 for (ii=0; ii<fNumberOfTofClusters; ii++) {
798 digitIndex = fTofClusters[ii]->GetIndex();
799 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
800
801 Int_t index = calib->GetIndex(detectorIndex);
802
340693af 803 AliTOFChannel * calChannel = calTOFArray->GetChannel(index);
58d8d9a3 804
805 // Get channel status
806 Bool_t status=calChannel->GetStatus();
807 if(status)fTofClusters[ii]->SetStatus(!status); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
808
809 // Get Rough channel online equalization
810 Float_t roughDelay=calChannel->GetDelay();
0451c2e6 811 AliDebug(2,Form(" channel delay = %f", roughDelay));
58d8d9a3 812 // Get Refined channel offline calibration parameters
37879eed 813 Float_t par[6];
814 for (Int_t j = 0; j<6; j++){
340693af 815 par[j]=calChannel->GetSlewPar(j);
37879eed 816 }
605370db 817 tToT = fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()*1.E-3;
58d8d9a3 818 Float_t 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+roughDelay;
0451c2e6 819 AliDebug(2,Form(" time correction (ns) = %f", timeCorr));
820 AliDebug(2,Form(" channel time, uncorr (ns)= %f",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3 ));
340693af 821 tdcCorr=(fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()+32)*1.E-3-timeCorr;
822 tdcCorr=(tdcCorr*1E3-32)/AliTOFGeometry::TdcBinWidth();
823 fTofClusters[ii]->SetTDC(tdcCorr);
0451c2e6 824 AliDebug(2,Form(" channel time, corr (ns)= %f",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3 ));
37879eed 825
826 } // loop on clusters
827
828 delete calib;
829}
d08a92dd 830//______________________________________________________________________________
831
832void AliTOFClusterFinder::ResetRecpoint()
833{
834 //
835 // Clear the list of reconstructed points
836 //
837
838 fNumberOfTofClusters = 0;
839 if (fRecPoints) fRecPoints->Clear();
840
841}
842//______________________________________________________________________________
843
844void AliTOFClusterFinder::Load()
845{
846 //
847 // Load TOF.Digits.root and TOF.RecPoints.root files
848 //
849
850 fTOFLoader->LoadDigits("READ");
851 fTOFLoader->LoadRecPoints("recreate");
852
853}
854//______________________________________________________________________________
855
856void AliTOFClusterFinder::LoadClusters()
857{
858 //
859 // Load TOF.RecPoints.root file
860 //
861
862 fTOFLoader->LoadRecPoints("recreate");
863
864}
865//______________________________________________________________________________
866
867void AliTOFClusterFinder::UnLoad()
868{
869 //
870 // Unload TOF.Digits.root and TOF.RecPoints.root files
871 //
872
873 fTOFLoader->UnloadDigits();
874 fTOFLoader->UnloadRecPoints();
875
876}
877//______________________________________________________________________________
878
879void AliTOFClusterFinder::UnLoadClusters()
880{
881 //
882 // Unload TOF.RecPoints.root file
883 //
884
885 fTOFLoader->UnloadRecPoints();
886
887}
888//______________________________________________________________________________