]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizer.cxx
Using AliLog (F.Carminati)
[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
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   fPar         = 0;
51
52 }
53
54 //_____________________________________________________________________________
55 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
56                   :TNamed(name, title)
57 {
58   //
59   // AliTRDclusterizer default constructor
60   //
61
62   fClusterTree = NULL;
63   fRecPoints   = 0;
64   fVerbose     = 0;
65   fPar         = 0;
66
67 }
68
69 //_____________________________________________________________________________
70 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
71 {
72   //
73   // AliTRDclusterizer copy constructor
74   //
75
76   ((AliTRDclusterizer &) c).Copy(*this);
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 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
95 {
96   //
97   // Assignment operator
98   //
99
100   if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
101   return *this;
102
103 }
104
105 //_____________________________________________________________________________
106 void AliTRDclusterizer::Copy(TObject &c) const
107 {
108   //
109   // Copy function
110   //
111
112   ((AliTRDclusterizer &) c).fClusterTree = NULL;
113   ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
114   ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
115   ((AliTRDclusterizer &) c).fPar         = 0;
116
117 }
118
119 //_____________________________________________________________________________
120 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
121 {
122   //
123   // Opens the AliROOT file. Output and input are in the same file
124   //
125   TString evfoldname = AliConfig::GetDefaultEventFolderName();
126   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
127   if (!fRunLoader)
128     fRunLoader = AliRunLoader::Open(name);
129   if (!fRunLoader)
130    {
131      Error("Open","Can not open session for file %s.",name);
132      return kFALSE;
133    }
134
135   OpenInput(nEvent);
136   OpenOutput();
137   return kTRUE;
138 }
139
140
141 //_____________________________________________________________________________
142 Bool_t AliTRDclusterizer::OpenOutput()
143 {
144   //
145   // Open the output file
146   //
147
148   TObjArray *ioArray = 0;
149
150   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
151   loader->MakeTree("R");
152   fClusterTree = loader->TreeR();
153   fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
154
155
156   return kTRUE;
157
158 }
159
160 //_____________________________________________________________________________
161 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
162 {
163   //
164   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
165   //
166
167   // Connect the AliRoot file containing Geometry, Kine, and Hits
168   if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
169   gAlice = fRunLoader->GetAliRun();
170
171   if (!(gAlice)) {
172     fRunLoader->LoadgAlice();
173     gAlice = fRunLoader->GetAliRun();
174       if (!(gAlice)) {
175         printf("AliTRDclusterizer::OpenInput -- ");
176         printf("Could not find AliRun object.\n");
177         return kFALSE;
178       }
179   }
180
181   // Import the Trees for the event nEvent in the file
182   fRunLoader->GetEvent(nEvent);
183   
184   return kTRUE;
185
186 }
187
188 //_____________________________________________________________________________
189 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
190 {
191   //
192   // Fills TRDcluster branch in the tree with the clusters 
193   // found in detector = det. For det=-1 writes the tree. 
194   //
195
196   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
197     printf("AliTRDclusterizer::WriteClusters -- ");
198     printf("Unexpected detector index %d.\n",det);
199     return kFALSE;
200   }
201  
202
203   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
204   if (!branch) {
205     TObjArray *ioArray = 0;
206     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
207   }
208
209   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
210
211     Int_t nRecPoints = RecPoints()->GetEntriesFast();
212     TObjArray *detRecPoints = new TObjArray(400);
213
214     for (Int_t i = 0; i < nRecPoints; i++) {
215       AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
216       if (det == c->GetDetector()) {
217         detRecPoints->AddLast(c);
218       }
219       else {
220         printf("AliTRDclusterizer::WriteClusters --");
221         printf("Attempt to write a cluster with unexpected detector index\n");
222       }
223     }
224
225     branch->SetAddress(&detRecPoints);
226     fClusterTree->Fill();
227
228     delete detRecPoints;
229
230     return kTRUE;
231
232   }
233
234   if (det == -1) {
235
236     Info("WriteClusters","Writing the cluster tree %s for event %d."
237          ,fClusterTree->GetName(),fRunLoader->GetEventNumber());
238     /*
239     fClusterTree->Write();
240     AliTRDgeometry *geo = fTRD->GetGeometry();
241     geo->SetName("TRDgeometry");
242     geo->Write();
243     fPar->Write();
244     */
245     AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
246     loader->WriteRecPoints("OVERWRITE");
247   
248     return kTRUE;  
249
250   }
251   /*
252   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
253   loader->WriteDigits("OVERWRITE");
254   */
255   printf("AliTRDclusterizer::WriteClusters -- ");
256   printf("Unexpected detector index %d.\n",det);
257  
258   return kFALSE;  
259   
260 }
261
262
263 //_____________________________________________________________________________
264 void AliTRDclusterizer::AddCluster(Double_t *pos, Int_t det, Double_t amp
265                                  , Int_t *tracks, Double_t *sig, Int_t iType)
266 {
267   //
268   // Add a cluster for the TRD
269   //
270
271   AliTRDcluster *c = new AliTRDcluster();
272
273   c->SetDetector(det);
274   c->AddTrackIndex(tracks);
275   c->SetQ(amp);
276   c->SetY(pos[0]);
277   c->SetZ(pos[1]);
278   c->SetSigmaY2(sig[0]);   
279   c->SetSigmaZ2(sig[1]);
280   c->SetLocalTimeBin(((Int_t) pos[2]));
281
282   switch (iType) {
283   case 0:
284     c->Set2pad();
285     break;
286   case 1:
287     c->Set3pad();
288     break;
289   case 2:
290     c->Set4pad();
291     break;
292   case 3:
293     c->Set5pad();
294     break;
295   case 4:
296     c->SetLarge();
297     break;
298   };
299
300   RecPoints()->Add(c);
301
302 }