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