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 <Riostream.h>
55 #include <TObjArray.h>
56 #include <TClonesArray.h>
59 #include "AliRunLoader.h"
60 #include "AliLoader.h"
62 #include "AliTOFdigit.h"
63 #include "AliTOFcluster.h"
64 #include "AliTOFGeometry.h"
65 #include "AliTOFRawStream.h"
67 #include "AliTOFClusterFinder.h"
69 ClassImp(AliTOFClusterFinder)
71 AliTOFClusterFinder::AliTOFClusterFinder():
76 fDigits(new TClonesArray("AliTOFdigit", 4000)),
77 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
78 fNumberOfTofClusters(0)
84 fTOFGeometry = new AliTOFGeometry();
87 //______________________________________________________________________________
89 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader):
90 fRunLoader(runLoader),
91 fTOFLoader(runLoader->GetLoader("TOFLoader")),
94 fDigits(new TClonesArray("AliTOFdigit", 4000)),
95 fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
96 fNumberOfTofClusters(0)
102 fTOFGeometry = new AliTOFGeometry();
105 //______________________________________________________________________________
107 AliTOFClusterFinder::~AliTOFClusterFinder()
122 fRecPoints->Delete();
130 //______________________________________________________________________________
132 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
135 // Converts digits to recpoints for TOF
138 fRunLoader->GetEvent(iEvent);
140 fTreeD = fTOFLoader->TreeD();
143 AliFatal("AliTOFClusterFinder: Can not get TreeD");
146 TBranch *branch = fTreeD->GetBranch("TOF");
148 AliError("can't get the branch with the TOF digits !");
152 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
153 branch->SetAddress(&digits);
157 fTreeR = fTOFLoader->TreeR();
160 fTOFLoader->MakeTree("R");
161 fTreeR = fTOFLoader->TreeR();
164 Int_t bufsize = 32000;
165 fTreeR->Branch("TOF", &fRecPoints, bufsize);
168 Int_t nDigits = digits->GetEntriesFast();
169 AliDebug(2,Form("Number of TOF digits: %d",nDigits));
175 for (ii=0; ii<nDigits; ii++) {
176 AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
177 dig[0]=d->GetSector();
178 dig[1]=d->GetPlate();
179 dig[2]=d->GetStrip();
183 for (jj=0; jj<3; jj++) g[jj] = 0.;
184 fTOFGeometry->GetPos(dig,g);
186 h[0] = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
187 h[1] = TMath::ATan2(g[1],g[0]);
192 AliTOFcluster *tofCluster = new AliTOFcluster(h,d->GetTracks(),dig,ii);
193 InsertCluster(tofCluster);
197 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
204 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
205 fTOFLoader->WriteRecPoints("OVERWRITE");
208 //______________________________________________________________________________
210 void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
214 // Converts RAW data to recpoints for TOF
217 const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
221 Int_t bufsize = 32000;
222 clustersTree->Branch("TOF", &fRecPoints, bufsize);
227 Int_t detectorIndex[5];
229 Double_t cylindricalPosition[5];
231 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
234 AliTOFRawStream tofInput(rawReader);
235 rawReader->Select(5, indexDDL, indexDDL);
237 while(tofInput.Next()) {
239 detectorIndex[0] = tofInput.GetSector();
240 detectorIndex[1] = tofInput.GetPlate();
241 detectorIndex[2] = tofInput.GetStrip();
242 detectorIndex[3] = tofInput.GetPadZ();
243 detectorIndex[4] = tofInput.GetPadX();
245 for (ii=0; ii<3; ii++) position[ii] = 0.;
247 fTOFGeometry->GetPos(detectorIndex, position);
249 cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
250 cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
251 cylindricalPosition[2] = position[2];
252 cylindricalPosition[3] = tofInput.GetTofBin();
253 cylindricalPosition[4] = tofInput.GetADCbin();
255 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
256 InsertCluster(tofCluster);
260 } // loop on DDL files
262 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
266 clustersTree->Fill();
270 //______________________________________________________________________________
272 void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader)
275 // Converts RAW data to recpoints for TOF
278 const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
280 fRunLoader->GetEvent(iEvent);
282 AliDebug(2,Form(" Event number %2i ", iEvent));
284 fTreeR = fTOFLoader->TreeR();
287 fTOFLoader->MakeTree("R");
288 fTreeR = fTOFLoader->TreeR();
291 Int_t bufsize = 32000;
292 fTreeR->Branch("TOF", &fRecPoints, bufsize);
297 Int_t detectorIndex[5];
299 Double_t cylindricalPosition[5];
301 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
304 AliTOFRawStream tofInput(rawReader);
305 rawReader->Select(5, indexDDL, indexDDL);
307 while(tofInput.Next()) {
309 detectorIndex[0] = (Int_t)tofInput.GetSector();
310 detectorIndex[1] = (Int_t)tofInput.GetPlate();
311 detectorIndex[2] = (Int_t)tofInput.GetStrip();
312 detectorIndex[3] = (Int_t)tofInput.GetPadZ();
313 detectorIndex[4] = (Int_t)tofInput.GetPadX();
315 for (ii=0; ii<3; ii++) position[ii] = 0.;
317 fTOFGeometry->GetPos(detectorIndex, position);
319 cylindricalPosition[0] = (Double_t)TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
320 cylindricalPosition[1] = (Double_t)TMath::ATan2(position[1], position[0]);
321 cylindricalPosition[2] = (Double_t)position[2];
322 cylindricalPosition[3] = (Double_t)tofInput.GetTofBin();
323 cylindricalPosition[4] = (Double_t)tofInput.GetADCbin();
325 AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
326 InsertCluster(tofCluster);
332 AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
339 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
340 fTOFLoader->WriteRecPoints("OVERWRITE");
343 //______________________________________________________________________________
345 void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
348 // Converts RAW data to MC digits for TOF
350 // (temporary solution)
353 fRunLoader->GetEvent(iEvent);
355 fTreeD = fTOFLoader->TreeD();
358 AliInfo("AliTOFClusterFinder: TreeD re-creation");
360 fTOFLoader->MakeTree("D");
361 fTreeD = fTOFLoader->TreeD();
365 fTreeR = fTOFLoader->TreeD();
368 fTOFLoader->MakeTree("D");
369 fTreeD = fTOFLoader->TreeD();
372 TClonesArray dummy("AliTOFdigit",10000), *tofDigits=&dummy;
373 Int_t bufsize = 32000;
374 fTreeD->Branch("TOF", &tofDigits, bufsize);
377 const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
379 fRunLoader->GetEvent(iEvent);
381 AliDebug(2,Form(" Event number %2i ", iEvent));
385 Int_t detectorIndex[5];
388 for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
391 AliTOFRawStream tofInput(rawReader);
392 rawReader->Select(5, indexDDL, indexDDL);
394 while(tofInput.Next()) {
396 detectorIndex[0] = tofInput.GetSector();
397 detectorIndex[1] = tofInput.GetPlate();
398 detectorIndex[2] = tofInput.GetStrip();
399 detectorIndex[3] = tofInput.GetPadX();
400 detectorIndex[4] = tofInput.GetPadZ();
402 digit[0] = (Float_t)tofInput.GetTofBin();
403 digit[1] = (Float_t)tofInput.GetADCbin();
405 Int_t tracknum[3]={-1,-1,-1};
407 TClonesArray &aDigits = *tofDigits;
408 Int_t last=tofDigits->GetEntriesFast();
409 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
417 fTOFLoader = fRunLoader->GetLoader("TOFLoader");
418 fTOFLoader->WriteDigits("OVERWRITE");
421 //______________________________________________________________________________
423 Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
424 //---------------------------------------------------------------------------//
425 // This function adds a TOF cluster to the array of TOF clusters sorted in Z //
426 //---------------------------------------------------------------------------//
427 if (fNumberOfTofClusters==kTofMaxCluster) {
428 AliError("Too many clusters !");
432 if (fNumberOfTofClusters==0) {
433 fTofClusters[fNumberOfTofClusters++] = tofCluster;
437 Int_t ii = FindClusterIndex(tofCluster->GetZ());
438 memmove(fTofClusters+ii+1 ,fTofClusters+ii,(fNumberOfTofClusters-ii)*sizeof(AliTOFcluster*));
439 fTofClusters[ii] = tofCluster;
440 fNumberOfTofClusters++;
445 //_________________________________________________________________________
447 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
448 //--------------------------------------------------------------------
449 // This function returns the index of the nearest cluster
450 //--------------------------------------------------------------------
451 if (fNumberOfTofClusters==0) return 0;
452 if (z <= fTofClusters[0]->GetZ()) return 0;
453 if (z > fTofClusters[fNumberOfTofClusters-1]->GetZ()) return fNumberOfTofClusters;
454 Int_t b = 0, e = fNumberOfTofClusters-1, m = (b+e)/2;
455 for (; b<e; m=(b+e)/2) {
456 if (z > fTofClusters[m]->GetZ()) b=m+1;
463 //_________________________________________________________________________
465 void AliTOFClusterFinder::FillRecPoint()
468 // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
469 // in Z) in the global TClonesArray of AliTOFcluster,
475 Int_t detectorIndex[5];
476 Double_t cylindricalPosition[5];
477 Int_t trackLabels[3];
478 Int_t digitIndex = -1;
480 TClonesArray &lRecPoints = *fRecPoints;
482 for (ii=0; ii<fNumberOfTofClusters; ii++) {
484 digitIndex = fTofClusters[ii]->GetIndex();
485 for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
486 for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
487 cylindricalPosition[0] = fTofClusters[ii]->GetR();
488 cylindricalPosition[1] = fTofClusters[ii]->GetPhi();
489 cylindricalPosition[2] = fTofClusters[ii]->GetZ();
490 cylindricalPosition[3] = fTofClusters[ii]->GetTDC();
491 cylindricalPosition[4] = fTofClusters[ii]->GetADC();
493 new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, trackLabels, detectorIndex, digitIndex);
495 //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]));
497 } // loop on clusters
500 //______________________________________________________________________________
502 void AliTOFClusterFinder::ResetRecpoint()
505 // Clear the list of reconstructed points
508 fNumberOfTofClusters = 0;
509 if (fRecPoints) fRecPoints->Clear();
512 //______________________________________________________________________________
514 void AliTOFClusterFinder::Load()
517 // Load TOF.Digits.root and TOF.RecPoints.root files
520 fTOFLoader->LoadDigits("READ");
521 fTOFLoader->LoadRecPoints("recreate");
524 //______________________________________________________________________________
526 void AliTOFClusterFinder::LoadClusters()
529 // Load TOF.RecPoints.root file
532 fTOFLoader->LoadRecPoints("recreate");
535 //______________________________________________________________________________
537 void AliTOFClusterFinder::UnLoad()
540 // Unload TOF.Digits.root and TOF.RecPoints.root files
543 fTOFLoader->UnloadDigits();
544 fTOFLoader->UnloadRecPoints();
547 //______________________________________________________________________________
549 void AliTOFClusterFinder::UnLoadClusters()
552 // Unload TOF.RecPoints.root file
555 fTOFLoader->UnloadRecPoints();
558 //______________________________________________________________________________