]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizer.cxx
Stand-alone library for ESD. Possibility to use only root and lidESD.so for analysis...
[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"
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;
5443e65e 50 fPar = 0;
f7336fa3 51
52}
53
54//_____________________________________________________________________________
55AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
56 :TNamed(name, title)
57{
58 //
59 // AliTRDclusterizer default constructor
60 //
61
3e1a3ad8 62 fClusterTree = NULL;
bdbb05bb 63 fRecPoints = 0;
3e1a3ad8 64 fVerbose = 0;
5443e65e 65 fPar = 0;
f7336fa3 66
67}
68
8230f242 69//_____________________________________________________________________________
73ae7b59 70AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
8230f242 71{
72 //
73 // AliTRDclusterizer copy constructor
74 //
75
dd9a6ee3 76 ((AliTRDclusterizer &) c).Copy(*this);
8230f242 77
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 }
f7336fa3 91}
92
8230f242 93//_____________________________________________________________________________
dd9a6ee3 94AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
95{
96 //
97 // Assignment operator
98 //
99
100 if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
101 return *this;
102
103}
104
105//_____________________________________________________________________________
106void AliTRDclusterizer::Copy(TObject &c)
8230f242 107{
108 //
109 // Copy function
110 //
111
3e1a3ad8 112 ((AliTRDclusterizer &) c).fClusterTree = NULL;
bdbb05bb 113 ((AliTRDclusterizer &) c).fRecPoints = NULL;
3e1a3ad8 114 ((AliTRDclusterizer &) c).fVerbose = fVerbose;
5443e65e 115 ((AliTRDclusterizer &) c).fPar = 0;
8230f242 116
117}
118
f7336fa3 119//_____________________________________________________________________________
3e1a3ad8 120Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
f7336fa3 121{
122 //
3e1a3ad8 123 // Opens the AliROOT file. Output and input are in the same file
f7336fa3 124 //
e191bb57 125 TString evfoldname = AliConfig::GetDefaultEventFolderName();
19dd5b2f 126 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
127 if (!fRunLoader)
128 fRunLoader = AliRunLoader::Open(name);
88cb7938 129 if (!fRunLoader)
130 {
131 Error("Open","Can not open session for file %s.",name);
132 return kFALSE;
133 }
134
135 OpenInput(nEvent);
136 OpenOutput();
3e1a3ad8 137 return kTRUE;
f7336fa3 138}
139
3e1a3ad8 140
141//_____________________________________________________________________________
88cb7938 142Bool_t AliTRDclusterizer::OpenOutput()
3e1a3ad8 143{
144 //
145 // Open the output file
146 //
147
3e1a3ad8 148 TObjArray *ioArray = 0;
88cb7938 149
150 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
151 loader->MakeTree("R");
152 fClusterTree = loader->TreeR();
365d0374 153 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
3e1a3ad8 154
3e1a3ad8 155
156 return kTRUE;
157
158}
159
160//_____________________________________________________________________________
88cb7938 161Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
f7336fa3 162{
163 //
164 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
165 //
166
167 // Connect the AliRoot file containing Geometry, Kine, and Hits
19dd5b2f 168 if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
88cb7938 169 gAlice = fRunLoader->GetAliRun();
f7336fa3 170
a3c76cdc 171 if (!(gAlice)) {
88cb7938 172 fRunLoader->LoadgAlice();
173 gAlice = fRunLoader->GetAliRun();
174 if (!(gAlice)) {
175 printf("AliTRDclusterizer::OpenInput -- ");
176 printf("Could not find AliRun object.\n");
177 return kFALSE;
178 }
a3c76cdc 179 }
f7336fa3 180
f7336fa3 181 // Import the Trees for the event nEvent in the file
bdbb05bb 182 fRunLoader->GetEvent(nEvent);
88cb7938 183
f7336fa3 184 return kTRUE;
185
186}
187
188//_____________________________________________________________________________
793ff80c 189Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
f7336fa3 190{
191 //
3e1a3ad8 192 // Fills TRDcluster branch in the tree with the clusters
793ff80c 193 // found in detector = det. For det=-1 writes the tree.
a3c76cdc 194 //
793ff80c 195
3e1a3ad8 196 if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
197 printf("AliTRDclusterizer::WriteClusters -- ");
198 printf("Unexpected detector index %d.\n",det);
199 return kFALSE;
793ff80c 200 }
3e1a3ad8 201
f7336fa3 202
3e1a3ad8 203 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
204 if (!branch) {
793ff80c 205 TObjArray *ioArray = 0;
3e1a3ad8 206 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
793ff80c 207 }
208
209 if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
210
bdbb05bb 211 Int_t nRecPoints = RecPoints()->GetEntriesFast();
3e1a3ad8 212 TObjArray *detRecPoints = new TObjArray(400);
213
214 for (Int_t i = 0; i < nRecPoints; i++) {
bdbb05bb 215 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
3e1a3ad8 216 if (det == c->GetDetector()) {
217 detRecPoints->AddLast(c);
218 }
219 else {
220 printf("AliTRDclusterizer::WriteClusters --");
221 printf("Attempt to write a cluster with unexpected detector index\n");
222 }
793ff80c 223 }
224
3e1a3ad8 225 branch->SetAddress(&detRecPoints);
226 fClusterTree->Fill();
227
d9b8978b 228 delete detRecPoints;
229
793ff80c 230 return kTRUE;
3e1a3ad8 231
793ff80c 232 }
233
234 if (det == -1) {
235
19dd5b2f 236 Info("WriteClusters","Writing the cluster tree %s for event %d."
bdbb05bb 237 ,fClusterTree->GetName(),fRunLoader->GetEventNumber());
c630aafd 238 /*
3e1a3ad8 239 fClusterTree->Write();
ba2e024c 240 AliTRDgeometry *geo = fTRD->GetGeometry();
88cb7938 241 geo->SetName("TRDgeometry");
242 geo->Write();
c630aafd 243 fPar->Write();
244 */
245 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
246 loader->WriteRecPoints("OVERWRITE");
247
793ff80c 248 return kTRUE;
3e1a3ad8 249
793ff80c 250 }
c630aafd 251 /*
88cb7938 252 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
253 loader->WriteDigits("OVERWRITE");
c630aafd 254 */
3e1a3ad8 255 printf("AliTRDclusterizer::WriteClusters -- ");
256 printf("Unexpected detector index %d.\n",det);
257
793ff80c 258 return kFALSE;
88cb7938 259
f7336fa3 260}
793ff80c 261
262
bdbb05bb 263//_____________________________________________________________________________
264void AliTRDclusterizer::AddCluster(Float_t *pos, Int_t det, Float_t amp
265 , Int_t *tracks, Float_t *sig, Int_t iType)
266{
267 //
268 // Add a cluster for the TRD
269 //
793ff80c 270
bdbb05bb 271 AliTRDcluster *c = new AliTRDcluster();
272
273 c->SetDetector(det);
274 c->AddTrackIndex(tracks);
275 c->SetQ(amp);
276 c->SetY(pos[0]);
277 c->SetZ(pos[1]);
278 c->SetSigmaY2(sig[0]);
279 c->SetSigmaZ2(sig[1]);
280 c->SetLocalTimeBin(((Int_t) pos[2]));
281
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);
301
302}