Update of tracking code for tilted pads
[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$
fd621f36 18Revision 1.14 2002/10/14 14:57:43 hristov
19Merging the VirtualMC branch to the main development branch (HEAD)
20
b9d0a01d 21Revision 1.11.6.2 2002/10/11 07:26:37 hristov
22Updating VirtualMC to v3-09-02
23
24Revision 1.13 2002/09/18 09:20:53 cblume
25Write the parameter class into the cluster file
26
fd621f36 27Revision 1.12 2002/06/12 09:54:35 cblume
28Update of tracking code provided by Sergei
29
5443e65e 30Revision 1.11 2001/11/27 08:50:33 hristov
31BranchOld replaced by Branch
32
365d0374 33Revision 1.10 2001/11/14 10:50:45 cblume
34Changes in digits IO. Add merging of summable digits
35
abaf1f1d 36Revision 1.9 2001/10/21 18:30:02 hristov
37Several pointers were set to zero in the default constructors to avoid memory management problems
38
2685bf00 39Revision 1.8 2001/05/07 08:06:44 cblume
40Speedup of the code. Create only AliTRDcluster
41
3e1a3ad8 42Revision 1.7 2001/03/30 14:40:14 cblume
43Update of the digitization parameter
44
a3c76cdc 45Revision 1.6 2000/11/01 14:53:20 cblume
46Merge with TRD-develop
47
793ff80c 48
49Revision 1.1.4.5 2000/10/15 23:40:01 cblume
50Remove AliTRDconst
51
52Revision 1.1.4.4 2000/10/06 16:49:46 cblume
53Made Getters const
54
55Revision 1.1.4.3 2000/10/04 16:34:58 cblume
56Replace include files by forward declarations
57
58Revision 1.1.4.2 2000/09/22 14:49:49 cblume
59Adapted to tracking code
60
61Revision 1.5 2000/10/02 21:28:19 fca
62Removal of useless dependecies via forward declarations
63
64Revision 1.4 2000/06/09 11:10:07 cblume
65Compiler warnings and coding conventions, next round
66
67Revision 1.3 2000/06/08 18:32:58 cblume
68Make code compliant to coding conventions
69
70Revision 1.2 2000/05/08 16:17:27 cblume
71Merge TRD-develop
72
73Revision 1.1.4.1 2000/05/08 15:08:03 cblume
74Remove the class AliTRDcluster
75
94de3818 76Revision 1.4 2000/06/09 11:10:07 cblume
77Compiler warnings and coding conventions, next round
78
dd9a6ee3 79Revision 1.3 2000/06/08 18:32:58 cblume
80Make code compliant to coding conventions
81
8230f242 82Revision 1.2 2000/05/08 16:17:27 cblume
83Merge TRD-develop
84
6f1e466d 85Revision 1.1.4.1 2000/05/08 15:08:03 cblume
86Remove the class AliTRDcluster
87
88Revision 1.1 2000/02/28 18:57:58 cblume
89Add new TRD classes
90
f7336fa3 91*/
92
93///////////////////////////////////////////////////////////////////////////////
94// //
95// TRD cluster finder base class //
96// //
97///////////////////////////////////////////////////////////////////////////////
98
94de3818 99#include <TROOT.h>
100#include <TTree.h>
793ff80c 101#include <TFile.h>
f7336fa3 102
94de3818 103#include "AliRun.h"
f7336fa3 104#include "AliTRD.h"
105#include "AliTRDclusterizer.h"
3e1a3ad8 106#include "AliTRDcluster.h"
793ff80c 107#include "AliTRDrecPoint.h"
108#include "AliTRDgeometry.h"
5443e65e 109#include "AliTRDparameter.h"
f7336fa3 110
111ClassImp(AliTRDclusterizer)
112
113//_____________________________________________________________________________
114AliTRDclusterizer::AliTRDclusterizer():TNamed()
115{
116 //
117 // AliTRDclusterizer default constructor
118 //
119
3e1a3ad8 120 fInputFile = NULL;
121 fOutputFile = NULL;
122 fClusterTree = NULL;
2685bf00 123 fTRD = 0;
3e1a3ad8 124 fEvent = 0;
125 fVerbose = 0;
5443e65e 126 fPar = 0;
f7336fa3 127
128}
129
130//_____________________________________________________________________________
131AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
132 :TNamed(name, title)
133{
134 //
135 // AliTRDclusterizer default constructor
136 //
137
3e1a3ad8 138 fInputFile = NULL;
139 fOutputFile = NULL;
140 fClusterTree = NULL;
141 fEvent = 0;
142 fVerbose = 0;
5443e65e 143 fPar = 0;
f7336fa3 144
145}
146
8230f242 147//_____________________________________________________________________________
dd9a6ee3 148AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
8230f242 149{
150 //
151 // AliTRDclusterizer copy constructor
152 //
153
dd9a6ee3 154 ((AliTRDclusterizer &) c).Copy(*this);
8230f242 155
156}
157
f7336fa3 158//_____________________________________________________________________________
159AliTRDclusterizer::~AliTRDclusterizer()
160{
8230f242 161 //
162 // AliTRDclusterizer destructor
163 //
f7336fa3 164
165 if (fInputFile) {
166 fInputFile->Close();
167 delete fInputFile;
168 }
169
3e1a3ad8 170 if (fOutputFile) {
171 fOutputFile->Close();
172 delete fOutputFile;
173 }
174
175 if (fClusterTree) {
176 delete fClusterTree;
177 }
178
f7336fa3 179}
180
8230f242 181//_____________________________________________________________________________
dd9a6ee3 182AliTRDclusterizer &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//_____________________________________________________________________________
194void AliTRDclusterizer::Copy(TObject &c)
8230f242 195{
196 //
197 // Copy function
198 //
199
3e1a3ad8 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;
5443e65e 205 ((AliTRDclusterizer &) c).fPar = 0;
8230f242 206
207}
208
f7336fa3 209//_____________________________________________________________________________
3e1a3ad8 210Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
f7336fa3 211{
212 //
3e1a3ad8 213 // Opens the AliROOT file. Output and input are in the same file
f7336fa3 214 //
215
3e1a3ad8 216 OpenInput(name,nEvent);
217 OpenOutput(name);
218
219 return kTRUE;
220
f7336fa3 221}
222
223//_____________________________________________________________________________
3e1a3ad8 224Bool_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//_____________________________________________________________________________
239Bool_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
abaf1f1d 257 Char_t treeName[12];
258 sprintf(treeName,"TreeR%d_TRD",fEvent);
259 fClusterTree = new TTree(treeName,"TRD cluster");
3e1a3ad8 260 TObjArray *ioArray = 0;
365d0374 261 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
3e1a3ad8 262
263 if (savedir) {
264 savedir->cd();
265 }
266
267 return kTRUE;
268
269}
270
271//_____________________________________________________________________________
272Bool_t AliTRDclusterizer::OpenInput(const Char_t *name, Int_t nEvent)
f7336fa3 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) {
3e1a3ad8 281 printf("AliTRDclusterizer::OpenInput -- ");
f7336fa3 282 printf("Open the ALIROOT-file %s.\n",name);
283 fInputFile = new TFile(name,"UPDATE");
284 }
285 else {
3e1a3ad8 286 printf("AliTRDclusterizer::OpenInput -- ");
f7336fa3 287 printf("%s is already open.\n",name);
288 }
289
3e1a3ad8 290 // Get AliRun object from file
291 gAlice = (AliRun *) fInputFile->Get("gAlice");
a3c76cdc 292 if (!(gAlice)) {
3e1a3ad8 293 printf("AliTRDclusterizer::OpenInput -- ");
294 printf("Could not find AliRun object.\n");
295 return kFALSE;
a3c76cdc 296 }
f7336fa3 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) {
3e1a3ad8 303 printf("AliTRDclusterizer::OpenInput -- ");
f7336fa3 304 printf("No entries in the trees for event %d.\n",fEvent);
305 return kFALSE;
306 }
307
3e1a3ad8 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 }
a3c76cdc 315
f7336fa3 316 return kTRUE;
317
318}
319
320//_____________________________________________________________________________
793ff80c 321Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
f7336fa3 322{
323 //
3e1a3ad8 324 // Fills TRDcluster branch in the tree with the clusters
793ff80c 325 // found in detector = det. For det=-1 writes the tree.
a3c76cdc 326 //
793ff80c 327
3e1a3ad8 328 if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
329 printf("AliTRDclusterizer::WriteClusters -- ");
330 printf("Unexpected detector index %d.\n",det);
331 return kFALSE;
793ff80c 332 }
3e1a3ad8 333
334 TDirectory *savedir = gDirectory;
f7336fa3 335
3e1a3ad8 336 if (fOutputFile) {
337 fOutputFile->cd();
338 }
f7336fa3 339
3e1a3ad8 340 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
341 if (!branch) {
793ff80c 342 TObjArray *ioArray = 0;
3e1a3ad8 343 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
793ff80c 344 }
345
346 if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
347
3e1a3ad8 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 }
793ff80c 360 }
361
3e1a3ad8 362 branch->SetAddress(&detRecPoints);
363 fClusterTree->Fill();
364
793ff80c 365 return kTRUE;
3e1a3ad8 366
793ff80c 367 }
368
369 if (det == -1) {
370
3e1a3ad8 371 printf("AliTRDclusterizer::WriteClusters -- ");
793ff80c 372 printf("Writing the cluster tree %-18s for event %d.\n"
3e1a3ad8 373 ,fClusterTree->GetName(),fEvent);
793ff80c 374
3e1a3ad8 375 fClusterTree->Write();
ba2e024c 376
377 AliTRDgeometry *geo = fTRD->GetGeometry();
378 geo->SetName("TRDgeometry");
379 geo->Write();
fd621f36 380 fPar->Write();
3e1a3ad8 381
793ff80c 382 return kTRUE;
3e1a3ad8 383
793ff80c 384 }
385
3e1a3ad8 386 savedir->cd();
387
388 printf("AliTRDclusterizer::WriteClusters -- ");
389 printf("Unexpected detector index %d.\n",det);
390
793ff80c 391 return kFALSE;
f7336fa3 392
393}
793ff80c 394
395
396