]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliClusters.cxx
60f6ed146fbb28e3c211a6085f55d60a57612fd3
[u/mrichter/AliRoot.git] / TPC / AliClusters.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.2.4.2  2000/06/14 16:45:13  kowal2
19 Improved algorithms. Compiler warnings removed.
20
21 Revision 1.2.4.1  2000/06/09 07:09:29  kowal2
22
23 Clustering and tracking classes are splitted from the simulation ones
24
25 Revision 1.2  2000/04/17 09:37:33  kowal2
26 removed obsolete AliTPCDigitsDisplay.C
27
28 Revision 1.1.4.2  2000/04/10 11:34:02  kowal2
29
30 Clusters handling in a new data structure
31
32 */
33
34 ///////////////////////////////////////////////////////////////////////////////
35 //                                                                           //
36 //  Time Projection Chamber clusters objects                                //
37 //
38 //  Origin: Marian Ivanov , GSI Darmstadt
39 //                                                                           //
40 //                                                                           //
41 //                                                                          //
42 ///////////////////////////////////////////////////////////////////////////////
43 #include "TError.h"
44 #include "TClass.h"
45 #include  <TROOT.h>
46 #include "AliCluster.h"
47 #include "AliClusters.h"
48 #include "TClonesArray.h"
49 #include "TMarker.h"
50
51
52 const Int_t kDefSize = 1;  //defalut size
53
54
55 ClassImp(AliClusters) 
56
57 //*****************************************************************************
58 //
59 //_____________________________________________________________________________
60 AliClusters::AliClusters() 
61 {  
62   //
63   //default constructor
64   //
65   fNclusters=0;
66   fClusters =0;
67   fClass =0;
68 }
69
70 //________________________________________________________________________
71 AliClusters::~AliClusters()
72 {
73    //
74    //default destructor
75   //
76    if (fClusters !=0) fClusters->Clear();
77    delete fClusters;
78 }
79
80 //_________________________________________________________________________
81
82 Bool_t AliClusters::SetClass(const Text_t *classname)
83 {
84   //
85   //set class of stored object
86   if ( fClass !=0 ) {
87     delete fClass;
88     fClass = 0;
89   }
90  
91   if (!gROOT)
92       ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
93    
94    fClass = gROOT->GetClass(classname);
95    if (!fClass) {
96       Error("AliClusters", "%s is not a valid class name", classname);
97       return kFALSE;
98    }
99    if (!fClass->InheritsFrom(TObject::Class())) {
100       Error("AliClusters", "%s does not inherit from TObject", classname);
101       return kFALSE; 
102    } 
103    return kTRUE;
104 }
105
106 //_____________________________________________________________________________
107 void AliClusters::SetArray(Int_t length)
108 {
109   //
110   // construct Clones array of object
111   //
112   if (fClusters!=0) delete fClusters;
113   if (fClass==0){
114      Error("AliClusters", "cluster type not initialised \n SetClass before!");
115      return;
116   }
117   fClusters = new TClonesArray(fClass->GetName(),length);
118 }
119
120
121
122 //_____________________________________________________________________________
123 const  TObject* AliClusters::operator[](Int_t i)
124 {
125   //
126   // return cluster at internal position i
127   //
128   if (fClusters==0) return 0;
129   return fClusters->UncheckedAt(i);
130 }
131 //_____________________________________________________________________________
132 void  AliClusters::Sort()
133 {
134   // sort cluster 
135   if (fClusters!=0) fClusters->Sort();
136 }
137
138 //_____________________________________________________________________________
139 TObject * AliClusters::InsertCluster( const TObject * c) 
140
141   //
142   // Add a simulated cluster copy to the list
143   //
144   if (fClass==0) { 
145     Error("AliClusters", "class type not specified");
146     return 0; 
147   }
148   if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),1000);
149   TClonesArray &lclusters = *fClusters;
150   return new(lclusters[fNclusters++]) AliCluster(*((AliCluster*)c));
151 }
152
153 //_____________________________________________________________________________
154 Int_t AliClusters::Find(Double_t y) const 
155 {
156   //
157   // return index of cluster nearest to given y position
158   //
159   AliCluster* cl;
160   cl=(AliCluster*)fClusters->UncheckedAt(0);
161   if (y <= cl->fY) return 0;  
162   cl=(AliCluster*)fClusters->UncheckedAt(fNclusters-1);
163   if (y > cl->fY) return fNclusters; 
164   Int_t b=0, e=fNclusters-1, m=(b+e)/2;
165   for (; b<e; m=(b+e)/2) {
166     cl = (AliCluster*)fClusters->UncheckedAt(m);
167     if (y > cl->fY) b=m+1;
168     else e=m; 
169   }
170   return m;
171 }
172
173
174 //_____________________________________________________________________________
175
176 void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty, 
177                                   Int_t color, Int_t size, Int_t style)
178 {
179
180   if (fClusters==0) return;  
181   //draw marker for each of cluster
182   Int_t ncl=fClusters->GetEntriesFast();
183   for (Int_t i=0;i<ncl;i++){
184     AliCluster *cl = (AliCluster*)fClusters->UncheckedAt(i);
185     TMarker * marker = new TMarker;
186     marker->SetX(cl->fX+shiftx);
187     marker->SetY(cl->fY+shifty);
188     marker->SetMarkerSize(size);
189     marker->SetMarkerStyle(style);
190     marker->SetMarkerColor(color);
191     marker->Draw();    
192   }
193 }
194