]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliClusters.cxx
Defining properly momentum components in AliMUONHit constructors (thanks Artur)
[u/mrichter/AliRoot.git] / TPC / AliClusters.cxx
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 /* $Id$ */
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>
30 #include "AliComplexCluster.h"
31 #include "AliClusters.h"
32 #include "TMarker.h"
33
34
35 const Int_t kDefSize = 1;  //defalut size
36
37
38 ClassImp(AliClusters) 
39
40 //*****************************************************************************
41 //
42 //_____________________________________________________________________________
43 AliClusters::AliClusters() 
44 {  
45   //
46   //default constructor
47   //
48   fNclusters=0;
49   fClusters =0;
50   fClass =0;
51 }
52
53 //________________________________________________________________________
54 AliClusters::~AliClusters()
55 {
56    //
57    //default destructor
58   //
59    if (fClusters !=0) fClusters->Clear();
60    delete fClusters;
61 }
62
63 //_________________________________________________________________________
64
65 Bool_t AliClusters::SetClass(const Text_t *classname)
66 {
67   //
68   //set class of stored object
69   if ( fClass !=0 ) {
70     //    delete fClass;
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    }
82    if (!fClass->InheritsFrom(TObject::Class())) {
83       Error("AliClusters", "%s does not inherit from TObject", classname);
84       return kFALSE; 
85    } 
86    return kTRUE;
87 }
88
89 //_____________________________________________________________________________
90 void 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 //_____________________________________________________________________________
106 const  TObject* AliClusters::operator[](Int_t i)
107 {
108   //
109   // return cluster at internal position i
110   //
111   if (fClusters==0) return 0;
112   return fClusters->UncheckedAt(i);
113 }
114 //_____________________________________________________________________________
115 void  AliClusters::Sort()
116 {
117   // sort cluster 
118   if (fClusters!=0) fClusters->Sort();
119 }
120
121 //_____________________________________________________________________________
122 TObject * AliClusters::InsertCluster( const TObject * c) 
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;
133   return new(lclusters[fNclusters++]) AliComplexCluster(*((AliComplexCluster*)c));
134 }
135
136 //_____________________________________________________________________________
137 Int_t AliClusters::Find(Double_t y) const 
138 {
139   //
140   // return index of cluster nearest to given y position
141   //
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;
151     else e=m; 
152   }
153   return m;
154 }
155
156
157 //_____________________________________________________________________________
158
159 void AliClusters::DrawClusters(Float_t shiftx, Float_t shifty, 
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++){
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);
174     marker->Draw();    
175   }
176 }
177