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