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