1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 $Log: AliTOFClusterFinder.cxx,v $
18 Revision 1.31 2007/11/24 14:53:19 zampolli
19 Status flag implemented as UChar_t
21 Revision 1.30 2007/10/04 13:08:52 arcelli
22 updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
24 Revision 1.29 2007/10/03 10:42:33 arcelli
25 updates to handle new AliTOFcluster, inheriting form AliCluster3D
27 Revision 1.28 2007/05/31 16:06:05 arcelli
28 move instance of AliRawStream outside loop on DDL
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
35 Revision 1.26 2007/04/30 19:02:24 arcelli
36 hopefully the last refinements for correct type conversion in calibration
38 Revision 1.25 2007/04/30 15:22:17 arcelli
39 Change TOF digit Time, Tot etc to int type
41 Revision 1.24 2007/04/27 11:19:31 arcelli
42 updates for the new decoder
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)
48 Revision 1.22 2007/04/19 17:26:32 arcelli
49 Fix a bug (add some debug printout
51 Revision 1.21 2007/04/18 17:28:12 arcelli
52 Set the ToT bin width to the one actually used...
54 Revision 1.20 2007/03/09 09:57:23 arcelli
55 Remove a forgotten include of Riostrem
57 Revision 1.19 2007/03/08 15:41:20 arcelli
58 set uncorrected times when filling RecPoints
60 Revision 1.18 2007/03/06 16:31:20 arcelli
61 Add Uncorrected TOF Time signal
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
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
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
77 Revision 0.02 2005/07/27 A. De Caro
78 Implement public method
79 Digits2RecPoint(Int_t)
80 to convert digits in clusters
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
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
96 ////////////////////////////////////////////////////////////////
98 // Class for TOF cluster finder //
100 // Starting from Raw Data, create rec points, //
101 // fill TreeR for TOF, //
102 // write TOF.RecPoints.root file //
104 ////////////////////////////////////////////////////////////////
106 #include "Riostream.h"
108 #include "TClonesArray.h"
109 #include "TStopwatch.h"
111 //#include <TGeoManager.h>
112 #include <TGeoMatrix.h>
113 //#include <TGeoPhysicalNode.h>
116 #include "AliLoader.h"
118 #include "AliRawReader.h"
119 #include "AliRunLoader.h"
120 //#include "AliAlignObj.h"
121 #include <AliGeomManager.h>
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"
134 #include "AliTOFDeltaBCOffset.h"
135 #include "AliTOFCTPLatency.h"
136 #include "AliTOFT0Fill.h"
138 //extern TFile *gFile;
140 ClassImp(AliTOFClusterFinder)
142 AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
147 fDigits(new TClonesArray("AliTOFdigit", 4000)),
148 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
149 fNumberOfTofClusters(0),
153 fTOFRawStream(AliTOFRawStream())
161 //______________________________________________________________________________
163 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
164 fRunLoader(runLoader),
165 fTOFLoader(runLoader->GetLoader("TOFLoader")),
168 fDigits(new TClonesArray("AliTOFdigit", 4000)),
169 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
170 fNumberOfTofClusters(0),
174 fTOFRawStream(AliTOFRawStream())
182 //------------------------------------------------------------------------
183 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
189 fDigits(source.fDigits),
190 fRecPoints(source.fRecPoints),
191 fNumberOfTofClusters(0),
193 fDecoderVersion(source.fDecoderVersion),
194 fTOFcalib(source.fTOFcalib),
195 fTOFRawStream(source.fTOFRawStream)
200 //------------------------------------------------------------------------
201 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
208 TObject::operator=(source);
209 fDigits=source.fDigits;
210 fRecPoints=source.fRecPoints;
211 fVerbose=source.fVerbose;
212 fDecoderVersion=source.fDecoderVersion;
213 fTOFcalib=source.fTOFcalib;
214 fTOFRawStream=source.fTOFRawStream;
218 //______________________________________________________________________________
220 AliTOFClusterFinder::~AliTOFClusterFinder()
235 fRecPoints->Delete();
241 //______________________________________________________________________________
243 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
246 // Converts digits to recpoints for TOF
249 TStopwatch stopwatch;
254 fRunLoader->GetEvent(iEvent);
256 fTreeD = fTOFLoader->TreeD();
259 AliFatal("AliTOFClusterFinder: Can not get TreeD");
262 TBranch *branch = fTreeD->GetBranch("TOF");
264 AliError("can't get the branch with the TOF digits !");
268 TClonesArray staticdigits("AliTOFdigit",10000);
269 staticdigits.Clear();
270 TClonesArray *digits =&staticdigits;
271 branch->SetAddress(&digits);
275 fTreeR = fTOFLoader->TreeR();
278 fTOFLoader->MakeTree("R");
279 fTreeR = fTOFLoader->TreeR();
282 Int_t bufsize = 32000;
283 fTreeR->Branch("TOF", &fRecPoints, bufsize);
286 Int_t nDigits = digits->GetEntriesFast();
287 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
290 Int_t dig[5]; //cluster detector indeces
291 Int_t parTOF[7]; //The TOF signal parameters
292 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
293 for (ii=0; ii<nDigits; ii++) {
294 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
295 dig[0]=d->GetSector();
296 dig[1]=d->GetPlate();
297 dig[2]=d->GetStrip();
301 /* check valid index */
302 if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
304 // Do not reconstruct anything in the holes
305 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
306 if (dig[1]==2) { // plate with holes
312 AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
314 parTOF[0] = d->GetTdc(); //the TDC signal
315 parTOF[1] = d->GetToT(); //the ToT signal
316 parTOF[2] = d->GetAdc(); // the adc charge
317 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
318 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
319 parTOF[5] = 0; // deltaBC
320 parTOF[6] = 0; // L0-L1 latency
323 UShort_t volIdClus=GetClusterVolIndex(dig);
324 GetClusterPars(dig, posClus,covClus);
325 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);
326 InsertCluster(tofCluster);
330 AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
338 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
339 fTOFLoader->WriteRecPoints("OVERWRITE");
341 AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
342 stopwatch.RealTime(),stopwatch.CpuTime()));
343 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
347 //______________________________________________________________________________
349 void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
352 // Converts digits to recpoints for TOF
355 TStopwatch stopwatch;
360 /// fRunLoader->GetEvent(iEvent);
362 if (digitsTree == 0x0)
364 AliFatal("AliTOFClusterFinder: Can not get TreeD");
367 TBranch *branch = digitsTree->GetBranch("TOF");
369 AliError("can't get the branch with the TOF digits !");
373 TClonesArray staticdigits("AliTOFdigit",10000);
374 staticdigits.Clear();
375 TClonesArray *digits = & staticdigits;
376 branch->SetAddress(&digits);
381 Int_t bufsize = 32000;
382 fTreeR->Branch("TOF", &fRecPoints, bufsize);
384 digitsTree->GetEvent(0);
385 Int_t nDigits = digits->GetEntriesFast();
386 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
389 Int_t dig[5]; //cluster detector indeces
390 Int_t parTOF[7]; //The TOF signal parameters
391 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
392 for (ii=0; ii<nDigits; ii++) {
393 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
394 dig[0]=d->GetSector();
395 dig[1]=d->GetPlate();
396 dig[2]=d->GetStrip();
400 /* check valid index */
401 if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
403 // Do not reconstruct anything in the holes
404 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
405 if (dig[1]==2) { // plate with holes
411 // AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
413 parTOF[0] = d->GetTdc(); //the TDC signal
414 parTOF[1] = d->GetToT(); //the ToT signal
415 parTOF[2] = d->GetAdc(); // the adc charge
416 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
417 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
418 parTOF[5] = 0; // deltaBC
419 parTOF[6] = 0; // L0-L1 latency
423 UShort_t volIdClus=GetClusterVolIndex(dig);
424 GetClusterPars(dig,posClus,covClus);
425 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);
426 InsertCluster(tofCluster);
430 AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
438 AliDebug(1,Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
439 stopwatch.RealTime(),stopwatch.CpuTime()));
440 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
443 //______________________________________________________________________________
445 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
449 // Converts RAW data to recpoints for TOF
452 TStopwatch stopwatch;
457 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
461 Int_t bufsize = 32000;
462 clustersTree->Branch("TOF", &fRecPoints, bufsize);
464 TClonesArray * clonesRawData;
468 Int_t detectorIndex[5];
472 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
474 //AliTOFRawStream tofInput(rawReader);
475 fTOFRawStream.Clear();
476 fTOFRawStream.SetRawReader(rawReader);
479 AliInfo("Using New Decoder");
482 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
486 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
487 else fTOFRawStream.LoadRawData(indexDDL);
489 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
491 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
493 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
495 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
496 if (tofRawDatum->GetTOF()==-1) continue;
499 if (indexDDL<10) ftxt << " " << indexDDL;
500 else ftxt << " " << indexDDL;
501 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
502 else ftxt << " " << tofRawDatum->GetTRM();
503 ftxt << " " << tofRawDatum->GetTRMchain();
504 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
505 else ftxt << " " << tofRawDatum->GetTDC();
506 ftxt << " " << tofRawDatum->GetTDCchannel();
509 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
510 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
511 dummy = detectorIndex[3];
512 detectorIndex[3] = detectorIndex[4];
513 detectorIndex[4] = dummy;
516 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
517 else ftxt << " -> " << detectorIndex[0];
518 ftxt << " " << detectorIndex[1];
519 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
520 else ftxt << " " << detectorIndex[2];
521 ftxt << " " << detectorIndex[3];
522 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
523 else ftxt << " " << detectorIndex[4];
526 /* check valid index */
527 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
529 // Do not reconstruct anything in the holes
530 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
531 if (detectorIndex[1]==2) { // plate with holes
537 parTOF[0] = tofRawDatum->GetTOF(); //TDC
538 parTOF[1] = tofRawDatum->GetTOT(); // TOT
539 parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
540 parTOF[3] = -1;//raw data: no track of undecalib sim time
541 parTOF[4] = tofRawDatum->GetTOF(); // RAW time
542 parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
543 parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
546 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
547 Int_t lab[3]={-1,-1,-1};
549 GetClusterPars(detectorIndex,posClus,covClus);
550 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);
551 InsertCluster(tofCluster);
554 if (parTOF[1]<10)ftxt << " " << parTOF[1];
555 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
556 else ftxt << " " << parTOF[1];
557 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
558 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
559 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
560 else ftxt << " " << parTOF[3] << endl;
563 } // closed loop on TOF raw data per current DDL file
565 clonesRawData->Clear();
567 } // closed loop on DDL index
569 if (fVerbose==2) ftxt.close();
571 AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
576 clustersTree->Fill();
580 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
581 stopwatch.RealTime(),stopwatch.CpuTime()));
582 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
585 //______________________________________________________________________________
587 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
590 // Converts RAW data to recpoints for TOF
593 TStopwatch stopwatch;
598 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
600 fRunLoader->GetEvent(iEvent);
602 AliDebug(2,Form(" Event number %2d ", iEvent));
604 fTreeR = fTOFLoader->TreeR();
607 fTOFLoader->MakeTree("R");
608 fTreeR = fTOFLoader->TreeR();
611 Int_t bufsize = 32000;
612 fTreeR->Branch("TOF", &fRecPoints, bufsize);
614 TClonesArray * clonesRawData;
618 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
621 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
623 //AliTOFRawStream tofInput(rawReader);
624 fTOFRawStream.Clear();
625 fTOFRawStream.SetRawReader(rawReader);
628 AliInfo("Using New Decoder");
631 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
635 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
636 else fTOFRawStream.LoadRawData(indexDDL);
638 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
640 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
642 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
644 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
645 if (tofRawDatum->GetTOF()==-1) continue;
648 if (indexDDL<10) ftxt << " " << indexDDL;
649 else ftxt << " " << indexDDL;
650 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
651 else ftxt << " " << tofRawDatum->GetTRM();
652 ftxt << " " << tofRawDatum->GetTRMchain();
653 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
654 else ftxt << " " << tofRawDatum->GetTDC();
655 ftxt << " " << tofRawDatum->GetTDCchannel();
658 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
659 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
660 dummy = detectorIndex[3];
661 detectorIndex[3] = detectorIndex[4];
662 detectorIndex[4] = dummy;
665 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
666 else ftxt << " -> " << detectorIndex[0];
667 ftxt << " " << detectorIndex[1];
668 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
669 else ftxt << " " << detectorIndex[2];
670 ftxt << " " << detectorIndex[3];
671 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
672 else ftxt << " " << detectorIndex[4];
675 /* check valid index */
676 if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
678 // Do not reconstruct anything in the holes
679 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
680 if (detectorIndex[1]==2) { // plate with holes
686 parTOF[0] = tofRawDatum->GetTOF(); // TDC
687 parTOF[1] = tofRawDatum->GetTOT(); // TOT
688 parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
689 parTOF[3] = -1; //raw data: no track of the undecalib sim time
690 parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
691 parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
692 parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
695 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
696 Int_t lab[3]={-1,-1,-1};
698 GetClusterPars(detectorIndex,posClus,covClus);
699 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);
700 InsertCluster(tofCluster);
703 if (parTOF[1]<10)ftxt << " " << parTOF[1];
704 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
705 else ftxt << " " << parTOF[1];
706 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
707 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
708 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
709 else ftxt << " " << parTOF[3] << endl;
712 } // closed loop on TOF raw data per current DDL file
714 clonesRawData->Clear();
716 } // closed loop on DDL index
718 if (fVerbose==2) ftxt.close();
720 AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
728 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
729 fTOFLoader->WriteRecPoints("OVERWRITE");
731 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
732 stopwatch.RealTime(),stopwatch.CpuTime()));
733 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
736 //______________________________________________________________________________
738 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
741 // Converts RAW data to MC digits for TOF
743 // (temporary solution)
746 TStopwatch stopwatch;
749 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
751 fRunLoader->GetEvent(iEvent);
753 fTreeD = fTOFLoader->TreeD();
756 AliInfo("TreeD re-creation");
758 fTOFLoader->MakeTree("D");
759 fTreeD = fTOFLoader->TreeD();
762 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
763 Int_t bufsize = 32000;
764 fTreeD->Branch("TOF", &tofDigits, bufsize);
766 fRunLoader->GetEvent(iEvent);
768 AliDebug(2,Form(" Event number %2d ", iEvent));
770 TClonesArray * clonesRawData;
774 Int_t detectorIndex[5];
777 //AliTOFRawStream tofInput(rawReader);
778 fTOFRawStream.Clear();
779 fTOFRawStream.SetRawReader(rawReader);
782 AliInfo("Using New Decoder");
785 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
789 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
790 else fTOFRawStream.LoadRawData(indexDDL);
792 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
794 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
796 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
798 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
799 if (tofRawDatum->GetTOF()==-1) continue;
801 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
802 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
803 dummy = detectorIndex[3];
804 detectorIndex[3] = detectorIndex[4];
805 detectorIndex[4] = dummy;
807 digit[0] = fTOFRawStream.GetTofBin();
808 digit[1] = fTOFRawStream.GetToTbin();
809 digit[2] = fTOFRawStream.GetToTbin();
812 Int_t tracknum[3]={-1,-1,-1};
814 TClonesArray &aDigits = *tofDigits;
815 Int_t last=tofDigits->GetEntriesFast();
816 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
820 clonesRawData->Clear();
826 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
827 fTOFLoader->WriteDigits("OVERWRITE");
831 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
832 stopwatch.RealTime(),stopwatch.CpuTime()));
836 //______________________________________________________________________________
838 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
841 // Converts RAW data to MC digits for TOF for the current event
845 TStopwatch stopwatch;
848 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
852 AliError("No input digits Tree");
856 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
857 Int_t bufsize = 32000;
858 digitsTree->Branch("TOF", &tofDigits, bufsize);
860 TClonesArray * clonesRawData;
864 Int_t detectorIndex[5];
867 //AliTOFRawStream tofInput(rawReader);
868 fTOFRawStream.Clear();
869 fTOFRawStream.SetRawReader(rawReader);
872 AliInfo("Using New Decoder");
875 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
879 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
880 else fTOFRawStream.LoadRawData(indexDDL);
882 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
884 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
886 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
888 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
889 if (tofRawDatum->GetTOF()==-1) continue;
891 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
892 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
893 dummy = detectorIndex[3];
894 detectorIndex[3] = detectorIndex[4];
895 detectorIndex[4] = dummy;
897 digit[0] = fTOFRawStream.GetTofBin();
898 digit[1] = fTOFRawStream.GetToTbin();
899 digit[2] = fTOFRawStream.GetToTbin();
902 Int_t tracknum[3]={-1,-1,-1};
904 TClonesArray &aDigits = *tofDigits;
905 Int_t last=tofDigits->GetEntriesFast();
906 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
910 clonesRawData->Clear();
918 AliDebug(1, Form("Got %d digits: ", fDigits->GetEntries()));
919 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
920 stopwatch.RealTime(),stopwatch.CpuTime()));
923 //______________________________________________________________________________
925 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
926 //---------------------------------------------------------------------------//
927 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
928 //---------------------------------------------------------------------------//
929 if (fNumberOfTofClusters==kTofMaxCluster) {
930 AliError("Too many clusters !");
934 if (fNumberOfTofClusters==0) {
935 fTofClusters[fNumberOfTofClusters++] = tofCluster;
939 Int_t ii = FindClusterIndex(tofCluster->GetZ());
940 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
941 fTofClusters[ii] = tofCluster;
942 fNumberOfTofClusters++;
947 //_________________________________________________________________________
949 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
950 //--------------------------------------------------------------------
951 // This function returns the index of the nearest cluster in z
952 //--------------------------------------------------------------------
953 if (fNumberOfTofClusters==0) return 0;
954 if (z <= fTofClusters[0]->GetZ()) return 0;
955 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
956 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
957 for (; b<e; m=(b+e)/2) {
958 if (z > fTofClusters[m]->GetZ()) b=m+1;
965 //_________________________________________________________________________
967 void AliTOFClusterFinder::FillRecPoint()
970 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
971 // in Z) in the global TClonesArray of AliTOFcluster,
977 Int_t detectorIndex[5];
979 Int_t trackLabels[3];
980 Int_t digitIndex = -1;
983 TClonesArray &lRecPoints = *fRecPoints;
985 for (ii=0; ii<fNumberOfTofClusters; ii++) {
987 digitIndex = fTofClusters[ii]->GetIndex();
988 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
989 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
990 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
991 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
992 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
993 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
994 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
995 parTOF[5] = fTofClusters[ii]->GetDeltaBC();//deltaBC
996 parTOF[6] = fTofClusters[ii]->GetL0L1Latency();//L0-L1 latency
997 status=fTofClusters[ii]->GetStatus();
1000 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
1001 GetClusterPars(detectorIndex,posClus,covClus);
1002 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);
1004 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",
1005 ii, volIdClus, posClus[0], posClus[1], posClus[2],
1006 fTofClusters[ii]->GetSigmaX2(),
1007 fTofClusters[ii]->GetSigmaXY(),
1008 fTofClusters[ii]->GetSigmaXZ(),
1009 fTofClusters[ii]->GetSigmaY2(),
1010 fTofClusters[ii]->GetSigmaYZ(),
1011 fTofClusters[ii]->GetSigmaZ2(),
1012 trackLabels[0], trackLabels[1], trackLabels[2],
1013 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
1014 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
1015 status, digitIndex));
1017 } // loop on clusters
1021 //_________________________________________________________________________
1022 void AliTOFClusterFinder::CalibrateRecPoint()
1025 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
1026 // in Z) in the global TClonesArray of AliTOFcluster,
1032 Int_t detectorIndex[5];
1033 Int_t digitIndex = -1;
1037 Float_t tdcLatencyWindow;
1038 AliDebug(1," Calibrating TOF Clusters");
1040 AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();
1041 AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();
1042 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
1044 AliTOFDeltaBCOffset *deltaBCOffsetObj = fTOFcalib->GetDeltaBCOffset();
1045 Int_t deltaBCOffset = deltaBCOffsetObj->GetDeltaBCOffset();
1046 AliTOFCTPLatency *ctpLatencyObj = fTOFcalib->GetCTPLatency();
1047 Float_t ctpLatency = ctpLatencyObj->GetCTPLatency();
1048 AliTOFT0Fill *t0FillObj = fTOFcalib->GetT0Fill();
1049 Float_t t0Fill = t0FillObj->GetT0Fill();
1051 TString validity = (TString)fTOFcalib->GetOfflineValidity();
1052 Int_t calibration = -1;
1053 if (validity.CompareTo("valid")==0) {
1054 AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
1057 AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
1061 for (ii=0; ii<fNumberOfTofClusters; ii++) {
1062 digitIndex = fTofClusters[ii]->GetIndex();
1063 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1065 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1067 UChar_t statusPulser=calStatus->GetPulserStatus(index);
1068 UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1069 UChar_t statusHW=calStatus->GetHWStatus(index);
1070 UChar_t status=calStatus->GetStatus(index);
1071 tdcLatencyWindow = calStatus->GetLatencyWindow(index) * 1.e3; /* ns -> ps */
1073 //check the status, also unknown is fine!!!!!!!
1075 AliDebug(2, Form(" Status for channel %d = %d",index, (Int_t)status));
1076 if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
1077 AliDebug(2, Form(" Bad Status for channel %d",index));
1078 fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1081 AliDebug(2, Form(" Good Status for channel %d",index));
1083 // Get Rough channel online equalization
1084 Double_t roughDelay=(Double_t)calDelay->GetDelay(index); // in ns
1085 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
1086 // Get Refined channel offline calibration parameters
1087 if (calibration ==1){
1088 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1090 for (Int_t j = 0; j<6; j++){
1091 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1093 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
1094 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
1095 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
1096 tToT*=1.E-3; //ToT in ns
1098 /* check TOT limits and set new TOT in case */
1099 if (tToT < AliTOFGeometry::SlewTOTMin()) tToT = AliTOFGeometry::SlewTOTMin();
1100 if (tToT > AliTOFGeometry::SlewTOTMax()) tToT = AliTOFGeometry::SlewTOTMax();
1102 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1103 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)
1106 timeCorr = roughDelay; // correction in ns
1108 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
1109 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
1110 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1112 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
1114 /* here timeCorr should be already corrected for calibration.
1115 * we now go into further corrections keeping in mind that timeCorr
1118 * the following corrections are performed in this way:
1120 * time = timeRaw - deltaBC + L0L1Latency + CTPLatency - TDCLatencyWindow - T0Fill
1124 AliDebug(2, Form("applying further corrections (DeltaBC): DeltaBC=%d (BC bins), DeltaBCoffset=%d (BC bins)", fTofClusters[ii]->GetDeltaBC(), deltaBCOffset));
1125 AliDebug(2, Form("applying further corrections (L0L1Latency): L0L1Latency=%d (BC bins)", fTofClusters[ii]->GetL0L1Latency()));
1126 AliDebug(2, Form("applying further corrections (CTPLatency): CTPLatency=%f (ps)", ctpLatency));
1127 AliDebug(2, Form("applying further corrections (TDCLatencyWindow): TDCLatencyWindow=%f (ps)", tdcLatencyWindow));
1128 AliDebug(2, Form("applying further corrections (T0Fill): T0Fill=%f (ps)", t0Fill));
1130 /* deltaBC correction */
1131 timeCorr -= (fTofClusters[ii]->GetDeltaBC() - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
1132 /* L0L1-latency correction */
1133 timeCorr += fTofClusters[ii]->GetL0L1Latency() * AliTOFGeometry::BunchCrossingBinWidth();
1134 /* CTP-latency correction (from OCDB) */
1135 timeCorr += ctpLatency;
1136 /* TDC latency-window correction (from OCDB) */
1137 timeCorr -= tdcLatencyWindow;
1138 /* T0Fill correction (from OCDB) */
1142 * end of furhter corrections
1145 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1146 fTofClusters[ii]->SetTDC(tdcCorr);
1147 } // loop on clusters
1150 //______________________________________________________________________________
1152 void AliTOFClusterFinder::ResetRecpoint()
1155 // Clear the list of reconstructed points
1158 fNumberOfTofClusters = 0;
1159 if (fRecPoints) fRecPoints->Clear();
1162 //______________________________________________________________________________
1164 void AliTOFClusterFinder::Load()
1167 // Load TOF.Digits.root and TOF.RecPoints.root files
1170 fTOFLoader->LoadDigits("READ");
1171 fTOFLoader->LoadRecPoints("recreate");
1174 //______________________________________________________________________________
1176 void AliTOFClusterFinder::LoadClusters()
1179 // Load TOF.RecPoints.root file
1182 fTOFLoader->LoadRecPoints("recreate");
1185 //______________________________________________________________________________
1187 void AliTOFClusterFinder::UnLoad()
1190 // Unload TOF.Digits.root and TOF.RecPoints.root files
1193 fTOFLoader->UnloadDigits();
1194 fTOFLoader->UnloadRecPoints();
1197 //______________________________________________________________________________
1199 void AliTOFClusterFinder::UnLoadClusters()
1202 // Unload TOF.RecPoints.root file
1205 fTOFLoader->UnloadRecPoints();
1208 //-------------------------------------------------------------------------
1209 UShort_t AliTOFClusterFinder::GetClusterVolIndex(const Int_t * const ind) const {
1211 //First of all get the volume ID to retrieve the l2t transformation...
1213 // Detector numbering scheme
1220 Int_t isector =ind[0];
1221 if (isector >= nSector)
1222 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1223 Int_t iplate = ind[1];
1224 if (iplate >= nPlate)
1225 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1226 Int_t istrip = ind[2];
1228 Int_t stripOffset = 0;
1234 stripOffset = nStripC;
1237 stripOffset = nStripC+nStripB;
1240 stripOffset = nStripC+nStripB+nStripA;
1243 stripOffset = nStripC+nStripB+nStripA+nStripB;
1246 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1250 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1254 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1258 //-------------------------------------------------------------------------
1259 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1261 //First of all get the volume ID to retrieve the l2t transformation...
1263 UShort_t volIndex = GetClusterVolIndex(ind);
1266 //we now go in the system of the strip: determine the local coordinates
1269 // 47---------------------------------------------------0 ^ z
1270 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1271 // ----------------------------------------------------- | y going outwards
1272 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1274 // ----------------------------------------------------- |
1275 // x <-----------------------------------------------------
1278 Float_t localX = (ind[4]-23.5)*AliTOFGeometry::XPad();
1280 Float_t localZ = (ind[3]- 0.5)*AliTOFGeometry::ZPad();
1282 Float_t localX = (ind[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.;
1284 Float_t localZ = (ind[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::ZPad()+AliTOFGeometry::ZPad()/2.;
1285 //move to the tracking ref system
1292 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1293 // Get The position in the track ref system
1295 l2t->MasterToLocal(lpos,tpos);
1300 //Get The cluster covariance in the track ref system
1303 //cluster covariance in the local system:
1308 lcov[0] = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1316 lcov[8] = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
1318 //cluster covariance in the tracking system:
1320 m.SetRotation(lcov);
1322 m.MultiplyLeft(&l2t->Inverse());
1323 Double_t *tcov = m.GetRotationMatrix();
1324 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1325 cov[3] = tcov[4]; cov[4] = tcov[5];