]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TRD/AliTRDclusterizer.cxx
Try to fix Delete problem in trigger code
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
... / ...
CommitLineData
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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// TRD cluster finder base class //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24#include <TROOT.h>
25#include <TTree.h>
26#include <TFile.h>
27#include <TObjArray.h>
28
29#include "AliRun.h"
30#include "AliRunLoader.h"
31#include "AliLoader.h"
32#include "AliLog.h"
33
34#include "AliTRDclusterizer.h"
35#include "AliTRDcluster.h"
36#include "AliTRDrecPoint.h"
37#include "AliTRDgeometry.h"
38#include "AliTRDcalibDB.h"
39
40ClassImp(AliTRDclusterizer)
41
42//_____________________________________________________________________________
43AliTRDclusterizer::AliTRDclusterizer()
44 :TNamed()
45 ,fRunLoader(NULL)
46 ,fClusterTree(NULL)
47 ,fRecPoints(NULL)
48{
49 //
50 // AliTRDclusterizer default constructor
51 //
52
53}
54
55//_____________________________________________________________________________
56AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
57 :TNamed(name,title)
58 ,fRunLoader(NULL)
59 ,fClusterTree(NULL)
60 ,fRecPoints(NULL)
61{
62 //
63 // AliTRDclusterizer constructor
64 //
65
66}
67
68//_____________________________________________________________________________
69AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
70 :TNamed(c)
71 ,fRunLoader(NULL)
72 ,fClusterTree(NULL)
73 ,fRecPoints(NULL)
74{
75 //
76 // AliTRDclusterizer copy constructor
77 //
78
79}
80
81//_____________________________________________________________________________
82AliTRDclusterizer::~AliTRDclusterizer()
83{
84 //
85 // AliTRDclusterizer destructor
86 //
87
88 if (fRecPoints) {
89 fRecPoints->Delete();
90 delete fRecPoints;
91 }
92
93}
94
95//_____________________________________________________________________________
96AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
97{
98 //
99 // Assignment operator
100 //
101
102 if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
103 return *this;
104
105}
106
107//_____________________________________________________________________________
108void AliTRDclusterizer::Copy(TObject &c) const
109{
110 //
111 // Copy function
112 //
113
114 ((AliTRDclusterizer &) c).fClusterTree = NULL;
115 ((AliTRDclusterizer &) c).fRecPoints = NULL;
116
117}
118
119//_____________________________________________________________________________
120Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
121{
122 //
123 // Opens the AliROOT file. Output and input are in the same file
124 //
125
126 TString evfoldname = AliConfig::GetDefaultEventFolderName();
127 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
128
129 if (!fRunLoader) {
130 fRunLoader = AliRunLoader::Open(name);
131 }
132
133 if (!fRunLoader) {
134 AliError(Form("Can not open session for file %s.",name));
135 return kFALSE;
136 }
137
138 OpenInput(nEvent);
139 OpenOutput();
140
141 return kTRUE;
142
143}
144
145//_____________________________________________________________________________
146Bool_t AliTRDclusterizer::OpenOutput()
147{
148 //
149 // Open the output file
150 //
151
152 TObjArray *ioArray = 0;
153
154 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
155 loader->MakeTree("R");
156
157 fClusterTree = loader->TreeR();
158 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
159
160 return kTRUE;
161
162}
163
164//_____________________________________________________________________________
165Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
166{
167 //
168 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
169 //
170
171 // Connect the AliRoot file containing Geometry, Kine, and Hits
172 if (fRunLoader->GetAliRun() == 0x0) {
173 fRunLoader->LoadgAlice();
174 }
175 gAlice = fRunLoader->GetAliRun();
176
177 if (!(gAlice)) {
178 fRunLoader->LoadgAlice();
179 gAlice = fRunLoader->GetAliRun();
180 if (!(gAlice)) {
181 AliError("Could not find AliRun object.\n");
182 return kFALSE;
183 }
184 }
185
186 // Import the Trees for the event nEvent in the file
187 fRunLoader->GetEvent(nEvent);
188
189 return kTRUE;
190
191}
192
193//_____________________________________________________________________________
194Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
195{
196 //
197 // Fills TRDcluster branch in the tree with the clusters
198 // found in detector = det. For det=-1 writes the tree.
199 //
200
201 if ((det < -1) ||
202 (det >= AliTRDgeometry::Ndet())) {
203 AliError(Form("Unexpected detector index %d.\n",det));
204 return kFALSE;
205 }
206
207 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
208 if (!branch) {
209 TObjArray *ioArray = 0;
210 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
211 }
212
213 if ((det >= 0) &&
214 (det < AliTRDgeometry::Ndet())) {
215
216 Int_t nRecPoints = RecPoints()->GetEntriesFast();
217 TObjArray *detRecPoints = new TObjArray(400);
218
219 for (Int_t i = 0; i < nRecPoints; i++) {
220 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
221 if (det == c->GetDetector()) {
222 detRecPoints->AddLast(c);
223 }
224 else {
225 AliError("Attempt to write a cluster with unexpected detector index\n");
226 }
227 }
228
229 branch->SetAddress(&detRecPoints);
230 fClusterTree->Fill();
231
232 delete detRecPoints;
233
234 return kTRUE;
235
236 }
237
238 if (det == -1) {
239
240 AliInfo(Form("Writing the cluster tree %s for event %d."
241 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
242
243 if (fRecPoints) {
244
245 branch->SetAddress(&fRecPoints);
246
247 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
248 loader->WriteRecPoints("OVERWRITE");
249
250 }
251 else {
252
253 AliError("Cluster tree does not exist. Cannot write clusters.\n");
254 return kFALSE;
255
256 }
257
258 return kTRUE;
259
260 }
261
262 AliError(Form("Unexpected detector index %d.\n",det));
263
264 return kFALSE;
265
266}
267
268
269//_____________________________________________________________________________
270AliTRDcluster* AliTRDclusterizer::AddCluster(Double_t *pos, Int_t timebin
271 , Int_t det, Double_t amp
272 , Int_t *tracks, Double_t *sig
273 , Int_t iType, Float_t center)
274{
275 //
276 // Add a cluster for the TRD
277 //
278
279 AliTRDcluster *c = new AliTRDcluster();
280
281 c->SetDetector(det);
282 c->SetQ(amp);
283 c->SetX(pos[2]);
284 c->SetY(pos[0]);
285 c->SetZ(pos[1]);
286 c->SetSigmaY2(sig[0]);
287 c->SetSigmaZ2(sig[1]);
288 c->SetLocalTimeBin(timebin);
289 c->SetCenter(center);
290
291 if (tracks) {
292 c->AddTrackIndex(tracks);
293 }
294
295 switch (iType) {
296 case 0:
297 c->Set2pad();
298 break;
299 case 1:
300 c->Set3pad();
301 break;
302 case 2:
303 c->Set4pad();
304 break;
305 case 3:
306 c->Set5pad();
307 break;
308 case 4:
309 c->SetLarge();
310 break;
311 };
312
313 RecPoints()->Add(c);
314 return c;
315
316}
317
318//_____________________________________________________________________________
319Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
320 , Int_t col, Int_t row)
321{
322 //
323 // Calculates the local x position in the detector from the timebin,
324 // depends on the drift velocity and t0
325 //
326
327 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
328 if (!calibration) {
329 AliError("Cannot find calibration object");
330 return -1;
331 }
332
333 Float_t vdrift = calibration->GetVdrift(idet,col,row);
334 Float_t t0 = calibration->GetT0(idet,col,row);
335 Float_t samplingFrequency = calibration->GetSamplingFrequency();
336
337 timebin -= t0;
338
339 return timebin / samplingFrequency * vdrift;
340
341}
342
343//_____________________________________________________________________________
344void AliTRDclusterizer::ResetRecPoints()
345{
346 //
347 // Resets the list of rec points
348 //
349
350 if (fRecPoints) {
351 fRecPoints->Delete();
352 }
353
354}
355
356//_____________________________________________________________________________
357TObjArray* AliTRDclusterizer::RecPoints()
358{
359 //
360 // Returns the list of rec points
361 //
362
363 if (!fRecPoints) {
364 fRecPoints = new TObjArray(400);
365 }
366
367 return fRecPoints;
368
369}