]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizer.cxx
Update of clusterizer
[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
88cb7938 16/* $Id$ */
f7336fa3 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// TRD cluster finder base class //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
94de3818 24#include <TROOT.h>
25#include <TTree.h>
793ff80c 26#include <TFile.h>
6d50f529 27#include <TObjArray.h>
f7336fa3 28
94de3818 29#include "AliRun.h"
88cb7938 30#include "AliRunLoader.h"
31#include "AliLoader.h"
6d50f529 32#include "AliLog.h"
88cb7938 33
f7336fa3 34#include "AliTRDclusterizer.h"
3e1a3ad8 35#include "AliTRDcluster.h"
793ff80c 36#include "AliTRDrecPoint.h"
37#include "AliTRDgeometry.h"
3551db50 38#include "AliTRDcalibDB.h"
f7336fa3 39
40ClassImp(AliTRDclusterizer)
41
42//_____________________________________________________________________________
6d50f529 43AliTRDclusterizer::AliTRDclusterizer()
44 :TNamed()
45 ,fRunLoader(NULL)
46 ,fClusterTree(NULL)
47 ,fRecPoints(NULL)
f7336fa3 48{
49 //
50 // AliTRDclusterizer default constructor
51 //
52
f7336fa3 53}
54
55//_____________________________________________________________________________
56AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
6d50f529 57 :TNamed(name,title)
58 ,fRunLoader(NULL)
59 ,fClusterTree(NULL)
60 ,fRecPoints(NULL)
f7336fa3 61{
62 //
6d50f529 63 // AliTRDclusterizer constructor
f7336fa3 64 //
65
f7336fa3 66}
67
8230f242 68//_____________________________________________________________________________
6d50f529 69AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
70 :TNamed(c)
71 ,fRunLoader(NULL)
72 ,fClusterTree(NULL)
73 ,fRecPoints(NULL)
8230f242 74{
75 //
76 // AliTRDclusterizer copy constructor
77 //
78
8230f242 79}
80
f7336fa3 81//_____________________________________________________________________________
82AliTRDclusterizer::~AliTRDclusterizer()
83{
8230f242 84 //
85 // AliTRDclusterizer destructor
86 //
f7336fa3 87
bdbb05bb 88 if (fRecPoints) {
89 fRecPoints->Delete();
90 delete fRecPoints;
91 }
6d50f529 92
f7336fa3 93}
94
8230f242 95//_____________________________________________________________________________
dd9a6ee3 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//_____________________________________________________________________________
e0d47c25 108void AliTRDclusterizer::Copy(TObject &c) const
8230f242 109{
110 //
111 // Copy function
112 //
113
3e1a3ad8 114 ((AliTRDclusterizer &) c).fClusterTree = NULL;
bdbb05bb 115 ((AliTRDclusterizer &) c).fRecPoints = NULL;
8230f242 116
117}
118
f7336fa3 119//_____________________________________________________________________________
3e1a3ad8 120Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
f7336fa3 121{
122 //
3e1a3ad8 123 // Opens the AliROOT file. Output and input are in the same file
f7336fa3 124 //
6d50f529 125
e191bb57 126 TString evfoldname = AliConfig::GetDefaultEventFolderName();
6d50f529 127 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
128
129 if (!fRunLoader) {
19dd5b2f 130 fRunLoader = AliRunLoader::Open(name);
6d50f529 131 }
132
133 if (!fRunLoader) {
134 AliError(Form("Can not open session for file %s.",name));
135 return kFALSE;
136 }
88cb7938 137
138 OpenInput(nEvent);
139 OpenOutput();
6d50f529 140
3e1a3ad8 141 return kTRUE;
f7336fa3 142
6d50f529 143}
3e1a3ad8 144
145//_____________________________________________________________________________
88cb7938 146Bool_t AliTRDclusterizer::OpenOutput()
3e1a3ad8 147{
148 //
149 // Open the output file
150 //
151
3e1a3ad8 152 TObjArray *ioArray = 0;
88cb7938 153
154 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
155 loader->MakeTree("R");
6d50f529 156
88cb7938 157 fClusterTree = loader->TreeR();
365d0374 158 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
3e1a3ad8 159
3e1a3ad8 160 return kTRUE;
161
162}
163
164//_____________________________________________________________________________
88cb7938 165Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
f7336fa3 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
6d50f529 172 if (fRunLoader->GetAliRun() == 0x0) {
173 fRunLoader->LoadgAlice();
174 }
88cb7938 175 gAlice = fRunLoader->GetAliRun();
f7336fa3 176
a3c76cdc 177 if (!(gAlice)) {
88cb7938 178 fRunLoader->LoadgAlice();
179 gAlice = fRunLoader->GetAliRun();
6d50f529 180 if (!(gAlice)) {
181 AliError("Could not find AliRun object.\n");
182 return kFALSE;
183 }
a3c76cdc 184 }
f7336fa3 185
f7336fa3 186 // Import the Trees for the event nEvent in the file
bdbb05bb 187 fRunLoader->GetEvent(nEvent);
88cb7938 188
f7336fa3 189 return kTRUE;
190
191}
192
193//_____________________________________________________________________________
793ff80c 194Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
f7336fa3 195{
196 //
3e1a3ad8 197 // Fills TRDcluster branch in the tree with the clusters
793ff80c 198 // found in detector = det. For det=-1 writes the tree.
a3c76cdc 199 //
793ff80c 200
6d50f529 201 if ((det < -1) ||
202 (det >= AliTRDgeometry::Ndet())) {
203 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 204 return kFALSE;
793ff80c 205 }
3e1a3ad8 206
3e1a3ad8 207 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
208 if (!branch) {
793ff80c 209 TObjArray *ioArray = 0;
3e1a3ad8 210 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
793ff80c 211 }
212
6d50f529 213 if ((det >= 0) &&
214 (det < AliTRDgeometry::Ndet())) {
793ff80c 215
bdbb05bb 216 Int_t nRecPoints = RecPoints()->GetEntriesFast();
3e1a3ad8 217 TObjArray *detRecPoints = new TObjArray(400);
218
219 for (Int_t i = 0; i < nRecPoints; i++) {
bdbb05bb 220 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
3e1a3ad8 221 if (det == c->GetDetector()) {
222 detRecPoints->AddLast(c);
223 }
224 else {
6d50f529 225 AliError("Attempt to write a cluster with unexpected detector index\n");
3e1a3ad8 226 }
793ff80c 227 }
228
3e1a3ad8 229 branch->SetAddress(&detRecPoints);
230 fClusterTree->Fill();
231
d9b8978b 232 delete detRecPoints;
233
793ff80c 234 return kTRUE;
3e1a3ad8 235
793ff80c 236 }
237
238 if (det == -1) {
239
6d50f529 240 AliInfo(Form("Writing the cluster tree %s for event %d."
241 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
242
a6dd11e9 243 if (fRecPoints) {
244
245 branch->SetAddress(&fRecPoints);
246
247 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
248 loader->WriteRecPoints("OVERWRITE");
c630aafd 249
a6dd11e9 250 }
251 else {
252
253 AliError("Cluster tree does not exist. Cannot write clusters.\n");
254 return kFALSE;
255
256 }
257
793ff80c 258 return kTRUE;
3e1a3ad8 259
793ff80c 260 }
6d50f529 261
262 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 263
793ff80c 264 return kFALSE;
88cb7938 265
f7336fa3 266}
793ff80c 267
268
bdbb05bb 269//_____________________________________________________________________________
6d50f529 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)
bdbb05bb 274{
275 //
276 // Add a cluster for the TRD
277 //
793ff80c 278
bdbb05bb 279 AliTRDcluster *c = new AliTRDcluster();
280
281 c->SetDetector(det);
bdbb05bb 282 c->SetQ(amp);
3551db50 283 c->SetX(pos[2]);
bdbb05bb 284 c->SetY(pos[0]);
285 c->SetZ(pos[1]);
286 c->SetSigmaY2(sig[0]);
287 c->SetSigmaZ2(sig[1]);
3551db50 288 c->SetLocalTimeBin(timebin);
828b670e 289 c->SetCenter(center);
6d50f529 290
a6dd11e9 291 if (tracks) {
292 c->AddTrackIndex(tracks);
293 }
294
bdbb05bb 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);
c85a4951 314 return c;
6d50f529 315
bdbb05bb 316}
3551db50 317
318//_____________________________________________________________________________
6d50f529 319Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
320 , Int_t col, Int_t row)
3551db50 321{
322 //
6d50f529 323 // Calculates the local x position in the detector from the timebin,
324 // depends on the drift velocity and t0
3551db50 325 //
326
6d50f529 327 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
328 if (!calibration) {
a6dd11e9 329 AliError("Cannot find calibration object");
3551db50 330 return -1;
6d50f529 331 }
88719a08 332
6d50f529 333 Float_t vdrift = calibration->GetVdrift(idet,col,row);
334 Float_t t0 = calibration->GetT0(idet,col,row);
3551db50 335 Float_t samplingFrequency = calibration->GetSamplingFrequency();
88719a08 336
337 timebin -= t0;
338
339 return timebin / samplingFrequency * vdrift;
6d50f529 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
3551db50 369}