]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizer.cxx
Add Raw2SDigits by Andreas
[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
88cb7938 29#include "AliRunLoader.h"
30#include "AliLoader.h"
6d50f529 31#include "AliLog.h"
88cb7938 32
f7336fa3 33#include "AliTRDclusterizer.h"
3e1a3ad8 34#include "AliTRDcluster.h"
793ff80c 35#include "AliTRDrecPoint.h"
36#include "AliTRDgeometry.h"
3551db50 37#include "AliTRDcalibDB.h"
b43a3e17 38#include "AliTRDCommonParam.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
b43a3e17 102 if (this != &c) {
103 ((AliTRDclusterizer &) c).Copy(*this);
104 }
dd9a6ee3 105 return *this;
106
107}
108
109//_____________________________________________________________________________
e0d47c25 110void AliTRDclusterizer::Copy(TObject &c) const
8230f242 111{
112 //
113 // Copy function
114 //
115
3e1a3ad8 116 ((AliTRDclusterizer &) c).fClusterTree = NULL;
bdbb05bb 117 ((AliTRDclusterizer &) c).fRecPoints = NULL;
8230f242 118
119}
120
f7336fa3 121//_____________________________________________________________________________
3e1a3ad8 122Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
f7336fa3 123{
124 //
3e1a3ad8 125 // Opens the AliROOT file. Output and input are in the same file
f7336fa3 126 //
6d50f529 127
e191bb57 128 TString evfoldname = AliConfig::GetDefaultEventFolderName();
6d50f529 129 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
130
131 if (!fRunLoader) {
19dd5b2f 132 fRunLoader = AliRunLoader::Open(name);
6d50f529 133 }
134
135 if (!fRunLoader) {
136 AliError(Form("Can not open session for file %s.",name));
137 return kFALSE;
138 }
88cb7938 139
140 OpenInput(nEvent);
141 OpenOutput();
6d50f529 142
3e1a3ad8 143 return kTRUE;
f7336fa3 144
6d50f529 145}
3e1a3ad8 146
147//_____________________________________________________________________________
88cb7938 148Bool_t AliTRDclusterizer::OpenOutput()
3e1a3ad8 149{
150 //
151 // Open the output file
152 //
153
3e1a3ad8 154 TObjArray *ioArray = 0;
88cb7938 155
156 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
157 loader->MakeTree("R");
6d50f529 158
88cb7938 159 fClusterTree = loader->TreeR();
365d0374 160 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
3e1a3ad8 161
3e1a3ad8 162 return kTRUE;
163
164}
165
25ca55ce 166//_____________________________________________________________________________
167Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
168{
169 //
170 // Connect the output tree
171 //
172
173 TObjArray *ioArray = 0;
174
175 fClusterTree = clusterTree;
176 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
177
178 return kTRUE;
179
180}
181
3e1a3ad8 182//_____________________________________________________________________________
88cb7938 183Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
f7336fa3 184{
185 //
186 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
187 //
188
f7336fa3 189 // Import the Trees for the event nEvent in the file
bdbb05bb 190 fRunLoader->GetEvent(nEvent);
88cb7938 191
f7336fa3 192 return kTRUE;
193
194}
195
196//_____________________________________________________________________________
793ff80c 197Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
f7336fa3 198{
199 //
3e1a3ad8 200 // Fills TRDcluster branch in the tree with the clusters
793ff80c 201 // found in detector = det. For det=-1 writes the tree.
a3c76cdc 202 //
793ff80c 203
6d50f529 204 if ((det < -1) ||
205 (det >= AliTRDgeometry::Ndet())) {
206 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 207 return kFALSE;
793ff80c 208 }
3e1a3ad8 209
3e1a3ad8 210 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
211 if (!branch) {
793ff80c 212 TObjArray *ioArray = 0;
3e1a3ad8 213 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
793ff80c 214 }
215
6d50f529 216 if ((det >= 0) &&
217 (det < AliTRDgeometry::Ndet())) {
793ff80c 218
bdbb05bb 219 Int_t nRecPoints = RecPoints()->GetEntriesFast();
3e1a3ad8 220 TObjArray *detRecPoints = new TObjArray(400);
221
222 for (Int_t i = 0; i < nRecPoints; i++) {
bdbb05bb 223 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
3e1a3ad8 224 if (det == c->GetDetector()) {
225 detRecPoints->AddLast(c);
226 }
227 else {
6d50f529 228 AliError("Attempt to write a cluster with unexpected detector index\n");
3e1a3ad8 229 }
793ff80c 230 }
231
3e1a3ad8 232 branch->SetAddress(&detRecPoints);
233 fClusterTree->Fill();
234
d9b8978b 235 delete detRecPoints;
236
793ff80c 237 return kTRUE;
3e1a3ad8 238
793ff80c 239 }
240
241 if (det == -1) {
242
6d50f529 243 AliInfo(Form("Writing the cluster tree %s for event %d."
244 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
245
a6dd11e9 246 if (fRecPoints) {
247
248 branch->SetAddress(&fRecPoints);
249
250 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
251 loader->WriteRecPoints("OVERWRITE");
c630aafd 252
a6dd11e9 253 }
254 else {
255
256 AliError("Cluster tree does not exist. Cannot write clusters.\n");
257 return kFALSE;
258
259 }
260
793ff80c 261 return kTRUE;
3e1a3ad8 262
793ff80c 263 }
6d50f529 264
265 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 266
793ff80c 267 return kFALSE;
88cb7938 268
f7336fa3 269}
793ff80c 270
271
bdbb05bb 272//_____________________________________________________________________________
6d50f529 273AliTRDcluster* AliTRDclusterizer::AddCluster(Double_t *pos, Int_t timebin
274 , Int_t det, Double_t amp
275 , Int_t *tracks, Double_t *sig
524fc8fa 276 , Int_t iType, Int_t col
d74f970b 277 , UShort_t volid
524fc8fa 278 , Float_t center)
bdbb05bb 279{
280 //
281 // Add a cluster for the TRD
282 //
793ff80c 283
bdbb05bb 284 AliTRDcluster *c = new AliTRDcluster();
285
286 c->SetDetector(det);
bdbb05bb 287 c->SetQ(amp);
3551db50 288 c->SetX(pos[2]);
bdbb05bb 289 c->SetY(pos[0]);
290 c->SetZ(pos[1]);
291 c->SetSigmaY2(sig[0]);
292 c->SetSigmaZ2(sig[1]);
3551db50 293 c->SetLocalTimeBin(timebin);
828b670e 294 c->SetCenter(center);
524fc8fa 295 c->SetPad(col);
d74f970b 296 c->SetVolumeId(volid);
6d50f529 297
a6dd11e9 298 if (tracks) {
299 c->AddTrackIndex(tracks);
300 }
301
bdbb05bb 302 switch (iType) {
303 case 0:
304 c->Set2pad();
305 break;
306 case 1:
307 c->Set3pad();
308 break;
309 case 2:
310 c->Set4pad();
311 break;
312 case 3:
313 c->Set5pad();
314 break;
315 case 4:
316 c->SetLarge();
317 break;
318 };
319
320 RecPoints()->Add(c);
c85a4951 321 return c;
6d50f529 322
bdbb05bb 323}
3551db50 324
325//_____________________________________________________________________________
6d50f529 326Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
327 , Int_t col, Int_t row)
3551db50 328{
329 //
6d50f529 330 // Calculates the local x position in the detector from the timebin,
331 // depends on the drift velocity and t0
3551db50 332 //
333
b43a3e17 334 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
6d50f529 335 if (!calibration) {
a6dd11e9 336 AliError("Cannot find calibration object");
3551db50 337 return -1;
6d50f529 338 }
b43a3e17 339 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
340 if (!parCom) {
341 AliError("Could not get common parameters\n");
342 return kFALSE;
343 }
88719a08 344
6d50f529 345 Float_t vdrift = calibration->GetVdrift(idet,col,row);
346 Float_t t0 = calibration->GetT0(idet,col,row);
b43a3e17 347 Float_t samplingFrequency = parCom->GetSamplingFrequency();
88719a08 348
349 timebin -= t0;
350
351 return timebin / samplingFrequency * vdrift;
6d50f529 352
353}
354
355//_____________________________________________________________________________
356void AliTRDclusterizer::ResetRecPoints()
357{
358 //
359 // Resets the list of rec points
360 //
361
362 if (fRecPoints) {
363 fRecPoints->Delete();
364 }
365
366}
367
368//_____________________________________________________________________________
369TObjArray* AliTRDclusterizer::RecPoints()
370{
371 //
372 // Returns the list of rec points
373 //
374
375 if (!fRecPoints) {
376 fRecPoints = new TObjArray(400);
377 }
378
379 return fRecPoints;
380
3551db50 381}