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