next50 trigger mask in AliHLTGlobalEsdConverterComponent
[u/mrichter/AliRoot.git] / TRD / Macros / AliTRDTracking.C
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // AliTRDTracking.C 
4 //
5 // date: 06.02.2003
6 // author: Thomas Kuhr based on AliTPCTracking.C
7 // version: 1.0
8 // description: 
9 //      reconstructs of tracks in TRD in the following steps:
10 //         TRD cluster finding
11 //         TRD track finding
12 // input parameters: 
13 //        Int_t nEvents      ... nr of events to process
14 //        Int_t firstEventNr ... first event number (starts from 0)
15 //        const char* fileNameParam ... name of file with TPC parameters
16 //        const char* fileNameHits ... name of file with hits
17 //        const char* fileNameDigits .. name of file with TRD digits
18 //        const char* fileNameSeeds .. name of file with TPC track seeds
19 //        const char* fileNameClusters .. name of file with TRD clusters (output)
20 //        const char* fileNameTracks .. name of file with TRD tracks (output)
21 //
22 //        default file names correspond to pp production (2002-04)
23 //
24 ////////////////////////////////////////////////////////////////////////
25
26 #if !defined(__CINT__) || defined(__MAKECINT__)
27 #include "Riostream.h"
28 #include "TFile.h"
29 #include "TBenchmark.h"
30 #include "AliTRD.h"
31 #include "AliTRDparameter.h"
32 #include "AliTRDtracker.h"
33 #include "AliTRDclusterizerV1.h"
34 #include "AliTPC.h"
35 #include "AliTPCParamSR.h"
36 #include "AliTPCtracker.h"
37 #include "AliITS.h"
38 #include "AliITSgeom.h"
39 #include "AliITStrackerV2.h"
40 #include "AliRun.h"
41 #endif
42
43 Int_t gDEBUG = 2;
44
45 Int_t AliTRDTracking(Int_t nEvents=1, Int_t firstEvent=0,
46                      const char* fileNameParam="trd.sdigits.root",
47                      const char* fileNameDigits="trd.digits.root",
48                      const char* fileNameSeed="tpc.tracks.root",
49                      const char* fileNameClusters="trd.clusters.root",
50                      const char* fileNameTracks="trd.tracks.root");
51
52 Bool_t ITSPropagateBack(Int_t nEvents=1, Int_t firstEvent=0,
53                         const char* fileNameClusters="its.clusters.root",
54                         const char* fileNameTracks="its.tracks.root",
55                         const char* fileNameBackTracks="its.back.tracks.root");
56 Bool_t TPCPropagateBack(Int_t nEvents=1, Int_t firstEvent=0,
57                         const char* fileNameClusters="tpc.clusters.root",
58                         const char* fileNameTracks="tpc.tracks.root",
59                         const char* fileNameITSBackTracks="its.back.tracks.root",
60                         const char* fileNameBackTracks="tpc.back.tracks.root");
61 Bool_t TRDFindClusters(Int_t nEvents=1, Int_t firstEvent=0,
62                       const char* fileNameParam="trd.sdigits.root", 
63                       const char* fileNameDigits="trd.digits.root", 
64                       const char* fileNameClusters="trd.clusters.root");
65 Bool_t TRDFindTracks(Int_t nEvents=1, Int_t firstEvent=0,
66                     const char* fileNameSeeds="tpc.tracks.root",
67                     const char* fileNameClusters="trd.clusters.root",
68                     const char* fileNameTracks="trd.tracks.root",
69                      Bool_t inwards = kTRUE, Bool_t addSeeds = kTRUE);
70
71
72 ////////////////////////////////////////////////////////////////////////
73 Int_t AliTRDTracking( Int_t nEvents, Int_t firstEvent,
74                       const char* fileNameParam,
75                       const char* fileNameDigits,
76                       const char* fileNameSeeds,
77                       const char* fileNameClusters,
78                       const char* fileNameTracks) {
79
80   AliTracker::SetFieldFactor(fileNameParam,kFALSE);
81
82 // ********** Find TRD clusters *********** //
83   if (fileNameParam && fileNameDigits && fileNameClusters){
84     if (!TRDFindClusters(nEvents,firstEvent,fileNameParam,fileNameDigits,fileNameClusters)) {
85       cerr<<"Failed to get TRD clusters: !\n";
86       return 1;
87     }
88   }      
89
90 // ********** Find TRD tracks *********** //
91   if (fileNameSeeds && fileNameClusters && fileNameTracks) {
92     if (!TRDFindTracks(nEvents,firstEvent,fileNameSeeds,fileNameClusters,fileNameTracks)) {
93       cerr<<"Failed to get TRD tracks !\n";
94       return 2;
95     }
96   }
97
98   return 0;
99 }
100
101 ////////////////////////////////////////////////////////////////////////
102 ////////////////////////////////////////////////////////////////////////
103 Bool_t ITSPropagateBack(Int_t nEvents, Int_t firstEvent,
104                         const char* fileNameClusters,
105                         const char* fileNameTracks,
106                         const char* fileNameBackTracks)
107 {
108   const char *name="ITSPropagateBack";
109   if (gDEBUG>1) cout<<name<<" starts...\n";
110   if (gDEBUG>1) gBenchmark->Start(name);
111
112   TFile* clustersFile = TFile::Open(fileNameClusters);
113   if (!clustersFile->IsOpen()) {
114     cerr<<"Cannot open "<<fileNameClusters<<" !\n"; 
115     return kFALSE;
116   }
117   TFile* tracksFile = NULL;
118   TFile* backTracksFile = NULL;
119   if (strcmp(fileNameTracks, fileNameBackTracks) == 0) {
120     tracksFile = backTracksFile = TFile::Open(fileNameTracks, "UPDATE");
121   } else {
122     backTracksFile = TFile::Open(fileNameBackTracks, "RECREATE");
123     tracksFile = TFile::Open(fileNameTracks);
124   }
125   if (!tracksFile->IsOpen()) {
126     cerr<<"Cannot open "<<fileNameTracks<<" !\n"; 
127     return kFALSE;
128   }
129
130   gROOT->cd();
131   AliITSgeom* geom = (AliITSgeom*) clustersFile->Get("AliITSgeom");
132   AliITStrackerV2 tracker(geom);
133   clustersFile->cd();
134
135   for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++) {
136     tracker.SetEventNumber(iEvent);
137     tracker.PropagateBack(tracksFile, backTracksFile);
138   }
139
140   if (tracksFile != backTracksFile) {
141     backTracksFile->Close();
142     delete backTracksFile;
143   }
144   tracksFile->Close();
145   delete tracksFile;
146   clustersFile->Close();
147   delete clustersFile;
148
149   if (gDEBUG>1) gBenchmark->Show(name);
150   return kTRUE;
151 }
152 ////////////////////////////////////////////////////////////////////////
153 Bool_t TPCPropagateBack(Int_t nEvents, Int_t firstEvent,
154                         const char* fileNameClusters,
155                         const char* fileNameTracks,
156                         const char* fileNameITSBackTracks,
157                         const char* fileNameBackTracks)
158 {
159   const char *name="TPCPropagateBack";
160   if (gDEBUG>1) cout<<name<<" starts...\n";
161   if (gDEBUG>1) gBenchmark->Start(name);
162
163   TFile* clustersFile = TFile::Open(fileNameClusters);
164   if (!clustersFile->IsOpen()) {
165     cerr<<"Cannot open "<<fileNameClusters<<" !\n"; 
166     return kFALSE;
167   }
168   TFile* itsBackFile = NULL;
169   if (fileNameITSBackTracks) {
170     itsBackFile = TFile::Open(fileNameITSBackTracks);
171     if (!itsBackFile->IsOpen()) {
172       cerr<<"Cannot open "<<fileNameITSBackTracks<<" !\n"; 
173       return kFALSE;
174     }
175   }
176   TFile* tracksFile = NULL;
177   TFile* backTracksFile = NULL;
178   if (strcmp(fileNameTracks, fileNameBackTracks) == 0) {
179     tracksFile = backTracksFile = TFile::Open(fileNameTracks, "UPDATE");
180   } else {
181     backTracksFile = TFile::Open(fileNameBackTracks, "RECREATE");
182     tracksFile = TFile::Open(fileNameTracks);
183   }
184   if (!tracksFile->IsOpen()) {
185     cerr<<"Cannot open "<<fileNameTracks<<" !\n"; 
186     return kFALSE;
187   }
188
189   gROOT->cd();
190   AliTPCParam* tpcParam = (AliTPCParam*) 
191     clustersFile->Get("75x40_100x60_150x60");
192   if (!tpcParam) tpcParam = new AliTPCParamSR;
193   AliTPCtracker tracker(tpcParam);
194   clustersFile->cd();
195
196   for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++) {
197     tracker.SetEventNumber(iEvent);
198     tracker.PropagateBack(tracksFile, itsBackFile, backTracksFile);
199   }
200
201   if (tracksFile != backTracksFile) {
202     backTracksFile->Close();
203     delete backTracksFile;
204   }
205   tracksFile->Close();
206   delete tracksFile;
207   clustersFile->Close();
208   delete clustersFile;
209
210   if (gDEBUG>1) gBenchmark->Show(name);
211   return kTRUE;
212 }
213 ////////////////////////////////////////////////////////////////////////
214 Bool_t TRDFindClusters(Int_t nEvents, Int_t firstEvent,
215                       const char* fileNameParam, 
216                       const char* fileNameDigits, const char* fileNameClusters) {
217   
218   const char *name="TRDFindClusters";
219   if (gDEBUG>1) cout<<name<<" starts...\n";
220   if (gDEBUG>1) gBenchmark->Start(name);
221
222   TFile* paramFile = TFile::Open(fileNameParam);
223   if (!paramFile->IsOpen()) {
224     cerr<<"Cannot open "<<fileNameParam<<" !\n"; 
225     return kFALSE;
226   }
227   AliTRDparameter* trdParam = 
228     (AliTRDparameter*) paramFile->Get("TRDparameter"); 
229   if (!trdParam) {
230     cerr << "TRD parameters have not been found !\n"; 
231     return kFALSE;
232   }
233   trdParam->ReInit();
234   AliTRDclusterizerV1 clusterizer("clusterizer", "Clusterizer class"); 
235   clusterizer.SetParameter(trdParam);
236
237   for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++) {
238     clusterizer.Open(fileNameDigits, fileNameClusters, iEvent);
239     clusterizer.ReadDigits();
240     clusterizer.MakeClusters();
241     clusterizer.WriteClusters(-1);
242   }
243
244   paramFile->Close();
245   delete paramFile;
246
247   if (gDEBUG>1) gBenchmark->Show(name);
248   return kTRUE;
249 }
250 ////////////////////////////////////////////////////////////////////////
251 Bool_t TRDFindTracks(Int_t nEvents, Int_t firstEvent,
252                     const char* fileNameSeeds,
253                      const char* fileNameClusters, const char* fileNameTracks,
254                      Bool_t inwards, Bool_t addSeeds) {
255
256   const char *name="TRDFindTracks";
257   if (gDEBUG>1) cout<<name<<" starts...\n";
258   if (gDEBUG>1) gBenchmark->Start(name);
259
260   TFile* seedsFile = TFile::Open(fileNameSeeds);
261   if (!seedsFile->IsOpen()) {
262     cerr<<"Cannot open "<<fileNameSeeds<<" !\n"; 
263     return kFALSE;
264   }
265   TFile* clustersFile = TFile::Open(fileNameClusters);
266   if (!clustersFile->IsOpen()) {
267     cerr<<"Cannot open "<<fileNameClusters<<" !\n"; 
268     return kFALSE;
269   }
270   TFile* tracksFile = TFile::Open(fileNameTracks, "recreate");
271   if (!tracksFile->IsOpen()) {
272     cerr<<"Cannot open "<<fileNameTracks<<" !\n"; 
273     return kFALSE;
274   }
275
276   AliTRDtracker tracker(clustersFile);
277   if (addSeeds) tracker.SetAddTRDseeds();
278   clustersFile->cd();  
279   for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++) {
280     printf("Processing event %d\n", iEvent);
281     tracker.SetEventNumber(iEvent);
282     tracker.PropagateBack(seedsFile, tracksFile);
283     if (inwards) tracker.Clusters2Tracks(tracksFile, tracksFile);
284   }
285
286   seedsFile->Close();
287   delete seedsFile;
288   clustersFile->Close();
289   delete clustersFile;
290   tracksFile->Close();
291   delete tracksFile;
292
293   if (gDEBUG>1) gBenchmark->Show(name);
294   return kTRUE;
295 }
296