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