Latest version
[u/mrichter/AliRoot.git] / TRD / AliTRDtimeBin.cxx
CommitLineData
46d29e70 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
0a29d0f1 18Revision 1.5 2001/11/06 17:19:41 cblume
19Add detailed geometry and simple simulator
20
16bf9884 21Revision 1.4 2001/10/21 18:30:02 hristov
22Several pointers were set to zero in the default constructors to avoid memory management problems
23
2685bf00 24Revision 1.3 2000/10/15 23:40:01 cblume
25Remove AliTRDconst
26
0e9c2ad5 27Revision 1.2 2000/10/06 16:49:46 cblume
28Made Getters const
29
46d29e70 30Revision 1.1.2.2 2000/10/04 16:34:58 cblume
31Replace include files by forward declarations
32
33Revision 1.1.2.1 2000/09/22 14:47:52 cblume
34Add the tracking code
35
36*/
0a29d0f1 37
38//////////////////////////////////////////////////////////////////////
39// //
40// Hit compression class //
41// Adapted from AliTPCTimeBin by Marian //
42// //
43//////////////////////////////////////////////////////////////////////
44
46d29e70 45#include "AliTRDcluster.h"
46d29e70 46#include "AliTRDtimeBin.h"
47
48ClassImp(AliTRDtimeBin)
49
50//______________________________________________________
51
2685bf00 52 AliTRDtimeBin::AliTRDtimeBin() {
53 //default constructor
54 fN=0;
0a29d0f1 55 for (UInt_t i=0; i<kMaxClusterPerTimeBin; i++)
2685bf00 56 fClusters[i]=0;
57 }
58//______________________________________________________
59
46d29e70 60void AliTRDtimeBin::InsertCluster(AliTRDcluster* c, UInt_t index) {
61
62// Insert cluster in TimeBin cluster array.
63// Clusters are sorted according to Y coordinate.
64
0a29d0f1 65 if (fN==kMaxClusterPerTimeBin) {
46d29e70 66 printf("AliTRDtimeBin::InsertCluster(): Too many clusters !\n");
67 return;
68 }
69 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
70 Int_t i=Find(c->GetY());
71 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTRDcluster*));
72 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
73 fIndex[i]=index; fClusters[i]=c; fN++;
74}
75
76//______________________________________________________
77
78Int_t AliTRDtimeBin::Find(Double_t y) const {
79
80// Returns index of the cluster nearest in Y
81
82 if (y <= fClusters[0]->GetY()) return 0;
83 if (y > fClusters[fN-1]->GetY()) return fN;
84 Int_t b=0, e=fN-1, m=(b+e)/2;
85 for (; b<e; m=(b+e)/2) {
86 if (y > fClusters[m]->GetY()) b=m+1;
87 else e=m;
88 }
89 return m;
90}
91
92//______________________________________________________
93AliTRDcluster *AliTRDtimeBin::operator[](Int_t i)
94{
95 //
96 // Index operator
97 //
98
99 return fClusters[i];
100
101}