1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Time Projection Chamber clusters objects //
22 // Origin: Marian Ivanov , GSI Darmstadt
26 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliComplexCluster.h"
31 #include "AliClusters.h"
35 const Int_t kDefSize = 1; //defalut size
40 //*****************************************************************************
42 //_____________________________________________________________________________
43 AliClusters::AliClusters()
54 //________________________________________________________________________
55 AliClusters::AliClusters(const AliClusters ¶m)
62 // copy constructor - dummy
64 fNclusters = param.fNclusters;
67 //________________________________________________________________________
68 AliClusters::AliClusters(const char *classname)
75 // Special constructor
77 fClass = gROOT->GetClass(classname);
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);
84 fClusters = new TClonesArray(fClass->GetName(),100);
87 //______________________________________________________________________
88 AliClusters & AliClusters::operator =(const AliClusters & param)
91 // assignment operator - dummy
93 if (this == ¶m) return (*this);
94 fNclusters=param.fNclusters;
97 //________________________________________________________________________
98 AliClusters::~AliClusters()
103 if (fClusters !=0) fClusters->Delete();
107 //_________________________________________________________________________
109 Bool_t AliClusters::SetClass(const Text_t *classname)
112 //set class of stored object
119 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
121 fClass = gROOT->GetClass(classname);
123 Error("AliClusters", "%s is not a valid class name", classname);
126 if (!fClass->InheritsFrom(TObject::Class())) {
127 Error("AliClusters", "%s does not inherit from TObject", classname);
133 //_____________________________________________________________________________
134 void AliClusters::SetArray(Int_t length)
137 // construct Clones array of object
139 if (fClusters!=0) delete fClusters;
141 Error("AliClusters", "cluster type not initialised \n SetClass before!");
144 fClusters = new TClonesArray(fClass->GetName(),length);
149 //_____________________________________________________________________________
150 const TObject* AliClusters::operator[](Int_t i)
153 // return cluster at internal position i
155 if (fClusters==0) return 0;
156 return fClusters->UncheckedAt(i);
158 //_____________________________________________________________________________
159 void AliClusters::Sort()
162 if (fClusters!=0) fClusters->Sort();
165 //_____________________________________________________________________________
166 TObject * AliClusters::InsertCluster( const TObject * c)
169 // Add a simulated cluster copy to the list
172 Error("AliClusters", "class type not specified");
175 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),100);
176 TClonesArray &lclusters = *fClusters;
177 return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
180 //_____________________________________________________________________________
181 Int_t AliClusters::Find(Double_t y) const
184 // return index of cluster nearest to given y position
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;
201 //_____________________________________________________________________________
203 void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
204 Int_t color, Int_t size, Int_t style)
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);