]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Several pointers were set to zero in the default constructors to avoid memory managem...
[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.8  2001/05/07 08:06:44  cblume
19 Speedup of the code. Create only AliTRDcluster
20
21 Revision 1.7  2001/03/30 14:40:14  cblume
22 Update of the digitization parameter
23
24 Revision 1.6  2000/11/01 14:53:20  cblume
25 Merge with TRD-develop
26
27
28 Revision 1.1.4.5  2000/10/15 23:40:01  cblume
29 Remove AliTRDconst
30
31 Revision 1.1.4.4  2000/10/06 16:49:46  cblume
32 Made Getters const
33
34 Revision 1.1.4.3  2000/10/04 16:34:58  cblume
35 Replace include files by forward declarations
36
37 Revision 1.1.4.2  2000/09/22 14:49:49  cblume
38 Adapted to tracking code
39
40 Revision 1.5  2000/10/02 21:28:19  fca
41 Removal of useless dependecies via forward declarations
42
43 Revision 1.4  2000/06/09 11:10:07  cblume
44 Compiler warnings and coding conventions, next round
45
46 Revision 1.3  2000/06/08 18:32:58  cblume
47 Make code compliant to coding conventions
48
49 Revision 1.2  2000/05/08 16:17:27  cblume
50 Merge TRD-develop
51
52 Revision 1.1.4.1  2000/05/08 15:08:03  cblume
53 Remove the class AliTRDcluster
54
55 Revision 1.4  2000/06/09 11:10:07  cblume
56 Compiler warnings and coding conventions, next round
57
58 Revision 1.3  2000/06/08 18:32:58  cblume
59 Make code compliant to coding conventions
60
61 Revision 1.2  2000/05/08 16:17:27  cblume
62 Merge TRD-develop
63
64 Revision 1.1.4.1  2000/05/08 15:08:03  cblume
65 Remove the class AliTRDcluster
66
67 Revision 1.1  2000/02/28 18:57:58  cblume
68 Add new TRD classes
69
70 */
71
72 ///////////////////////////////////////////////////////////////////////////////
73 //                                                                           //
74 //  TRD cluster finder base class                                            //
75 //                                                                           //
76 ///////////////////////////////////////////////////////////////////////////////
77
78 #include <TROOT.h>
79 #include <TTree.h>
80 #include <TFile.h>
81
82 #include "AliRun.h"
83 #include "AliTRD.h"
84 #include "AliTRDclusterizer.h"
85 #include "AliTRDcluster.h"
86 #include "AliTRDrecPoint.h"
87 #include "AliTRDgeometry.h"
88
89 ClassImp(AliTRDclusterizer)
90
91 //_____________________________________________________________________________
92 AliTRDclusterizer::AliTRDclusterizer():TNamed()
93 {
94   //
95   // AliTRDclusterizer default constructor
96   //
97
98   fInputFile   = NULL;
99   fOutputFile  = NULL;
100   fClusterTree = NULL;
101   fTRD         = 0;
102   fEvent       = 0;
103   fVerbose     = 0;
104
105 }
106
107 //_____________________________________________________________________________
108 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
109                   :TNamed(name, title)
110 {
111   //
112   // AliTRDclusterizer default constructor
113   //
114
115   fInputFile   = NULL;
116   fOutputFile  = NULL;
117   fClusterTree = NULL;
118   fEvent       = 0;
119   fVerbose     = 0;
120
121 }
122
123 //_____________________________________________________________________________
124 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
125 {
126   //
127   // AliTRDclusterizer copy constructor
128   //
129
130   ((AliTRDclusterizer &) c).Copy(*this);
131
132 }
133
134 //_____________________________________________________________________________
135 AliTRDclusterizer::~AliTRDclusterizer()
136 {
137   //
138   // AliTRDclusterizer destructor
139   //
140
141   if (fInputFile) {
142     fInputFile->Close();
143     delete fInputFile;
144   }
145
146   if (fOutputFile) {
147     fOutputFile->Close();
148     delete fOutputFile;
149   }
150
151   if (fClusterTree) {
152     delete fClusterTree;
153   }
154
155 }
156
157 //_____________________________________________________________________________
158 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
159 {
160   //
161   // Assignment operator
162   //
163
164   if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
165   return *this;
166
167 }
168
169 //_____________________________________________________________________________
170 void AliTRDclusterizer::Copy(TObject &c)
171 {
172   //
173   // Copy function
174   //
175
176   ((AliTRDclusterizer &) c).fInputFile   = NULL;
177   ((AliTRDclusterizer &) c).fOutputFile  = NULL;
178   ((AliTRDclusterizer &) c).fClusterTree = NULL;
179   ((AliTRDclusterizer &) c).fEvent       = 0;  
180   ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
181
182 }
183
184 //_____________________________________________________________________________
185 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
186 {
187   //
188   // Opens the AliROOT file. Output and input are in the same file
189   //
190
191   OpenInput(name,nEvent);
192   OpenOutput(name);
193
194   return kTRUE;
195
196 }
197
198 //_____________________________________________________________________________
199 Bool_t AliTRDclusterizer::Open(const Char_t *inname, const Char_t *outname
200                               , Int_t nEvent)
201 {
202   //
203   // Opens the AliROOT file. Output and input are in different files
204   //
205
206   OpenInput(inname,nEvent);
207   OpenOutput(outname);
208
209   return kTRUE;
210
211 }
212
213 //_____________________________________________________________________________
214 Bool_t AliTRDclusterizer::OpenOutput(const Char_t *name)
215 {
216   //
217   // Open the output file
218   //
219
220   TDirectory *savedir = NULL;
221
222   if (!fInputFile) return kFALSE;
223
224   if (strcmp(name,fInputFile->GetName()) != 0) {
225     savedir = gDirectory;
226     printf("AliTRDclusterizer::OpenOutput -- ");
227     printf("Open the output file %s.\n",name);
228     fOutputFile = new TFile(name,"RECREATE");
229   }
230
231   // Create a tree for the cluster
232   fClusterTree = new TTree("ClusterTree","Tree with TRDcluster");
233   TObjArray *ioArray = 0;
234   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
235
236   if (savedir) {
237     savedir->cd();
238   }
239
240   return kTRUE;
241
242 }
243
244 //_____________________________________________________________________________
245 Bool_t AliTRDclusterizer::OpenInput(const Char_t *name, Int_t nEvent)
246 {
247   //
248   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
249   //
250
251   // Connect the AliRoot file containing Geometry, Kine, and Hits
252   fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
253   if (!fInputFile) {
254     printf("AliTRDclusterizer::OpenInput -- ");
255     printf("Open the ALIROOT-file %s.\n",name);
256     fInputFile = new TFile(name,"UPDATE");
257   }
258   else {
259     printf("AliTRDclusterizer::OpenInput -- ");
260     printf("%s is already open.\n",name);
261   }
262
263   // Get AliRun object from file
264   gAlice = (AliRun *) fInputFile->Get("gAlice");
265   if (!(gAlice)) {
266     printf("AliTRDclusterizer::OpenInput -- ");
267     printf("Could not find AliRun object.\n");
268     return kFALSE;
269   }
270
271   fEvent = nEvent;
272
273   // Import the Trees for the event nEvent in the file
274   Int_t nparticles = gAlice->GetEvent(fEvent);
275   if (nparticles <= 0) {
276     printf("AliTRDclusterizer::OpenInput -- ");
277     printf("No entries in the trees for event %d.\n",fEvent);
278     return kFALSE;
279   }
280
281   // Get the TRD object
282   fTRD = (AliTRD*) gAlice->GetDetector("TRD"); 
283   if (!fTRD) {
284     printf("AliTRDclusterizer::OpenInput -- ");
285     printf("No TRD detector object found\n");
286     return kFALSE;
287   }
288
289   return kTRUE;
290
291 }
292
293 //_____________________________________________________________________________
294 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
295 {
296   //
297   // Fills TRDcluster branch in the tree with the clusters 
298   // found in detector = det. For det=-1 writes the tree. 
299   //
300
301   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
302     printf("AliTRDclusterizer::WriteClusters -- ");
303     printf("Unexpected detector index %d.\n",det);
304     return kFALSE;
305   }
306  
307   TDirectory *savedir = gDirectory;
308
309   if (fOutputFile) {
310     fOutputFile->cd();
311   }
312
313   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
314   if (!branch) {
315     TObjArray *ioArray = 0;
316     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
317   }
318
319   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
320
321     Int_t nRecPoints = fTRD->RecPoints()->GetEntriesFast();
322     TObjArray *detRecPoints = new TObjArray(400);
323
324     for (Int_t i = 0; i < nRecPoints; i++) {
325       AliTRDcluster *c = (AliTRDcluster *) fTRD->RecPoints()->UncheckedAt(i);
326       if (det == c->GetDetector()) {
327         detRecPoints->AddLast(c);
328       }
329       else {
330         printf("AliTRDclusterizer::WriteClusters --");
331         printf("Attempt to write a cluster with unexpected detector index\n");
332       }
333     }
334
335     branch->SetAddress(&detRecPoints);
336     fClusterTree->Fill();
337
338     return kTRUE;
339
340   }
341
342   if (det == -1) {
343
344     printf("AliTRDclusterizer::WriteClusters -- ");
345     printf("Writing the cluster tree %-18s for event %d.\n"
346           ,fClusterTree->GetName(),fEvent);
347
348     fClusterTree->Write();
349      
350     return kTRUE;  
351
352   }
353   
354   savedir->cd();
355
356   printf("AliTRDclusterizer::WriteClusters -- ");
357   printf("Unexpected detector index %d.\n",det);
358  
359   return kFALSE;  
360
361 }
362
363
364