]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TPC/AliClusters.cxx
par file fix
[u/mrichter/AliRoot.git] / TPC / AliClusters.cxx
... / ...
CommitLineData
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/* $Id$ */
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>
30#include "AliComplexCluster.h"
31#include "AliClusters.h"
32#include "TMarker.h"
33
34
35const Int_t kDefSize = 1; //defalut size
36
37
38ClassImp(AliClusters)
39
40//*****************************************************************************
41//
42//_____________________________________________________________________________
43AliClusters::AliClusters()
44 :AliSegmentID(),
45 fClusters(0),
46 fNclusters(0),
47 fClass(0)
48{
49 //
50 //default constructor
51 //
52
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}
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//______________________________________________________________________
88AliClusters & AliClusters::operator =(const AliClusters & param)
89{
90 //
91 // assignment operator - dummy
92 //
93 if (this == &param) return (*this);
94 fNclusters=param.fNclusters;
95 return (*this);
96}
97//________________________________________________________________________
98AliClusters::~AliClusters()
99{
100 //
101 //default destructor
102 //
103 if (fClusters !=0) fClusters->Delete();
104 delete fClusters;
105}
106
107//_________________________________________________________________________
108
109Bool_t AliClusters::SetClass(const Text_t *classname)
110{
111 //
112 //set class of stored object
113 if ( fClass !=0 ) {
114 // delete fClass;
115 fClass = 0;
116 }
117
118 if (!gROOT)
119 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
120
121 fClass = gROOT->GetClass(classname);
122 if (!fClass) {
123 Error("AliClusters", "%s is not a valid class name", classname);
124 return kFALSE;
125 }
126 if (!fClass->InheritsFrom(TObject::Class())) {
127 Error("AliClusters", "%s does not inherit from TObject", classname);
128 return kFALSE;
129 }
130 return kTRUE;
131}
132
133//_____________________________________________________________________________
134void AliClusters::SetArray(Int_t length)
135{
136 //
137 // construct Clones array of object
138 //
139 if (fClusters!=0) delete fClusters;
140 if (fClass==0){
141 Error("AliClusters", "cluster type not initialised \n SetClass before!");
142 return;
143 }
144 fClusters = new TClonesArray(fClass->GetName(),length);
145}
146
147
148
149//_____________________________________________________________________________
150const TObject* AliClusters::operator[](Int_t i)
151{
152 //
153 // return cluster at internal position i
154 //
155 if (fClusters==0) return 0;
156 return fClusters->UncheckedAt(i);
157}
158//_____________________________________________________________________________
159void AliClusters::Sort()
160{
161 // sort cluster
162 if (fClusters!=0) fClusters->Sort();
163}
164
165//_____________________________________________________________________________
166TObject * AliClusters::InsertCluster( const TObject * c)
167{
168 //
169 // Add a simulated cluster copy to the list
170 //
171 if (fClass==0) {
172 Error("AliClusters", "class type not specified");
173 return 0;
174 }
175 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),100);
176 TClonesArray &lclusters = *fClusters;
177 return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
178}
179
180//_____________________________________________________________________________
181Int_t AliClusters::Find(Double_t y) const
182{
183 //
184 // return index of cluster nearest to given y position
185 //
186 AliComplexCluster* cl;
187 cl=(AliComplexCluster*)fClusters->UncheckedAt(0);
188 if (y <= cl->GetY()) return 0;
189 cl=(AliComplexCluster*)fClusters->UncheckedAt(fNclusters-1);
190 if (y > cl->GetY()) return fNclusters;
191 Int_t b=0, e=fNclusters-1, m=(b+e)/2;
192 for (; b<e; m=(b+e)/2) {
193 cl = (AliComplexCluster*)fClusters->UncheckedAt(m);
194 if (y > cl->GetY()) b=m+1;
195 else e=m;
196 }
197 return m;
198}
199
200
201//_____________________________________________________________________________
202
203void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
204 Int_t color, Int_t size, Int_t style)
205{
206
207 if (fClusters==0) return;
208 //draw marker for each of cluster
209 Int_t ncl=fClusters->GetEntriesFast();
210 for (Int_t i=0;i<ncl;i++){
211 AliComplexCluster *cl = (AliComplexCluster*)fClusters->UncheckedAt(i);
212 TMarker * marker = new TMarker;
213 marker->SetX(cl->GetX()+shiftx);
214 marker->SetY(cl->GetY()+shifty);
215 marker->SetMarkerSize(size);
216 marker->SetMarkerStyle(style);
217 marker->SetMarkerColor(color);
218 marker->Draw();
219 }
220}
221