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