GetClusterFast function implemented (No getter before) (Marian)
[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//_____________________________________________________________________________
43AliClusters::AliClusters()
44{
45 //
46 //default constructor
73042f01 47 //
cc80f89e 48 fNclusters=0;
49 fClusters =0;
50 fClass =0;
51}
52
73042f01 53//________________________________________________________________________
54AliClusters::~AliClusters()
55{
56 //
57 //default destructor
58 //
59 if (fClusters !=0) fClusters->Clear();
60 delete fClusters;
61}
62
63//_________________________________________________________________________
64
cc80f89e 65Bool_t AliClusters::SetClass(const Text_t *classname)
66{
67 //
68 //set class of stored object
69 if ( fClass !=0 ) {
bb5e9dae 70 // delete fClass;
cc80f89e 71 fClass = 0;
72 }
73
74 if (!gROOT)
75 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
76
77 fClass = gROOT->GetClass(classname);
78 if (!fClass) {
79 Error("AliClusters", "%s is not a valid class name", classname);
80 return kFALSE;
81 }
73042f01 82 if (!fClass->InheritsFrom(TObject::Class())) {
83 Error("AliClusters", "%s does not inherit from TObject", classname);
84 return kFALSE;
85 }
cc80f89e 86 return kTRUE;
87}
88
89//_____________________________________________________________________________
90void AliClusters::SetArray(Int_t length)
91{
92 //
93 // construct Clones array of object
94 //
95 if (fClusters!=0) delete fClusters;
96 if (fClass==0){
97 Error("AliClusters", "cluster type not initialised \n SetClass before!");
98 return;
99 }
100 fClusters = new TClonesArray(fClass->GetName(),length);
101}
102
103
104
105//_____________________________________________________________________________
73042f01 106const TObject* AliClusters::operator[](Int_t i)
cc80f89e 107{
108 //
109 // return cluster at internal position i
110 //
111 if (fClusters==0) return 0;
73042f01 112 return fClusters->UncheckedAt(i);
cc80f89e 113}
114//_____________________________________________________________________________
115void AliClusters::Sort()
116{
117 // sort cluster
118 if (fClusters!=0) fClusters->Sort();
119}
120
121//_____________________________________________________________________________
73042f01 122TObject * AliClusters::InsertCluster( const TObject * c)
cc80f89e 123{
124 //
125 // Add a simulated cluster copy to the list
126 //
127 if (fClass==0) {
128 Error("AliClusters", "class type not specified");
129 return 0;
130 }
131 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),1000);
132 TClonesArray &lclusters = *fClusters;
c9787763 133 return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
cc80f89e 134}
135
136//_____________________________________________________________________________
137Int_t AliClusters::Find(Double_t y) const
138{
139 //
140 // return index of cluster nearest to given y position
141 //
c9787763 142 AliComplexCluster* cl;
143 cl=(AliComplexCluster*)fClusters->UncheckedAt(0);
cc80f89e 144 if (y <= cl->fY) return 0;
c9787763 145 cl=(AliComplexCluster*)fClusters->UncheckedAt(fNclusters-1);
cc80f89e 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) {
c9787763 149 cl = (AliComplexCluster*)fClusters->UncheckedAt(m);
cc80f89e 150 if (y > cl->fY) b=m+1;
151 else e=m;
152 }
153 return m;
154}
155
156
157//_____________________________________________________________________________
158
73042f01 159void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
cc80f89e 160 Int_t color, Int_t size, Int_t style)
161{
162
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++){
c9787763 167 AliComplexCluster *cl = (AliComplexCluster*)fClusters->UncheckedAt(i);
cc80f89e 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);
174 marker->Draw();
175 }
176}
177