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),
155 //______________________________________________________________________________
157 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
158 fRunLoader(runLoader),
159 fTOFLoader(runLoader->GetLoader("TOFLoader")),
162 fDigits(new TClonesArray("AliTOFdigit", 4000)),
163 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
164 fNumberOfTofClusters(0),
175 //------------------------------------------------------------------------
176 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
182 fDigits(source.fDigits),
183 fRecPoints(source.fRecPoints),
184 fNumberOfTofClusters(0),
186 fDecoderVersion(source.fDecoderVersion),
187 fTOFcalib(source.fTOFcalib)
192 //------------------------------------------------------------------------
193 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
200 TObject::operator=(source);
201 fDigits=source.fDigits;
202 fRecPoints=source.fRecPoints;
203 fVerbose=source.fVerbose;
204 fDecoderVersion=source.fDecoderVersion;
205 fTOFcalib=source.fTOFcalib;
209 //______________________________________________________________________________
211 AliTOFClusterFinder::~AliTOFClusterFinder()
226 fRecPoints->Delete();
232 //______________________________________________________________________________
234 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
237 // Converts digits to recpoints for TOF
240 TStopwatch stopwatch;
245 fRunLoader->GetEvent(iEvent);
247 fTreeD = fTOFLoader->TreeD();
250 AliFatal("AliTOFClusterFinder: Can not get TreeD");
253 TBranch *branch = fTreeD->GetBranch("TOF");
255 AliError("can't get the branch with the TOF digits !");
259 TClonesArray staticdigits("AliTOFdigit",10000);
260 staticdigits.Clear();
261 TClonesArray *digits =&staticdigits;
262 branch->SetAddress(&digits);
266 fTreeR = fTOFLoader->TreeR();
269 fTOFLoader->MakeTree("R");
270 fTreeR = fTOFLoader->TreeR();
273 Int_t bufsize = 32000;
274 fTreeR->Branch("TOF", &fRecPoints, bufsize);
277 Int_t nDigits = digits->GetEntriesFast();
278 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
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();
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
300 // AliDebug(2,Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
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
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);
316 AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
324 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
325 fTOFLoader->WriteRecPoints("OVERWRITE");
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));
333 //______________________________________________________________________________
335 void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
338 // Converts digits to recpoints for TOF
341 TStopwatch stopwatch;
346 /// fRunLoader->GetEvent(iEvent);
348 if (digitsTree == 0x0)
350 AliFatal("AliTOFClusterFinder: Can not get TreeD");
353 TBranch *branch = digitsTree->GetBranch("TOF");
355 AliError("can't get the branch with the TOF digits !");
359 TClonesArray staticdigits("AliTOFdigit",10000);
360 staticdigits.Clear();
361 TClonesArray *digits = & staticdigits;
362 branch->SetAddress(&digits);
367 Int_t bufsize = 32000;
368 fTreeR->Branch("TOF", &fRecPoints, bufsize);
370 digitsTree->GetEvent(0);
371 Int_t nDigits = digits->GetEntriesFast();
372 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
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();
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
394 // AliDebug(2,Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
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
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);
411 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
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));
424 //______________________________________________________________________________
426 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
430 // Converts RAW data to recpoints for TOF
433 TStopwatch stopwatch;
438 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
439 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
443 Int_t bufsize = 32000;
444 clustersTree->Branch("TOF", &fRecPoints, bufsize);
446 TClonesArray * clonesRawData;
450 Int_t detectorIndex[5];
454 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
456 AliTOFRawStream tofInput(rawReader);
459 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
462 if (fDecoderVersion) {
463 AliInfo("Using New Decoder \n");
464 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
466 else tofInput.LoadRawData(indexDDL);
468 clonesRawData = (TClonesArray*)tofInput.GetRawData();
470 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
472 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
474 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
475 if (tofRawDatum->GetTOF()==-1) continue;
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();
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;
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];
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
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
520 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
521 Int_t lab[3]={-1,-1,-1};
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);
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;
537 } // closed loop on TOF raw data per current DDL file
539 clonesRawData->Clear();
541 } // closed loop on DDL index
543 if (fVerbose==2) ftxt.close();
545 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
550 clustersTree->Fill();
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));
559 //______________________________________________________________________________
561 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
564 // Converts RAW data to recpoints for TOF
567 TStopwatch stopwatch;
572 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
573 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
575 fRunLoader->GetEvent(iEvent);
577 AliDebug(2,Form(" Event number %2i ", iEvent));
579 fTreeR = fTOFLoader->TreeR();
582 fTOFLoader->MakeTree("R");
583 fTreeR = fTOFLoader->TreeR();
586 Int_t bufsize = 32000;
587 fTreeR->Branch("TOF", &fRecPoints, bufsize);
589 TClonesArray * clonesRawData;
593 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
596 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
598 AliTOFRawStream tofInput(rawReader);
601 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
604 if (fDecoderVersion) {
605 AliInfo("Using New Decoder \n");
606 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
608 else tofInput.LoadRawData(indexDDL);
610 clonesRawData = (TClonesArray*)tofInput.GetRawData();
612 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
614 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
616 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
617 if (tofRawDatum->GetTOF()==-1) continue;
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();
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;
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];
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
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
662 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
663 Int_t lab[3]={-1,-1,-1};
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);
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;
679 } // closed loop on TOF raw data per current DDL file
681 clonesRawData->Clear();
683 } // closed loop on DDL index
685 if (fVerbose==2) ftxt.close();
687 AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
695 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
696 fTOFLoader->WriteRecPoints("OVERWRITE");
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));
703 //______________________________________________________________________________
705 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
708 // Converts RAW data to MC digits for TOF
710 // (temporary solution)
713 TStopwatch stopwatch;
716 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
717 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
719 fRunLoader->GetEvent(iEvent);
721 fTreeD = fTOFLoader->TreeD();
724 AliInfo("TreeD re-creation");
726 fTOFLoader->MakeTree("D");
727 fTreeD = fTOFLoader->TreeD();
730 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
731 Int_t bufsize = 32000;
732 fTreeD->Branch("TOF", &tofDigits, bufsize);
734 fRunLoader->GetEvent(iEvent);
736 AliDebug(2,Form(" Event number %2i ", iEvent));
738 TClonesArray * clonesRawData;
742 Int_t detectorIndex[5];
745 AliTOFRawStream tofInput(rawReader);
748 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
751 if (fDecoderVersion) {
752 AliInfo("Using New Decoder \n");
753 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
755 else tofInput.LoadRawData(indexDDL);
757 clonesRawData = (TClonesArray*)tofInput.GetRawData();
759 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
761 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
763 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
764 if (tofRawDatum->GetTOF()==-1) continue;
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;
772 digit[0] = tofInput.GetTofBin();
773 digit[1] = tofInput.GetToTbin();
774 digit[2] = tofInput.GetToTbin();
777 Int_t tracknum[3]={-1,-1,-1};
779 TClonesArray &aDigits = *tofDigits;
780 Int_t last=tofDigits->GetEntriesFast();
781 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
785 clonesRawData->Clear();
791 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
792 fTOFLoader->WriteDigits("OVERWRITE");
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()));
799 //______________________________________________________________________________
801 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
804 // Converts RAW data to MC digits for TOF for the current event
808 TStopwatch stopwatch;
811 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
815 AliError("No input digits Tree");
819 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
820 Int_t bufsize = 32000;
821 digitsTree->Branch("TOF", &tofDigits, bufsize);
823 /// fRunLoader->GetEvent(iEvent);
825 /// AliDebug(2,Form(" Event number %2i ", iEvent));
827 TClonesArray * clonesRawData;
831 Int_t detectorIndex[5];
834 AliTOFRawStream tofInput(rawReader);
837 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
840 if (fDecoderVersion) {
841 AliInfo("Using New Decoder \n");
842 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
844 else tofInput.LoadRawData(indexDDL);
846 clonesRawData = (TClonesArray*)tofInput.GetRawData();
848 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
850 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
852 //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
853 if (tofRawDatum->GetTOF()==-1) continue;
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;
861 digit[0] = tofInput.GetTofBin();
862 digit[1] = tofInput.GetToTbin();
863 digit[2] = tofInput.GetToTbin();
866 Int_t tracknum[3]={-1,-1,-1};
868 TClonesArray &aDigits = *tofDigits;
869 Int_t last=tofDigits->GetEntriesFast();
870 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
874 clonesRawData->Clear();
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()));
885 //______________________________________________________________________________
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 !");
896 if (fNumberOfTofClusters==0) {
897 fTofClusters[fNumberOfTofClusters++] = tofCluster;
901 Int_t ii = FindClusterIndex(tofCluster->GetZ());
902 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
903 fTofClusters[ii] = tofCluster;
904 fNumberOfTofClusters++;
909 //_________________________________________________________________________
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;
927 //_________________________________________________________________________
929 void AliTOFClusterFinder::FillRecPoint()
932 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
933 // in Z) in the global TClonesArray of AliTOFcluster,
939 Int_t detectorIndex[5];
941 Int_t trackLabels[3];
942 Int_t digitIndex = -1;
945 TClonesArray &lRecPoints = *fRecPoints;
947 for (ii=0; ii<fNumberOfTofClusters; ii++) {
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();
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);
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));
977 } // loop on clusters
981 //_________________________________________________________________________
982 void AliTOFClusterFinder::CalibrateRecPoint()
985 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
986 // in Z) in the global TClonesArray of AliTOFcluster,
992 Int_t detectorIndex[5];
993 Int_t digitIndex = -1;
997 AliInfo(" Calibrating TOF Clusters: ")
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");
1010 AliInfo(" Using online calibration parameters");
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);
1017 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
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);
1024 //check the status, also unknown is fine!!!!!!!
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).
1032 AliDebug(2, Form(" Good Status for channel %i",index));
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);
1041 for (Int_t j = 0; j<6; j++){
1042 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
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)
1052 timeCorr = roughDelay; // correction in ns
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
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
1064 //______________________________________________________________________________
1066 void AliTOFClusterFinder::ResetRecpoint()
1069 // Clear the list of reconstructed points
1072 fNumberOfTofClusters = 0;
1073 if (fRecPoints) fRecPoints->Clear();
1076 //______________________________________________________________________________
1078 void AliTOFClusterFinder::Load()
1081 // Load TOF.Digits.root and TOF.RecPoints.root files
1084 fTOFLoader->LoadDigits("READ");
1085 fTOFLoader->LoadRecPoints("recreate");
1088 //______________________________________________________________________________
1090 void AliTOFClusterFinder::LoadClusters()
1093 // Load TOF.RecPoints.root file
1096 fTOFLoader->LoadRecPoints("recreate");
1099 //______________________________________________________________________________
1101 void AliTOFClusterFinder::UnLoad()
1104 // Unload TOF.Digits.root and TOF.RecPoints.root files
1107 fTOFLoader->UnloadDigits();
1108 fTOFLoader->UnloadRecPoints();
1111 //______________________________________________________________________________
1113 void AliTOFClusterFinder::UnLoadClusters()
1116 // Unload TOF.RecPoints.root file
1119 fTOFLoader->UnloadRecPoints();
1122 //-------------------------------------------------------------------------
1123 UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
1125 //First of all get the volume ID to retrieve the l2t transformation...
1127 // Detector numbering scheme
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];
1142 Int_t stripOffset = 0;
1148 stripOffset = nStripC;
1151 stripOffset = nStripC+nStripB;
1154 stripOffset = nStripC+nStripB+nStripA;
1157 stripOffset = nStripC+nStripB+nStripA+nStripB;
1160 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1164 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1168 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1172 //-------------------------------------------------------------------------
1173 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1175 //First of all get the volume ID to retrieve the l2t transformation...
1177 UShort_t volIndex = GetClusterVolIndex(ind);
1180 //we now go in the system of the strip: determine the local coordinates
1183 // 47---------------------------------------------------0 ^ z
1184 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1185 // ----------------------------------------------------- | y going outwards
1186 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1188 // ----------------------------------------------------- |
1189 // x <-----------------------------------------------------
1191 Float_t localX=(ind[4]-23.5)*AliTOFGeometry::XPad();
1193 Float_t localZ=(ind[3]- 0.5)*AliTOFGeometry::ZPad();
1195 //move to the tracking ref system
1202 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1203 // Get The position in the track ref system
1205 l2t->MasterToLocal(lpos,tpos);
1210 //Get The cluster covariance in the track ref system
1213 //cluster covariance in the local system:
1218 lcov[0]=AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
1226 lcov[8]=AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
1228 //cluster covariance in the tracking system:
1230 m.SetRotation(lcov);
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];