]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Adding protected copy constructor and assignment operator
[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 "AliTRDparameter.h"
37 #include "AliTRDcalibDB.h"
38
39 ClassImp(AliTRDclusterizer)
40
41 //_____________________________________________________________________________
42 AliTRDclusterizer::AliTRDclusterizer():TNamed()
43 {
44   //
45   // AliTRDclusterizer default constructor
46   //
47
48   fClusterTree = NULL;
49   fRecPoints   = 0;
50   fVerbose     = 0;
51   fPar         = 0;
52
53 }
54
55 //_____________________________________________________________________________
56 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
57                   :TNamed(name, title)
58 {
59   //
60   // AliTRDclusterizer default constructor
61   //
62
63   fClusterTree = NULL;
64   fRecPoints   = 0;
65   fVerbose     = 0;
66   fPar         = 0;
67
68 }
69
70 //_____________________________________________________________________________
71 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
72 {
73   //
74   // AliTRDclusterizer copy constructor
75   //
76
77   ((AliTRDclusterizer &) c).Copy(*this);
78
79 }
80
81 //_____________________________________________________________________________
82 AliTRDclusterizer::~AliTRDclusterizer()
83 {
84   //
85   // AliTRDclusterizer destructor
86   //
87
88   if (fRecPoints) {
89     fRecPoints->Delete();
90     delete fRecPoints;
91   }
92 }
93
94 //_____________________________________________________________________________
95 AliTRDclusterizer &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 //_____________________________________________________________________________
107 void AliTRDclusterizer::Copy(TObject &c) const
108 {
109   //
110   // Copy function
111   //
112
113   ((AliTRDclusterizer &) c).fClusterTree = NULL;
114   ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
115   ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
116   ((AliTRDclusterizer &) c).fPar         = 0;
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   TString evfoldname = AliConfig::GetDefaultEventFolderName();
127   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
128   if (!fRunLoader)
129     fRunLoader = AliRunLoader::Open(name);
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();
138   return kTRUE;
139 }
140
141
142 //_____________________________________________________________________________
143 Bool_t AliTRDclusterizer::OpenOutput()
144 {
145   //
146   // Open the output file
147   //
148
149   TObjArray *ioArray = 0;
150
151   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
152   loader->MakeTree("R");
153   fClusterTree = loader->TreeR();
154   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
155
156
157   return kTRUE;
158
159 }
160
161 //_____________________________________________________________________________
162 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
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
169   if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
170   gAlice = fRunLoader->GetAliRun();
171
172   if (!(gAlice)) {
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       }
180   }
181
182   // Import the Trees for the event nEvent in the file
183   fRunLoader->GetEvent(nEvent);
184   
185   return kTRUE;
186
187 }
188
189 //_____________________________________________________________________________
190 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
191 {
192   //
193   // Fills TRDcluster branch in the tree with the clusters 
194   // found in detector = det. For det=-1 writes the tree. 
195   //
196
197   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
198     printf("AliTRDclusterizer::WriteClusters -- ");
199     printf("Unexpected detector index %d.\n",det);
200     return kFALSE;
201   }
202  
203
204   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
205   if (!branch) {
206     TObjArray *ioArray = 0;
207     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
208   }
209
210   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
211
212     Int_t nRecPoints = RecPoints()->GetEntriesFast();
213     TObjArray *detRecPoints = new TObjArray(400);
214
215     for (Int_t i = 0; i < nRecPoints; i++) {
216       AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
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       }
224     }
225
226     branch->SetAddress(&detRecPoints);
227     fClusterTree->Fill();
228
229     delete detRecPoints;
230
231     return kTRUE;
232
233   }
234
235   if (det == -1) {
236
237     Info("WriteClusters","Writing the cluster tree %s for event %d."
238          ,fClusterTree->GetName(),fRunLoader->GetEventNumber());
239     /*
240     fClusterTree->Write();
241     AliTRDgeometry *geo = fTRD->GetGeometry();
242     geo->SetName("TRDgeometry");
243     geo->Write();
244     fPar->Write();
245     */
246     AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
247     loader->WriteRecPoints("OVERWRITE");
248   
249     return kTRUE;  
250
251   }
252   /*
253   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
254   loader->WriteDigits("OVERWRITE");
255   */
256   printf("AliTRDclusterizer::WriteClusters -- ");
257   printf("Unexpected detector index %d.\n",det);
258  
259   return kFALSE;  
260   
261 }
262
263
264 //_____________________________________________________________________________
265 AliTRDcluster* AliTRDclusterizer::AddCluster(Double_t *pos, Int_t timebin, Int_t det, Double_t amp
266                                    , Int_t *tracks, Double_t *sig, Int_t iType, Float_t center)
267 {
268   //
269   // Add a cluster for the TRD
270   //
271
272   AliTRDcluster *c = new AliTRDcluster();
273
274   c->SetDetector(det);
275   c->AddTrackIndex(tracks);
276   c->SetQ(amp);
277   c->SetX(pos[2]);
278   c->SetY(pos[0]);
279   c->SetZ(pos[1]);
280   c->SetSigmaY2(sig[0]);   
281   c->SetSigmaZ2(sig[1]);
282   c->SetLocalTimeBin(timebin);
283   c->SetCenter(center);
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);
303   return c;
304 }
305
306 //_____________________________________________________________________________
307 Double_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 }