]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Major upgrades to the strip structure
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.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 /*
17 $Log$
18 Revision 1.6  2000/11/01 14:53:20  cblume
19 Merge with TRD-develop
20
21
22 Revision 1.1.4.5  2000/10/15 23:40:01  cblume
23 Remove AliTRDconst
24
25 Revision 1.1.4.4  2000/10/06 16:49:46  cblume
26 Made Getters const
27
28 Revision 1.1.4.3  2000/10/04 16:34:58  cblume
29 Replace include files by forward declarations
30
31 Revision 1.1.4.2  2000/09/22 14:49:49  cblume
32 Adapted to tracking code
33
34 Revision 1.5  2000/10/02 21:28:19  fca
35 Removal of useless dependecies via forward declarations
36
37 Revision 1.4  2000/06/09 11:10:07  cblume
38 Compiler warnings and coding conventions, next round
39
40 Revision 1.3  2000/06/08 18:32:58  cblume
41 Make code compliant to coding conventions
42
43 Revision 1.2  2000/05/08 16:17:27  cblume
44 Merge TRD-develop
45
46 Revision 1.1.4.1  2000/05/08 15:08:03  cblume
47 Remove the class AliTRDcluster
48
49 Revision 1.4  2000/06/09 11:10:07  cblume
50 Compiler warnings and coding conventions, next round
51
52 Revision 1.3  2000/06/08 18:32:58  cblume
53 Make code compliant to coding conventions
54
55 Revision 1.2  2000/05/08 16:17:27  cblume
56 Merge TRD-develop
57
58 Revision 1.1.4.1  2000/05/08 15:08:03  cblume
59 Remove the class AliTRDcluster
60
61 Revision 1.1  2000/02/28 18:57:58  cblume
62 Add new TRD classes
63
64 */
65
66 ///////////////////////////////////////////////////////////////////////////////
67 //                                                                           //
68 //  TRD cluster finder base class                                            //
69 //                                                                           //
70 ///////////////////////////////////////////////////////////////////////////////
71
72 #include <TROOT.h>
73 #include <TTree.h>
74 #include <TFile.h>
75
76 #include "AliRun.h"
77 #include "AliTRD.h"
78 #include "AliTRDclusterizer.h"
79 #include "AliTRDrecPoint.h"
80 #include "AliTRDgeometry.h"
81
82 ClassImp(AliTRDclusterizer)
83
84 //_____________________________________________________________________________
85 AliTRDclusterizer::AliTRDclusterizer():TNamed()
86 {
87   //
88   // AliTRDclusterizer default constructor
89   //
90
91   fInputFile = NULL;
92   fEvent     = 0;
93
94 }
95
96 //_____________________________________________________________________________
97 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
98                   :TNamed(name, title)
99 {
100   //
101   // AliTRDclusterizer default constructor
102   //
103
104   fInputFile = NULL;
105   fEvent     = 0;
106
107   Init();
108
109 }
110
111 //_____________________________________________________________________________
112 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
113 {
114   //
115   // AliTRDclusterizer copy constructor
116   //
117
118   ((AliTRDclusterizer &) c).Copy(*this);
119
120 }
121
122 //_____________________________________________________________________________
123 AliTRDclusterizer::~AliTRDclusterizer()
124 {
125   //
126   // AliTRDclusterizer destructor
127   //
128
129   if (fInputFile) {
130     fInputFile->Close();
131     delete fInputFile;
132   }
133
134 }
135
136 //_____________________________________________________________________________
137 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
138 {
139   //
140   // Assignment operator
141   //
142
143   if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
144   return *this;
145
146 }
147
148 //_____________________________________________________________________________
149 void AliTRDclusterizer::Copy(TObject &c)
150 {
151   //
152   // Copy function
153   //
154
155   ((AliTRDclusterizer &) c).fInputFile = NULL;
156   ((AliTRDclusterizer &) c).fEvent     = 0;  
157
158 }
159
160 //_____________________________________________________________________________
161 void AliTRDclusterizer::Init()
162 {
163   //
164   // Initializes the cluster finder
165   //
166
167 }
168
169 //_____________________________________________________________________________
170 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
171 {
172   //
173   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
174   //
175
176   // Connect the AliRoot file containing Geometry, Kine, and Hits
177   fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
178   if (!fInputFile) {
179     printf("AliTRDclusterizer::Open -- ");
180     printf("Open the ALIROOT-file %s.\n",name);
181     fInputFile = new TFile(name,"UPDATE");
182   }
183   else {
184     printf("AliTRDclusterizer::Open -- ");
185     printf("%s is already open.\n",name);
186   }
187
188   // Get AliRun object from file or create it if not on file
189   if (!(gAlice)) {
190     gAlice = (AliRun *) fInputFile->Get("gAlice");
191     if (!(gAlice)) {
192       printf("AliTRDclusterizer::Open -- ");
193       printf("Could not find AliRun object.\n");
194       return kFALSE;
195     }
196   }
197
198   fEvent = nEvent;
199
200   // Import the Trees for the event nEvent in the file
201   Int_t nparticles = gAlice->GetEvent(fEvent);
202   if (nparticles <= 0) {
203     printf("AliTRDclusterizer::Open -- ");
204     printf("No entries in the trees for event %d.\n",fEvent);
205     return kFALSE;
206   }
207
208   // Create a tree for the reconstructed points
209   TTree *recPointTree = new TTree("ClusterTree","Tree with clusters and rec. points");
210   TObjArray *ioArray = 0;
211   recPointTree->Branch("TRDrecPoints","TObjArray",&ioArray,32000,0);
212 //   TObjArray *iopointer = 0;
213 //   recPointTree->Branch("Clusters","TObjArray",&iopointer,32000,0);
214
215   return kTRUE;
216
217 }
218
219 //_____________________________________________________________________________
220 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
221 {
222   //
223   // Fills TRDrecPoints branch in TRDrecPoints## tree with rec. points 
224   // found in detector = det. For det=-1 writes the tree. 
225   // For det=-2 recreates the tree.
226   //
227
228   Char_t treeName[14];
229   sprintf(treeName,"TRDrecPoints%d", fEvent);
230
231   if (det == -2) {
232     fInputFile->Delete(treeName);
233     TTree *tree = new TTree(treeName,"Tree with TRD rec. points");
234     tree->Write();
235     return kTRUE;
236   }
237
238   //TTree *tree = (TTree *) fInputFile->Get(treeName);
239   TTree *tree = (TTree *) fInputFile->Get("ClusterTree");
240   TBranch *branch = tree->GetBranch("TRDrecPoints");
241
242   if(!branch) {
243     TObjArray *ioArray = 0;
244     branch = tree->Branch("TRDrecPoints","TObjArray",&ioArray,32000,0);
245   }
246
247   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
248
249     AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
250     Int_t nRecPoints = TRD->RecPoints()->GetEntriesFast();
251     TObjArray *fDetRecPoints = new TObjArray(400);
252
253     for (Int_t i=0; i<nRecPoints; i++) {
254       AliTRDrecPoint *p=(AliTRDrecPoint*)TRD->RecPoints()->UncheckedAt(i);
255       if(det == p->GetDetector()) fDetRecPoints->AddLast(p);
256       else printf("attempt to write a RecPoint with unexpected detector index");
257     }
258
259     branch->SetAddress(&fDetRecPoints);
260     tree->Fill();
261     return kTRUE;
262   }
263
264   if (det == -1) {
265
266     printf("\rAliTRDclusterizer::WriteClusters -- ");
267     printf("Writing the cluster tree %-18s for event %d.\n"
268            ,tree->GetName(),fEvent);
269
270     tree->Write();     
271     return kTRUE;  
272   }
273   
274   printf("\rAliTRDclusterizer::WriteClusters -- ");
275   printf("Unexpected detector index %d.\n", det); 
276   return kFALSE;  
277
278 }
279
280
281