]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Update of calibration classes by Jan Fiete
[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
28 #include "AliRun.h"
29 #include "AliRunLoader.h"
30 #include "AliLoader.h"
31
32 #include "AliTRDclusterizer.h"
33 #include "AliTRDcluster.h"
34 #include "AliTRDrecPoint.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDcalibDB.h"
37
38 ClassImp(AliTRDclusterizer)
39
40 //_____________________________________________________________________________
41 AliTRDclusterizer::AliTRDclusterizer():TNamed()
42 {
43   //
44   // AliTRDclusterizer default constructor
45   //
46
47   fClusterTree = NULL;
48   fRecPoints   = 0;
49   fVerbose     = 0;
50
51 }
52
53 //_____________________________________________________________________________
54 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
55                   :TNamed(name, title)
56 {
57   //
58   // AliTRDclusterizer default constructor
59   //
60
61   fClusterTree = NULL;
62   fRecPoints   = 0;
63   fVerbose     = 0;
64
65 }
66
67 //_____________________________________________________________________________
68 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
69 {
70   //
71   // AliTRDclusterizer copy constructor
72   //
73
74   ((AliTRDclusterizer &) c).Copy(*this);
75
76 }
77
78 //_____________________________________________________________________________
79 AliTRDclusterizer::~AliTRDclusterizer()
80 {
81   //
82   // AliTRDclusterizer destructor
83   //
84
85   if (fRecPoints) {
86     fRecPoints->Delete();
87     delete fRecPoints;
88   }
89 }
90
91 //_____________________________________________________________________________
92 AliTRDclusterizer &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 //_____________________________________________________________________________
104 void AliTRDclusterizer::Copy(TObject &c) const
105 {
106   //
107   // Copy function
108   //
109
110   ((AliTRDclusterizer &) c).fClusterTree = NULL;
111   ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
112   ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
113
114 }
115
116 //_____________________________________________________________________________
117 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
118 {
119   //
120   // Opens the AliROOT file. Output and input are in the same file
121   //
122   TString evfoldname = AliConfig::GetDefaultEventFolderName();
123   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
124   if (!fRunLoader)
125     fRunLoader = AliRunLoader::Open(name);
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();
134   return kTRUE;
135 }
136
137
138 //_____________________________________________________________________________
139 Bool_t AliTRDclusterizer::OpenOutput()
140 {
141   //
142   // Open the output file
143   //
144
145   TObjArray *ioArray = 0;
146
147   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
148   loader->MakeTree("R");
149   fClusterTree = loader->TreeR();
150   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
151
152
153   return kTRUE;
154
155 }
156
157 //_____________________________________________________________________________
158 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
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
165   if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
166   gAlice = fRunLoader->GetAliRun();
167
168   if (!(gAlice)) {
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       }
176   }
177
178   // Import the Trees for the event nEvent in the file
179   fRunLoader->GetEvent(nEvent);
180   
181   return kTRUE;
182
183 }
184
185 //_____________________________________________________________________________
186 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
187 {
188   //
189   // Fills TRDcluster branch in the tree with the clusters 
190   // found in detector = det. For det=-1 writes the tree. 
191   //
192
193   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
194     printf("AliTRDclusterizer::WriteClusters -- ");
195     printf("Unexpected detector index %d.\n",det);
196     return kFALSE;
197   }
198  
199
200   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
201   if (!branch) {
202     TObjArray *ioArray = 0;
203     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
204   }
205
206   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
207
208     Int_t nRecPoints = RecPoints()->GetEntriesFast();
209     TObjArray *detRecPoints = new TObjArray(400);
210
211     for (Int_t i = 0; i < nRecPoints; i++) {
212       AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
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       }
220     }
221
222     branch->SetAddress(&detRecPoints);
223     fClusterTree->Fill();
224
225     delete detRecPoints;
226
227     return kTRUE;
228
229   }
230
231   if (det == -1) {
232
233     Info("WriteClusters","Writing the cluster tree %s for event %d."
234          ,fClusterTree->GetName(),fRunLoader->GetEventNumber());
235     /*
236     fClusterTree->Write();
237     AliTRDgeometry *geo = fTRD->GetGeometry();
238     geo->SetName("TRDgeometry");
239     geo->Write();
240     */
241     AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
242     loader->WriteRecPoints("OVERWRITE");
243   
244     return kTRUE;  
245
246   }
247   /*
248   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
249   loader->WriteDigits("OVERWRITE");
250   */
251   printf("AliTRDclusterizer::WriteClusters -- ");
252   printf("Unexpected detector index %d.\n",det);
253  
254   return kFALSE;  
255   
256 }
257
258
259 //_____________________________________________________________________________
260 AliTRDcluster* AliTRDclusterizer::AddCluster(Double_t *pos, Int_t timebin, Int_t det, Double_t amp
261                                    , Int_t *tracks, Double_t *sig, Int_t iType, Float_t center)
262 {
263   //
264   // Add a cluster for the TRD
265   //
266
267   AliTRDcluster *c = new AliTRDcluster();
268
269   c->SetDetector(det);
270   c->AddTrackIndex(tracks);
271   c->SetQ(amp);
272   c->SetX(pos[2]);
273   c->SetY(pos[0]);
274   c->SetZ(pos[1]);
275   c->SetSigmaY2(sig[0]);   
276   c->SetSigmaZ2(sig[1]);
277   c->SetLocalTimeBin(timebin);
278   c->SetCenter(center);
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);
298   return c;
299 }
300
301 //_____________________________________________________________________________
302 Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet, Int_t col, Int_t row)
303 {
304   //
305   // Calculates the local x position in the detector from the timebin, depends on the drift velocity
306   // and t0
307   //
308   
309   AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
310   if (!calibration)
311     return -1;
312
313   Float_t vdrift = calibration->GetVdrift(idet, col, row);  
314   Float_t t0 = calibration->GetT0(idet, col, row);
315   Float_t samplingFrequency = calibration->GetSamplingFrequency();
316
317   timebin -= t0;
318
319   return timebin / samplingFrequency * vdrift;
320 }