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