Changes due to the coding conventions
[u/mrichter/AliRoot.git] / TPC / AliTPCTracking.C
CommitLineData
171e422d 1////////////////////////////////////////////////////////////////////////
2//
3// AliTPCTracking.C
4//
5// date: 22.08.2002
6// author: Jiri Chudoba based on code of Jourij Belikov
7// version: 1.0
8// description:
f8aae377 9// reconstructs of tracks in TPC in the following steps:
171e422d 10// TPC cluster finding
11// TPC track finding
12// input parameters:
f8aae377 13// Int_t nEvents ... nr of events to process (<0 means all)
171e422d 14// Int_t firstEventNr ... first event number (starts from 0)
f8aae377 15// const char* fileName ... name of galice file
16// Bool_t makeClusters ... run the cluster finder or not?
17// Bool_t makeTracks ... run the track finder or not?
18// const char* fileNameRaw ... if not NULL, the cluster finder uses
19// the given file as raw data input
171e422d 20//
21// History:
22//
f8aae377 23// 21.07.2003 ... NewIO
24//
17210e28 25// 18.03.2003 ... Char_t* replaced by const char*
26//
2d813ef1 27// 03.03.2003 ... SetFieldFactor moved to AliTracker class and
28// LoadTPCParam moved to AliTPC class
29// TString replaced by Char_t*
30//
73f6cbc2 31// 20.11.2002 ... Changes due to a changed interface of AliTPCtracker.
32// Use Riostream.h instead of iostream.h
33//
171e422d 34// 22.08.2002 ... first version
35//
36////////////////////////////////////////////////////////////////////////
37
38#if !defined(__CINT__) || defined(__MAKECINT__)
f8aae377 39#include <Riostream.h>
40#include <TFile.h>
41#include <TTree.h>
42#include <TBenchmark.h>
43#include "AliRunLoader.h"
17210e28 44#include "AliTPC.h"
f8aae377 45#include "AliTPCParam.h"
46#include "AliTPCclustererMI.h"
47#include "AliTPCtrackerMI.h"
48#include "AliRawReaderRoot.h"
171e422d 49#endif
50
f8aae377 51Bool_t AliTPCTracking(Int_t nEvents = -1, Int_t firstEvent = 0,
52 const char* fileName = "galice.root",
53 Bool_t makeClusters = kTRUE,
54 Bool_t makeTracks = kTRUE,
55 const char* fileNameRaw = NULL);
171e422d 56
f8aae377 57/*
58Int_t TPCRefitInward(Int_t nEvents=1, Int_t firstEvent=0,
17210e28 59 const char* fileNameClusters="tpc.clusters.root",
60 const char* fileNameTracks="tpc.tracks.root",
f8aae377 61 const char* fileNameTRDTracks="trd.tracks.root",
62 const char* fileNameRefittedTracks="tpc.refitted.tracks.root");
63*/
171e422d 64
171e422d 65////////////////////////////////////////////////////////////////////////
f8aae377 66Bool_t AliTPCTracking(Int_t nEvents, Int_t firstEvent,
67 const char* fileName,
68 Bool_t makeClusters,
69 Bool_t makeTracks,
70 const char* fileNameRaw)
71{
72 // get the loaders
73 AliRunLoader* runLoader = AliRunLoader::Open(fileName);
74 if (!runLoader) {
75 cerr << "AliTPCTracking: no run loader found\n";
76 return kFALSE;
77 }
78 AliLoader* tpcLoader = runLoader->GetLoader("TPCLoader");
79 if (!tpcLoader) {
80 cerr << "AliTPCTracking: no TPC loader found\n";
81 return kFALSE;
171e422d 82 }
83
f8aae377 84 // get the TPC parameters
85 runLoader->CdGAFile();
86 AliTPCParam* param = AliTPC::LoadTPCParam(gFile);
87 if (!param) {
88 cerr << "AliTPCTracking: no TPC parameters found\n";
89 return kFALSE;
90 }
171e422d 91
f8aae377 92 // create the clusterer object
93 AliTPCclustererMI* clusterer = NULL;
94 if (makeClusters) {
95 clusterer = new AliTPCclustererMI(param);
96 if (!fileNameRaw) tpcLoader->LoadDigits();
97 tpcLoader->LoadRecPoints("recreate");
171e422d 98 }
f8aae377 99
100 // create the tracker object
101 AliTPCtrackerMI* tracker = NULL;
102 if (makeTracks) {
103// tracker = new AliTPCtrackerMI(param);
104 if (!makeClusters) tpcLoader->LoadRecPoints();
105 tpcLoader->LoadTracks("recreate");
171e422d 106 }
107
f8aae377 108 // get the event number range
109 Int_t maxEvent = 0;
110 if (fileNameRaw) {
111 TFile* file = TFile::Open(fileNameRaw);
112 if (file && file->IsOpen()) {
113 TTree* tree = (TTree*) file->Get("T");
114 if (tree) maxEvent = (Int_t) tree->GetEntries();
115 }
17210e28 116 } else {
f8aae377 117 maxEvent = runLoader->GetNumberOfEvents();
17210e28 118 }
f8aae377 119 if (nEvents < 0) nEvents = maxEvent - firstEvent;
120 Int_t lastEvent = firstEvent + nEvents;
121 if (lastEvent > maxEvent) lastEvent = maxEvent;
122
123 // loop over the events
124 for (Int_t iEvent = firstEvent; iEvent < lastEvent; iEvent++) {
125
126 runLoader->GetEvent(iEvent);
127
128 // run the cluster finder
129 if (makeClusters) {
130 if (!tpcLoader->TreeR()) tpcLoader->MakeRecPointsContainer();
131 clusterer->SetOutput(tpcLoader->TreeR());
132 if (fileNameRaw) {
133 AliRawReaderRoot rawReader(fileNameRaw, iEvent);
134 clusterer->Digits2Clusters(&rawReader);
135 } else {
136 clusterer->SetInput(tpcLoader->TreeD());
137 clusterer->Digits2Clusters();
138 }
139 tpcLoader->WriteRecPoints("OVERWRITE");
140 }
171e422d 141
f8aae377 142 // run the track finder
143 if (makeTracks) {
144 tracker = new AliTPCtrackerMI(param);
145 tracker->Clusters2Tracks();
146 delete tracker;
147 }
171e422d 148 }
17210e28 149
f8aae377 150 if (tracker) delete tracker;
151 if (clusterer) delete clusterer;
17210e28 152
f8aae377 153 return kTRUE;
17210e28 154}
171e422d 155
f8aae377 156/*
157////////////////////////////////////////////////////////////////////////
158Int_t TPCRefitInward(Int_t nEvents, Int_t firstEvent,
159 const char* fileNameClusters,
160 const char* fileNameTracks,
161 const char* fileNameTRDTracks,
162 const char* fileNameRefittedTracks)
163{
171e422d 164 Int_t rc = 0;
f8aae377 165 const Char_t *name="TPCRefitInward";
171e422d 166 if (gDEBUG>1) cout<<name<<" starts"<<endl;
167 if (gDEBUG>1) gBenchmark->Start(name);
f8aae377 168 TFile *fileClusters = TFile::Open(fileNameClusters);
169 TFile *fileTracks = TFile::Open(fileNameTracks);
170 TFile *fileTRDTracks = TFile::Open(fileNameTRDTracks);
171 TFile *fileRefittedTracks = TFile::Open(fileNameRefittedTracks, "recreate");
171e422d 172
f8aae377 173 AliTPCParam* paramTPC = AliTPC::LoadTPCParam(fileClusters);
171e422d 174 if (!paramTPC) return 1;
175
176 for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++){
f8aae377 177 if (gDEBUG > 2) cout<<"TPCRefitInward: event "<<iEvent<<endl;
73f6cbc2 178 AliTPCtracker *tracker = new AliTPCtracker(paramTPC);
179 tracker->SetEventNumber(iEvent);
171e422d 180 fileClusters->cd();
f8aae377 181 rc = tracker->RefitInward(fileTRDTracks, fileTracks, fileRefittedTracks);
171e422d 182 delete tracker;
f8aae377 183 if (rc) return rc;
171e422d 184 }
17210e28 185
f8aae377 186 fileClusters->Close();
187 fileTracks->Close();
188 fileTRDTracks->Close();
189 fileRefittedTracks->Close();
190 delete fileClusters;
191 delete fileTracks;
192 delete fileTRDTracks;
193 delete fileRefittedTracks;
194 if (gDEBUG>1) gBenchmark->Show(name);
17210e28 195 return rc;
196}
f8aae377 197*/