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 Revision 1.1.4.2 2000/04/10 11:34:02 kowal2
20 Clusters handling in a new data structure
24 ///////////////////////////////////////////////////////////////////////////////
26 // Time Projection Chamber clusters objects //
28 // Origin: Marian Ivanov , GSI Darmstadt
32 ///////////////////////////////////////////////////////////////////////////////
36 #include "AliCluster.h"
37 #include "AliClusters.h"
38 #include "TClonesArray.h"
42 const Int_t kDefSize = 1; //defalut size
47 //*****************************************************************************
49 //_____________________________________________________________________________
50 AliClusters::AliClusters()
59 Bool_t AliClusters::SetClass(const Text_t *classname)
62 //set class of stored object
69 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
71 fClass = gROOT->GetClass(classname);
73 Error("AliClusters", "%s is not a valid class name", classname);
76 if (!fClass->InheritsFrom(AliCluster::Class())) {
77 Error("AliClusters", "%s does not inherit from AliCluster", classname);
83 //_____________________________________________________________________________
84 void AliClusters::SetArray(Int_t length)
87 // construct Clones array of object
89 if (fClusters!=0) delete fClusters;
91 Error("AliClusters", "cluster type not initialised \n SetClass before!");
94 fClusters = new TClonesArray(fClass->GetName(),length);
99 //_____________________________________________________________________________
100 const AliCluster* AliClusters::operator[](Int_t i)
103 // return cluster at internal position i
105 if (fClusters==0) return 0;
106 void * cl = fClusters->UncheckedAt(i);
108 return (AliCluster*)cl;
110 //_____________________________________________________________________________
111 void AliClusters::Sort()
114 if (fClusters!=0) fClusters->Sort();
117 //_____________________________________________________________________________
118 AliCluster * AliClusters::InsertCluster( const AliCluster * c)
121 // Add a simulated cluster copy to the list
124 Error("AliClusters", "class type not specified");
127 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),1000);
128 TClonesArray &lclusters = *fClusters;
129 return new(lclusters[fNclusters++]) AliCluster(*c);
132 //_____________________________________________________________________________
133 Int_t AliClusters::Find(Double_t y) const
136 // return index of cluster nearest to given y position
139 cl=(AliCluster*)fClusters->UncheckedAt(0);
140 if (y <= cl->fY) return 0;
141 cl=(AliCluster*)fClusters->UncheckedAt(fNclusters-1);
142 if (y > cl->fY) return fNclusters;
143 Int_t b=0, e=fNclusters-1, m=(b+e)/2;
144 for (; b<e; m=(b+e)/2) {
145 cl = (AliCluster*)fClusters->UncheckedAt(m);
146 if (y > cl->fY) b=m+1;
153 //_____________________________________________________________________________
155 void AliClusters::Draw(Float_t shiftx, Float_t shifty,
156 Int_t color, Int_t size, Int_t style)
159 if (fClusters==0) return;
160 //draw marker for each of cluster
161 Int_t ncl=fClusters->GetEntriesFast();
162 for (Int_t i=0;i<ncl;i++){
163 AliCluster *cl = (AliCluster*)fClusters->UncheckedAt(i);
164 TMarker * marker = new TMarker;
165 marker->SetX(cl->fX+shiftx);
166 marker->SetY(cl->fY+shifty);
167 marker->SetMarkerSize(size);
168 marker->SetMarkerStyle(style);
169 marker->SetMarkerColor(color);