]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Implementing ESD functionality in the NewIO (Yu.Belikov)
[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)
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   fRunLoader = AliRunLoader::Open(name);
124   if (!fRunLoader)
125    {
126      Error("Open","Can not open session for file %s.",name);
127      return kFALSE;
128    }
129
130   OpenInput(nEvent);
131   OpenOutput();
132   return kTRUE;
133 }
134
135
136 //_____________________________________________________________________________
137 Bool_t AliTRDclusterizer::OpenOutput()
138 {
139   //
140   // Open the output file
141   //
142
143   TObjArray *ioArray = 0;
144
145   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
146   loader->MakeTree("R");
147   fClusterTree = loader->TreeR();
148   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
149
150
151   return kTRUE;
152
153 }
154
155 //_____________________________________________________________________________
156 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
157 {
158   //
159   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
160   //
161
162   // Connect the AliRoot file containing Geometry, Kine, and Hits
163   fRunLoader->LoadgAlice();
164   gAlice = fRunLoader->GetAliRun();
165
166   if (!(gAlice)) {
167     fRunLoader->LoadgAlice();
168     gAlice = fRunLoader->GetAliRun();
169       if (!(gAlice)) {
170         printf("AliTRDclusterizer::OpenInput -- ");
171         printf("Could not find AliRun object.\n");
172         return kFALSE;
173       }
174   }
175
176   fEvent = nEvent;
177
178   // Import the Trees for the event nEvent in the file
179   fRunLoader->GetEvent(fEvent);
180   
181   // Get the TRD object
182   fTRD = (AliTRD*) gAlice->GetDetector("TRD"); 
183   if (!fTRD) {
184     printf("AliTRDclusterizer::OpenInput -- ");
185     printf("No TRD detector object found\n");
186     return kFALSE;
187   }
188
189   return kTRUE;
190
191 }
192
193 //_____________________________________________________________________________
194 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
195 {
196   //
197   // Fills TRDcluster branch in the tree with the clusters 
198   // found in detector = det. For det=-1 writes the tree. 
199   //
200
201   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
202     printf("AliTRDclusterizer::WriteClusters -- ");
203     printf("Unexpected detector index %d.\n",det);
204     return kFALSE;
205   }
206  
207
208   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
209   if (!branch) {
210     TObjArray *ioArray = 0;
211     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
212   }
213
214   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
215
216     Int_t nRecPoints = fTRD->RecPoints()->GetEntriesFast();
217     TObjArray *detRecPoints = new TObjArray(400);
218
219     for (Int_t i = 0; i < nRecPoints; i++) {
220       AliTRDcluster *c = (AliTRDcluster *) fTRD->RecPoints()->UncheckedAt(i);
221       if (det == c->GetDetector()) {
222         detRecPoints->AddLast(c);
223       }
224       else {
225         printf("AliTRDclusterizer::WriteClusters --");
226         printf("Attempt to write a cluster with unexpected detector index\n");
227       }
228     }
229
230     branch->SetAddress(&detRecPoints);
231     fClusterTree->Fill();
232
233     return kTRUE;
234
235   }
236
237   if (det == -1) {
238
239     printf("AliTRDclusterizer::WriteClusters -- ");
240     printf("Writing the cluster tree %-18s for event %d.\n"
241           ,fClusterTree->GetName(),fEvent);
242     /*
243     fClusterTree->Write();
244     AliTRDgeometry *geo = fTRD->GetGeometry();
245     geo->SetName("TRDgeometry");
246     geo->Write();
247     fPar->Write();
248     */
249     AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
250     loader->WriteRecPoints("OVERWRITE");
251   
252     return kTRUE;  
253
254   }
255   /*
256   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
257   loader->WriteDigits("OVERWRITE");
258   */
259   printf("AliTRDclusterizer::WriteClusters -- ");
260   printf("Unexpected detector index %d.\n",det);
261  
262   return kFALSE;  
263   
264 }
265
266
267