]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliClusters.cxx
Renamed
[u/mrichter/AliRoot.git] / TPC / AliClusters.cxx
CommitLineData
cc80f89e 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
88cb7938 16/* $Id$ */
cc80f89e 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Time Projection Chamber clusters objects //
21//
22// Origin: Marian Ivanov , GSI Darmstadt
23// //
24// //
25// //
26///////////////////////////////////////////////////////////////////////////////
27#include "TError.h"
28#include "TClass.h"
29#include <TROOT.h>
c9787763 30#include "AliComplexCluster.h"
cc80f89e 31#include "AliClusters.h"
cc80f89e 32#include "TMarker.h"
33
34
35const Int_t kDefSize = 1; //defalut size
36
37
38ClassImp(AliClusters)
39
40//*****************************************************************************
41//
42//_____________________________________________________________________________
179c6296 43AliClusters::AliClusters()
44 :AliSegmentID(),
45 fClusters(0),
46 fNclusters(0),
47 fClass(0)
cc80f89e 48{
49 //
50 //default constructor
73042f01 51 //
cc80f89e 52
179c6296 53}
54//________________________________________________________________________
55AliClusters::AliClusters(const AliClusters &param)
56 :AliSegmentID(),
57 fClusters(0),
58 fNclusters(0),
59 fClass(0)
60{
61 //
62 // copy constructor - dummy
63 //
64 fNclusters = param.fNclusters;
65}
e7de6656 66
67//________________________________________________________________________
68AliClusters::AliClusters(const char *classname)
69 :AliSegmentID(),
70 fClusters(0),
71 fNclusters(0),
72 fClass(0)
73{
74//
75// Special constructor
76//
77 fClass = gROOT->GetClass(classname);
78
79 if (!fClass)
80 Error("AliClusters", "%s is not a valid class name", classname);
81 if (!fClass->InheritsFrom(TObject::Class()))
82 Error("AliClusters", "%s does not inherit from TObject", classname);
83
84 fClusters = new TClonesArray(fClass->GetName(),100);
85}
86
87//______________________________________________________________________
179c6296 88AliClusters & AliClusters::operator =(const AliClusters & param)
89{
90 //
91 // assignment operator - dummy
92 //
93 fNclusters=param.fNclusters;
94 return (*this);
95}
73042f01 96//________________________________________________________________________
97AliClusters::~AliClusters()
98{
99 //
100 //default destructor
101 //
a0f67dc8 102 if (fClusters !=0) fClusters->Delete();
73042f01 103 delete fClusters;
104}
105
106//_________________________________________________________________________
107
cc80f89e 108Bool_t AliClusters::SetClass(const Text_t *classname)
109{
110 //
111 //set class of stored object
112 if ( fClass !=0 ) {
bb5e9dae 113 // delete fClass;
cc80f89e 114 fClass = 0;
115 }
116
117 if (!gROOT)
118 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
119
120 fClass = gROOT->GetClass(classname);
121 if (!fClass) {
122 Error("AliClusters", "%s is not a valid class name", classname);
123 return kFALSE;
124 }
73042f01 125 if (!fClass->InheritsFrom(TObject::Class())) {
126 Error("AliClusters", "%s does not inherit from TObject", classname);
127 return kFALSE;
128 }
cc80f89e 129 return kTRUE;
130}
131
132//_____________________________________________________________________________
133void AliClusters::SetArray(Int_t length)
134{
135 //
136 // construct Clones array of object
137 //
138 if (fClusters!=0) delete fClusters;
139 if (fClass==0){
140 Error("AliClusters", "cluster type not initialised \n SetClass before!");
141 return;
142 }
143 fClusters = new TClonesArray(fClass->GetName(),length);
144}
145
146
147
148//_____________________________________________________________________________
73042f01 149const TObject* AliClusters::operator[](Int_t i)
cc80f89e 150{
151 //
152 // return cluster at internal position i
153 //
154 if (fClusters==0) return 0;
73042f01 155 return fClusters->UncheckedAt(i);
cc80f89e 156}
157//_____________________________________________________________________________
158void AliClusters::Sort()
159{
160 // sort cluster
161 if (fClusters!=0) fClusters->Sort();
162}
163
164//_____________________________________________________________________________
73042f01 165TObject * AliClusters::InsertCluster( const TObject * c)
cc80f89e 166{
167 //
168 // Add a simulated cluster copy to the list
169 //
170 if (fClass==0) {
171 Error("AliClusters", "class type not specified");
172 return 0;
173 }
e7de6656 174 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),100);
cc80f89e 175 TClonesArray &lclusters = *fClusters;
c9787763 176 return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
cc80f89e 177}
178
179//_____________________________________________________________________________
180Int_t AliClusters::Find(Double_t y) const
181{
182 //
183 // return index of cluster nearest to given y position
184 //
c9787763 185 AliComplexCluster* cl;
186 cl=(AliComplexCluster*)fClusters->UncheckedAt(0);
b9671574 187 if (y <= cl->GetY()) return 0;
c9787763 188 cl=(AliComplexCluster*)fClusters->UncheckedAt(fNclusters-1);
b9671574 189 if (y > cl->GetY()) return fNclusters;
cc80f89e 190 Int_t b=0, e=fNclusters-1, m=(b+e)/2;
191 for (; b<e; m=(b+e)/2) {
c9787763 192 cl = (AliComplexCluster*)fClusters->UncheckedAt(m);
b9671574 193 if (y > cl->GetY()) b=m+1;
cc80f89e 194 else e=m;
195 }
196 return m;
197}
198
199
200//_____________________________________________________________________________
201
73042f01 202void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
cc80f89e 203 Int_t color, Int_t size, Int_t style)
204{
205
206 if (fClusters==0) return;
207 //draw marker for each of cluster
208 Int_t ncl=fClusters->GetEntriesFast();
209 for (Int_t i=0;i<ncl;i++){
c9787763 210 AliComplexCluster *cl = (AliComplexCluster*)fClusters->UncheckedAt(i);
cc80f89e 211 TMarker * marker = new TMarker;
b9671574 212 marker->SetX(cl->GetX()+shiftx);
213 marker->SetY(cl->GetY()+shifty);
cc80f89e 214 marker->SetMarkerSize(size);
215 marker->SetMarkerStyle(style);
216 marker->SetMarkerColor(color);
217 marker->Draw();
218 }
219}
220