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 0.03 2005/07/28 A. De Caro
19 Implement public method
20 Raw2Digits(Int_t, AliRawReader *)
21 to convert digits from raw data in MC digits
24 Revision 0.02 2005/07/27 A. De Caro
25 Implement public method
26 Digits2RecPoint(Int_t)
27 to convert digits in clusters
29 Revision 0.02 2005/07/26 A. De Caro
30 Implement private methods
31 InsertCluster(AliTOFcluster *)
32 FindClusterIndex(Double_t)
33 originally implemented in AliTOFtracker
34 by S. Arcelli and C. Zampolli
36 Revision 0.01 2005/07/25 A. De Caro
37 Implement public methods
38 Digits2RecPoint(AliRawReader *, TTree *)
39 Digits2RecPoint(Int_t, AliRawReader *)
40 to convert raw data in clusters
43 ////////////////////////////////////////////////////////////////
45 // Class for TOF cluster finder //
47 // Starting from Raw Data, create rec points, //
48 // fill TreeR for TOF, //
49 // write TOF.RecPoints.root file //
51 ////////////////////////////////////////////////////////////////
53 #include "TClonesArray.h"
58 #include "AliLoader.h"
60 #include "AliRawReader.h"
61 #include "AliRunLoader.h"
63 #include "AliTOFcalib.h"
64 #include "AliTOFCal.h"
65 #include "AliTOFChannel.h"
66 #include "AliTOFClusterFinder.h"
67 #include "AliTOFcluster.h"
68 #include "AliTOFdigit.h"
69 #include "AliTOFGeometryV5.h"
70 #include "AliTOFGeometry.h"
71 #include "AliTOFRawStream.h"
75 ClassImp(AliTOFClusterFinder)
77 AliTOFClusterFinder::AliTOFClusterFinder():
82 fTOFGeometry(new AliTOFGeometryV5()),
83 fDigits(new TClonesArray("AliTOFdigit", 4000)),
84 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
85 fNumberOfTofClusters(0)
91 AliInfo("V5 TOF Geometry is taken as the default");
94 //______________________________________________________________________________
96 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader):
97 fRunLoader(runLoader),
98 fTOFLoader(runLoader->GetLoader("TOFLoader")),
101 fTOFGeometry(new AliTOFGeometryV5()),
102 fDigits(new TClonesArray("AliTOFdigit", 4000)),
103 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
104 fNumberOfTofClusters(0)
110 runLoader->CdGAFile();
111 TFile *in=(TFile*)gFile;
113 fTOFGeometry = (AliTOFGeometry*)in->Get("TOFgeometry");
117 //------------------------------------------------------------------------
118 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
124 fTOFGeometry(new AliTOFGeometryV5()),
125 fDigits(new TClonesArray("AliTOFdigit", 4000)),
126 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
127 fNumberOfTofClusters(0)
130 this->fDigits=source.fDigits;
131 this->fRecPoints=source.fRecPoints;
132 this->fTOFGeometry=source.fTOFGeometry;
136 //------------------------------------------------------------------------
137 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
140 this->fDigits=source.fDigits;
141 this->fRecPoints=source.fRecPoints;
142 this->fTOFGeometry=source.fTOFGeometry;
146 //______________________________________________________________________________
148 AliTOFClusterFinder::~AliTOFClusterFinder()
163 fRecPoints->Delete();
171 //______________________________________________________________________________
173 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
176 // Converts digits to recpoints for TOF
179 fRunLoader->GetEvent(iEvent);
181 fTreeD = fTOFLoader->TreeD();
184 AliFatal("AliTOFClusterFinder: Can not get TreeD");
187 TBranch *branch = fTreeD->GetBranch("TOF");
189 AliError("can't get the branch with the TOF digits !");
193 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
194 branch->SetAddress(&digits);
198 fTreeR = fTOFLoader->TreeR();
201 fTOFLoader->MakeTree("R");
202 fTreeR = fTOFLoader->TreeR();
205 Int_t bufsize = 32000;
206 fTreeR->Branch("TOF", &fRecPoints, bufsize);
209 Int_t nDigits = digits->GetEntriesFast();
210 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
218 for (ii=0; ii<nDigits; ii++) {
219 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
220 dig[0]=d->GetSector();
221 dig[1]=d->GetPlate();
222 dig[2]=d->GetStrip();
226 //AliInfo(Form(" %2i %1i %2i %1i %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
228 for (jj=0; jj<3; jj++) g[jj] = 0.;
229 fTOFGeometry->GetPos(dig,g);
231 h[0] = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
232 h[1] = TMath::ATan2(g[1],g[0]);
237 tTdcND = d->GetTdcND();
239 AliTOFcluster *tofCluster = new AliTOFcluster(h,d->GetTracks(),dig,ii,tToT, tTdcND);
240 InsertCluster(tofCluster);
244 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
252 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
253 fTOFLoader->WriteRecPoints("OVERWRITE");
256 //______________________________________________________________________________
258 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
262 // Converts RAW data to recpoints for TOF
265 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
266 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
270 Int_t bufsize = 32000;
271 clustersTree->Branch("TOF", &fRecPoints, bufsize);
276 Int_t detectorIndex[5];
278 Double_t cylindricalPosition[5];
282 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
285 AliTOFRawStream tofInput(rawReader);
286 rawReader->Select("TOF", indexDDL, indexDDL);
288 while(tofInput.Next()) {
290 for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
292 detectorIndex[0] = tofInput.GetSector();
293 detectorIndex[1] = tofInput.GetPlate();
294 detectorIndex[2] = tofInput.GetStrip();
295 detectorIndex[3] = tofInput.GetPadZ();
296 detectorIndex[4] = tofInput.GetPadX();
298 //AliInfo(Form(" %2i %1i %2i %1i %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
300 if (detectorIndex[0]==-1 ||
301 detectorIndex[1]==-1 ||
302 detectorIndex[2]==-1 ||
303 detectorIndex[3]==-1 ||
304 detectorIndex[4]==-1) continue;
306 for (ii=0; ii<3; ii++) position[ii] = 0.;
308 fTOFGeometry->GetPos(detectorIndex, position);
310 cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
311 cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
312 cylindricalPosition[2] = position[2];
313 cylindricalPosition[3] = tofInput.GetTofBin();
314 cylindricalPosition[4] = tofInput.GetToTbin();
315 tToT = tofInput.GetToTbin();
317 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
318 tofCluster->SetToT(tToT);
319 tofCluster->SetTDCND(tTdcND);
320 InsertCluster(tofCluster);
324 } // loop on DDL files
326 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
331 clustersTree->Fill();
336 //______________________________________________________________________________
338 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
341 // Converts RAW data to recpoints for TOF
344 //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
345 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
347 fRunLoader->GetEvent(iEvent);
349 AliDebug(2,Form(" Event number %2i ", iEvent));
351 fTreeR = fTOFLoader->TreeR();
354 fTOFLoader->MakeTree("R");
355 fTreeR = fTOFLoader->TreeR();
358 Int_t bufsize = 32000;
359 fTreeR->Branch("TOF", &fRecPoints, bufsize);
364 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
366 Double_t cylindricalPosition[5];
370 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
373 AliTOFRawStream tofInput(rawReader);
374 rawReader->Select("TOF", indexDDL, indexDDL);
376 while(tofInput.Next()) {
378 for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
380 detectorIndex[0] = (Int_t)tofInput.GetSector();
381 detectorIndex[1] = (Int_t)tofInput.GetPlate();
382 detectorIndex[2] = (Int_t)tofInput.GetStrip();
383 detectorIndex[3] = (Int_t)tofInput.GetPadZ();
384 detectorIndex[4] = (Int_t)tofInput.GetPadX();
386 if (detectorIndex[0]==-1 ||
387 detectorIndex[1]==-1 ||
388 detectorIndex[2]==-1 ||
389 detectorIndex[3]==-1 ||
390 detectorIndex[4]==-1) continue;
392 //AliInfo(Form(" %2i %1i %2i %1i %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
394 for (ii=0; ii<3; ii++) position[ii] = 0.;
396 fTOFGeometry->GetPos(detectorIndex, position);
398 cylindricalPosition[0] = (Double_t)TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
399 cylindricalPosition[1] = (Double_t)TMath::ATan2(position[1], position[0]);
400 cylindricalPosition[2] = (Double_t)position[2];
401 cylindricalPosition[3] = (Double_t)tofInput.GetTofBin();
402 cylindricalPosition[4] = (Double_t)tofInput.GetToTbin();
403 tToT = tofInput.GetToTbin();
406 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
407 tofCluster->SetToT(tToT);
408 tofCluster->SetTDCND(tTdcND);
409 InsertCluster(tofCluster);
415 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
423 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
424 fTOFLoader->WriteRecPoints("OVERWRITE");
427 //______________________________________________________________________________
429 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
432 // Converts RAW data to MC digits for TOF
434 // (temporary solution)
437 fRunLoader->GetEvent(iEvent);
439 fTreeD = fTOFLoader->TreeD();
442 AliInfo("TreeD re-creation");
444 fTOFLoader->MakeTree("D");
445 fTreeD = fTOFLoader->TreeD();
448 TClonesArray dummy("AliTOFdigit",10000), *tofDigits=&dummy;
449 Int_t bufsize = 32000;
450 fTreeD->Branch("TOF", &tofDigits, bufsize);
453 const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
455 fRunLoader->GetEvent(iEvent);
457 AliDebug(2,Form(" Event number %2i ", iEvent));
462 Int_t detectorIndex[5];
465 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
468 AliTOFRawStream tofInput(rawReader);
469 rawReader->Select("TOF", indexDDL, indexDDL);
471 while(tofInput.Next()) {
473 for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
475 detectorIndex[0] = tofInput.GetSector();
476 detectorIndex[1] = tofInput.GetPlate();
477 detectorIndex[2] = tofInput.GetStrip();
478 detectorIndex[3] = tofInput.GetPadX();
479 detectorIndex[4] = tofInput.GetPadZ();
481 //AliInfo(Form(" %2i %1i %2i %1i %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
483 if (detectorIndex[0]==-1 ||
484 detectorIndex[1]==-1 ||
485 detectorIndex[2]==-1 ||
486 detectorIndex[3]==-1 ||
487 detectorIndex[4]==-1) continue;
489 digit[0] = (Float_t)tofInput.GetTofBin();
490 digit[1] = (Float_t)tofInput.GetToTbin();
491 digit[2] = (Float_t)tofInput.GetToTbin();
494 Int_t tracknum[3]={-1,-1,-1};
496 TClonesArray &aDigits = *tofDigits;
497 Int_t last=tofDigits->GetEntriesFast();
498 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
506 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
507 fTOFLoader->WriteDigits("OVERWRITE");
510 //______________________________________________________________________________
512 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
513 //---------------------------------------------------------------------------//
514 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
515 //---------------------------------------------------------------------------//
516 if (fNumberOfTofClusters==kTofMaxCluster) {
517 AliError("Too many clusters !");
521 if (fNumberOfTofClusters==0) {
522 fTofClusters[fNumberOfTofClusters++] = tofCluster;
526 Int_t ii = FindClusterIndex(tofCluster->GetZ());
527 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
528 fTofClusters[ii] = tofCluster;
529 fNumberOfTofClusters++;
534 //_________________________________________________________________________
536 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
537 //--------------------------------------------------------------------
538 // This function returns the index of the nearest cluster
539 //--------------------------------------------------------------------
540 if (fNumberOfTofClusters==0) return 0;
541 if (z <= fTofClusters[0]->GetZ()) return 0;
542 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
543 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
544 for (; b<e; m=(b+e)/2) {
545 if (z > fTofClusters[m]->GetZ()) b=m+1;
552 //_________________________________________________________________________
554 void AliTOFClusterFinder::FillRecPoint()
557 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
558 // in Z) in the global TClonesArray of AliTOFcluster,
564 Int_t detectorIndex[5];
565 Double_t cylindricalPosition[5];
566 Int_t trackLabels[3];
567 Int_t digitIndex = -1;
570 Bool_t cStatus = kTRUE;
572 TClonesArray &lRecPoints = *fRecPoints;
574 for (ii=0; ii<fNumberOfTofClusters; ii++) {
576 digitIndex = fTofClusters[ii]->GetIndex();
577 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
578 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
579 cylindricalPosition[0] = fTofClusters[ii]->GetR();
580 cylindricalPosition[1] = fTofClusters[ii]->GetPhi();
581 cylindricalPosition[2] = fTofClusters[ii]->GetZ();
582 cylindricalPosition[3] = fTofClusters[ii]->GetTDC();
583 cylindricalPosition[4] = fTofClusters[ii]->GetADC();
584 tToT = fTofClusters[ii]->GetToT();
585 tTdcND = fTofClusters[ii]->GetTDCND();
586 cStatus=fTofClusters[ii]->GetStatus();
588 new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, trackLabels, detectorIndex, digitIndex, tToT, tTdcND, cStatus);
590 //AliInfo(Form("%3i %3i %f %f %f %f %f %2i %2i %2i %1i %2i",ii,digitIndex, cylindricalPosition[2],cylindricalPosition[0],cylindricalPosition[1],cylindricalPosition[3],cylindricalPosition[4],detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
592 } // loop on clusters
596 //_________________________________________________________________________
597 void AliTOFClusterFinder::CalibrateRecPoint()
600 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
601 // in Z) in the global TClonesArray of AliTOFcluster,
607 Int_t detectorIndex[5];
608 Int_t digitIndex = -1;
611 AliInfo(" Calibrating TOF Clusters: ")
612 AliTOFcalib *calib = new AliTOFcalib(fTOFGeometry);
613 // calib->ReadParFromCDB("TOF/Calib",0); // original
614 calib->ReadParFromCDB("TOF/Calib",-1); // Use AliCDBManager's run number
615 AliTOFCal *calTOFArray = calib->GetTOFCalArray();
617 for (ii=0; ii<fNumberOfTofClusters; ii++) {
618 digitIndex = fTofClusters[ii]->GetIndex();
619 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
621 Int_t index = calib->GetIndex(detectorIndex);
623 AliTOFChannel * calChannel = calTOFArray->GetChannel(index);
625 // Get channel status
626 Bool_t status=calChannel->GetStatus();
627 if(status)fTofClusters[ii]->SetStatus(!status); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
629 // Get Rough channel online equalization
630 Float_t roughDelay=calChannel->GetDelay();
632 // Get Refined channel offline calibration parameters
634 for (Int_t j = 0; j<6; j++){
635 par[j]=calChannel->GetSlewPar(j);
637 tToT = fTofClusters[ii]->GetToT();
638 Float_t 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+roughDelay;
639 tdcCorr=(fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()+32)*1.E-3-timeCorr;
640 tdcCorr=(tdcCorr*1E3-32)/AliTOFGeometry::TdcBinWidth();
641 fTofClusters[ii]->SetTDC(tdcCorr);
643 } // loop on clusters
647 //______________________________________________________________________________
649 void AliTOFClusterFinder::ResetRecpoint()
652 // Clear the list of reconstructed points
655 fNumberOfTofClusters = 0;
656 if (fRecPoints) fRecPoints->Clear();
659 //______________________________________________________________________________
661 void AliTOFClusterFinder::Load()
664 // Load TOF.Digits.root and TOF.RecPoints.root files
667 fTOFLoader->LoadDigits("READ");
668 fTOFLoader->LoadRecPoints("recreate");
671 //______________________________________________________________________________
673 void AliTOFClusterFinder::LoadClusters()
676 // Load TOF.RecPoints.root file
679 fTOFLoader->LoadRecPoints("recreate");
682 //______________________________________________________________________________
684 void AliTOFClusterFinder::UnLoad()
687 // Unload TOF.Digits.root and TOF.RecPoints.root files
690 fTOFLoader->UnloadDigits();
691 fTOFLoader->UnloadRecPoints();
694 //______________________________________________________________________________
696 void AliTOFClusterFinder::UnLoadClusters()
699 // Unload TOF.RecPoints.root file
702 fTOFLoader->UnloadRecPoints();
705 //______________________________________________________________________________