Line data Source code
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 :
16 : /// \class AliClusters
17 : /// \brief Time Projection Chamber clusters objects
18 : ///
19 : /// \author Marian Ivanov , GSI Darmstadt
20 :
21 : #include "TError.h"
22 : #include "TClass.h"
23 : #include <TROOT.h>
24 : #include "AliComplexCluster.h"
25 : #include "AliClusters.h"
26 : #include "TMarker.h"
27 :
28 : const Int_t kDefSize = 1; ///< defalut size
29 :
30 : /// \cond CLASSIMP
31 24 : ClassImp(AliClusters)
32 : /// \endcond
33 :
34 : AliClusters::AliClusters()
35 0 : :AliSegmentID(),
36 0 : fClusters(0),
37 0 : fNclusters(0),
38 0 : fClass(0)
39 0 : {
40 : /// default constructor
41 0 : }
42 :
43 : AliClusters::AliClusters(const AliClusters ¶m)
44 0 : :AliSegmentID(),
45 0 : fClusters(0),
46 0 : fNclusters(0),
47 0 : fClass(0)
48 0 : {
49 : /// copy constructor - dummy
50 :
51 0 : fNclusters = param.fNclusters;
52 0 : }
53 :
54 : AliClusters::AliClusters(const char *classname)
55 12 : :AliSegmentID(),
56 12 : fClusters(0),
57 12 : fNclusters(0),
58 12 : fClass(0)
59 36 : {
60 : /// Special constructor
61 :
62 24 : fClass = gROOT->GetClass(classname);
63 :
64 12 : if (!fClass)
65 0 : Error("AliClusters", "%s is not a valid class name", classname);
66 36 : if (!fClass->InheritsFrom(TObject::Class()))
67 0 : Error("AliClusters", "%s does not inherit from TObject", classname);
68 :
69 48 : fClusters = new TClonesArray(fClass->GetName(),100);
70 12 : }
71 :
72 : AliClusters & AliClusters::operator =(const AliClusters & param)
73 : {
74 : /// assignment operator - dummy
75 :
76 0 : if (this == ¶m) return (*this);
77 0 : fNclusters=param.fNclusters;
78 0 : return (*this);
79 0 : }
80 :
81 : AliClusters::~AliClusters()
82 20 : {
83 : /// default destructor
84 :
85 20 : if (fClusters !=0) fClusters->Delete();
86 20 : delete fClusters;
87 10 : }
88 :
89 : Bool_t AliClusters::SetClass(const Text_t *classname)
90 : {
91 : /// set class of stored object
92 :
93 0 : if ( fClass !=0 ) {
94 : // delete fClass;
95 0 : fClass = 0;
96 0 : }
97 :
98 0 : if (!gROOT)
99 0 : ::Fatal("AliClusters::SetClass", "ROOT system not initialized");
100 :
101 0 : fClass = gROOT->GetClass(classname);
102 0 : if (!fClass) {
103 0 : Error("AliClusters", "%s is not a valid class name", classname);
104 0 : return kFALSE;
105 : }
106 0 : if (!fClass->InheritsFrom(TObject::Class())) {
107 0 : Error("AliClusters", "%s does not inherit from TObject", classname);
108 0 : return kFALSE;
109 : }
110 0 : return kTRUE;
111 0 : }
112 :
113 : void AliClusters::SetArray(Int_t length)
114 : {
115 : /// construct Clones array of object
116 :
117 0 : if (fClusters!=0) delete fClusters;
118 0 : if (fClass==0){
119 0 : Error("AliClusters", "cluster type not initialised \n SetClass before!");
120 0 : return;
121 : }
122 0 : fClusters = new TClonesArray(fClass->GetName(),length);
123 0 : }
124 :
125 : const TObject* AliClusters::operator[](Int_t i)
126 : {
127 : /// return cluster at internal position i
128 :
129 0 : if (fClusters==0) return 0;
130 0 : return fClusters->UncheckedAt(i);
131 0 : }
132 :
133 : void AliClusters::Sort()
134 : {
135 : /// sort cluster
136 :
137 0 : if (fClusters!=0) fClusters->Sort();
138 0 : }
139 :
140 : TObject * AliClusters::InsertCluster( const TObject * c)
141 : {
142 : /// Add a simulated cluster copy to the list
143 :
144 0 : if (fClass==0) {
145 0 : Error("AliClusters", "class type not specified");
146 0 : return 0;
147 : }
148 0 : if(!fClusters) fClusters=new TClonesArray(fClass->GetName(),100);
149 0 : TClonesArray &lclusters = *fClusters;
150 0 : return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
151 0 : }
152 :
153 : Int_t AliClusters::Find(Double_t y) const
154 : {
155 : /// return index of cluster nearest to given y position
156 :
157 : AliComplexCluster* cl;
158 0 : cl=(AliComplexCluster*)fClusters->UncheckedAt(0);
159 0 : if (y <= cl->GetY()) return 0;
160 0 : cl=(AliComplexCluster*)fClusters->UncheckedAt(fNclusters-1);
161 0 : if (y > cl->GetY()) return fNclusters;
162 0 : Int_t b=0, e=fNclusters-1, m=(b+e)/2;
163 0 : for (; b<e; m=(b+e)/2) {
164 0 : cl = (AliComplexCluster*)fClusters->UncheckedAt(m);
165 0 : if (y > cl->GetY()) b=m+1;
166 : else e=m;
167 : }
168 : return m;
169 0 : }
170 :
171 :
172 : void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty,
173 : Int_t color, Int_t size, Int_t style)
174 : {
175 :
176 0 : if (fClusters==0) return;
177 : //draw marker for each of cluster
178 0 : Int_t ncl=fClusters->GetEntriesFast();
179 0 : for (Int_t i=0;i<ncl;i++){
180 0 : AliComplexCluster *cl = (AliComplexCluster*)fClusters->UncheckedAt(i);
181 0 : TMarker * marker = new TMarker;
182 0 : marker->SetX(cl->GetX()+shiftx);
183 0 : marker->SetY(cl->GetY()+shifty);
184 0 : marker->SetMarkerSize(size);
185 0 : marker->SetMarkerStyle(style);
186 0 : marker->SetMarkerColor(color);
187 0 : marker->Draw();
188 : }
189 0 : }
|