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