]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizer.cxx
Remove t0 again from global calibration
[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
166//_____________________________________________________________________________
88cb7938 167Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
f7336fa3 168{
169 //
170 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
171 //
172
f7336fa3 173 // Import the Trees for the event nEvent in the file
bdbb05bb 174 fRunLoader->GetEvent(nEvent);
88cb7938 175
f7336fa3 176 return kTRUE;
177
178}
179
180//_____________________________________________________________________________
793ff80c 181Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
f7336fa3 182{
183 //
3e1a3ad8 184 // Fills TRDcluster branch in the tree with the clusters
793ff80c 185 // found in detector = det. For det=-1 writes the tree.
a3c76cdc 186 //
793ff80c 187
6d50f529 188 if ((det < -1) ||
189 (det >= AliTRDgeometry::Ndet())) {
190 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 191 return kFALSE;
793ff80c 192 }
3e1a3ad8 193
3e1a3ad8 194 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
195 if (!branch) {
793ff80c 196 TObjArray *ioArray = 0;
3e1a3ad8 197 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
793ff80c 198 }
199
6d50f529 200 if ((det >= 0) &&
201 (det < AliTRDgeometry::Ndet())) {
793ff80c 202
bdbb05bb 203 Int_t nRecPoints = RecPoints()->GetEntriesFast();
3e1a3ad8 204 TObjArray *detRecPoints = new TObjArray(400);
205
206 for (Int_t i = 0; i < nRecPoints; i++) {
bdbb05bb 207 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
3e1a3ad8 208 if (det == c->GetDetector()) {
209 detRecPoints->AddLast(c);
210 }
211 else {
6d50f529 212 AliError("Attempt to write a cluster with unexpected detector index\n");
3e1a3ad8 213 }
793ff80c 214 }
215
3e1a3ad8 216 branch->SetAddress(&detRecPoints);
217 fClusterTree->Fill();
218
d9b8978b 219 delete detRecPoints;
220
793ff80c 221 return kTRUE;
3e1a3ad8 222
793ff80c 223 }
224
225 if (det == -1) {
226
6d50f529 227 AliInfo(Form("Writing the cluster tree %s for event %d."
228 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
229
a6dd11e9 230 if (fRecPoints) {
231
232 branch->SetAddress(&fRecPoints);
233
234 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
235 loader->WriteRecPoints("OVERWRITE");
c630aafd 236
a6dd11e9 237 }
238 else {
239
240 AliError("Cluster tree does not exist. Cannot write clusters.\n");
241 return kFALSE;
242
243 }
244
793ff80c 245 return kTRUE;
3e1a3ad8 246
793ff80c 247 }
6d50f529 248
249 AliError(Form("Unexpected detector index %d.\n",det));
3e1a3ad8 250
793ff80c 251 return kFALSE;
88cb7938 252
f7336fa3 253}
793ff80c 254
255
bdbb05bb 256//_____________________________________________________________________________
6d50f529 257AliTRDcluster* AliTRDclusterizer::AddCluster(Double_t *pos, Int_t timebin
258 , Int_t det, Double_t amp
259 , Int_t *tracks, Double_t *sig
260 , Int_t iType, Float_t center)
bdbb05bb 261{
262 //
263 // Add a cluster for the TRD
264 //
793ff80c 265
bdbb05bb 266 AliTRDcluster *c = new AliTRDcluster();
267
268 c->SetDetector(det);
bdbb05bb 269 c->SetQ(amp);
3551db50 270 c->SetX(pos[2]);
bdbb05bb 271 c->SetY(pos[0]);
272 c->SetZ(pos[1]);
273 c->SetSigmaY2(sig[0]);
274 c->SetSigmaZ2(sig[1]);
3551db50 275 c->SetLocalTimeBin(timebin);
828b670e 276 c->SetCenter(center);
6d50f529 277
a6dd11e9 278 if (tracks) {
279 c->AddTrackIndex(tracks);
280 }
281
bdbb05bb 282 switch (iType) {
283 case 0:
284 c->Set2pad();
285 break;
286 case 1:
287 c->Set3pad();
288 break;
289 case 2:
290 c->Set4pad();
291 break;
292 case 3:
293 c->Set5pad();
294 break;
295 case 4:
296 c->SetLarge();
297 break;
298 };
299
300 RecPoints()->Add(c);
c85a4951 301 return c;
6d50f529 302
bdbb05bb 303}
3551db50 304
305//_____________________________________________________________________________
6d50f529 306Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
307 , Int_t col, Int_t row)
3551db50 308{
309 //
6d50f529 310 // Calculates the local x position in the detector from the timebin,
311 // depends on the drift velocity and t0
3551db50 312 //
313
b43a3e17 314 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
6d50f529 315 if (!calibration) {
a6dd11e9 316 AliError("Cannot find calibration object");
3551db50 317 return -1;
6d50f529 318 }
b43a3e17 319 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
320 if (!parCom) {
321 AliError("Could not get common parameters\n");
322 return kFALSE;
323 }
88719a08 324
6d50f529 325 Float_t vdrift = calibration->GetVdrift(idet,col,row);
326 Float_t t0 = calibration->GetT0(idet,col,row);
b43a3e17 327 Float_t samplingFrequency = parCom->GetSamplingFrequency();
88719a08 328
329 timebin -= t0;
330
331 return timebin / samplingFrequency * vdrift;
6d50f529 332
333}
334
335//_____________________________________________________________________________
336void AliTRDclusterizer::ResetRecPoints()
337{
338 //
339 // Resets the list of rec points
340 //
341
342 if (fRecPoints) {
343 fRecPoints->Delete();
344 }
345
346}
347
348//_____________________________________________________________________________
349TObjArray* AliTRDclusterizer::RecPoints()
350{
351 //
352 // Returns the list of rec points
353 //
354
355 if (!fRecPoints) {
356 fRecPoints = new TObjArray(400);
357 }
358
359 return fRecPoints;
360
3551db50 361}