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