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