New AliTRDcluster constructor
[u/mrichter/AliRoot.git] / TOF / AliTOFReconstructor.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 // class for TOF reconstruction                                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "TFile.h"
25
26 #include "AliLog.h"
27 #include "AliRawReader.h"
28 #include "AliRunLoader.h"
29
30 #include "AliTOFClusterFinder.h"
31 #include "AliTOFGeometry.h"
32 #include "AliTOFGeometryV5.h"
33 #include "AliTOFcalib.h"
34 #include "AliTOFtrackerMI.h"
35 #include "AliTOFtracker.h"
36 #include "AliTOFReconstructor.h"
37
38 class TTree;
39
40 class AliESD;
41
42 extern TDirectory *gDirectory;
43 extern TFile *gFile;
44
45 ClassImp(AliTOFReconstructor)
46
47  //____________________________________________________________________
48 AliTOFReconstructor::AliTOFReconstructor() 
49   : AliReconstructor(),
50     fTOFGeometry(0),
51     fTOFcalib(0)
52 {
53 //
54 // ctor
55 //
56   //Retrieving the TOF calibration info  
57   fTOFGeometry = new AliTOFGeometryV5();
58   fTOFcalib    = new AliTOFcalib(fTOFGeometry);
59   if(!fTOFcalib->ReadParFromCDB("TOF/Calib",-1)) {AliFatal("Exiting, no CDB object found!!!");exit(0);}  
60 }
61
62 //------------------------------------------------------------------------
63 AliTOFReconstructor::AliTOFReconstructor(const AliTOFReconstructor &source)
64   : AliReconstructor(),
65     fTOFGeometry(0),
66     fTOFcalib(0)
67 {
68 //
69 // copy ctor
70 //
71   this->fTOFGeometry=source.fTOFGeometry;
72   this->fTOFcalib=source.fTOFcalib;
73 }
74
75 //------------------------------------------------------------------------
76 AliTOFReconstructor & AliTOFReconstructor::operator=(const AliTOFReconstructor &source)
77 {
78 //
79 // assignment op.
80 //
81   this->fTOFGeometry=source.fTOFGeometry;
82   this->fTOFcalib=source.fTOFcalib;
83   return *this;
84 }
85 //_____________________________________________________________________________
86 AliTOFReconstructor::~AliTOFReconstructor() 
87 {
88 //
89 // dtor
90 //
91   delete fTOFGeometry;
92   delete fTOFcalib;
93 }
94
95 //_____________________________________________________________________________
96   void AliTOFReconstructor::Reconstruct(AliRunLoader* runLoader) const
97 {
98 // reconstruct clusters from digits
99
100   AliTOFClusterFinder tofClus(runLoader, fTOFcalib);
101   tofClus.Load();
102   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++)
103     {
104       AliDebug(2,Form("Local Event loop mode: Creating Recpoints from Digits, Event n. %i",iEvent)); 
105       tofClus.Digits2RecPoints(iEvent);
106     }
107   tofClus.UnLoad();
108
109 }
110
111 //_____________________________________________________________________________
112 void AliTOFReconstructor::Reconstruct(AliRunLoader* runLoader,
113                                       AliRawReader *rawReader) const
114 {
115 // reconstruct clusters from Raw Data
116
117   AliTOFClusterFinder tofClus(runLoader, fTOFcalib);
118   tofClus.LoadClusters();
119   Int_t iEvent = 0;
120   while (rawReader->NextEvent()) {
121     AliDebug(2,Form("Local Event loop mode: Creating Recpoints from Raw data, Event n. %i",iEvent)); 
122     tofClus.Digits2RecPoints(iEvent,rawReader);
123     iEvent++;
124   }
125   tofClus.UnLoadClusters();
126
127 }
128
129 //_____________________________________________________________________________
130 void AliTOFReconstructor::Reconstruct(AliRawReader *rawReader,
131                                       TTree *clustersTree) const
132 {
133 // reconstruct clusters from Raw Data
134
135   AliTOFClusterFinder tofClus(fTOFcalib);
136   tofClus.Digits2RecPoints(rawReader, clustersTree);
137
138 }
139
140 //_____________________________________________________________________________
141 void AliTOFReconstructor::Reconstruct(TTree *digitsTree,
142                                       TTree *clustersTree) const
143 {
144 // reconstruct clusters from Raw Data
145
146   AliDebug(2,Form("Global Event loop mode: Creating Recpoints from Digits Tree")); 
147   AliTOFClusterFinder tofClus(fTOFcalib);
148   tofClus.Digits2RecPoints(digitsTree, clustersTree);
149
150 }
151 //_____________________________________________________________________________
152   void AliTOFReconstructor::ConvertDigits(AliRawReader* reader, TTree* digitsTree) const
153 {
154 // reconstruct clusters from digits
155
156   AliDebug(2,Form("Global Event loop mode: Converting Raw Data to a Digits Tree")); 
157   AliTOFClusterFinder tofClus(fTOFcalib);
158   tofClus.Raw2Digits(reader, digitsTree);
159
160 }
161
162 //_____________________________________________________________________________
163 AliTracker* AliTOFReconstructor::CreateTracker(AliRunLoader* /*runLoader*/) const
164 {
165 // create a TOF tracker
166
167   TString selectedTracker = GetOption();
168   // use MI tracker if selected
169   if (selectedTracker.Contains("MI")) return new AliTOFtrackerMI();
170   return new AliTOFtracker();
171 }
172
173 //_____________________________________________________________________________
174 void AliTOFReconstructor::FillESD(AliRunLoader* /*runLoader*/, 
175                                   AliESD* /*esd*/) const
176 {
177 // nothing to be done
178
179 }
180
181 //_____________________________________________________________________________
182 AliTOFGeometry* AliTOFReconstructor::GetTOFGeometry(AliRunLoader* runLoader) const
183 {
184 // get the TOF parameters
185
186   AliTOFGeometry *tofGeom;
187
188   runLoader->CdGAFile();
189   TDirectory *savedir=gDirectory; 
190   TFile *in=(TFile*)gFile;  
191   if (!in->IsOpen()) {
192     AliWarning("Geometry file is not open default  TOF geometry will be used");
193     tofGeom = new AliTOFGeometryV5();
194   }
195   else {
196     in->cd();  
197     tofGeom = (AliTOFGeometry*) in->Get("TOFgeometry");
198   }
199
200   savedir->cd();  
201
202   if (!tofGeom) {
203     AliError("no TOF geometry available");
204     return NULL;
205   }
206   return tofGeom;
207 }