]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizer.cxx
Coding conventions
[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 "AliTRDgeometry.h"
3551db50 36#include "AliTRDcalibDB.h"
b43a3e17 37#include "AliTRDCommonParam.h"
f7336fa3 38
39ClassImp(AliTRDclusterizer)
40
41//_____________________________________________________________________________
6d50f529 42AliTRDclusterizer::AliTRDclusterizer()
43 :TNamed()
44 ,fRunLoader(NULL)
45 ,fClusterTree(NULL)
46 ,fRecPoints(NULL)
f7336fa3 47{
48 //
49 // AliTRDclusterizer default constructor
50 //
51
f7336fa3 52}
53
54//_____________________________________________________________________________
55AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
6d50f529 56 :TNamed(name,title)
57 ,fRunLoader(NULL)
58 ,fClusterTree(NULL)
59 ,fRecPoints(NULL)
f7336fa3 60{
61 //
6d50f529 62 // AliTRDclusterizer constructor
f7336fa3 63 //
64
f7336fa3 65}
66
8230f242 67//_____________________________________________________________________________
6d50f529 68AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
69 :TNamed(c)
70 ,fRunLoader(NULL)
71 ,fClusterTree(NULL)
72 ,fRecPoints(NULL)
8230f242 73{
74 //
75 // AliTRDclusterizer copy constructor
76 //
77
8230f242 78}
79
f7336fa3 80//_____________________________________________________________________________
81AliTRDclusterizer::~AliTRDclusterizer()
82{
8230f242 83 //
84 // AliTRDclusterizer destructor
85 //
f7336fa3 86
bdbb05bb 87 if (fRecPoints) {
88 fRecPoints->Delete();
89 delete fRecPoints;
90 }
6d50f529 91
f7336fa3 92}
93
8230f242 94//_____________________________________________________________________________
dd9a6ee3 95AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
96{
97 //
98 // Assignment operator
99 //
100
b43a3e17 101 if (this != &c) {
102 ((AliTRDclusterizer &) c).Copy(*this);
103 }
dd9a6ee3 104 return *this;
105
106}
107
108//_____________________________________________________________________________
e0d47c25 109void AliTRDclusterizer::Copy(TObject &c) const
8230f242 110{
111 //
112 // Copy function
113 //
114
3e1a3ad8 115 ((AliTRDclusterizer &) c).fClusterTree = NULL;
bdbb05bb 116 ((AliTRDclusterizer &) c).fRecPoints = NULL;
8230f242 117
118}
119
f7336fa3 120//_____________________________________________________________________________
3e1a3ad8 121Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
f7336fa3 122{
123 //
3e1a3ad8 124 // Opens the AliROOT file. Output and input are in the same file
f7336fa3 125 //
6d50f529 126
e191bb57 127 TString evfoldname = AliConfig::GetDefaultEventFolderName();
6d50f529 128 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
129
130 if (!fRunLoader) {
19dd5b2f 131 fRunLoader = AliRunLoader::Open(name);
6d50f529 132 }
133
134 if (!fRunLoader) {
135 AliError(Form("Can not open session for file %s.",name));
136 return kFALSE;
137 }
88cb7938 138
139 OpenInput(nEvent);
140 OpenOutput();
6d50f529 141
3e1a3ad8 142 return kTRUE;
f7336fa3 143
6d50f529 144}
3e1a3ad8 145
146//_____________________________________________________________________________
88cb7938 147Bool_t AliTRDclusterizer::OpenOutput()
3e1a3ad8 148{
149 //
150 // Open the output file
151 //
152
3e1a3ad8 153 TObjArray *ioArray = 0;
88cb7938 154
155 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
156 loader->MakeTree("R");
6d50f529 157
88cb7938 158 fClusterTree = loader->TreeR();
365d0374 159 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
3e1a3ad8 160
3e1a3ad8 161 return kTRUE;
162
163}
164
25ca55ce 165//_____________________________________________________________________________
166Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
167{
168 //
169 // Connect the output tree
170 //
171
172 TObjArray *ioArray = 0;
173
174 fClusterTree = clusterTree;
175 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
176
177 return kTRUE;
178
179}
180
3e1a3ad8 181//_____________________________________________________________________________
88cb7938 182Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
f7336fa3 183{
184 //
185 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
186 //
187
f7336fa3 188 // Import the Trees for the event nEvent in the file
bdbb05bb 189 fRunLoader->GetEvent(nEvent);
88cb7938 190
f7336fa3 191 return kTRUE;
192
193}
194
195//_____________________________________________________________________________
793ff80c 196Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
f7336fa3 197{
198 //
3e1a3ad8 199 // Fills TRDcluster branch in the tree with the clusters
793ff80c 200 // found in detector = det. For det=-1 writes the tree.
a3c76cdc 201 //
793ff80c 202
6d50f529 203 if ((det < -1) ||
204 (det >= AliTRDgeometry::Ndet())) {
205 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 206 return kFALSE;
793ff80c 207 }
3e1a3ad8 208
3e1a3ad8 209 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
210 if (!branch) {
793ff80c 211 TObjArray *ioArray = 0;
3e1a3ad8 212 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
793ff80c 213 }
214
6d50f529 215 if ((det >= 0) &&
216 (det < AliTRDgeometry::Ndet())) {
793ff80c 217
bdbb05bb 218 Int_t nRecPoints = RecPoints()->GetEntriesFast();
3e1a3ad8 219 TObjArray *detRecPoints = new TObjArray(400);
220
221 for (Int_t i = 0; i < nRecPoints; i++) {
bdbb05bb 222 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
3e1a3ad8 223 if (det == c->GetDetector()) {
224 detRecPoints->AddLast(c);
225 }
226 else {
6d50f529 227 AliError("Attempt to write a cluster with unexpected detector index\n");
3e1a3ad8 228 }
793ff80c 229 }
230
3e1a3ad8 231 branch->SetAddress(&detRecPoints);
232 fClusterTree->Fill();
233
d9b8978b 234 delete detRecPoints;
235
793ff80c 236 return kTRUE;
3e1a3ad8 237
793ff80c 238 }
239
240 if (det == -1) {
241
6d50f529 242 AliInfo(Form("Writing the cluster tree %s for event %d."
243 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
244
a6dd11e9 245 if (fRecPoints) {
246
247 branch->SetAddress(&fRecPoints);
248
249 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
250 loader->WriteRecPoints("OVERWRITE");
c630aafd 251
a6dd11e9 252 }
253 else {
254
255 AliError("Cluster tree does not exist. Cannot write clusters.\n");
256 return kFALSE;
257
258 }
259
793ff80c 260 return kTRUE;
3e1a3ad8 261
793ff80c 262 }
6d50f529 263
264 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 265
793ff80c 266 return kFALSE;
88cb7938 267
f7336fa3 268}
793ff80c 269
3551db50 270//_____________________________________________________________________________
6d50f529 271Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
272 , Int_t col, Int_t row)
3551db50 273{
274 //
6d50f529 275 // Calculates the local x position in the detector from the timebin,
276 // depends on the drift velocity and t0
3551db50 277 //
278
b43a3e17 279 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
6d50f529 280 if (!calibration) {
a6dd11e9 281 AliError("Cannot find calibration object");
3551db50 282 return -1;
6d50f529 283 }
b43a3e17 284 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
285 if (!parCom) {
286 AliError("Could not get common parameters\n");
287 return kFALSE;
288 }
88719a08 289
6d50f529 290 Float_t vdrift = calibration->GetVdrift(idet,col,row);
291 Float_t t0 = calibration->GetT0(idet,col,row);
b43a3e17 292 Float_t samplingFrequency = parCom->GetSamplingFrequency();
88719a08 293
294 timebin -= t0;
295
296 return timebin / samplingFrequency * vdrift;
6d50f529 297
298}
299
300//_____________________________________________________________________________
301void AliTRDclusterizer::ResetRecPoints()
302{
303 //
304 // Resets the list of rec points
305 //
306
307 if (fRecPoints) {
308 fRecPoints->Delete();
309 }
310
311}
312
313//_____________________________________________________________________________
34eaaa7e 314TObjArray *AliTRDclusterizer::RecPoints()
6d50f529 315{
316 //
317 // Returns the list of rec points
318 //
319
320 if (!fRecPoints) {
321 fRecPoints = new TObjArray(400);
322 }
323
324 return fRecPoints;
325
3551db50 326}