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 //extern TFile *gFile;
136 ClassImp(AliTOFClusterFinder)
138 AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
143 fDigits(new TClonesArray("AliTOFdigit", 4000)),
144 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
145 fNumberOfTofClusters(0),
149 fTOFRawStream(AliTOFRawStream())
157 //______________________________________________________________________________
159 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
160 fRunLoader(runLoader),
161 fTOFLoader(runLoader->GetLoader("TOFLoader")),
164 fDigits(new TClonesArray("AliTOFdigit", 4000)),
165 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
166 fNumberOfTofClusters(0),
170 fTOFRawStream(AliTOFRawStream())
178 //------------------------------------------------------------------------
179 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
185 fDigits(source.fDigits),
186 fRecPoints(source.fRecPoints),
187 fNumberOfTofClusters(0),
189 fDecoderVersion(source.fDecoderVersion),
190 fTOFcalib(source.fTOFcalib),
191 fTOFRawStream(source.fTOFRawStream)
196 //------------------------------------------------------------------------
197 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
204 TObject::operator=(source);
205 fDigits=source.fDigits;
206 fRecPoints=source.fRecPoints;
207 fVerbose=source.fVerbose;
208 fDecoderVersion=source.fDecoderVersion;
209 fTOFcalib=source.fTOFcalib;
210 fTOFRawStream=source.fTOFRawStream;
214 //______________________________________________________________________________
216 AliTOFClusterFinder::~AliTOFClusterFinder()
231 fRecPoints->Delete();
237 //______________________________________________________________________________
239 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
242 // Converts digits to recpoints for TOF
245 TStopwatch stopwatch;
250 fRunLoader->GetEvent(iEvent);
252 fTreeD = fTOFLoader->TreeD();
255 AliFatal("AliTOFClusterFinder: Can not get TreeD");
258 TBranch *branch = fTreeD->GetBranch("TOF");
260 AliError("can't get the branch with the TOF digits !");
264 TClonesArray staticdigits("AliTOFdigit",10000);
265 staticdigits.Clear();
266 TClonesArray *digits =&staticdigits;
267 branch->SetAddress(&digits);
271 fTreeR = fTOFLoader->TreeR();
274 fTOFLoader->MakeTree("R");
275 fTreeR = fTOFLoader->TreeR();
278 Int_t bufsize = 32000;
279 fTreeR->Branch("TOF", &fRecPoints, bufsize);
282 Int_t nDigits = digits->GetEntriesFast();
283 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
286 Int_t dig[5]; //cluster detector indeces
287 Int_t parTOF[5]; //The TOF signal parameters
288 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
289 for (ii=0; ii<nDigits; ii++) {
290 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
291 dig[0]=d->GetSector();
292 dig[1]=d->GetPlate();
293 dig[2]=d->GetStrip();
297 // Do not reconstruct anything in the holes
298 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
299 if (dig[1]==2) { // plate with holes
305 AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
307 parTOF[0] = d->GetTdc(); //the TDC signal
308 parTOF[1] = d->GetToT(); //the ToT signal
309 parTOF[2] = d->GetAdc(); // the adc charge
310 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
311 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
314 UShort_t volIdClus=GetClusterVolIndex(dig);
315 GetClusterPars(dig, posClus,covClus);
316 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);
317 InsertCluster(tofCluster);
321 AliInfo(Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
329 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
330 fTOFLoader->WriteRecPoints("OVERWRITE");
332 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
333 stopwatch.RealTime(),stopwatch.CpuTime()));
334 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
338 //______________________________________________________________________________
340 void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
343 // Converts digits to recpoints for TOF
346 TStopwatch stopwatch;
351 /// fRunLoader->GetEvent(iEvent);
353 if (digitsTree == 0x0)
355 AliFatal("AliTOFClusterFinder: Can not get TreeD");
358 TBranch *branch = digitsTree->GetBranch("TOF");
360 AliError("can't get the branch with the TOF digits !");
364 TClonesArray staticdigits("AliTOFdigit",10000);
365 staticdigits.Clear();
366 TClonesArray *digits = & staticdigits;
367 branch->SetAddress(&digits);
372 Int_t bufsize = 32000;
373 fTreeR->Branch("TOF", &fRecPoints, bufsize);
375 digitsTree->GetEvent(0);
376 Int_t nDigits = digits->GetEntriesFast();
377 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
380 Int_t dig[5]; //cluster detector indeces
381 Int_t parTOF[5]; //The TOF signal parameters
382 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
383 for (ii=0; ii<nDigits; ii++) {
384 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
385 dig[0]=d->GetSector();
386 dig[1]=d->GetPlate();
387 dig[2]=d->GetStrip();
391 // Do not reconstruct anything in the holes
392 if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
393 if (dig[1]==2) { // plate with holes
399 // AliDebug(2,Form(" %2d %1d %2d %1d %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
401 parTOF[0] = d->GetTdc(); //the TDC signal
402 parTOF[1] = d->GetToT(); //the ToT signal
403 parTOF[2] = d->GetAdc(); // the adc charge
404 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
405 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
409 UShort_t volIdClus=GetClusterVolIndex(dig);
410 GetClusterPars(dig,posClus,covClus);
411 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);
412 InsertCluster(tofCluster);
416 AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
424 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
425 stopwatch.RealTime(),stopwatch.CpuTime()));
426 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
429 //______________________________________________________________________________
431 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
435 // Converts RAW data to recpoints for TOF
438 TStopwatch stopwatch;
443 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
447 Int_t bufsize = 32000;
448 clustersTree->Branch("TOF", &fRecPoints, bufsize);
450 TClonesArray * clonesRawData;
454 Int_t detectorIndex[5];
458 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
460 //AliTOFRawStream tofInput(rawReader);
461 fTOFRawStream.Clear();
462 fTOFRawStream.SetRawReader(rawReader);
465 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
468 if (fDecoderVersion) {
469 AliInfo("Using New Decoder \n");
470 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
472 else fTOFRawStream.LoadRawData(indexDDL);
474 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
476 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
478 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
480 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
481 if (tofRawDatum->GetTOF()==-1) continue;
484 if (indexDDL<10) ftxt << " " << indexDDL;
485 else ftxt << " " << indexDDL;
486 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
487 else ftxt << " " << tofRawDatum->GetTRM();
488 ftxt << " " << tofRawDatum->GetTRMchain();
489 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
490 else ftxt << " " << tofRawDatum->GetTDC();
491 ftxt << " " << tofRawDatum->GetTDCchannel();
494 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
495 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
496 dummy = detectorIndex[3];
497 detectorIndex[3] = detectorIndex[4];
498 detectorIndex[4] = dummy;
501 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
502 else ftxt << " -> " << detectorIndex[0];
503 ftxt << " " << detectorIndex[1];
504 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
505 else ftxt << " " << detectorIndex[2];
506 ftxt << " " << detectorIndex[3];
507 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
508 else ftxt << " " << detectorIndex[4];
511 // Do not reconstruct anything in the holes
512 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
513 if (detectorIndex[1]==2) { // plate with holes
519 parTOF[0] = tofRawDatum->GetTOF(); //TDC
520 parTOF[1] = tofRawDatum->GetTOT(); // TOT
521 parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
522 parTOF[3] = -1;//raw data: no track of undecalib sim time
523 parTOF[4] = tofRawDatum->GetTOF(); // RAW time
526 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
527 Int_t lab[3]={-1,-1,-1};
529 GetClusterPars(detectorIndex,posClus,covClus);
530 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);
531 InsertCluster(tofCluster);
534 if (parTOF[1]<10)ftxt << " " << parTOF[1];
535 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
536 else ftxt << " " << parTOF[1];
537 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
538 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
539 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
540 else ftxt << " " << parTOF[3] << endl;
543 } // closed loop on TOF raw data per current DDL file
545 clonesRawData->Clear();
547 } // closed loop on DDL index
549 if (fVerbose==2) ftxt.close();
551 AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
556 clustersTree->Fill();
560 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
561 stopwatch.RealTime(),stopwatch.CpuTime()));
562 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
565 //______________________________________________________________________________
567 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
570 // Converts RAW data to recpoints for TOF
573 TStopwatch stopwatch;
578 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
580 fRunLoader->GetEvent(iEvent);
582 AliDebug(2,Form(" Event number %2d ", iEvent));
584 fTreeR = fTOFLoader->TreeR();
587 fTOFLoader->MakeTree("R");
588 fTreeR = fTOFLoader->TreeR();
591 Int_t bufsize = 32000;
592 fTreeR->Branch("TOF", &fRecPoints, bufsize);
594 TClonesArray * clonesRawData;
598 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
601 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
603 //AliTOFRawStream tofInput(rawReader);
604 fTOFRawStream.Clear();
605 fTOFRawStream.SetRawReader(rawReader);
608 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
611 if (fDecoderVersion) {
612 AliInfo("Using New Decoder \n");
613 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
615 else fTOFRawStream.LoadRawData(indexDDL);
617 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
619 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
621 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
623 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
624 if (tofRawDatum->GetTOF()==-1) continue;
627 if (indexDDL<10) ftxt << " " << indexDDL;
628 else ftxt << " " << indexDDL;
629 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
630 else ftxt << " " << tofRawDatum->GetTRM();
631 ftxt << " " << tofRawDatum->GetTRMchain();
632 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
633 else ftxt << " " << tofRawDatum->GetTDC();
634 ftxt << " " << tofRawDatum->GetTDCchannel();
637 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
638 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
639 dummy = detectorIndex[3];
640 detectorIndex[3] = detectorIndex[4];
641 detectorIndex[4] = dummy;
644 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
645 else ftxt << " -> " << detectorIndex[0];
646 ftxt << " " << detectorIndex[1];
647 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
648 else ftxt << " " << detectorIndex[2];
649 ftxt << " " << detectorIndex[3];
650 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
651 else ftxt << " " << detectorIndex[4];
654 // Do not reconstruct anything in the holes
655 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
656 if (detectorIndex[1]==2) { // plate with holes
662 parTOF[0] = tofRawDatum->GetTOF(); // TDC
663 parTOF[1] = tofRawDatum->GetTOT(); // TOT
664 parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
665 parTOF[3] = -1; //raw data: no track of the undecalib sim time
666 parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
669 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
670 Int_t lab[3]={-1,-1,-1};
672 GetClusterPars(detectorIndex,posClus,covClus);
673 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);
674 InsertCluster(tofCluster);
677 if (parTOF[1]<10)ftxt << " " << parTOF[1];
678 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
679 else ftxt << " " << parTOF[1];
680 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
681 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
682 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
683 else ftxt << " " << parTOF[3] << endl;
686 } // closed loop on TOF raw data per current DDL file
688 clonesRawData->Clear();
690 } // closed loop on DDL index
692 if (fVerbose==2) ftxt.close();
694 AliInfo(Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
702 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
703 fTOFLoader->WriteRecPoints("OVERWRITE");
705 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
706 stopwatch.RealTime(),stopwatch.CpuTime()));
707 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
710 //______________________________________________________________________________
712 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
715 // Converts RAW data to MC digits for TOF
717 // (temporary solution)
720 TStopwatch stopwatch;
723 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
725 fRunLoader->GetEvent(iEvent);
727 fTreeD = fTOFLoader->TreeD();
730 AliInfo("TreeD re-creation");
732 fTOFLoader->MakeTree("D");
733 fTreeD = fTOFLoader->TreeD();
736 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
737 Int_t bufsize = 32000;
738 fTreeD->Branch("TOF", &tofDigits, bufsize);
740 fRunLoader->GetEvent(iEvent);
742 AliDebug(2,Form(" Event number %2d ", iEvent));
744 TClonesArray * clonesRawData;
748 Int_t detectorIndex[5];
751 //AliTOFRawStream tofInput(rawReader);
752 fTOFRawStream.Clear();
753 fTOFRawStream.SetRawReader(rawReader);
756 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
759 if (fDecoderVersion) {
760 AliInfo("Using New Decoder \n");
761 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
763 else fTOFRawStream.LoadRawData(indexDDL);
765 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
767 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
769 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
771 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
772 if (tofRawDatum->GetTOF()==-1) continue;
774 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
775 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
776 dummy = detectorIndex[3];
777 detectorIndex[3] = detectorIndex[4];
778 detectorIndex[4] = dummy;
780 digit[0] = fTOFRawStream.GetTofBin();
781 digit[1] = fTOFRawStream.GetToTbin();
782 digit[2] = fTOFRawStream.GetToTbin();
785 Int_t tracknum[3]={-1,-1,-1};
787 TClonesArray &aDigits = *tofDigits;
788 Int_t last=tofDigits->GetEntriesFast();
789 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
793 clonesRawData->Clear();
799 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
800 fTOFLoader->WriteDigits("OVERWRITE");
804 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
805 stopwatch.RealTime(),stopwatch.CpuTime()));
809 //______________________________________________________________________________
811 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
814 // Converts RAW data to MC digits for TOF for the current event
818 TStopwatch stopwatch;
821 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
825 AliError("No input digits Tree");
829 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
830 Int_t bufsize = 32000;
831 digitsTree->Branch("TOF", &tofDigits, bufsize);
833 TClonesArray * clonesRawData;
837 Int_t detectorIndex[5];
840 //AliTOFRawStream tofInput(rawReader);
841 fTOFRawStream.Clear();
842 fTOFRawStream.SetRawReader(rawReader);
845 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
848 if (fDecoderVersion) {
849 AliInfo("Using New Decoder \n");
850 fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
852 else fTOFRawStream.LoadRawData(indexDDL);
854 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
856 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
858 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
860 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
861 if (tofRawDatum->GetTOF()==-1) continue;
863 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
864 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
865 dummy = detectorIndex[3];
866 detectorIndex[3] = detectorIndex[4];
867 detectorIndex[4] = dummy;
869 digit[0] = fTOFRawStream.GetTofBin();
870 digit[1] = fTOFRawStream.GetToTbin();
871 digit[2] = fTOFRawStream.GetToTbin();
874 Int_t tracknum[3]={-1,-1,-1};
876 TClonesArray &aDigits = *tofDigits;
877 Int_t last=tofDigits->GetEntriesFast();
878 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
882 clonesRawData->Clear();
890 AliDebug(1, Form("Got %d digits: ", fDigits->GetEntries()));
891 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
892 stopwatch.RealTime(),stopwatch.CpuTime()));
895 //______________________________________________________________________________
897 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
898 //---------------------------------------------------------------------------//
899 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
900 //---------------------------------------------------------------------------//
901 if (fNumberOfTofClusters==kTofMaxCluster) {
902 AliError("Too many clusters !");
906 if (fNumberOfTofClusters==0) {
907 fTofClusters[fNumberOfTofClusters++] = tofCluster;
911 Int_t ii = FindClusterIndex(tofCluster->GetZ());
912 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
913 fTofClusters[ii] = tofCluster;
914 fNumberOfTofClusters++;
919 //_________________________________________________________________________
921 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
922 //--------------------------------------------------------------------
923 // This function returns the index of the nearest cluster in z
924 //--------------------------------------------------------------------
925 if (fNumberOfTofClusters==0) return 0;
926 if (z <= fTofClusters[0]->GetZ()) return 0;
927 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
928 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
929 for (; b<e; m=(b+e)/2) {
930 if (z > fTofClusters[m]->GetZ()) b=m+1;
937 //_________________________________________________________________________
939 void AliTOFClusterFinder::FillRecPoint()
942 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
943 // in Z) in the global TClonesArray of AliTOFcluster,
949 Int_t detectorIndex[5];
951 Int_t trackLabels[3];
952 Int_t digitIndex = -1;
955 TClonesArray &lRecPoints = *fRecPoints;
957 for (ii=0; ii<fNumberOfTofClusters; ii++) {
959 digitIndex = fTofClusters[ii]->GetIndex();
960 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
961 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
962 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
963 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
964 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
965 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
966 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
967 status=fTofClusters[ii]->GetStatus();
970 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
971 GetClusterPars(detectorIndex,posClus,covClus);
972 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);
974 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",
975 ii, volIdClus, posClus[0], posClus[1], posClus[2],
976 fTofClusters[ii]->GetSigmaX2(),
977 fTofClusters[ii]->GetSigmaXY(),
978 fTofClusters[ii]->GetSigmaXZ(),
979 fTofClusters[ii]->GetSigmaY2(),
980 fTofClusters[ii]->GetSigmaYZ(),
981 fTofClusters[ii]->GetSigmaZ2(),
982 trackLabels[0], trackLabels[1], trackLabels[2],
983 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
984 parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
985 status, digitIndex));
987 } // loop on clusters
991 //_________________________________________________________________________
992 void AliTOFClusterFinder::CalibrateRecPoint()
995 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
996 // in Z) in the global TClonesArray of AliTOFcluster,
1002 Int_t detectorIndex[5];
1003 Int_t digitIndex = -1;
1007 AliInfo(" Calibrating TOF Clusters: ")
1009 AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();
1010 AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();
1011 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
1012 TString validity = (TString)fTOFcalib->GetOfflineValidity();
1013 AliInfo(Form(" validity = %s",validity.Data()));
1014 Int_t calibration = -1;
1015 if (validity.CompareTo("valid")==0) {
1016 AliInfo(" Using offline calibration parameters");
1020 AliInfo(" Using online calibration parameters");
1023 for (ii=0; ii<fNumberOfTofClusters; ii++) {
1024 digitIndex = fTofClusters[ii]->GetIndex();
1025 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1027 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1029 UChar_t statusPulser=calStatus->GetPulserStatus(index);
1030 UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1031 UChar_t statusHW=calStatus->GetHWStatus(index);
1032 UChar_t status=calStatus->GetStatus(index);
1034 //check the status, also unknown is fine!!!!!!!
1036 AliDebug(2, Form(" Status for channel %d = %d",index, (Int_t)status));
1037 if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
1038 AliDebug(2, Form(" Bad Status for channel %d",index));
1039 fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1042 AliDebug(2, Form(" Good Status for channel %d",index));
1044 // Get Rough channel online equalization
1045 Double_t roughDelay=(Double_t)calDelay->GetDelay(index); // in ns
1046 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
1047 // Get Refined channel offline calibration parameters
1048 if (calibration ==1){
1049 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1051 for (Int_t j = 0; j<6; j++){
1052 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1054 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
1055 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
1056 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
1057 tToT*=1.E-3; //ToT in ns
1058 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1059 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)
1062 timeCorr = roughDelay; // correction in ns
1064 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
1065 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
1066 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1068 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
1069 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1070 fTofClusters[ii]->SetTDC(tdcCorr);
1071 } // loop on clusters
1074 //______________________________________________________________________________
1076 void AliTOFClusterFinder::ResetRecpoint()
1079 // Clear the list of reconstructed points
1082 fNumberOfTofClusters = 0;
1083 if (fRecPoints) fRecPoints->Clear();
1086 //______________________________________________________________________________
1088 void AliTOFClusterFinder::Load()
1091 // Load TOF.Digits.root and TOF.RecPoints.root files
1094 fTOFLoader->LoadDigits("READ");
1095 fTOFLoader->LoadRecPoints("recreate");
1098 //______________________________________________________________________________
1100 void AliTOFClusterFinder::LoadClusters()
1103 // Load TOF.RecPoints.root file
1106 fTOFLoader->LoadRecPoints("recreate");
1109 //______________________________________________________________________________
1111 void AliTOFClusterFinder::UnLoad()
1114 // Unload TOF.Digits.root and TOF.RecPoints.root files
1117 fTOFLoader->UnloadDigits();
1118 fTOFLoader->UnloadRecPoints();
1121 //______________________________________________________________________________
1123 void AliTOFClusterFinder::UnLoadClusters()
1126 // Unload TOF.RecPoints.root file
1129 fTOFLoader->UnloadRecPoints();
1132 //-------------------------------------------------------------------------
1133 UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
1135 //First of all get the volume ID to retrieve the l2t transformation...
1137 // Detector numbering scheme
1144 Int_t isector =ind[0];
1145 if (isector >= nSector)
1146 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1147 Int_t iplate = ind[1];
1148 if (iplate >= nPlate)
1149 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1150 Int_t istrip = ind[2];
1152 Int_t stripOffset = 0;
1158 stripOffset = nStripC;
1161 stripOffset = nStripC+nStripB;
1164 stripOffset = nStripC+nStripB+nStripA;
1167 stripOffset = nStripC+nStripB+nStripA+nStripB;
1170 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1174 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1178 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1182 //-------------------------------------------------------------------------
1183 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1185 //First of all get the volume ID to retrieve the l2t transformation...
1187 UShort_t volIndex = GetClusterVolIndex(ind);
1190 //we now go in the system of the strip: determine the local coordinates
1193 // 47---------------------------------------------------0 ^ z
1194 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1195 // ----------------------------------------------------- | y going outwards
1196 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1198 // ----------------------------------------------------- |
1199 // x <-----------------------------------------------------
1201 Float_t localX=(ind[4]-23.5)*AliTOFGeometry::XPad();
1203 Float_t localZ=(ind[3]- 0.5)*AliTOFGeometry::ZPad();
1205 //move to the tracking ref system
1212 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1213 // Get The position in the track ref system
1215 l2t->MasterToLocal(lpos,tpos);
1220 //Get The cluster covariance in the track ref system
1223 //cluster covariance in the local system:
1228 lcov[0]=AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1236 lcov[8]=AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
1238 //cluster covariance in the tracking system:
1240 m.SetRotation(lcov);
1242 m.MultiplyLeft(&l2t->Inverse());
1243 Double_t *tcov = m.GetRotationMatrix();
1244 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1245 cov[3] = tcov[4]; cov[4] = tcov[5];