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 **************************************************************************/
18 Revision 1.30 2007/10/04 13:08:52 arcelli
19 updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
21 Revision 1.29 2007/10/03 10:42:33 arcelli
22 updates to handle new AliTOFcluster, inheriting form AliCluster3D
24 Revision 1.28 2007/05/31 16:06:05 arcelli
25 move instance of AliRawStream outside loop on DDL
27 Revision 1.27 2007/05/02 16:31:49 arcelli
28 Add methods to handle single event reconstruction. retrieval of Calib info moved to AliTOFReconstructor ctor, and passed via a pointer to AliTOFcalib
30 Revision 1.26 2007/04/30 19:02:24 arcelli
31 hopefully the last refinements for correct type conversion in calibration
33 Revision 1.25 2007/04/30 15:22:17 arcelli
34 Change TOF digit Time, Tot etc to int type
36 Revision 1.24 2007/04/27 11:19:31 arcelli
37 updates for the new decoder
39 Revision 1.23 2007/04/23 16:51:39 decaro
40 Digits-to-raw_data conversion: correction for a more real description (A.De Caro, R.Preghenella)
42 Revision 1.22 2007/04/19 17:26:32 arcelli
43 Fix a bug (add some debug printout
45 Revision 1.21 2007/04/18 17:28:12 arcelli
46 Set the ToT bin width to the one actually used...
48 Revision 1.20 2007/03/09 09:57:23 arcelli
49 Remove a forgotten include of Riostrem
51 Revision 1.19 2007/03/08 15:41:20 arcelli
52 set uncorrected times when filling RecPoints
54 Revision 1.18 2007/03/06 16:31:20 arcelli
55 Add Uncorrected TOF Time signal
57 Revision 1.17 2007/02/28 18:09:11 arcelli
58 Add protection against failed retrieval of the CDB cal object, now Reconstruction exits with AliFatal
60 Revision 1.16 2007/02/20 15:57:00 decaro
61 Raw data update: to read the TOF raw data defined in UNPACKED mode
64 Revision 0.03 2005/07/28 A. De Caro
65 Implement public method
66 Raw2Digits(Int_t, AliRawReader *)
67 to convert digits from raw data in MC digits
70 Revision 0.02 2005/07/27 A. De Caro
71 Implement public method
72 Digits2RecPoint(Int_t)
73 to convert digits in clusters
75 Revision 0.02 2005/07/26 A. De Caro
76 Implement private methods
77 InsertCluster(AliTOFcluster *)
78 FindClusterIndex(Double_t)
79 originally implemented in AliTOFtracker
80 by S. Arcelli and C. Zampolli
82 Revision 0.01 2005/07/25 A. De Caro
83 Implement public methods
84 Digits2RecPoint(AliRawReader *, TTree *)
85 Digits2RecPoint(Int_t, AliRawReader *)
86 to convert raw data in clusters
89 ////////////////////////////////////////////////////////////////
91 // Class for TOF cluster finder //
93 // Starting from Raw Data, create rec points, //
94 // fill TreeR for TOF, //
95 // write TOF.RecPoints.root file //
97 ////////////////////////////////////////////////////////////////
100 #include "TClonesArray.h"
101 #include "TStopwatch.h"
103 #include <TGeoManager.h>
104 #include <AliGeomManager.h>
105 #include <TGeoMatrix.h>
106 #include <TGeoPhysicalNode.h>
107 #include "AliAlignObj.h"
110 #include "AliLoader.h"
112 #include "AliRawReader.h"
113 #include "AliRunLoader.h"
115 #include "AliTOFcalib.h"
116 #include "AliTOFChannelOnline.h"
117 #include "AliTOFChannelOffline.h"
118 #include "AliTOFClusterFinder.h"
119 #include "AliTOFcluster.h"
120 #include "AliTOFdigit.h"
121 #include "AliTOFGeometry.h"
122 #include "AliTOFrawData.h"
123 #include "AliTOFRawStream.h"
124 #include "Riostream.h"
126 //extern TFile *gFile;
128 ClassImp(AliTOFClusterFinder)
130 AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
135 fDigits(new TClonesArray("AliTOFdigit", 4000)),
136 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
137 fNumberOfTofClusters(0),
147 //______________________________________________________________________________
149 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
150 fRunLoader(runLoader),
151 fTOFLoader(runLoader->GetLoader("TOFLoader")),
154 fDigits(new TClonesArray("AliTOFdigit", 4000)),
155 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
156 fNumberOfTofClusters(0),
167 //------------------------------------------------------------------------
168 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
174 fDigits(new TClonesArray("AliTOFdigit", 4000)),
175 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
176 fNumberOfTofClusters(0),
182 this->fDigits=source.fDigits;
183 this->fRecPoints=source.fRecPoints;
184 this->fDecoderVersion=source.fDecoderVersion;
185 this->fTOFcalib=source.fTOFcalib;
189 //------------------------------------------------------------------------
190 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
193 this->fDigits=source.fDigits;
194 this->fRecPoints=source.fRecPoints;
195 this->fVerbose=source.fVerbose;
196 this->fDecoderVersion=source.fDecoderVersion;
197 this->fTOFcalib=source.fTOFcalib;
201 //______________________________________________________________________________
203 AliTOFClusterFinder::~AliTOFClusterFinder()
218 fRecPoints->Delete();
224 //______________________________________________________________________________
226 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
229 // Converts digits to recpoints for TOF
232 TStopwatch stopwatch;
235 fRunLoader->GetEvent(iEvent);
237 fTreeD = fTOFLoader->TreeD();
240 AliFatal("AliTOFClusterFinder: Can not get TreeD");
243 TBranch *branch = fTreeD->GetBranch("TOF");
245 AliError("can't get the branch with the TOF digits !");
249 TClonesArray *digits = new TClonesArray("AliTOFdigit",10000);
250 branch->SetAddress(&digits);
254 fTreeR = fTOFLoader->TreeR();
257 fTOFLoader->MakeTree("R");
258 fTreeR = fTOFLoader->TreeR();
261 Int_t bufsize = 32000;
262 fTreeR->Branch("TOF", &fRecPoints, bufsize);
265 Int_t nDigits = digits->GetEntriesFast();
266 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
269 Int_t dig[5]; //cluster detector indeces
270 Int_t parTOF[5]; //The TOF signal parameters
271 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
272 for (ii=0; ii<nDigits; ii++) {
273 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
274 dig[0]=d->GetSector();
275 dig[1]=d->GetPlate();
276 dig[2]=d->GetStrip();
280 // AliDebug(2,Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
282 parTOF[0] = d->GetTdc(); //the TDC signal
283 parTOF[1] = d->GetToT(); //the ToT signal
284 parTOF[2] = d->GetAdc(); // the adc charge
285 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
286 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
289 UShort_t volIdClus=GetClusterVolIndex(dig);
290 GetClusterPars(dig, posClus,covClus);
291 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);
292 InsertCluster(tofCluster);
296 AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
304 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
305 fTOFLoader->WriteRecPoints("OVERWRITE");
307 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
308 stopwatch.RealTime(),stopwatch.CpuTime()));
314 //______________________________________________________________________________
316 void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
319 // Converts digits to recpoints for TOF
322 TStopwatch stopwatch;
325 /// fRunLoader->GetEvent(iEvent);
327 if (digitsTree == 0x0)
329 AliFatal("AliTOFClusterFinder: Can not get TreeD");
332 TBranch *branch = digitsTree->GetBranch("TOF");
334 AliError("can't get the branch with the TOF digits !");
338 TClonesArray *digits = new TClonesArray("AliTOFdigit",10000);
339 branch->SetAddress(&digits);
344 Int_t bufsize = 32000;
345 fTreeR->Branch("TOF", &fRecPoints, bufsize);
347 digitsTree->GetEvent(0);
348 Int_t nDigits = digits->GetEntriesFast();
349 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
352 Int_t dig[5]; //cluster detector indeces
353 Int_t parTOF[5]; //The TOF signal parameters
354 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
355 for (ii=0; ii<nDigits; ii++) {
356 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
357 dig[0]=d->GetSector();
358 dig[1]=d->GetPlate();
359 dig[2]=d->GetStrip();
363 // AliDebug(2,Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
365 parTOF[0] = d->GetTdc(); //the TDC signal
366 parTOF[1] = d->GetToT(); //the ToT signal
367 parTOF[2] = d->GetAdc(); // the adc charge
368 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
369 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
373 UShort_t volIdClus=GetClusterVolIndex(dig);
374 GetClusterPars(dig,posClus,covClus);
375 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);
376 InsertCluster(tofCluster);
380 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
388 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
389 stopwatch.RealTime(),stopwatch.CpuTime()));
394 //______________________________________________________________________________
396 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
400 // Converts RAW data to recpoints for TOF
403 TStopwatch stopwatch;
406 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
407 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
411 Int_t bufsize = 32000;
412 clustersTree->Branch("TOF", &fRecPoints, bufsize);
414 TClonesArray * clonesRawData;
418 Int_t detectorIndex[5];
422 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
424 AliTOFRawStream tofInput(rawReader);
427 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
430 if (fDecoderVersion) {
431 AliInfo("Using New Decoder \n");
432 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
434 else tofInput.LoadRawData(indexDDL);
436 clonesRawData = (TClonesArray*)tofInput.GetRawData();
438 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
440 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
442 if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
445 if (indexDDL<10) ftxt << " " << indexDDL;
446 else ftxt << " " << indexDDL;
447 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
448 else ftxt << " " << tofRawDatum->GetTRM();
449 ftxt << " " << tofRawDatum->GetTRMchain();
450 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
451 else ftxt << " " << tofRawDatum->GetTDC();
452 ftxt << " " << tofRawDatum->GetTDCchannel();
455 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
456 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
457 dummy = detectorIndex[3];
458 detectorIndex[3] = detectorIndex[4];
459 detectorIndex[4] = dummy;
462 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
463 else ftxt << " -> " << detectorIndex[0];
464 ftxt << " " << detectorIndex[1];
465 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
466 else ftxt << " " << detectorIndex[2];
467 ftxt << " " << detectorIndex[3];
468 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
469 else ftxt << " " << detectorIndex[4];
472 parTOF[0] = tofRawDatum->GetTOF(); //TDC
473 parTOF[1] = tofRawDatum->GetTOT(); // TOT
474 parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
475 parTOF[3] = -1;//raw data: no track of undecalib sim time
476 parTOF[4] = tofRawDatum->GetTOF(); // RAW time
479 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
480 Int_t lab[3]={-1,-1,-1};
482 GetClusterPars(detectorIndex,posClus,covClus);
483 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);
484 InsertCluster(tofCluster);
487 if (parTOF[1]<10)ftxt << " " << parTOF[1];
488 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
489 else ftxt << " " << parTOF[1];
490 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
491 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
492 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
493 else ftxt << " " << parTOF[3] << endl;
496 } // closed loop on TOF raw data per current DDL file
498 clonesRawData->Clear();
500 } // closed loop on DDL index
502 if (fVerbose==2) ftxt.close();
504 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
509 clustersTree->Fill();
513 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
514 stopwatch.RealTime(),stopwatch.CpuTime()));
517 //______________________________________________________________________________
519 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
522 // Converts RAW data to recpoints for TOF
525 TStopwatch stopwatch;
528 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
529 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
531 fRunLoader->GetEvent(iEvent);
533 AliDebug(2,Form(" Event number %2i ", iEvent));
535 fTreeR = fTOFLoader->TreeR();
538 fTOFLoader->MakeTree("R");
539 fTreeR = fTOFLoader->TreeR();
542 Int_t bufsize = 32000;
543 fTreeR->Branch("TOF", &fRecPoints, bufsize);
545 TClonesArray * clonesRawData;
549 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
552 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
554 AliTOFRawStream tofInput(rawReader);
557 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
560 if (fDecoderVersion) {
561 AliInfo("Using New Decoder \n");
562 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
564 else tofInput.LoadRawData(indexDDL);
566 clonesRawData = (TClonesArray*)tofInput.GetRawData();
568 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
570 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
572 if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
575 if (indexDDL<10) ftxt << " " << indexDDL;
576 else ftxt << " " << indexDDL;
577 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
578 else ftxt << " " << tofRawDatum->GetTRM();
579 ftxt << " " << tofRawDatum->GetTRMchain();
580 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
581 else ftxt << " " << tofRawDatum->GetTDC();
582 ftxt << " " << tofRawDatum->GetTDCchannel();
585 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
586 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
587 dummy = detectorIndex[3];
588 detectorIndex[3] = detectorIndex[4];
589 detectorIndex[4] = dummy;
592 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
593 else ftxt << " -> " << detectorIndex[0];
594 ftxt << " " << detectorIndex[1];
595 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
596 else ftxt << " " << detectorIndex[2];
597 ftxt << " " << detectorIndex[3];
598 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
599 else ftxt << " " << detectorIndex[4];
602 parTOF[0] = tofRawDatum->GetTOF(); // TDC
603 parTOF[1] = tofRawDatum->GetTOT(); // TOT
604 parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
605 parTOF[3] = -1; //raw data: no track of the undecalib sim time
606 parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
609 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
610 Int_t lab[3]={-1,-1,-1};
612 GetClusterPars(detectorIndex,posClus,covClus);
613 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);
614 InsertCluster(tofCluster);
617 if (parTOF[1]<10)ftxt << " " << parTOF[1];
618 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
619 else ftxt << " " << parTOF[1];
620 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
621 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
622 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
623 else ftxt << " " << parTOF[3] << endl;
626 } // closed loop on TOF raw data per current DDL file
628 clonesRawData->Clear();
630 } // closed loop on DDL index
632 if (fVerbose==2) ftxt.close();
634 AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
642 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
643 fTOFLoader->WriteRecPoints("OVERWRITE");
645 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
646 stopwatch.RealTime(),stopwatch.CpuTime()));
649 //______________________________________________________________________________
651 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
654 // Converts RAW data to MC digits for TOF
656 // (temporary solution)
659 TStopwatch stopwatch;
662 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
663 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
665 fRunLoader->GetEvent(iEvent);
667 fTreeD = fTOFLoader->TreeD();
670 AliInfo("TreeD re-creation");
672 fTOFLoader->MakeTree("D");
673 fTreeD = fTOFLoader->TreeD();
676 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
677 Int_t bufsize = 32000;
678 fTreeD->Branch("TOF", &tofDigits, bufsize);
680 fRunLoader->GetEvent(iEvent);
682 AliDebug(2,Form(" Event number %2i ", iEvent));
684 TClonesArray * clonesRawData;
688 Int_t detectorIndex[5];
691 AliTOFRawStream tofInput(rawReader);
694 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
697 if (fDecoderVersion) {
698 AliInfo("Using New Decoder \n");
699 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
701 else tofInput.LoadRawData(indexDDL);
703 clonesRawData = (TClonesArray*)tofInput.GetRawData();
705 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
707 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
709 if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
711 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
712 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
713 dummy = detectorIndex[3];
714 detectorIndex[3] = detectorIndex[4];
715 detectorIndex[4] = dummy;
717 digit[0] = tofInput.GetTofBin();
718 digit[1] = tofInput.GetToTbin();
719 digit[2] = tofInput.GetToTbin();
722 Int_t tracknum[3]={-1,-1,-1};
724 TClonesArray &aDigits = *tofDigits;
725 Int_t last=tofDigits->GetEntriesFast();
726 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
730 clonesRawData->Clear();
736 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
737 fTOFLoader->WriteDigits("OVERWRITE");
739 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
740 stopwatch.RealTime(),stopwatch.CpuTime()));
744 //______________________________________________________________________________
746 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
749 // Converts RAW data to MC digits for TOF for the current event
753 TStopwatch stopwatch;
756 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
760 AliError("No input digits Tree");
764 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
765 Int_t bufsize = 32000;
766 digitsTree->Branch("TOF", &tofDigits, bufsize);
768 /// fRunLoader->GetEvent(iEvent);
770 /// AliDebug(2,Form(" Event number %2i ", iEvent));
772 TClonesArray * clonesRawData;
776 Int_t detectorIndex[5];
779 AliTOFRawStream tofInput(rawReader);
782 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
785 if (fDecoderVersion) {
786 AliInfo("Using New Decoder \n");
787 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
789 else tofInput.LoadRawData(indexDDL);
791 clonesRawData = (TClonesArray*)tofInput.GetRawData();
793 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
795 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
797 if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
799 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
800 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
801 dummy = detectorIndex[3];
802 detectorIndex[3] = detectorIndex[4];
803 detectorIndex[4] = dummy;
805 digit[0] = tofInput.GetTofBin();
806 digit[1] = tofInput.GetToTbin();
807 digit[2] = tofInput.GetToTbin();
810 Int_t tracknum[3]={-1,-1,-1};
812 TClonesArray &aDigits = *tofDigits;
813 Int_t last=tofDigits->GetEntriesFast();
814 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
818 clonesRawData->Clear();
824 AliDebug(1, Form("Got %d digits: ", tofDigits->GetEntries()));
825 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
826 stopwatch.RealTime(),stopwatch.CpuTime()));
829 //______________________________________________________________________________
831 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
832 //---------------------------------------------------------------------------//
833 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
834 //---------------------------------------------------------------------------//
835 if (fNumberOfTofClusters==kTofMaxCluster) {
836 AliError("Too many clusters !");
840 if (fNumberOfTofClusters==0) {
841 fTofClusters[fNumberOfTofClusters++] = tofCluster;
845 Int_t ii = FindClusterIndex(tofCluster->GetZ());
846 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
847 fTofClusters[ii] = tofCluster;
848 fNumberOfTofClusters++;
853 //_________________________________________________________________________
855 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
856 //--------------------------------------------------------------------
857 // This function returns the index of the nearest cluster in z
858 //--------------------------------------------------------------------
859 if (fNumberOfTofClusters==0) return 0;
860 if (z <= fTofClusters[0]->GetZ()) return 0;
861 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
862 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
863 for (; b<e; m=(b+e)/2) {
864 if (z > fTofClusters[m]->GetZ()) b=m+1;
871 //_________________________________________________________________________
873 void AliTOFClusterFinder::FillRecPoint()
876 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
877 // in Z) in the global TClonesArray of AliTOFcluster,
883 Int_t detectorIndex[5];
885 Int_t trackLabels[3];
886 Int_t digitIndex = -1;
889 TClonesArray &lRecPoints = *fRecPoints;
891 for (ii=0; ii<fNumberOfTofClusters; ii++) {
893 digitIndex = fTofClusters[ii]->GetIndex();
894 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
895 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
896 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
897 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
898 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
899 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
900 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
901 status=fTofClusters[ii]->GetStatus();
904 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
905 GetClusterPars(detectorIndex,posClus,covClus);
906 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);
908 } // loop on clusters
912 //_________________________________________________________________________
913 void AliTOFClusterFinder::CalibrateRecPoint()
916 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
917 // in Z) in the global TClonesArray of AliTOFcluster,
923 Int_t detectorIndex[5];
924 Int_t digitIndex = -1;
928 AliInfo(" Calibrating TOF Clusters: ")
930 TObjArray *calTOFArrayOnline = fTOFcalib->GetTOFCalArrayOnline();
931 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
932 TString validity = (TString)fTOFcalib->GetOfflineValidity();
933 AliInfo(Form(" validity = %s",validity.Data()));
934 Int_t calibration = -1;
935 if (validity.CompareTo("valid")==0) {
936 AliInfo(" Using offline calibration parameters");
940 AliInfo(" Using online calibration parameters");
943 for (ii=0; ii<fNumberOfTofClusters; ii++) {
944 digitIndex = fTofClusters[ii]->GetIndex();
945 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
947 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
949 AliTOFChannelOnline * calChannelOnline = (AliTOFChannelOnline* )calTOFArrayOnline->At(index);
951 // Get channel status
952 UChar_t status=calChannelOnline->GetStatus();
953 if((status & AliTOFChannelOnline::kTOFOnlineOk)!=(AliTOFChannelOnline::kTOFOnlineOk))fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
954 // Get Rough channel online equalization
955 Double_t roughDelay=(Double_t)calChannelOnline->GetDelay(); // in ns
956 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
957 // Get Refined channel offline calibration parameters
958 if (calibration ==1){
959 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
961 for (Int_t j = 0; j<6; j++){
962 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
964 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
965 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %i , %i", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
966 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
967 tToT*=1.E-3; //ToT in ns
968 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
969 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)
972 timeCorr = roughDelay; // correction in ns
974 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
975 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
976 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
978 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
979 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
980 fTofClusters[ii]->SetTDC(tdcCorr);
981 } // loop on clusters
984 //______________________________________________________________________________
986 void AliTOFClusterFinder::ResetRecpoint()
989 // Clear the list of reconstructed points
992 fNumberOfTofClusters = 0;
993 if (fRecPoints) fRecPoints->Clear();
996 //______________________________________________________________________________
998 void AliTOFClusterFinder::Load()
1001 // Load TOF.Digits.root and TOF.RecPoints.root files
1004 fTOFLoader->LoadDigits("READ");
1005 fTOFLoader->LoadRecPoints("recreate");
1008 //______________________________________________________________________________
1010 void AliTOFClusterFinder::LoadClusters()
1013 // Load TOF.RecPoints.root file
1016 fTOFLoader->LoadRecPoints("recreate");
1019 //______________________________________________________________________________
1021 void AliTOFClusterFinder::UnLoad()
1024 // Unload TOF.Digits.root and TOF.RecPoints.root files
1027 fTOFLoader->UnloadDigits();
1028 fTOFLoader->UnloadRecPoints();
1031 //______________________________________________________________________________
1033 void AliTOFClusterFinder::UnLoadClusters()
1036 // Unload TOF.RecPoints.root file
1039 fTOFLoader->UnloadRecPoints();
1042 //-------------------------------------------------------------------------
1043 UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
1045 //First of all get the volume ID to retrieve the l2t transformation...
1047 // Detector numbering scheme
1054 Int_t isector =ind[0];
1055 if (isector >= nSector)
1056 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1057 Int_t iplate = ind[1];
1058 if (iplate >= nPlate)
1059 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1060 Int_t istrip = ind[2];
1062 Int_t stripOffset = 0;
1068 stripOffset = nStripC;
1071 stripOffset = nStripC+nStripB;
1074 stripOffset = nStripC+nStripB+nStripA;
1077 stripOffset = nStripC+nStripB+nStripA+nStripB;
1080 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1084 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1088 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1092 //-------------------------------------------------------------------------
1093 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1095 //First of all get the volume ID to retrieve the l2t transformation...
1097 UShort_t volIndex = GetClusterVolIndex(ind);
1100 //we now go in the system of the strip: determine the local coordinates
1103 // 47---------------------------------------------------0 ^ z
1104 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1105 // ----------------------------------------------------- | y going outwards
1106 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1108 // ----------------------------------------------------- |
1109 // x <-----------------------------------------------------
1111 Float_t localX=(ind[4]-23.5)*2.5;
1113 Float_t localZ=(ind[3]-0.5)*3.5;
1115 //move to the tracking ref system
1122 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1123 // Get The position in the track ref system
1125 l2t->MasterToLocal(lpos,tpos);
1130 //Get The cluster covariance in the track ref system
1133 //cluster covariance in the local system:
1138 lcov[0]=2.5*2.5/12.;
1146 lcov[8]=3.5*3.5/12.;
1148 //cluster covariance in the tracking system:
1150 m.SetRotation(lcov);
1152 m.MultiplyLeft(&l2t->Inverse());
1153 Double_t *tcov = m.GetRotationMatrix();
1154 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1155 cov[3] = tcov[4]; cov[4] = tcov[5];