1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder base class //
22 ///////////////////////////////////////////////////////////////////////////////
27 #include <TObjArray.h>
29 #include "AliRunLoader.h"
30 #include "AliLoader.h"
33 #include "AliTRDclusterizer.h"
34 #include "AliTRDcluster.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDCommonParam.h"
39 ClassImp(AliTRDclusterizer)
41 //_____________________________________________________________________________
42 AliTRDclusterizer::AliTRDclusterizer()
49 // AliTRDclusterizer default constructor
54 //_____________________________________________________________________________
55 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
62 // AliTRDclusterizer constructor
67 //_____________________________________________________________________________
68 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
75 // AliTRDclusterizer copy constructor
80 //_____________________________________________________________________________
81 AliTRDclusterizer::~AliTRDclusterizer()
84 // AliTRDclusterizer destructor
94 //_____________________________________________________________________________
95 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
98 // Assignment operator
102 ((AliTRDclusterizer &) c).Copy(*this);
108 //_____________________________________________________________________________
109 void AliTRDclusterizer::Copy(TObject &c) const
115 ((AliTRDclusterizer &) c).fClusterTree = NULL;
116 ((AliTRDclusterizer &) c).fRecPoints = NULL;
120 //_____________________________________________________________________________
121 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
124 // Opens the AliROOT file. Output and input are in the same file
127 TString evfoldname = AliConfig::GetDefaultEventFolderName();
128 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
131 fRunLoader = AliRunLoader::Open(name);
135 AliError(Form("Can not open session for file %s.",name));
146 //_____________________________________________________________________________
147 Bool_t AliTRDclusterizer::OpenOutput()
150 // Open the output file
153 TObjArray *ioArray = 0;
155 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
156 loader->MakeTree("R");
158 fClusterTree = loader->TreeR();
159 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
165 //_____________________________________________________________________________
166 Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
169 // Connect the output tree
172 TObjArray *ioArray = 0;
174 fClusterTree = clusterTree;
175 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
181 //_____________________________________________________________________________
182 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
185 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
188 // Import the Trees for the event nEvent in the file
189 fRunLoader->GetEvent(nEvent);
195 //_____________________________________________________________________________
196 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
199 // Fills TRDcluster branch in the tree with the clusters
200 // found in detector = det. For det=-1 writes the tree.
204 (det >= AliTRDgeometry::Ndet())) {
205 AliError(Form("Unexpected detector index %d.\n",det));
209 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
211 TObjArray *ioArray = 0;
212 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
216 (det < AliTRDgeometry::Ndet())) {
218 Int_t nRecPoints = RecPoints()->GetEntriesFast();
219 TObjArray *detRecPoints = new TObjArray(400);
221 for (Int_t i = 0; i < nRecPoints; i++) {
222 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
223 if (det == c->GetDetector()) {
224 detRecPoints->AddLast(c);
227 AliError(Form("Attempt to write a cluster with unexpected detector index: got=%d expected=%d\n", c->GetDetector(), det));
231 branch->SetAddress(&detRecPoints);
232 fClusterTree->Fill();
236 //AliInfo(Form("Writing %d clusters to tree", nRecPoints));
244 AliInfo(Form("Writing the cluster tree %s for event %d."
245 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
249 branch->SetAddress(&fRecPoints);
251 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
252 loader->WriteRecPoints("OVERWRITE");
257 AliError("Cluster tree does not exist. Cannot write clusters.\n");
266 AliError(Form("Unexpected detector index %d.\n",det));
272 //_____________________________________________________________________________
273 Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
274 , Int_t col, Int_t row)
277 // Calculates the local x position in the detector from the timebin,
278 // depends on the drift velocity and t0
281 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
283 AliError("Cannot find calibration object");
286 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
288 AliError("Could not get common parameters\n");
292 Float_t vdrift = calibration->GetVdrift(idet,col,row);
293 Float_t t0 = calibration->GetT0(idet,col,row);
294 Float_t samplingFrequency = parCom->GetSamplingFrequency();
298 return timebin / samplingFrequency * vdrift;
302 //_____________________________________________________________________________
303 void AliTRDclusterizer::ResetRecPoints()
306 // Resets the list of rec points
310 fRecPoints->Delete();
315 //_____________________________________________________________________________
316 TObjArray *AliTRDclusterizer::RecPoints()
319 // Returns the list of rec points
323 fRecPoints = new TObjArray(400);