]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
And some more effc++
[u/mrichter/AliRoot.git] / TRD / AliTRDReconstructor.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 TRD reconstruction                                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TFile.h>
25
26 #include "AliRunLoader.h"
27 #include "AliRawReader.h"
28 #include "AliLog.h"
29 #include "AliRun.h"
30 #include "AliESDTrdTrack.h"
31 #include "AliESD.h"
32
33 #include "AliTRDReconstructor.h"
34 #include "AliTRDclusterizerV1.h"
35 #include "AliTRDtracker.h"
36 #include "AliTRDpidESD.h"
37 #include "AliTRDtrigger.h"
38 #include "AliTRDtrigParam.h"
39 #include "AliTRDgtuTrack.h"
40
41 ClassImp(AliTRDReconstructor)
42
43 Bool_t AliTRDReconstructor::fgkSeedingOn  = kFALSE;
44 Int_t  AliTRDReconstructor::fgStreamLevel = 0;      // Stream (debug) level
45
46 //_____________________________________________________________________________
47 void AliTRDReconstructor::Reconstruct(AliRunLoader *runLoader) const
48 {
49   //
50   // Reconstruct clusters
51   //
52
53   AliLoader *loader = runLoader->GetLoader("TRDLoader");
54   loader->LoadRecPoints("recreate");
55
56   runLoader->CdGAFile();
57   Int_t nEvents = runLoader->GetNumberOfEvents();
58
59   for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
60     AliTRDclusterizerV1 clusterer("clusterer","TRD clusterizer");
61     clusterer.Open(runLoader->GetFileName(),iEvent);
62     clusterer.ReadDigits();
63     clusterer.MakeClusters();
64     clusterer.WriteClusters(-1);
65   }
66
67   loader->UnloadRecPoints();
68
69   //
70   // Trigger (tracklets, LTU)
71   //
72   loader->LoadTracks("RECREATE");
73   AliInfo("Trigger tracklets will be produced");
74
75   AliTRDtrigger trdTrigger("Trigger","Trigger class"); 
76
77   AliTRDtrigParam *trigp = new AliTRDtrigParam("TRDtrigParam"
78                                               ,"TRD Trigger parameters");
79
80   if (runLoader->GetAliRun() == 0x0) {
81     runLoader->LoadgAlice();
82   }
83   gAlice = runLoader->GetAliRun();
84   Double_t x[3]  = { 0.0, 0.0, 0.0 };
85   Double_t b[3];
86   gAlice->Field(x,b);          // b[] is in kilo Gauss
87   Float_t  field = b[2] * 0.1; // Tesla
88   AliInfo(Form("Trigger set for magnetic field = %f Tesla \n",field));
89
90   trigp->SetField(field);
91   trigp->Init();
92   trdTrigger.SetParameter(trigp);
93
94   for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
95     trdTrigger.Open(runLoader->GetFileName(),iEvent);
96     trdTrigger.ReadDigits();
97     trdTrigger.MakeTracklets();
98     trdTrigger.WriteTracklets(-1);
99   }
100
101   loader->UnloadTracks();
102
103 }
104
105 //_____________________________________________________________________________
106 void AliTRDReconstructor::Reconstruct(AliRunLoader *runLoader
107                                     , AliRawReader *rawReader) const
108 {
109   //
110   // Reconstruct clusters
111   //
112
113   AliInfo("Reconstruct TRD clusters from RAW data");
114
115   AliLoader *loader = runLoader->GetLoader("TRDLoader");
116   loader->LoadRecPoints("recreate");
117
118   runLoader->CdGAFile();
119   Int_t nEvents = runLoader->GetNumberOfEvents();
120
121   for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
122     if (!rawReader->NextEvent()) break;
123     AliTRDclusterizerV1 clusterer("clusterer","TRD clusterizer");
124     clusterer.Open(runLoader->GetFileName(),iEvent);
125     clusterer.ReadDigits(rawReader);
126     clusterer.MakeClusters();
127     clusterer.WriteClusters(-1);
128   }
129
130   loader->UnloadRecPoints();
131
132   //
133   // Trigger (tracklets, LTU)
134   //
135   loader->LoadTracks();
136   if (loader->TreeT()) {
137     AliError("Tracklets already exist");
138     return;
139   }
140   AliInfo("Trigger tracklets will be produced");
141
142   AliTRDtrigger trdTrigger("Trigger","Trigger class"); 
143
144   AliTRDtrigParam *trigp = new AliTRDtrigParam("TRDtrigParam"
145                                               ,"TRD Trigger parameters");
146
147   if (runLoader->GetAliRun() == 0x0) {
148     runLoader->LoadgAlice();
149   }
150   gAlice = runLoader->GetAliRun();
151   Double_t x[3]  = { 0.0, 0.0, 0.0 };
152   Double_t b[3];
153   gAlice->Field(x,b);          // b[] is in kilo Gauss
154   Float_t  field = b[2] * 0.1; // Tesla
155   AliInfo(Form("Trigger set for magnetic field = %f Tesla \n",field));
156
157   trigp->SetField(field);
158   trigp->Init();
159   trdTrigger.SetParameter(trigp);
160
161   rawReader->RewindEvents();
162
163   for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
164     if (!rawReader->NextEvent()) break;
165     trdTrigger.Open(runLoader->GetFileName(),iEvent);
166     trdTrigger.ReadDigits(rawReader);
167     trdTrigger.MakeTracklets();
168     trdTrigger.WriteTracklets(-1);
169   }
170
171   loader->UnloadTracks();
172
173 }
174
175 //_____________________________________________________________________________
176 AliTracker *AliTRDReconstructor::CreateTracker(AliRunLoader *runLoader) const
177 {
178   //
179   // Create a TRD tracker
180   //
181
182   runLoader->CdGAFile();
183
184   return new AliTRDtracker(gFile);
185
186 }
187
188 //_____________________________________________________________________________
189 void AliTRDReconstructor::FillESD(AliRunLoader *runLoader
190                                  , AliESD *esd) const
191 {
192   //
193   // Make PID
194   //
195
196   AliTRDpidESD trdPID;
197   trdPID.MakePID(esd);
198
199   //
200   // Trigger (tracks, GTU)
201   //
202   AliTRDtrigger trdTrigger("Trigger","Trigger class"); 
203
204   AliTRDtrigParam *trigp = new AliTRDtrigParam("TRDtrigParam"
205                                               ,"TRD Trigger parameters");
206
207   if (runLoader->GetAliRun() == 0x0) {
208     runLoader->LoadgAlice();
209   }
210   gAlice = runLoader->GetAliRun();
211   Double_t x[3]  = { 0.0, 0.0, 0.0 };
212   Double_t b[3];
213   gAlice->Field(x,b);          // b[] is in kilo Gauss
214   Float_t  field = b[2] * 0.1; // Tesla
215   AliInfo(Form("Trigger set for magnetic field = %f Tesla \n",field));
216
217   trigp->SetField(field);
218   trigp->Init();
219
220   trdTrigger.SetParameter(trigp);
221   trdTrigger.SetRunLoader(runLoader);
222   trdTrigger.Init();
223
224   Int_t iEvent = runLoader->GetEventNumber(); 
225   runLoader->GetEvent(iEvent);
226   trdTrigger.ReadTracklets(runLoader);
227
228   AliESDTrdTrack *TrdTrack = new AliESDTrdTrack();
229   AliTRDgtuTrack *GtuTrack;
230
231   Int_t nTracks = trdTrigger.GetNumberOfTracks();
232   for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
233
234     GtuTrack = trdTrigger.GetTrack(iTrack);
235
236     TrdTrack->SetYproj(GtuTrack->GetYproj());
237     TrdTrack->SetZproj(GtuTrack->GetZproj());
238     TrdTrack->SetSlope(GtuTrack->GetSlope());
239     TrdTrack->SetDetector(GtuTrack->GetDetector());
240     TrdTrack->SetTracklets(GtuTrack->GetTracklets());
241     TrdTrack->SetPlanes(GtuTrack->GetPlanes());
242     TrdTrack->SetClusters(GtuTrack->GetClusters());
243     TrdTrack->SetPt(GtuTrack->GetPt());
244     TrdTrack->SetPhi(GtuTrack->GetPhi());
245     TrdTrack->SetEta(GtuTrack->GetEta());
246     TrdTrack->SetLabel(GtuTrack->GetLabel());
247     TrdTrack->SetPID(GtuTrack->GetPID());
248     TrdTrack->SetIsElectron(GtuTrack->IsElectron());
249
250     esd->AddTrdTrack(TrdTrack);
251
252   }
253
254 }