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 info moved to AliTOFReconstructor ctor, and passed via a pointer to AliTOFcalib
33 Revision 1.26 2007/04/30 19:02:24 arcelli
34 hopefully the last refinements for correct type conversion in calibration
36 Revision 1.25 2007/04/30 15:22:17 arcelli
37 Change TOF digit Time, Tot etc to int type
39 Revision 1.24 2007/04/27 11:19:31 arcelli
40 updates for the new decoder
42 Revision 1.23 2007/04/23 16:51:39 decaro
43 Digits-to-raw_data conversion: correction for a more real description (A.De Caro, R.Preghenella)
45 Revision 1.22 2007/04/19 17:26:32 arcelli
46 Fix a bug (add some debug printout
48 Revision 1.21 2007/04/18 17:28:12 arcelli
49 Set the ToT bin width to the one actually used...
51 Revision 1.20 2007/03/09 09:57:23 arcelli
52 Remove a forgotten include of Riostrem
54 Revision 1.19 2007/03/08 15:41:20 arcelli
55 set uncorrected times when filling RecPoints
57 Revision 1.18 2007/03/06 16:31:20 arcelli
58 Add Uncorrected TOF Time signal
60 Revision 1.17 2007/02/28 18:09:11 arcelli
61 Add protection against failed retrieval of the CDB cal object, now Reconstruction exits with AliFatal
63 Revision 1.16 2007/02/20 15:57:00 decaro
64 Raw data update: to read the TOF raw data defined in UNPACKED mode
67 Revision 0.03 2005/07/28 A. De Caro
68 Implement public method
69 Raw2Digits(Int_t, AliRawReader *)
70 to convert digits from raw data in MC digits
73 Revision 0.02 2005/07/27 A. De Caro
74 Implement public method
75 Digits2RecPoint(Int_t)
76 to convert digits in clusters
78 Revision 0.02 2005/07/26 A. De Caro
79 Implement private methods
80 InsertCluster(AliTOFcluster *)
81 FindClusterIndex(Double_t)
82 originally implemented in AliTOFtracker
83 by S. Arcelli and C. Zampolli
85 Revision 0.01 2005/07/25 A. De Caro
86 Implement public methods
87 Digits2RecPoint(AliRawReader *, TTree *)
88 Digits2RecPoint(Int_t, AliRawReader *)
89 to convert raw data in clusters
92 ////////////////////////////////////////////////////////////////
94 // Class for TOF cluster finder //
96 // Starting from Raw Data, create rec points, //
97 // fill TreeR for TOF, //
98 // write TOF.RecPoints.root file //
100 ////////////////////////////////////////////////////////////////
102 #include "Riostream.h"
104 #include "TClonesArray.h"
105 #include "TStopwatch.h"
107 //#include <TGeoManager.h>
108 #include <TGeoMatrix.h>
109 //#include <TGeoPhysicalNode.h>
112 #include "AliLoader.h"
114 #include "AliRawReader.h"
115 #include "AliRunLoader.h"
116 //#include "AliAlignObj.h"
117 #include <AliGeomManager.h>
119 #include "AliTOFcalib.h"
120 #include "AliTOFChannelOnline.h"
121 #include "AliTOFChannelOnlineStatus.h"
122 #include "AliTOFChannelOffline.h"
123 #include "AliTOFClusterFinder.h"
124 #include "AliTOFcluster.h"
125 #include "AliTOFdigit.h"
126 #include "AliTOFGeometry.h"
127 #include "AliTOFrawData.h"
128 #include "AliTOFRawStream.h"
130 //extern TFile *gFile;
132 ClassImp(AliTOFClusterFinder)
134 AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
139 fDigits(new TClonesArray("AliTOFdigit", 4000)),
140 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
141 fNumberOfTofClusters(0),
151 //______________________________________________________________________________
153 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
154 fRunLoader(runLoader),
155 fTOFLoader(runLoader->GetLoader("TOFLoader")),
158 fDigits(new TClonesArray("AliTOFdigit", 4000)),
159 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
160 fNumberOfTofClusters(0),
171 //------------------------------------------------------------------------
172 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
178 fDigits(new TClonesArray("AliTOFdigit", 4000)),
179 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
180 fNumberOfTofClusters(0),
186 this->fDigits=source.fDigits;
187 this->fRecPoints=source.fRecPoints;
188 this->fDecoderVersion=source.fDecoderVersion;
189 this->fTOFcalib=source.fTOFcalib;
193 //------------------------------------------------------------------------
194 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
197 this->fDigits=source.fDigits;
198 this->fRecPoints=source.fRecPoints;
199 this->fVerbose=source.fVerbose;
200 this->fDecoderVersion=source.fDecoderVersion;
201 this->fTOFcalib=source.fTOFcalib;
205 //______________________________________________________________________________
207 AliTOFClusterFinder::~AliTOFClusterFinder()
222 fRecPoints->Delete();
228 //______________________________________________________________________________
230 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
233 // Converts digits to recpoints for TOF
236 TStopwatch stopwatch;
239 fRunLoader->GetEvent(iEvent);
241 fTreeD = fTOFLoader->TreeD();
244 AliFatal("AliTOFClusterFinder: Can not get TreeD");
247 TBranch *branch = fTreeD->GetBranch("TOF");
249 AliError("can't get the branch with the TOF digits !");
253 TClonesArray staticdigits("AliTOFdigit",10000);
254 staticdigits.Clear();
255 TClonesArray *digits =&staticdigits;
256 branch->SetAddress(&digits);
260 fTreeR = fTOFLoader->TreeR();
263 fTOFLoader->MakeTree("R");
264 fTreeR = fTOFLoader->TreeR();
267 Int_t bufsize = 32000;
268 fTreeR->Branch("TOF", &fRecPoints, bufsize);
271 Int_t nDigits = digits->GetEntriesFast();
272 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
275 Int_t dig[5]; //cluster detector indeces
276 Int_t parTOF[5]; //The TOF signal parameters
277 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
278 for (ii=0; ii<nDigits; ii++) {
279 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
280 dig[0]=d->GetSector();
281 dig[1]=d->GetPlate();
282 dig[2]=d->GetStrip();
286 // AliDebug(2,Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
288 parTOF[0] = d->GetTdc(); //the TDC signal
289 parTOF[1] = d->GetToT(); //the ToT signal
290 parTOF[2] = d->GetAdc(); // the adc charge
291 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
292 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
295 UShort_t volIdClus=GetClusterVolIndex(dig);
296 GetClusterPars(dig, posClus,covClus);
297 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);
298 InsertCluster(tofCluster);
302 AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
310 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
311 fTOFLoader->WriteRecPoints("OVERWRITE");
313 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
314 stopwatch.RealTime(),stopwatch.CpuTime()));
318 //______________________________________________________________________________
320 void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree)
323 // Converts digits to recpoints for TOF
326 TStopwatch stopwatch;
329 /// fRunLoader->GetEvent(iEvent);
331 if (digitsTree == 0x0)
333 AliFatal("AliTOFClusterFinder: Can not get TreeD");
336 TBranch *branch = digitsTree->GetBranch("TOF");
338 AliError("can't get the branch with the TOF digits !");
342 TClonesArray staticdigits("AliTOFdigit",10000);
343 staticdigits.Clear();
344 TClonesArray *digits = & staticdigits;
345 branch->SetAddress(&digits);
350 Int_t bufsize = 32000;
351 fTreeR->Branch("TOF", &fRecPoints, bufsize);
353 digitsTree->GetEvent(0);
354 Int_t nDigits = digits->GetEntriesFast();
355 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
358 Int_t dig[5]; //cluster detector indeces
359 Int_t parTOF[5]; //The TOF signal parameters
360 Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
361 for (ii=0; ii<nDigits; ii++) {
362 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
363 dig[0]=d->GetSector();
364 dig[1]=d->GetPlate();
365 dig[2]=d->GetStrip();
369 // AliDebug(2,Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
371 parTOF[0] = d->GetTdc(); //the TDC signal
372 parTOF[1] = d->GetToT(); //the ToT signal
373 parTOF[2] = d->GetAdc(); // the adc charge
374 parTOF[3] = d->GetTdcND(); // non decalibrated sim time
375 parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
379 UShort_t volIdClus=GetClusterVolIndex(dig);
380 GetClusterPars(dig,posClus,covClus);
381 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);
382 InsertCluster(tofCluster);
386 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
394 AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
395 stopwatch.RealTime(),stopwatch.CpuTime()));
398 //______________________________________________________________________________
400 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
404 // Converts RAW data to recpoints for TOF
407 TStopwatch stopwatch;
410 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
411 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
415 Int_t bufsize = 32000;
416 clustersTree->Branch("TOF", &fRecPoints, bufsize);
418 TClonesArray * clonesRawData;
422 Int_t detectorIndex[5];
426 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
428 AliTOFRawStream tofInput(rawReader);
431 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
434 if (fDecoderVersion) {
435 AliInfo("Using New Decoder \n");
436 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
438 else tofInput.LoadRawData(indexDDL);
440 clonesRawData = (TClonesArray*)tofInput.GetRawData();
442 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
444 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
446 if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
449 if (indexDDL<10) ftxt << " " << indexDDL;
450 else ftxt << " " << indexDDL;
451 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
452 else ftxt << " " << tofRawDatum->GetTRM();
453 ftxt << " " << tofRawDatum->GetTRMchain();
454 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
455 else ftxt << " " << tofRawDatum->GetTDC();
456 ftxt << " " << tofRawDatum->GetTDCchannel();
459 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
460 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
461 dummy = detectorIndex[3];
462 detectorIndex[3] = detectorIndex[4];
463 detectorIndex[4] = dummy;
466 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
467 else ftxt << " -> " << detectorIndex[0];
468 ftxt << " " << detectorIndex[1];
469 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
470 else ftxt << " " << detectorIndex[2];
471 ftxt << " " << detectorIndex[3];
472 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
473 else ftxt << " " << detectorIndex[4];
476 parTOF[0] = tofRawDatum->GetTOF(); //TDC
477 parTOF[1] = tofRawDatum->GetTOT(); // TOT
478 parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
479 parTOF[3] = -1;//raw data: no track of undecalib sim time
480 parTOF[4] = tofRawDatum->GetTOF(); // RAW time
483 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
484 Int_t lab[3]={-1,-1,-1};
486 GetClusterPars(detectorIndex,posClus,covClus);
487 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);
488 InsertCluster(tofCluster);
491 if (parTOF[1]<10)ftxt << " " << parTOF[1];
492 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
493 else ftxt << " " << parTOF[1];
494 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
495 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
496 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
497 else ftxt << " " << parTOF[3] << endl;
500 } // closed loop on TOF raw data per current DDL file
502 clonesRawData->Clear();
504 } // closed loop on DDL index
506 if (fVerbose==2) ftxt.close();
508 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
513 clustersTree->Fill();
517 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
518 stopwatch.RealTime(),stopwatch.CpuTime()));
521 //______________________________________________________________________________
523 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
526 // Converts RAW data to recpoints for TOF
529 TStopwatch stopwatch;
532 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
533 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
535 fRunLoader->GetEvent(iEvent);
537 AliDebug(2,Form(" Event number %2i ", iEvent));
539 fTreeR = fTOFLoader->TreeR();
542 fTOFLoader->MakeTree("R");
543 fTreeR = fTOFLoader->TreeR();
546 Int_t bufsize = 32000;
547 fTreeR->Branch("TOF", &fRecPoints, bufsize);
549 TClonesArray * clonesRawData;
553 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
556 if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
558 AliTOFRawStream tofInput(rawReader);
561 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
564 if (fDecoderVersion) {
565 AliInfo("Using New Decoder \n");
566 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
568 else tofInput.LoadRawData(indexDDL);
570 clonesRawData = (TClonesArray*)tofInput.GetRawData();
572 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
574 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
576 if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
579 if (indexDDL<10) ftxt << " " << indexDDL;
580 else ftxt << " " << indexDDL;
581 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
582 else ftxt << " " << tofRawDatum->GetTRM();
583 ftxt << " " << tofRawDatum->GetTRMchain();
584 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
585 else ftxt << " " << tofRawDatum->GetTDC();
586 ftxt << " " << tofRawDatum->GetTDCchannel();
589 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
590 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
591 dummy = detectorIndex[3];
592 detectorIndex[3] = detectorIndex[4];
593 detectorIndex[4] = dummy;
596 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
597 else ftxt << " -> " << detectorIndex[0];
598 ftxt << " " << detectorIndex[1];
599 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
600 else ftxt << " " << detectorIndex[2];
601 ftxt << " " << detectorIndex[3];
602 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[4];
603 else ftxt << " " << detectorIndex[4];
606 parTOF[0] = tofRawDatum->GetTOF(); // TDC
607 parTOF[1] = tofRawDatum->GetTOT(); // TOT
608 parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
609 parTOF[3] = -1; //raw data: no track of the undecalib sim time
610 parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
613 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
614 Int_t lab[3]={-1,-1,-1};
616 GetClusterPars(detectorIndex,posClus,covClus);
617 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);
618 InsertCluster(tofCluster);
621 if (parTOF[1]<10)ftxt << " " << parTOF[1];
622 else if (parTOF[1]>=10 && parTOF[1]<100) ftxt << " " << parTOF[1];
623 else ftxt << " " << parTOF[1];
624 if (parTOF[0]<10) ftxt << " " << parTOF[0] << endl;
625 else if (parTOF[0]>=10 && parTOF[0]<100) ftxt << " " << parTOF[0] << endl;
626 else if (parTOF[0]>=100 && parTOF[0]<1000) ftxt << " " << parTOF[0] << endl;
627 else ftxt << " " << parTOF[3] << endl;
630 } // closed loop on TOF raw data per current DDL file
632 clonesRawData->Clear();
634 } // closed loop on DDL index
636 if (fVerbose==2) ftxt.close();
638 AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
646 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
647 fTOFLoader->WriteRecPoints("OVERWRITE");
649 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
650 stopwatch.RealTime(),stopwatch.CpuTime()));
653 //______________________________________________________________________________
655 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
658 // Converts RAW data to MC digits for TOF
660 // (temporary solution)
663 TStopwatch stopwatch;
666 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
667 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
669 fRunLoader->GetEvent(iEvent);
671 fTreeD = fTOFLoader->TreeD();
674 AliInfo("TreeD re-creation");
676 fTOFLoader->MakeTree("D");
677 fTreeD = fTOFLoader->TreeD();
680 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
681 Int_t bufsize = 32000;
682 fTreeD->Branch("TOF", &tofDigits, bufsize);
684 fRunLoader->GetEvent(iEvent);
686 AliDebug(2,Form(" Event number %2i ", iEvent));
688 TClonesArray * clonesRawData;
692 Int_t detectorIndex[5];
695 AliTOFRawStream tofInput(rawReader);
698 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
701 if (fDecoderVersion) {
702 AliInfo("Using New Decoder \n");
703 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
705 else tofInput.LoadRawData(indexDDL);
707 clonesRawData = (TClonesArray*)tofInput.GetRawData();
709 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
711 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
713 if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
715 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
716 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
717 dummy = detectorIndex[3];
718 detectorIndex[3] = detectorIndex[4];
719 detectorIndex[4] = dummy;
721 digit[0] = tofInput.GetTofBin();
722 digit[1] = tofInput.GetToTbin();
723 digit[2] = tofInput.GetToTbin();
726 Int_t tracknum[3]={-1,-1,-1};
728 TClonesArray &aDigits = *tofDigits;
729 Int_t last=tofDigits->GetEntriesFast();
730 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
734 clonesRawData->Clear();
740 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
741 fTOFLoader->WriteDigits("OVERWRITE");
743 AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
744 stopwatch.RealTime(),stopwatch.CpuTime()));
748 //______________________________________________________________________________
750 void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
753 // Converts RAW data to MC digits for TOF for the current event
757 TStopwatch stopwatch;
760 const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
764 AliError("No input digits Tree");
768 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
769 Int_t bufsize = 32000;
770 digitsTree->Branch("TOF", &tofDigits, bufsize);
772 /// fRunLoader->GetEvent(iEvent);
774 /// AliDebug(2,Form(" Event number %2i ", iEvent));
776 TClonesArray * clonesRawData;
780 Int_t detectorIndex[5];
783 AliTOFRawStream tofInput(rawReader);
786 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
789 if (fDecoderVersion) {
790 AliInfo("Using New Decoder \n");
791 tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
793 else tofInput.LoadRawData(indexDDL);
795 clonesRawData = (TClonesArray*)tofInput.GetRawData();
797 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
799 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
801 if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
803 tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
804 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
805 dummy = detectorIndex[3];
806 detectorIndex[3] = detectorIndex[4];
807 detectorIndex[4] = dummy;
809 digit[0] = tofInput.GetTofBin();
810 digit[1] = tofInput.GetToTbin();
811 digit[2] = tofInput.GetToTbin();
814 Int_t tracknum[3]={-1,-1,-1};
816 TClonesArray &aDigits = *tofDigits;
817 Int_t last=tofDigits->GetEntriesFast();
818 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
822 clonesRawData->Clear();
828 AliDebug(1, Form("Got %d digits: ", tofDigits->GetEntries()));
829 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
830 stopwatch.RealTime(),stopwatch.CpuTime()));
833 //______________________________________________________________________________
835 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
836 //---------------------------------------------------------------------------//
837 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
838 //---------------------------------------------------------------------------//
839 if (fNumberOfTofClusters==kTofMaxCluster) {
840 AliError("Too many clusters !");
844 if (fNumberOfTofClusters==0) {
845 fTofClusters[fNumberOfTofClusters++] = tofCluster;
849 Int_t ii = FindClusterIndex(tofCluster->GetZ());
850 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
851 fTofClusters[ii] = tofCluster;
852 fNumberOfTofClusters++;
857 //_________________________________________________________________________
859 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
860 //--------------------------------------------------------------------
861 // This function returns the index of the nearest cluster in z
862 //--------------------------------------------------------------------
863 if (fNumberOfTofClusters==0) return 0;
864 if (z <= fTofClusters[0]->GetZ()) return 0;
865 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
866 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
867 for (; b<e; m=(b+e)/2) {
868 if (z > fTofClusters[m]->GetZ()) b=m+1;
875 //_________________________________________________________________________
877 void AliTOFClusterFinder::FillRecPoint()
880 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
881 // in Z) in the global TClonesArray of AliTOFcluster,
887 Int_t detectorIndex[5];
889 Int_t trackLabels[3];
890 Int_t digitIndex = -1;
893 TClonesArray &lRecPoints = *fRecPoints;
895 for (ii=0; ii<fNumberOfTofClusters; ii++) {
897 digitIndex = fTofClusters[ii]->GetIndex();
898 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
899 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
900 parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
901 parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
902 parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
903 parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
904 parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
905 status=fTofClusters[ii]->GetStatus();
908 UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
909 GetClusterPars(detectorIndex,posClus,covClus);
910 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);
912 } // loop on clusters
916 //_________________________________________________________________________
917 void AliTOFClusterFinder::CalibrateRecPoint()
920 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
921 // in Z) in the global TClonesArray of AliTOFcluster,
927 Int_t detectorIndex[5];
928 Int_t digitIndex = -1;
932 AliInfo(" Calibrating TOF Clusters: ")
934 TObjArray *calTOFArrayOnline = fTOFcalib->GetTOFCalArrayOnline();
935 TObjArray *calTOFArrayOnlinePulser = fTOFcalib->GetTOFCalArrayOnlinePulser();
936 TObjArray *calTOFArrayOnlineNoise = fTOFcalib->GetTOFCalArrayOnlineNoise();
937 TObjArray *calTOFArrayOnlineHW = fTOFcalib->GetTOFCalArrayOnlineHW();
938 TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
939 TString validity = (TString)fTOFcalib->GetOfflineValidity();
940 AliInfo(Form(" validity = %s",validity.Data()));
941 Int_t calibration = -1;
942 if (validity.CompareTo("valid")==0) {
943 AliInfo(" Using offline calibration parameters");
947 AliInfo(" Using online calibration parameters");
950 for (ii=0; ii<fNumberOfTofClusters; ii++) {
951 digitIndex = fTofClusters[ii]->GetIndex();
952 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
954 Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
956 AliTOFChannelOnlineStatus * calChannelOnlineStPulser = (AliTOFChannelOnlineStatus* )calTOFArrayOnlinePulser->At(index);
957 AliTOFChannelOnlineStatus * calChannelOnlineStNoise = (AliTOFChannelOnlineStatus* )calTOFArrayOnlineNoise->At(index);
958 AliTOFChannelOnlineStatus * calChannelOnlineStHW = (AliTOFChannelOnlineStatus* )calTOFArrayOnlineHW->At(index);
960 // Get channel status
961 UChar_t statusPulser=calChannelOnlineStPulser->GetStatus();
962 UChar_t statusNoise=calChannelOnlineStNoise->GetStatus();
963 UChar_t statusHW=calChannelOnlineStHW->GetStatus();
965 //check the status, also unknow is fine!!!!!!!
967 UChar_t status = 0x0;
968 status |= statusPulser;
969 status |= statusNoise;
971 // set status of the cluster to false if at least one of the three status (Pulser/Noise/HW) is bad
972 if((statusPulser & AliTOFChannelOnlineStatus::kTOFPulserBad)==(AliTOFChannelOnlineStatus::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatus::kTOFNoiseBad)==(AliTOFChannelOnlineStatus::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatus::kTOFHWBad)==(AliTOFChannelOnlineStatus::kTOFHWBad)){
973 AliDebug(2, Form(" Bad Status for channel %i",index));
974 fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
977 AliDebug(2, Form(" Good Status for channel %i",index));
979 // if((status & AliTOFChannelOnlineStatus::kTOFOnlineOk)!=(AliTOFChannelOnline::kTOFOnlineOk))fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
980 // Get Rough channel online equalization
981 AliTOFChannelOnline * calChannelOnline = (AliTOFChannelOnline* )calTOFArrayOnline->At(index);
982 Double_t roughDelay=(Double_t)calChannelOnline->GetDelay(); // in ns
983 AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
984 // Get Refined channel offline calibration parameters
985 if (calibration ==1){
986 AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
988 for (Int_t j = 0; j<6; j++){
989 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
991 AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
992 AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %i , %i", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
993 tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
994 tToT*=1.E-3; //ToT in ns
995 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
996 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)
999 timeCorr = roughDelay; // correction in ns
1001 AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
1002 AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
1003 timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
1005 AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
1006 tdcCorr=(Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
1007 fTofClusters[ii]->SetTDC(tdcCorr);
1008 } // loop on clusters
1011 //______________________________________________________________________________
1013 void AliTOFClusterFinder::ResetRecpoint()
1016 // Clear the list of reconstructed points
1019 fNumberOfTofClusters = 0;
1020 if (fRecPoints) fRecPoints->Clear();
1023 //______________________________________________________________________________
1025 void AliTOFClusterFinder::Load()
1028 // Load TOF.Digits.root and TOF.RecPoints.root files
1031 fTOFLoader->LoadDigits("READ");
1032 fTOFLoader->LoadRecPoints("recreate");
1035 //______________________________________________________________________________
1037 void AliTOFClusterFinder::LoadClusters()
1040 // Load TOF.RecPoints.root file
1043 fTOFLoader->LoadRecPoints("recreate");
1046 //______________________________________________________________________________
1048 void AliTOFClusterFinder::UnLoad()
1051 // Unload TOF.Digits.root and TOF.RecPoints.root files
1054 fTOFLoader->UnloadDigits();
1055 fTOFLoader->UnloadRecPoints();
1058 //______________________________________________________________________________
1060 void AliTOFClusterFinder::UnLoadClusters()
1063 // Unload TOF.RecPoints.root file
1066 fTOFLoader->UnloadRecPoints();
1069 //-------------------------------------------------------------------------
1070 UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
1072 //First of all get the volume ID to retrieve the l2t transformation...
1074 // Detector numbering scheme
1081 Int_t isector =ind[0];
1082 if (isector >= nSector)
1083 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1084 Int_t iplate = ind[1];
1085 if (iplate >= nPlate)
1086 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1087 Int_t istrip = ind[2];
1089 Int_t stripOffset = 0;
1095 stripOffset = nStripC;
1098 stripOffset = nStripC+nStripB;
1101 stripOffset = nStripC+nStripB+nStripA;
1104 stripOffset = nStripC+nStripB+nStripA+nStripB;
1107 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1111 Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
1115 UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
1119 //-------------------------------------------------------------------------
1120 void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
1122 //First of all get the volume ID to retrieve the l2t transformation...
1124 UShort_t volIndex = GetClusterVolIndex(ind);
1127 //we now go in the system of the strip: determine the local coordinates
1130 // 47---------------------------------------------------0 ^ z
1131 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
1132 // ----------------------------------------------------- | y going outwards
1133 // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 | par[0]=0;
1135 // ----------------------------------------------------- |
1136 // x <-----------------------------------------------------
1138 Float_t localX=(ind[4]-23.5)*2.5;
1140 Float_t localZ=(ind[3]-0.5)*3.5;
1142 //move to the tracking ref system
1149 const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
1150 // Get The position in the track ref system
1152 l2t->MasterToLocal(lpos,tpos);
1157 //Get The cluster covariance in the track ref system
1160 //cluster covariance in the local system:
1165 lcov[0]=2.5*2.5/12.;
1173 lcov[8]=3.5*3.5/12.;
1175 //cluster covariance in the tracking system:
1177 m.SetRotation(lcov);
1179 m.MultiplyLeft(&l2t->Inverse());
1180 Double_t *tcov = m.GetRotationMatrix();
1181 cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
1182 cov[3] = tcov[4]; cov[4] = tcov[5];