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