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()
53 //________________________________________________________________________
54 AliClusters::~AliClusters()
59 if (fClusters !=0) fClusters->Clear();
63 //_________________________________________________________________________
65 Bool_t AliClusters::SetClass(const Text_t *classname)
68 //set class of stored object
75 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
77 fClass = gROOT->GetClass(classname);
79 Error("AliClusters", "%s is not a valid class name", classname);
82 if (!fClass->InheritsFrom(TObject::Class())) {
83 Error("AliClusters", "%s does not inherit from TObject", classname);
89 //_____________________________________________________________________________
90 void AliClusters::SetArray(Int_t length)
93 // construct Clones array of object
95 if (fClusters!=0) delete fClusters;
97 Error("AliClusters", "cluster type not initialised \n SetClass before!");
100 fClusters = new TClonesArray(fClass->GetName(),length);
105 //_____________________________________________________________________________
106 const TObject* AliClusters::operator[](Int_t i)
109 // return cluster at internal position i
111 if (fClusters==0) return 0;
112 return fClusters->UncheckedAt(i);
114 //_____________________________________________________________________________
115 void AliClusters::Sort()
118 if (fClusters!=0) fClusters->Sort();
121 //_____________________________________________________________________________
122 TObject * AliClusters::InsertCluster( const TObject * c)
125 // Add a simulated cluster copy to the list
128 Error("AliClusters", "class type not specified");
131 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),1000);
132 TClonesArray &lclusters = *fClusters;
133 return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
136 //_____________________________________________________________________________
137 Int_t AliClusters::Find(Double_t y) const
140 // return index of cluster nearest to given y position
142 AliComplexCluster* cl;
143 cl=(AliComplexCluster*)fClusters->UncheckedAt(0);
144 if (y <= cl->fY) return 0;
145 cl=(AliComplexCluster*)fClusters->UncheckedAt(fNclusters-1);
146 if (y > cl->fY) return fNclusters;
147 Int_t b=0, e=fNclusters-1, m=(b+e)/2;
148 for (; b<e; m=(b+e)/2) {
149 cl = (AliComplexCluster*)fClusters->UncheckedAt(m);
150 if (y > cl->fY) b=m+1;
157 //_____________________________________________________________________________
159 void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
160 Int_t color, Int_t size, Int_t style)
163 if (fClusters==0) return;
164 //draw marker for each of cluster
165 Int_t ncl=fClusters->GetEntriesFast();
166 for (Int_t i=0;i<ncl;i++){
167 AliComplexCluster *cl = (AliComplexCluster*)fClusters->UncheckedAt(i);
168 TMarker * marker = new TMarker;
169 marker->SetX(cl->fX+shiftx);
170 marker->SetY(cl->fY+shifty);
171 marker->SetMarkerSize(size);
172 marker->SetMarkerStyle(style);
173 marker->SetMarkerColor(color);