]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Latest version of zero suppressed raw data by Ken and Mateusz
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
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
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD cluster finder base class                                            //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TROOT.h>
25 #include <TTree.h>
26 #include <TFile.h>
27 #include <TObjArray.h>
28
29 #include "AliRunLoader.h"
30 #include "AliLoader.h"
31 #include "AliLog.h"
32
33 #include "AliTRDclusterizer.h"
34 #include "AliTRDcluster.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDCommonParam.h"
38
39 ClassImp(AliTRDclusterizer)
40
41 //_____________________________________________________________________________
42 AliTRDclusterizer::AliTRDclusterizer()
43   :TNamed()
44   ,fRunLoader(NULL)
45   ,fClusterTree(NULL)
46   ,fRecPoints(NULL)
47 {
48   //
49   // AliTRDclusterizer default constructor
50   //
51
52 }
53
54 //_____________________________________________________________________________
55 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
56   :TNamed(name,title)
57   ,fRunLoader(NULL)
58   ,fClusterTree(NULL)
59   ,fRecPoints(NULL)
60 {
61   //
62   // AliTRDclusterizer constructor
63   //
64
65 }
66
67 //_____________________________________________________________________________
68 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
69   :TNamed(c)
70   ,fRunLoader(NULL)
71   ,fClusterTree(NULL)
72   ,fRecPoints(NULL)
73 {
74   //
75   // AliTRDclusterizer copy constructor
76   //
77
78 }
79
80 //_____________________________________________________________________________
81 AliTRDclusterizer::~AliTRDclusterizer()
82 {
83   //
84   // AliTRDclusterizer destructor
85   //
86
87   if (fRecPoints) {
88     fRecPoints->Delete();
89     delete fRecPoints;
90   }
91
92 }
93
94 //_____________________________________________________________________________
95 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
96 {
97   //
98   // Assignment operator
99   //
100
101   if (this != &c) {
102     ((AliTRDclusterizer &) c).Copy(*this);
103   }
104   return *this;
105
106 }
107
108 //_____________________________________________________________________________
109 void AliTRDclusterizer::Copy(TObject &c) const
110 {
111   //
112   // Copy function
113   //
114
115   ((AliTRDclusterizer &) c).fClusterTree = NULL;
116   ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
117
118 }
119
120 //_____________________________________________________________________________
121 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
122 {
123   //
124   // Opens the AliROOT file. Output and input are in the same file
125   //
126
127   TString evfoldname = AliConfig::GetDefaultEventFolderName();
128   fRunLoader         = AliRunLoader::GetRunLoader(evfoldname);
129
130   if (!fRunLoader) {
131     fRunLoader = AliRunLoader::Open(name);
132   }
133
134   if (!fRunLoader) {
135     AliError(Form("Can not open session for file %s.",name));
136     return kFALSE;
137   }
138
139   OpenInput(nEvent);
140   OpenOutput();
141
142   return kTRUE;
143
144 }
145
146 //_____________________________________________________________________________
147 Bool_t AliTRDclusterizer::OpenOutput()
148 {
149   //
150   // Open the output file
151   //
152
153   TObjArray *ioArray = 0;
154
155   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
156   loader->MakeTree("R");
157
158   fClusterTree = loader->TreeR();
159   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
160
161   return kTRUE;
162
163 }
164
165 //_____________________________________________________________________________
166 Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
167 {
168   //
169   // Connect the output tree
170   //
171
172   TObjArray *ioArray = 0;
173
174   fClusterTree = clusterTree;
175   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
176
177   return kTRUE;
178
179 }
180
181 //_____________________________________________________________________________
182 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
183 {
184   //
185   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
186   //
187
188   // Import the Trees for the event nEvent in the file
189   fRunLoader->GetEvent(nEvent);
190   
191   return kTRUE;
192
193 }
194
195 //_____________________________________________________________________________
196 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
197 {
198   //
199   // Fills TRDcluster branch in the tree with the clusters 
200   // found in detector = det. For det=-1 writes the tree. 
201   //
202
203   if ((det <                      -1) || 
204       (det >= AliTRDgeometry::Ndet())) {
205     AliError(Form("Unexpected detector index %d.\n",det));
206     return kFALSE;
207   }
208  
209   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
210   if (!branch) {
211     TObjArray *ioArray = 0;
212     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
213   }
214
215   if ((det >=                      0) && 
216       (det <  AliTRDgeometry::Ndet())) {
217
218     Int_t nRecPoints = RecPoints()->GetEntriesFast();
219     TObjArray *detRecPoints = new TObjArray(400);
220
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);
225       }
226       else {
227         AliError(Form("Attempt to write a cluster with unexpected detector index: got=%d expected=%d\n", c->GetDetector(), det));
228       }
229     }
230
231     branch->SetAddress(&detRecPoints);
232     fClusterTree->Fill();
233
234     delete detRecPoints;
235
236     //AliInfo(Form("Writing %d clusters to tree", nRecPoints));
237     
238     return kTRUE;
239
240   }
241
242   if (det == -1) {
243
244     AliInfo(Form("Writing the cluster tree %s for event %d."
245                 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
246
247     if (fRecPoints) {
248
249       branch->SetAddress(&fRecPoints);
250
251       AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
252       loader->WriteRecPoints("OVERWRITE");
253   
254     }
255     else {
256
257       AliError("Cluster tree does not exist. Cannot write clusters.\n");
258       return kFALSE;
259
260     }
261
262     return kTRUE;  
263
264   }
265
266   AliError(Form("Unexpected detector index %d.\n",det));
267  
268   return kFALSE;  
269   
270 }
271
272 //_____________________________________________________________________________
273 Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
274                                               , Int_t col, Int_t row)
275 {
276   //
277   // Calculates the local x position in the detector from the timebin, 
278   // depends on the drift velocity and t0
279   //
280   
281   AliTRDcalibDB     *calibration = AliTRDcalibDB::Instance();
282   if (!calibration) {
283     AliError("Cannot find calibration object");
284     return -1;
285   }
286   AliTRDCommonParam *parCom      = AliTRDCommonParam::Instance();
287   if (!parCom) {
288     AliError("Could not get common parameters\n");
289     return kFALSE;
290   }
291
292   Float_t vdrift            = calibration->GetVdrift(idet,col,row);  
293   Float_t t0                = calibration->GetT0(idet,col,row);
294   Float_t samplingFrequency = parCom->GetSamplingFrequency();
295
296   timebin -= t0;
297
298   return timebin / samplingFrequency * vdrift;
299
300 }
301
302 //_____________________________________________________________________________
303 void AliTRDclusterizer::ResetRecPoints() 
304 {
305   //
306   // Resets the list of rec points
307   //
308
309   if (fRecPoints) {
310     fRecPoints->Delete();
311   }
312
313 }
314
315 //_____________________________________________________________________________
316 TObjArray *AliTRDclusterizer::RecPoints() 
317 {
318   //
319   // Returns the list of rec points
320   //
321
322   if (!fRecPoints) {
323     fRecPoints = new TObjArray(400);
324   }
325  
326   return fRecPoints;
327
328 }