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