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(new TClonesArray("AliTOFdigit", 4000)),
183 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
184 fNumberOfTofClusters(0),
190 this->fDigits=source.fDigits;
191 this->fRecPoints=source.fRecPoints;
192 this->fDecoderVersion=source.fDecoderVersion;
193 this->fTOFcalib=source.fTOFcalib;
197 //------------------------------------------------------------------------
198 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
201 this->fDigits=source.fDigits;
202 this->fRecPoints=source.fRecPoints;
203 this->fVerbose=source.fVerbose;
204 this->fDecoderVersion=source.fDecoderVersion;
205 this->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;
765 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
766 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
767 dummy = detectorIndex[3];
768 detectorIndex[3] = detectorIndex[4];
769 detectorIndex[4] = dummy;
771 digit[0] = tofInput.GetTofBin();
772 digit[1] = tofInput.GetToTbin();
773 digit[2] = tofInput.GetToTbin();
776 Int_t tracknum[3]={-1,-1,-1};
778 TClonesArray &aDigits = *tofDigits;
779 Int_t last=tofDigits->GetEntriesFast();
780 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
784 clonesRawData->Clear();
790 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
791 fTOFLoader->WriteDigits("OVERWRITE");
793 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
794 stopwatch.RealTime(),stopwatch.CpuTime()));
798 //______________________________________________________________________________
800 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
803 // Converts RAW data to MC digits for TOF for the current event
807 TStopwatch stopwatch;
810 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
814 AliError("No input digits Tree");
818 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
819 Int_t bufsize = 32000;
820 digitsTree->Branch("TOF", &tofDigits, bufsize);
822 /// fRunLoader->GetEvent(iEvent);
824 /// AliDebug(2,Form(" Event number %2i ", iEvent));
826 TClonesArray * clonesRawData;
830 Int_t detectorIndex[5];
833 AliTOFRawStream tofInput(rawReader);
836 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
839 if (fDecoderVersion) {
840 AliInfo("Using New Decoder \n");
841 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
843 else tofInput.LoadRawData(indexDDL);
845 clonesRawData = (TClonesArray*)tofInput.GetRawData();
847 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
849 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
851 if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
853 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
854 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
855 dummy = detectorIndex[3];
856 detectorIndex[3] = detectorIndex[4];
857 detectorIndex[4] = dummy;
859 digit[0] = tofInput.GetTofBin();
860 digit[1] = tofInput.GetToTbin();
861 digit[2] = tofInput.GetToTbin();
864 Int_t tracknum[3]={-1,-1,-1};
866 TClonesArray &aDigits = *tofDigits;
867 Int_t last=tofDigits->GetEntriesFast();
868 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
872 clonesRawData->Clear();
878 AliDebug(1, Form("Got %d digits: ", tofDigits->GetEntries()));
879 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
880 stopwatch.RealTime(),stopwatch.CpuTime()));
883 //______________________________________________________________________________
885 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
886 //---------------------------------------------------------------------------//
887 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
888 //---------------------------------------------------------------------------//
889 if (fNumberOfTofClusters==kTofMaxCluster) {
890 AliError("Too many clusters !");
894 if (fNumberOfTofClusters==0) {
895 fTofClusters[fNumberOfTofClusters++] = tofCluster;
899 Int_t ii = FindClusterIndex(tofCluster->GetZ());
900 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
901 fTofClusters[ii] = tofCluster;
902 fNumberOfTofClusters++;
907 //_________________________________________________________________________
909 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
910 //--------------------------------------------------------------------
911 // This function returns the index of the nearest cluster in z
912 //--------------------------------------------------------------------
913 if (fNumberOfTofClusters==0) return 0;
914 if (z <= fTofClusters[0]->GetZ()) return 0;
915 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
916 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
917 for (; b<e; m=(b+e)/2) {
918 if (z > fTofClusters[m]->GetZ()) b=m+1;
925 //_________________________________________________________________________
927 void AliTOFClusterFinder::FillRecPoint()
930 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
931 // in Z) in the global TClonesArray of AliTOFcluster,
937 Int_t detectorIndex[5];
939 Int_t trackLabels[3];
940 Int_t digitIndex = -1;
943 TClonesArray &lRecPoints = *fRecPoints;
945 for (ii=0; ii<fNumberOfTofClusters; ii++) {
947 digitIndex = fTofClusters[ii]->GetIndex();
948 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
949 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
950 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
951 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
952 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
953 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
954 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
955 status=fTofClusters[ii]->GetStatus();
958 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
959 GetClusterPars(detectorIndex,posClus,covClus);
960 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);
962 } // loop on clusters
966 //_________________________________________________________________________
967 void AliTOFClusterFinder::CalibrateRecPoint()
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];
978 Int_t digitIndex = -1;
982 AliInfo(" Calibrating TOF Clusters: ")
984 AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();
985 AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();
986 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
987 TString validity = (TString)fTOFcalib->GetOfflineValidity();
988 AliInfo(Form(" validity = %s",validity.Data()));
989 Int_t calibration = -1;
990 if (validity.CompareTo("valid")==0) {
991 AliInfo(" Using offline calibration parameters");
995 AliInfo(" Using online calibration parameters");
998 for (ii=0; ii<fNumberOfTofClusters; ii++) {
999 digitIndex = fTofClusters[ii]->GetIndex();
1000 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
1002 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
1004 UChar_t statusPulser=calStatus->GetPulserStatus(index);
1005 UChar_t statusNoise=calStatus->GetNoiseStatus(index);
1006 UChar_t statusHW=calStatus->GetHWStatus(index);
1007 UChar_t status=calStatus->GetStatus(index);
1009 //check the status, also unknown is fine!!!!!!!
1011 AliDebug(2, Form(" Status for channel %i = %i",index, (Int_t)status));
1012 if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
1013 AliDebug(2, Form(" Bad Status for channel %i",index));
1014 fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
1017 AliDebug(2, Form(" Good Status for channel %i",index));
1019 // Get Rough channel online equalization
1020 Double_t roughDelay=(Double_t)calDelay->GetDelay(index); // in ns
1021 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
1022 // Get Refined channel offline calibration parameters
1023 if (calibration ==1){
1024 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
1026 for (Int_t j = 0; j<6; j++){
1027 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
1029 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
1030 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %i , %i", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
1031 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
1032 tToT*=1.E-3; //ToT in ns
1033 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
1034 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)
1037 timeCorr = roughDelay; // correction in ns
1039 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
1040 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
1041 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1043 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
1044 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1045 fTofClusters[ii]->SetTDC(tdcCorr);
1046 } // loop on clusters
1049 //______________________________________________________________________________
1051 void AliTOFClusterFinder::ResetRecpoint()
1054 // Clear the list of reconstructed points
1057 fNumberOfTofClusters = 0;
1058 if (fRecPoints) fRecPoints->Clear();
1061 //______________________________________________________________________________
1063 void AliTOFClusterFinder::Load()
1066 // Load TOF.Digits.root and TOF.RecPoints.root files
1069 fTOFLoader->LoadDigits("READ");
1070 fTOFLoader->LoadRecPoints("recreate");
1073 //______________________________________________________________________________
1075 void AliTOFClusterFinder::LoadClusters()
1078 // Load TOF.RecPoints.root file
1081 fTOFLoader->LoadRecPoints("recreate");
1084 //______________________________________________________________________________
1086 void AliTOFClusterFinder::UnLoad()
1089 // Unload TOF.Digits.root and TOF.RecPoints.root files
1092 fTOFLoader->UnloadDigits();
1093 fTOFLoader->UnloadRecPoints();
1096 //______________________________________________________________________________
1098 void AliTOFClusterFinder::UnLoadClusters()
1101 // Unload TOF.RecPoints.root file
1104 fTOFLoader->UnloadRecPoints();
1107 //-------------------------------------------------------------------------
1108 UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
1110 //First of all get the volume ID to retrieve the l2t transformation...
1112 // Detector numbering scheme
1119 Int_t isector =ind[0];
1120 if (isector >= nSector)
1121 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1122 Int_t iplate = ind[1];
1123 if (iplate >= nPlate)
1124 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1125 Int_t istrip = ind[2];
1127 Int_t stripOffset = 0;
1133 stripOffset = nStripC;
1136 stripOffset = nStripC+nStripB;
1139 stripOffset = nStripC+nStripB+nStripA;
1142 stripOffset = nStripC+nStripB+nStripA+nStripB;
1145 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1149 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1153 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1157 //-------------------------------------------------------------------------
1158 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1160 //First of all get the volume ID to retrieve the l2t transformation...
1162 UShort_t volIndex = GetClusterVolIndex(ind);
1165 //we now go in the system of the strip: determine the local coordinates
1168 // 47---------------------------------------------------0 ^ z
1169 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1170 // ----------------------------------------------------- | y going outwards
1171 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1173 // ----------------------------------------------------- |
1174 // x <-----------------------------------------------------
1176 Float_t localX=(ind[4]-23.5)*2.5;
1178 Float_t localZ=(ind[3]-0.5)*3.5;
1180 //move to the tracking ref system
1187 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1188 // Get The position in the track ref system
1190 l2t->MasterToLocal(lpos,tpos);
1195 //Get The cluster covariance in the track ref system
1198 //cluster covariance in the local system:
1203 lcov[0]=2.5*2.5/12.;
1211 lcov[8]=3.5*3.5/12.;
1213 //cluster covariance in the tracking system:
1215 m.SetRotation(lcov);
1217 m.MultiplyLeft(&l2t->Inverse());
1218 Double_t *tcov = m.GetRotationMatrix();
1219 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1220 cov[3] = tcov[4]; cov[4] = tcov[5];