]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
d04fb07aede739ffa45a70e8d22f9dc5a3707b1e
[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 "AliTRD.h"
33 #include "AliTRDclusterizer.h"
34 #include "AliTRDcluster.h"
35 #include "AliTRDrecPoint.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDparameter.h"
38
39 ClassImp(AliTRDclusterizer)
40
41 //_____________________________________________________________________________
42 AliTRDclusterizer::AliTRDclusterizer():TNamed()
43 {
44   //
45   // AliTRDclusterizer default constructor
46   //
47
48   fClusterTree = NULL;
49   fTRD         = 0;
50   fEvent       = 0;
51   fVerbose     = 0;
52   fPar         = 0;
53
54 }
55
56 //_____________________________________________________________________________
57 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
58                   :TNamed(name, title)
59 {
60   //
61   // AliTRDclusterizer default constructor
62   //
63
64   fClusterTree = NULL;
65   fEvent       = 0;
66   fVerbose     = 0;
67   fPar         = 0;
68
69 }
70
71 //_____________________________________________________________________________
72 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
73 {
74   //
75   // AliTRDclusterizer copy constructor
76   //
77
78   ((AliTRDclusterizer &) c).Copy(*this);
79
80 }
81
82 //_____________________________________________________________________________
83 AliTRDclusterizer::~AliTRDclusterizer()
84 {
85   //
86   // AliTRDclusterizer destructor
87   //
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)
105 {
106   //
107   // Copy function
108   //
109
110   ((AliTRDclusterizer &) c).fClusterTree = NULL;
111   ((AliTRDclusterizer &) c).fEvent       = 0;  
112   ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
113   ((AliTRDclusterizer &) c).fPar         = 0;
114
115 }
116
117 //_____________________________________________________________________________
118 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
119 {
120   //
121   // Opens the AliROOT file. Output and input are in the same file
122   //
123   TString evfoldname = AliConfig::GetDefaultEventFolderName();
124   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
125   if (!fRunLoader)
126     fRunLoader = AliRunLoader::Open(name);
127   if (!fRunLoader)
128    {
129      Error("Open","Can not open session for file %s.",name);
130      return kFALSE;
131    }
132
133   OpenInput(nEvent);
134   OpenOutput();
135   return kTRUE;
136 }
137
138
139 //_____________________________________________________________________________
140 Bool_t AliTRDclusterizer::OpenOutput()
141 {
142   //
143   // Open the output file
144   //
145
146   TObjArray *ioArray = 0;
147
148   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
149   loader->MakeTree("R");
150   fClusterTree = loader->TreeR();
151   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
152
153
154   return kTRUE;
155
156 }
157
158 //_____________________________________________________________________________
159 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
160 {
161   //
162   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
163   //
164
165   // Connect the AliRoot file containing Geometry, Kine, and Hits
166   if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
167   gAlice = fRunLoader->GetAliRun();
168
169   if (!(gAlice)) {
170     fRunLoader->LoadgAlice();
171     gAlice = fRunLoader->GetAliRun();
172       if (!(gAlice)) {
173         printf("AliTRDclusterizer::OpenInput -- ");
174         printf("Could not find AliRun object.\n");
175         return kFALSE;
176       }
177   }
178
179   fEvent = nEvent;
180
181   // Import the Trees for the event nEvent in the file
182   fRunLoader->GetEvent(fEvent);
183   
184   // Get the TRD object
185   fTRD = (AliTRD*) gAlice->GetDetector("TRD"); 
186   if (!fTRD) {
187     printf("AliTRDclusterizer::OpenInput -- ");
188     printf("No TRD detector object found\n");
189     return kFALSE;
190   }
191
192   return kTRUE;
193
194 }
195
196 //_____________________________________________________________________________
197 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
198 {
199   //
200   // Fills TRDcluster branch in the tree with the clusters 
201   // found in detector = det. For det=-1 writes the tree. 
202   //
203
204   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
205     printf("AliTRDclusterizer::WriteClusters -- ");
206     printf("Unexpected detector index %d.\n",det);
207     return kFALSE;
208   }
209  
210
211   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
212   if (!branch) {
213     TObjArray *ioArray = 0;
214     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
215   }
216
217   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
218
219     Int_t nRecPoints = fTRD->RecPoints()->GetEntriesFast();
220     TObjArray *detRecPoints = new TObjArray(400);
221
222     for (Int_t i = 0; i < nRecPoints; i++) {
223       AliTRDcluster *c = (AliTRDcluster *) fTRD->RecPoints()->UncheckedAt(i);
224       if (det == c->GetDetector()) {
225         detRecPoints->AddLast(c);
226       }
227       else {
228         printf("AliTRDclusterizer::WriteClusters --");
229         printf("Attempt to write a cluster with unexpected detector index\n");
230       }
231     }
232
233     branch->SetAddress(&detRecPoints);
234     fClusterTree->Fill();
235
236     delete detRecPoints;
237
238     return kTRUE;
239
240   }
241
242   if (det == -1) {
243
244     Info("WriteClusters","Writing the cluster tree %s for event %d."
245          ,fClusterTree->GetName(),fEvent);
246     /*
247     fClusterTree->Write();
248     AliTRDgeometry *geo = fTRD->GetGeometry();
249     geo->SetName("TRDgeometry");
250     geo->Write();
251     fPar->Write();
252     */
253     AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
254     loader->WriteRecPoints("OVERWRITE");
255   
256     return kTRUE;  
257
258   }
259   /*
260   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
261   loader->WriteDigits("OVERWRITE");
262   */
263   printf("AliTRDclusterizer::WriteClusters -- ");
264   printf("Unexpected detector index %d.\n",det);
265  
266   return kFALSE;  
267   
268 }
269
270
271