]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFClusterFinder.cxx
Modifications to ITS standalone tracker: 1) improve efficiency at low pt for p-p...
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinder.cxx
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 /* 
17 $Log: AliTOFClusterFinder.cxx,v $
18 Revision 1.31  2007/11/24 14:53:19  zampolli
19 Status flag implemented as UChar_t
20
21 Revision 1.30  2007/10/04 13:08:52  arcelli
22 updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
23
24 Revision 1.29  2007/10/03 10:42:33  arcelli
25 updates to handle new AliTOFcluster, inheriting form AliCluster3D
26
27 Revision 1.28  2007/05/31 16:06:05  arcelli
28 move instance of AliRawStream outside loop on DDL
29
30 Revision 1.27  2007/05/02 16:31:49  arcelli
31 Add methods to handle single event reconstruction.  retrieval of Calib
32 info moved to AliTOFReconstructor ctor, and passed via a pointer to
33 AliTOFcalib
34
35 Revision 1.26  2007/04/30 19:02:24  arcelli
36 hopefully the last refinements for correct type conversion in calibration
37
38 Revision 1.25  2007/04/30 15:22:17  arcelli
39 Change TOF digit Time, Tot etc to int type
40
41 Revision 1.24  2007/04/27 11:19:31  arcelli
42 updates for the new decoder
43
44 Revision 1.23  2007/04/23 16:51:39  decaro
45 Digits-to-raw_data conversion: correction for a more real description
46 (A.De Caro, R.Preghenella)
47
48 Revision 1.22  2007/04/19 17:26:32  arcelli
49 Fix a bug (add some debug printout
50
51 Revision 1.21  2007/04/18 17:28:12  arcelli
52 Set the ToT bin width to the one actually used...
53
54 Revision 1.20  2007/03/09 09:57:23  arcelli
55  Remove a forgotten include of Riostrem
56
57 Revision 1.19  2007/03/08 15:41:20  arcelli
58 set uncorrected times when filling RecPoints
59
60 Revision 1.18  2007/03/06 16:31:20  arcelli
61 Add Uncorrected TOF Time signal
62
63 Revision 1.17  2007/02/28 18:09:11  arcelli
64 Add protection against failed retrieval of the CDB cal object,
65 now Reconstruction exits with AliFatal
66
67 Revision 1.16  2007/02/20 15:57:00  decaro
68 Raw data update: to read the TOF raw data defined in UNPACKED mode
69
70
71 Revision 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
77 Revision 0.02  2005/07/27 A. De Caro
78          Implement public method
79          Digits2RecPoint(Int_t)
80          to convert digits in clusters
81
82 Revision 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
89 Revision 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
106 #include "Riostream.h"
107
108 #include "TClonesArray.h"
109 #include "TStopwatch.h"
110 #include "TTree.h"
111 //#include <TGeoManager.h>
112 #include <TGeoMatrix.h>
113 //#include <TGeoPhysicalNode.h>
114
115 #include "AliDAQ.h"
116 #include "AliLoader.h"
117 #include "AliLog.h"
118 #include "AliRawReader.h"
119 #include "AliRunLoader.h"
120 //#include "AliAlignObj.h"
121 #include <AliGeomManager.h>
122
123 #include "AliTOFcalib.h"
124 #include "AliTOFChannelOnlineArray.h"
125 #include "AliTOFChannelOnlineStatusArray.h"
126 #include "AliTOFChannelOffline.h"
127 #include "AliTOFClusterFinder.h"
128 #include "AliTOFcluster.h"
129 #include "AliTOFdigit.h"
130 #include "AliTOFGeometry.h"
131 #include "AliTOFrawData.h"
132 #include "AliTOFRawStream.h"
133
134 //extern TFile *gFile;
135
136 ClassImp(AliTOFClusterFinder)
137
138 AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
139   fRunLoader(0),
140   fTOFLoader(0),
141   fTreeD(0),
142   fTreeR(0),
143   fDigits(new TClonesArray("AliTOFdigit", 4000)),
144   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
145   fNumberOfTofClusters(0),
146   fVerbose(0),
147   fDecoderVersion(0),
148   fTOFcalib(calib)
149 {
150 //
151 // Constructor
152 //
153
154 }
155 //______________________________________________________________________________
156
157 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
158   fRunLoader(runLoader),
159   fTOFLoader(runLoader->GetLoader("TOFLoader")),
160   fTreeD(0),
161   fTreeR(0),
162   fDigits(new TClonesArray("AliTOFdigit", 4000)),
163   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
164   fNumberOfTofClusters(0),
165   fVerbose(0),
166   fDecoderVersion(0),
167   fTOFcalib(calib)
168 {
169 //
170 // Constructor
171 //
172
173 }
174
175 //------------------------------------------------------------------------
176 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
177   :TObject(source),
178   fRunLoader(0),
179   fTOFLoader(0),
180   fTreeD(0),
181   fTreeR(0),
182   fDigits(source.fDigits),
183   fRecPoints(source.fRecPoints),
184   fNumberOfTofClusters(0),
185   fVerbose(0),
186   fDecoderVersion(source.fDecoderVersion),
187   fTOFcalib(source.fTOFcalib)
188 {
189   // copy constructor
190 }
191
192 //------------------------------------------------------------------------
193 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
194 {
195   // ass. op.
196
197   if (this == &source)
198     return *this;
199
200   TObject::operator=(source);  
201   fDigits=source.fDigits;
202   fRecPoints=source.fRecPoints;
203   fVerbose=source.fVerbose;
204   fDecoderVersion=source.fDecoderVersion;
205   fTOFcalib=source.fTOFcalib;
206   return *this;
207
208 }
209 //______________________________________________________________________________
210
211 AliTOFClusterFinder::~AliTOFClusterFinder()
212 {
213
214   //
215   // Destructor
216   //
217
218   if (fDigits)
219     {
220       fDigits->Delete();
221       delete fDigits;
222       fDigits=0;
223     }
224   if (fRecPoints)
225     {
226       fRecPoints->Delete();
227       delete fRecPoints;
228       fRecPoints=0;
229     }
230
231 }
232 //______________________________________________________________________________
233
234 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
235 {
236   //
237   // Converts digits to recpoints for TOF
238   //
239
240   TStopwatch stopwatch;
241   stopwatch.Start();
242
243   Int_t inholes = 0;
244
245   fRunLoader->GetEvent(iEvent);
246
247   fTreeD = fTOFLoader->TreeD();
248   if (fTreeD == 0x0)
249     {
250       AliFatal("AliTOFClusterFinder: Can not get TreeD");
251     }
252
253   TBranch *branch = fTreeD->GetBranch("TOF");
254   if (!branch) { 
255     AliError("can't get the branch with the TOF digits !");
256     return;
257   }
258
259   TClonesArray staticdigits("AliTOFdigit",10000);
260   staticdigits.Clear();
261   TClonesArray *digits =&staticdigits;
262   branch->SetAddress(&digits);
263
264   ResetRecpoint();
265
266   fTreeR = fTOFLoader->TreeR();
267   if (fTreeR == 0x0)
268     {
269       fTOFLoader->MakeTree("R");
270       fTreeR = fTOFLoader->TreeR();
271     }
272
273   Int_t bufsize = 32000;
274   fTreeR->Branch("TOF", &fRecPoints, bufsize);
275
276   fTreeD->GetEvent(0);
277   Int_t nDigits = digits->GetEntriesFast();
278   AliDebug(2,Form("Number of TOF digits: %d",nDigits));
279
280   Int_t ii;
281   Int_t dig[5]; //cluster detector indeces
282   Int_t  parTOF[5]; //The TOF signal parameters
283   Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
284   for (ii=0; ii<nDigits; ii++) {
285     AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
286     dig[0]=d->GetSector();
287     dig[1]=d->GetPlate();
288     dig[2]=d->GetStrip();
289     dig[3]=d->GetPadz();
290     dig[4]=d->GetPadx();
291
292     // Do not reconstruct anything in the holes
293     if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
294       if (dig[1]==2) { // plate with holes
295         inholes++;
296         continue;
297       }
298     }
299
300     //    AliDebug(2,Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
301
302     parTOF[0] = d->GetTdc(); //the TDC signal
303     parTOF[1] = d->GetToT(); //the ToT signal
304     parTOF[2] = d->GetAdc(); // the adc charge
305     parTOF[3] = d->GetTdcND(); // non decalibrated sim time
306     parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
307     Double_t posClus[3];
308     Double_t covClus[6];
309     UShort_t volIdClus=GetClusterVolIndex(dig);
310     GetClusterPars(dig, posClus,covClus);
311     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);
312     InsertCluster(tofCluster);
313
314   }
315
316   AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
317
318   CalibrateRecPoint();
319   FillRecPoint();
320
321   fTreeR->Fill();
322   ResetRecpoint();
323
324   fTOFLoader = fRunLoader->GetLoader("TOFLoader");  
325   fTOFLoader->WriteRecPoints("OVERWRITE");
326
327   AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
328                stopwatch.RealTime(),stopwatch.CpuTime()));
329   if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
330
331 }
332
333 //______________________________________________________________________________
334
335 void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
336 {
337   //
338   // Converts digits to recpoints for TOF
339   //
340
341   TStopwatch stopwatch;
342   stopwatch.Start();
343
344   Int_t inholes = 0;
345
346   ///  fRunLoader->GetEvent(iEvent);
347
348   if (digitsTree == 0x0)
349     {
350       AliFatal("AliTOFClusterFinder: Can not get TreeD");
351     }
352
353   TBranch *branch = digitsTree->GetBranch("TOF");
354   if (!branch) { 
355     AliError("can't get the branch with the TOF digits !");
356     return;
357   }
358
359   TClonesArray staticdigits("AliTOFdigit",10000);
360   staticdigits.Clear();
361   TClonesArray *digits = & staticdigits;
362   branch->SetAddress(&digits);
363
364   ResetRecpoint();
365
366   fTreeR=clusterTree;
367   Int_t bufsize = 32000;
368   fTreeR->Branch("TOF", &fRecPoints, bufsize);
369
370   digitsTree->GetEvent(0);
371   Int_t nDigits = digits->GetEntriesFast();
372   AliDebug(2,Form("Number of TOF digits: %d",nDigits));
373
374   Int_t ii;
375   Int_t dig[5]; //cluster detector indeces
376   Int_t  parTOF[5]; //The TOF signal parameters
377   Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
378   for (ii=0; ii<nDigits; ii++) {
379     AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
380     dig[0]=d->GetSector();
381     dig[1]=d->GetPlate();
382     dig[2]=d->GetStrip();
383     dig[3]=d->GetPadz();
384     dig[4]=d->GetPadx();
385
386     // Do not reconstruct anything in the holes
387     if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
388       if (dig[1]==2) { // plate with holes
389         inholes++;
390         continue;
391       }
392     }
393
394     //    AliDebug(2,Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
395
396     parTOF[0] = d->GetTdc(); //the TDC signal
397     parTOF[1] = d->GetToT(); //the ToT signal
398     parTOF[2] = d->GetAdc(); // the adc charge
399     parTOF[3] = d->GetTdcND(); // non decalibrated sim time
400     parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
401     
402     Double_t posClus[3];
403     Double_t covClus[6];
404     UShort_t volIdClus=GetClusterVolIndex(dig);
405     GetClusterPars(dig,posClus,covClus);
406    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);
407     InsertCluster(tofCluster);
408
409   }
410
411   AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
412
413   CalibrateRecPoint();
414   FillRecPoint();
415
416   clusterTree->Fill();
417   ResetRecpoint();
418
419   AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
420                stopwatch.RealTime(),stopwatch.CpuTime()));
421   if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
422
423 }
424 //______________________________________________________________________________
425
426 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
427                                            TTree *clustersTree)
428 {
429   //
430   // Converts RAW data to recpoints for TOF
431   //
432
433   TStopwatch stopwatch;
434   stopwatch.Start();
435
436   Int_t inholes = 0;
437
438   //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
439   const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
440
441   ResetRecpoint();
442
443   Int_t bufsize = 32000;
444   clustersTree->Branch("TOF", &fRecPoints, bufsize);
445
446   TClonesArray * clonesRawData;
447
448   Int_t dummy = -1;
449
450   Int_t detectorIndex[5];
451   Int_t parTOF[5];
452
453   ofstream ftxt;
454   if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
455
456   AliTOFRawStream tofInput(rawReader);
457
458   Int_t indexDDL = 0;
459   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
460
461     rawReader->Reset();
462     if (fDecoderVersion) {
463       AliInfo("Using New Decoder \n"); 
464       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
465     }
466     else tofInput.LoadRawData(indexDDL);
467
468     clonesRawData = (TClonesArray*)tofInput.GetRawData();
469
470     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
471
472       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
473
474       //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
475       if (tofRawDatum->GetTOF()==-1) continue;
476
477       if (fVerbose==2) {
478         if (indexDDL<10) ftxt << "  " << indexDDL;
479         else         ftxt << " " << indexDDL;
480         if (tofRawDatum->GetTRM()<10) ftxt << "  " << tofRawDatum->GetTRM();
481         else         ftxt << " " << tofRawDatum->GetTRM();
482         ftxt << "  " << tofRawDatum->GetTRMchain();
483         if (tofRawDatum->GetTDC()<10) ftxt << "  " << tofRawDatum->GetTDC();
484         else         ftxt << " " << tofRawDatum->GetTDC();
485         ftxt << "  " << tofRawDatum->GetTDCchannel();
486       }
487
488       tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
489                                     tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
490       dummy = detectorIndex[3];
491       detectorIndex[3] = detectorIndex[4];
492       detectorIndex[4] = dummy;
493
494       if (fVerbose==2) {
495         if (detectorIndex[0]<10) ftxt  << "  ->  " << detectorIndex[0];
496         else              ftxt  << "  -> " << detectorIndex[0];
497         ftxt << "  " << detectorIndex[1];
498         if (detectorIndex[2]<10) ftxt << "  " << detectorIndex[2];
499         else              ftxt << " " << detectorIndex[2];
500         ftxt << "  " << detectorIndex[3];
501         if (detectorIndex[4]<10) ftxt << "  " << detectorIndex[4];
502         else              ftxt << " " << detectorIndex[4];
503       }
504
505       // Do not reconstruct anything in the holes
506       if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
507         if (detectorIndex[1]==2) { // plate with holes
508           inholes++;
509           continue;
510         }
511       }
512
513       parTOF[0] = tofRawDatum->GetTOF(); //TDC
514       parTOF[1] = tofRawDatum->GetTOT(); // TOT
515       parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
516       parTOF[3] = -1;//raw data: no track of undecalib sim time
517       parTOF[4] = tofRawDatum->GetTOF(); // RAW time
518       Double_t posClus[3];
519       Double_t covClus[6];
520       UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
521       Int_t lab[3]={-1,-1,-1};
522       Bool_t status=kTRUE;
523       GetClusterPars(detectorIndex,posClus,covClus);
524      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);
525       InsertCluster(tofCluster);
526
527       if (fVerbose==2) {
528         if (parTOF[1]<10)ftxt << "        " << parTOF[1];
529         else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << "      " << parTOF[1];
530         else ftxt << "      " << parTOF[1];
531         if (parTOF[0]<10) ftxt << "      " << parTOF[0] << endl;
532         else if (parTOF[0]>=10 && parTOF[0]<100)   ftxt << "    " << parTOF[0] << endl;
533         else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << "    " << parTOF[0] << endl;
534         else ftxt << "   " << parTOF[3] << endl;
535       }
536
537     } // closed loop on TOF raw data per current DDL file
538
539     clonesRawData->Clear();
540
541   } // closed loop on DDL index
542
543   if (fVerbose==2) ftxt.close();
544
545   AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
546
547   CalibrateRecPoint();
548   FillRecPoint();
549
550   clustersTree->Fill();
551
552   ResetRecpoint();
553
554   AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
555                    stopwatch.RealTime(),stopwatch.CpuTime()));
556   if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
557
558 }
559 //______________________________________________________________________________
560
561 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
562 {
563   //
564   // Converts RAW data to recpoints for TOF
565   //
566
567   TStopwatch stopwatch;
568   stopwatch.Start();
569
570   Int_t inholes = 0;
571
572   //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
573   const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
574
575   fRunLoader->GetEvent(iEvent);
576
577   AliDebug(2,Form(" Event number %2i ", iEvent));
578
579   fTreeR = fTOFLoader->TreeR();
580
581   if (fTreeR == 0x0){
582     fTOFLoader->MakeTree("R");
583     fTreeR = fTOFLoader->TreeR();
584   }
585
586   Int_t bufsize = 32000;
587   fTreeR->Branch("TOF", &fRecPoints, bufsize);
588
589   TClonesArray * clonesRawData;
590
591   Int_t dummy = -1;
592
593   Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
594   Int_t parTOF[5];
595   ofstream ftxt;
596   if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
597
598   AliTOFRawStream tofInput(rawReader);
599
600   Int_t indexDDL = 0;
601   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
602
603     rawReader->Reset();
604     if (fDecoderVersion) {
605       AliInfo("Using New Decoder \n"); 
606       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
607     }
608     else tofInput.LoadRawData(indexDDL);
609
610     clonesRawData = (TClonesArray*)tofInput.GetRawData();
611
612     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
613
614       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
615
616       //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
617       if (tofRawDatum->GetTOF()==-1) continue;
618
619       if (fVerbose==2) {
620         if (indexDDL<10) ftxt << "  " << indexDDL;
621         else         ftxt << " " << indexDDL;
622         if (tofRawDatum->GetTRM()<10) ftxt << "  " << tofRawDatum->GetTRM();
623         else         ftxt << " " << tofRawDatum->GetTRM();
624         ftxt << "  " << tofRawDatum->GetTRMchain();
625         if (tofRawDatum->GetTDC()<10) ftxt << "  " << tofRawDatum->GetTDC();
626         else         ftxt << " " << tofRawDatum->GetTDC();
627         ftxt << "  " << tofRawDatum->GetTDCchannel();
628       }
629
630       tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
631                                     tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
632       dummy = detectorIndex[3];
633       detectorIndex[3] = detectorIndex[4];
634       detectorIndex[4] = dummy;
635
636       if (fVerbose==2) {
637         if (detectorIndex[0]<10) ftxt  << "  ->  " << detectorIndex[0];
638         else              ftxt  << "  -> " << detectorIndex[0];
639         ftxt << "  " << detectorIndex[1];
640         if (detectorIndex[2]<10) ftxt << "  " << detectorIndex[2];
641         else              ftxt << " " << detectorIndex[2];
642         ftxt << "  " << detectorIndex[3];
643         if (detectorIndex[4]<10) ftxt << "  " << detectorIndex[4];
644         else              ftxt << " " << detectorIndex[4];
645       }
646
647       // Do not reconstruct anything in the holes
648       if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
649         if (detectorIndex[1]==2) { // plate with holes
650           inholes++;
651           continue;
652         }
653       }
654
655       parTOF[0] = tofRawDatum->GetTOF(); // TDC
656       parTOF[1] = tofRawDatum->GetTOT(); // TOT
657       parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
658       parTOF[3] = -1; //raw data: no track of the undecalib sim time
659       parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
660       Double_t posClus[3];
661       Double_t covClus[6];
662       UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
663       Int_t lab[3]={-1,-1,-1};
664       Bool_t status=kTRUE;
665       GetClusterPars(detectorIndex,posClus,covClus);
666       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);
667       InsertCluster(tofCluster);
668
669       if (fVerbose==2) {
670         if (parTOF[1]<10)ftxt << "        " << parTOF[1];
671         else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << "      " << parTOF[1];
672         else ftxt << "      " << parTOF[1];
673         if (parTOF[0]<10) ftxt << "      " << parTOF[0] << endl;
674         else if (parTOF[0]>=10 && parTOF[0]<100)   ftxt << "    " << parTOF[0] << endl;
675         else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << "    " << parTOF[0] << endl;
676         else ftxt << "   " << parTOF[3] << endl;
677       }
678
679     } // closed loop on TOF raw data per current DDL file
680
681     clonesRawData->Clear();
682
683   } // closed loop on DDL index
684
685   if (fVerbose==2) ftxt.close();
686
687   AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
688
689   CalibrateRecPoint();
690   FillRecPoint();
691
692   fTreeR->Fill();
693   ResetRecpoint();
694
695   fTOFLoader = fRunLoader->GetLoader("TOFLoader");
696   fTOFLoader->WriteRecPoints("OVERWRITE");
697   
698   AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
699                stopwatch.RealTime(),stopwatch.CpuTime()));
700   if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
701
702 }
703 //______________________________________________________________________________
704
705 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
706 {
707   //
708   // Converts RAW data to MC digits for TOF
709   //
710   //             (temporary solution)
711   //
712
713   TStopwatch stopwatch;
714   stopwatch.Start();
715
716   //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
717   const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
718
719   fRunLoader->GetEvent(iEvent);
720
721   fTreeD = fTOFLoader->TreeD();
722   if (fTreeD)
723     {
724     AliInfo("TreeD re-creation");
725     fTreeD = 0x0;
726     fTOFLoader->MakeTree("D");
727     fTreeD = fTOFLoader->TreeD();
728     }
729
730   TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
731   Int_t bufsize = 32000;
732   fTreeD->Branch("TOF", &tofDigits, bufsize);
733
734   fRunLoader->GetEvent(iEvent);
735
736   AliDebug(2,Form(" Event number %2i ", iEvent));
737
738   TClonesArray * clonesRawData;
739
740   Int_t dummy = -1;
741
742   Int_t detectorIndex[5];
743   Int_t digit[4];
744
745   AliTOFRawStream tofInput(rawReader);
746
747   Int_t indexDDL = 0;
748   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
749
750     rawReader->Reset();
751     if (fDecoderVersion) {
752       AliInfo("Using New Decoder \n"); 
753       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
754     }
755     else tofInput.LoadRawData(indexDDL);
756
757     clonesRawData = (TClonesArray*)tofInput.GetRawData();
758
759     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
760
761       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
762
763       //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
764       if (tofRawDatum->GetTOF()==-1) continue;
765
766       tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
767                                     tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
768       dummy = detectorIndex[3];
769       detectorIndex[3] = detectorIndex[4];
770       detectorIndex[4] = dummy;
771
772       digit[0] = tofInput.GetTofBin();
773       digit[1] = tofInput.GetToTbin();
774       digit[2] = tofInput.GetToTbin();
775       digit[3] = -1;
776
777       Int_t tracknum[3]={-1,-1,-1};
778
779       TClonesArray &aDigits = *tofDigits;
780       Int_t last=tofDigits->GetEntriesFast();
781       new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
782
783     } // while loop
784
785     clonesRawData->Clear();
786
787   } // DDL Loop
788
789   fTreeD->Fill();
790
791   fTOFLoader = fRunLoader->GetLoader("TOFLoader");
792   fTOFLoader->WriteDigits("OVERWRITE");
793   
794   AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
795                    stopwatch.RealTime(),stopwatch.CpuTime()));
796
797 }
798
799 //______________________________________________________________________________
800
801 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
802 {
803   //
804   // Converts RAW data to MC digits for TOF for the current event
805   //
806   //
807
808   TStopwatch stopwatch;
809   stopwatch.Start();
810
811   const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
812
813   if (!digitsTree)
814     {
815     AliError("No input digits Tree");
816     return;
817     }
818
819   TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
820   Int_t bufsize = 32000;
821   digitsTree->Branch("TOF", &tofDigits, bufsize);
822
823   ///  fRunLoader->GetEvent(iEvent);
824
825   ///  AliDebug(2,Form(" Event number %2i ", iEvent));
826
827   TClonesArray * clonesRawData;
828
829   Int_t dummy = -1;
830
831   Int_t detectorIndex[5];
832   Int_t digit[4];
833
834   AliTOFRawStream tofInput(rawReader);
835
836   Int_t indexDDL = 0;
837   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
838
839     rawReader->Reset();
840     if (fDecoderVersion) {
841       AliInfo("Using New Decoder \n"); 
842       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
843     }
844     else tofInput.LoadRawData(indexDDL);
845
846     clonesRawData = (TClonesArray*)tofInput.GetRawData();
847
848     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
849
850       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
851
852       //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
853       if (tofRawDatum->GetTOF()==-1) continue;
854
855       tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
856                                     tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
857       dummy = detectorIndex[3];
858       detectorIndex[3] = detectorIndex[4];
859       detectorIndex[4] = dummy;
860
861       digit[0] = tofInput.GetTofBin();
862       digit[1] = tofInput.GetToTbin();
863       digit[2] = tofInput.GetToTbin();
864       digit[3] = -1;
865
866       Int_t tracknum[3]={-1,-1,-1};
867
868       TClonesArray &aDigits = *tofDigits;
869       Int_t last=tofDigits->GetEntriesFast();
870       new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
871
872     } // while loop
873
874     clonesRawData->Clear();
875
876   } // DDL Loop
877
878   digitsTree->Fill();
879
880   AliDebug(1, Form("Got %d digits: ", tofDigits->GetEntries()));
881   AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
882                    stopwatch.RealTime(),stopwatch.CpuTime()));
883
884 }
885 //______________________________________________________________________________
886
887 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
888   //---------------------------------------------------------------------------//
889   // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
890   //---------------------------------------------------------------------------//
891   if (fNumberOfTofClusters==kTofMaxCluster) {
892     AliError("Too many clusters !");
893     return 1;
894   }
895
896   if (fNumberOfTofClusters==0) {
897     fTofClusters[fNumberOfTofClusters++] = tofCluster;
898     return 0;
899   }
900
901   Int_t ii = FindClusterIndex(tofCluster->GetZ());
902   memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
903   fTofClusters[ii] = tofCluster;
904   fNumberOfTofClusters++;
905   
906   return 0;
907
908 }
909 //_________________________________________________________________________
910
911 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
912   //--------------------------------------------------------------------
913   // This function returns the index of the nearest cluster in z
914   //--------------------------------------------------------------------
915   if (fNumberOfTofClusters==0) return 0;
916   if (z <= fTofClusters[0]->GetZ()) return 0;
917   if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
918   Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
919   for (; b<e; m=(b+e)/2) {
920     if (z > fTofClusters[m]->GetZ()) b=m+1;
921     else e=m;
922   }
923
924   return m;
925
926 }
927 //_________________________________________________________________________
928
929 void AliTOFClusterFinder::FillRecPoint()
930 {
931   //
932   // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
933   // in Z) in the global TClonesArray of AliTOFcluster,
934   // i.e. fRecPoints.
935   //
936
937   Int_t ii, jj;
938
939   Int_t detectorIndex[5];
940   Int_t parTOF[5];
941   Int_t trackLabels[3];
942   Int_t digitIndex = -1;
943   Bool_t status=kTRUE;
944
945   TClonesArray &lRecPoints = *fRecPoints;
946   
947   for (ii=0; ii<fNumberOfTofClusters; ii++) {
948
949     digitIndex = fTofClusters[ii]->GetIndex();
950     for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
951     for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
952     parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
953     parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
954     parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
955     parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
956     parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
957     status=fTofClusters[ii]->GetStatus();
958     Double_t posClus[3];
959     Double_t covClus[6];
960     UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
961     GetClusterPars(detectorIndex,posClus,covClus);
962     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);
963
964     AliDebug(2, Form(" %4i  %4i  %f %f %f  %f %f %f %f %f %f  %3i %3i %3i  %2i %1i %2i %1i %2i  %4i %3i %3i %4i %4i  %1i  %4i", 
965                      ii, volIdClus, posClus[0], posClus[1], posClus[2],
966                      fTofClusters[ii]->GetSigmaX2(),
967                      fTofClusters[ii]->GetSigmaXY(),
968                      fTofClusters[ii]->GetSigmaXZ(),
969                      fTofClusters[ii]->GetSigmaY2(),
970                      fTofClusters[ii]->GetSigmaYZ(),
971                      fTofClusters[ii]->GetSigmaZ2(),
972                      trackLabels[0], trackLabels[1], trackLabels[2],
973                      detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
974                      parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
975                      status, digitIndex));
976
977   } // loop on clusters
978
979 }
980
981 //_________________________________________________________________________
982 void AliTOFClusterFinder::CalibrateRecPoint()
983 {
984   //
985   // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
986   // in Z) in the global TClonesArray of AliTOFcluster,
987   // i.e. fRecPoints.
988   //
989
990   Int_t ii, jj;
991
992   Int_t detectorIndex[5];
993   Int_t digitIndex = -1;
994   Double_t tToT;
995   Double_t timeCorr;
996   Int_t   tdcCorr;
997   AliInfo(" Calibrating TOF Clusters: ")
998   
999   AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();  
1000   AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();  
1001   TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
1002   TString validity = (TString)fTOFcalib->GetOfflineValidity();
1003   AliInfo(Form(" validity = %s",validity.Data()));
1004   Int_t calibration = -1;
1005   if (validity.CompareTo("valid")==0) {
1006     AliInfo(" Using offline calibration parameters");
1007     calibration = 1;
1008   }
1009   else {
1010     AliInfo(" Using online calibration parameters");
1011     calibration = 0 ;
1012   }
1013   for (ii=0; ii<fNumberOfTofClusters; ii++) {
1014     digitIndex = fTofClusters[ii]->GetIndex();
1015     for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1016
1017     Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1018      
1019     UChar_t statusPulser=calStatus->GetPulserStatus(index);
1020     UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1021     UChar_t statusHW=calStatus->GetHWStatus(index);
1022     UChar_t status=calStatus->GetStatus(index);
1023
1024     //check the status, also unknown is fine!!!!!!!
1025
1026     AliDebug(2, Form(" Status for channel %i = %i",index, (Int_t)status));
1027     if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
1028       AliDebug(2, Form(" Bad Status for channel %i",index));
1029       fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1030     }
1031     else {
1032       AliDebug(2, Form(" Good Status for channel %i",index));
1033     }
1034     // Get Rough channel online equalization 
1035     Double_t roughDelay=(Double_t)calDelay->GetDelay(index);  // in ns
1036     AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
1037     // Get Refined channel offline calibration parameters
1038     if (calibration ==1){
1039       AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1040       Double_t par[6];
1041       for (Int_t j = 0; j<6; j++){
1042         par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1043      } 
1044       AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
1045       AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %i , %i", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
1046       tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());    
1047       tToT*=1.E-3; //ToT in ns
1048       AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1049       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)
1050     }
1051     else {
1052       timeCorr = roughDelay; // correction in ns
1053     }
1054     AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
1055     AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
1056     timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1057     timeCorr*=1.E3;
1058     AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
1059     tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1060     fTofClusters[ii]->SetTDC(tdcCorr);
1061   } // loop on clusters
1062
1063 }
1064 //______________________________________________________________________________
1065
1066 void AliTOFClusterFinder::ResetRecpoint()
1067 {
1068   //
1069   // Clear the list of reconstructed points
1070   //
1071
1072   fNumberOfTofClusters = 0;
1073   if (fRecPoints) fRecPoints->Clear();
1074
1075 }
1076 //______________________________________________________________________________
1077
1078 void AliTOFClusterFinder::Load()
1079 {
1080   //
1081   // Load TOF.Digits.root and TOF.RecPoints.root files
1082   //
1083
1084   fTOFLoader->LoadDigits("READ");
1085   fTOFLoader->LoadRecPoints("recreate");
1086
1087 }
1088 //______________________________________________________________________________
1089
1090 void AliTOFClusterFinder::LoadClusters()
1091 {
1092   //
1093   // Load TOF.RecPoints.root file
1094   //
1095
1096   fTOFLoader->LoadRecPoints("recreate");
1097
1098 }
1099 //______________________________________________________________________________
1100
1101 void AliTOFClusterFinder::UnLoad()
1102 {
1103   //
1104   // Unload TOF.Digits.root and TOF.RecPoints.root files
1105   //
1106
1107   fTOFLoader->UnloadDigits();
1108   fTOFLoader->UnloadRecPoints();
1109
1110 }
1111 //______________________________________________________________________________
1112
1113 void AliTOFClusterFinder::UnLoadClusters()
1114 {
1115   //
1116   // Unload TOF.RecPoints.root file
1117   //
1118
1119   fTOFLoader->UnloadRecPoints();
1120
1121 }
1122 //-------------------------------------------------------------------------
1123 UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
1124
1125   //First of all get the volume ID to retrieve the l2t transformation...
1126   //
1127   // Detector numbering scheme
1128   Int_t nSector = 18;
1129   Int_t nPlate  = 5;
1130   Int_t nStripA = 15;
1131   Int_t nStripB = 19;
1132   Int_t nStripC = 19;
1133
1134   Int_t isector =ind[0];
1135   if (isector >= nSector)
1136     AliError(Form("Wrong sector number in TOF (%d) !",isector));
1137   Int_t iplate = ind[1];
1138   if (iplate >= nPlate)
1139     AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1140   Int_t istrip = ind[2];
1141
1142   Int_t stripOffset = 0;
1143   switch (iplate) {
1144   case 0:
1145     stripOffset = 0;
1146     break;
1147   case 1:
1148     stripOffset = nStripC;
1149     break;
1150   case 2:
1151     stripOffset = nStripC+nStripB;
1152     break;
1153   case 3:
1154     stripOffset = nStripC+nStripB+nStripA;
1155     break;
1156   case 4:
1157     stripOffset = nStripC+nStripB+nStripA+nStripB;
1158     break;
1159   default:
1160     AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1161     break;
1162   };
1163
1164   Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1165                stripOffset +
1166                istrip;
1167
1168   UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1169   return volIndex;
1170 }
1171 //
1172 //-------------------------------------------------------------------------
1173 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1174
1175   //First of all get the volume ID to retrieve the l2t transformation...
1176   //
1177   UShort_t volIndex = GetClusterVolIndex(ind);
1178   //
1179   //
1180   //we now go in the system of the strip: determine the local coordinates
1181   //
1182   //
1183   // 47---------------------------------------------------0  ^ z
1184   // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1185   // -----------------------------------------------------   | y going outwards
1186   // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 |  par[0]=0;
1187
1188   // -----------------------------------------------------   |
1189   // x <-----------------------------------------------------
1190
1191   Float_t localX=(ind[4]-23.5)*AliTOFGeometry::XPad();
1192   Float_t localY=0;
1193   Float_t localZ=(ind[3]- 0.5)*AliTOFGeometry::ZPad();
1194
1195   //move to the tracking ref system
1196
1197   Double_t lpos[3];
1198   lpos[0]=localX;
1199   lpos[1]=localY;
1200   lpos[2]=localZ; 
1201
1202   const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1203   // Get The position in the track ref system
1204   Double_t tpos[3];
1205   l2t->MasterToLocal(lpos,tpos);
1206   pos[0]=tpos[0];
1207   pos[1]=tpos[1];
1208   pos[2]=tpos[2];
1209
1210   //Get The cluster covariance in the track ref system
1211   Double_t lcov[9];
1212
1213   //cluster covariance in the local system:
1214   // sx2   0   0
1215   // 0     0   0
1216   // 0     0   sz2
1217
1218   lcov[0]=AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1219   lcov[1]=0;
1220   lcov[2]=0;
1221   lcov[3]=0;
1222   lcov[4]=0;
1223   lcov[5]=0;
1224   lcov[6]=0;
1225   lcov[7]=0;
1226   lcov[8]=AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
1227
1228   //cluster covariance in the tracking system:
1229   TGeoHMatrix m;
1230   m.SetRotation(lcov);
1231   m.Multiply(l2t);
1232   m.MultiplyLeft(&l2t->Inverse());
1233   Double_t *tcov = m.GetRotationMatrix();
1234   cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1235   cov[3] = tcov[4]; cov[4] = tcov[5];
1236   cov[5] = tcov[8];
1237
1238   return;
1239
1240 }