Adding simple example to load default debug streamer
[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//_____________________________________________________________________________
179c6296 43AliClusters::AliClusters()
44 :AliSegmentID(),
45 fClusters(0),
46 fNclusters(0),
47 fClass(0)
cc80f89e 48{
49 //
50 //default constructor
73042f01 51 //
cc80f89e 52
179c6296 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}
66AliClusters & AliClusters::operator =(const AliClusters & param)
67{
68 //
69 // assignment operator - dummy
70 //
71 fNclusters=param.fNclusters;
72 return (*this);
73}
73042f01 74//________________________________________________________________________
75AliClusters::~AliClusters()
76{
77 //
78 //default destructor
79 //
a0f67dc8 80 if (fClusters !=0) fClusters->Delete();
73042f01 81 delete fClusters;
82}
83
84//_________________________________________________________________________
85
cc80f89e 86Bool_t AliClusters::SetClass(const Text_t *classname)
87{
88 //
89 //set class of stored object
90 if ( fClass !=0 ) {
bb5e9dae 91 // delete fClass;
cc80f89e 92 fClass = 0;
93 }
94
95 if (!gROOT)
96 ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
97
98 fClass = gROOT->GetClass(classname);
99 if (!fClass) {
100 Error("AliClusters", "%s is not a valid class name", classname);
101 return kFALSE;
102 }
73042f01 103 if (!fClass->InheritsFrom(TObject::Class())) {
104 Error("AliClusters", "%s does not inherit from TObject", classname);
105 return kFALSE;
106 }
cc80f89e 107 return kTRUE;
108}
109
110//_____________________________________________________________________________
111void AliClusters::SetArray(Int_t length)
112{
113 //
114 // construct Clones array of object
115 //
116 if (fClusters!=0) delete fClusters;
117 if (fClass==0){
118 Error("AliClusters", "cluster type not initialised \n SetClass before!");
119 return;
120 }
121 fClusters = new TClonesArray(fClass->GetName(),length);
122}
123
124
125
126//_____________________________________________________________________________
73042f01 127const TObject* AliClusters::operator[](Int_t i)
cc80f89e 128{
129 //
130 // return cluster at internal position i
131 //
132 if (fClusters==0) return 0;
73042f01 133 return fClusters->UncheckedAt(i);
cc80f89e 134}
135//_____________________________________________________________________________
136void AliClusters::Sort()
137{
138 // sort cluster
139 if (fClusters!=0) fClusters->Sort();
140}
141
142//_____________________________________________________________________________
73042f01 143TObject * AliClusters::InsertCluster( const TObject * c)
cc80f89e 144{
145 //
146 // Add a simulated cluster copy to the list
147 //
148 if (fClass==0) {
149 Error("AliClusters", "class type not specified");
150 return 0;
151 }
152 if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),1000);
153 TClonesArray &lclusters = *fClusters;
c9787763 154 return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
cc80f89e 155}
156
157//_____________________________________________________________________________
158Int_t AliClusters::Find(Double_t y) const
159{
160 //
161 // return index of cluster nearest to given y position
162 //
c9787763 163 AliComplexCluster* cl;
164 cl=(AliComplexCluster*)fClusters->UncheckedAt(0);
b9671574 165 if (y <= cl->GetY()) return 0;
c9787763 166 cl=(AliComplexCluster*)fClusters->UncheckedAt(fNclusters-1);
b9671574 167 if (y > cl->GetY()) return fNclusters;
cc80f89e 168 Int_t b=0, e=fNclusters-1, m=(b+e)/2;
169 for (; b<e; m=(b+e)/2) {
c9787763 170 cl = (AliComplexCluster*)fClusters->UncheckedAt(m);
b9671574 171 if (y > cl->GetY()) b=m+1;
cc80f89e 172 else e=m;
173 }
174 return m;
175}
176
177
178//_____________________________________________________________________________
179
73042f01 180void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
cc80f89e 181 Int_t color, Int_t size, Int_t style)
182{
183
184 if (fClusters==0) return;
185 //draw marker for each of cluster
186 Int_t ncl=fClusters->GetEntriesFast();
187 for (Int_t i=0;i<ncl;i++){
c9787763 188 AliComplexCluster *cl = (AliComplexCluster*)fClusters->UncheckedAt(i);
cc80f89e 189 TMarker * marker = new TMarker;
b9671574 190 marker->SetX(cl->GetX()+shiftx);
191 marker->SetY(cl->GetY()+shifty);
cc80f89e 192 marker->SetMarkerSize(size);
193 marker->SetMarkerStyle(style);
194 marker->SetMarkerColor(color);
195 marker->Draw();
196 }
197}
198