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