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